There should be a way to associate bugs with analysis tasks
[WebKit-https.git] / Websites / perf.webkit.org / public / v2 / analysis.js
1 App.AnalysisTask = App.NameLabelModel.extend({
2     author: DS.attr('string'),
3     createdAt: DS.attr('date'),
4     platform: DS.belongsTo('platform'),
5     metric: DS.belongsTo('metric'),
6     startRun: DS.attr('number'),
7     endRun: DS.attr('number'),
8     bugs: DS.hasMany('bugs'),
9     testGroups: function () {
10         return this.store.find('testGroup', {task: this.get('id')});
11     }.property(),
12     label: function () {
13         var label = this.get('name');
14         var bugs = this.get('bugs').map(function (bug) { return bug.get('label'); }).join(' / ');
15         return bugs ? label + ' (' + bugs + ')' : label;
16     }.property('name', 'bugs'),
17 });
18
19 App.Bug = App.Model.extend({
20     task: DS.belongsTo('AnalysisTask'),
21     bugTracker: DS.belongsTo('BugTracker'),
22     createdAt: DS.attr('date'),
23     number: DS.attr('number'),
24     label: function () {
25         return this.get('bugTracker').get('label') + ': ' + this.get('number');
26     }.property('name', 'bugTracker'),
27 });
28
29 // FIXME: Use DS.RESTAdapter instead.
30 App.AnalysisTask.create = function (name, startMeasurement, endMeasurement)
31 {
32     return PrivilegedAPI.sendRequest('create-analysis-task', {
33         name: name,
34         startRun: startMeasurement.id(),
35         endRun: endMeasurement.id(),
36     });
37 }
38
39 App.AnalysisTaskAdapter = DS.RESTAdapter.extend({
40     buildURL: function (type, id)
41     {
42         return '../api/analysis-tasks/' + (id ? id : '');
43     },
44 });
45
46 App.BugAdapter = DS.RESTAdapter.extend({
47     createRecord: function (store, type, record)
48     {
49         var param = {
50             task: record.get('task').get('id'),
51             bugTracker: record.get('bugTracker').get('id'),
52             number: record.get('number'),
53         };
54         return PrivilegedAPI.sendRequest('associate-bug', param).then(function (data) {
55             param['id'] = data['bugId'];
56             return {'bug': param};
57         });
58     }
59 });
60
61 App.TestGroup = App.NameLabelModel.extend({
62     analysisTask: DS.belongsTo('analysisTask'),
63     author: DS.attr('string'),
64     createdAt: DS.attr('date'),
65     buildRequests: DS.hasMany('buildRequests'),
66 });
67
68 App.TestGroupAdapter = DS.RESTAdapter.extend({
69     buildURL: function (type, id)
70     {
71         return '../api/test-groups/' + (id ? id : '');
72     },
73 });
74
75 App.AnalysisTaskSerializer = App.TestGroupSerializer = DS.RESTSerializer.extend({
76     normalizePayload: function (payload)
77     {
78         delete payload['status'];
79         return payload;
80     }
81 });
82
83 App.BuildRequest = App.Model.extend({
84     group: DS.belongsTo('testGroup'),
85     order: DS.attr('number'),
86     rootSet: DS.attr('number'),
87     build: DS.attr('number'),
88     buildNumber: DS.attr('number'),
89     buildBuilder: DS.belongsTo('builder'),
90     buildTime: DS.attr('date'),
91 });