| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import Benevole from "@/models/Benevole";
- import Competence from "@/models/Competence";
- import Creneau from "@/models/Creneau";
- import Evenement from "@/models/Evenement";
- import { MutationTypes } from "@/store/Mutations";
- import { EvenementStateJSON } from "@/store/State";
- import { Ressource } from "jc-timeline";
- import { defineComponent } from "vue";
- const keyofEvent: Array<keyof Evenement> = ["name", "uuid", "start", "end"];
- export default defineComponent({
- methods: {
- importJsonState(obj: EvenementStateJSON, preserve = false) {
- // Remove previous content and load the main event title
- if (preserve == false) {
- 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],
- });
- }
- }
- // 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]: Ressource } = {};
- const creneauGroups = obj.creneauGroups.map((element) => {
- const ressource = new Ressource(element);
- dict[element.id] = ressource;
- return ressource;
- });
- // map parent to children
- obj.creneauGroups.forEach((iRessource) => {
- if (iRessource.parentId) {
- if (iRessource.parentId in dict) {
- dict[iRessource.id].parent = dict[iRessource.parentId];
- } else {
- throw new Error("Missing parent of creneau group : " + iRessource.id);
- }
- }
- return iRessource;
- });
- // Push the items to the store
- creneauGroups.forEach((r, pos) => {
- this.$store.commit(MutationTypes.addCreneauGroupAt, { r, pos });
- });
- // Import Creneau
- for (const 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 `);
- }
- }
- }
- },
- },
- });
|