OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2011 Google 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 ui = ui || {}; | |
27 ui.notifications = ui.notifications || {}; | |
28 | |
29 (function(){ | |
30 | |
31 var kMaxTestsPerGroup = 3; | |
32 | |
33 ui.notifications.Stream = base.extends('ol', { | |
34 init: function() | |
35 { | |
36 this.className = 'notifications'; | |
37 }, | |
38 add: function(notification) | |
39 { | |
40 var insertBefore = null; | |
41 Array.prototype.some.call(this.children, function(existingNotification)
{ | |
42 if (existingNotification.index() < notification.index()) { | |
43 insertBefore = existingNotification; | |
44 return true; | |
45 } | |
46 }); | |
47 this.insertBefore(notification, insertBefore); | |
48 return notification; | |
49 } | |
50 }); | |
51 | |
52 ui.notifications.Notification = base.extends('li', { | |
53 init: function() | |
54 { | |
55 this._how = this.appendChild(document.createElement('div')); | |
56 this._how.className = 'how'; | |
57 this._what = this.appendChild(document.createElement('div')); | |
58 this._what.className = 'what'; | |
59 this._index = 0; | |
60 $(this).hide().fadeIn('fast'); | |
61 }, | |
62 index: function() | |
63 { | |
64 return this._index; | |
65 }, | |
66 setIndex: function(index) | |
67 { | |
68 this._index = index; | |
69 }, | |
70 dismiss: function() | |
71 { | |
72 // FIXME: These fade in/out effects are lame. | |
73 $(this).fadeOut(function() | |
74 { | |
75 this.parentNode && this.parentNode.removeChild(this); | |
76 }); | |
77 }, | |
78 }); | |
79 | |
80 ui.notifications.Info = base.extends(ui.notifications.Notification, { | |
81 init: function(message) | |
82 { | |
83 this.update(message); | |
84 }, | |
85 update: function(message) | |
86 { | |
87 this._what.textContent = message; | |
88 }, | |
89 updateWithNode: function(node) | |
90 { | |
91 $(this._what).empty(); | |
92 this._what.appendChild(node); | |
93 } | |
94 }); | |
95 | |
96 ui.notifications.FailingTestGroup = base.extends('li', { | |
97 init: function(groupName, testNameList) | |
98 { | |
99 this.appendChild(base.createLinkNode(ui.urlForFlakinessDashboard(testNam
eList), groupName, '_blank')); | |
100 } | |
101 }); | |
102 | |
103 var Cause = base.extends('li', { | |
104 init: function() | |
105 { | |
106 this._description = this.appendChild(document.createElement('div')); | |
107 this._description.className = 'description'; | |
108 } | |
109 }); | |
110 | |
111 ui.notifications.SuspiciousCommit = base.extends(Cause, { | |
112 init: function(commitData) | |
113 { | |
114 this._revision = commitData.revision; | |
115 this._description.appendChild(base.createLinkNode(trac.changesetURL(comm
itData.revision), commitData.revision, '_blank')); | |
116 this._details = this._description.appendChild(document.createElement('sp
an')); | |
117 this._addDetail('summary', commitData); | |
118 this._addDetail('author', commitData); | |
119 this._addDetail('reviewer', commitData); | |
120 this._addDetail('bugID', commitData, bugzilla.bugURL); | |
121 }, | |
122 hasRevision: function(revision) | |
123 { | |
124 return this._revision == revision; | |
125 }, | |
126 _addDetail: function(part, commitData, linkFunction) | |
127 { | |
128 var content = commitData[part]; | |
129 if (!content) | |
130 return; | |
131 | |
132 var span = this._details.appendChild(document.createElement('span')); | |
133 span.className = part; | |
134 | |
135 if (linkFunction) { | |
136 var link = base.createLinkNode(linkFunction(content), content, '_bla
nk'); | |
137 span.appendChild(link); | |
138 } else | |
139 span.textContent = content; | |
140 } | |
141 }); | |
142 | |
143 ui.notifications.Failure = base.extends(ui.notifications.Notification, { | |
144 init: function() | |
145 { | |
146 this._time = this._how.appendChild(new ui.RelativeTime()); | |
147 this._problem = this._what.appendChild(document.createElement('div')); | |
148 this._problem.className = 'problem'; | |
149 this._effects = this._problem.appendChild(document.createElement('ul')); | |
150 this._effects.className = 'effects'; | |
151 this._causes = this._what.appendChild(document.createElement('ul')); | |
152 this._causes.className = 'causes'; | |
153 }, | |
154 date: function() | |
155 { | |
156 return this._time.date; | |
157 } | |
158 }); | |
159 | |
160 ui.notifications.FailingTests = base.extends(ui.notifications.Failure, { | |
161 init: function() { | |
162 // FIXME: Convert actions to a link from test! | |
163 this._problem.appendChild(new ui.actions.List([ | |
164 new ui.actions.Examine().makeDefault(), | |
165 new ui.actions.Rebaseline(), | |
166 ])); | |
167 this._testNameList = []; | |
168 }, | |
169 testNameList: function() | |
170 { | |
171 return this._testNameList; | |
172 }, | |
173 containsFailureAnalysis: function(failureAnalysis) | |
174 { | |
175 return this._testNameList.indexOf(failureAnalysis.testName) != -1; | |
176 }, | |
177 addFailureAnalysis: function(failureAnalysis) | |
178 { | |
179 if (this.containsFailureAnalysis(failureAnalysis)) | |
180 return false; | |
181 this._testNameList.push(failureAnalysis.testName); | |
182 $(this._effects).empty(); | |
183 this._forEachTestGroup(function(groupName, testNameList) { | |
184 this._effects.appendChild(new ui.notifications.FailingTestGroup(grou
pName, testNameList)) | |
185 }.bind(this)); | |
186 return true; | |
187 }, | |
188 _forEachTestGroup: function(callback) | |
189 { | |
190 var individualTests = []; | |
191 base.forEachDirectory(this._testNameList, function(groupLabel, testsInDi
rectory) { | |
192 if (testsInDirectory.length <= kMaxTestsPerGroup) { | |
193 individualTests = individualTests.concat(testsInDirectory); | |
194 return; | |
195 } | |
196 callback(groupLabel, testsInDirectory); | |
197 }); | |
198 individualTests.forEach(function(testName) { | |
199 callback(testName, [testName]); | |
200 }); | |
201 } | |
202 }); | |
203 | |
204 ui.notifications.FailingTestsSummary = base.extends(ui.notifications.FailingTest
s, { | |
205 init: function() { | |
206 this._where = this._how.appendChild(new ui.failures.FailureGrid()); | |
207 this._commitDataPinned = false; | |
208 }, | |
209 purge: function() { | |
210 this._where.purge(); | |
211 }, | |
212 updateBuilderResults: function(resultNodesByBuilder) | |
213 { | |
214 this._where.update(resultNodesByBuilder); | |
215 }, | |
216 addFailureAnalysis: function(failureAnalysis) | |
217 { | |
218 this.updateBuilderResults(failureAnalysis.resultNodesByBuilder); | |
219 if (!ui.notifications.FailingTests.prototype.addFailureAnalysis.call(thi
s, failureAnalysis)) | |
220 return false; | |
221 }, | |
222 pinToCommitData: function(commitData) | |
223 { | |
224 if (this._commitDataPinned) | |
225 return; | |
226 this._commitDataPinned = true; | |
227 $(this._causes).children().each(function() { | |
228 if (this.hasRevision(commitData.revision)) | |
229 return; | |
230 $(this).detach(); | |
231 }); | |
232 }, | |
233 addCommitData: function(commitData) | |
234 { | |
235 if (this._commitDataPinned) | |
236 return null; | |
237 var commitDataDate = new Date(commitData.time); | |
238 if (this._time.date > commitDataDate); { | |
239 this.setIndex(commitDataDate.getTime()); | |
240 this._time.setDate(commitDataDate); | |
241 } | |
242 return this._causes.appendChild(new ui.notifications.SuspiciousCommit(co
mmitData)); | |
243 } | |
244 }); | |
245 | |
246 ui.notifications.BuildersFailing = base.extends(ui.notifications.Failure, { | |
247 init: function(message) | |
248 { | |
249 this._problem.insertBefore(document.createTextNode(message + ':'), this.
_problem.firstChild); | |
250 }, | |
251 setFailingBuilders: function(failuresList) | |
252 { | |
253 $(this._effects).empty().append(Object.keys(failuresList).map(function(b
uilderName) { | |
254 var effect = document.createElement('li'); | |
255 effect.className = 'builder'; | |
256 effect.appendChild(new ui.failures.Builder(builderName, failuresList
[builderName])); | |
257 return effect; | |
258 })); | |
259 } | |
260 }); | |
261 | |
262 })(); | |
OLD | NEW |