forked from deblan/side_menu
add feature: order categories
This commit is contained in:
parent
77e27bcc1a
commit
64da45e676
9 changed files with 250 additions and 48 deletions
|
|
@ -21,13 +21,11 @@ namespace OCA\SideMenu\Controller;
|
|||
use OC;
|
||||
use OC\App\AppStore\Fetcher\CategoryFetcher;
|
||||
use OC\URLGenerator;
|
||||
use OCA\SideMenu\AppInfo\Application;
|
||||
use OCA\SideMenu\Service\AppRepository;
|
||||
use OCA\SideMenu\Service\CategoryRepository;
|
||||
use OCA\SideMenu\Service\ConfigProxy;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserSession;
|
||||
use OCP\L10N\IFactory;
|
||||
|
|
@ -39,11 +37,6 @@ class NavController extends Controller
|
|||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var IConfig
|
||||
*/
|
||||
protected $iConfig;
|
||||
|
||||
/**
|
||||
* @var AppRepository
|
||||
*/
|
||||
|
|
@ -67,20 +60,17 @@ class NavController extends Controller
|
|||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
IConfig $iConfig,
|
||||
ConfigProxy $config,
|
||||
AppRepository $appRepository,
|
||||
CategoryFetcher $categoryFetcher,
|
||||
CategoryRepository $categoryRepository,
|
||||
URLGenerator $router,
|
||||
IL10N $trans,
|
||||
IFactory $l10nFactory
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
$this->config = $config;
|
||||
$this->iConfig = $iConfig;
|
||||
$this->appRepository = $appRepository;
|
||||
$this->categoryFetcher = $categoryFetcher;
|
||||
$this->categoryRepository = $categoryRepository;
|
||||
$this->l10nFactory = $l10nFactory;
|
||||
$this->router = $router;
|
||||
}
|
||||
|
|
@ -94,14 +84,7 @@ class NavController extends Controller
|
|||
*/
|
||||
public function items()
|
||||
{
|
||||
$apps = $this->appRepository->getVisibleApps();
|
||||
$currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
|
||||
$externalSitesInTopMenu = $this->config->getAppValueBool('external-sites-in-top-menu', '0');
|
||||
$hiddenApps = $this->config->getAppValueArray('big-menu-hidden-apps', '[]');
|
||||
$user = OC::$server[IUserSession::class]->getUser();
|
||||
$isForced = $this->config->getAppValueBool('force', '0');
|
||||
$appsCategories = [];
|
||||
$categoriesAppsCount = [];
|
||||
$items = [];
|
||||
|
||||
if (!$user) {
|
||||
|
|
@ -110,34 +93,19 @@ class NavController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
$categoriesLabels = $this->config->getAppValueArray('cache-categories', '[]');
|
||||
|
||||
if (empty($categoriesLabels)) {
|
||||
$categoriesLabels = $this->categoryFetcher->get();
|
||||
|
||||
$this->iConfig->setAppValue(Application::APP_ID, 'cache-categories', json_encode($categoriesLabels));
|
||||
}
|
||||
|
||||
$apps = $this->appRepository->getVisibleApps();
|
||||
$categoriesLabels = $this->categoryRepository->getOrderedCategories();
|
||||
$hiddenApps = $this->config->getAppValueArray('big-menu-hidden-apps', '[]');
|
||||
$isForced = $this->config->getAppValueBool('force', '0');
|
||||
$topMenuApps = $this->config->getAppValueArray('top-menu-apps', '[]');
|
||||
$userTopMenuApps = $this->config->getUserValueArray($user, 'top-menu-apps', '[]');
|
||||
$appsCategories = [];
|
||||
$categoriesAppsCount = [];
|
||||
|
||||
if (!$isForced && !empty($userTopMenuApps)) {
|
||||
$topMenuApps = $userTopMenuApps;
|
||||
}
|
||||
|
||||
foreach ($categoriesLabels as $k => $category) {
|
||||
$categoriesLabels[$category['id']] = $category['translations'][$currentLanguage]['name'] ?? $category['translations']['en']['name'];
|
||||
|
||||
unset($categoriesLabels[$k]);
|
||||
}
|
||||
|
||||
$categoriesLabels['external_links'] = $this->l10nFactory->get('external')->t('External sites');
|
||||
|
||||
$items['other'] = [
|
||||
'name' => '',
|
||||
'apps' => [],
|
||||
];
|
||||
|
||||
foreach ($apps as $app) {
|
||||
if (in_array($app['id'], $topMenuApps)) {
|
||||
continue;
|
||||
|
|
@ -158,6 +126,7 @@ class NavController extends Controller
|
|||
if (!isset($items[$category])) {
|
||||
$items[$category] = [
|
||||
'name' => $categoriesLabels[$category] ?? $category,
|
||||
'categoryId' => $category,
|
||||
'apps' => [],
|
||||
];
|
||||
}
|
||||
|
|
@ -216,8 +185,16 @@ class NavController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
usort($items, function ($a, $b) {
|
||||
return ($a['name'] < $b['name']) ? -1 : 1;
|
||||
usort($items, function ($a, $b) use ($categoriesLabels) {
|
||||
foreach ($categoriesLabels as $key => $value) {
|
||||
if ($a['categoryId'] === $key) {
|
||||
return -1;
|
||||
} elseif ($b['categoryId'] === $key) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
return new JSONResponse([
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue