Skip to content

Commit

Permalink
ConDec-441: Unify context menus for decision knowledge stored in JIRA…
Browse files Browse the repository at this point in the history
… issue comments and JIRA issues (#96)

* Add documentation location variable to createContextMenu function 

* Delete createContextMenuForSentences function and replace calls to it with calling createContextMenu

* Use the same edit dialog for elements from different documentation locations

* Make Issue knowledge type the default type in decision knowledge page

* Add event.dataTransfer.setData("text", event.target.id) to enable drag and drop in decision knowledge page
  • Loading branch information
kleebaum authored Jan 4, 2019
1 parent 55f6a1c commit 28c4b6b
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 237 deletions.
4 changes: 2 additions & 2 deletions src/main/resources/js/condec.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,10 @@
});
}

ConDecAPI.prototype.openJiraIssue = function openJiraIssue(nodeId) {
ConDecAPI.prototype.openJiraIssue = function openJiraIssue(elementId, documentationLocation) {
console.log("conDecAPI openJiraIssue");

this.getDecisionKnowledgeElement(nodeId, "i", function(decisionKnowledgeElement) {
this.getDecisionKnowledgeElement(elementId, documentationLocation, function(decisionKnowledgeElement) {
global.open(decisionKnowledgeElement.url, '_self');
});
};
Expand Down
153 changes: 62 additions & 91 deletions src/main/resources/js/condec.context.menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
function hideContextMenu() {
/*
* @issue This event gets launched many times at the same time! Check
* what fires it Probably more and more onclick event handlers ges added
* what fires it. Probably more and more onclick event handlers ges added
* instead of just one
*
* @decision On click and on blur event handlers are only set in the
Expand All @@ -44,7 +44,11 @@
isContextMenuOpen = false;
}

ConDecContextMenu.prototype.createContextMenu = function createContextMenu(event, id, container) {
/*
* external references: condec.treant, condec.tree.viewer
*/
ConDecContextMenu.prototype.createContextMenu = function createContextMenu(id, documentationLocation, event,
container) {
console.log("contextmenu opened");
isContextMenuOpen = true;

Expand All @@ -54,7 +58,7 @@
return;
}

setContextMenuItemsEventHandlers(id);
setContextMenuItemsEventHandlers(id, documentationLocation);

var position = getPosition(event, container);
var posX = position["x"];
Expand All @@ -67,134 +71,101 @@

contextMenuNode.style.zIndex = 9998; // why this number?
contextMenuNode.setAttribute('aria-hidden', 'false');

if (documentationLocation === "s") {
document.getElementById("condec-context-menu-link-item").style.display = "none";
document.getElementById("condec-context-menu-sentence-irrelevant-item").style.display = "initial";
document.getElementById("condec-context-menu-sentence-convert-item").style.display = "initial";
document.getElementById("condec-context-menu-set-root-item").style.display = "none";
} else {
document.getElementById("condec-context-menu-link-item").style.display = "initial";
document.getElementById("condec-context-menu-sentence-irrelevant-item").style.display = "none";
document.getElementById("condec-context-menu-sentence-convert-item").style.display = "none";
document.getElementById("condec-context-menu-set-root-item").style.display = "initial";
}
};

function setContextMenuItemsEventHandlers(id) {
function setContextMenuItemsEventHandlers(id, documentationLocation) {
document.getElementById("condec-context-menu-create-item").onclick = function() {
conDecDialog.showCreateDialog(id, "i");
conDecDialog.showCreateDialog(id, documentationLocation);
};

document.getElementById("condec-context-menu-edit-item").onclick = function() {
conDecDialog.showEditDialog(id);
conDecDialog.showEditDialog(id, documentationLocation);
};

document.getElementById("condec-context-menu-change-type-item").onclick = function() {
conDecDialog.showChangeTypeDialog(id, "");
};

document.getElementById("condec-context-menu-link-item").onclick = function() {
conDecDialog.showLinkDialog(id, "");
};

document.getElementById("condec-context-menu-delete-link-item").onclick = function() {
var parentId = conDecTreant.findParentId(id);
conDecDialog.showDeleteLinkDialog(id, parentId);
conDecDialog.showChangeTypeDialog(id, documentationLocation);
};

document.getElementById("condec-context-menu-delete-item").onclick = function() {
conDecDialog.showDeleteDialog(id, "");
};

document.getElementById("condec-context-menu-set-root-item").onclick = function() {
conDecAPI.getDecisionKnowledgeElement(id, "i", function(decisionKnowledgeElement) {
conDecTreant.buildTreant(decisionKnowledgeElement.key, true, "");
document.getElementById("condec-context-menu-issue-item").onclick = function() {
conDecAPI.changeKnowledgeType(id, "Issue", documentationLocation, function() {
conDecObservable.notify();
});
};

document.getElementById("condec-context-menu-open-jira-issue-item").onclick = function() {
conDecAPI.openJiraIssue(id);
};
}

ConDecContextMenu.prototype.createContextMenuForSentences = function createContextMenuForSentences(event, id,
container) {
isContextMenuOpen = true;
console.log("contextmenu opened");

contextMenuForSentencesNode = document.getElementById("condec-context-menu-sentence");
if (!contextMenuForSentencesNode) {
console.error("contextmenu for sentences not found");
return;
}

setContextMenuItemsSentencesEventHandlers(id);

var position = getPosition(event, container);
var posX = position["x"];
var posY = position["y"];

$(contextMenuForSentencesNode).css({
left : posX,
top : posY
});

contextMenuForSentencesNode.style.zIndex = 9998;
contextMenuForSentencesNode.setAttribute('aria-hidden', 'false');
};

function setContextMenuItemsSentencesEventHandlers(id) {
document.getElementById("condec-context-menu-sentence-create-item").onclick = function() {
conDecDialog.showCreateDialog(id, "s");
};

document.getElementById("condec-context-menu-sentence-edit-item").onclick = function() {
conDecDialog.setUpDialogForEditSentenceAction(id);
};

document.getElementById("condec-context-menu-sentence-delete-link-item").onclick = function() {
var parentId = conDecTreant.findParentId(id);
conDecAPI.deleteLink(parentId, id, "i", "s", conDecAPI.setSentenceIrrelevant(id, function() {
document.getElementById("condec-context-menu-decision-item").onclick = function() {
conDecAPI.changeKnowledgeType(id, "Decision", documentationLocation, function() {
conDecObservable.notify();
}), false);
conDecAPI.deleteLink(parentId, id, "s", "s", conDecAPI.setSentenceIrrelevant(id, function() {
conDecObservable.notify();
}), false);
});
};

document.getElementById("condec-context-menu-sentence-convert-item").onclick = function() {
conDecAPI.createIssueFromSentence(id, function() {
document.getElementById("condec-context-menu-alternative-item").onclick = function() {
conDecAPI.changeKnowledgeType(id, "Alternative", documentationLocation, function() {
conDecObservable.notify();
});
};

document.getElementById("condec-context-menu-sentence-irrelevant-item").onclick = function() {
conDecAPI.setSentenceIrrelevant(id, function() {
document.getElementById("condec-context-menu-pro-item").onclick = function() {
conDecAPI.changeKnowledgeType(id, "Pro", documentationLocation, function() {
conDecObservable.notify();
});
};

document.getElementById("condec-context-menu-sentence-issue-item").onclick = function() {
conDecAPI.changeKnowledgeType(id, "Issue", "s", function() {
document.getElementById("condec-context-menu-con-item").onclick = function() {
conDecAPI.changeKnowledgeType(id, "Con", documentationLocation, function() {
conDecObservable.notify();
});
};

document.getElementById("condec-context-menu-sentence-decision-item").onclick = function() {
conDecAPI.changeKnowledgeType(id, "Decision", "s", function() {
conDecObservable.notify();
});
// only default documentation location
// TODO enable linking of existing elements for every documentation
// location
document.getElementById("condec-context-menu-link-item").onclick = function() {
conDecDialog.showLinkDialog(id, documentationLocation);
};

document.getElementById("condec-context-menu-sentence-alternative-item").onclick = function() {
conDecAPI.changeKnowledgeType(id, "Alternative", "s", function() {
conDecObservable.notify();
});
document.getElementById("condec-context-menu-delete-link-item").onclick = function() {
conDecDialog.showDeleteLinkDialog(id, documentationLocation);
};

document.getElementById("condec-context-menu-sentence-pro-item").onclick = function() {
conDecAPI.changeKnowledgeType(id, "Pro", "s", function() {
conDecObservable.notify();
document.getElementById("condec-context-menu-delete-item").onclick = function() {
conDecDialog.showDeleteDialog(id, documentationLocation);
};

// only default documentation location
// TODO set as root for sentences
document.getElementById("condec-context-menu-set-root-item").onclick = function() {
conDecAPI.getDecisionKnowledgeElement(id, documentationLocation, function(decisionKnowledgeElement) {
conDecTreant.buildTreant(decisionKnowledgeElement.key, true, "");
});
};

document.getElementById("condec-context-menu-sentence-con-item").onclick = function() {
conDecAPI.changeKnowledgeType(id, "Con", "s", function() {
document.getElementById("condec-context-menu-open-jira-issue-item").onclick = function() {
conDecAPI.openJiraIssue(id, documentationLocation);
};

// only for sentences
document.getElementById("condec-context-menu-sentence-irrelevant-item").onclick = function() {
conDecAPI.setSentenceIrrelevant(id, function() {
conDecObservable.notify();
});
};

document.getElementById("condec-context-menu-sentence-delete-item").onclick = function() {
conDecDialog.showDeleteDialog(id, "s");
document.getElementById("condec-context-menu-sentence-convert-item").onclick = function() {
conDecAPI.createIssueFromSentence(id, function() {
conDecObservable.notify();
});
};
}

Expand Down
Loading

0 comments on commit 28c4b6b

Please sign in to comment.