feat core
resources
build-files
: Create the server navigation router, change minor things in blade wrappers and start working on inserting routes in core.
This commit is contained in:
parent
71a331f280
commit
d3fc7dc4c8
7 changed files with 117 additions and 52 deletions
12
blueprint.sh
12
blueprint.sh
|
@ -705,7 +705,7 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) ]]; then VCMD="y"
|
|||
|
||||
# Route identifier
|
||||
COMPONENTS_ROUTE_IDEN=$(tr -dc '[:lower:]' < /dev/urandom | fold -w 10 | head -n 1)
|
||||
COMPONENTS_ROUTE_IDEN="${COMPONENTS_ROUTE_IDEN^}"
|
||||
COMPONENTS_ROUTE_IDEN="${identifier^}${COMPONENTS_ROUTE_IDEN^}"
|
||||
|
||||
echo -e "NAME: $COMPONENTS_ROUTE_NAME\nPATH: $COMPONENTS_ROUTE_PATH\nTYPE: $COMPONENTS_ROUTE_TYPE\nCOMP: $COMPONENTS_ROUTE_COMP\nIDEN: $COMPONENTS_ROUTE_IDEN" >> $BLUEPRINT__DEBUG
|
||||
|
||||
|
@ -765,6 +765,16 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) ]]; then VCMD="y"
|
|||
# copy build file
|
||||
cp .blueprint/extensions/blueprint/private/build/extensions/clientServerRoute .blueprint/extensions/blueprint/private/build/extensions/clientServerRoute.bak
|
||||
|
||||
sed -i "s~\[id\]~$identifier~g" ".blueprint/extensions/blueprint/private/build/extensions/clientServerRoute.bak"
|
||||
sed -i "s~\[path\]~$COMPONENTS_ROUTE_PATH~g" ".blueprint/extensions/blueprint/private/build/extensions/clientServerRoute.bak"
|
||||
sed -i "s~\[name\]~$COMPONENTS_ROUTE_NAME~g" ".blueprint/extensions/blueprint/private/build/extensions/clientServerRoute.bak"
|
||||
sed -i "s~\[iden\]~$COMPONENTS_ROUTE_IDEN~g" ".blueprint/extensions/blueprint/private/build/extensions/clientServerRoute.bak"
|
||||
|
||||
im="\/\* blueprint\/import \*\/"; re="{/\* blueprint\/react \*/}"; co="resources/scripts/blueprint/components"
|
||||
s="import ${COMPONENTS_ROUTE_IDEN} from '"; e="';"
|
||||
|
||||
sed -i "s~""$im""~""${im}${s}@/blueprint/extensions/${identifier}/$1${e}""~g" "$co"/"$2"
|
||||
|
||||
# remove copied build file
|
||||
rm .blueprint/extensions/blueprint/private/build/extensions/clientServerRoute.bak
|
||||
elif [[ $COMPONENTS_ROUTE_TYPE == "account" ]]; then
|
||||
|
|
|
@ -1 +1 @@
|
|||
{ path: '[path]', name: '[name]', component: [component], },
|
||||
{ path: '[path]', name: '[name]', component: [comp], },
|
|
@ -1 +1 @@
|
|||
{ path: '[path]', name: '[name]', component: [component], permission: null, },
|
||||
{ path: '[path]', name: '[name]', component: [iden], permission: null, },
|
|
@ -1,8 +1,99 @@
|
|||
import React from 'react';
|
||||
import { NavLink, Route, Switch, useRouteMatch } from 'react-router-dom';
|
||||
import TransitionRouter from '@/TransitionRouter';
|
||||
import PermissionRoute from '@/components/elements/PermissionRoute';
|
||||
import Can from '@/components/elements/Can';
|
||||
import Spinner from '@/components/elements/Spinner';
|
||||
import { NotFound } from '@/components/elements/ScreenBlock';
|
||||
import { useLocation } from 'react-router';
|
||||
|
||||
import routes from '@/routers/routes';
|
||||
import blueprintRoutes from './routes';
|
||||
|
||||
export const NavigationLinks = () => {
|
||||
const match = useRouteMatch<{ id: string }>();
|
||||
const to = (value: string, url = false) => {
|
||||
if (value === '/') {
|
||||
return url ? match.url : match.path;
|
||||
}
|
||||
return `${(url ? match.url : match.path).replace(/\/*$/, '')}/${value.replace(/^\/+/, '')}`;
|
||||
};
|
||||
|
||||
export default () => {
|
||||
return (
|
||||
<>
|
||||
|
||||
{/* Pterodactyl routes */}
|
||||
{routes.server
|
||||
.filter((route) => !!route.name)
|
||||
.map((route) =>
|
||||
route.permission ? (
|
||||
<Can key={route.path} action={route.permission} matchAny>
|
||||
<NavLink to={to(route.path, true)} exact={route.exact}>
|
||||
{route.name}
|
||||
</NavLink>
|
||||
</Can>
|
||||
) : (
|
||||
<NavLink key={route.path} to={to(route.path, true)} exact={route.exact}>
|
||||
{route.name}
|
||||
</NavLink>
|
||||
)
|
||||
)}
|
||||
|
||||
{/* Blueprint routes */}
|
||||
{blueprintRoutes.server
|
||||
.filter((route) => !!route.name)
|
||||
.map((route) =>
|
||||
route.permission ? (
|
||||
<Can key={route.path} action={route.permission} matchAny>
|
||||
<NavLink to={to(route.path, true)} exact={route.exact}>
|
||||
{route.name}
|
||||
</NavLink>
|
||||
</Can>
|
||||
) : (
|
||||
<NavLink key={route.path} to={to(route.path, true)} exact={route.exact}>
|
||||
{route.name}
|
||||
</NavLink>
|
||||
)
|
||||
)}
|
||||
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const NavigationRouter = () => {
|
||||
const match = useRouteMatch<{ id: string }>();
|
||||
const to = (value: string, url = false) => {
|
||||
if (value === '/') {
|
||||
return url ? match.url : match.path;
|
||||
}
|
||||
return `${(url ? match.url : match.path).replace(/\/*$/, '')}/${value.replace(/^\/+/, '')}`;
|
||||
};
|
||||
|
||||
const location = useLocation();
|
||||
return (
|
||||
<>
|
||||
<TransitionRouter>
|
||||
<Switch location={location}>
|
||||
|
||||
{routes.server.map(({ path, permission, component: Component }) => (
|
||||
<PermissionRoute key={path} permission={permission} path={to(path)} exact>
|
||||
<Spinner.Suspense>
|
||||
<Component />
|
||||
</Spinner.Suspense>
|
||||
</PermissionRoute>
|
||||
))}
|
||||
|
||||
{blueprintRoutes.server.map(({ path, permission, component: Component }) => (
|
||||
<PermissionRoute key={path} permission={permission} path={to(path)} exact>
|
||||
<Spinner.Suspense>
|
||||
<Component />
|
||||
</Spinner.Suspense>
|
||||
</PermissionRoute>
|
||||
))}
|
||||
|
||||
<Route path={'*'} component={NotFound} />
|
||||
</Switch>
|
||||
</TransitionRouter>
|
||||
</>
|
||||
);
|
||||
};
|
|
@ -1,14 +1,12 @@
|
|||
import TransferListener from '@/components/server/TransferListener';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { NavLink, Route, Switch, useRouteMatch } from 'react-router-dom';
|
||||
import { useRouteMatch } from 'react-router-dom';
|
||||
import NavigationBar from '@/components/NavigationBar';
|
||||
import TransitionRouter from '@/TransitionRouter';
|
||||
import WebsocketHandler from '@/components/server/WebsocketHandler';
|
||||
import { ServerContext } from '@/state/server';
|
||||
import { CSSTransition } from 'react-transition-group';
|
||||
import Can from '@/components/elements/Can';
|
||||
import Spinner from '@/components/elements/Spinner';
|
||||
import { NotFound, ServerError } from '@/components/elements/ScreenBlock';
|
||||
import { ServerError } from '@/components/elements/ScreenBlock';
|
||||
import { httpErrorToHuman } from '@/api/http';
|
||||
import { useStoreState } from 'easy-peasy';
|
||||
import SubNavigation from '@/components/elements/SubNavigation';
|
||||
|
@ -18,13 +16,11 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|||
import { faExternalLinkAlt } from '@fortawesome/free-solid-svg-icons';
|
||||
import { useLocation } from 'react-router';
|
||||
import ConflictStateRenderer from '@/components/server/ConflictStateRenderer';
|
||||
import PermissionRoute from '@/components/elements/PermissionRoute';
|
||||
import routes from '@/routers/routes';
|
||||
|
||||
import BlueprintRouter from '@/blueprint/extends/routers/ServerRouter';
|
||||
import BeforeSubNavigation from '@/blueprint/components/Navigation/SubNavigation/BeforeSubNavigation';
|
||||
import AdditionalServerItems from '@/blueprint/components/Navigation/SubNavigation/AdditionalServerItems';
|
||||
import AfterSubNavigation from '@/blueprint/components/Navigation/SubNavigation/AfterSubNavigation';
|
||||
import { NavigationLinks, NavigationRouter } from '@/blueprint/extends/routers/DashboardRouter';
|
||||
import BeforeSubNavigation from '@/blueprint/components/Navigation/SubNavigation/BeforeSubNavigation';
|
||||
import AdditionalServerItems from '@/blueprint/components/Navigation/SubNavigation/AdditionalServerItems';
|
||||
import AfterSubNavigation from '@/blueprint/components/Navigation/SubNavigation/AfterSubNavigation';
|
||||
|
||||
export default () => {
|
||||
const match = useRouteMatch<{ id: string }>();
|
||||
|
@ -40,13 +36,6 @@ export default () => {
|
|||
const getServer = ServerContext.useStoreActions((actions) => actions.server.getServer);
|
||||
const clearServerState = ServerContext.useStoreActions((actions) => actions.clearServerState);
|
||||
|
||||
const to = (value: string, url = false) => {
|
||||
if (value === '/') {
|
||||
return url ? match.url : match.path;
|
||||
}
|
||||
return `${(url ? match.url : match.path).replace(/\/*$/, '')}/${value.replace(/^\/+/, '')}`;
|
||||
};
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
clearServerState();
|
||||
|
@ -82,21 +71,7 @@ export default () => {
|
|||
<SubNavigation>
|
||||
<div>
|
||||
<BeforeSubNavigation />
|
||||
{routes.server
|
||||
.filter((route) => !!route.name)
|
||||
.map((route) =>
|
||||
route.permission ? (
|
||||
<Can key={route.path} action={route.permission} matchAny>
|
||||
<NavLink to={to(route.path, true)} exact={route.exact}>
|
||||
{route.name}
|
||||
</NavLink>
|
||||
</Can>
|
||||
) : (
|
||||
<NavLink key={route.path} to={to(route.path, true)} exact={route.exact}>
|
||||
{route.name}
|
||||
</NavLink>
|
||||
)
|
||||
)}
|
||||
<NavigationLinks />
|
||||
<AdditionalServerItems />
|
||||
{rootAdmin && (
|
||||
// eslint-disable-next-line react/jsx-no-target-blank
|
||||
|
@ -115,18 +90,7 @@ export default () => {
|
|||
<ConflictStateRenderer />
|
||||
) : (
|
||||
<ErrorBoundary>
|
||||
<TransitionRouter>
|
||||
<Switch location={location}>
|
||||
{routes.server.map(({ path, permission, component: Component }) => (
|
||||
<PermissionRoute key={path} permission={permission} path={to(path)} exact>
|
||||
<Spinner.Suspense>
|
||||
<Component />
|
||||
</Spinner.Suspense>
|
||||
</PermissionRoute>
|
||||
))}
|
||||
<Route path={'*'} component={NotFound} />
|
||||
</Switch>
|
||||
</TransitionRouter>
|
||||
<NavigationRouter />
|
||||
</ErrorBoundary>
|
||||
)}
|
||||
</>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
@php
|
||||
<?php
|
||||
// Allow BlueprintExtensionLibrary to work in all admin views without
|
||||
// modifying all admin page controllers. Doing this should preserve
|
||||
// basic compatibility for other modifications.
|
||||
use Pterodactyl\BlueprintFramework\Libraries\ExtensionLibrary\Admin\BlueprintAdminLibrary as BlueprintExtensionLibrary;
|
||||
$settings = app()->make('Pterodactyl\Contracts\Repository\SettingsRepositoryInterface');
|
||||
$blueprint = app()->make(BlueprintExtensionLibrary::class, ['settings' => $settings]);
|
||||
@endphp
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
@php
|
||||
<?php
|
||||
use Pterodactyl\BlueprintFramework\Libraries\ExtensionLibrary\Client\BlueprintClientLibrary as BlueprintExtensionLibrary;
|
||||
$settings = app()->make('Pterodactyl\Contracts\Repository\SettingsRepositoryInterface');
|
||||
$blueprint = app()->make(BlueprintExtensionLibrary::class, ['settings' => $settings]);
|
||||
@endphp
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
|
Loading…
Reference in a new issue