Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
232 lines (195 loc) · 8.62 KB
/
Copy pathscript.js
File metadata and controls
232 lines (195 loc) · 8.62 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
let addBtn = document.querySelector(".add-btn");
let removeBtn = document.querySelector(".remove-btn");
let modalCont = document.querySelector(".modal-cont");
let mainCont = document.querySelector(".main-cont");
let modalTextArea = document.querySelector(".textarea-cont");
let Colors = ["lightpink", "lightblue", "lightgreen", "black"];
let setModalColor = Colors[Colors.length - 1];
let allPriorityColor = document.querySelectorAll(".priority-color");
let toolboxColors = document.querySelectorAll(".color");
//#️⃣ All Tickets Array
let ticketArr = [];
//#️⃣ Lock-Unlock classes
let lockClass = "fa-lock";
let unlockClass = "fa-lock-open";
// **************************************Fetching Data From Local Storage************************************ */
if (localStorage.getItem("jira_tickets")) {
// Retrive and display tickets
ticketArr = JSON.parse(localStorage.getItem("jira_tickets"));
// Create the existing tickets
ticketArr.forEach((ticketObj) => {
createTicket(ticketObj.ticketColor, ticketObj.ticketId, ticketObj.ticketTask);
})
}
//********************************************************************************************************** */
//#️⃣Change/toggle priority color while creating modal functionality
allPriorityColor.forEach((colorElem) => {
colorElem.addEventListener("click", (e) => {
//step 1: remove border class from color Element
allPriorityColor.forEach((defaultColor) => {
defaultColor.classList.remove("border");
})
//step 2: add border class on clicked color Element
colorElem.classList.add("border");
//step 3: get color class name of the clicked color Element
setModalColor = colorElem.classList[0];
})
})
//#️⃣ Add & Remove Button Functionality
// If addflag -> true, Modal display:flex
// If addflag -> false, Modal display:none
let addFlag = false;
let removeFlag = false;
addBtn.addEventListener("click", (e) => {
//Display Modal (On click: Toggle)
addFlag = !addFlag;
if (addFlag) {
modalCont.style.display = "flex";
}
else {
modalCont.style.display = "none";
}
})
removeBtn.addEventListener("click", (e) => {
removeFlag = !removeFlag;
})
//#️⃣Pressing Shift key to add ticket
modalCont.addEventListener("keydown", (e) => {
let key = e.key + e.location;
if (key === "Shift2") {
createTicket(setModalColor, shortid(), modalTextArea.value);
addFlag = false;
setModalToDefault();
}
})
//#️⃣Make a function to create a ticket
function createTicket(ticketColor, ticketId, ticketTask) {
let ticketCont = document.createElement("div");
ticketCont.setAttribute("class", "ticket-cont");
ticketCont.innerHTML = `
<div class="ticket-color ${ticketColor}"></div>
<div class="ticket-id">#${ticketId}</div>
<div class="ticket-task-area">${ticketTask}</div>
<div class="ticket-lock-icon">
<i class="fa-solid fa-lock"></i>
</div>`
//*️⃣*️⃣ Do Check if the ticket created above is already exist in (ticket array or database) Or Not.
let ticketIdx = getTicketIdx(ticketId);
if (ticketIdx === -1) {
//*️⃣Creating an object of ticket and pushing in the ticket array
ticketArr.push({ ticketColor, ticketId, ticketTask });
//*️⃣Creating a local storage and adding array as a object
localStorage.setItem("jira_tickets", JSON.stringify(ticketArr));
}
//step 1: Add created ticket to the main container
mainCont.appendChild(ticketCont);
//step 2: Handle remove: attach remove click event listiner on every created
handleRemove(ticketCont, ticketId);
// step 3:Handle lock-unlock: Lock-Unlock Functionality, attach click event listener on every created ticket
handleLockUnlock(ticketCont, ticketId);
// step 4: Handle toggle color functionality
handleToggleColor(ticketCont, ticketId);
}
//#️⃣Handle Remove functionality
function handleRemove(ticket, id) {
ticket.addEventListener("click", (e) => {
// removeFlag -> True, remove the ticket
if (removeFlag) {
//*️⃣ Get ticket index from ticket array : so that we can update the data after deletion of some tickets in local storage
let ticketIdx = getTicketIdx(id);
ticket.remove();
//*️⃣ Modify data in local storage and ticket array : (Some tickets Deleted)
ticketArr.splice(ticketIdx, 1);
localStorage.setItem("jira_tickets", JSON.stringify(ticketArr));
}
})
}
//#️⃣ Handle Lock-Unlock Icon Functionality : Edit task area(Using property contenteditable)
function handleLockUnlock(ticket, id) {
let ticketLockIcon = ticket.querySelector(".ticket-lock-icon");
let icon = ticketLockIcon.children[0];
let ticketTaskArea = ticket.querySelector(".ticket-task-area");
icon.addEventListener("click", (e) => {
//*️⃣ Get ticket index from ticket array : so that we can update the value of TaskArea in local storage
let ticketIdx = getTicketIdx(id);
if (icon.classList.contains(lockClass)) {
//unlocking
icon.classList.remove(lockClass);
icon.classList.add(unlockClass);
ticketTaskArea.setAttribute("contenteditable", "true");
} else {
//locking
icon.classList.remove(unlockClass);
icon.classList.add(lockClass);
ticketTaskArea.setAttribute("contenteditable", "false");
}
//*️⃣ Modify data in local storage and ticket array : (Task Area Change)
ticketArr[ticketIdx].ticketTask = ticketTaskArea.innerText;
localStorage.setItem("jira_tickets", JSON.stringify(ticketArr));
})
}
//#️⃣Handle change/toggle priority color of ticket functionality
function handleToggleColor(ticket, id) {
let ticketColor = ticket.querySelector(".ticket-color");
ticketColor.addEventListener("click", (e) => {
//*️⃣ Get ticket index from ticket array : so that we can update the value of color in local storage
let ticketIdx = getTicketIdx(id);
//step 1: Get current color
let currentColor = ticketColor.classList[1];
// step 2: find index of current color in Colors array
let currentColorIdx = Colors.findIndex((color) => {
return color === currentColor;
});
//step 3: finally increanment index and toggle color
currentColorIdx++;
let newColorIdx = currentColorIdx % Colors.length;
let newColor = Colors[newColorIdx];
ticketColor.classList.remove(currentColor);
ticketColor.classList.add(newColor);
//*️⃣ Modify data in local storage and ticket array : (Priority Color Change)
ticketArr[ticketIdx].ticketColor = newColor;
localStorage.setItem("jira_tickets", JSON.stringify(ticketArr));
})
}
//#️⃣Get ticket index using ticket id
function getTicketIdx(id) {
let ticketIdx = ticketArr.findIndex((ticketObj) => {
return ticketObj.ticketId === id;
});
return ticketIdx;
}
//#️⃣Handle ToolBox Priority color select and display only selected color tickets Functionality
for (let i = 0; i < toolboxColors.length; i++) {
let selectedToolBoxColor = toolboxColors[i].classList[0];
toolboxColors[i].addEventListener("click", (e) => {
let allTickets = document.querySelectorAll(".ticket-cont");
let allTicketsColor = document.querySelectorAll(".ticket-color");
for (let j = 0; j < allTickets.length; j++) {
if (selectedToolBoxColor !== allTicketsColor[j].classList[1]) {
allTickets[j].style.display = "none";
} else {
allTickets[j].style.display = "block";
}
}
})
toolboxColors[i].addEventListener("dblclick", (e) => {
let allTickets = document.querySelectorAll(".ticket-cont");
let allTicketsColor = document.querySelectorAll(".ticket-color");
for (let j = 0; j < allTickets.length; j++) {
allTickets[j].style.display = "block";
}
})
}
//#️⃣Set Modal priority color, value and display property to default
function setModalToDefault() {
// step 1: remove border class from modal priority colors
allPriorityColor.forEach((colorElem) => {
colorElem.classList.remove("border");
})
// step 2: add border class on the default Black color & also setModalColor to black
allPriorityColor[allPriorityColor.length - 1].classList.add("border");
setModalColor = Colors[Colors.length - 1];
// step 3: display none & value of textarea empty
modalCont.style.display = "none";
modalTextArea.value = "";
}