-
Notifications
You must be signed in to change notification settings - Fork 0
/
importTicket.js
executable file
·163 lines (140 loc) · 6.66 KB
/
importTicket.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
function importTicket(){
/** Check if we're on the correct site - only check by URL segment now */
/** Now importTicket() can seamlessly support both URL formats */
var requiredPageURL = "BoardViewController";
var CLS = false;
if (window.location.href.indexOf(requiredPageURL) <= -1){
if(confirm('This script must be run on the Kanboard dashboard. Go there now?')){
if (window.location.href.contains("webhostingkanban")){
var URLdomain = window.location.href.split('?')[0];
} else {
var URLdomain = "http://webhostingkanban/";
}
var URLtoRedirect = URLdomain + "?controller=BoardViewController&action=show&project_id=1";
window.open(URLtoRedirect);
console.log("Closing page");
return;
}
return;
}
/** Need to add a button element to the web page with a click event-handler */
var kanboardHeaderElement = document.getElementsByClassName("title-container")[0];
var pasteButton = document.createElement("button");
var pasteButtonText = document.createTextNode("Import ticket to Kanboard");
pasteButton.appendChild(pasteButtonText);
pasteButton.id = "pasteButtonID";
/** Building text input element for holding pasted ticket data */
var ticketDataHiddenInput = document.createElement("input");
/** ticketDataHiddenInput.style = "display: none;"; */
ticketDataHiddenInput.id = "hiddenTicketInput";
pasteButton.addEventListener("click", function(){
/** Retrieve the new ticket button element, verifying it is correct */
/** if CLS flag set to true, create a new ticket in the CLS backlog instead of the BAU backlog */
if (CLS){
var newTaskItemLink = $(".board-swimlane-columns-7 > th:nth-child(1) > div:nth-child(2) > div:nth-child(1) > a:nth-child(1)" ).get(0);
} else {
var newTaskItemLink = $(".board-swimlane-columns-1 > th:nth-child(1) > div:nth-child(2) > div:nth-child(1) > a:nth-child(1)" ).get(0);
}
if (newTaskItemLink.title == "Add a new task"){
console.log("The 'Add a new task' link element has been found on the page.");
} else {
console.log("The 'Add a new task' link element could not be found on the page. Function exiting.");
return;
}
/** retrieve ticketdata from the input field, will need to add tests to ensure it's a valid object */
var ticketDataObjectString = document.getElementById("hiddenTicketInput").value;
console.log("found following ticketDataObjectString value: " + ticketDataObjectString);
var ticketDetails = JSON.parse(ticketDataObjectString);
/** Do any category/name transformations necessary */
/** Insert values from the object into the new ticket form, we'll do this in a setTimeOut() event until I add a proper load event handler */
newTaskItemLink.click();
var kanboardTicketTitle = ticketDetails.ticketID + ' - ' + ticketDetails.ticketTitle;
var kanboardTicketDescription = "**Ticket ID:** " + ticketDetails.ticketID + " \n" + '**Current Phase:** ' + ticketDetails.ticketPhase + ' \n' + '**Initiator:** ' + ticketDetails.ticketInitiator + ' \n' + '**Description:** ' + ticketDetails.ticketDescription + ' \n';
var ticketCategoryCodeMappings = {
NO_CATEGORY: 0,
ACCESS: 74,
ADMIN: 75,
ADMIN_TECHNICAL: 92,
ANALYSIS: 76,
CONFIG_CHANGE: 77,
ECAB_EXCAB: 78,
EMAIL: 93,
INCIDENT_PROD: 79,
INCIDENT_UAT: 80,
INFORMATION: 81,
MEETING: 91,
NEW_SETUP: 82,
OOH: 83,
PATCH_PROD: 84,
PATCH_UAT: 85,
PROBLEM_MANAGEMENT: 87,
PRODUCT_REFRESH: 89,
SCRIP: 9,
WALKUP: 90
};
/** Determine a possible tag for the item based on its title */
var ticketTag = "";
/** to add: citadel, ssis, sso, dpr */
if (ticketDetails.ticketTitle.toLowerCase().includes('dpsng')){
ticketTag = "DPSNG";
} else if (ticketDetails.ticketTitle.toLowerCase().includes('cpm2')){
ticketTag = "CPM2";
} else if (ticketDetails.ticketTitle.toLowerCase().includes('sso')){
ticketTag = "SSO";
} else if (ticketDetails.ticketTitle.toLowerCase().includes('ssrs')){
ticketTag = "SSRS";
} else if (ticketDetails.ticketTitle.toLowerCase().includes('ssis')){
ticketTag = "SSIS";
} else if (ticketDetails.ticketTitle.toLowerCase().includes('dpr')){
ticketTag = "DPR";
} else if (ticketDetails.ticketTitle.toLowerCase().includes('gv')){
ticketTag = "GV";
} else if (ticketDetails.ticketTitle.toLowerCase().includes('scrip')){
ticketTag = "SCRIP";
} else if (ticketDetails.ticketTitle.toLowerCase().includes('citadel')){
ticketTag = "Citadel";
} else if (ticketDetails.ticketTitle.toLowerCase().includes('TeamCity')){
ticketTag = "TeamCity";
} else if (ticketDetails.ticketTitle.toLowerCase().includes('OctopusDeploy')){
ticketTag = "OctopusDeploy";
} else {
console.log('No recognized keywords found in ticket title for category determination.');
}
/** Trying to determine if this might be a PROD/UAT deployment */
var ticketCategoryCode = 0;
if (ticketDetails.ticketTitle.toLowerCase().includes('uat')){
ticketCategoryCode = ticketCategoryCodeMappings.PATCH_UAT;
console.log("UAT Patch ticket determined");
} else if (ticketDetails.ticketTitle.toLowerCase().includes('prod')){
ticketCategoryCode = ticketCategoryCodeMappings.PATCH_PROD;
console.log("PROD Patch ticket determined");
} else {
console.log('No recognized keywords found in ticket title for category determination.');
}
setTimeout(function(){
document.getElementById('form-title').value = kanboardTicketTitle;
$('.text-editor-write-mode > textarea:nth-child(2)').get(0).value = kanboardTicketDescription;
document.getElementById('form-reference').value = ticketDetails.ticketID;
document.getElementById('form-category_id').value = ticketCategoryCode;
if (ticketTag != ""){
var tagid = ticketTag;
var tagtext = ticketTag;
if ($('#form-tags').find("option[value='" + tagid + "']").length) {
$('#form-tags').val(tagid).trigger('change');
} else {
var newOption = new Option(tagtext, tagid, true, true);
$('#form-tags').append(newOption).trigger('change');
}
/** Now remove the added button and input elements from the Kanboard header */
var ticketDataHiddenInputToDelete = document.getElementById("hiddenTicketInput");
var pasteButtonToDelete = document.getElementById("pasteButtonID");
ticketDataHiddenInputToDelete.parentNode.removeChild(ticketDataHiddenInputToDelete);
pasteButtonToDelete.parentNode.removeChild(pasteButtonToDelete);
}
}, 2000);
});
kanboardHeaderElement.appendChild(pasteButton);
kanboardHeaderElement.appendChild(ticketDataHiddenInput);
document.getElementById("hiddenTicketInput").focus();
}
importTicket();