Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

[WIP] Redirect to first app in list after login #16

Merged
merged 5 commits into from
Sep 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ env:
global:
- DB=sqlite
matrix:
- CORE_BRANCH=stable9 REPO=owncloud/core
- CORE_BRANCH=stable9.1 REPO=owncloud/core
- CORE_BRANCH=master REPO=owncloud/core
- CORE_BRANCH=stable9 REPO=nextcloud/server
- CORE_BRANCH=stable10 REPO=nextcloud/server
- CORE_BRANCH=master REPO=nextcloud/server

matrix:
Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,24 @@ app.

![AppOrder in Action](https://bitgrid.net/~jus/apporder.gif)

**This app is still work in progress.**

## Set a default order for all new users

Go to the Admin settings > Additional settings and drag the icons under App order.

## Use first app as default app

You can easily let Nextcloud redirect your user to the first app in their
personal order by changing the following parameter in your config/config.php:

'defaultapp' => 'apporder',

Users will now get redirected to the first app of the default order or to the
first app of the user order.

# Installation

## From git

1. Clone the app into your apps/ directory: `git clone https://github.com/juliushaertl/apporder.git`
2. Enable it
7 changes: 0 additions & 7 deletions appinfo/app.php

This file was deleted.

21 changes: 0 additions & 21 deletions appinfo/application.php

This file was deleted.

29 changes: 17 additions & 12 deletions appinfo/autoload.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<?php
/**
* ownCloud - foobar
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
* @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/>.
*
* @author jus <jus@bitgrid.net>
* @copyright jus 2016
*/

namespace OCA\AppOrder\AppInfo;
use OCA\AppOrder\AppInfo\Application;

use OCP\AppFramework\App;

/**
* Additional autoloader registration, e.g. registering composer autoloaders
*/
// require_once __DIR__ . '/../vendor/autoload.php';
1 change: 1 addition & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<dependencies>
<owncloud min-version="9.0" max-version="9.2" />
</dependencies>
<namespace>AppOrder</namespace>
<repository type="git">https://github.com/juliushaertl/apporder.git</repository>
<ocsid>174715</ocsid>
</info>
Expand Down
7 changes: 3 additions & 4 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

namespace OCA\AppOrder;
$app = new AppInfo\Application();
$app->registerRoutes($this, [
return [
'routes' => [
['name' => 'app#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'settings#getOrder', 'url' => 'ajax/order.php', 'verb' => 'GET'],
['name' => 'settings#savePersonal', 'url' => 'ajax/personal.php', 'verb' => 'GET'],
['name' => 'settings#saveDefaultOrder', 'url' => 'ajax/admin.php', 'verb' => 'GET'],
]
]);
];
45 changes: 45 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* @copyright Copyright (c) 2016 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\AppInfo;

use \OCP\AppFramework\App;
use \OCA\AppOrder\Service\ConfigService;

class Application extends App {

public function __construct(array $urlParams = array()) {
parent::__construct('apporder', $urlParams);
$container = $this->getContainer();
$container->registerService('ConfigService', function($c) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw should also work without this

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice, thanks. 👍

return new ConfigService(
$c->query('Config'),
$c->query('AppName')
);
});

\OCP\Util::addStyle('apporder', 'apporder');
\OCP\Util::addScript('apporder', 'apporder');
\OCP\App::registerAdmin('apporder', 'admin');
}
}
68 changes: 68 additions & 0 deletions lib/Controller/AppController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* @copyright Copyright (c) 2016 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\Controller;

use \OCP\AppFramework\Controller;
use OCP\AppFramework\Http\RedirectResponse;
use \OCP\IRequest;
use \OCP\INavigationManager;
use \OCA\AppOrder\Service\ConfigService;
use OCA\AppOrder\Util;
use OCP\IURLGenerator;

class AppController extends Controller {

private $userId;
private $appConfig;
private $urlGenerator;
private $util;

public function __construct($appName, IRequest $request, ConfigService $appConfig, IURLGenerator $urlGenerator, Util $util, $userId) {
parent::__construct($appName, $request);
$this->userId = $userId;
$this->appConfig = $appConfig;
$this->urlGenerator = $urlGenerator;
$this->util = $util;
}

/**
* @NoCSRFRequired
* @return RedirectResponse
*/
public function index() {
$order = json_decode($this->util->getAppOrder());
if($order !== null && sizeof($order)>0) {
$firstPage = $order[0];
} else {
$appId = 'files';
if(getenv('front_controller_active') === 'true') {
$firstPage = $this->urlGenerator->getAbsoluteURL('/apps/' . $appId . '/');
} else {
$firstPage = $this->urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/');
}
}
return new RedirectResponse($firstPage);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,33 @@
use \OCP\IRequest;
use \OCP\INavigationManager;
use \OCA\AppOrder\Service\ConfigService;
use \OCA\AppOrder\Util;

class SettingsController extends Controller {

private $userId;
private $l10n;
private $appConfig;
private $navigationManager;
private $util;

public function __construct($appName, IRequest $request, ConfigService $appConfig, INavigationManager $navigationManager, $userId) {
public function __construct($appName, IRequest $request, ConfigService $appConfig, INavigationManager $urlGenerator, Util $util, $userId) {
parent::__construct($appName, $request);
$this->userId = $userId;
$this->appConfig = $appConfig;
$this->navigationManager = $navigationManager;
$this->navigationManager = $urlGenerator;
$this->util = $util;
}

/**
* Admin: render admin page
* FIXME: Move to dedicated class
* @return TemplateResponse
*/
public function adminIndex() {
// Private API call
$navigation = $this->navigationManager->getAll();
$order = json_decode($this->appConfig->getAppValue('order'));
$nav = $this->matchOrder($navigation, $order);
$nav = $this->util->matchOrder($navigation, $order);
return new TemplateResponse(
$this->appName,
'admin',
Expand All @@ -34,41 +42,31 @@ public function adminIndex() {
);
}

public function getAppOrder() {
$order_user = $this->appConfig->getUserValue('order', $this->userId);
$order_default = $this->appConfig->getAppValue('order');
if ($order_user !== null && $order_user !== "")
$order = $order_user;
else
$order = $order_default;
return $order;
}

public function matchOrder($nav, $order) {
$nav_tmp = array();
$result = array();
foreach ($nav as $app)
$nav_tmp[$app['href']] = $app;
foreach ($order as $app)
if(array_key_exists($app, $nav_tmp))
$result[$app] = $nav_tmp[$app];
foreach ($nav as $app)
if (!array_key_exists($app['href'], $result))
$result[$app['href']] = $app;
return $result;
}
/**
* Admin: save default order
* @param $order
* @return array
*/
public function saveDefaultOrder($order) {
if (!is_null($order)) {
$this->appConfig->setAppValue('order', $order);
}
return array('status' => 'success', 'order' => $order);
}

/**
* @NoAdminRequired
*/
public function getOrder() {
$order = $this->getAppOrder();
$order = $this->util->getAppOrder();
return array('status' => 'success', 'order' => $order);
}

/**
* @NoAdminRequired
*/
/**
* @NoAdminRequired
* @param $order string
* @return array response
*/
public function savePersonal($order) {
$this->appConfig->setUserValue('order', $this->userId, $order);
$response = array(
Expand All @@ -79,10 +77,5 @@ public function savePersonal($order) {
return $response;
}

public function saveDefaultOrder($order) {
if (!is_null($order)) {
$this->appConfig->setAppValue('order', $order);
}
return array('status' => 'success', 'order' => $order);
}

}
File renamed without changes.
Loading