add possibility to define side_menu as default app and redirect to the first top menu app (#177)

This commit is contained in:
Simon Vieille 2022-11-20 14:00:26 +01:00
parent b474eeb29a
commit a4060c8db7
Signed by: deblan
GPG Key ID: 579388D585F70417
3 changed files with 111 additions and 0 deletions

View File

@ -47,6 +47,14 @@ Users can disable the menu using the page of personal settings.
Use the shortcut `Ctrl`+`o` to open and to hide the side menu. Use `tab` to navigate.
### Use first top menu app as default app
You can easily let Nextcloud redirect to the first top menu app by changing the following parameter in your `config/config.php`:
```
'defaultapp' => 'side_menu',
```
How to contribute?
------------------

View File

@ -19,6 +19,7 @@
return [
'routes' => [
['name' => 'App#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'Css#stylesheet', 'url' => '/css/stylesheet', 'verb' => 'GET'],
['name' => 'Js#script', 'url' => '/js/script', 'verb' => 'GET'],
['name' => 'Js#config', 'url' => '/js/config', 'verb' => 'GET'],

View File

@ -0,0 +1,102 @@
<?php
/**
* @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\SideMenu\Controller;
use OC;
use OCA\SideMenu\Service\AppRepository;
use OCA\SideMenu\Service\ConfigProxy;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
class AppController extends Controller
{
/**
* @var ConfigProxy
*/
protected $config;
/**
* @var AppRepository
*/
protected $appRepository;
public function __construct(
string $appName,
IRequest $request,
AppRepository $appRepository,
IURLGenerator $urlGenerator,
ConfigProxy $config
) {
parent::__construct($appName, $request);
$this->appRepository = $appRepository;
$this->urlGenerator = $urlGenerator;
$this->config = $config;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function index(): RedirectResponse
{
$user = OC::$server[IUserSession::class]->getUser();
$topMenuApps = $this->config->getAppValueArray('top-menu-apps', '[]');
$hiddenApps = $this->config->getAppValueArray('big-menu-hidden-apps', '[]');
$isForced = $this->config->getAppValueBool('force', '0');
$userTopMenuApps = $this->config->getUserValueArray($user, 'top-menu-apps', '[]');
$apps = $this->appRepository->getOrderedApps($user);
if (!$isForced && !empty($userTopMenuApps)) {
$topMenuApps = $userTopMenuApps;
}
foreach ($apps as $app) {
$inTopMenuApps = in_array($app['id'], $topMenuApps);
$inHiddenApps = in_array($app['id'], $hiddenApps);
if (!$inTopMenuApps || $inHiddenApps) {
continue;
}
return $this->redirectToApp($app['id']);
}
return $this->redirectToApp('files');
}
protected function redirectToApp($appId): RedirectResponse
{
$isIgnoreFrontController = true === OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false);
$isFrontControllerActive = 'true' === getenv('front_controller_active');
if ($isIgnoreFrontController || $isFrontControllerActive) {
$path = '/apps/%s/';
} else {
$path = '/index.php/apps/%s/';
}
$url = $this->urlGenerator->getAbsoluteURL(sprintf($path, $appId));
return new RedirectResponse($url);
}
}