show warning message when users attempt to create a new scenario

fix warning message when users attempt to create a new scenario, or import an existing scenario, for an existing configuration

Tracked-On: #7898
Signed-off-by: Chuang-Ke chuangx.ke@intel.com
Reviewed-by: Junjie Mao junjie.mao@intel.com
This commit is contained in:
chuangxke 2022-07-19 11:14:10 +08:00 committed by acrnsi-robot
parent 715a597e37
commit e5a9c36095

View File

@ -3,7 +3,7 @@
<div class="border-end-sm py-1 col-sm"> <div class="border-end-sm py-1 col-sm">
<div class="py-4 text-center"> <div class="py-4 text-center">
<NewScenario v-model:show-modal="showCreateScenario" @newScenario="newScenario"/> <NewScenario v-model:show-modal="showCreateScenario" @newScenario="newScenario"/>
<button type="button" class="btn btn-primary btn-lg" @click="showCreateScenario=true"> <button type="button" class="btn btn-primary btn-lg" @click="CreateScenario">
Create Scenario Create Scenario
</button> </button>
</div> </div>
@ -27,7 +27,7 @@
<tr> <tr>
<td> <td>
<div class="py-4 text-right"> <div class="py-4 text-right">
<button type="button" class="wel-btn btn btn-primary btn-lg" @click="loadScenario(false)"> <button type="button" class="wel-btn btn btn-primary btn-lg" @click="checkAndLoadScenario(false)">
Import Scenario Import Scenario
</button> </button>
</div> </div>
@ -44,6 +44,7 @@
<script> <script>
import configurator from "../../lib/acrn"; import configurator from "../../lib/acrn";
import NewScenario from "./Scenario/NewScenario.vue"; import NewScenario from "./Scenario/NewScenario.vue";
import _ from "lodash";
export default { export default {
name: "Scenario", name: "Scenario",
@ -57,7 +58,7 @@ export default {
} }
}, },
props: { props: {
WorkingFolder: { WorkingFolder: {
type: String type: String
}, },
scenario: { scenario: {
@ -67,27 +68,55 @@ export default {
mounted() { mounted() {
//get init scenario if it exist, add to history //get init scenario if it exist, add to history
this.getExistScenarioPath() this.getExistScenarioPath()
.then((filePath) => { .then((filePath) => {
if (filePath.length > 0) { if (filePath.length > 0) {
configurator.addHistory('Scenario', filePath) configurator.addHistory('Scenario', filePath)
.then(()=>{ .then(() => {
this.getScenarioHistory().then(() => { this.getScenarioHistory().then(() => {
// delay 2s for board loading // delay 2s for board loading
setTimeout(() => { setTimeout(() => {
this.loadScenario(true) this.loadScenario(true)
}, 2000); }, 2000);
}) })
}) })
} }
}) })
this.getScenarioHistory() this.getScenarioHistory()
// Todo: auto load scenario // Todo: auto load scenario
}, },
methods: { methods: {
CreateScenario() {
if (!_.isEmpty(this.scenario)) {
confirm(`Warning: Overwrite the existing scenario file?`)
.then((r) => {
// user cancel the operation
if (!r) {
return
}
// user confirm the operation
this.showCreateScenario = true
})
} else this.showCreateScenario = true
},
newScenario(data) { newScenario(data) {
this.$emit('scenarioUpdate', data) this.$emit('scenarioUpdate', data)
}, },
loadScenario(auto = false) { checkAndLoadScenario(auto = false) {
if (!_.isEmpty(this.scenario)) {
confirm(`Warning: Overwrite the existing scenario file?`)
.then((r) => {
// user cancel the operation
if (!r) {
return
}
// user confirm the operation
this.loadScenario(auto)
})
} else this.loadScenario(auto)
},
loadScenario(auto) {
if (this.currentSelectedScenario.length > 0) { if (this.currentSelectedScenario.length > 0) {
configurator.loadScenario(this.currentSelectedScenario) configurator.loadScenario(this.currentSelectedScenario)
.then((scenarioConfig) => { .then((scenarioConfig) => {
@ -97,14 +126,14 @@ export default {
alert(`Scenario ${this.currentSelectedScenario} loaded success!`) alert(`Scenario ${this.currentSelectedScenario} loaded success!`)
} }
}).catch((err) => { }).catch((err) => {
console.log(err) console.log(err)
alert(`Loading ${this.currentSelectedScenario} failed: ${err}`) alert(`Loading ${this.currentSelectedScenario} failed: ${err}`)
}) })
} }
}, },
getExistScenarioPath() { getExistScenarioPath() {
// only return filename when using exist configuration. // only return filename when using exist configuration.
return configurator.readDir(this.WorkingFolder, false) return configurator.readDir(this.WorkingFolder, false)
.then((res) => { .then((res) => {
let scenarioPath = '' let scenarioPath = ''
res.map((filepath) => { res.map((filepath) => {