forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBugzillaTrackerCSSRegions.js
More file actions
167 lines (128 loc) · 5.62 KB
/
BugzillaTrackerCSSRegions.js
File metadata and controls
167 lines (128 loc) · 5.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
(function(){
function getIssuesFromDocument(){
var list = {},
issues = document.querySelectorAll(".issue-marker");
if (issues){
// make issue an array
issues = Array.prototype.slice.call(issues);
// pluck out the bug data from the DOM object
issues.forEach(function(issue){
var bugId = issue.dataset["bug_id"];
if (bugId){
list[bugId] = {
"bug_status": issue.dataset["bug_status"],
"short_desc": issue.querySelector(".short-desc").innerText
}
}
})
}
return list;
}
// Decorate the issues received from the sever with their state related to the issues in the page (new, changed)
function setIssueStates(serverIssues, documentIssues){
var serverIssue, documentIssue;
if (!serverIssues){
throw new TypeError("Missing 'serverIssues' from server. Expected Object, got "+ typeof serverIssues)
}
if (!documentIssues){
throw new TypeError("Missing 'documentIssues' from document. Expected Object, got "+ typeof documentIssues)
}
for (var bugId in serverIssues){
serverIssue = serverIssues[bugId];
documentIssue = documentIssues[bugId];
// is the bug in the doument?
if (documentIssues[bugId]){
// bug status has changed. it's an updated issue
if ( (documentIssue.bug_status !== serverIssue.bug_status) ||
(documentIssue.short_desc !== serverIssue.short_desc) ){
serverIssue.issue_state = "updated";
}
}
else{
// not found in the document. it's a new issue if the bug_status
// is not RESOLVED
if (serverIssue.bug_status === "RESOLVED") {
serverIssue.issue_state = 'resolved';
} else {
serverIssue.issue_state = "new";
}
}
}
return serverIssues;
}
// "this" is bound to the "BugzillaTracker" instance
function renderIssues(serverIssues){
if (!serverIssues && !serverIssues.length){
return;
}
// get a list of bugs from the document
var documentIssues = getIssuesFromDocument();
// get the bugs list with the updated state (not bug status) related to the bugs already in the page
var issueList = setIssueStates(serverIssues, documentIssues);
var fragment = document.createDocumentFragment();
for (var issueId in issueList){
// bind the bug data to the bug template
var issueFragment = this.renderIssue(issueList[issueId]);
var wrapper = document.createElement("div");
var trigger = document.createElement("a");
trigger.className = "issue-markup-trigger";
trigger.href = "#";
trigger.innerHTML = "toggle markup"
if (issueList[issueId]["issue_state"]){
wrapper.setAttribute("data-issue_state", issueList[issueId]["issue_state"]);
}
wrapper.appendChild(trigger);
wrapper.appendChild(issueFragment);
fragment.appendChild(wrapper);
}
var issueListContainer = document.querySelector("#issue-list");
issueListContainer.appendChild(fragment);
// show/hide the markup for a bug entry
issueListContainer.addEventListener("click", toggleMarkup);
}
function toggleMarkup(e){
if (e.target.className && e.target.classList.contains("issue-markup-trigger")){
e.preventDefault();
var parent = e.target.parentNode,
issueEl = parent.querySelector(".issue-marker"),
markup = issueEl.outerHTML;
parent.classList.toggle("showMarkup");
// already generated the markup
if (parent.querySelector("pre")){
return
}
else{
var pre = document.createElement("pre");
pre.textContent = markup;
parent.appendChild(pre);
}
}
}
function filterIssues(e){
if (e.target.name !== "issue-filter"){
return
}
var issueManager = document.querySelector("#issue-manager");
switch(e.target.value){
case "all":
issueManager.removeAttribute("data-view_state");
break;
case "new":
issueManager.setAttribute("data-view_state", "new");
break;
case "updated":
issueManager.setAttribute("data-view_state", "updated");
break;
}
}
document.addEventListener("DOMContentLoaded", function(){
BugzillaTracker.setIssueTemplate(document.querySelector("#issue-template").innerHTML);
BugzillaTracker.sync(
{
product: "CSS",
component: "CSS Regions",
},
renderIssues);
document.querySelector("#issue-manager form").addEventListener("change", filterIssues)
})
})()