This commit is contained in:
2019-01-11 03:03:44 +05:30
parent c28e9290de
commit 240371d1b7
3 changed files with 457 additions and 441 deletions

View File

@@ -6,6 +6,8 @@ import * as microbotOps from './services/microbot-ops';
import { Helper } from './helpers/helper';
import { store } from "./services/persistent-ops.js";
const recastclient = new recastOps.Recast();
const dom = new domManipulator.DomManipulator();
const app = new microbotOps.Microbot();
@@ -71,7 +73,9 @@ $(document).ready(() => {
const intent = $(`#${$config.constants.hiddenIntentFieldId}`).val();
if (intent) {
data.intent = intent;
// store.dispatch($)
var action = $config.intentSlugToOperations[intent].action;
action.payload = data;
store.dispatch(action);
const operation = $config.intentSlugToOperations[intent].githubOperation;
app[operation](data);
}

View File

@@ -6,7 +6,7 @@ import { createissue } from "../views/createissue.js";
import { createrepo } from "../views/createrepo.js";
import { displaylastcomment } from "../views/displaylastcomment.js";
import { viewrepos } from "../views/viewrepos.js";
import { PersistentOps } from "./persistent-ops.js";
// import { PersistentOps } from "./persistent-ops.js";
import { store } from "./persistent-ops.js";
const $config = require("../config.js");
@@ -30,21 +30,21 @@ export class DomManipulator {
showWidget(intent) {
let widget = document.getElementById(intent);
if (widget) {
if (!widget) {
widget = this.getWidget(intent);
widgets.prepend(widget);
}
if (!this.isVisible(widget)) {
widget.classList.remove("hide");
$("#underWidgetLine").removeClass("hide");
}
} else {
}
getWidget(intent) {
const template = document.createElement("template");
template.innerHTML = this.map[intent];
widget = template.content.firstChild;
if (!this.isVisible(widget)) {
widget.classList.remove("hide");
$("#underWidgetLine").removeClass("hide");
}
widgets.prepend(template.content.firstElementChild);
}
let widget = template.content.firstChild;
return widget;
}
displayIntentBox(intent) {
@@ -314,6 +314,16 @@ export class DomManipulator {
cardTitle.innerHTML = "Operation Completed!";
cardText.innerHTML = data.command;
}
} else if (data.type = 'widget') {
cardTitle.innerHTML = "Operation recorded with below data, click submit to repeat.";
cardText.innerHTML = $config.intentSlugToOperations[intent].cardMsg;
if (data && data.length && data.length > 0) {
if (intent === "viewrepos") {
table = this.createRepoTable(data);
} else if (intent === "displaylastcomment") {
comment = this.createCommentBody(data);
}
}
} else {
cardTitle.innerHTML = "Server Responded As..";
cardText.innerHTML = `Operation failed with status: ${data.status}`;

View File

@@ -138,19 +138,21 @@ function mbReducer(currentState, action) {
return nextState;
break;
case "ADD_REPO":
// let command = document.getElementById('command').value;
// nextState = window.localStorage.getItem('currentState') ? JSON.parse(window.localStorage.getItem('currentState')) : currentState;
// newHistory.command = command;
// newHistory.type = 'command';
// // newHistory.intent = 'commandbot'
// newHistory.insertionCounter = ++nextState.insertionCounter;
// if(nextState.queries) {
// nextState.queries = [ ...nextState.queries, newHistory ];
// } else {
// nextState.queries = [ newHistory ];
// }
// window.localStorage.setItem('currentState', JSON.stringify(nextState));
// return nextState;
response = action.payload;
nextState = window.localStorage.getItem('currentState') ? JSON.parse(window.localStorage.getItem('currentState')) : currentState;
newHistory = response;
newHistory.type = 'widget';
newHistory.insertionCounter = ++nextState.insertionCounter;
if(response.intent) {
let intent = response.intent;
if(nextState[intent]) {
nextState[intent] = [ ...nextState[intent], newHistory ];
} else {
nextState[intent] = [ newHistory ];
}
}
window.localStorage.setItem('currentState', JSON.stringify(nextState));
return nextState;
break;
case "ADD_COLLAB":
// let command = document.getElementById('command').value;