diff --git a/administrator/components/com_media/controllers/api.json.php b/administrator/components/com_media/controllers/api.json.php index 9c41a0cfeb..abbd2484c6 100644 --- a/administrator/components/com_media/controllers/api.json.php +++ b/administrator/components/com_media/controllers/api.json.php @@ -144,7 +144,7 @@ public function files() $this->adapter->createFolder($name, $path); } - $data = $this->adapter->getFiles($path . '/' . $name); + $data = $this->adapter->getFile($path . '/' . $name); break; case 'put': $content = $this->input->json; diff --git a/administrator/components/com_media/libraries/media/file/adapter/local.php b/administrator/components/com_media/libraries/media/file/adapter/local.php index b9992379c1..9862516bce 100644 --- a/administrator/components/com_media/libraries/media/file/adapter/local.php +++ b/administrator/components/com_media/libraries/media/file/adapter/local.php @@ -43,6 +43,42 @@ public function __construct($rootPath) $this->rootPath = $rootPath; } + /** + * Returns the requested file or folder. The returned object + * has the following properties available: + * - type: The type can be file or dir + * - name: The name of the file + * - path: The relative path to the root + * - extension: The file extension + * - size: The size of the file + * - create_date: The date created + * - modified_date: The date modified + * - mime_type: The mime type + * - width: The width, when available + * - height: The height, when available + * + * @param string $path The folder + * + * @return stdClass[] + * + * @since __DEPLOY_VERSION__ + * @throws Exception + */ + public function getFile($path = '/') + { + // Set up the path correctly + $path = JPath::clean('/' . $path); + $basePath = JPath::clean($this->rootPath . $path); + + // Check if file exists + if (!file_exists($basePath)) + { + return array(); + } + + return $this->getPathInformation($basePath); + } + /** * Returns the folders and files for the given path. The returned objects * have the following properties available: diff --git a/administrator/components/com_media/resources/app/Api.js b/administrator/components/com_media/resources/app/Api.js index a333281b70..beec9c4e49 100644 --- a/administrator/components/com_media/resources/app/Api.js +++ b/administrator/components/com_media/resources/app/Api.js @@ -34,6 +34,46 @@ class Api { }).catch(this._handleError); } + /** + * Create a directory + * @param name + * @param parent + * @returns {Promise.} + */ + createDirectory(name, parent) { + // Wrap the jquery call into a real promise + return new Promise((resolve, reject) => { + const url = this._baseUrl + '&task=api.files&path=' + parent; + jQuery.ajax({ + url: url, + type: "POST", + data: JSON.stringify({'name': name}), + contentType: "application/json", + }) + .done((json) => resolve(this._normalizeItem(json.data))) + .fail((xhr, status, error) => { + reject(xhr) + }) + }).catch(this._handleError); + } + + /** + * Normalize a single item + * @param item + * @returns {*} + * @private + */ + _normalizeItem(item) { + if(item.type === 'dir') { + item.directories = []; + item.files = []; + } + + item.directory = path.dirname(item.path); + + return item; + } + /** * Normalize array data * @param data @@ -42,21 +82,10 @@ class Api { */ _normalizeArray(data) { - // Directories const directories = data.filter(item => (item.type === 'dir')) - .map(directory => { - directory.directory = path.dirname(directory.path); - directory.directories = []; - directory.files = []; - return directory; - }); - - // Files + .map(directory => this._normalizeItem(directory)); const files = data.filter(item => (item.type === 'file')) - .map(file => { - file.directory = path.dirname(file.path); - return file; - }); + .map(file => this._normalizeItem(file)); return { directories: directories, diff --git a/administrator/components/com_media/resources/components/app.vue b/administrator/components/com_media/resources/components/app.vue index d1ab533d7b..af35b12872 100644 --- a/administrator/components/com_media/resources/components/app.vue +++ b/administrator/components/com_media/resources/components/app.vue @@ -7,6 +7,7 @@ + @@ -37,7 +38,7 @@ }); }, beforeDestroy() { - // Add the global resize event listener + // Remove the global resize event listener window.removeEventListener('resize', this.setFullHeight) }, } diff --git a/administrator/components/com_media/resources/components/modals/create-folder-modal.vue b/administrator/components/com_media/resources/components/modals/create-folder-modal.vue new file mode 100644 index 0000000000..c0a052d088 --- /dev/null +++ b/administrator/components/com_media/resources/components/modals/create-folder-modal.vue @@ -0,0 +1,40 @@ + + + \ No newline at end of file diff --git a/administrator/components/com_media/resources/components/modals/modal.vue b/administrator/components/com_media/resources/components/modals/modal.vue new file mode 100644 index 0000000000..824b517fa1 --- /dev/null +++ b/administrator/components/com_media/resources/components/modals/modal.vue @@ -0,0 +1,96 @@ + + + + + \ No newline at end of file diff --git a/administrator/components/com_media/resources/components/toolbar/toolbar.vue b/administrator/components/com_media/resources/components/toolbar/toolbar.vue index ff60e6adb6..ac0e45018c 100644 --- a/administrator/components/com_media/resources/components/toolbar/toolbar.vue +++ b/administrator/components/com_media/resources/components/toolbar/toolbar.vue @@ -2,12 +2,12 @@
- +