Switch to Vue-Router HTML5 routing mode so URLs match existing ones.

This commit is contained in:
Buster Neece 2023-08-12 10:52:41 -05:00
parent 6fde92db89
commit 01a80bcdcb
No known key found for this signature in database
14 changed files with 129 additions and 29 deletions

46
config/routes/admin.php Normal file
View File

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
use App\Controller\Admin\IndexAction;
use App\Enums\GlobalPermissions;
use App\Middleware;
use Slim\Routing\RouteCollectorProxy;
return static function (RouteCollectorProxy $app) {
$app->group(
'/admin',
function (RouteCollectorProxy $group) {
$routes = [
'admin:index:index' => '',
'admin:debug:index' => '/debug',
'admin:install_shoutcast:index' => '/install/shoutcast',
'admin:install_stereo_tool:index' => '/install/stereo_tool',
'admin:install_geolite:index' => '/install/geolite',
'admin:auditlog:index' => '/auditlog',
'admin:api:index' => '/api-keys',
'admin:backups:index' => '/backups',
'admin:branding:index' => '/branding',
'admin:custom_fields:index' => '/custom_fields',
'admin:logs:index' => '/logs',
'admin:permissions:index' => '/permissions',
'admin:relays:index' => '/relays',
'admin:settings:index' => '/settings',
'admin:stations:index' => '/stations',
'admin:storage_locations:index' => '/storage_locations',
'admin:updates:index' => '/updates',
'admin:users:index' => '/users',
];
foreach ($routes as $routeName => $routePath) {
$group->get($routePath, IndexAction::class)
->setName($routeName);
}
$group->get('/{routes:.+}', IndexAction::class);
}
)->add(Middleware\Module\PanelLayout::class)
->add(Middleware\EnableView::class)
->add(new Middleware\Permissions(GlobalPermissions::View))
->add(Middleware\RequireLogin::class);
};

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
use App\Controller;
use App\Enums\GlobalPermissions;
use App\Enums\StationPermissions;
use App\Middleware;
use Slim\Routing\RouteCollectorProxy;
@ -76,21 +75,7 @@ return static function (RouteCollectorProxy $app) {
}
)->add(Middleware\EnableView::class);
$app->get('/admin', Controller\Admin\IndexAction::class)
->setName('admin:index:index')
->add(Middleware\Module\PanelLayout::class)
->add(Middleware\EnableView::class)
->add(new Middleware\Permissions(GlobalPermissions::View))
->add(Middleware\RequireLogin::class);
call_user_func(include(__DIR__ . '/admin.php'), $app);
$app->get(
'/station/{station_id}',
Controller\Stations\IndexAction::class
)->setName('stations:index:index')
->add(Middleware\Module\PanelLayout::class)
->add(new Middleware\Permissions(StationPermissions::View, true))
->add(Middleware\EnableView::class)
->add(Middleware\RequireStation::class)
->add(Middleware\GetStation::class)
->add(Middleware\RequireLogin::class);
call_user_func(include(__DIR__ . '/stations.php'), $app);
};

View File

@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
use App\Controller\Stations\IndexAction;
use App\Enums\StationPermissions;
use App\Middleware;
use Slim\Routing\RouteCollectorProxy;
return static function (RouteCollectorProxy $app) {
$app->group(
'/station/{station_id}',
function (RouteCollectorProxy $group) {
$routes = [
'stations:index:index' => '',
'stations:branding' => '/branding',
'stations:bulk-media' => '/bulk-media',
'stations:fallback' => '/fallback',
'stations:files:index' => '/files[/{fspath}]',
'stations:hls_streams:index' => '/hls_streams',
'stations:util:ls_config' => '/ls_config',
'stations:stereo_tool_config' => '/stereo_tool_config',
'stations:logs' => '/logs',
'stations:playlists:index' => '/playlists',
'stations:podcasts:index' => '/podcasts',
'stations:mounts:index' => '/mounts',
'stations:profile:index' => '/profile',
'stations:profile:edit' => '/profile/edit',
'stations:queue:index' => '/queue',
'stations:remotes:index' => '/remotes',
'stations:reports:overview' => '/reports/overview',
'stations:reports:timeline' => '/reports/timeline',
'stations:reports:listeners' => '/reports/listeners',
'stations:reports:soundexchange' => '/reports/soundexchange',
'stations:reports:requests' => '/reports/requests',
'stations:restart:index' => '/restart',
'stations:sftp_users:index' => '/sftp_users',
'stations:streamers:index' => '/streamers',
'stations:webhooks:index' => '/webhooks',
];
foreach ($routes as $routeName => $routePath) {
$group->get($routePath, IndexAction::class)
->setName($routeName);
}
$group->get('/{routes:.+}', IndexAction::class);
}
)->add(Middleware\Module\PanelLayout::class)
->add(new Middleware\Permissions(StationPermissions::View, true))
->add(Middleware\EnableView::class)
->add(Middleware\RequireStation::class)
->add(Middleware\GetStation::class)
->add(Middleware\RequireLogin::class);
};

