-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
68 lines (59 loc) · 2.61 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
document.getElementById('issueInputForm').addEventListener('submit', submitIssue);
function submitIssue(e) {
const getInputValue = id => document.getElementById(id).value;
const description = getInputValue('issueDescription');
const severity = getInputValue('issueSeverity');
const assignedTo = getInputValue('issueAssignedTo');
const id = Math.floor(Math.random()*100000000) + '';
const status = 'Open';
const issue = { id, description, severity, assignedTo, status };
let issues = [];
if (localStorage.getItem('issues')){
issues = JSON.parse(localStorage.getItem('issues'));
}
issues.push(issue);
localStorage.setItem('issues', JSON.stringify(issues));
document.getElementById('issueInputForm').reset();
fetchIssues();
e.preventDefault();
}
const closeIssue = id => {
const issues = JSON.parse(localStorage.getItem('issues'));
const currentIssue = issues.find(issue => issue.id === id+'');
currentIssue.status = 'Closed';
localStorage.setItem('issues', JSON.stringify(issues));
fetchIssues();
}
const deleteIssue = id => {
const issues = JSON.parse(localStorage.getItem('issues'));
const remainingIssues = issues.filter( issue => issue.id !== id+'');
localStorage.setItem('issues', JSON.stringify(remainingIssues));
fetchIssues();
}
const fetchIssues = () => {
const issues = JSON.parse(localStorage.getItem('issues'));
const issuesList = document.getElementById('issuesList');
issuesList.innerHTML = '';
let openIssueCount = 0;
for (var i = 0; i < issues.length; i++) {
const {id, description, severity, assignedTo, status} = issues[i];
if(status === 'Open') openIssueCount++;
let style = '';
if(status === 'Closed') {
style = `text-decoration: line-through;
text-decoration-color: red;
text-decoration-style: double;
`;
}
issuesList.innerHTML += `<div class="well">
<h6>Issue ID: ${id} </h6>
<p><span class="label label-info"> ${status} </span></p>
<h3 style="${style}"> ${description} </h3>
<p><span class="glyphicon glyphicon-time"></span> ${severity}</p>
<p><span class="glyphicon glyphicon-user"></span> ${assignedTo}</p>
<a href="#" onclick="closeIssue(${id})" class="btn btn-warning">Close</a>
<a href="#" onclick="deleteIssue(${id})" class="btn btn-danger">Delete</a>
</div>`;
}
document.getElementById('issue-count').innerText = `${openIssueCount} / ${issues.length}`;
}