-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/183 manage scenario state (#204)
* Added page for scenarios * Implemented scenarios page * Added scenario form * Added "Clear all scenarios" button * Added delete scenario button and made some scenario overview fixes * Added "Set scenario" button at stub * Updated changelog * Updated docs Co-authored-by: Duco <[email protected]>
- Loading branch information
1 parent
9ee06c4
commit d0b9938
Showing
21 changed files
with
349 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<template> | ||
<h1>{{ title }}</h1> | ||
|
||
<div class="row"> | ||
<div class="col-md-12 mb-2"> | ||
<div class="input-group"> | ||
<input | ||
type="text" | ||
class="form-control" | ||
placeholder="Scenario name (required)" | ||
v-model="scenarioForm.scenario" | ||
/> | ||
</div> | ||
</div> | ||
<div class="col-md-12 mb-2"> | ||
<div class="input-group"> | ||
<input | ||
type="text" | ||
class="form-control" | ||
placeholder="Scenario state (optional)" | ||
v-model="scenarioForm.state" | ||
/> | ||
</div> | ||
</div> | ||
<div class="col-md-12 mb-2"> | ||
<div class="input-group"> | ||
<input | ||
type="text" | ||
class="form-control" | ||
placeholder="Scenario hit count (optional)" | ||
v-model="scenarioForm.hitCount" | ||
/> | ||
</div> | ||
</div> | ||
<div class="col-md-12 mb-2"> | ||
<button class="btn btn-success" @click="save" :disabled="saveDisabled"> | ||
Save | ||
</button> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { useRoute, useRouter } from "vue-router"; | ||
import { computed, onMounted, onUnmounted, ref } from "vue"; | ||
import { useStore } from "vuex"; | ||
import { handleHttpError } from "@/utils/error"; | ||
import toastr from "toastr"; | ||
import { resources } from "@/constants/resources"; | ||
import { shouldSave } from "@/utils/event"; | ||
export default { | ||
name: "ScenarioForm", | ||
setup() { | ||
const route = useRoute(); | ||
const router = useRouter(); | ||
const store = useStore(); | ||
// Data | ||
const scenarioForm = ref({ | ||
scenario: "", | ||
state: "", | ||
hitCount: "", | ||
}); | ||
// Computed | ||
const scenarioName = computed(() => route.params.scenario); | ||
const newScenario = computed(() => !scenarioName.value); | ||
const title = computed(() => | ||
newScenario.value ? "Add scenario" : "Update scenario" | ||
); | ||
const saveDisabled = computed(() => !scenarioForm.value.scenario); | ||
// Methods | ||
const save = async () => { | ||
try { | ||
if (!scenarioForm.value.hitCount) { | ||
scenarioForm.value.hitCount = 0; | ||
} | ||
await store.dispatch("scenarios/setScenario", scenarioForm.value); | ||
toastr.success(resources.scenarioSetSuccessfully); | ||
await router.push({ name: "Scenarios" }); | ||
} catch (e) { | ||
handleHttpError(e); | ||
} | ||
}; | ||
const checkSave = async (e) => { | ||
if (shouldSave(e) && !saveDisabled.value) { | ||
e.preventDefault(); | ||
await save(); | ||
} | ||
}; | ||
// Lifecycle | ||
const keydownEventListener = async (e) => await checkSave(e); | ||
onMounted(async () => { | ||
document.addEventListener("keydown", keydownEventListener); | ||
if (scenarioName.value) { | ||
scenarioForm.value.scenario = scenarioName.value; | ||
} | ||
if (!newScenario.value) { | ||
try { | ||
scenarioForm.value = await store.dispatch( | ||
"scenarios/getScenario", | ||
scenarioName.value | ||
); | ||
} catch (e) { | ||
if (e.status !== 404) { | ||
handleHttpError(e); | ||
} | ||
} | ||
} | ||
}); | ||
onUnmounted(() => | ||
document.removeEventListener("keydown", keydownEventListener) | ||
); | ||
return { title, scenarioForm, save, saveDisabled }; | ||
}, | ||
}; | ||
</script> | ||
|
||
<style scoped></style> |
Oops, something went wrong.