forked from stefankendall/AppTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
447 lines (346 loc) · 16.9 KB
/
App.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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/*
BuildActionBoard -
https://github.com/skandl/BuildActionBoard
A Rally webapp that provides at-a-glance continuous integration build status.
Integrates with CI Build Report and Build Breakdown apps to display add'l info
on specific builds clicked in this app.
11/15 - fixed bugs
*/
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
layout: {
type: 'fit'
},
launch: function() {
this._loadBuildDefs();
},
// Creates a query for specific build definitions
_createQuery: function(buildDefRecords) {
// get first entry
var q = Ext.create('Rally.data.QueryFilter', {
property: 'BuildDefinition',
operator: '=',
value: buildDefRecords[0].get('_ref')
// value: '/slm/webservice/1.37/builddefinition/6035424766' //PacSystems Mainline Build Definition
});
// remove teh first entry
Ext.Array.remove(buildDefRecords, buildDefRecords[0]);
// cycle through the remaineder in the array
Ext.Array.forEach(buildDefRecords, function(item, index, allItems) {
q = q.or(Ext.create('Rally.data.QueryFilter', {
property: 'BuildDefinition',
operator: '=',
value: item.get('_ref')
}));
});
//console.log("query = ", q.toString());
return q;
},
_getBuilds: function(buildDefRecords) {
var query = this._createQuery(buildDefRecords);
Ext.create('Rally.data.WsapiDataStore', {
model: 'Build',
fetch: true,
listeners: {
load: function(store, records, success) {
console.log("Fetched %d builds", records.length);
Ext.Array.forEach(records, function(item) {
// console.log("Name: %s, Def: %s, Status %s", item.get("Number"), item.get("BuildDefinition")._ref, item.get("Status"));
});
this._siftBuilds(records);
},
scope: this
},
sorters: [{
property: 'CreationDate',
direction: 'DESC'
}],
filters: query,
autoLoad: true,
pageSize: 100
});
},
_loadBuildDefs: function() {
Ext.create('Rally.data.WsapiDataStore', {
model: 'Build Definition',
fetch: true,
listeners: {
load: function(store, records, success) {
console.log("Loaded %d Build Definitions.", records.length);
this.buildDefinitions = [];
Ext.Array.forEach(records, function(item) {
Ext.Array.push(this.buildDefinitions, item.get("_ref"));
}, this);
//console.log("Build definitions array ", this.buildDefinitions);
this._getBuilds(records);
},
scope: this
},
autoLoad: true
});
},
// creates the build def/ build record data struct
_siftBuilds: function(buildDefBuildRecords) {
var buildStructure = {};
// Create a build structure
Ext.Array.forEach(buildDefBuildRecords, function(item) {
build = item;
buildDef = item.get("BuildDefinition")._ref;
//console.log(item.get("BuildDefinition"));
if (!buildStructure.hasOwnProperty(buildDef)) {
buildStructure[buildDef] = {
buildDefName: item.get("BuildDefinition")._refObjectName,
builds: [build],
lastBuild: null,
failCount: 0,
successCount: 0
};
// console.log("Added new build def %s",buildDef);
}
else {
Ext.Array.push(buildStructure[buildDef].builds, build);
// console.log("Pushed build %s",item.get("Number"));
}
});
//Now update the lastGoodBuild and failCount fields
// for each build ref
// for each build
// if build failed
// increment failCount
// else
// set lastGoodBuild
// break;
Ext.Array.forEach(this.buildDefinitions, function(item) {
var buildDef = item;
//console.log("Working on %s",buildDef);
// Handle empty builds.
if(buildStructure[buildDef] === undefined)
{
//console.log("empty build, bailing.");
return;
}
buildStructure[buildDef].failCount = 0;
Ext.Array.forEach(buildStructure[item].builds, function(item) {
var build = item;
// if we already found a good build, just return
if (buildStructure[buildDef].lastGoodBuild != null)
{
return;
}
// look at the current build
if (build.get("Status") === "FAILURE") {
if (buildStructure[buildDef].lastGoodBuild == undefined) {
buildStructure[buildDef].failCount = buildStructure[buildDef].failCount + 1;
//console.log("%s failed, failCount %d",build.get("Number"), buildStructure[buildDef].failCount);
}
else {
return;
}
}
else {
//console.log("%s succeeded, failCount %d",build.get("Number"), buildStructure[buildDef].failCount);
buildStructure[buildDef].lastGoodBuild = build;
buildStructure[buildDef].lastGoodBuildDate = build.get("CreationDate");
return;
}
});
console.log("Build %s Fails %d", buildDef, buildStructure[buildDef].failCount);
});
//Now update the successCount
// for each build ref
// for each build
// if build succeeded
// increment successCount
// else
// set foundFailedBuild
// break;
Ext.Array.forEach(this.buildDefinitions, function(item) {
var buildDef = item;
if(buildStructure[buildDef] === undefined)
{
//console.log("empty build, bailing.");
return;
}
buildStructure[buildDef].successCount = 0;
var foundFail = false;
Ext.Array.forEach(buildStructure[item].builds, function(item) {
var build = item;
// if we already found a good build, just return
if (foundFail)
{
return;
}
// look at the current build
if (build.get("Status") === "SUCCESS") {
buildStructure[buildDef].successCount = buildStructure[buildDef].successCount + 1;
}
else {
foundFail = true;
}
});
console.log("Build %s Successes %d", buildDef, buildStructure[buildDef].successCount);
});
console.log("buildStructure");
console.log(buildStructure);
gridFormattedBuilds = [];
var count = 0;
var buildDef = 0;
//format data into a new grid-freindly array
Ext.Array.forEach(this.buildDefinitions, function(item) {
buildDef = item;
if(buildStructure[buildDef] === undefined)
{
//console.log("empty build, bailing.");
return;
}
if(buildStructure[buildDef].lastGoodBuild === undefined)
{
console.log("No last good build, bailing.");
return;
}
gridFormattedBuilds[count] = {};
gridFormattedBuilds[count].Name = buildStructure[buildDef].buildDefName; //i.e : "PACSystems Mainline CI Builds"
//todo: make sure a build exists
gridFormattedBuilds[count].Status = buildStructure[buildDef].builds[0].get("Status");
gridFormattedBuilds[count].CurrentBuild = buildStructure[buildDef].builds[0].get("Number");
gridFormattedBuilds[count].LastGoodBuild = buildStructure[buildDef].lastGoodBuild.get("Number");
gridFormattedBuilds[count].NumFailedBuilds = buildStructure[buildDef].failCount;
gridFormattedBuilds[count].NumSucceededBuilds = buildStructure[buildDef].successCount;
//field for build refs
gridFormattedBuilds[count].CurrentBuildRef = buildStructure[buildDef].builds[0].get('_ref');
gridFormattedBuilds[count].LastGoodBuildRef = buildStructure[buildDef].lastGoodBuild.get('_ref');
//build def ref
gridFormattedBuilds[count].BuildDefinitionRef = buildDef;
count++;
});
console.log("Grid Array:");
console.log(gridFormattedBuilds);
//pipe it into a store
Ext.create('Ext.data.Store', {
storeId: 'ciBuildStore',
fields: ['Name', 'Status', 'CurrentBuild', 'LastGoodBuild', 'NumFailedBuilds', 'NumSucceededBuilds'],
data: gridFormattedBuilds,
sorters: ['Name']
});
// Color
var statusTpl = new Ext.XTemplate(
"<tpl switch='Status'>",
"<tpl case='SUCCESS'>",
"<div style='background-color:#07C600; width:100%; padding: 3px'> {Status}; </div>",
"<tpl default>",
"<div style='background-color:#FF0000; width:100%; padding: 3px'> {Status}; </div>",
"</tpl>");
var currentBuildTpl = new Ext.XTemplate(
"<tpl switch='Status'>",
"<tpl case='SUCCESS'>",
"<div style='background-color:#07C600; color:#FFF;font-weight:bold; width:100%; padding: 3px'> {CurrentBuild} </div>",
"<tpl default>",
"<div style='background-color:#FF0000; color:#FFF;font-weight:bold; width:100%; padding: 3px'> {CurrentBuild} </div>",
"</tpl>");
var lastGoodBuildTpl = new Ext.XTemplate(
"<tpl>",
"<div style='background-color:#07C600; color:#FFF;font-weight:bold; width:100%; padding: 3px'> {LastGoodBuild} </div>",
"</tpl>");
var myGrid = Ext.create('Ext.grid.Panel', {
// title: 'Build Status',
store: Ext.data.StoreManager.lookup('ciBuildStore'),
columns: [
{ text: 'Name', dataIndex: 'Name', width: 205 , flex: 1},
// { text: 'Status', dataIndex: 'Status', flex: 1, xtype: 'templatecolumn', tpl: statusTpl},
{ text: 'Current Build', dataIndex: 'CurrentBuild', width: 120, flex: 2, xtype: 'templatecolumn', tpl: currentBuildTpl},
{ text: 'Last Good Build', dataIndex: 'LastGoodBuild', width: 120, flex: 2, xtype: 'templatecolumn', tpl: lastGoodBuildTpl },
{ text: 'Fails', dataIndex: 'NumFailedBuilds', width: 35, tooltip: 'Number of failed builds since the last success', tooltipType: "qtip"},
{ text: 'Successes', dataIndex: 'NumSucceededBuilds', width: 50, tooltip: 'Number of failed builds since the last success', tooltipType: "qtip"},
// { menuDisabled: true, width: 80, sortable: false, xtype: 'actioncolumn',items: [{
// icon: 'https://raw.github.com/skandl/BuildActionBoard/master/button_build_text.jpg',
// iconCls: 'gotItButton',
// tooltip: 'I got it',
// handler: function(grid, rowIndex, colIndex) {
// console.log("Selected row %d", rowIndex);
// }}],
// },
// { menuDisabled: true, width: 80, sortable: false, xtype: 'actioncolumn',items: [{
// icon: 'https://raw.github.com/skandl/BuildActionBoard/master/button_got_it_text.jpg',
// iconCls: 'gotItButton',
// tooltip: 'I got it',
// handler: function(grid, rowIndex, colIndex) {
// console.log("Selected row %d", rowIndex);
// }}],
// },
// {text: 'Build Savior', dataIndex: 'Owner', flex: 1}
],
listeners: {
cellclick: function(table, td, cellIndex, record, tr, rowIndex){
// If build definition (column 0)
if (cellIndex === 0){
console.log("publishing...." + gridFormattedBuilds[rowIndex].BuildDefinitionRef);
Rally.environment.getMessageBus().publish('buildDefinitionSelected', gridFormattedBuilds[rowIndex].BuildDefinitionRef);
}
// cellIndex 1 is current build
//todo qualify index into array
if (cellIndex === 1)
{
// Publish the selected build
console.log(gridFormattedBuilds[rowIndex].CurrentBuildRef);
Rally.environment.getMessageBus().publish('buildSelected', gridFormattedBuilds[rowIndex].CurrentBuildRef);
Rally.environment.getMessageBus().publish('buildDefinitionSelected', gridFormattedBuilds[rowIndex].BuildDefinitionRef);
// Publish the number of days since the last working build
var currBuildRef = gridFormattedBuilds[rowIndex].BuildDefinitionRef;
var dateBrokenBuild = buildStructure[currBuildRef].lastGoodBuild.get('CreationDate');
console.log(dateBrokenBuild);
var dateBrokenBuild_date = new Date(dateBrokenBuild);
var elapsed_ms = Ext.Date.getElapsed(dateBrokenBuild_date);
var elapsed_days = elapsed_ms / 1000 / 60 / 60 / 24;
console.log("elapsed days since build: %d",elapsed_days);
Rally.environment.getMessageBus().publish('daysSinceBuild', elapsed_days);
}
if (cellIndex === 2)
{
console.log(gridFormattedBuilds[rowIndex].CurrentBuildRef);
console.log(gridFormattedBuilds[rowIndex].LastGoodBuildRef);
Rally.environment.getMessageBus().publish('buildSelected', gridFormattedBuilds[rowIndex].LastGoodBuildRef);
Rally.environment.getMessageBus().publish('buildDefinitionSelected', gridFormattedBuilds[rowIndex].BuildDefinitionRef);
// Publish the number of days since the last working build
var currBuildRef = gridFormattedBuilds[rowIndex].BuildDefinitionRef;
var dateBrokenBuild = buildStructure[currBuildRef].lastGoodBuild.get('CreationDate');
console.log(dateBrokenBuild);
var dateBrokenBuild_date = new Date(dateBrokenBuild);
var elapsed_ms = Ext.Date.getElapsed(dateBrokenBuild_date);
var elapsed_days = elapsed_ms / 1000 / 60 / 60 / 24;
console.log("elapsed days since build: %d",elapsed_days);
Rally.environment.getMessageBus().publish('daysSinceBuild', elapsed_days);
}
console.log("cell click %d %d",cellIndex, rowIndex);
}
}
// plugins: [{
// ptype: 'rowexpander',
// rowBodyTpl: new Ext.XTemplate('foo')
// }],
// collapsible: true,
// animCollapse: false
});
this.add(myGrid);
}
/* // Creates a table using Rally ui
Rally.data.ModelFactory.getModel({
type:'Build Definition',
scope:this,
success: function(model){
var myGrid = Ext.create('Rally.ui.grid.Grid',{
model: model,
columnCfgs: [
'Name',
'Description',
'LastStatus'
]
});
this.add(myGrid);
},
context: {
workspace: "/workspace/4365660833"
}
});
*/
});