New perf dashboard UI tries to fetch commits all the time
[WebKit-https.git] / Websites / perf.webkit.org / public / v2 / manifest.js
1 App.NameLabelModel = DS.Model.extend({
2     name: DS.attr('string'),
3     label: function ()
4     {
5         return this.get('name');
6     }.property('name'),
7 });
8
9 App.Test = App.NameLabelModel.extend({
10     url: DS.attr('string'),
11     parent: DS.belongsTo('test', {inverse: 'childTests'}),
12     childTests: DS.hasMany('test', {inverse: 'parent'}),
13     metrics: DS.hasMany('metrics'),
14 });
15
16 App.Metric = App.NameLabelModel.extend({
17     test: DS.belongsTo('test'),
18     aggregator: DS.attr('string'),
19     label: function ()
20     {
21         return this.get('name') + ' : ' + this.get('aggregator');
22     }.property('name', 'aggregator'),
23     path: function ()
24     {
25         var path = [];
26         var parent = this.get('test');
27         while (parent) {
28             path.push(parent.get('name'));
29             parent = parent.get('parent');
30         }
31         return path.reverse();
32     }.property('name', 'test'),
33 });
34
35 App.Builder = App.NameLabelModel.extend({
36     buildUrl: DS.attr('string'),
37     urlFromBuildNumber: function (buildNumber)
38     {
39         var template = this.get('buildUrl');
40         return template ? template.replace(/\$buildNumber/g, buildNumber) : null;
41     }
42 });
43
44 App.BugTracker = App.NameLabelModel.extend({
45     buildUrl: DS.attr('string'),
46 });
47
48 App.Platform = App.NameLabelModel.extend({
49     _metricSet: null,
50     _testSet: null,
51     metrics: DS.hasMany('metric'),
52     containsMetric: function (metric)
53     {
54         if (!this._metricSet)
55             this._metricSet = new Ember.Set(this.get('metrics'));
56         return this._metricSet.contains(metric);
57     },
58     containsTest: function (test)
59     {
60         if (!this._testSet) {
61             var set = new Ember.Set();
62             this.get('metrics').forEach(function (metric) {
63                 for (var test = metric.get('test'); test; test = test.get('parent'))
64                     set.push(test);
65             });
66             this._testSet = set;
67         }
68         return this._testSet.contains(test);
69     },
70 });
71
72 App.Repository = App.NameLabelModel.extend({
73     url: DS.attr('string'),
74     blameUrl: DS.attr('string'),
75     hasReportedCommits: DS.attr('boolean'),
76     urlForRevision: function (currentRevision) {
77         return (this.get('url') || '').replace(/\$1/g, currentRevision);
78     },
79     urlForRevisionRange: function (from, to) {
80         return (this.get('blameUrl') || '').replace(/\$1/g, from).replace(/\$2/g, to);
81     },
82 });
83
84 App.MetricSerializer = App.PlatformSerializer = DS.RESTSerializer.extend({
85     normalizePayload: function (payload)
86     {
87         var results = {
88             platforms: this._normalizeIdMap(payload['all']),
89             builders: this._normalizeIdMap(payload['builders']),
90             tests: this._normalizeIdMap(payload['tests']).map(function (test) {
91                 test['parent'] = test['parentId'];
92                 return test;
93             }),
94             metrics: this._normalizeIdMap(payload['metrics']),
95             repositories: this._normalizeIdMap(payload['repositories']),
96         };
97
98         for (var testId in payload['tests']) {
99             var test = payload['tests'][testId];
100             var parent = payload['tests'][test['parent']];
101             if (!parent)
102                 continue;
103             if (!parent['childTests'])
104                 parent['childTests'] = [];
105             parent['childTests'].push(testId);
106         }
107
108         for (var metricId in payload['metrics']) {
109             var metric = payload['metrics'][metricId];
110             var test = payload['tests'][metric['test']];
111             if (!test['metrics'])
112                 test['metrics'] = [];
113             test['metrics'].push(metricId);
114         }
115
116         return results;
117     },
118     _normalizeIdMap: function (idMap)
119     {
120         var results = [];
121         for (var id in idMap) {
122             var definition = idMap[id];
123             definition['id'] = id;
124             results.push(definition);
125         }
126         return results;
127     }
128 });
129
130 App.PlatformAdapter = DS.RESTAdapter.extend({
131     buildURL: function (type, id)
132     {
133         return '../data/manifest.json';
134     },
135 });
136
137 App.MetricAdapter = DS.RESTAdapter.extend({
138     buildURL: function (type, id)
139     {
140         return '../data/manifest.json';
141     },
142 });
143
144 App.Manifest = Ember.Controller.extend({
145     platforms: null,
146     topLevelTests: null,
147     _platformById: {},
148     _metricById: {},
149     _builderById: {},
150     _repositoryById: {},
151     _fetchPromise: null,
152     fetch: function ()
153     {
154         if (this._fetchPromise)
155             return this._fetchPromise;
156         // FIXME: We shouldn't use DS.Store at all.
157         var store = App.__container__.lookup('store:main');
158         var promise = store.findAll('platform');
159         this._fetchPromise = promise.then(this._fetchedManifest.bind(this, store));
160         return this._fetchPromise;
161     },
162     isFetched: function () { return !!this.get('platforms'); }.property('platforms'),
163     platform: function (id) { return this._platformById[id]; },
164     metric: function (id) { return this._metricById[id]; },
165     builder: function (id) { return this._builderById[id]; },
166     repository: function (id) { return this._repositoryById[id]; },
167     _fetchedManifest: function (store)
168     {
169         var startTime = Date.now();
170         var self = this;
171
172         var topLevelTests = [];
173         store.all('test').forEach(function (test) {
174             var parent = test.get('parent');
175             if (!parent)
176                 topLevelTests.push(test);
177         });
178         this.set('topLevelTests', topLevelTests);
179
180         store.all('metric').forEach(function (metric) {
181             self._metricById[metric.get('id')] = metric;
182         });
183         var platforms = store.all('platform');
184         platforms.forEach(function (platform) {
185             self._platformById[platform.get('id')] = platform;
186         });
187         this.set('platforms', platforms);
188
189         store.all('builder').forEach(function (builder) {
190             self._builderById[builder.get('id')] = builder;
191         });
192
193         store.all('repository').forEach(function (repository) {
194             self._repositoryById[repository.get('id')] = repository;
195         });
196     }
197 }).create();