-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
134 lines (111 loc) · 4.55 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
document.getElementById('issueInputForm').addEventListener('submit', saveIssue);
document.getElementById('issueInputForm').addEventListener('reset', showHideJumbotron);
function fetchIssues(status = 'all'){
var issues = [];
if (status == 'all') {
issues = JSON.parse(localStorage.getItem('issues'));
} else {
issues = JSON.parse(localStorage.getItem('issues'))
if (issues.length > 0){
issues = issues.filter((i) => i.status === status);
}
}
var issuesList = document.getElementById('issuesList');
if (typeof issues != "undefined"
&& issues != null
&& issues.length != null
&& issues.length > 0) {
issuesList.innerHTML = '';
for (var i = 0; i < issues.length; i++){
var id = issues[i].id;
var title = issues[i].title;
var desc = issues[i].description;
var severity = issues[i].severity;
var assignedTo = issues[i].assignedTo;
var status = issues[i].status;
issuesList.innerHTML += '<div class="well">' +
'<p><a href="#" onclick="openIssue(\''+id+'\')" class="label label-info">' + status + '</a></p>'+
'<h3>' + title + '</h3>'+
'<h5>' + desc + '</h5>' +
'<p><span class="glyphicon glyphicon-time"></span> ' + severity + ' '+
'<span class="glyphicon glyphicon-user"></span> ' + assignedTo + '</p>'+
'<a href="#" class="btn btn-warning" onclick="setStatusClosed(\''+id+'\')">Close</a> '+
'<a href="#" class="btn btn-danger" onclick="deleteIssue(\''+id+'\')">Delete</a>'+
'<h6>Issue ID: ' + id + '</h6>'
'</div>';
}
} else {
issuesList.innerHTML = '<p>No issues to show</p>'
}
}
function saveIssue(e){
var issueId = chance.guid();
var issueTitle = document.getElementById('issueTitleInput').value;
var issueDesc = document.getElementById('issueDescInput').value;
var issueSeverity = document.getElementById('issueSeverityInput').value;
var issueAssignedTo = document.getElementById('issueAssignedToInput').value;
var issueStatus = 'Open';
var issue = {
id: issueId,
title: issueTitle,
description: issueDesc,
severity: issueSeverity,
assignedTo: issueAssignedTo,
status: issueStatus
}
if (localStorage.getItem('issues') === null){
var issues = [];
issues.push(issue);
localStorage.setItem('issues', JSON.stringify(issues));
} else {
var issues = JSON.parse(localStorage.getItem('issues'));
issues.push(issue);
localStorage.setItem('issues', JSON.stringify(issues));
}
document.getElementById('issueInputForm').reset();
document.getElementById('addIssue').style.display = "none";
document.getElementById('addButton').innerHTML = "Add New Issue";
fetchIssues();
e.preventDefault();
}
function setStatusClosed (id) {
var issues = JSON.parse(localStorage.getItem('issues'));
for(var i = 0; i < issues.length; i++) {
if (issues[i].id == id) {
issues[i].status = "Closed";
}
}
localStorage.setItem('issues', JSON.stringify(issues));
fetchIssues();
}
function openIssue (id){
var issues = JSON.parse(localStorage.getItem('issues'));
for (var i = 0;i < issues.length; i++){
if (issues[i].status = 'Closed'){
issues[i].status = 'Open';
}
}
localStorage.setItem('issues', JSON.stringify(issues));
fetchIssues();
}
function deleteIssue (id) {
var issues = JSON.parse(localStorage.getItem('issues'));
for(var i = 0; i < issues.length; i++) {
if (issues[i].id == id) {
issues.splice(i, 1);
}
}
localStorage.setItem('issues', JSON.stringify(issues));
fetchIssues();
}
function showHideJumbotron(){
var addIssue = document.getElementById("addIssue");
var closeAddIssue = document.getElementById("addButton");
if (addIssue.style.display === "none") {
addIssue.style.display = "block";
closeAddIssue.innerHTML = "Hide New Issue";
} else {
addIssue.style.display = "none";
closeAddIssue.innerHTML = "Add New Issue";
}
}