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
61
resources/scripts/api/admin/nodes/getAllocations.ts
Normal file
61
resources/scripts/api/admin/nodes/getAllocations.ts
Normal file
|
@ -0,0 +1,61 @@
|
|||
import http, { FractalResponseData } from '@/api/http';
|
||||
import { rawDataToServer, Server } from '@/api/admin/servers/getServers';
|
||||
|
||||
export interface Allocation {
|
||||
id: number;
|
||||
ip: string;
|
||||
port: number;
|
||||
alias: string | null;
|
||||
serverId: number | null;
|
||||
assigned: boolean;
|
||||
|
||||
relations: {
|
||||
server?: Server;
|
||||
}
|
||||
|
||||
getDisplayText (): string;
|
||||
}
|
||||
|
||||
export const rawDataToAllocation = ({ attributes }: FractalResponseData): Allocation => ({
|
||||
id: attributes.id,
|
||||
ip: attributes.ip,
|
||||
port: attributes.port,
|
||||
alias: attributes.alias || null,
|
||||
serverId: attributes.server_id,
|
||||
assigned: attributes.assigned,
|
||||
|
||||
relations: {
|
||||
server: attributes.relationships?.server?.object === 'server' ? rawDataToServer(attributes.relationships.server as FractalResponseData) : undefined,
|
||||
},
|
||||
|
||||
// TODO: If IP is an IPv6, wrap IP in [].
|
||||
getDisplayText (): string {
|
||||
if (attributes.alias !== null) {
|
||||
return `${attributes.ip}:${attributes.port} (${attributes.alias})`;
|
||||
}
|
||||
return `${attributes.ip}:${attributes.port}`;
|
||||
},
|
||||
});
|
||||
|
||||
export interface Filters {
|
||||
ip?: string
|
||||
/* eslint-disable camelcase */
|
||||
server_id?: string;
|
||||
/* eslint-enable camelcase */
|
||||
}
|
||||
|
||||
export default (id: string | number, filters: Filters = {}, include: string[] = []): Promise<Allocation[]> => {
|
||||
const params = {};
|
||||
if (filters !== null) {
|
||||
Object.keys(filters).forEach(key => {
|
||||
// @ts-ignore
|
||||
params['filter[' + key + ']'] = filters[key];
|
||||
});
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/application/nodes/${id}/allocations`, { params: { include: include.join(','), ...params } })
|
||||
.then(({ data }) => resolve((data.data || []).map(rawDataToAllocation)))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue