Fix files app LoadSidebar event (#18213)

Fix files app LoadSidebar event
This commit is contained in:
John Molakvoæ 2019-12-04 12:47:40 +01:00 committed by GitHub
commit bfb9ccec1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 103 additions and 23 deletions

View File

@ -26,6 +26,9 @@
*/
use OC\Search\Provider\File;
use OCA\Files\AppInfo\Application;
$app = \OC::$server->query(Application::class);
// required for translation purpose
// t('Files')

View File

@ -44,6 +44,7 @@ return array(
'OCA\\Files\\Exception\\TransferOwnershipException' => $baseDir . '/../lib/Exception/TransferOwnershipException.php',
'OCA\\Files\\Helper' => $baseDir . '/../lib/Helper.php',
'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => $baseDir . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
'OCA\\Files\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php',
'OCA\\Files\\Migration\\Version11301Date20191113195931' => $baseDir . '/../lib/Migration/Version11301Date20191113195931.php',
'OCA\\Files\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
'OCA\\Files\\Service\\DirectEditingService' => $baseDir . '/../lib/Service/DirectEditingService.php',

View File

@ -59,6 +59,7 @@ class ComposerStaticInitFiles
'OCA\\Files\\Exception\\TransferOwnershipException' => __DIR__ . '/..' . '/../lib/Exception/TransferOwnershipException.php',
'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => __DIR__ . '/..' . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
'OCA\\Files\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php',
'OCA\\Files\\Migration\\Version11301Date20191113195931' => __DIR__ . '/..' . '/../lib/Migration/Version11301Date20191113195931.php',
'OCA\\Files\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
'OCA\\Files\\Service\\DirectEditingService' => __DIR__ . '/..' . '/../lib/Service/DirectEditingService.php',

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,4 @@
[
"dist/sidebar.js",
"app.js",
"breadcrumb.js",
"detailfileinfoview.js",

View File

@ -27,14 +27,14 @@
namespace OCA\Files\AppInfo;
use OCA\Files\Activity\Helper;
use OCA\Files\Capabilities;
use OCA\Files\Collaboration\Resources\Listener;
use OCA\Files\Collaboration\Resources\ResourceProvider;
use OCA\Files\Controller\ApiController;
use OCA\Files\Controller\ViewController;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files\Event\LoadSidebar;
use OCA\Files\Listener\LegacyLoadAdditionalScriptsAdapter;
use OCA\Files\Listener\LoadSidebarListener;
use OCA\Files\Notification\Notifier;
use OCA\Files\Service\TagService;
use OCP\AppFramework\App;
@ -97,6 +97,7 @@ class Application extends App {
/** @var IEventDispatcher $dispatcher */
$dispatcher = $container->query(IEventDispatcher::class);
$dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class);
$dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class);
/** @var \OCP\Notification\IManager $notifications */
$notifications = $container->query(\OCP\Notification\IManager::class);

View File

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019, John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Files\Listener;
use OCA\Files\AppInfo\Application;
use OCA\Files\Event\LoadSidebar;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;
class LoadSidebarListener implements IEventListener {
public function handle(Event $event): void {
if (!($event instanceof LoadSidebar)) {
return;
}
Util::addScript(Application::APP_ID, 'dist/sidebar');
}
}

View File

@ -31,11 +31,13 @@ Vue.use(VueClipboard)
Vue.prototype.t = t
window.addEventListener('DOMContentLoaded', () => {
// Init Sidebar Service
if (window.OCA && window.OCA.Files) {
Object.assign(window.OCA.Files, { Sidebar: new Sidebar() })
Object.assign(window.OCA.Files.Sidebar, { Tab })
if (!window.OCA.Files) {
window.OCA.Files = {}
}
Object.assign(window.OCA.Files, { Sidebar: new Sidebar() })
Object.assign(window.OCA.Files.Sidebar, { Tab })
// Make sure we have a proper layout
if (document.getElementById('content')) {

View File

@ -199,6 +199,8 @@ export default {
defaultAction() {
return this.fileInfo
&& OCA.Files && OCA.Files.App && OCA.Files.App.fileList
&& OCA.Files.App.fileList.fileActions
&& OCA.Files.App.fileList.fileActions.getDefaultFileAction
&& OCA.Files.App.fileList
.fileActions.getDefaultFileAction(this.fileInfo.mimetype, this.fileInfo.type, OC.PERMISSION_READ)
@ -239,7 +241,7 @@ export default {
})
} catch (error) {
this.error = t('files', 'Error while loading the file data')
console.error('Error while loading the file data')
console.error('Error while loading the file data', error)
}
}
}
@ -272,11 +274,42 @@ export default {
}
})
},
getPreviewIfAny(fileInfo) {
if (fileInfo.hasPreview) {
return OC.generateUrl(`/core/preview?fileId=${fileInfo.id}&x=${screen.width}&y=${screen.height}&a=true`)
}
return OCA.Files.App.fileList._getIconUrl(fileInfo)
return this.getIconUrl(fileInfo)
},
/**
* Copied from https://github.com/nextcloud/server/blob/16e0887ec63591113ee3f476e0c5129e20180cde/apps/files/js/filelist.js#L1377
* TODO: We also need this as a standalone library
*
* @param {Object} fileInfo the fileinfo
* @returns {string} Url to the icon for mimeType
*/
getIconUrl(fileInfo) {
var mimeType = fileInfo.mimetype || 'application/octet-stream'
if (mimeType === 'httpd/unix-directory') {
// use default folder icon
if (fileInfo.mountType === 'shared' || fileInfo.mountType === 'shared-root') {
return OC.MimeType.getIconUrl('dir-shared')
} else if (fileInfo.mountType === 'external-root') {
return OC.MimeType.getIconUrl('dir-external')
} else if (fileInfo.mountType !== undefined && fileInfo.mountType !== '') {
return OC.MimeType.getIconUrl('dir-' + fileInfo.mountType)
} else if (fileInfo.shareTypes && (
fileInfo.shareTypes.indexOf(OC.Share.SHARE_TYPE_LINK) > -1
|| fileInfo.shareTypes.indexOf(OC.Share.SHARE_TYPE_EMAIL) > -1)
) {
return OC.MimeType.getIconUrl('dir-public')
} else if (fileInfo.shareTypes && fileInfo.shareTypes.length > 0) {
return OC.MimeType.getIconUrl('dir-shared')
}
return OC.MimeType.getIconUrl('dir')
}
return OC.MimeType.getIconUrl(mimeType)
},
tabComponent(tab) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -26,14 +26,12 @@ import ExternalLinkActions from './services/ExternalLinkActions'
import TabSections from './services/TabSections'
if (window.OCA && window.OCA.Sharing) {
Object.assign(window.OCA.Sharing, { ShareSearch: new ShareSearch() })
// Init Sharing Tab Service
if (!window.OCA.Sharing) {
window.OCA.Sharing = {}
}
if (window.OCA && window.OCA.Sharing) {
Object.assign(window.OCA.Sharing, { ExternalLinkActions: new ExternalLinkActions() })
}
Object.assign(window.OCA.Sharing, { ShareSearch: new ShareSearch() })
Object.assign(window.OCA.Sharing, { ExternalLinkActions: new ExternalLinkActions() })
Object.assign(window.OCA.Sharing, { ShareTabSections: new TabSections() })
window.addEventListener('DOMContentLoaded', () => {