diff options
author | Julius Härtl <github@jus.li> | 2017-05-17 13:47:23 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-17 13:47:23 +0300 |
commit | a3c7860e659c62a6d1409b40cc6608c621cfbd06 (patch) | |
tree | 57e20d75aab4d401bbab381c1820bf04d78dc702 | |
parent | afd1017a41de6e2b0a70e1b3811aedb697fdaa4e (diff) | |
parent | a993164d831fa263acd54f6529ece4bc5d4107a4 (diff) |
Merge pull request #31 from juliushaertl/nc12
Add basic support for Nextcloud 12
-rw-r--r-- | .travis.yml | 11 | ||||
-rw-r--r-- | appinfo/app.php | 2 | ||||
-rw-r--r-- | appinfo/info.xml | 7 | ||||
-rw-r--r-- | controller/settingscontroller.php | 15 | ||||
-rw-r--r-- | js/apporder.js | 62 | ||||
-rw-r--r-- | personal.php | 27 | ||||
-rw-r--r-- | templates/admin.php | 2 | ||||
-rw-r--r-- | tests/bootstrap.php | 6 | ||||
-rw-r--r-- | tests/unit/controller/SettingsControllerTest.php | 30 |
9 files changed, 111 insertions, 51 deletions
diff --git a/.travis.yml b/.travis.yml index 9241747..95a432d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,16 +7,17 @@ env: global: - DB=sqlite matrix: - - CORE_BRANCH=stable9.1 REPO=owncloud/core - - CORE_BRANCH=master REPO=owncloud/core - - CORE_BRANCH=stable10 REPO=nextcloud/server - CORE_BRANCH=master REPO=nextcloud/server matrix: fast_finish: true before_install: - # install core + - wget https://phar.phpunit.de/phpunit-5.7.phar + - chmod +x phpunit-5.7.phar + - mkdir bin + - mv phpunit-5.7.phar bin/phpunit + - phpunit --version - cd ../ - git clone https://github.com/$REPO.git --recursive --depth 1 -b $CORE_BRANCH mainrepo - mv apporder mainrepo/apps/ @@ -30,6 +31,8 @@ before_script: - ./occ app:check-code apporder - php -S localhost:8080 & - cd apps/apporder + - export PATH="$PWD/bin:$PATH" + script: - make test diff --git a/appinfo/app.php b/appinfo/app.php index acff6b3..786773a 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -24,3 +24,5 @@ \OCP\Util::addStyle('apporder', 'apporder'); \OCP\Util::addScript('apporder', 'apporder'); \OCP\App::registerAdmin('apporder', 'admin'); +\OCP\App::registerPersonal('apporder', 'personal'); + diff --git a/appinfo/info.xml b/appinfo/info.xml index 6c8b28b..245beba 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -5,7 +5,7 @@ <name>AppOrder</name> <summary>Sort apps in the menu with drag and drop</summary> <description> -Enable sorting for icons inside the app menu. The order will be saved for each +Enable sorting the app icons from the personal settings. The order will be saved for each user individually. Administrators can define a custom default order. AppOrder works with the default owncloud menu as well as with the direct_menu app. @@ -25,12 +25,11 @@ Users will now get redirected to the first app of the default order or to the first app of the user order. </description> <category>customization</category> - <version>0.3.3</version> + <version>0.4.0</version> <licence>agpl</licence> <author mail="jus@bitgrid.net">Julius Härtl</author> <dependencies> - <owncloud min-version="9.0" max-version="9.2" /> - <nextcloud min-version="9" max-version="11" /> + <nextcloud min-version="12" max-version="12" /> </dependencies> <namespace>AppOrder</namespace> <repository type="git">https://github.com/juliushaertl/apporder.git</repository> diff --git a/controller/settingscontroller.php b/controller/settingscontroller.php index 1a65ea7..2bfb59a 100644 --- a/controller/settingscontroller.php +++ b/controller/settingscontroller.php @@ -59,7 +59,20 @@ class SettingsController extends Controller { return new TemplateResponse( $this->appName, 'admin', - ["nav" => $nav], + ["nav" => $nav, 'type' => 'admin'], + 'blank' + ); + } + + public function personalIndex() { + // Private API call + $navigation = $this->navigationManager->getAll(); + $order = json_decode($this->appConfig->getUserValue('order', $this->userId)); + $nav = $this->util->matchOrder($navigation, $order); + return new TemplateResponse( + $this->appName, + 'admin', + ["nav" => $nav, 'type' => 'personal'], 'blank' ); } diff --git a/js/apporder.js b/js/apporder.js index 90dfba8..23e7ec5 100644 --- a/js/apporder.js +++ b/js/apporder.js @@ -1,52 +1,38 @@ $(function () { - var app_menu = $('#apps ul'); + var app_menu = $('#appmenu'); if (!app_menu.length) return; app_menu.hide(); + var mapMenu = function(parent, order) { + available_apps = {}; + parent.find('li').each(function () { + var id = $(this).find('a').attr('href'); + available_apps[id] = $(this); + }); + $.each(order, function (order, value) { + parent.prepend(available_apps[value]); + }); + }; + // restore existing order $.get(OC.generateUrl('/apps/apporder/getOrder'), function (data) { var json = data.order; - var order = [] + var order = []; try { - var order = JSON.parse(json).reverse(); + order = JSON.parse(json).reverse(); } catch (e) { order = []; } if (order.length === 0) { - $('#apps ul').show(); + app_menu.show(); return; } - available_apps = {}; - app_menu.find('li').each(function () { - var id = $(this).find('a').attr('href'); - available_apps[id] = $(this); - }); - $.each(order, function (order, value) { - app_menu.prepend(available_apps[value]); - }); - $('#apps ul').show(); - }); - - // make app menu sortable - $("#apps ul").sortable({ - handle: 'a', - stop: function (event, ui) { - var items = []; - $("#apps ul").children().each(function (i, el) { - var item = $(el).find('a').attr('href'); - items.push(item); - }); - - var json = JSON.stringify(items); - $.post(OC.generateUrl('/apps/apporder/savePersonal'), { - order: json, - }, function (data) { - $(event.srcElement).fadeTo('fast', 0.5).fadeTo('fast', 1.0); - }); - } + mapMenu($('#appmenu'), order); + mapMenu($('#apps').find('ul'), order); + app_menu.show(); }); // Sorting inside settings @@ -55,13 +41,21 @@ $(function () { placeholder: 'placeholder', stop: function (event, ui) { var items = []; + var url; + var type = $('#appsorter').data('type'); + console.log(type); + if(type === 'admin') { + url = OC.generateUrl('/apps/apporder/saveDefaultOrder'); + } else { + url = OC.generateUrl('/apps/apporder/savePersonal'); + } $("#appsorter").children().each(function (i, el) { var item = $(el).find('a').attr('href'); items.push(item) }); var json = JSON.stringify(items); - $.post(OC.generateUrl('/apps/apporder/saveDefaultOrder'), { - order: json, + $.post(url, { + order: json }, function (data) { $(event.srcElement).effect("highlight", {}, 1000); }); diff --git a/personal.php b/personal.php new file mode 100644 index 0000000..0ff3ca6 --- /dev/null +++ b/personal.php @@ -0,0 +1,27 @@ +<?php +/** + * @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @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\AppOrder; + +$response = \OC::$server->query('\OCA\AppOrder\Controller\SettingsController')->personalIndex(); +return $response->render(); diff --git a/templates/admin.php b/templates/admin.php index 101e09e..8709ba8 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -2,7 +2,7 @@ <h2><?php p($l->t('App Order')) ?></h2> <p><?php p($l->t('Set a default order for all users. This will be ignored, if the user has setup a custom order.')) ?></p> <p><em><?php p($l->t('Drag the app icons to change their order.')); ?></em></p> - <ul id="appsorter"> + <ul id="appsorter" data-type="<?php p($_['type']); ?>"> <?php foreach($_['nav'] as $entry) { ?> <li> <img class="app-icon svg" alt="" src="<?php print_unescaped($entry['icon']); ?>"> diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9e67e95..a2d39b0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -23,12 +23,6 @@ require_once __DIR__.'/../../../tests/bootstrap.php'; - -require_once __DIR__.'/../../../lib/base.php'; -if (!class_exists('PHPUnit_Framework_TestCase')) { - require_once('PHPUnit/Autoload.php'); -} - \OC_App::loadApp('apporder'); OC_Hook::clear(); diff --git a/tests/unit/controller/SettingsControllerTest.php b/tests/unit/controller/SettingsControllerTest.php index 400e35c..387f9bf 100644 --- a/tests/unit/controller/SettingsControllerTest.php +++ b/tests/unit/controller/SettingsControllerTest.php @@ -102,7 +102,35 @@ class SettingsControllerTest extends \PHPUnit_Framework_TestCase { $expected = new \OCP\AppFramework\Http\TemplateResponse( $this->appName, 'admin', - ["nav" => $nav_final], + ["nav" => $nav_final, 'type' => 'admin'], + 'blank' + ); + $this->assertEquals($expected, $result); + } + + public function testPersonalIndex() { + $nav_custom = ['/app/calendar/', '/app/tasks/']; + $nav_oc = [ + ['href' => '/app/files/', 'name' => 'Files'], + ['href' => '/app/calendar/', 'name' => 'Calendar'], + ['href' => '/app/tasks/', 'name' => 'Tasks'], + ]; + $nav_final = [ + '/app/calendar/' => $nav_oc[1], '/app/tasks/' => $nav_oc[2], '/app/files/' => $nav_oc[0] + ]; + $this->service->expects($this->once()) + ->method('getUserValue') + ->with('order', 'admin') + ->will($this->returnValue(json_encode($nav_custom))); + $this->navigationManager->expects($this->once()) + ->method('getAll') + ->will($this->returnValue($nav_oc)); + + $result = $this->controller->personalIndex(); + $expected = new \OCP\AppFramework\Http\TemplateResponse( + $this->appName, + 'admin', + ["nav" => $nav_final, 'type' => 'personal'], 'blank' ); $this->assertEquals($expected, $result); |