diff options
author | blackst0ne <blackst0ne.ru@gmail.com> | 2017-06-03 12:40:20 +1100 |
---|---|---|
committer | blackst0ne <blackst0ne.ru@gmail.com> | 2017-06-03 12:40:20 +1100 |
commit | 78f131c0514bc99f73b9c063fac3158ab2e51e17 (patch) | |
tree | 1f9cc2feccd343ce1b83bb5d7a82bab7fea7e6e1 /app/assets/javascripts/commits.js | |
parent | 70b927a55ca62f1219464182660877bcdefd55b0 (diff) | |
download | gitlab-ce-78f131c0514bc99f73b9c063fac3158ab2e51e17.tar.gz |
Fix duplication of commits header on commits page
Diffstat (limited to 'app/assets/javascripts/commits.js')
-rw-r--r-- | app/assets/javascripts/commits.js | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/app/assets/javascripts/commits.js b/app/assets/javascripts/commits.js index e3f9eaaf39c..2b0bf49cf92 100644 --- a/app/assets/javascripts/commits.js +++ b/app/assets/javascripts/commits.js @@ -7,6 +7,8 @@ window.CommitsList = (function() { CommitsList.timer = null; CommitsList.init = function(limit) { + this.$contentList = $('.content_list'); + $("body").on("click", ".day-commits-table li.commit", function(e) { if (e.target.nodeName !== "A") { location.href = $(this).attr("url"); @@ -14,9 +16,9 @@ window.CommitsList = (function() { return false; } }); - Pager.init(limit, false, false, function() { - gl.utils.localTimeAgo($('.js-timeago')); - }); + + Pager.init(limit, false, false, this.processCommits); + this.content = $("#commits-list"); this.searchField = $("#commits-search"); this.lastSearch = this.searchField.val(); @@ -62,5 +64,34 @@ window.CommitsList = (function() { }); }; + // Prepare loaded data. + CommitsList.processCommits = (data) => { + let processedData = data; + const $processedData = $(processedData); + const $commitsHeadersLast = CommitsList.$contentList.find('li.js-commit-header').last(); + const lastShownDay = $commitsHeadersLast.data('day'); + const $loadedCommitsHeadersFirst = $processedData.filter('li.js-commit-header').first(); + const loadedShownDayFirst = $loadedCommitsHeadersFirst.data('day'); + let commitsCount; + + // If commits headers show the same date, + // remove the last header and change the previous one. + if (lastShownDay === loadedShownDayFirst) { + // Last shown commits count under the last commits header. + commitsCount = $commitsHeadersLast.nextUntil('li.js-commit-header').find('li.commit').length; + + // Remove duplicate of commits header. + processedData = $processedData.not(`li.js-commit-header[data-day="${loadedShownDayFirst}"]`); + + // Update commits count in the previous commits header. + commitsCount += Number($(processedData).nextUntil('li.js-commit-header').first().find('li.commit').length); + $commitsHeadersLast.find('span.commits-count').text(`${commitsCount} ${gl.text.pluralize('commit', commitsCount)}`); + } + + gl.utils.localTimeAgo($processedData.find('.js-timeago')); + + return processedData; + }; + return CommitsList; })(); |