| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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 { StateJSON } from "@/store/State";
- import { IRessource, Ressource, RessourceJSON } from "jc-timeline";
- import { defineComponent } from "vue";
- const keyofEvent: Array<keyof Evenement> = ["name", "uuid", "start", "end"];
- export default defineComponent({
- methods: {
- importJsonState(obj: StateJSON, 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]: 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 (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 `);
- }
- }
- }
- },
- },
- });
|