From 04f73275ba222f0aae80cf80890477b141cd4902 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 9 Dec 2013 13:18:13 +0100 Subject: [PATCH 1/6] Now settings CSS class with appid in content DIV --- core/templates/layout.user.php | 2 +- lib/private/template.php | 4 +++- lib/private/templatelayout.php | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php index a217446ca7..b0ae8637ac 100644 --- a/core/templates/layout.user.php +++ b/core/templates/layout.user.php @@ -123,7 +123,7 @@
-
+
diff --git a/lib/private/template.php b/lib/private/template.php index 3d18b52bac..dfeb5d14b0 100644 --- a/lib/private/template.php +++ b/lib/private/template.php @@ -30,6 +30,7 @@ class OC_Template extends \OC\Template\Base { private $renderas; // Create a full page? private $path; // The path to the template private $headers=array(); //custom headers + protected $app; // app id /** * @brief Constructor @@ -62,6 +63,7 @@ class OC_Template extends \OC\Template\Base { // Set the private data $this->renderas = $renderas; $this->path = $path; + $this->app = $app; parent::__construct($template, $requesttoken, $l10n, $themeDefaults); } @@ -172,7 +174,7 @@ class OC_Template extends \OC\Template\Base { $data = parent::fetchPage(); if( $this->renderas ) { - $page = new OC_TemplateLayout($this->renderas); + $page = new OC_TemplateLayout($this->renderas, $this->app); // Add custom headers $page->assign('headers', $this->headers, false); diff --git a/lib/private/templatelayout.php b/lib/private/templatelayout.php index 0672ffc4a3..a5dd9a0c61 100644 --- a/lib/private/templatelayout.php +++ b/lib/private/templatelayout.php @@ -15,8 +15,9 @@ class OC_TemplateLayout extends OC_Template { /** * @param string $renderas + * @param string $appid application id */ - public function __construct( $renderas ) { + public function __construct( $renderas, $appid = '' ) { // Decide which page we show if( $renderas == 'user' ) { @@ -43,6 +44,7 @@ class OC_TemplateLayout extends OC_Template { // Add navigation entry $this->assign( 'application', '', false ); + $this->assign( 'appid', $appid ); $navigation = OC_App::getNavigation(); $this->assign( 'navigation', $navigation); $this->assign( 'settingsnavigation', OC_App::getSettingsNavigation()); From 9ccb3279dd09b7042ab07c936a4c04127282476f Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 9 Dec 2013 13:32:28 +0100 Subject: [PATCH 2/6] Added app navigation for files app - Added links to trashbin and shared dir - Moved "WebDAV" settings block to the app nav's settings section - Added sidebar support in trashbin app as well --- apps/files/css/files.css | 7 +++++++ apps/files/index.php | 6 ++++++ apps/files/js/files.js | 8 ++++++++ apps/files/templates/appnavigation.php | 19 +++++++++++++++++++ apps/files/templates/index.php | 7 ++++--- apps/files_trashbin/index.php | 5 +++++ apps/files_trashbin/templates/index.php | 3 +++ core/css/apps.css | 3 +++ core/css/styles.css | 5 ----- settings/templates/personal.php | 6 ------ 10 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 apps/files/templates/appnavigation.php diff --git a/apps/files/css/files.css b/apps/files/css/files.css index 3dc5ef5a39..db23f54f21 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -84,6 +84,9 @@ } #filestable tbody tr { background-color:#fff; height:51px; } +.app-files #controls { + left: 300px; +} #filestable tbody tr:hover, tbody tr:active { background-color: rgb(240,240,240); } @@ -431,3 +434,7 @@ table.dragshadow td.size { .mask.transparent{ opacity: 0; } + +.app-files #app-settings input { + width: 90%; +} diff --git a/apps/files/index.php b/apps/files/index.php index a4e9a93850..df207582dd 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -89,6 +89,11 @@ if ($trashEnabled) { $trashEmpty = \OCA\Files_Trashbin\Trashbin::isEmpty($user); } +$nav = new OCP\Template('files', 'appnavigation', ''); + +$nav->assign('trash', $trashEnabled); +$nav->assign('trashEmpty', $trashEmpty); + OCP\Util::addscript('files', 'fileactions'); OCP\Util::addscript('files', 'files'); OCP\Util::addscript('files', 'keyboardshortcuts'); @@ -110,5 +115,6 @@ $tmpl->assign("mailNotificationEnabled", $config->getAppValue('core', 'shareapi_ $tmpl->assign("allowShareWithLink", $config->getAppValue('core', 'shareapi_allow_links', 'yes')); $tmpl->assign("encryptionInitStatus", $encryptionInitStatus); $tmpl->assign('disableSharing', false); +$tmpl->assign('appNavigation', $nav); $tmpl->printPage(); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 6d167851e6..60e20a62e8 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -254,6 +254,14 @@ $(document).ready(function() { } } + $('#app-settings-header').on('click', function() { + var $settings = $('#app-settings'); + $settings.toggleClass('opened'); + if ($settings.hasClass('opened')) { + $settings.find('input').focus(); + } + }); + //scroll to and highlight preselected file if (getURLParameter('scrollto')) { FileList.scrollTo(getURLParameter('scrollto')); diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php new file mode 100644 index 0000000000..22987ec637 --- /dev/null +++ b/apps/files/templates/appnavigation.php @@ -0,0 +1,19 @@ +
+ +
+
+ +
+
+

t('WebDAV'));?>

