ui(admin): add new node page

This commit is contained in:
Matthew Penner 2021-09-12 21:22:33 -06:00
parent 3c01dbbcc5
commit d0a78ec067
No known key found for this signature in database
GPG key ID: 030E4AB751DC756F
15 changed files with 362 additions and 176 deletions

View file

@ -1,11 +1,41 @@
import http from '@/api/http';
import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes';
export default (name: string, description: string | null, include: string[] = []): Promise<Node> => {
export interface Values {
name: string;
locationId: number;
databaseHostId: number | null;
fqdn: string;
scheme: string;
behindProxy: boolean;
public: boolean;
daemonBase: string;
memory: number;
memoryOverallocate: number;
disk: number;
diskOverallocate: number;
listenPortHTTP: number;
publicPortHTTP: number;
listenPortSFTP: number;
publicPortSFTP: number;
}
export default (values: Values, include: string[] = []): Promise<Node> => {
const data = {};
Object.keys(values).forEach((key) => {
const key2 = key
.replace('HTTP', 'Http')
.replace('SFTP', 'Sftp')
.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
// @ts-ignore
data[key2] = values[key];
});
return new Promise((resolve, reject) => {
http.post('/api/application/nodes', {
name, description,
}, { params: { include: include.join(',') } })
http.post('/api/application/nodes', data, { params: { include: include.join(',') } })
.then(({ data }) => resolve(rawDataToNode(data)))
.catch(reject);
});

View file

@ -14,9 +14,7 @@ export default (id: number, node: Partial<Node>, include: string[] = []): Promis
});
return new Promise((resolve, reject) => {
http.patch(`/api/application/nodes/${id}`, {
...data,
}, { params: { include: include.join(',') } })
http.patch(`/api/application/nodes/${id}`, data, { params: { include: include.join(',') } })
.then(({ data }) => resolve(rawDataToNode(data)))
.catch(reject);
});