This repository has been archived by the owner on Nov 10, 2017. It is now read-only.
/
controller.js
74 lines (64 loc) · 2.97 KB
/
controller.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
"use strict";
treeherder.controller('BugsPluginCtrl', [
'$scope', 'ThLog', 'ThJobArtifactModel','$q', 'thTabs',
function BugsPluginCtrl(
$scope, ThLog, ThJobArtifactModel, $q, thTabs) {
var $log = new ThLog(this.constructor.name);
$log.debug("bugs plugin initialized");
var timeout_promise = null;
var bug_limit = 20;
$scope.tabs = thTabs.tabs;
// update function triggered by the plugins controller
thTabs.tabs.failureSummary.update = function(){
var newValue = thTabs.tabs.failureSummary.contentId;
$scope.suggestions = [];
if(angular.isDefined(newValue)){
thTabs.tabs.failureSummary.is_loading = true;
// if there's a ongoing request, abort it
if (timeout_promise !== null) {
timeout_promise.resolve();
}
timeout_promise = $q.defer();
ThJobArtifactModel.get_list({
name: "Bug suggestions",
"type": "json",
job_id: newValue
}, {timeout: timeout_promise})
.then(function(artifact_list){
// using a temporary array here to not trigger a
// dirty check for every element pushed
var suggestions = [];
if(artifact_list.length > 0){
var artifact = artifact_list[0];
angular.forEach(artifact.blob, function (suggestion) {
// Workaround logs ingested prior to the fix for
// bug 1059306 landing.
if(!suggestion.bugs){
suggestion.bugs = {"open_recent":[], "all_others":[]};
}
suggestion.bugs.too_many_open_recent = (
suggestion.bugs.open_recent.length > bug_limit
);
suggestion.bugs.too_many_all_others = (
suggestion.bugs.all_others.length > bug_limit
);
suggestion.open_recent_hidden = (
suggestion.bugs.too_many_open_recent ||
suggestion.bugs.open_recent.length === 0
);
suggestion.all_others_hidden = (
suggestion.bugs.too_many_all_others ||
suggestion.bugs.all_others.length === 0
);
suggestions.push(suggestion);
});
$scope.suggestions = suggestions;
}
})
.finally(function () {
thTabs.tabs.failureSummary.is_loading = false;
});
}
};
}
]);