OLD | NEW |
---|---|
1 <!-- | 1 <!-- |
2 Copyright 2014 The Chromium Authors. All rights reserved. | 2 Copyright 2014 The Chromium Authors. All rights reserved. |
3 Use of this source code is governed by a BSD-style license that can be | 3 Use of this source code is governed by a BSD-style license that can be |
4 found in the LICENSE file. | 4 found in the LICENSE file. |
5 --> | 5 --> |
6 | 6 |
7 <link rel='import' href='ct-commit.html'> | 7 <link rel='import' href='ct-commit.html'> |
8 | 8 |
9 <link rel='import' href='ct-repositories.html'> | 9 <link rel='import' href='ct-repositories.html'> |
10 | 10 |
11 <script> | 11 <script> |
12 function CTCommitLog() { | 12 function CTCommitLog() { |
13 this.commits = {}; | 13 this.commits = {}; |
14 this.firstRevision = {}; | 14 this.firstRevision = {}; |
15 this.lastRevision = {}; | |
15 this._repositories = new CTRepositories(); | 16 this._repositories = new CTRepositories(); |
16 } | 17 } |
17 | 18 |
18 CTCommitLog.prototype.update = function() { | 19 CTCommitLog.prototype.update = function() { |
19 var requests = []; | 20 var requests = []; |
20 Object.keys(this._repositories.repositories, (function(name, repository) { | 21 Object.keys(this._repositories.repositories, (function(name, repository) { |
21 var responseHandler = this._handleResponse.bind(this, repository.repositoryU rl, repository.name); | 22 var responseHandler = this._handleResponse.bind(this, repository.repositoryU rl, repository.name); |
22 // FIXME: Turn net.js into net.html and import it at the top of this file. | 23 // FIXME: Turn net.js into net.html and import it at the top of this file. |
23 requests.push(net.ajax({url: repository.dataUrl}).then(responseHandler)); | 24 requests.push(net.ajax({url: repository.dataUrl}).then(responseHandler)); |
24 }.bind(this))); | 25 }.bind(this))); |
25 return Promise.all(requests); | 26 return Promise.all(requests); |
26 } | 27 } |
27 | 28 |
28 CTCommitLog.prototype._handleResponse = function(repositoryUrl, repository, json ) { | 29 CTCommitLog.prototype._handleResponse = function(repositoryUrl, repository, json ) { |
29 if (!this.commits[repository]) | 30 if (!this.commits[repository]) |
30 this.commits[repository] = {}; | 31 this.commits[repository] = {}; |
31 | 32 |
32 // FIXME: Fix googlesource to not do this outdated JSON XSS mitigation. | 33 // FIXME: Fix googlesource to not do this outdated JSON XSS mitigation. |
33 json = json.substring(')]}\n'.length); | 34 json = json.substring(')]}\n'.length); |
34 JSON.parse(json).log.forEach(function(entry) { | 35 JSON.parse(json).log.forEach(function(entry) { |
35 var commit = CTCommit.create(entry.author.name, entry.message, repositoryUrl , repository); | 36 var commit = CTCommit.create(entry.author.name, entry.message, repositoryUrl , repository); |
36 this.commits[repository][commit.revision] = commit; | 37 this.commits[repository][commit.revision] = commit; |
37 }.bind(this)); | 38 }.bind(this)); |
38 | 39 |
39 this.firstRevision[repository] = Object.keys(this.commits[repository]).sort()[ 0]; | 40 this._findFirstAndLastRevisions(repository); |
41 } | |
42 | |
43 CTCommitLog.prototype._findFirstAndLastRevisions = function(repository) { | |
44 var sortedCommits = Object.keys(this.commits[repository]).sort(); | |
45 this.firstRevision[repository] = parseInt(sortedCommits[0]); | |
46 this.lastRevision[repository] = parseInt(sortedCommits[sortedCommits.length - 1]); | |
ojan
2014/08/05 02:07:23
sugarjs has first() and last() for these.
ojan
2014/08/05 02:07:23
sugarjs has first() and last() for these.
| |
40 } | 47 } |
41 | 48 |
42 CTCommitLog.prototype.range = function(repository, first, last) { | 49 CTCommitLog.prototype.range = function(repository, first, last) { |
43 var commits = []; | 50 var commits = []; |
44 for (var revision = first; revision <= last; revision++) { | 51 for (var revision = first; revision <= last; revision++) { |
45 // Until we've seen a commit we have data for, fill in dummy data | 52 // Until we've seen a commit we have data for, fill in dummy data |
46 // so that we show something. Assume that we have the correct data | 53 // so that we show something. Assume that we have the correct data |
47 // for all the commits after the first one we have data for. | 54 // for all the commits after the first one we have data for. |
48 if (revision >= this.firstRevision[repository]) { | 55 if (revision >= this.firstRevision[repository]) { |
49 var commit = this.commits[repository][revision]; | 56 var commit = this.commits[repository][revision]; |
50 if (commit) | 57 if (commit) |
51 commits.push(commit); | 58 commits.push(commit); |
52 } else { | 59 } else { |
53 var url = this._repositories.repositories[repository].repositoryUrl; | 60 var url = this._repositories.repositories[repository].repositoryUrl; |
54 commits.push(CTCommit.createIncomplete(url, revision, repository)); | 61 commits.push(CTCommit.createIncomplete(url, revision, repository)); |
55 } | 62 } |
56 } | 63 } |
57 return commits; | 64 return commits; |
58 } | 65 } |
59 </script> | 66 </script> |
OLD | NEW |