|
|
@@ -33,12 +33,15 @@
|
|
|
<script lang="ts">
|
|
|
import SockJS from "sockjs-client";
|
|
|
import Stomp from "stompjs";
|
|
|
+import dayjs from "dayjs";
|
|
|
import { defineComponent } from "vue";
|
|
|
-import toast, { Toast } from "@/utils/Toast";
|
|
|
import ConstraintTranslation from "@/assets/ConstraintTranslation";
|
|
|
+import toast, { Toast } from "@/utils/Toast";
|
|
|
+import { zipEncode, decodeUnzip } from "@/utils/Compression";
|
|
|
import Evenement from "@/models/Evenement";
|
|
|
import Creneau from "@/models/Creneau";
|
|
|
-import PlanningUpdateMessage from "@/models/PlanningUpdateMessage";
|
|
|
+import { PlanningUpdateMessage } from "@/models/messages/PlanningUpdateMessage";
|
|
|
+import { StompQueryMessage } from "@/models/messages/StompQueryMessage";
|
|
|
import {
|
|
|
AssignementPair,
|
|
|
SolverInput,
|
|
|
@@ -49,11 +52,10 @@ import {
|
|
|
} from "@/models/SolverInput";
|
|
|
import updatePlanningVersions from "@/mixins/updatePlanningVersions";
|
|
|
import importJsonState from "@/mixins/ImportJsonState";
|
|
|
-import { MutationTypes } from "@/store/Mutations";
|
|
|
-import dayjs from "dayjs";
|
|
|
-import { StateJSON } from "@/store/State";
|
|
|
-import Header, { HeaderLink } from "./components/Utils/Header.vue";
|
|
|
-import cFooter from "./components/Utils/Footer.vue";
|
|
|
+import { MutationTypes } from "@/views/Mutations";
|
|
|
+import { EvenementStateJSON } from "@/store/State";
|
|
|
+import Header, { HeaderLink } from "@/components/Utils/Header.vue";
|
|
|
+import cFooter from "@/components/Utils/Footer.vue";
|
|
|
|
|
|
const API_URL = process.env.VUE_APP_API_URL;
|
|
|
|
|
|
@@ -104,9 +106,11 @@ export default defineComponent({
|
|
|
var content = JSON.parse(msg.body) as { text: string; type: string };
|
|
|
toast({ html: content.text, classes: content.type });
|
|
|
});
|
|
|
+ this.stompClient.subscribe("/user/queue/query", this.handleStompQuery);
|
|
|
this.subscribe(this.uuid);
|
|
|
},
|
|
|
- () => {
|
|
|
+ (error) => {
|
|
|
+ console.error(error);
|
|
|
toast({
|
|
|
html:
|
|
|
"Impossible d'établir une connection avec le serveur.<br>Veuillez recharger la page.",
|
|
|
@@ -175,14 +179,33 @@ export default defineComponent({
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
+ handleStompQuery(msg: Stomp.Message) {
|
|
|
+ var content = JSON.parse(msg.body) as StompQueryMessage;
|
|
|
+ if (content.type == "planningRequest" && content.uuid == this.uuid) {
|
|
|
+ const response: StompQueryMessage = {
|
|
|
+ type: "planningData",
|
|
|
+ uuid: this.uuid,
|
|
|
+ destination: content.destination,
|
|
|
+ payload: zipEncode(JSON.stringify(this.$store.getters.getJSONEvenementState)),
|
|
|
+ };
|
|
|
+ this.stompClient.send("/app/response", {}, JSON.stringify(response));
|
|
|
+ }
|
|
|
+ if (content.type == "planningData" && content.uuid == this.uuid) {
|
|
|
+ const payload = JSON.parse(decodeUnzip(content.payload)) as EvenementStateJSON;
|
|
|
+ this.importState(payload);
|
|
|
+ }
|
|
|
+ },
|
|
|
localSave() {
|
|
|
- window.localStorage.setItem("activeState", JSON.stringify(this.$store.getters.getJSONState));
|
|
|
+ window.localStorage.setItem(
|
|
|
+ "activeState",
|
|
|
+ JSON.stringify(this.$store.getters.getJSONEvenementState)
|
|
|
+ );
|
|
|
},
|
|
|
save() {
|
|
|
const body = {
|
|
|
uuid: this.$store.state.evenement.uuid,
|
|
|
name: this.$store.state.evenement.name,
|
|
|
- content: JSON.stringify(this.$store.getters.getJSONState),
|
|
|
+ content: JSON.stringify(this.$store.getters.getJSONEvenementState),
|
|
|
};
|
|
|
// local save
|
|
|
window.localStorage.setItem("activeState", body.content);
|
|
|
@@ -232,7 +255,7 @@ export default defineComponent({
|
|
|
}
|
|
|
},
|
|
|
newEvenement() {
|
|
|
- const newState: StateJSON = {
|
|
|
+ const newState: EvenementStateJSON = {
|
|
|
evenement: new Evenement().toJSON(),
|
|
|
competences: [],
|
|
|
benevoles: [],
|
|
|
@@ -243,7 +266,7 @@ export default defineComponent({
|
|
|
this.save();
|
|
|
this.importState(newState);
|
|
|
},
|
|
|
- importState(newState: StateJSON) {
|
|
|
+ importState(newState: EvenementStateJSON) {
|
|
|
const prevUuid = this.$store.state.evenement.uuid;
|
|
|
this.importJsonState(newState);
|
|
|
if (this.$store.state.evenement.uuid != prevUuid) {
|
|
|
@@ -253,7 +276,7 @@ export default defineComponent({
|
|
|
this.clearToast();
|
|
|
},
|
|
|
exportStateToJson(): void {
|
|
|
- const obj: StateJSON = this.$store.getters.getJSONState;
|
|
|
+ const obj: EvenementStateJSON = this.$store.getters.getJSONEvenementState;
|
|
|
const mimeType = "data:text/json;charset=utf-8";
|
|
|
const dummy = document.createElement("a");
|
|
|
dummy.href = mimeType + ", " + encodeURI(JSON.stringify(obj));
|