mirror of
https://gitnet.fr/deblan/side_menu.git
synced 2025-12-18 05:10:50 +01:00
fix #349: add custom controller to retrieve core apps
This commit is contained in:
parent
f58dedf553
commit
cd4b3b1054
3 changed files with 81 additions and 7 deletions
74
lib/Controller/CoreController.php
Normal file
74
lib/Controller/CoreController.php
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<?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 OCA\SideMenu\Service\ConfigProxy;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
|
||||
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
|
||||
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
|
||||
use OCP\AppFramework\Http\Attribute\PublicPage;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserSession;
|
||||
|
||||
class CoreController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
protected ConfigProxy $config,
|
||||
protected AppRepository $appRepository,
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
}
|
||||
|
||||
#[NoCSRFRequired]
|
||||
#[NoAdminRequired]
|
||||
#[PublicPage]
|
||||
#[FrontpageRoute(verb: 'GET', url: '/core/apps')]
|
||||
public function items(): JSONResponse
|
||||
{
|
||||
$user = \OC::$server[IUserSession::class]->getUser();
|
||||
$items = [];
|
||||
|
||||
if (!$user) {
|
||||
return new JSONResponse([
|
||||
'items' => $items,
|
||||
]);
|
||||
}
|
||||
|
||||
$apps = $this->appRepository->getOrderedApps($user);
|
||||
$keys = ['id', 'name', 'category', 'href', 'icon'];
|
||||
|
||||
foreach ($apps as &$app) {
|
||||
foreach ($app as $key => $value) {
|
||||
if (!in_array($key, $keys)) {
|
||||
unset($app[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new JSONResponse([
|
||||
'items' => $apps,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
:data-app-id="app.id"
|
||||
class="app-menu-entry"
|
||||
:class="{
|
||||
'app-menu-entry__active': app.active,
|
||||
'app-menu-entry__active': app.id === activeApp,
|
||||
'app-menu-entry__hidden-label': hiddenLabels === 1,
|
||||
'app-menu-main__show-hovered': hiddenLabels === 2,
|
||||
}"
|
||||
|
|
@ -44,7 +44,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
:class="{ 'has-unread': app.unread > 0 }"
|
||||
:aria-label="app.name"
|
||||
:target="targetBlankApps.indexOf(app.id) !== -1 ? '_blank' : undefined"
|
||||
:aria-current="app.active ? 'page' : false"
|
||||
:aria-current="app.id === activeApp ? 'page' : false"
|
||||
>
|
||||
<img
|
||||
:src="app.icon"
|
||||
|
|
@ -69,7 +69,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
v-for="app in popoverAppList"
|
||||
:key="app.id"
|
||||
:aria-label="app.name"
|
||||
:aria-current="app.active ? 'page' : false"
|
||||
:aria-current="app.id === activeApp ? 'page' : false"
|
||||
:href="app.href"
|
||||
:style="makeStyle(app)"
|
||||
class="cm-standardmenu-app-menu-popover-entry app-menu-popover-entry"
|
||||
|
|
@ -101,6 +101,7 @@ import { ref, onMounted } from 'vue'
|
|||
import { useConfigStore } from '../store/config.js'
|
||||
import { useNavStore } from '../store/nav.js'
|
||||
import { NcActions, NcActionLink } from '@nextcloud/vue'
|
||||
import { getActiveAppId } from '../lib/app.js'
|
||||
|
||||
const navStore = useNavStore()
|
||||
const configStore = useConfigStore()
|
||||
|
|
@ -112,6 +113,7 @@ const topMenuApps = ref([])
|
|||
const appsOrder = ref([])
|
||||
const mainAppList = ref([])
|
||||
const popoverAppList = ref([])
|
||||
const activeApp = ref(null)
|
||||
let resizeTimeout = null
|
||||
|
||||
const setApps = (value) => {
|
||||
|
|
@ -170,6 +172,7 @@ onMounted(async () => {
|
|||
hiddenLabels.value = config['top-menu-mouse-over-hidden-label']
|
||||
topMenuApps.value = config['top-menu-apps']
|
||||
appsOrder.value = config['apps-order']
|
||||
activeApp.value = getActiveAppId()
|
||||
ready.value = true
|
||||
|
||||
setApps(await navStore.getCoreApps())
|
||||
|
|
|
|||
|
|
@ -41,10 +41,7 @@ export const useNavStore = defineStore('nav', () => {
|
|||
|
||||
async function getCoreApps() {
|
||||
if (coreApps == null) {
|
||||
coreApps = await axios
|
||||
.get(generateOcsUrl('core/navigation', 2) + '/apps?format=json')
|
||||
.then((response) => response.data)
|
||||
.then((value) => value.ocs.data)
|
||||
coreApps = await await axios.get(generateUrl('/apps/side_menu/core/apps')).then((response) => response.data.items)
|
||||
}
|
||||
|
||||
return coreApps
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue