Dashboard code restructuring
[WebKit-https.git] / Tools / BuildSlaveSupport / build.webkit.org-config / public_html / dashboard / Scripts / Main.js
1 /*
2  * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 var hasBubbles = typeof bubbleQueueServer != "undefined";
27 var BubblesCategory = "bubbles";
28
29 if (!categorizedQueuesByPlatformAndBuildType)
30     var categorizedQueuesByPlatformAndBuildType = {};
31 var platformsByFamily = {};
32
33 for (var i = 0; i < buildbots.length; ++i) {
34     var buildbot = buildbots[i];
35     for (var id in buildbot.queuesInfo) {
36         if (buildbot.queuesInfo[id].combinedQueues) {
37             var info = buildbot.queuesInfo[id];
38             var queue = {
39                 id: id,
40                 branches: info.branches,
41                 platform: info.platform.name,
42                 heading: info.heading,
43                 builder: info.builder,
44                 combinedQueues: Object.keys(info.combinedQueues).map(function(combinedQueueID) { return buildbot.queues[combinedQueueID]; }),
45             };
46         } else
47             var queue = buildbot.queues[id];
48
49         var platformName = queue.platform;
50         var platform = categorizedQueuesByPlatformAndBuildType[platformName];
51         if (!platform)
52             platform = categorizedQueuesByPlatformAndBuildType[platformName] = {};
53         if (!platform.builders)
54             platform.builders = [];
55
56         var categoryName;
57         if ("combinedQueues" in queue)
58             if (queue.builder)
59                 categoryName = "builderCombinedQueues";
60             else
61                 categoryName = "otherCombinedQueues"
62         else if (queue.builder)
63             categoryName = "builders";
64         else if (queue.tester)
65             categoryName = queue.testCategory;
66         else if (queue.performance)
67             categoryName = "performance";
68         else if (queue.leaks)
69             categoryName = "leaks";
70         else if (queue.staticAnalyzer)
71             categoryName = "staticAnalyzer";
72         else {
73             console.assert("Unknown queue type.");
74             continue;
75         }
76
77         category = platform[categoryName];
78         if (!category)
79             category = platform[categoryName] = [];
80
81         category.push(queue);
82     }
83 }
84
85 if (hasBubbles) {
86     for (var id in bubbleQueueServer.queues) {
87         var queue = bubbleQueueServer.queues[id];
88         var platform = categorizedQueuesByPlatformAndBuildType[queue.platform];
89         if (!platform)
90             platform = categorizedQueuesByPlatformAndBuildType[queue.platform] = {};
91         if (!platform.builders)
92             platform.builders = [];
93
94         var categoryName = BubblesCategory;
95
96         platformQueues = platform[categoryName];
97         if (!platformQueues)
98             platformQueues = platform[categoryName] = [];
99
100         platformQueues.push(queue);
101     }
102 }
103
104 var testNames = {};
105 testNames[Buildbot.TestCategory.WebKit2] = "WK2 Tests";
106 testNames[Buildbot.TestCategory.WebKit1] = "WK1 Tests";
107
108 function initPlatformsByFamily()
109 {
110     var platforms = Dashboard.sortedPlatforms;
111     for (var i in platforms) {
112         // Make sure the platform will be displayed on the page before considering its platform family.
113         if (!categorizedQueuesByPlatformAndBuildType[platforms[i].name])
114             continue;
115
116         var platformFamily = settings.parsePlatformFamily(platforms[i].name);
117         if (platformsByFamily[platformFamily])
118             platformsByFamily[platformFamily].push(platforms[i].name)
119         else
120             platformsByFamily[platformFamily] = [platforms[i].name]
121     }
122 }
123
124 function updateHiddenPlatforms()
125 {
126     var hiddenPlatformFamilies = settings.getObject("hiddenPlatformFamilies") || [];
127     var platformRows = document.querySelectorAll("tr.platform");
128     for (var i = 0; i < platformRows.length; ++i)
129         platformRows[i].classList.remove("hidden");
130
131     for (var i = 0; i < hiddenPlatformFamilies.length; ++i) {
132         var platformFamily = hiddenPlatformFamilies[i];
133         for (var j = 0; j < platformsByFamily[platformFamily].length; ++j) {
134             var name = platformsByFamily[platformFamily][j];
135             var platformRow = document.querySelector("tr.platform." + name);
136             if (platformRow)
137                 platformRow.classList.add("hidden");
138         }
139     }
140     settings.updateToggleButtons();
141 }
142
143 function applyAccessibilityColorSetting()
144 {
145     var useAccessibleColors = settings.getObject("accessibilityColorsEnabled");
146     var toggleAccessibilityColorButton = document.getElementById("accessibilityButton");
147     if (useAccessibleColors) {
148         toggleAccessibilityColorButton.textContent = "disable accessibility colors";
149         document.body.classList.toggle("accessibility-colors");
150     } else
151         toggleAccessibilityColorButton.textContent = "enable accessibility colors";
152 }
153
154 function toggleAccessibilityColors()
155 {
156     var isCurrentlyActivated = settings.getObject("accessibilityColorsEnabled");
157     if (isCurrentlyActivated === undefined)
158         isCurrentlyActivated = false;
159     
160     settings.setObject("accessibilityColorsEnabled", !isCurrentlyActivated);
161     document.body.classList.toggle("accessibility-colors");
162     var toggleAccessibilityColorButton = document.getElementById("accessibilityButton");
163     if (!isCurrentlyActivated)
164         toggleAccessibilityColorButton.textContent = "disable accessibility colors";
165     else
166         toggleAccessibilityColorButton.textContent = "enable accessibility colors";
167 }
168
169 function documentReady()
170 {
171     var table = document.createElement("table");
172     table.classList.add("queue-grid");
173
174     var row = document.createElement("tr");
175     row.classList.add("headers");
176
177     var header = document.createElement("th"); 
178     row.appendChild(header);
179
180     header = document.createElement("th");
181     header.textContent = "Builders";
182     row.appendChild(header);
183
184     for (var testerKey in Buildbot.TestCategory) {
185         var header = document.createElement("th");
186         header.textContent = testNames[Buildbot.TestCategory[testerKey]];
187         row.appendChild(header);
188     }
189
190     var header = document.createElement("th");
191     header.textContent = "Other";
192     row.appendChild(header);
193
194     table.appendChild(row);
195
196     var platforms = Dashboard.sortedPlatforms;
197
198     for (var i in platforms) {
199         var platform = platforms[i];
200         var platformQueues = categorizedQueuesByPlatformAndBuildType[platform.name];
201         if (!platformQueues)
202             continue;
203
204         var row = document.createElement("tr");
205         row.classList.add("platform");
206         row.classList.add(platform.name);
207
208         var cell = document.createElement("td");
209         cell.classList.add("logo");
210
211         var logoImage = document.createElement("img");
212         logoImage.classList.add("logo");
213         cell.appendChild(logoImage);
214
215         var ringImage = document.createElement("img");
216         ringImage.classList.add("ring");
217         ringImage.title = platform.readableName;
218         cell.appendChild(ringImage);
219
220         row.appendChild(cell);
221
222         cell = document.createElement("td");
223         var view = new BuildbotBuilderQueueView(platformQueues.builders);
224         cell.appendChild(view.element);
225         row.appendChild(cell);
226
227         if ("builderCombinedQueues" in platformQueues) {
228             for (var i = 0; i < platformQueues.builderCombinedQueues.length; ++i) {
229                 var view = new BuildbotCombinedQueueView(platformQueues.builderCombinedQueues[i]);
230                 cell.appendChild(view.element);
231             }
232         }
233
234         for (var testerKey in Buildbot.TestCategory) {
235             var cell = document.createElement("td");
236
237             var testerProperty = Buildbot.TestCategory[testerKey];
238             if (platformQueues[testerProperty]) {
239                 var view = new BuildbotTesterQueueView(platformQueues[testerProperty]);
240                 cell.appendChild(view.element);
241             }
242
243             row.appendChild(cell);
244         }
245
246         var cell = document.createElement("td");
247         if (platformQueues.performance) {
248             var view = new BuildbotPerformanceQueueView(platformQueues.performance);
249             cell.appendChild(view.element);
250         }
251
252         if (platformQueues.staticAnalyzer) {
253             var view = new BuildbotStaticAnalyzerQueueView(platformQueues.staticAnalyzer);
254             cell.appendChild(view.element);
255         }
256
257         if (platformQueues.leaks) {
258             var view = new BuildbotLeaksQueueView(platformQueues.leaks);
259             cell.appendChild(view.element);
260         }
261
262         if (platformQueues.customView)
263             cell.appendChild(platformQueues.customView.element);
264
265         if (platformQueues[BubblesCategory]) {
266             var view = new BubbleQueueView(platformQueues[BubblesCategory]);
267             cell.appendChild(view.element);
268         }
269
270         if ("otherCombinedQueues" in platformQueues) {
271             for (var i = 0; i < platformQueues.otherCombinedQueues.length; ++i) {
272                 var view = new BuildbotCombinedQueueView(platformQueues.otherCombinedQueues[i]);
273                 cell.appendChild(view.element);
274             }
275         }
276
277         row.appendChild(cell);
278
279         table.appendChild(row);
280     }
281
282     document.body.appendChild(table);
283
284     if (settings.available()) {
285         var settingsButton = document.createElement("div");
286         settingsButton.addEventListener("click", function () { settings.toggleSettingsDisplay(); });
287         settingsButton.classList.add("settings");
288         document.body.appendChild(settingsButton);
289
290         var settingsWrapper = document.createElement("div");
291         settingsWrapper.classList.add("unhide", "hidden", "settingsWrapper")
292
293         var platformFamilyToggleWrapper = document.createElement("div");
294         platformFamilyToggleWrapper.classList.add("unhide", "hidden", "familyToggleWrapper");
295
296         var unhideAllButton = document.createElement("div");
297         unhideAllButton.addEventListener("click", function () { settings.clearHiddenPlatformFamilies(); });
298         unhideAllButton.classList.add("unhide", "hidden", "platformFamilyToggleButton");
299         unhideAllButton.setAttribute("id", "all-platformFamilyToggleButton");
300         unhideAllButton.textContent = "all";
301         platformFamilyToggleWrapper.appendChild(unhideAllButton);
302
303         initPlatformsByFamily();
304         for (var platformFamily in platformsByFamily) {
305             var platformFamilyToggle = document.createElement("div");
306             platformFamilyToggle.addEventListener("click", function () {
307                 settings.toggleHiddenPlatformFamily(this.toString());
308             }.bind(platformFamily));
309             platformFamilyToggle.classList.add("unhide", "hidden", "platformFamilyToggleButton");
310             platformFamilyToggle.setAttribute("id", platformFamily + "-platformFamilyToggleButton");
311             platformFamilyToggle.textContent = platformFamily;
312             platformFamilyToggleWrapper.appendChild(platformFamilyToggle);
313         }
314         settingsWrapper.appendChild(platformFamilyToggleWrapper);
315
316         var toggleAccessibilityColorButton = document.createElement("div");
317         toggleAccessibilityColorButton.addEventListener("click", function() { toggleAccessibilityColors(); });
318         toggleAccessibilityColorButton.classList.add("unhide", "hidden", "accessibilityButton");
319         toggleAccessibilityColorButton.setAttribute("id", "accessibilityButton");
320         toggleAccessibilityColorButton.textContent = "enable accessibility colors";
321         settingsWrapper.appendChild(toggleAccessibilityColorButton);
322         document.body.appendChild(settingsWrapper);
323         applyAccessibilityColorSetting();
324
325         updateHiddenPlatforms();
326         settings.addSettingListener("hiddenPlatformFamilies", updateHiddenPlatforms);
327     }
328 }
329
330 var sortedRepositories = Dashboard.sortedRepositories;
331 for (var i = 0; i < sortedRepositories.length; ++i) {
332     var trac = sortedRepositories[i].trac;
333     if (typeof trac !== "undefined")
334         trac.startPeriodicUpdates();
335 }
336
337 document.addEventListener("DOMContentLoaded", documentReady);