feat core
routes
: Empty -init values now get assigned default values and add admin-only route scope
This commit is contained in:
parent
055398b618
commit
fa39d9fc47
4 changed files with 44 additions and 33 deletions
38
blueprint.sh
38
blueprint.sh
|
@ -237,7 +237,7 @@ if [[ $1 != "-bash" ]]; then
|
|||
fi
|
||||
|
||||
# Make sure all files have correct permissions.
|
||||
PRINT INFO "Changing Pterodactyl file ownership to 'www-data'.."
|
||||
PRINT INFO "Changing Pterodactyl file ownership to '$OWNERSHIP'.."
|
||||
chown -R $OWNERSHIP \
|
||||
$FOLDER/.blueprint/* \
|
||||
$FOLDER/app/* \
|
||||
|
@ -797,7 +797,7 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD="
|
|||
# Route component
|
||||
if [[ $child == "Components_Navigation_Routes_"+([0-9])"_Component" ]]; then COMPONENTS_ROUTE_COMP="${!child}"; fi
|
||||
# Route admin
|
||||
if [[ $child == "Components_Navigation_Routes_"+([0-9])"_Admin" ]]; then COMPONENTS_ROUTE_ADMI="${!child}"; fi
|
||||
if [[ $child == "Components_Navigation_Routes_"+([0-9])"_AdminOnly" ]]; then COMPONENTS_ROUTE_ADMI="${!child}"; fi
|
||||
done
|
||||
|
||||
# Route identifier
|
||||
|
@ -876,14 +876,14 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD="
|
|||
if [[ $COMPONENTS_ROUTE_TYPE == "account" ]]; then
|
||||
# Account routes
|
||||
COMPONENTS_IMPORT="import $COMPONENTS_ROUTE_IDEN from '@/blueprint/extensions/$identifier/$COMPONENTS_ROUTE_COMP';"
|
||||
COMPONENTS_ROUTE="{ path: '$COMPONENTS_ROUTE_PATH', name: '$COMPONENTS_ROUTE_NAME', component: $COMPONENTS_ROUTE_IDEN, admin: $COMPONENTS_ROUTE_ADMI },"
|
||||
COMPONENTS_ROUTE="{ path: '$COMPONENTS_ROUTE_PATH', name: '$COMPONENTS_ROUTE_NAME', component: $COMPONENTS_ROUTE_IDEN, adminOnly: $COMPONENTS_ROUTE_ADMI },"
|
||||
|
||||
sed -i "s~/\* \[import] \*/~/* [import] */""$COMPONENTS_IMPORT""~g" $ImportConstructor
|
||||
sed -i "s~/\* \[routes] \*/~/* [routes] */""$COMPONENTS_ROUTE""~g" $AccountRouteConstructor
|
||||
elif [[ $COMPONENTS_ROUTE_TYPE == "server" ]]; then
|
||||
# Server routes
|
||||
COMPONENTS_IMPORT="import $COMPONENTS_ROUTE_IDEN from '@/blueprint/extensions/$identifier/$COMPONENTS_ROUTE_COMP';"
|
||||
COMPONENTS_ROUTE="{ path: '$COMPONENTS_ROUTE_PATH', permission: null, name: '$COMPONENTS_ROUTE_NAME', component: $COMPONENTS_ROUTE_IDEN, },"
|
||||
COMPONENTS_ROUTE="{ path: '$COMPONENTS_ROUTE_PATH', permission: null, name: '$COMPONENTS_ROUTE_NAME', component: $COMPONENTS_ROUTE_IDEN, adminOnly: $COMPONENTS_ROUTE_ADMI },"
|
||||
|
||||
sed -i "s~/\* \[import] \*/~/* [import] */""$COMPONENTS_IMPORT""~g" $ImportConstructor
|
||||
sed -i "s~/\* \[routes] \*/~/* [routes] */""$COMPONENTS_ROUTE""~g" $ServerRouteConstructor
|
||||
|
@ -1540,14 +1540,14 @@ if [[ ( $2 == "-init" || $2 == "-I" ) ]]; then VCMD="y"
|
|||
}
|
||||
|
||||
ask_name() {
|
||||
PRINT INPUT "Name [SpaceInvaders]:"
|
||||
INPUT_DEFAULT="SpaceInvaders"
|
||||
PRINT INPUT "Name [$INPUT_DEFAULT]:"
|
||||
read -r ASKNAME
|
||||
REDO_NAME=false
|
||||
|
||||
# Name should not be empty
|
||||
if [[ ${ASKNAME} == "" ]]; then
|
||||
PRINT WARNING "Name should not be empty."
|
||||
REDO_NAME=true
|
||||
ASKNAME="$INPUT_DEFAULT"
|
||||
fi
|
||||
|
||||
# Ask again if response does not pass validation.
|
||||
|
@ -1555,14 +1555,14 @@ if [[ ( $2 == "-init" || $2 == "-I" ) ]]; then VCMD="y"
|
|||
}
|
||||
|
||||
ask_identifier() {
|
||||
PRINT INPUT "Identifier [spaceinvaders]:"
|
||||
INPUT_DEFAULT="spaceinvaders"
|
||||
PRINT INPUT "Identifier [$INPUT_DEFAULT]:"
|
||||
read -r ASKIDENTIFIER
|
||||
REDO_IDENTIFIER=false
|
||||
|
||||
# Identifier should not be empty
|
||||
if [[ ${ASKIDENTIFIER} == "" ]]; then
|
||||
PRINT WARNING "Identifier should not be empty."
|
||||
REDO_IDENTIFIER=true
|
||||
ASKIDENTIFIER="$INPUT_DEFAULT"
|
||||
fi
|
||||
# Identifier should be a-z.
|
||||
if ! [[ ${ASKIDENTIFIER} =~ [a-z] ]]; then
|
||||
|
@ -1575,14 +1575,14 @@ if [[ ( $2 == "-init" || $2 == "-I" ) ]]; then VCMD="y"
|
|||
}
|
||||
|
||||
ask_description() {
|
||||
PRINT INPUT "Description [Shoot down space aliens!]:"
|
||||
INPUT_DEFAULT="Shoot down space aliens!"
|
||||
PRINT INPUT "Description [$INPUT_DEFAULT]:"
|
||||
read -r ASKDESCRIPTION
|
||||
REDO_DESCRIPTION=false
|
||||
|
||||
# Description should not be empty
|
||||
if [[ ${ASKDESCRIPTION} == "" ]]; then
|
||||
PRINT WARNING "Description should not be empty."
|
||||
REDO_DESCRIPTION=true
|
||||
ASKDESCRIPTION="$INPUT_DEFAULT"
|
||||
fi
|
||||
|
||||
# Ask again if response does not pass validation.
|
||||
|
@ -1590,14 +1590,14 @@ if [[ ( $2 == "-init" || $2 == "-I" ) ]]; then VCMD="y"
|
|||
}
|
||||
|
||||
ask_version() {
|
||||
PRINT INPUT "Version [1.0]:"
|
||||
INPUT_DEFAULT="1.0"
|
||||
PRINT INPUT "Version [$INPUT_DEFAULT]:"
|
||||
read -r ASKVERSION
|
||||
REDO_VERSION=false
|
||||
|
||||
# Version should not be empty
|
||||
if [[ ${ASKVERSION} == "" ]]; then
|
||||
PRINT WARNING "Version should not be empty."
|
||||
REDO_VERSION=true
|
||||
ASKVERSION="$INPUT_DEFAULT"
|
||||
fi
|
||||
|
||||
# Ask again if response does not pass validation.
|
||||
|
@ -1605,14 +1605,14 @@ if [[ ( $2 == "-init" || $2 == "-I" ) ]]; then VCMD="y"
|
|||
}
|
||||
|
||||
ask_author() {
|
||||
PRINT INPUT "Author [byte]:"
|
||||
INPUT_DEFAULT="byte"
|
||||
PRINT INPUT "Author [$INPUT_DEFAULT]:"
|
||||
read -r ASKAUTHOR
|
||||
REDO_AUTHOR=false
|
||||
|
||||
# Author should not be empty
|
||||
if [[ ${ASKAUTHOR} == "" ]]; then
|
||||
PRINT WARNING "Author should not be empty."
|
||||
REDO_AUTHOR=true
|
||||
ASKAUTHOR="$INPUT_DEFAULT"
|
||||
fi
|
||||
|
||||
# Ask again if response does not pass validation.
|
||||
|
|
|
@ -28,7 +28,7 @@ export const NavigationLinks = () => {
|
|||
{/* Blueprint routes */}
|
||||
{blueprintRoutes.account.length > 0 && blueprintRoutes.account
|
||||
.filter((route) => !!route.name)
|
||||
.filter((route) => route.admin ? rootAdmin : true)
|
||||
.filter((route) => route.adminOnly ? rootAdmin : true)
|
||||
.map(({ path, name, exact = false }) => (
|
||||
<NavLink key={path} to={`/account/${path}`.replace('//', '/')} exact={exact}>
|
||||
{name}
|
||||
|
@ -42,6 +42,7 @@ export const NavigationLinks = () => {
|
|||
|
||||
export const NavigationRouter = () => {
|
||||
const location = useLocation();
|
||||
const rootAdmin = useStoreState((state) => state.user.data!.rootAdmin);
|
||||
return (
|
||||
<>
|
||||
<TransitionRouter>
|
||||
|
@ -59,11 +60,14 @@ export const NavigationRouter = () => {
|
|||
))}
|
||||
|
||||
{/* Blueprint routes */}
|
||||
{blueprintRoutes.account.length > 0 && blueprintRoutes.account.map(({ path, component: Component }) => (
|
||||
{blueprintRoutes.account.length > 0 && blueprintRoutes.account
|
||||
.filter((route) => route.adminOnly ? rootAdmin : true)
|
||||
.map(({ path, component: Component }) => (
|
||||
<Route key={path} path={`/account/${path}`.replace('//', '/')} exact>
|
||||
<Component />
|
||||
</Route>
|
||||
))}
|
||||
))
|
||||
}
|
||||
|
||||
<Route path={'*'}>
|
||||
<NotFound />
|
||||
|
|
|
@ -6,11 +6,13 @@ import Can from '@/components/elements/Can';
|
|||
import Spinner from '@/components/elements/Spinner';
|
||||
import { NotFound } from '@/components/elements/ScreenBlock';
|
||||
import { useLocation } from 'react-router';
|
||||
import { useStoreState } from 'easy-peasy';
|
||||
|
||||
import routes from '@/routers/routes';
|
||||
import blueprintRoutes from './routes';
|
||||
|
||||
export const NavigationLinks = () => {
|
||||
const rootAdmin = useStoreState((state) => state.user.data!.rootAdmin);
|
||||
const match = useRouteMatch<{ id: string }>();
|
||||
const to = (value: string, url = false) => {
|
||||
if (value === '/') {
|
||||
|
@ -43,6 +45,7 @@ export const NavigationLinks = () => {
|
|||
{/* Blueprint routes */}
|
||||
{blueprintRoutes.server.length > 0 && blueprintRoutes.server
|
||||
.filter((route) => !!route.name)
|
||||
.filter((route) => route.adminOnly ? rootAdmin : true)
|
||||
.map((route) =>
|
||||
route.permission ? (
|
||||
<Can key={route.path} action={route.permission} matchAny>
|
||||
|
@ -63,6 +66,7 @@ export const NavigationLinks = () => {
|
|||
};
|
||||
|
||||
export const NavigationRouter = () => {
|
||||
const rootAdmin = useStoreState((state) => state.user.data!.rootAdmin);
|
||||
const match = useRouteMatch<{ id: string }>();
|
||||
const to = (value: string, url = false) => {
|
||||
if (value === '/') {
|
||||
|
@ -87,13 +91,16 @@ export const NavigationRouter = () => {
|
|||
))}
|
||||
|
||||
{/* Blueprint routes */}
|
||||
{blueprintRoutes.server.length > 0 && blueprintRoutes.server.map(({ path, permission, component: Component }) => (
|
||||
{blueprintRoutes.server.length > 0 && blueprintRoutes.server
|
||||
.filter((route) => route.adminOnly ? rootAdmin : true)
|
||||
.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>
|
||||
|
|
|
@ -7,7 +7,7 @@ interface RouteDefinition {
|
|||
name: string | undefined;
|
||||
component: React.ComponentType;
|
||||
exact?: boolean;
|
||||
admin: boolean | false;
|
||||
adminOnly: boolean | false;
|
||||
}
|
||||
interface ServerRouteDefinition extends RouteDefinition {
|
||||
permission: string | string[] | null;
|
||||
|
|
Loading…
Reference in a new issue