|
|
@@ -42,13 +42,11 @@
|
|
|
</template>
|
|
|
<script lang="ts">
|
|
|
import { defineComponent } from "vue";
|
|
|
-import toast, { Toast } from "./utils/Toast";
|
|
|
+import toast, { Toast } from "@/utils/Toast";
|
|
|
import "@/assets/css/tabs.css";
|
|
|
import ConstraintTranslation from "@/assets/ConstraintTranslation";
|
|
|
-import Evenement from "./models/Evenement";
|
|
|
-import Benevole from "./models/Benevole";
|
|
|
-import Creneau from "./models/Creneau";
|
|
|
-import Competence from "./models/Competence";
|
|
|
+import Evenement from "@/models/Evenement";
|
|
|
+import Creneau from "@/models/Creneau";
|
|
|
import {
|
|
|
AssignementPair,
|
|
|
SolverInput,
|
|
|
@@ -56,18 +54,17 @@ import {
|
|
|
JustificationObject,
|
|
|
ScoreExplanation,
|
|
|
HardConstraint,
|
|
|
-} from "./models/SolverInput";
|
|
|
-import Ressource, { IRessource, RessourceJSON } from "jc-timeline/lib/Ressource";
|
|
|
+} from "@/models/SolverInput";
|
|
|
import updatePlanningVersions from "@/mixins/updatePlanningVersions";
|
|
|
-import { MutationTypes } from "./store/Mutations";
|
|
|
+import importJsonState from "@/mixins/ImportJsonState";
|
|
|
+import { MutationTypes } from "@/store/Mutations";
|
|
|
import dayjs from "dayjs";
|
|
|
-import { StateJSON } from "./store/State";
|
|
|
+import { StateJSON } from "@/store/State";
|
|
|
|
|
|
const API_URL = process.env.VUE_APP_API_URL;
|
|
|
|
|
|
-const keyofEvent: Array<keyof Evenement> = ["name", "uuid", "start", "end"];
|
|
|
export default defineComponent({
|
|
|
- mixins: [updatePlanningVersions],
|
|
|
+ mixins: [updatePlanningVersions, importJsonState],
|
|
|
data() {
|
|
|
return {
|
|
|
optimisationInProgress: false,
|
|
|
@@ -77,7 +74,9 @@ export default defineComponent({
|
|
|
};
|
|
|
},
|
|
|
mounted() {
|
|
|
- fetch(`${API_URL}api/evenements`)
|
|
|
+ const url = `${API_URL}api/evenements`;
|
|
|
+ console.log(url);
|
|
|
+ fetch(url)
|
|
|
.then((response) => {
|
|
|
if (response.status == 200) {
|
|
|
return response.json();
|
|
|
@@ -90,8 +89,8 @@ export default defineComponent({
|
|
|
const previousState = window.localStorage.getItem("activeState");
|
|
|
toast({ html: "Bienvenue" });
|
|
|
if (previousState) {
|
|
|
- this.importJsonState(JSON.parse(previousState), false);
|
|
|
- if (this.$route.path != "/planner") this.$router.push({ name: "Evenement" });
|
|
|
+ this.importState(JSON.parse(previousState));
|
|
|
+ if (this.$route.path == "/planner") this.$router.push({ name: "Evenement" });
|
|
|
}
|
|
|
window.onbeforeunload = () => {
|
|
|
this.localSave();
|
|
|
@@ -164,7 +163,16 @@ export default defineComponent({
|
|
|
};
|
|
|
newState.evenement.name = "Nouvel événement";
|
|
|
this.save();
|
|
|
+ this.importState(newState);
|
|
|
+ },
|
|
|
+ importState(newState: StateJSON) {
|
|
|
+ const prevUuid = this.$store.state.evenement.uuid;
|
|
|
this.importJsonState(newState);
|
|
|
+ if (this.$store.state.evenement.uuid != prevUuid) {
|
|
|
+ this.updatePlanningVersions();
|
|
|
+ }
|
|
|
+ // Remove past score explanation.
|
|
|
+ this.clearToast();
|
|
|
},
|
|
|
exportStateToJson(): void {
|
|
|
const obj: StateJSON = this.$store.getters.getJSONState;
|
|
|
@@ -292,73 +300,6 @@ export default defineComponent({
|
|
|
this.lastToast.element.lastElementChild?.addEventListener("click", this.clearToast);
|
|
|
}
|
|
|
},
|
|
|
- importJsonState(obj: StateJSON, preserve = false) {
|
|
|
- // Remove previous content and load the main event title
|
|
|
- if (preserve == false) {
|
|
|
- const prevUuid = this.$store.state.evenement.uuid;
|
|
|
- this.$store.commit(MutationTypes.resetState, undefined);
|
|
|
- const e = Evenement.fromJSON(obj.evenement);
|
|
|
- for (const k of keyofEvent) {
|
|
|
- this.$store.commit(MutationTypes.editEvenement, {
|
|
|
- field: k,
|
|
|
- value: e[k],
|
|
|
- });
|
|
|
- }
|
|
|
- if (e.uuid != prevUuid) {
|
|
|
- this.updatePlanningVersions();
|
|
|
- }
|
|
|
- }
|
|
|
- // Import constraint
|
|
|
- obj.competences.forEach((c) => {
|
|
|
- this.$store.commit(MutationTypes.addConstraint, Competence.fromJSON(c));
|
|
|
- });
|
|
|
- // Import Benevoles
|
|
|
- obj.benevoles.forEach((b) => {
|
|
|
- this.$store.commit(MutationTypes.addBenevole, Benevole.fromJSON(b));
|
|
|
- });
|
|
|
- // Import creneau group
|
|
|
- const dict: { [k: string]: RessourceJSON } = {};
|
|
|
- obj.creneauGroups.forEach((element) => {
|
|
|
- dict[element.id] = element;
|
|
|
- });
|
|
|
- // map parent to children
|
|
|
- const creneauGroups = obj.creneauGroups.map((ressource) => {
|
|
|
- const iRessource: IRessource = { ...ressource };
|
|
|
- if (iRessource.parentId) {
|
|
|
- if (iRessource.parentId in dict) {
|
|
|
- iRessource.parent = dict[iRessource.parentId];
|
|
|
- } else {
|
|
|
- throw new Error("Missing parent of creneau group : " + ressource.id);
|
|
|
- }
|
|
|
- }
|
|
|
- return iRessource;
|
|
|
- });
|
|
|
- // Push the items to this application
|
|
|
- creneauGroups.forEach((r) => {
|
|
|
- this.$store.commit(MutationTypes.addCreneauGroup, new Ressource(r));
|
|
|
- });
|
|
|
- // Import Creneau
|
|
|
- for (let c of obj.creneaux) {
|
|
|
- const creneau = Creneau.fromJSON(c);
|
|
|
- this.$store.commit(MutationTypes.addCreneau, creneau);
|
|
|
- // add the creneau to the corresponding benevole
|
|
|
- for (const id of creneau.benevoleIdList) {
|
|
|
- const b = this.$store.getters.getBenevoleById(id);
|
|
|
- if (b) {
|
|
|
- this.$store.commit(MutationTypes.editBenevole, {
|
|
|
- id: id,
|
|
|
- field: "creneauIdList",
|
|
|
- value: Array.from(new Set([...b.creneauIdList, creneau.id])),
|
|
|
- });
|
|
|
- } else {
|
|
|
- throw new Error(`The benevole ${id} was not find `);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // Remove past score explanation.
|
|
|
- this.clearToast();
|
|
|
- this.$router.push({ name: "Evenement" });
|
|
|
- },
|
|
|
},
|
|
|
});
|
|
|
</script>
|