View File

@ -1,9 +1,10 @@
import initApp from "~/layout";
import {h} from "vue";
import {createRouter, createWebHashHistory} from "vue-router";
import {createRouter, createWebHistory} from "vue-router";
import AdminLayout from "~/components/Admin/AdminLayout.vue";
import useAdminRoutes from "~/components/Admin/routes";
import installRouterLoading from "~/functions/installRouterLoading";
import {useAzuraCast} from "~/vendor/azuracast";
initApp({
render() {
@ -12,8 +13,10 @@ initApp({
}, async (vueApp) => {
const routes = useAdminRoutes();
const {componentProps} = useAzuraCast();
const router = createRouter({
history: createWebHashHistory(),
history: createWebHistory(componentProps.baseUrl),
routes
});

View File

@ -1,9 +1,10 @@
import initApp from "~/layout";
import {h} from "vue";
import {createRouter, createWebHashHistory} from "vue-router";
import {createRouter, createWebHistory} from "vue-router";
import StationsLayout from "~/components/Stations/StationsLayout.vue";
import useStationsRoutes from "~/components/Stations/routes";
import installRouterLoading from "~/functions/installRouterLoading";
import {useAzuraCast} from "~/vendor/azuracast";
initApp({
render() {
@ -12,8 +13,10 @@ initApp({
}, (vueApp) => {
const routes = useStationsRoutes();
const {componentProps} = useAzuraCast();
const router = createRouter({
history: createWebHashHistory(),
history: createWebHistory(componentProps.baseUrl),
routes
});

View File

@ -21,6 +21,9 @@ final class IndexAction implements SingleActionInterface
component: 'Admin',
id: 'admin-index',
title: __('Administration'),
props: [
'baseUrl' => $request->getRouter()->named('admin:index:index'),
]
);
}
}

View File

@ -61,9 +61,9 @@ final class StationsAction implements SingleActionInterface
if ($listenersEnabled && $acl->isAllowed(StationPermissions::Reports, $station->getId())) {
$row->links['listeners'] = $router->named(
'stations:index:index',
'stations:reports:listeners',
['station_id' => $station->getId()]
) . '#/reports/listeners';
);
}
$viewStations[] = $row;

View File

@ -21,6 +21,6 @@ final class EndMasqueradeAction implements SingleActionInterface
$router = $request->getRouter();
return $response->withRedirect($router->named('admin:index:index') . '#/users');
return $response->withRedirect($router->named('admin:users:index'));
}
}

View File

@ -41,7 +41,7 @@ final class DashboardAction implements SingleActionInterface
'notificationsUrl' => $router->named('api:frontend:dashboard:notifications'),
'showCharts' => $showCharts,
'chartsUrl' => $router->named('api:frontend:dashboard:charts'),
'manageStationsUrl' => $router->named('admin:index:index') . '#/stations',
'manageStationsUrl' => $router->named('admin:stations:index'),
'stationsUrl' => $router->named('api:frontend:dashboard:stations'),
'showAlbumArt' => !$settings->getHideAlbumArt(),
]

View File

@ -67,6 +67,11 @@ final class IndexAction implements SingleActionInterface
component: 'Stations',
id: 'stations-index',
title: $station->getName(),
props: [
'baseUrl' => $router->named('stations:index:index', [
'station_id' => $station->getIdRequired(),
]),
]
);
}
}

View File

@ -56,7 +56,7 @@ final class BaseUrlCheck
$notification->body = implode(' ', $notificationBodyParts);
$notification->type = FlashLevels::Warning->value;
$notification->actionLabel = __('System Settings');
$notification->actionUrl = $router->named('admin:index:index') . '#/settings';
$notification->actionUrl = $router->named('admin:settings:index');
$event->addNotification($notification);
}

View File

@ -50,7 +50,7 @@ final class RecentBackupCheck
$router = $request->getRouter();
$notification->actionLabel = __('Backups');
$notification->actionUrl = $router->named('admin:index:index') . '#/backups';
$notification->actionUrl = $router->named('admin:backups:index');
$event->addNotification($notification);
}

View File

@ -57,7 +57,7 @@ final class SyncTaskCheck
$router = $request->getRouter();
$notification->actionLabel = __('System Debugger');
$notification->actionUrl = $router->named('admin:index:index') . '#/debug';
$notification->actionUrl = $router->named('admin:debug:index');
// phpcs:enable
$event->addNotification($notification);

View File

@ -42,7 +42,7 @@ final class UpdateCheck
$router = $event->getRequest()->getRouter();
$actionLabel = __('Update AzuraCast');
$actionUrl = $router->named('admin:index:index') . '#/updates';
$actionUrl = $router->named('admin:updates:index');
$releaseChannel = $this->version->getReleaseChannelEnum();