浏览代码

implement message to lock during optimisation

tripeur 4 年之前
父节点
当前提交
9d4013e667
共有 4 个文件被更改,包括 21 次插入4 次删除
  1. 16 1
      src/PlannerApp.vue
  2. 1 1
      src/components/EditeurCreneau.vue
  3. 1 1
      src/models/messages/PlanningUpdateMessage.ts
  4. 3 1
      src/store/Actions.ts

+ 16 - 1
src/PlannerApp.vue

@@ -182,6 +182,10 @@ export default defineComponent({
             displayLength: 20000,
             classes: "warn",
           });
+        } else if (content.method === "optiStart") {
+          this.optimisationInProgress = true;
+        } else if (content.method === "optiStop") {
+          this.optimisationInProgress = false;
         } else {
           this.$store.dispatch(ActionTypes.commitRemote, content);
         }
@@ -337,6 +341,13 @@ export default defineComponent({
         headers: { "Content-Type": "application/json" },
       };
       this.optimisationInProgress = true;
+      const msg: PlanningUpdateMessage = {
+        uuid: this.uuid,
+        user: this.username,
+        method: "optiStart",
+        payload: "",
+      };
+      this.stompClient?.send("/app/notify", {}, JSON.stringify(msg));
       fetch(`${API_URL}planning/solve`, options)
         .then((response) => {
           if (response.status == 200) {
@@ -349,10 +360,14 @@ export default defineComponent({
         .catch((error) => {
           toast({ html: "Pas de réponse du serveur<br>" + error.toString(), classes: "error" });
           this.optimisationInProgress = false;
+        })
+        .finally(() => {
+          msg.method = "optiStop";
+          this.stompClient?.send("/app/notify", {}, JSON.stringify(msg));
+          this.optimisationInProgress = false;
         });
     },
     updatePlanningWithNewPairing(data: SolverOutput): void {
-      this.optimisationInProgress = false;
       // Display message from the solver
       toast({
         html: "Le planning a été mis à jour <br>Score : " + data.score,

+ 1 - 1
src/components/EditeurCreneau.vue

@@ -280,7 +280,7 @@ export default defineComponent({
           if (s != 0) {
             return s;
           }
-          // put the available volunteer first
+          // Put the available volunteer first
           s = (a.collide ? 1 : 0) - (b.collide ? 1 : 0);
           if (s != 0) {
             return s;

+ 1 - 1
src/models/messages/PlanningUpdateMessage.ts

@@ -3,7 +3,7 @@ import { Mutations } from "@/store/Mutations";
 export type PlanningUpdateMessage = {
   uuid: string;
   user: string;
-  method: keyof Mutations | "toast" | "join" | "leave";
+  method: keyof Mutations | "toast" | "join" | "leave" | "optiStart" | "optiStop";
   payload: string;
 };
 export default PlanningUpdateMessage;

+ 3 - 1
src/store/Actions.ts

@@ -88,7 +88,7 @@ export const actions: ActionTree<State, State> & Actions = {
         body.payload = JSON.stringify({ r: content.r.toJSON(), pos: content.pos });
       }
 
-      // Prepare payload
+      // Send the message
       if (
         data.mutation === MutationTypes.editBenevole ||
         data.mutation === MutationTypes.editConstraint ||
@@ -116,6 +116,8 @@ export const actions: ActionTree<State, State> & Actions = {
       data.method != "toast" &&
       data.method != "join" &&
       data.method != "leave" &&
+      data.method != "optiStart" &&
+      data.method != "optiStop" &&
       data.uuid == context.state.evenement.uuid
     ) {
       // Handle mutations that have dedicated JSON parser