BuildRequest should have a method to fetch all in-progress and pending requests for...
[WebKit.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             var test = rawResponse.tests[testId];
20             var topLevel = !test.parentId;
21             if (test.parentId)
22                 testParentMap[testId] = parseInt(test.parentId);
23             tests.push(new Test(testId, test, topLevel));
24         }
25         for (var testId in testParentMap)
26             Test.findById(testId).setParentTest(Test.findById(testParentMap[testId]));
27
28         function buildObjectsFromIdMap(idMap, constructor, resolver) {
29             for (var id in idMap) {
30                 if (resolver)
31                     resolver(idMap[id]);
32                 new constructor(id, idMap[id]);
33             }
34         }
35         buildObjectsFromIdMap(rawResponse.metrics, Metric, function (raw) {
36             raw.test = Test.findById(raw.test);
37         });
38
39         buildObjectsFromIdMap(rawResponse.all, Platform, function (raw) {
40             raw.lastModifiedByMetric = {};
41             raw.lastModified.forEach(function (lastModified, index) {
42                 raw.lastModifiedByMetric[raw.metrics[index]] = lastModified;
43             });
44             raw.metrics = raw.metrics.map(function (id) { return Metric.findById(id); });
45         });
46         buildObjectsFromIdMap(rawResponse.builders, Builder);
47         buildObjectsFromIdMap(rawResponse.repositories, Repository);
48         buildObjectsFromIdMap(rawResponse.bugTrackers, BugTracker, function (raw) {
49             if (raw.repositories)
50                 raw.repositories = raw.repositories.map(function (id) { return Repository.findById(id); });
51         });
52
53         Instrumentation.endMeasuringTime('Manifest', '_didFetchManifest');
54
55         return {
56             siteTitle: rawResponse.siteTitle,
57             dashboards: rawResponse.dashboards, // FIXME: Add an abstraction around dashboards.
58         }
59     }
60 }
61
62 if (typeof module != 'undefined')
63     module.exports.Manifest = Manifest;