diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-07-10 10:14:03 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-07-10 10:14:03 +0200 |
commit | 87f3500fda04f76d97754185a71f285e9770c66c (patch) | |
tree | 8fd76813636a7ec3fdbce7565dd7fe2ba38e2e92 | |
parent | 176dabd9766a2b298ad3adf9e4e5338aecccc201 (diff) | |
parent | eb7a796ad98ec833e49c2544f03da52d11c302b1 (diff) | |
download | nextcloud-server-87f3500fda04f76d97754185a71f285e9770c66c.tar.gz nextcloud-server-87f3500fda04f76d97754185a71f285e9770c66c.zip |
Merge pull request #17483 from rullzer/migrate-mimetype-js
Move away from OCA.files.getMimeIcon and use OC.MimeType.getIconUrl
-rw-r--r-- | apps/files/ajax/mimeicon.php | 27 | ||||
-rw-r--r-- | apps/files/appinfo/routes.php | 2 | ||||
-rw-r--r-- | apps/files/js/filelist.js | 54 | ||||
-rw-r--r-- | apps/files/js/files.js | 19 | ||||
-rw-r--r-- | apps/files/tests/js/filelistSpec.js | 7 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/shareSpec.js | 2 | ||||
-rw-r--r-- | config/mimetypealiases.json | 119 | ||||
-rw-r--r-- | core/js/mimetypelist.js | 1 | ||||
-rw-r--r-- | core/js/oc-dialogs.js | 5 |
9 files changed, 101 insertions, 135 deletions
diff --git a/apps/files/ajax/mimeicon.php b/apps/files/ajax/mimeicon.php deleted file mode 100644 index 008ad41953e..00000000000 --- a/apps/files/ajax/mimeicon.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php -/** - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Lukas Reschke <lukas@owncloud.com> - * @author Robin Appelman <icewind@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ -\OC::$server->getSession()->close(); - -$mime = isset($_GET['mime']) ? (string)$_GET['mime'] : ''; - -print OC_Helper::mimetypeIcon($mime); diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index ceeb3cdcc8a..5aa52f17a29 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -66,8 +66,6 @@ $this->create('files_ajax_getstoragestats', 'ajax/getstoragestats.php') ->actionInclude('files/ajax/getstoragestats.php'); $this->create('files_ajax_list', 'ajax/list.php') ->actionInclude('files/ajax/list.php'); -$this->create('files_ajax_mimeicon', 'ajax/mimeicon.php') - ->actionInclude('files/ajax/mimeicon.php'); $this->create('files_ajax_move', 'ajax/move.php') ->actionInclude('files/ajax/move.php'); $this->create('files_ajax_newfile', 'ajax/newfile.php') diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 417c4b9fe99..a3fd605ff7e 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -670,7 +670,7 @@ */ _createRow: function(fileData, options) { var td, simpleSize, basename, extension, sizeColor, - icon = OC.Util.replaceSVGIcon(fileData.icon), + icon = OC.MimeType.getIconUrl(fileData.mimetype), name = fileData.name, type = fileData.type || 'file', mtime = parseInt(fileData.mtime, 10), @@ -1213,36 +1213,34 @@ var etag = options.etag; // get mime icon url - OCA.Files.Files.getMimeIcon(mime, function(iconURL) { - var previewURL, - urlSpec = {}; - ready(iconURL); // set mimeicon URL + var iconURL = OC.MimeType.getIconUrl(mime); + var previewURL, + urlSpec = {}; + ready(iconURL); // set mimeicon URL - urlSpec.file = OCA.Files.Files.fixPath(path); + urlSpec.file = OCA.Files.Files.fixPath(path); - if (etag){ - // use etag as cache buster - urlSpec.c = etag; - } - else { - console.warn('OCA.Files.FileList.lazyLoadPreview(): missing etag argument'); - } + if (etag){ + // use etag as cache buster + urlSpec.c = etag; + } else { + console.warn('OCA.Files.FileList.lazyLoadPreview(): missing etag argument'); + } - previewURL = self.generatePreviewUrl(urlSpec); - previewURL = previewURL.replace('(', '%28'); - previewURL = previewURL.replace(')', '%29'); - - // preload image to prevent delay - // this will make the browser cache the image - var img = new Image(); - img.onload = function(){ - // if loading the preview image failed (no preview for the mimetype) then img.width will < 5 - if (img.width > 5) { - ready(previewURL); - } - }; - img.src = previewURL; - }); + previewURL = self.generatePreviewUrl(urlSpec); + previewURL = previewURL.replace('(', '%28'); + previewURL = previewURL.replace(')', '%29'); + + // preload image to prevent delay + // this will make the browser cache the image + var img = new Image(); + img.onload = function(){ + // if loading the preview image failed (no preview for the mimetype) then img.width will < 5 + if (img.width > 5) { + ready(previewURL); + } + }; + img.src = previewURL; }, setDirectoryPermissions: function(permissions) { diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 44868e78bd0..1b498769dd6 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -163,18 +163,14 @@ return OC.filePath('files', 'ajax', action + '.php') + q; }, + /** + * Fetch the icon url for the mimetype + * @param {string} mime The mimetype + * @param {Files~mimeicon} ready Function to call when mimetype is retrieved + * @deprecated use OC.MimeType.getIconUrl(mime) + */ getMimeIcon: function(mime, ready) { - if (Files.getMimeIcon.cache[mime]) { - ready(Files.getMimeIcon.cache[mime]); - } else { - $.get( OC.filePath('files','ajax','mimeicon.php'), {mime: mime}, function(path) { - if(OC.Util.hasSVGSupport()){ - path = path.substr(0, path.length-4) + '.svg'; - } - Files.getMimeIcon.cache[mime]=path; - ready(Files.getMimeIcon.cache[mime]); - }); - } + ready(OC.MimeType.getIconUrl(mime)); }, /** @@ -211,7 +207,6 @@ * Initialize the files view */ initialize: function() { - Files.getMimeIcon.cache = {}; Files.bindKeyboardShortcuts(document, $); // TODO: move file list related code (upload) to OCA.Files.FileList diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index b12ac2f2517..316df0281e9 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -697,7 +697,7 @@ describe('OCA.Files.FileList tests', function() { expect(fileList.findFileEl('One.txt').length).toEqual(1); expect(OC.TestUtil.getImageUrl(fileList.findFileEl('One.txt').find('.thumbnail'))) - .toEqual(OC.imagePath('core', 'filetypes/file.svg')); + .toEqual(OC.imagePath('core', 'filetypes/text.svg')); }); }); describe('Moving files', function() { @@ -816,7 +816,7 @@ describe('OCA.Files.FileList tests', function() { expect(notificationStub.getCall(0).args[0]).toEqual('Error while moving file'); expect(OC.TestUtil.getImageUrl(fileList.findFileEl('One.txt').find('.thumbnail'))) - .toEqual(OC.imagePath('core', 'filetypes/file.svg')); + .toEqual(OC.imagePath('core', 'filetypes/text.svg')); }); }); describe('List rendering', function() { @@ -1161,7 +1161,8 @@ describe('OCA.Files.FileList tests', function() { var fileData = { type: 'file', name: 'test dir', - icon: OC.webroot + '/core/img/filetypes/application-pdf.svg' + icon: OC.webroot + '/core/img/filetypes/application-pdf.svg', + mimetype: 'application/pdf' }; var $tr = fileList.add(fileData); var $imgDiv = $tr.find('td.filename .thumbnail'); diff --git a/apps/files_sharing/tests/js/shareSpec.js b/apps/files_sharing/tests/js/shareSpec.js index 1bbf4ffca09..aa409285ca4 100644 --- a/apps/files_sharing/tests/js/shareSpec.js +++ b/apps/files_sharing/tests/js/shareSpec.js @@ -90,7 +90,7 @@ describe('OCA.Sharing.Util tests', function() { type: 'dir', name: 'One', path: '/subdir', - mimetype: 'text/plain', + mimetype: 'httpd/unix-directory', size: 12, permissions: OC.PERMISSION_ALL, etag: 'abc' diff --git a/config/mimetypealiases.json b/config/mimetypealiases.json index d1684460eff..f1b13b67ee6 100644 --- a/config/mimetypealiases.json +++ b/config/mimetypealiases.json @@ -4,65 +4,66 @@ "_comment3": "Otherwise your update won't propagate through the system", - "application/coreldraw": "image", - "application/font-sfnt": "font", - "application/font-woff": "font", - "application/illustrator": "image/vector", - "application/json": "text/code", - "application/msaccess": "database", - "application/msexcel": "x-office/spreadsheet", - "application/mspowerpoint": "x-office/presentation", - "application/msword": "x-office/document", - "application/octet-stream": "file", - "application/postscript": "image/vector", - "application/vnd.android.package-archive": "package/x-generic", - "application/vnd.ms-excel": "x-office/spreadsheet", - "application/vnd.ms-excel.addin.macroEnabled.12": "x-office/spreadsheet", - "application/vnd.ms-excel.sheet.binary.macroEnabled.12": "x-office/spreadsheet", - "application/vnd.ms-excel.sheet.macroEnabled.12": "x-office/spreadsheet", - "application/vnd.ms-excel.template.macroEnabled.12": "x-office/spreadsheet", - "application/vnd.ms-fontobject": "font", - "application/vnd.ms-powerpoint": "x-office/presentation", - "application/vnd.ms-powerpoint.addin.macroEnabled.12": "x-office/presentation", - "application/vnd.ms-powerpoint.presentation.macroEnabled.12": "x-office/presentation", - "application/vnd.ms-powerpoint.slideshow.macroEnabled.12": "x-office/presentation", - "application/vnd.ms-powerpoint.template.macroEnabled.12": "x-office/presentation", - "application/vnd.ms-word.document.macroEnabled.12": "x-office/document", - "application/vnd.ms-word.template.macroEnabled.12": "x-office/document", - "application/vnd.oasis.opendocument.presentation": "x-office/presentation", - "application/vnd.oasis.opendocument.presentation-template": "x-office/presentation", - "application/vnd.oasis.opendocument.spreadsheet": "x-office/spreadsheet", - "application/vnd.oasis.opendocument.spreadsheet-template": "x-office/spreadsheet", - "application/vnd.oasis.opendocument.text": "x-office/document", - "application/vnd.oasis.opendocument.text-master": "x-office/document", - "application/vnd.oasis.opendocument.text-template": "x-office/document", - "application/vnd.oasis.opendocument.text-web": "x-office/document", - "application/vnd.openxmlformats-officedocument.presentationml.presentation": "x-office/presentation", - "application/vnd.openxmlformats-officedocument.presentationml.slideshow": "x-office/presentation", - "application/vnd.openxmlformats-officedocument.presentationml.template": "x-office/presentation", - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "x-office/spreadsheet", - "application/vnd.openxmlformats-officedocument.spreadsheetml.template": "x-office/spreadsheet", - "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "x-office/document", - "application/vnd.openxmlformats-officedocument.wordprocessingml.template": "x-office/document", - "application/x-7z-compressed": "package/x-generic", - "application/x-compressed": "package/x-generic", - "application/x-dcraw": "image", - "application/x-deb": "package/x-generic", - "application/x-font": "font", - "application/x-gimp": "image", - "application/x-gzip": "package/x-generic", - "application/x-perl": "text/code", - "application/x-photoshop": "image", - "application/x-php": "text/code", - "application/x-rar-compressed": "package/x-generic", - "application/x-tar": "package/x-generic", - "application/x-tex": "text", - "application/xml": "text/html", - "application/yaml": "text/code", - "application/zip": "package/x-generic", - "image/svg+xml": "image/vector", - "text/css": "text/code", - "text/csv": "x-office/spreadsheet", + "application/coreldraw": "image", + "application/font-sfnt": "font", + "application/font-woff": "font", + "application/illustrator": "image/vector", + "application/json": "text/code", + "application/msaccess": "database", + "application/msexcel": "x-office/spreadsheet", + "application/mspowerpoint": "x-office/presentation", + "application/msword": "x-office/document", + "application/octet-stream": "file", + "application/postscript": "image/vector", + "application/vnd.android.package-archive": "package/x-generic", + "application/vnd.ms-excel": "x-office/spreadsheet", + "application/vnd.ms-excel.addin.macroEnabled.12": "x-office/spreadsheet", + "application/vnd.ms-excel.sheet.binary.macroEnabled.12": "x-office/spreadsheet", + "application/vnd.ms-excel.sheet.macroEnabled.12": "x-office/spreadsheet", + "application/vnd.ms-excel.template.macroEnabled.12": "x-office/spreadsheet", + "application/vnd.ms-fontobject": "font", + "application/vnd.ms-powerpoint": "x-office/presentation", + "application/vnd.ms-powerpoint.addin.macroEnabled.12": "x-office/presentation", + "application/vnd.ms-powerpoint.presentation.macroEnabled.12": "x-office/presentation", + "application/vnd.ms-powerpoint.slideshow.macroEnabled.12": "x-office/presentation", + "application/vnd.ms-powerpoint.template.macroEnabled.12": "x-office/presentation", + "application/vnd.ms-word.document.macroEnabled.12": "x-office/document", + "application/vnd.ms-word.template.macroEnabled.12": "x-office/document", + "application/vnd.oasis.opendocument.presentation": "x-office/presentation", + "application/vnd.oasis.opendocument.presentation-template": "x-office/presentation", + "application/vnd.oasis.opendocument.spreadsheet": "x-office/spreadsheet", + "application/vnd.oasis.opendocument.spreadsheet-template": "x-office/spreadsheet", + "application/vnd.oasis.opendocument.text": "x-office/document", + "application/vnd.oasis.opendocument.text-master": "x-office/document", + "application/vnd.oasis.opendocument.text-template": "x-office/document", + "application/vnd.oasis.opendocument.text-web": "x-office/document", + "application/vnd.openxmlformats-officedocument.presentationml.presentation": "x-office/presentation", + "application/vnd.openxmlformats-officedocument.presentationml.slideshow": "x-office/presentation", + "application/vnd.openxmlformats-officedocument.presentationml.template": "x-office/presentation", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "x-office/spreadsheet", + "application/vnd.openxmlformats-officedocument.spreadsheetml.template": "x-office/spreadsheet", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "x-office/document", + "application/vnd.openxmlformats-officedocument.wordprocessingml.template": "x-office/document", + "application/x-7z-compressed": "package/x-generic", + "application/x-compressed": "package/x-generic", + "application/x-dcraw": "image", + "application/x-deb": "package/x-generic", + "application/x-font": "font", + "application/x-gimp": "image", + "application/x-gzip": "package/x-generic", + "application/x-perl": "text/code", + "application/x-photoshop": "image", + "application/x-php": "text/code", + "application/x-rar-compressed": "package/x-generic", + "application/x-tar": "package/x-generic", + "application/x-tex": "text", + "application/xml": "text/html", + "application/yaml": "text/code", + "application/zip": "package/x-generic", + "httpd/unix-directory": "dir", + "image/svg+xml": "image/vector", + "text/css": "text/code", + "text/csv": "x-office/spreadsheet", "text/x-shellscript": "text/code" } diff --git a/core/js/mimetypelist.js b/core/js/mimetypelist.js index 2a780fc2bcb..b4de98247d1 100644 --- a/core/js/mimetypelist.js +++ b/core/js/mimetypelist.js @@ -64,6 +64,7 @@ OC.MimeTypeList={ "application/xml": "text/html", "application/yaml": "text/code", "application/zip": "package/x-generic", + "httpd/unix-directory": "dir", "image/svg+xml": "image/vector", "text/css": "text/code", "text/csv": "x-office/spreadsheet", diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index 9f88c268369..52ed34f61ec 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -396,9 +396,8 @@ var OCdialogs = { function(path){ $replacementDiv.find('.icon').css('background-image','url(' + path + ')'); }, function(){ - Files.getMimeIcon(replacement.type,function(path){ - $replacementDiv.find('.icon').css('background-image','url(' + path + ')'); - }); + path = OC.MimeType.getIconUrl(replacement.type); + $replacementDiv.find('.icon').css('background-image','url(' + path + ')'); } ); $conflicts.append($conflict); |