ui(admin): add "working" React admin ui
This commit is contained in:
parent
d1c7494933
commit
5402584508
199 changed files with 13387 additions and 151 deletions
31
resources/scripts/api/admin/eggs/createEgg.ts
Normal file
31
resources/scripts/api/admin/eggs/createEgg.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import http from '@/api/http';
|
||||
import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg';
|
||||
|
||||
type Egg2 = Omit<Omit<Partial<Egg>, 'configFiles'>, 'configStartup'> & { configFiles: string, configStartup: string };
|
||||
|
||||
export default (egg: Partial<Egg2>): Promise<Egg> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post(
|
||||
'/api/application/eggs',
|
||||
{
|
||||
nest_id: egg.nestId,
|
||||
name: egg.name,
|
||||
description: egg.description,
|
||||
features: egg.features,
|
||||
docker_images: egg.dockerImages,
|
||||
config_files: egg.configFiles,
|
||||
config_startup: egg.configStartup,
|
||||
config_stop: egg.configStop,
|
||||
config_from: egg.configFrom,
|
||||
startup: egg.startup,
|
||||
script_container: egg.scriptContainer,
|
||||
copy_script_from: egg.copyScriptFrom,
|
||||
script_entry: egg.scriptEntry,
|
||||
script_is_privileged: egg.scriptIsPrivileged,
|
||||
script_install: egg.scriptInstall,
|
||||
},
|
||||
)
|
||||
.then(({ data }) => resolve(rawDataToEgg(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
22
resources/scripts/api/admin/eggs/createEggVariable.ts
Normal file
22
resources/scripts/api/admin/eggs/createEggVariable.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import http from '@/api/http';
|
||||
import { EggVariable } from '@/api/admin/egg';
|
||||
import { Transformers } from '@definitions/admin';
|
||||
|
||||
export type CreateEggVariable = Omit<EggVariable, 'id' | 'eggId' | 'createdAt' | 'updatedAt' | 'relationships'>;
|
||||
|
||||
export default async (eggId: number, variable: CreateEggVariable): Promise<EggVariable> => {
|
||||
const { data } = await http.post(
|
||||
`/api/application/eggs/${eggId}/variables`,
|
||||
{
|
||||
name: variable.name,
|
||||
description: variable.description,
|
||||
env_variable: variable.environmentVariable,
|
||||
default_value: variable.defaultValue,
|
||||
user_viewable: variable.isUserViewable,
|
||||
user_editable: variable.isUserEditable,
|
||||
rules: variable.rules,
|
||||
},
|
||||
);
|
||||
|
||||
return Transformers.toEggVariable(data);
|
||||
};
|
9
resources/scripts/api/admin/eggs/deleteEgg.ts
Normal file
9
resources/scripts/api/admin/eggs/deleteEgg.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export default (id: number): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.delete(`/api/application/eggs/${id}`)
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
9
resources/scripts/api/admin/eggs/deleteEggVariable.ts
Normal file
9
resources/scripts/api/admin/eggs/deleteEggVariable.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export default (eggId: number, variableId: number): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.delete(`/api/application/eggs/${eggId}/variables/${variableId}`)
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
108
resources/scripts/api/admin/eggs/getEgg.ts
Normal file
108
resources/scripts/api/admin/eggs/getEgg.ts
Normal file
|
@ -0,0 +1,108 @@
|
|||
import { Nest } from '@/api/admin/nests/getNests';
|
||||
import { rawDataToServer, Server } from '@/api/admin/servers/getServers';
|
||||
import http, { FractalResponseData, FractalResponseList } from '@/api/http';
|
||||
import useSWR from 'swr';
|
||||
|
||||
export interface EggVariable {
|
||||
id: number;
|
||||
eggId: number;
|
||||
name: string;
|
||||
description: string;
|
||||
envVariable: string;
|
||||
defaultValue: string;
|
||||
userViewable: boolean;
|
||||
userEditable: boolean;
|
||||
rules: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export const rawDataToEggVariable = ({ attributes }: FractalResponseData): EggVariable => ({
|
||||
id: attributes.id,
|
||||
eggId: attributes.egg_id,
|
||||
name: attributes.name,
|
||||
description: attributes.description,
|
||||
envVariable: attributes.env_variable,
|
||||
defaultValue: attributes.default_value,
|
||||
userViewable: attributes.user_viewable,
|
||||
userEditable: attributes.user_editable,
|
||||
rules: attributes.rules,
|
||||
createdAt: new Date(attributes.created_at),
|
||||
updatedAt: new Date(attributes.updated_at),
|
||||
});
|
||||
|
||||
export interface Egg {
|
||||
id: number;
|
||||
uuid: string;
|
||||
nestId: number;
|
||||
author: string;
|
||||
name: string;
|
||||
description: string | null;
|
||||
features: string[] | null;
|
||||
dockerImages: Record<string, string>;
|
||||
configFiles: Record<string, any> | null;
|
||||
configStartup: Record<string, any> | null;
|
||||
configStop: string | null;
|
||||
configFrom: number | null;
|
||||
startup: string;
|
||||
scriptContainer: string;
|
||||
copyScriptFrom: number | null;
|
||||
scriptEntry: string;
|
||||
scriptIsPrivileged: boolean;
|
||||
scriptInstall: string | null;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
|
||||
relations: {
|
||||
nest?: Nest;
|
||||
servers?: Server[];
|
||||
variables?: EggVariable[];
|
||||
};
|
||||
}
|
||||
|
||||
export const rawDataToEgg = ({ attributes }: FractalResponseData): Egg => ({
|
||||
id: attributes.id,
|
||||
uuid: attributes.uuid,
|
||||
nestId: attributes.nest_id,
|
||||
author: attributes.author,
|
||||
name: attributes.name,
|
||||
description: attributes.description,
|
||||
features: attributes.features,
|
||||
dockerImages: attributes.docker_images,
|
||||
configFiles: attributes.config?.files,
|
||||
configStartup: attributes.config?.startup,
|
||||
configStop: attributes.config?.stop,
|
||||
configFrom: attributes.config?.extends,
|
||||
startup: attributes.startup,
|
||||
copyScriptFrom: attributes.copy_script_from,
|
||||
scriptContainer: attributes.script?.container,
|
||||
scriptEntry: attributes.script?.entry,
|
||||
scriptIsPrivileged: attributes.script?.privileged,
|
||||
scriptInstall: attributes.script?.install,
|
||||
createdAt: new Date(attributes.created_at),
|
||||
updatedAt: new Date(attributes.updated_at),
|
||||
|
||||
relations: {
|
||||
nest: undefined,
|
||||
servers: ((attributes.relationships?.servers as FractalResponseList | undefined)?.data || []).map(
|
||||
rawDataToServer,
|
||||
),
|
||||
variables: ((attributes.relationships?.variables as FractalResponseList | undefined)?.data || []).map(
|
||||
rawDataToEggVariable,
|
||||
),
|
||||
},
|
||||
});
|
||||
|
||||
export const getEgg = async (id: number): Promise<Egg> => {
|
||||
const { data } = await http.get(`/api/application/eggs/${id}`, { params: { include: ['variables'] } });
|
||||
|
||||
return rawDataToEgg(data);
|
||||
};
|
||||
|
||||
export default (id: number) => {
|
||||
return useSWR<Egg>(`egg:${id}`, async () => {
|
||||
const { data } = await http.get(`/api/application/eggs/${id}`, { params: { include: ['variables'] } });
|
||||
|
||||
return rawDataToEgg(data);
|
||||
});
|
||||
};
|
31
resources/scripts/api/admin/eggs/updateEgg.ts
Normal file
31
resources/scripts/api/admin/eggs/updateEgg.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import http from '@/api/http';
|
||||
import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg';
|
||||
|
||||
type Egg2 = Omit<Omit<Partial<Egg>, 'configFiles'>, 'configStartup'> & { configFiles?: string, configStartup?: string };
|
||||
|
||||
export default (id: number, egg: Partial<Egg2>): Promise<Egg> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.patch(
|
||||
`/api/application/eggs/${id}`,
|
||||
{
|
||||
nest_id: egg.nestId,
|
||||
name: egg.name,
|
||||
description: egg.description,
|
||||
features: egg.features,
|
||||
docker_images: egg.dockerImages,
|
||||
config_files: egg.configFiles,
|
||||
config_startup: egg.configStartup,
|
||||
config_stop: egg.configStop,
|
||||
config_from: egg.configFrom,
|
||||
startup: egg.startup,
|
||||
script_container: egg.scriptContainer,
|
||||
copy_script_from: egg.copyScriptFrom,
|
||||
script_entry: egg.scriptEntry,
|
||||
script_is_privileged: egg.scriptIsPrivileged,
|
||||
script_install: egg.scriptInstall,
|
||||
},
|
||||
)
|
||||
.then(({ data }) => resolve(rawDataToEgg(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
21
resources/scripts/api/admin/eggs/updateEggVariables.ts
Normal file
21
resources/scripts/api/admin/eggs/updateEggVariables.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import http from '@/api/http';
|
||||
import { EggVariable } from '@/api/admin/egg';
|
||||
import { Transformers } from '@definitions/admin';
|
||||
|
||||
export default async (eggId: number, variables: Omit<EggVariable, 'eggId' | 'createdAt' | 'updatedAt'>[]): Promise<EggVariable[]> => {
|
||||
const { data } = await http.patch(
|
||||
`/api/application/eggs/${eggId}/variables`,
|
||||
variables.map(variable => ({
|
||||
id: variable.id,
|
||||
name: variable.name,
|
||||
description: variable.description,
|
||||
env_variable: variable.environmentVariable,
|
||||
default_value: variable.defaultValue,
|
||||
user_viewable: variable.isUserViewable,
|
||||
user_editable: variable.isUserEditable,
|
||||
rules: variable.rules,
|
||||
})),
|
||||
);
|
||||
|
||||
return data.data.map(Transformers.toEggVariable);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue