', {class: classes, role: 'tabpanel', id});
}
class ConfigModel {
constructor(coreRest) {
this.coreRest = coreRest;
this.$modal = $('#config-modal');
this.$title = this.$modal.find('.modal-title');
this.$tabHeaders = this.$modal.find('.nav-tabs');
this.$tabContent = this.$modal.find('.tab-content');
this.$form = this.$modal.find('form');
this.$saveButton = $('#config-button');
this.$saveButton.click(this.onClick.bind(this));
this.$nodeEditModal = $('#nodeedit-modal');
this.$nodeEditModal.on('click', '#emane-options', this.emaneOptionsClick.bind(this));
this.$nodeEditModal.on('click', '#emane-model-options', this.emaneModelOptionsClick.bind(this));
}
async onClick() {
const nodeId = this.$nodeEditModal.data('node');
const configType = this.$modal.data('type');
console.log('config save clicked: ', nodeId, configType);
const configs = [];
for (let input of this.$form.find('input')) {
const $input = $(input);
const name = $input.attr('name');
const dataType = $input.parent().data('type');
const value = $input.val();
configs.push({name, value, type: dataType});
}
console.log('config data: ', configs);
await this.coreRest.setConfig({
name: configType,
node: nodeId,
values: configs
});
this.$modal.modal('hide');
}
showConfig(config) {
this.$tabHeaders.html('');
this.$tabContent.html('');
let initialTab = true;
for (let group of config.groups) {
let active = false;
if (initialTab) {
initialTab = false;
active = true;
}
console.log('option group: ', group.name);
const tabId = group.name.toLocaleLowerCase().split(" ").join("-");
console.log('tab id: ', tabId);
const $tabHeader = createTabHeader(tabId, group.name, active);
this.$tabHeaders.append($tabHeader);
const $tabPane = createTabPane(tabId, active);
this.$tabContent.append($tabPane);
for (let option of group.options) {
const $textbox = createTextbox(option.name, option.label, option.value);
$textbox.data('type', option.type);
$tabPane.append($textbox);
}
}
this.$modal.modal('show');
}
async emaneOptionsClick(event) {
this.$nodeEditModal.modal('hide');
const nodeId = this.$nodeEditModal.data('node');
const configName = 'emane';
this.$modal.data('type', configName);
this.$title.text('EMANE Options');
const config = await this.coreRest.getConfig({node: nodeId, name: configName});
console.log('emane options clicked: ', config);
this.showConfig(config);
return false;
}
async emaneModelOptionsClick(event) {
this.$nodeEditModal.modal('hide');
const nodeId = this.$nodeEditModal.data('node');
const configName = this.$nodeEditModal.find('input[name=emane]:checked').val();
this.$modal.data('type', configName);
this.$title.text('EMANE Model Options');
console.log('emane model clicked: ', configName);
const config = await this.coreRest.getConfig({node: nodeId, name: configName});
console.log('emane model options clicked: ', config);
this.showConfig(config);
return false;
}
}
class ServiceModal {
constructor(coreRest) {
this.coreRest = coreRest;
this.$modal = $('#service-modal');
this.$title = this.$modal.find('.modal-title');
this.$saveButton = $('#service-button');
this.$saveButton.click(this.onClick.bind(this));
}
async show(service) {
this.$title.text(`Edit ${service}`);
this.$modal.modal('show');
}
async onClick() {
}
}
class ServicesModal {
constructor(coreRest, coreNetwork, serviceModal) {
this.coreRest = coreRest;
this.coreNetwork = coreNetwork;
this.serviceModal = serviceModal;
this.$modal = $('#services-modal');
this.$modal.on('click', '.service-button', this.editService.bind(this));
this.$form = this.$modal.find('form');
this.$serviceGroup = $('#service-group');
this.$serviceGroup.on('change', this.groupChange.bind(this));
this.$servicesList = $('#services-list');
this.$saveButton = $('#services-button');
this.$saveButton.click(this.saveClicked.bind(this));
this.defaultServices = {
mdr: new Set(["zebra", "OSPFv3MDR", "IPForward"]),
PC: new Set(["DefaultRoute"]),
prouter: new Set(["zebra", "OSPFv2", "OSPFv3", "IPForward"]),
router: new Set(["zebra", "OSPFv2", "OSPFv3", "IPForward"]),
host: new Set(["DefaultRoute", "SSH"])
};
this.node = null;
this.nodeDefaults = null;
this.serviceGroups = null;
this.serviceOptions = new Map();
this.$currentGroup = null;
}
editService(event) {
const $target = $(event.target);
const service = $target.parent().parent().find('label').text();
console.log('edit service: ', service);
this.$modal.modal('hide');
this.serviceModal.show(service);
return false;
}
async show(nodeId) {
// get node and set default services for node type
this.node = this.coreNetwork.getCoreNode(nodeId);
if (this.node.services.length) {
this.nodeDefaults = new Set(this.node.services);
} else {
this.nodeDefaults = this.defaultServices[this.node.model] || new Set();
}
// retrieve service groups
this.serviceGroups = await coreRest.getServices(nodeId);
// clear data
this.$serviceGroup.html('');
this.$servicesList.html('');
this.serviceOptions.clear();
// set title
this.$modal.find('.modal-title').text(`Services: ${this.node.name}`);
// generate service form options
for (let group in this.serviceGroups) {
const $option = $('