+
+ t('Use this address to access your Files via WebDAV', array(link_to_docs('user-webdav'))));?> +
+
+
diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 9c593a9341..9ed294e6b6 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -1,4 +1,6 @@ +printPage(); ?> +
- - /> -
+
+ diff --git a/apps/files_trashbin/index.php b/apps/files_trashbin/index.php index 6e6a8a3830..16cd5ecd4c 100644 --- a/apps/files_trashbin/index.php +++ b/apps/files_trashbin/index.php @@ -39,4 +39,9 @@ if ($isIE8 && isset($_GET['dir'])){ $tmpl->assign('dir', $dir); $tmpl->assign('disableSharing', true); +$nav = new OCP\Template('files', 'appnavigation', ''); +$nav->assign('trash', true); + +$tmpl->assign('appNavigation', $nav); + $tmpl->printPage(); diff --git a/apps/files_trashbin/templates/index.php b/apps/files_trashbin/templates/index.php index 7c673c317e..02067385d4 100644 --- a/apps/files_trashbin/templates/index.php +++ b/apps/files_trashbin/templates/index.php @@ -1,4 +1,6 @@ +printPage(); ?> +
@@ -44,3 +46,4 @@ +
diff --git a/core/css/apps.css b/core/css/apps.css index a0bb262854..377878467c 100644 --- a/core/css/apps.css +++ b/core/css/apps.css @@ -178,6 +178,9 @@ bottom: 0; border-top: 1px solid #ccc; } +#app-settings.opened #app-settings-content { + display: block; +} #app-settings-header { background-color: #eee; } diff --git a/core/css/styles.css b/core/css/styles.css index d21e6bc690..b99af47ff3 100644 --- a/core/css/styles.css +++ b/core/css/styles.css @@ -302,11 +302,6 @@ input[type="submit"].enabled { border-bottom: 1px solid #e7e7e7; z-index: 50; } -/* account for shift of controls bar due to app navigation */ -#body-user #controls, -#body-settings #controls { - padding-left: 80px; -} #controls .button, #controls button, #controls input[type='submit'], diff --git a/settings/templates/personal.php b/settings/templates/personal.php index afa3f5d700..1d1500743a 100644 --- a/settings/templates/personal.php +++ b/settings/templates/personal.php @@ -133,12 +133,6 @@ if($_['passwordChangeSupported']) { -
-

t('WebDAV'));?>

-
- t('Use this address to access your Files via WebDAV', array(link_to_docs('user-webdav'))));?> -
- From 88ebb15f1d91b82022e02903ab73338065e223b9 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 8 May 2014 16:24:24 +0200 Subject: [PATCH 3/6] Added navigation manager in files app for the sidebar Apps can now register navigation items into the sidebar of the files app. For every sidebar item there is a container. The container's content is rendered based on the script name given at registration time. --- apps/files/index.php | 40 ++++++++++++++++++------- apps/files/lib/app.php | 17 +++++++++++ apps/files/templates/appnavigation.php | 8 ++--- apps/files/templates/index.php | 8 ++++- apps/files_trashbin/appinfo/app.php | 13 ++++++-- apps/files_trashbin/index.php | 37 ++--------------------- apps/files_trashbin/templates/index.php | 7 ----- 7 files changed, 70 insertions(+), 60 deletions(-) diff --git a/apps/files/index.php b/apps/files/index.php index df207582dd..ea57a548a2 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -83,16 +83,37 @@ if (OC_App::isEnabled('files_encryption')) { $encryptionInitStatus = $session->getInitialized(); } -$trashEnabled = \OCP\App::isEnabled('files_trashbin'); -$trashEmpty = true; -if ($trashEnabled) { - $trashEmpty = \OCA\Files_Trashbin\Trashbin::isEmpty($user); -} - $nav = new OCP\Template('files', 'appnavigation', ''); -$nav->assign('trash', $trashEnabled); -$nav->assign('trashEmpty', $trashEmpty); +$navItems = \OCA\Files\App::getNavigationManager()->getAll(); +$nav->assign('navigationItems', $navItems); + +$contentItems = array(); + +function renderScript($appName, $scriptName) { + $content = ''; + $appPath = OC_App::getAppPath($appName); + $scriptPath = $appPath . '/' . $scriptName; + if (file_exists($scriptPath)) { + // TODO: sanitize path / script name ? + ob_start(); + include $scriptPath; + $content = ob_get_contents(); + @ob_end_clean(); + } + return $content; +} + +foreach ($navItems as $item) { + $content = ''; + if (isset($item['script'])) { + $content = renderScript($item['appname'], $item['script']); + } + $contentItem = array(); + $contentItem['appname'] = $item['appname']; + $contentItem['content'] = $content; + $contentItems[] = $contentItem; +} OCP\Util::addscript('files', 'fileactions'); OCP\Util::addscript('files', 'files'); @@ -100,8 +121,6 @@ OCP\Util::addscript('files', 'keyboardshortcuts'); $tmpl = new OCP\Template('files', 'index', 'user'); $tmpl->assign('dir', $dir); $tmpl->assign('permissions', $permissions); -$tmpl->assign('trash', $trashEnabled); -$tmpl->assign('trashEmpty', $trashEmpty); $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); // minimium of freeSpace and uploadLimit $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize)); $tmpl->assign('freeSpace', $freeSpace); @@ -116,5 +135,6 @@ $tmpl->assign("allowShareWithLink", $config->getAppValue('core', 'shareapi_allow $tmpl->assign("encryptionInitStatus", $encryptionInitStatus); $tmpl->assign('disableSharing', false); $tmpl->assign('appNavigation', $nav); +$tmpl->assign('appContents', $contentItems); $tmpl->printPage(); diff --git a/apps/files/lib/app.php b/apps/files/lib/app.php index ed4aa32c66..e32225d068 100644 --- a/apps/files/lib/app.php +++ b/apps/files/lib/app.php @@ -30,6 +30,11 @@ class App { */ private $l10n; + /** + * @var \OCP\INavigationManager + */ + private static $navigationManager; + /** * @var \OC\Files\View */ @@ -40,6 +45,18 @@ class App { $this->l10n = $l10n; } + /** + * Returns the app's navigation manager + * + * @return \OCP\INavigationManager + */ + public static function getNavigationManager() { + if (self::$navigationManager === null) { + self::$navigationManager = new \OC\NavigationManager(); + } + return self::$navigationManager; + } + /** * rename a file * diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php index 22987ec637..a2fffd4c4b 100644 --- a/apps/files/templates/appnavigation.php +++ b/apps/files/templates/appnavigation.php @@ -1,10 +1,10 @@
diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 9ed294e6b6..335e2b2acd 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -1,6 +1,7 @@ printPage(); ?>
+
- +
+ + +
diff --git a/apps/files_trashbin/appinfo/app.php b/apps/files_trashbin/appinfo/app.php index d30a601ef5..a045b1f0f5 100644 --- a/apps/files_trashbin/appinfo/app.php +++ b/apps/files_trashbin/appinfo/app.php @@ -1,7 +1,14 @@ add( + array( + "appname" => 'files_trashbin', + "script" => 'index.php', + "order" => 1, + "name" => $l->t('Deleted files') + ) +); diff --git a/apps/files_trashbin/index.php b/apps/files_trashbin/index.php index 16cd5ecd4c..59258a6cf1 100644 --- a/apps/files_trashbin/index.php +++ b/apps/files_trashbin/index.php @@ -3,45 +3,12 @@ // Check if we are a user OCP\User::checkLoggedIn(); -OCP\App::setActiveNavigationEntry('files_index'); - OCP\Util::addScript('files_trashbin', 'disableDefaultActions'); -OCP\Util::addScript('files', 'fileactions'); -$tmpl = new OCP\Template('files_trashbin', 'index', 'user'); -OCP\Util::addStyle('files', 'files'); +$tmpl = new OCP\Template('files_trashbin', 'index', ''); + OCP\Util::addStyle('files_trashbin', 'trash'); -OCP\Util::addScript('files', 'filesummary'); -OCP\Util::addScript('files', 'breadcrumb'); -OCP\Util::addScript('files', 'filelist'); -// filelist overrides OCP\Util::addScript('files_trashbin', 'filelist'); -OCP\Util::addscript('files', 'files'); OCP\Util::addScript('files_trashbin', 'trash'); -$dir = isset($_GET['dir']) ? stripslashes($_GET['dir']) : ''; - -$isIE8 = false; -preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches); -if (count($matches) > 0 && $matches[1] <= 8){ - $isIE8 = true; -} - -// if IE8 and "?dir=path" was specified, reformat the URL to use a hash like "#?dir=path" -if ($isIE8 && isset($_GET['dir'])){ - if ($dir === ''){ - $dir = '/'; - } - header('Location: ' . OCP\Util::linkTo('files_trashbin', 'index.php') . '#?dir=' . \OCP\Util::encodePath($dir)); - exit(); -} - -$tmpl->assign('dir', $dir); -$tmpl->assign('disableSharing', true); - -$nav = new OCP\Template('files', 'appnavigation', ''); -$nav->assign('trash', true); - -$tmpl->assign('appNavigation', $nav); - $tmpl->printPage(); diff --git a/apps/files_trashbin/templates/index.php b/apps/files_trashbin/templates/index.php index 02067385d4..e90162e4d5 100644 --- a/apps/files_trashbin/templates/index.php +++ b/apps/files_trashbin/templates/index.php @@ -1,6 +1,4 @@ -printPage(); ?> -
@@ -8,10 +6,6 @@ - - - - @@ -46,4 +40,3 @@
-
From fb10bf4048aaf5b2a9665fc9dff217c790efe005 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 8 May 2014 19:00:42 +0200 Subject: [PATCH 4/6] Files app navigation can now switch - added new OCA.Files namespace for files classes - the sidebar can now switch between views/containers - the trashbin renders in its own container but currently doesn't work due to overrides - added app.js as entry point for JS code (ideally all other files should only contain classes and not trigger anything) --- .jshintrc | 1 + apps/files/index.php | 4 +- apps/files/js/app.js | 25 ++++++++ apps/files/js/navigation.js | 81 ++++++++++++++++++++++++++ apps/files/templates/appnavigation.php | 4 +- apps/files/templates/index.php | 2 +- apps/files_trashbin/appinfo/app.php | 1 + apps/files_trashbin/index.php | 8 ++- core/js/js.js | 5 ++ 9 files changed, 124 insertions(+), 7 deletions(-) create mode 100644 apps/files/js/app.js create mode 100644 apps/files/js/navigation.js diff --git a/.jshintrc b/.jshintrc index 77f9e9f143..d5da3e3082 100644 --- a/.jshintrc +++ b/.jshintrc @@ -26,6 +26,7 @@ "fakeServer": true, "_": true, "OC": true, + "OCA": true, "t": true, "n": true } diff --git a/apps/files/index.php b/apps/files/index.php index ea57a548a2..07c828fffe 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -28,6 +28,7 @@ OCP\User::checkLoggedIn(); OCP\Util::addStyle('files', 'files'); OCP\Util::addStyle('files', 'upload'); OCP\Util::addStyle('files', 'mobile'); +OCP\Util::addscript('files', 'app'); OCP\Util::addscript('files', 'file-upload'); OCP\Util::addscript('files', 'jquery.iframe-transport'); OCP\Util::addscript('files', 'jquery.fileupload'); @@ -110,13 +111,14 @@ foreach ($navItems as $item) { $content = renderScript($item['appname'], $item['script']); } $contentItem = array(); - $contentItem['appname'] = $item['appname']; + $contentItem['id'] = $item['id']; $contentItem['content'] = $content; $contentItems[] = $contentItem; } OCP\Util::addscript('files', 'fileactions'); OCP\Util::addscript('files', 'files'); +OCP\Util::addscript('files', 'navigation'); OCP\Util::addscript('files', 'keyboardshortcuts'); $tmpl = new OCP\Template('files', 'index', 'user'); $tmpl->assign('dir', $dir); diff --git a/apps/files/js/app.js b/apps/files/js/app.js new file mode 100644 index 0000000000..87f7e2bb6b --- /dev/null +++ b/apps/files/js/app.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2014 + * + * @author Vincent Petry + * @copyright 2014 Vincent Petry + * + * This file is licensed under the Affero General Public License version 3 + * or later. + * + * See the COPYING-README file. + * + */ + +if (!OCA.Files) { + OCA.Files = {}; +} + +$(document).ready(function() { + var nav = new OCA.Files.Navigation($('#app-navigation ul')); + + nav.setSelectedItem('files'); + + // TODO: init file list, actions and others +}); + diff --git a/apps/files/js/navigation.js b/apps/files/js/navigation.js new file mode 100644 index 0000000000..f53abddd4d --- /dev/null +++ b/apps/files/js/navigation.js @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2014 + * + * @author Vincent Petry + * @copyright 2014 Vincent Petry + * + * This file is licensed under the Affero General Public License version 3 + * or later. + * + * See the COPYING-README file. + * + */ + +(function() { + + var Navigation = function($el) { + this.initialize($el); + }; + + Navigation.prototype = { + + /** + * Currently selected item in the list + */ + _selectedItem: null, + + /** + * Currently selected container + */ + $currentContent: null, + + /** + * Initializes the navigation from the given container + * @param $el element containing the navigation + */ + initialize: function($el) { + this.$el = $el; + this._selectedItem = null; + this.$currentContent = null; + this._setupEvents(); + }, + + /** + * Setup UI events + */ + _setupEvents: function() { + this.$el.on('click', 'li a', _.bind(this._onClickItem, this)); + }, + + /** + * Switch the currently selected item, mark it as selected and + * make the content container visible, if any. + * @param string itemId id of the navigation item to select + */ + setSelectedItem: function(itemId) { + if (itemId === this._selectedItem) { + return; + } + this._selectedItem = itemId; + this.$el.find('li').removeClass('selected'); + if (this.$currentContent) { + this.$currentContent.addClass('hidden'); + } + this.$currentContent = $('#app-content-' + itemId); + this.$currentContent.removeClass('hidden'); + this.$el.find('li[data-id=' + itemId + ']').addClass('selected'); + }, + + /** + * Event handler for when clicking on an item. + */ + _onClickItem: function(ev) { + var $target = $(ev.target); + var itemId = $target.closest('li').attr('data-id'); + this.setSelectedItem(itemId); + } + }; + + OCA.Files.Navigation = Navigation; + +})(); diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php index a2fffd4c4b..52e4284d3e 100644 --- a/apps/files/templates/appnavigation.php +++ b/apps/files/templates/appnavigation.php @@ -1,9 +1,9 @@
diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 335e2b2acd..e93e93140d 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -113,7 +113,7 @@
-