add base of the big menu

This commit is contained in:
Simon Vieille
2020-08-06 15:00:59 +02:00
parent ddb7cc40ce
commit 8e0be738a6
14 changed files with 324 additions and 7 deletions
+1
View File
@@ -70,6 +70,7 @@ class CssController extends Controller
'external-sites-in-top-menu' => (bool) $this->config->getAppValue('side_menu', 'external-sites-in-top-menu', 0),
'size-icon' => $this->config->getAppValue('side_menu', 'size-icon', 'normal'),
'size-text' => $this->config->getAppValue('side_menu', 'size-text', 'normal'),
'big-menu' => (bool) $this->config->getAppValue('side_menu', 'big-menu', '0'),
];
$response = new TemplateResponse('side_menu', 'css/stylesheet', $parameters, 'blank');
+1
View File
@@ -60,6 +60,7 @@ class JsController extends Controller
'force-light-icon' => (bool) $this->config->getAppValue('side_menu', 'force-light-icon', '0'),
'hide-when-no-apps' => (bool) $this->config->getAppValue('side_menu', 'hide-when-no-apps', '0'),
'loader-enabled' => (bool) $this->config->getAppValue('side_menu', 'loader-enabled', '1'),
'big-menu' => (bool) $this->config->getAppValue('side_menu', 'big-menu', '0'),
];
$response = new TemplateResponse('side_menu', 'js/script', $parameters, 'blank');
+139
View File
@@ -0,0 +1,139 @@
<?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 OCA\SideMenu\Service\AppRepository;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OC\App\AppStore\Fetcher\CategoryFetcher;
use OCP\L10N\IFactory;
class NavController extends Controller
{
/**
* @var \OCP\IConfig
*/
protected $config;
/**
* @var AppRepository
*/
protected $appRepository;
/**
* @var IL10N
*/
protected $trans;
/**
* @var IFactory
*/
protected $l10nFactory;
/**
* @var CategoryFetcher
*/
protected $categoryFetcher;
/**
* @param string $appName
*/
public function __construct(
$appName,
IRequest $request,
IConfig $config,
AppRepository $appRepository,
CategoryFetcher $categoryFetcher,
IFactory $l10nFactory,
IL10N $trans)
{
parent::__construct($appName, $request);
$this->config = $config;
$this->appRepository = $appRepository;
$this->categoryFetcher = $categoryFetcher;
$this->l10nFactory = $l10nFactory;
$this->trans = $trans;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @PublicPage
*
* @return JSONResponse
*/
public function items()
{
$apps = $this->appRepository->getVisibleApps();
$currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
$categoriesLabels = $this->categoryFetcher->get();
$items = [];
foreach ($categoriesLabels as $k => $category) {
$categoriesLabels[$category['id']] = $category['translations'][$currentLanguage]['name'] ?? $category['translations']['en']['name'];
unset($categoriesLabels[$k]);
}
foreach ($apps as $app) {
$categories = $app['category'];
foreach ($categories as $category) {
if (!isset($items[$category])) {
$items[$category] = [
'name' => $categoriesLabels[$category],
'apps' => [],
];
}
$items[$category]['apps'][$app['id']] = [
'name' => $app['name'],
'href' => '#',
'icon' => $app['previewAsIcon'] ? $app['preview'] : null,
];
}
}
$items['other'] = [
'label' => $this->trans->t('Other'),
'apps' => [],
];
// foreach ($items as $category => $value) {
// if ($category !== 'other') {
// if (count($value['apps']) < 0) {
// $items['other']['apps'] = array_merge(
// $items['other']['apps'],
// $value['apps']
// );
//
// unset($items[$category]);
// }
// }
// }
return new JSONResponse([
'items' => $items,
]);
}
}
+7 -1
View File
@@ -61,10 +61,16 @@ class PersonalSettingController extends Controller
if (!in_array($value, ['0', '1'])) {
$value = '1';
}
} elseif ($name === 'big-menu') {
$doSave = true;
if (!in_array($value, ['0', '1'])) {
$value = '0';
}
}
if ($doSave) {
$this->config->setUserValue($user->getUid(), 'side_menu', 'enabled', $value);
$this->config->setUserValue($user->getUid(), 'side_menu', $name, $value);
}
return [];
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace OCA\SideMenu\Service;
use \OC_App;
/**
* class AppRepository.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class AppRepository
{
/**
* @var OC_App
*/
protected $ocApp;
/**
* @param OC_App $ocApp
*/
public function __construct(OC_App $ocApp)
{
$this->ocApp = $ocApp;
}
/**
* Retrieves visibles apps.
*
* @return array
*/
public function getVisibleApps()
{
$navigation = $this->ocApp->getNavigation();
$apps = $this->ocApp->listAllApps();
$visibleApps = [];
foreach ($apps as $app) {
$id = $app['id'];
if (isset($navigation[$id])) {
$visibleApps[$id] = $app;
}
}
return $visibleApps;
}
}
+1
View File
@@ -66,6 +66,7 @@ class Admin implements ISettings
'force-light-icon' => $this->config->getAppValue('side_menu', 'force-light-icon', '0'),
'cache' => $this->config->getAppValue('side_menu', 'cache', '0'),
'opener' => $this->config->getAppValue('side_menu', 'opener', 'side-menu-opener'),
'big-menu' => $this->config->getAppValue('side_menu', 'big-menu', '0'),
'display-logo' => $this->config->getAppValue('side_menu', 'display-logo', '1'),
'opener-position' => $this->config->getAppValue('side_menu', 'opener-position', 'before'),
'opener-hover' => $this->config->getAppValue('side_menu', 'opener-hover', '0'),
+1
View File
@@ -64,6 +64,7 @@ class Personal implements ISettings
$parameters = [
'enabled' => $this->config->getUserValue($user->getUid(), 'side_menu', 'enabled', '1'),
'big-menu' => $this->config->getUserValue($user->getUid(), 'side_menu', 'big-menu', '0'),
];
return new TemplateResponse('side_menu', 'settings/personal-form', $parameters, '');