ui(admin): allow editing allocations for servers

This commit is contained in:
Matthew Penner 2021-09-15 15:37:17 -06:00
parent 656ac62ad2
commit a6ab61adba
No known key found for this signature in database
GPG key ID: 030E4AB751DC756F
13 changed files with 219 additions and 84 deletions

View file

@ -1,26 +1,50 @@
import http, { FractalResponseData } from '@/api/http';
import { rawDataToServer, Server } from '@/api/admin/servers/getServers';
export interface Allocation {
id: number;
ip: string;
alias: string | null;
port: number;
notes: string | null;
alias: string | null;
serverId: number | null;
assigned: boolean;
relations: {
server?: Server;
}
}
export const rawDataToAllocation = (data: FractalResponseData): Allocation => ({
id: data.attributes.id,
ip: data.attributes.ip,
alias: data.attributes.ip_alias,
port: data.attributes.port,
notes: data.attributes.notes,
assigned: data.attributes.assigned,
export const rawDataToAllocation = ({ attributes }: FractalResponseData): Allocation => ({
id: attributes.id,
ip: attributes.ip,
port: attributes.port,
alias: attributes.ip_alias || null,
serverId: attributes.server_id,
assigned: attributes.assigned,
relations: {
server: attributes.relationships?.server?.object === 'server' ? rawDataToServer(attributes.relationships.server as FractalResponseData) : undefined,
},
});
export default (id: string | number): Promise<Allocation[]> => {
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`)
http.get(`/api/application/nodes/${id}/allocations`, { params: { include: include.join(','), ...params } })
.then(({ data }) => resolve((data.data || []).map(rawDataToAllocation)))
.catch(reject);
});