update ui of the big menu, add 'files' app

This commit is contained in:
Simon Vieille 2020-08-11 13:34:36 +02:00
commit ce5c806524
Signed by: deblan
GPG key ID: 03383D15A1D31745
3 changed files with 88 additions and 47 deletions

View file

@ -95,6 +95,8 @@ class NavController extends Controller
$apps = $this->appRepository->getVisibleApps();
$currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
$categoriesLabels = $this->categoryFetcher->get();
$appsCategories = [];
$categoriesAppsCount = [];
$items = [];
foreach ($categoriesLabels as $k => $category) {
@ -104,7 +106,8 @@ class NavController extends Controller
}
foreach ($apps as $app) {
$categories = $app['category'];
$categories = (array) $app['category'];
$appsCategories[$app['id']] = [];
foreach ($categories as $category) {
if (!isset($items[$category])) {
@ -114,6 +117,14 @@ class NavController extends Controller
];
}
if (!isset($categoriesAppsCount[$category])) {
$categoriesAppsCount[$category] = 0;
}
++$categoriesAppsCount[$category];
$appsCategories[$app['id']][] = $category;
$items[$category]['apps'][$app['id']] = [
'name' => $app['name'],
'href' => $this->router->linkTo($app['id'], ''),
@ -122,23 +133,52 @@ class NavController extends Controller
}
}
arsort($categoriesAppsCount);
$keys = array_keys($categoriesAppsCount);
foreach ($appsCategories as $app => $appCategories) {
$smallerIndex = count($categoriesAppsCount) - 1;
foreach ($appCategories as $appCategory) {
$appKey = array_keys($keys, $appCategory)[0];
if ($appKey < $smallerIndex) {
$smallerIndex = $appKey;
}
}
$category = $keys[$smallerIndex];
foreach ($items as $itemCategory => $value) {
if ($itemCategory !== $category && isset($value['apps'][$app])) {
unset($items[$itemCategory]['apps'][$app]);
if (empty($items[$itemCategory]['apps'])) {
unset($items[$itemCategory]);
}
}
}
}
$items['other'] = [
'label' => $this->trans->t('Other'),
'apps' => [],
'name' => '',
'apps' => [
'files' => [
'name' => 'Files',
'href' => $this->router->linkTo('files', ''),
'icon' => '/apps/files/img/app.svg',
]
],
];
// 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]);
// }
// }
// }
foreach ($items as $category => $value) {
ksort($items[$category]['apps']);
}
usort($items, function($a, $b) {
return ($a['name'] < $b['name']) ? -1 : 1;
});
return new JSONResponse([
'items' => $items,