Skip to content

Commit

Permalink
ConDec-386: Add a Change Type dialog and fix missing function bugs (#54)
Browse files Browse the repository at this point in the history
* ConDec-386: Add a Change Type dialog and fix missing function bugs

* ConDec-386: Add context menu point to issue modul

* ConDec-386: Fix link Type problem
  • Loading branch information
dekome authored and ematios committed Nov 7, 2018
1 parent de84392 commit f913578
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 17 deletions.
33 changes: 17 additions & 16 deletions src/main/resources/js/management.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,23 @@ function switchLinkTypes(type, idOfExistingElement, idOfNewElement, linkTypeFunc
function updateDecisionKnowledgeElementAsChild(childId, summary, description, type) {
console.log("management.js updateDecisionKnowledgeElementAsChild");
var simpleType = getSimpleType(type);
updateDecisionKnowledgeElement(childId, summary, description, simpleType, function() {
conDecAPI.getDecisionKnowledgeElement(childId, function(decisionKnowledgeElement) {
if (decisionKnowledgeElement.type !== type) {
var parentId = findParentId(childId);
switchLinkTypes(type, parentId, childId, function(linkType, parentId, childId) {
deleteLink(parentId, childId, function() {
conDecAPI.linkElements(parentId, childId, linkType, function() {
notify();
});
});
});
} else {
notify();
}
});
});
conDecAPI.getDecisionKnowledgeElement(childId, function(decisionKnowledgeElement) {
conDecAPI.updateDecisionKnowledgeElement(childId,summary,description,simpleType,function () {
console.log(decisionKnowledgeElement.type +" IN function "+ type);
if (decisionKnowledgeElement.type !== type) {
var parentId = findParentId(childId);
switchLinkTypes(type, parentId, childId, function(linkType, parentId, childId) {
conDecAPI.deleteLink(parentId, childId, function() {
conDecAPI.linkElements(parentId, childId, linkType, function() {
notify();
});
});
});
} else {
notify();
}
});
});
}

function getSimpleType(type) {
Expand Down
53 changes: 53 additions & 0 deletions src/main/resources/js/view.context.menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var linkKnowledgeElementText = "Link Existing Element";
var deleteLinkToParentText = "Delete Link to Parent";
var editKnowledgeElementText = "Edit Element";
var deleteKnowledgeElementText = "Delete Element";
var changeKnowledgeTypeText = "Change Element Type";

var contextMenuCreateAction = {
// label for Tree Viewer, name for Treant context menu
Expand Down Expand Up @@ -144,6 +145,24 @@ function setUpCreateOrEditDialog(summary, description, knowledgeType) {
AJS.$("#form-select-type").auiSelect2();
}

function setUpTypeChangeDialog(knowledgeType){
console.log("view.context.menu.js setUpTypeChangeDialog");
document.getElementById("dialog-content").insertAdjacentHTML(
"afterBegin",
"<form class='aui'><div class='field-group'><label for='form-select-type'>Knowledge type:</label>"
+ "<select id='form-select-type' name='form-select-type' class='select full-width-field'/></div>"
+ "</form>");
for (var index = 0; index < extendedKnowledgeTypes.length; index++) {
var isSelected = "";
if (isKnowledgeTypeLocatedAtIndex(knowledgeType, index)) {
isSelected = "selected ";
}
$("select[name='form-select-type']")[0].insertAdjacentHTML("beforeend", "<option " + isSelected + "value='"
+ extendedKnowledgeTypes[index] + "'>" + extendedKnowledgeTypes[index] + "</option>");
}
AJS.$("#form-select-type").auiSelect2();
}

function isKnowledgeTypeLocatedAtIndex(knowledgeType, index) {
console.log("view.context.menu.js isKnowledgeTypeLocatedAtIndex");
return knowledgeType.toLowerCase() === extendedKnowledgeTypes[index].toLowerCase();
Expand Down Expand Up @@ -338,6 +357,40 @@ function setUpDialogForDeleteLinkAction(id, parentId) {
};
}

var contextMenuChangeTypeAction = {
"label" : changeKnowledgeTypeText,
"name" : changeKnowledgeTypeText,
"action" : function (position) {
var node = getSelectedTreeViewerNode(position);
var id = node.id;
setUpDialogForChangeTypeAction(id);
},
"callback" : function(key, options) {
var id = getSelectedTreantNodeId(options);
setUpDialogForChangeTypeAction(id);
}
};

function setUpDialogForChangeTypeAction(id) {
console.log("view.context.menu.js setUpDialogForChangeTypeAction");
setUpDialog();
setHeaderText(changeKnowledgeTypeText);
conDecAPI.getDecisionKnowledgeElement(id, function(decisionKnowledgeElement) {
var summary = decisionKnowledgeElement.summary;
var description = decisionKnowledgeElement.description;
var type = decisionKnowledgeElement.type;
setUpTypeChangeDialog(type);

var submitButton = document.getElementById("dialog-submit-button");
submitButton.textContent = editKnowledgeElementText;
submitButton.onclick = function () {
var type = $("select[name='form-select-type']").val();
updateDecisionKnowledgeElementAsChild(id,summary,description,type);
AJS.dialog2("#dialog").hide();
};
});
}

var contextMenuSetAsRootAction = {
// label for Tree Viewer, name for Treant context menu
"name" : makeRootText,
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/js/view.decision.knowledge.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
, "deleteLink" : contextMenu.contextMenuDeleteLinkAction
, "delete" : contextMenu.contextMenuDeleteAction
, "openIssue" : contextMenu.contextMenuOpenJiraIssueAction
, "changeType" : contextMenu.contextMenuChangeTypeAction
};
return menu;
};
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/js/view.issue.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
"edit" : contextMenu.contextMenuEditAction,
"link" : contextMenu.contextMenuLinkAction,
"deleteLink" : contextMenu.contextMenuDeleteLinkAction,
"delete" : contextMenu.contextMenuDeleteAction
"delete" : contextMenu.contextMenuDeleteAction,
"changeType" : contextMenu.contextMenuChangeTypeAction
};
return menu;
}
Expand Down

0 comments on commit f913578

Please sign in to comment.