OwnedCommitViewer should include the preceding commit.
[WebKit.git] / Websites / perf.webkit.org / public / v3 / components / commit-log-viewer.js
index 47ea457..cc20c26 100644 (file)
@@ -4,86 +4,117 @@ class CommitLogViewer extends ComponentBase {
     constructor()
     {
         super('commit-log-viewer');
+        this._lazilyFetchCommitLogs = new LazilyEvaluatedFunction(this._fetchCommitLogs.bind(this));
         this._repository = null;
         this._fetchingPromise = null;
         this._commits = null;
+        this._precedingCommit = null;
+        this._renderCommitListLazily = new LazilyEvaluatedFunction(this._renderCommitList.bind(this));
+        this._showRepositoryName = true;
     }
 
-    currentRepository() { return this._repository; }
+    setShowRepositoryName(shouldShow)
+    {
+        this._showRepositoryName = shouldShow;
+        this.enqueueToRender();
+    }
 
-    view(repository, from, to)
+    view(repository, precedingRevision, lastRevision)
     {
+        this._lazilyFetchCommitLogs.evaluate(repository, precedingRevision, lastRevision);
+    }
+
+    _fetchCommitLogs(repository, precedingRevision, lastRevision)
+    {
+        this._fetchingPromise = null;
         this._commits = null;
 
-        if (!repository) {
-            this._fetchingPromise = null;
+        if (!repository || !lastRevision) {
             this._repository = null;
-            return Promise.resolve(null);
+            this.enqueueToRender();
+            return;
         }
 
-        this._repository = repository;
-
-        if (!to) {
-            this._fetchingPromise = null;
-            this.render();
-            return Promise.resolve(null);
-        }
-
-        var promise = CommitLog.fetchBetweenRevisions(repository, from || to, to);
+        let promise;
+        const fetchSingleCommit = !precedingRevision || precedingRevision == lastRevision;
+        if (fetchSingleCommit)
+            promise = CommitLog.fetchForSingleRevision(repository, lastRevision);
+        else
+            promise = CommitLog.fetchBetweenRevisions(repository, precedingRevision, lastRevision);
 
+        this._repository = repository;
         this._fetchingPromise = promise;
 
-        var self = this;
-        var spinnerTimer = setTimeout(function () {
-            self.render();
-        }, 300);
-
-        this._fetchingPromise.then(function (commits) {
-            clearTimeout(spinnerTimer);
-            if (self._fetchingPromise != promise)
+        this._fetchingPromise.then((commits) => {
+            if (this._fetchingPromise != promise)
                 return;
-            self._fetchingPromise = null;
-            self._commits = commits;
-        }, function (error) {
-            if (self._fetchingPromise != promise)
+            this._commits = commits;
+            if (fetchSingleCommit) {
+                this._fetchingPromise = null;
+                this._precedingCommit = null;
+                this.enqueueToRender();
                 return;
-            self._fetchingPromise = null;
-            self._commits = null;
+            }
+            return CommitLog.fetchForSingleRevision(repository, precedingRevision).then((precedingCommit) => {
+                if (this._fetchingPromise != promise)
+                    return;
+                this._fetchingPromise = null;
+                this._precedingCommit = precedingCommit[0];
+                this.enqueueToRender();
+            }, (error) => {
+                if (this._fetchingPromise != promise)
+                    return;
+                this._fetchingPromise = null;
+                this._precedingCommit = null;
+                this.enqueueToRender();
+            });
+        }, (error) => {
+            if (this._fetchingPromise != promise)
+                return;
+            this._fetchingPromise = null;
+            this._commits = null;
+            this.enqueueToRender();
         });
 
-        return this._fetchingPromise;
+        this.enqueueToRender();
     }
 
     render()
     {
-        var caption = '';
-        if (this._repository && (this._commits || this._fetchingPromise))
-            caption = this._repository.name();
-        this.content().querySelector('caption').textContent = caption;
-
-        var element = ComponentBase.createElement;
-        var link = ComponentBase.createLink;
-
-        this.renderReplace(this.content().querySelector('tbody'), (this._commits || []).map(function (commit) {
-            var label = commit.label();
-            var url = commit.url();
-            return element('tr', [
-                element('th', [element('h4', {class: 'revision'}, url ? link(label, commit.title(), url) : label), commit.author() || '']),
-                element('td', commit.message() ? commit.message().substring(0, 80) : '')]);
-        }));
+        const shouldShowRepositoryName = this._repository && (this._commits || this._fetchingPromise) && this._showRepositoryName;
+        this.content('repository-name').textContent = shouldShowRepositoryName ? this._repository.name() : '';
+        this.content('spinner-container').style.display = this._fetchingPromise ? null : 'none';
+        this._renderCommitListLazily.evaluate(this._commits, this._precedingCommit);
+    }
 
-        this.content().querySelector('.commits-viewer-spinner').style.display = this._fetchingPromise ? null : 'none';
+    _renderCommitList(commits, precedingCommit)
+    {
+        const element = ComponentBase.createElement;
+        const link = ComponentBase.createLink;
+        commits = commits && precedingCommit && precedingCommit.ownsCommits() ? [precedingCommit].concat(commits) : commits;
+        let previousCommit = null;
+
+        this.renderReplace(this.content('commits-list'), (commits || []).map((commit) => {
+            const label = commit.label();
+            const url = commit.url();
+            const ownsCommits = previousCommit && previousCommit.ownsCommits() && commit.ownsCommits();
+            const ownedCommitDifferenceRow = ownsCommits ? element('tr', element('td', {colspan: 2}, new OwnedCommitViewer(previousCommit, commit))) : [];
+            previousCommit = commit;
+            return [ownedCommitDifferenceRow,
+                element('tr', [
+                    element('th', [element('h4', {class: 'revision'}, url ? link(label, commit.title(), url) : label), commit.author() || '']),
+                    element('td', commit.message() ? commit.message().substring(0, 80) : '')])];
+        }));
     }
 
     static htmlTemplate()
     {
         return `
             <div class="commits-viewer-container">
-                <div class="commits-viewer-spinner"><spinner-icon></spinner-icon></div>
-                <table class="commits-viewer-table">
-                    <caption></caption>
-                    <tbody>
-                    </tbody>
+                <div id="spinner-container"><spinner-icon id="spinner"></spinner-icon></div>
+                <table id="commits-viewer-table">
+                    <caption id="repository-name"></caption>
+                    <tbody id="commits-list"></tbody>
                 </table>
             </div>
 `;
@@ -97,32 +128,28 @@ class CommitLogViewer extends ComponentBase {
                 height: calc(100% - 2px);
                 overflow-y: scroll;
             }
-            
-            .commits-viewer-table {
+
+            #commits-viewer-table {
                 width: 100%;
+                border-collapse: collapse;
+                border-bottom: solid 1px #ccc;
             }
 
-            .commits-viewer-table caption {
+            caption {
                 font-weight: inherit;
                 font-size: 1rem;
                 text-align: center;
                 padding: 0.2rem;
             }
 
-            .commits-viewer-table {
-                border-collapse: collapse;
-                border-bottom: solid 1px #ccc;
-            }
-
-            .commits-viewer-table .revision {
+            .revision {
                 white-space: nowrap;
                 font-weight: normal;
                 margin: 0;
                 padding: 0;
             }
 
-            .commits-viewer-table td,
-            .commits-viewer-table th {
+            td, th {
                 word-break: break-word;
                 border-top: solid 1px #ccc;
                 padding: 0.2rem;
@@ -131,7 +158,7 @@ class CommitLogViewer extends ComponentBase {
                 font-weight: normal;
             }
 
-            .commits-viewer-spinner {
+            #spinner-container {
                 margin-top: 2rem;
                 text-align: center;
             }