permanar

acknowledge TOBT

Dec 4th, 2020
1,356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // kode waktu klik button "Acknowledge"
  2. acknowledge() {
  3.       let data = {
  4.         departure_id: this.id,
  5.         role_id: this.$store.state.auth.user.id,
  6.         role_name: this.role,
  7.         tickmark: {
  8.           icon: "mdi-check-all",
  9.           color: "high-priority",
  10.         },
  11.       };
  12.  
  13.       this.$store
  14.         .dispatch("UPDATE_TOBT_ACKNOWLEDGE", data)
  15.         .then(() => {
  16.           // alert("TOBT acknowledged.");
  17.           let snackbar = {
  18.             message: "TOBT Acknowledged",
  19.             color: "green",
  20.             timeout: 5000,
  21.           };
  22.           this.$store.commit("snackbar/SET_SNACK", snackbar);
  23.  
  24.           this.isShown = false;
  25.           this.dialog = false;
  26.           this.reason = "";
  27.         })
  28.         .catch((e) => {
  29.           console.log(
  30.             "catching error when updating Acknowledge - Blue Tickmark: ",
  31.             e
  32.           );
  33.           if (e) {
  34.             if (e.status == 500) {
  35.               alert(
  36.                 `Acknowledge not updated with ${e.status} error server code. Please try again later.`
  37.               );
  38.             } else {
  39.               alert(`Something went wrong. Please try again later.`);
  40.             }
  41.           } else {
  42.             alert(`Something went wrong. Please try again later.`);
  43.           }
  44.         });
  45.     }
  46.  
  47.  
  48. // sambungan kode waktu nge-dispatch UPDATE_TOBT_ACKNOWLEDGE
  49.   async UPDATE_TOBT_ACKNOWLEDGE({ commit, state }, payload) {
  50.     let idx = state.departure.rows.findIndex(
  51.       (data) => data.id == payload.departure_id
  52.     );
  53.  
  54.     if (idx != -1) {
  55.       let data;
  56.       var { tickmark } = payload;
  57.  
  58.       let stringifyTOBT = JSON.stringify({
  59.         tickmark: {
  60.           icon: tickmark.icon || "mdi-check-all",
  61.           blink: null,
  62.           color: tickmark.color || "none-priority",
  63.           id_sender: payload.role_id,
  64.           sender_by: payload.role_name,
  65.         },
  66.       });
  67.  
  68.       data = {
  69.         id: state.departure.rows[idx].id,
  70.         airport_id: state.departure.rows[idx].airport_id,
  71.         flight_number: state.departure.rows[idx].flight_number,
  72.         call_sign: state.departure.rows[idx].call_sign,
  73.         nature: state.departure.rows[idx].nature,
  74.         acft: state.departure.rows[idx].acft,
  75.         register: state.departure.rows[idx].register,
  76.         stand: state.departure.rows[idx].stand,
  77.         gate_name: state.departure.rows[idx].gate_name,
  78.         gate_open: state.departure.rows[idx].gate_open,
  79.         runway_actual: state.departure.rows[idx].runway_actual,
  80.         runway_estimated: state.departure.rows[idx].runway_estimated,
  81.         transit: state.departure.rows[idx].transit,
  82.         destination: state.departure.rows[idx].destination,
  83.         status: state.departure.rows[idx].status,
  84.         code_share: state.departure.rows[idx].code_share,
  85.         departure_meta: {
  86.           tobt: stringifyTOBT,
  87.         },
  88.       };
  89.  
  90.       console.log("update ticksmark => acknowledged: ", data);
  91.  
  92.       if (payload.role_id == state.auth.user.id) {
  93.         try {
  94.           const ticksmark = await this.$axios.$put(
  95.             `/departure/${payload.departure_id}`,
  96.             data
  97.           );
  98.  
  99.           commit("SET_TICKSMARK", ticksmark);
  100.         } catch (error) {
  101.           throw error.response;
  102.         }
  103.       }
  104.     }
  105.   },
Advertisement
Add Comment
Please, Sign In to add comment