feature/issue177 #178
10
README.md
10
README.md
|
@ -47,6 +47,16 @@ 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 Custom Menu redirect to the first app in the top menu by changing the following parameter in your `config/config.php`:
|
||||
|
||||
```
|
||||
'defaultapp' => 'side_menu',
|
||||
```
|
||||
|
||||
If the top menu is empty then it redirects to files.
|
||||
|
||||
How to contribute?
|
||||
------------------
|
||||
|
||||
|
|
|
@ -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'],
|
||||
|
|
102
lib/Controller/AppController.php
Normal file
102
lib/Controller/AppController.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue