From 859f6b803cea2d47f4b8743dbadb3a1877f7bd60 Mon Sep 17 00:00:00 2001 From: Ziheng Li Date: Tue, 17 May 2022 09:12:50 +0800 Subject: [PATCH] [config_tool] Duplicate VM name Added check and error prompt for duplicate names of VM before save scenario. Tracked-On: projectacrn#7486 Signed-off-by: Ziheng Li --- .../configurator/src/pages/Config.vue | 71 ++++++++++++------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue b/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue index 1890abdb2..21b7e4bf6 100644 --- a/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue +++ b/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue @@ -308,7 +308,26 @@ export default { vmConfig['@id'] = vmIndex }) }, + confirmVmName() { + let vmNameArr = [] + let errorFlag = false + for (let i = 0; i < this.scenario.vm.length; i++) { + vmNameArr.push(this.scenario.vm[i].name) + } + vmNameArr.sort() + console.log(vmNameArr) + for (let i = 0; i < vmNameArr.length - 1; i++) { + if (vmNameArr[i] === vmNameArr[i + 1]) { + alert("There are duplicate VM name with" + vmNameArr[i] + + ",\n please your VM name"); + errorFlag = true + } + } + return errorFlag + }, saveScenario() { + let errorFlag = false + errorFlag = this.confirmVmName() this.assignVMID() let msg = ["Scenario xml saved\n", ".xml settings validated\n", @@ -332,31 +351,33 @@ export default { this.updateCurrentFormData() // get scenario XML with defaults scenarioXMLData = scenarioWithDefault.xml - // begin write down and verify - configurator.writeFile(this.WorkingFolder + 'scenario.xml', scenarioXMLData) - .then(() => { - step = 1 - configurator.pythonObject.validateScenario(this.board.content, scenarioXMLData) - }) - .then(() => { - step = 2 - let launchScripts = configurator.pythonObject.generateLaunchScript(this.board.content, scenarioXMLData) - for (let filename in launchScripts) { - configurator.writeFile(this.WorkingFolder + filename, launchScripts[filename]) - } - }) - .then(() => { - alert(`${msg.join('')} \n All files successfully saved to your working folder ${this.WorkingFolder}`) - }) - .catch((err) => { - console.log(err) - let outmsg = '' - for (var i = 0; i < step; i++) - outmsg += msg[i] - for (i = step; i < 3; i++) - outmsg += errmsg[i] - alert(`${outmsg} \n Please check your configuration`) - }) + if (!errorFlag) { + // begin write down and verify + configurator.writeFile(this.WorkingFolder + 'scenario.xml', scenarioXMLData) + .then(() => { + step = 1 + configurator.pythonObject.validateScenario(this.board.content, scenarioXMLData) + }) + .then(() => { + step = 2 + let launchScripts = configurator.pythonObject.generateLaunchScript(this.board.content, scenarioXMLData) + for (let filename in launchScripts) { + configurator.writeFile(this.WorkingFolder + filename, launchScripts[filename]) + } + }) + .then(() => { + alert(`${msg.join('')} \n All files successfully saved to your working folder ${this.WorkingFolder}`) + }) + .catch((err) => { + console.log(err) + let outmsg = '' + for (var i = 0; i < step; i++) + outmsg += msg[i] + for (i = step; i < 3; i++) + outmsg += errmsg[i] + alert(`${outmsg} \n Please check your configuration`) + }) + } } } }