OwnedCommitViewer should include the preceding commit.
[WebKit.git] / Websites / perf.webkit.org / public / v3 / components / commit-log-viewer.js
1
2 class CommitLogViewer extends ComponentBase {
3
4     constructor()
5     {
6         super('commit-log-viewer');
7         this._lazilyFetchCommitLogs = new LazilyEvaluatedFunction(this._fetchCommitLogs.bind(this));
8         this._repository = null;
9         this._fetchingPromise = null;
10         this._commits = null;
11         this._precedingCommit = null;
12         this._renderCommitListLazily = new LazilyEvaluatedFunction(this._renderCommitList.bind(this));
13         this._showRepositoryName = true;
14     }
15
16     setShowRepositoryName(shouldShow)
17     {
18         this._showRepositoryName = shouldShow;
19         this.enqueueToRender();
20     }
21
22     view(repository, precedingRevision, lastRevision)
23     {
24         this._lazilyFetchCommitLogs.evaluate(repository, precedingRevision, lastRevision);
25     }
26
27     _fetchCommitLogs(repository, precedingRevision, lastRevision)
28     {
29         this._fetchingPromise = null;
30         this._commits = null;
31
32         if (!repository || !lastRevision) {
33             this._repository = null;
34             this.enqueueToRender();
35             return;
36         }
37
38         let promise;
39         const fetchSingleCommit = !precedingRevision || precedingRevision == lastRevision;
40         if (fetchSingleCommit)
41             promise = CommitLog.fetchForSingleRevision(repository, lastRevision);
42         else
43             promise = CommitLog.fetchBetweenRevisions(repository, precedingRevision, lastRevision);
44
45         this._repository = repository;
46         this._fetchingPromise = promise;
47
48         this._fetchingPromise.then((commits) => {
49             if (this._fetchingPromise != promise)
50                 return;
51             this._commits = commits;
52             if (fetchSingleCommit) {
53                 this._fetchingPromise = null;
54                 this._precedingCommit = null;
55                 this.enqueueToRender();
56                 return;
57             }
58             return CommitLog.fetchForSingleRevision(repository, precedingRevision).then((precedingCommit) => {
59                 if (this._fetchingPromise != promise)
60                     return;
61                 this._fetchingPromise = null;
62                 this._precedingCommit = precedingCommit[0];
63                 this.enqueueToRender();
64             }, (error) => {
65                 if (this._fetchingPromise != promise)
66                     return;
67                 this._fetchingPromise = null;
68                 this._precedingCommit = null;
69                 this.enqueueToRender();
70             });
71         }, (error) => {
72             if (this._fetchingPromise != promise)
73                 return;
74             this._fetchingPromise = null;
75             this._commits = null;
76             this.enqueueToRender();
77         });
78
79         this.enqueueToRender();
80     }
81
82     render()
83     {
84         const shouldShowRepositoryName = this._repository && (this._commits || this._fetchingPromise) && this._showRepositoryName;
85         this.content('repository-name').textContent = shouldShowRepositoryName ? this._repository.name() : '';
86         this.content('spinner-container').style.display = this._fetchingPromise ? null : 'none';
87         this._renderCommitListLazily.evaluate(this._commits, this._precedingCommit);
88     }
89
90     _renderCommitList(commits, precedingCommit)
91     {
92         const element = ComponentBase.createElement;
93         const link = ComponentBase.createLink;
94         commits = commits && precedingCommit && precedingCommit.ownsCommits() ? [precedingCommit].concat(commits) : commits;
95         let previousCommit = null;
96
97         this.renderReplace(this.content('commits-list'), (commits || []).map((commit) => {
98             const label = commit.label();
99             const url = commit.url();
100             const ownsCommits = previousCommit && previousCommit.ownsCommits() && commit.ownsCommits();
101             const ownedCommitDifferenceRow = ownsCommits ? element('tr', element('td', {colspan: 2}, new OwnedCommitViewer(previousCommit, commit))) : [];
102             previousCommit = commit;
103             return [ownedCommitDifferenceRow,
104                 element('tr', [
105                     element('th', [element('h4', {class: 'revision'}, url ? link(label, commit.title(), url) : label), commit.author() || '']),
106                     element('td', commit.message() ? commit.message().substring(0, 80) : '')])];
107         }));
108     }
109
110     static htmlTemplate()
111     {
112         return `
113             <div class="commits-viewer-container">
114                 <div id="spinner-container"><spinner-icon id="spinner"></spinner-icon></div>
115                 <table id="commits-viewer-table">
116                     <caption id="repository-name"></caption>
117                     <tbody id="commits-list"></tbody>
118                 </table>
119             </div>
120 `;
121     }
122
123     static cssTemplate()
124     {
125         return `
126             .commits-viewer-container {
127                 width: 100%;
128                 height: calc(100% - 2px);
129                 overflow-y: scroll;
130             }
131
132             #commits-viewer-table {
133                 width: 100%;
134                 border-collapse: collapse;
135                 border-bottom: solid 1px #ccc;
136             }
137
138             caption {
139                 font-weight: inherit;
140                 font-size: 1rem;
141                 text-align: center;
142                 padding: 0.2rem;
143             }
144
145             .revision {
146                 white-space: nowrap;
147                 font-weight: normal;
148                 margin: 0;
149                 padding: 0;
150             }
151
152             td, th {
153                 word-break: break-word;
154                 border-top: solid 1px #ccc;
155                 padding: 0.2rem;
156                 margin: 0;
157                 font-size: 0.8rem;
158                 font-weight: normal;
159             }
160
161             #spinner-container {
162                 margin-top: 2rem;
163                 text-align: center;
164             }
165 `;
166     }
167
168 }
169
170 ComponentBase.defineElement('commit-log-viewer', CommitLogViewer);