Skip to content

Commit

Permalink
Merge pull request #80 from canada-ca/startover
Browse files Browse the repository at this point in the history
Adding start over button
  • Loading branch information
Guillaume Charest authored May 24, 2019
2 parents da6885b + 3b616f7 commit 9efacf9
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 18 deletions.
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"deploy": "npm run build; push-dir --dir=dist --branch=gh-pages --cleanup"
},
"dependencies": {
"@types/lodash.isempty": "^4.4.6",
"@types/showdown": "^1.9.2",
"lodash.isempty": "^4.4.0",
"push-dir": "^0.4.1",
"register-service-worker": "^1.6.2",
"showdown": "^1.9.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
<template>
<div>
<ul class="list-inline lst-spaced">
<li>
<button
type="button"
class="mrgn-bttm-sm btn btn-success"
v-on:click="saveSurvey"
v-if="$store.getters.inProgress"
>
{{ $t("saveButton") }}
</button>
</li>
<li>
<input
type="file"
class="btn btn-default"
value="Load"
@change="onFileChanged($event)"
/>
</li>
</ul>
<button
type="button"
class="mrgn-bttm-sm btn btn-success"
v-on:click="saveSurvey"
value="Start Over"
class="btn btn-default"
v-on:click="$emit('startAgain')"
>
{{ $t("saveButton") }}
{{ $t("startAgain") }}
</button>
<input
type="file"
class="btn btn-default"
value="Load"
@change="onFileChanged($event)"
/>
</div>
</template>

Expand All @@ -23,7 +38,7 @@ import i18n from "@/plugins/i18n";
import SurveyFile from "@/interfaces/SurveyFile";
@Component
export default class SaveLoadFile extends Vue {
export default class ActionButtonBar extends Vue {
saveSurvey() {
const a = document.createElement("a");
a.download = "SurveyResults.json";
Expand Down
1 change: 1 addition & 0 deletions src/plugins/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"startAgain": "Start Again",
"swtchLang": "Français",
"onThisPage": "On this page",
"htmlCode": "en-CA",
Expand Down
1 change: 1 addition & 0 deletions src/plugins/fr.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"startAgain": "Recommencer",
"swtchLang": "English",
"onThisPage": "Sur cette page",
"htmlCode": "fr-CA",
Expand Down
4 changes: 4 additions & 0 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Vuex, { StoreOptions } from "vuex";
import VuexPersistence from "vuex-persist";
import { RootState } from "./types";
import { IQuestion, QuestionSelectBase, SurveyModel } from "survey-vue";
import isEmpty from "lodash.isempty";

Vue.use(Vuex);

Expand Down Expand Up @@ -214,6 +215,9 @@ const store: StoreOptions<RootState> = {
}
},
getters: {
inProgress: state => {
return !isEmpty(state.toolData);
},
calcscore: state => {
if (state.result === undefined) return [0, 0, 0];
return calculateFinalScore(state.result, state.questionNames);
Expand Down
21 changes: 13 additions & 8 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
}}</a>
</p>
<form>
<SaveLoadFile v-on:fileLoaded="fileLoaded($event)" />
<ActionButtonBar
v-on:fileLoaded="fileLoaded($event)"
v-on:startAgain="startAgain"
/>
</form>
<AssessmentTool :survey="Survey" />
<Score />
Expand All @@ -21,7 +24,7 @@ import showdown from "showdown";
import AssessmentTool from "@/components/AssessmentTool.vue"; // @ is an alias to /src
import Score from "@/components/Score.vue";
import SaveLoadFile from "@/components/SaveLoadFile.vue";
import ActionButtonBar from "@/components/ActionButtonBar.vue";
import SurveyFile from "@/interfaces/SurveyFile";
import i18n from "@/plugins/i18n";
import { RootState } from "@/types";
Expand All @@ -30,13 +33,17 @@ import surveyJSON from "@/survey-enfr.json";
@Component({
components: {
AssessmentTool,
SaveLoadFile,
ActionButtonBar,
Score
}
})
export default class Home extends Vue {
Survey: Model = new Model(surveyJSON);
startAgain() {
this.Survey.clear(true, true);
window.localStorage.clear();
}
fileLoaded($event: SurveyFile) {
this.Survey.data = $event.data;
this.Survey.currentPageNo = $event.currentPage;
Expand Down Expand Up @@ -102,13 +109,11 @@ export default class Home extends Vue {
}
});
//if answer data was found reload from local storage
const obj = this.$store.state.toolData;
if (!(Object.entries(obj).length === 0 && obj.constructor === Object)) {
//if survey is in progress reload from store
if (this.$store.getters.inProgress) {
this.fileLoaded({
currentPage: this.$store.state.currentPageNo,
data: obj
data: this.$store.state.toolData
} as SurveyFile);
}
}
Expand Down

0 comments on commit 9efacf9

Please sign in to comment.