initial rough working service edit, with special way to retrieve custom values
This commit is contained in:
parent
517ef4c3d3
commit
3e5cd61ecc
6 changed files with 331 additions and 13 deletions
|
@ -31,11 +31,18 @@
|
|||
padding: .5rem 1.25rem;
|
||||
}
|
||||
|
||||
#config-modal {
|
||||
.modal {
|
||||
overflow-y: initial !important;
|
||||
}
|
||||
|
||||
#config-modal .modal-body {
|
||||
.modal-body {
|
||||
height: calc(100vh - 200px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.file-content {
|
||||
background-color: #000 !important;
|
||||
color: #00ff26 !important;
|
||||
font-size: small;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
|
|
@ -401,6 +401,10 @@ class CoreNetwork {
|
|||
}
|
||||
|
||||
async start() {
|
||||
// clear current session and set for nodes to start
|
||||
await coreRest.setSessionState(SessionStates.definition);
|
||||
await coreRest.setSessionState(SessionStates.configuration);
|
||||
|
||||
const nodes = coreNetwork.getCoreNodes();
|
||||
for (let node of nodes) {
|
||||
const response = await coreRest.createNode(node);
|
||||
|
|
|
@ -86,6 +86,10 @@ class CoreRest {
|
|||
return await putJson(`/sessions/${this.currentSession}/config`, config);
|
||||
}
|
||||
|
||||
async getNode(nodeId) {
|
||||
return await $.getJSON(`/sessions/${this.currentSession}/nodes/${nodeId}`);
|
||||
}
|
||||
|
||||
async createNode(node) {
|
||||
return await postJson(`/sessions/${this.currentSession}/nodes`, node);
|
||||
}
|
||||
|
@ -111,11 +115,31 @@ class CoreRest {
|
|||
}
|
||||
|
||||
async getLinks(nodeId) {
|
||||
return await $.getJSON(`/sessions/${this.currentSession}/nodes/${nodeId}/links`)
|
||||
return await $.getJSON(`/sessions/${this.currentSession}/nodes/${nodeId}/links`);
|
||||
}
|
||||
|
||||
async getServices(nodeId) {
|
||||
return await $.getJSON(`/sessions/${this.currentSession}/nodes/${nodeId}/services`)
|
||||
return await $.getJSON(`/sessions/${this.currentSession}/nodes/${nodeId}/services`);
|
||||
}
|
||||
|
||||
async getService(nodeId, service) {
|
||||
return await $.getJSON(`/sessions/${this.currentSession}/nodes/${nodeId}/services/${service}`);
|
||||
}
|
||||
|
||||
async setService(nodeId, service, data) {
|
||||
return await putJson(`/sessions/${this.currentSession}/nodes/${nodeId}/services/${service}`, data);
|
||||
}
|
||||
|
||||
async getServiceFile(nodeId, service, serviceFile) {
|
||||
return await $.getJSON(`/sessions/${this.currentSession}/nodes/${nodeId}/services/${service}/file`,
|
||||
{file: serviceFile});
|
||||
}
|
||||
|
||||
async setServiceFile(nodeId, service, serviceFile, data) {
|
||||
return await putJson(`/sessions/${this.currentSession}/nodes/${nodeId}/services/${service}/file`, {
|
||||
name: serviceFile,
|
||||
data
|
||||
});
|
||||
}
|
||||
|
||||
async getNodeIps(nodeId, ip4Prefix, ip6Prefix) {
|
||||
|
|
|
@ -149,18 +149,88 @@ class ServiceModal {
|
|||
constructor(coreRest) {
|
||||
this.coreRest = coreRest;
|
||||
this.$modal = $('#service-modal');
|
||||
this.$form = this.$modal.find('form');
|
||||
this.$files = this.$modal.find('select[name=file]');
|
||||
this.$files.change(this.fileChange.bind(this));
|
||||
this.$fileContent = this.$modal.find('textarea[name=filecontent]');
|
||||
this.$startIndex = this.$modal.find('input[name=index]');
|
||||
this.$startTime = this.$modal.find('input[name=time]');
|
||||
this.$startup = this.$modal.find('textarea[name=startup]');
|
||||
this.$shutdown = this.$modal.find('textarea[name=shutdown]');
|
||||
this.$validate = this.$modal.find('textarea[name=validate]');
|
||||
this.$title = this.$modal.find('.modal-title');
|
||||
this.$saveButton = $('#service-button');
|
||||
this.$saveButton.click(this.onClick.bind(this));
|
||||
this.$saveButton.click(this.saveClicked.bind(this));
|
||||
this.node = null;
|
||||
this.service = null;
|
||||
}
|
||||
|
||||
async show(service) {
|
||||
async fileChange(event) {
|
||||
const currentFile = this.$files.val();
|
||||
console.log('current file: ', currentFile);
|
||||
if (currentFile) {
|
||||
const fileData = await this.coreRest.getServiceFile(this.node.id, this.service, currentFile);
|
||||
this.$fileContent.val(fileData);
|
||||
}
|
||||
}
|
||||
|
||||
async show(node, service) {
|
||||
this.node = node;
|
||||
this.service = service;
|
||||
this.$title.text(`Edit ${service}`);
|
||||
this.$modal.modal('show');
|
||||
|
||||
try {
|
||||
await this.coreRest.getNode(node.id);
|
||||
} catch (err) {
|
||||
console.log('node does not exist, creating for editing services');
|
||||
await this.coreRest.createNode(node);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await this.coreRest.getService(node.id, service);
|
||||
console.log('service data: ', response);
|
||||
this.$files.html('');
|
||||
for (let fileName of response.files) {
|
||||
const $option = $('<option>', {value: fileName, text: fileName});
|
||||
this.$files.append($option);
|
||||
}
|
||||
|
||||
this.$fileContent.val('');
|
||||
this.$files.change();
|
||||
this.$startIndex.val(response.startidx);
|
||||
this.$startTime.val(response.starttime);
|
||||
this.$startup.val(response.cmdup.join('\n'));
|
||||
this.$shutdown.val(response.cmddown.join('\n'));
|
||||
this.$validate.val(response.cmdval.join('\n'));
|
||||
|
||||
this.$modal.modal('show');
|
||||
} catch (err) {
|
||||
console.log('error getting service data: ', err);
|
||||
toastr.error('Get service error', 'Internal Error');
|
||||
}
|
||||
}
|
||||
|
||||
async onClick() {
|
||||
async saveClicked() {
|
||||
const formData = formToJson(this.$form);
|
||||
console.log('saved service data: ', formData);
|
||||
|
||||
// update current service file data
|
||||
try {
|
||||
await this.coreRest.setServiceFile(this.node.id, this.service, formData.file, formData.filecontent);
|
||||
} catch (err) {
|
||||
console.log('error saving service file data: ', err);
|
||||
}
|
||||
|
||||
// update all other service settings
|
||||
delete formData.file;
|
||||
delete formData.filecontent;
|
||||
try {
|
||||
await this.coreRest.setService(this.node.id, this.service, formData);
|
||||
} catch (err) {
|
||||
console.log('error saving service data: ', err);
|
||||
}
|
||||
|
||||
this.$modal.modal('hide');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,7 +266,7 @@ class ServicesModal {
|
|||
const service = $target.parent().parent().find('label').text();
|
||||
console.log('edit service: ', service);
|
||||
this.$modal.modal('hide');
|
||||
this.serviceModal.show(service);
|
||||
this.serviceModal.show(this.node, service);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue