Extend perf dashboard to support multiple summary pages.
[WebKit-https.git] / Websites / perf.webkit.org / public / v3 / models / manifest.js
1 'use strict';
2
3 class Manifest {
4
5     static fetch()
6     {
7         return RemoteAPI.getJSON('/data/manifest.json').catch(function () {
8             return RemoteAPI.getJSON('/api/manifest/');
9         }).then(this._didFetchManifest.bind(this));
10     }
11
12     static _didFetchManifest(rawResponse)
13     {
14         Instrumentation.startMeasuringTime('Manifest', '_didFetchManifest');
15
16         var tests = [];
17         var testParentMap = {};
18         for (var testId in rawResponse.tests)
19             tests.push(new Test(testId, rawResponse.tests[testId]));
20
21         function buildObjectsFromIdMap(idMap, constructor, resolver) {
22             for (var id in idMap) {
23                 if (resolver)
24                     resolver(idMap[id]);
25                 new constructor(id, idMap[id]);
26             }
27         }
28         buildObjectsFromIdMap(rawResponse.metrics, Metric, function (raw) {
29             raw.test = Test.findById(raw.test);
30         });
31
32         buildObjectsFromIdMap(rawResponse.all, Platform, function (raw) {
33             raw.lastModifiedByMetric = {};
34             raw.lastModified.forEach(function (lastModified, index) {
35                 raw.lastModifiedByMetric[raw.metrics[index]] = lastModified;
36             });
37             raw.metrics = raw.metrics.map(function (id) { return Metric.findById(id); });
38         });
39         buildObjectsFromIdMap(rawResponse.builders, Builder);
40         buildObjectsFromIdMap(rawResponse.repositories, Repository);
41         buildObjectsFromIdMap(rawResponse.bugTrackers, BugTracker, function (raw) {
42             if (raw.repositories)
43                 raw.repositories = raw.repositories.map(function (id) { return Repository.findById(id); });
44         });
45
46         Instrumentation.endMeasuringTime('Manifest', '_didFetchManifest');
47
48         return {
49             siteTitle: rawResponse.siteTitle,
50             dashboards: rawResponse.dashboards, // FIXME: Add an abstraction around dashboards.
51             summaryPages: rawResponse.summaryPages,
52         }
53     }
54 }
55
56 if (typeof module != 'undefined')
57     module.exports.Manifest = Manifest;