-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
207 lines (173 loc) · 6.9 KB
/
main.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
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
let editIndex = -1;
let data = [];
function saveIssue(e) {
var issueDesc = document.getElementById('issueDescInput').value;
var issueSeverity = document.getElementById('issueSeverityInput').value;
var issueAssignedTo = document.getElementById('issueAssignedToInput').value;
if (!issueDesc || !issueSeverity || !issueAssignedTo) {
alert("Please fill in all fields before adding.");
return;
}
var issueId = chance.guid();
var issueStatus = 'Open';
var issue = {
id: issueId,
description: issueDesc,
severity: issueSeverity,
assignedTo: issueAssignedTo,
status: issueStatus
}
data.push(issue);
fetchIssues();
document.getElementById('issueInputForm').reset();
e.preventDefault();
}
function setStatusClosed(i) {
// for (var i = 0; i < data.length; i++) {
// if (data[i].id == id) {
// data[i].status = 'Closed';
// } else if (data[editIndex].status === 'Closed') {
// document.getElementById('deleteBtn').style.display = 'block';
// // document.getElementById('closeBtn').style.pointerEvents = 'none';
// document.getElementById('openBtn').style.display = "block";
// }
// }
data[i].status = 'Close';
console.log(data[i].status);
if(data[i].status = 'Closed'){
// document.getElementById('deleteBtn').style.display = 'inline';
// document.getElementById('openBtn').style.display = "inline";
document.getElementById('closeBtn').style.display="none";
}
closeIssues1();
}
function setStatusOpen1(i) {
// document.getElementById('openBtn').style.display = "none";
data[i].status = 'Open';
console.log(data[i].status);
if(data[i].status = 'Open'){
document.getElementById('deleteBtn').style.display = 'none';
// document.getElementById('closeBtn').style.display = "inline";
document.getElementById('openBtn1').style.display = "none";
}
// document.getElementById('closeBtn').style.pointerEvents = 'auto';
// fetchIssues();
OpenIssues1();
}
function deleteIssue(id) {
for (var i = 0; i < data.length; i++) {
if (data[i].id == id) {
if (data[i].status === "Closed") {
data.splice(i, 1);
alert("Issue deleted!");
fetchIssues();
break;
} else {
alert("You cannot delete the issue until it is closed.");
}
}
}
}
function EditIssue(index) {
const user = data[index];
document.getElementById('issueDescInput').value = user.description;
document.getElementById('issueSeverityInput').value = user.severity;
document.getElementById('issueAssignedToInput').value = user.assignedTo;
editIndex = index;
document.getElementById('headerTitle').innerHTML = "Update the Issue:";
document.getElementById('updateBtn').style.display = "block";
document.getElementById('addBtn').style.display = "none";
document.getElementById('issueStatus').innerHTML = "Status: " + data[editIndex].status;
}
const updateBtn = document.getElementById("updateBtn");
updateBtn.addEventListener("click", () => {
var issueDesc = document.getElementById('issueDescInput').value;
var issueSeverity = document.getElementById('issueSeverityInput').value;
var issueAssignedTo = document.getElementById('issueAssignedToInput').value;
if (!issueDesc || !issueSeverity || !issueAssignedTo) {
alert("Please fill in all fields before updating.");
return;
}
updateUser(issueDesc, issueSeverity, issueAssignedTo);
});
function updateUser(issueDesc, issueSeverity, issueAssignedTo) {
data[editIndex].description = issueDesc;
data[editIndex].severity = issueSeverity;
data[editIndex].assignedTo = issueAssignedTo;
fetchIssues();
document.getElementById('headerTitle').innerHTML = "Add New Issue:";
document.getElementById('addBtn').style.display = "block";
document.getElementById('updateBtn').style.display = "none";
document.getElementById('issueStatus').innerHTML = "Status: " + data[editIndex].status;
document.getElementById('issueInputForm').reset();
editIndex = -1;
}
function fetchIssues() {
var issuesList = document.getElementById('issuesList');
issuesList.innerHTML = '';
for (var i = 0; i < data.length; i++) {
var id = data[i].id;
var desc = data[i].description;
var severity = data[i].severity;
var assignedTo = data[i].assignedTo;
var status = data[i].status;
issuesList.innerHTML += `
<div class="well">
<h6>Issue ID: ${id}</h6>
<p><span class="label label-info" id="issueStatus">Status: ${status}</span></p>
<h3>${desc}</h3>
<p><span class="glyphicon glyphicon-time"></span> ${severity}</p>
<p><span class="glyphicon glyphicon-user"></span> ${assignedTo}</p>
<button type="button" id="closeBtn" class="btn btn-warning" onclick="setStatusClosed('${i}')">Close</button>
<button type="button" id="openBtn" class="btn btn-primary" style="display:none;" onclick="setStatusOpen('${i}')">Open</button>
<button type="button" id="updateIssueBtn" class="btn btn-primary" onclick="EditIssue(${i})">Update</button>
</div>
`;
}
}
function closeIssues1() {
var issuesList = document.getElementById('issuesList');
issuesList.innerHTML = '';
for (var i = 0; i < data.length; i++) {
var id = data[i].id;
var desc = data[i].description;
var severity = data[i].severity;
var assignedTo = data[i].assignedTo;
var status = data[i].status;
issuesList.innerHTML += `
<div class="well">
<h6>Issue ID: ${id}</h6>
<p><span class="label label-info" id="issueStatus">Status: ${status}</span></p>
<h3>${desc}</h3>
<p><span class="glyphicon glyphicon-time"></span> ${severity}</p>
<p><span class="glyphicon glyphicon-user"></span> ${assignedTo}</p>
<button type="button" id="deleteBtn" class="btn btn-danger" onclick="deleteIssue('${id}')">Delete</button>
<button type="button" id="openBtn1" class="btn btn-primary" onclick="setStatusOpen1('${i}')">Open</button>
</div>
`;
}
}
function OpenIssues1() {
var issuesList = document.getElementById('issuesList');
issuesList.innerHTML = '';
for (var i = 0; i < data.length; i++) {
var id = data[i].id;
var desc = data[i].description;
var severity = data[i].severity;
var assignedTo = data[i].assignedTo;
var status = data[i].status;
issuesList.innerHTML += `
<div class="well">
<h6>Issue ID: ${id}</h6>
<p><span class="label label-info" id="issueStatus">Status: ${status}</span></p>
<h3>${desc}</h3>
<p><span class="glyphicon glyphicon-time"></span> ${severity}</p>
<p><span class="glyphicon glyphicon-user"></span> ${assignedTo}</p>
<button type="button" id="closeBtn" class="btn btn-warning" onclick="setStatusClosed('${i}')">Close</button>
<button type="button" id="updateIssueBtn" class="btn btn-primary" onclick="EditIssue(${i})">Update</button>
</div>
`;
}
}
document.getElementById('issueInputForm').addEventListener('submit', saveIssue);
fetchIssues();