~girishm/op-mattermost

f7f138d4244ecc52ad677036980816f595a0971d — girishm 2 months ago b4c0078
1. confirm time log del 2. cancel search
3 files changed, 70 insertions(+), 14 deletions(-)

M resource/routes.js
M resource/uiActions.js
M resource/util.js
M resource/routes.js => resource/routes.js +4 -1
@@ 37,7 37,7 @@ module.exports = (app, axios) => {
    if(token === process.env.MATTERMOST_SLASH_TOKEN) {
      console.log("Request Body to / ", JSON.stringify(req.body, null, 2));
      if(command === "/op") {
        uiActions.showMenuButtons(req, res);
        uiActions.showMenuBtn(req, res);
      }
      else {
        res.send("*I don't understand ", command, ". Let's try again...* \n `/op`").status(500);


@@ 101,6 101,9 @@ module.exports = (app, axios) => {
      case "delSelTimeLog":
        uiActions.delTimeLog(req, res, axios);
        break;
      case "cnfDelTimeLog":
        uiActions.cnfDelTimeLog(req, res);
        break;
      default:
        uiActions.showTimeLogSel(req, res, axios);
    }

M resource/uiActions.js => resource/uiActions.js +9 -11
@@ 39,7 39,6 @@ class UIactions {
  }

  showSelProject(req, res, axios, action) {
    console.log("Request in showSelProject: ", req);
    axios({
      url: 'projects?sortBy=[["created_at","desc"]]',
      method: 'get',


@@ 71,7 70,6 @@ class UIactions {
  }

  showSelWP(req, res, axios, action) {
    console.log("Request in showSelWP: ", req);
    // noinspection JSUnresolvedVariable
    this.projectId = req.body.context.selected_option.slice(this.optLen);
    axios({


@@ 213,7 211,6 @@ class UIactions {
  }

  getTimeLog(req, res, axios) {
    console.log("Request to getTimeLog handler: ", req);
    axios({
      url: 'time_entries?sortBy=[["createdAt", "desc"]]',
      method: 'get',


@@ 241,7 238,6 @@ class UIactions {
  };

  showTimeLogSel(req, res, axios) {
    console.log("Request to showTimeLogSel handler: ", req);
    axios({
      url: 'time_entries?sortBy=[["createdAt", "desc"]]',
      method: 'get',


@@ 253,19 249,22 @@ class UIactions {
      response.data._embedded.elements.forEach(element => {
        timeLogArray.push({
          "value": "opt" + element.id,
          "text":  element.comment.raw + '-' + element.spentOn + '-' + this.moment.duration(element.hours, "h").humanize()
          "text":  element.comment.raw + '-' + element.spentOn + '-' + this.moment.duration(element.hours, "h").humanize() + '-' + element._links.workPackage.title + '-' + element._links.activity.title + '-' + element._links.project.title
        });
      });
      res.set('Content-Type', 'application/json').send(this.util.getTimeLogOptJSON(this.intURL, timeLogArray, "delSelTimeLog")).status(200);
      res.set('Content-Type', 'application/json').send(this.util.getTimeLogOptJSON(this.intURL, timeLogArray, "cnfDelTimeLog")).status(200);
    }).catch((error) => {
      console.log("Error in getting time logs: ", error);
      this.message.showMsg(req, res, axios, this.util.timeLogFetchErrMsg);
    });
  };

  delTimeLog(req, res, axios) {
    console.log("Request to delTimeLog handler: ", req);
  cnfDelTimeLog(req, res) {
    this.timeLogId = req.body.context.selected_option.slice(this.optLen);
    res.set('Content-Type', 'application/json').send(JSON.stringify(this.util.getCnfDelBtnJSON(this.intURL))).status(200);
  }

  delTimeLog(req, res, axios) {
    axios({
      url: 'time_entries/' + this.timeLogId,
      method: 'delete',


@@ 390,9 389,8 @@ class UIactions {
    }
  };

  showMenuButtons(req, res) {
    console.log("Request to showMenuButtons handler: ", req);
    res.set('Content-Type', 'application/json').send(JSON.stringify(this.util.getMenuButtonJSON(this.intURL))).status(200);
  showMenuBtn(req, res) {
    res.set('Content-Type', 'application/json').send(JSON.stringify(this.util.getMenuBtnJSON(this.intURL))).status(200);
  }
}
module.exports = UIactions;
\ No newline at end of file

M resource/util.js => resource/util.js +57 -2
@@ 132,7 132,14 @@ class Util {
                },
                "type": "select",
                "options": optArray
              }]
              },
              {
                "name": "Cancel search",
                "integration": {
                  "url": url + "bye"
                }
              }
            ]
          }
        ]
      }


@@ 166,6 173,12 @@ class Util {
                  },
                  "type": "select",
                  "options": optArray
                },
                {
                  "name": "Cancel search",
                  "integration": {
                    "url": url + "bye"
                  }
                }]
            }
          ]


@@ 194,6 207,12 @@ class Util {
                    },
                    "type": "select",
                    "options": optArray
                  },
                  {
                    "name": "Cancel search",
                    "integration": {
                      "url": url + "bye"
                    }
                  }]
              }
            ]


@@ 296,7 315,7 @@ class Util {
    };
  }

  getMenuButtonJSON(url) {
  getMenuBtnJSON(url) {
    return {
      "response_type": "in_channel",
      "props": {


@@ 356,5 375,41 @@ class Util {
      }
    };
  }

  getCnfDelBtnJSON(url, timeLog) {
    return {
      "update": {
        "response_type": "in_channel",
        "props": {
          "attachments": [
            {
              "pretext": timeLog,
              "text": "Confirm time log deletion?",
              "actions": [
                {
                  "name": "Yes, Delete!",
                  "integration": {
                    "url": url + "delTimeLog",
                    "context": {
                      "action": "delSelTimeLog"
                    }
                  }
                },
                {
                  "name": "No, go back.",
                  "integration": {
                    "url": url + "delTimeLog",
                    "context": {
                      "action": ""
                    }
                  }
                }
              ]
            }
          ]
        }
      }
    };
  }
}
module.exports = Util;
\ No newline at end of file