diff options
author | Phil Hughes <me@iamphill.com> | 2016-08-01 12:06:31 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2016-08-01 12:06:31 +0300 |
commit | c51cbc1f2f3b590c4f38198dd886c4e372b4e476 (patch) | |
tree | 5c4b1e26c68b810fa46bf42d200bf2f30e452f10 /app/assets/javascripts/diff_notes/components/jump_to_discussion.js.es6 | |
parent | db8c4bce381a137d7afea99d39ffd4d5e70b5580 (diff) |
Updated issues with jump tp button
Fixed styling bugs
Diffstat (limited to 'app/assets/javascripts/diff_notes/components/jump_to_discussion.js.es6')
-rw-r--r-- | app/assets/javascripts/diff_notes/components/jump_to_discussion.js.es6 | 85 |
1 files changed, 48 insertions, 37 deletions
diff --git a/app/assets/javascripts/diff_notes/components/jump_to_discussion.js.es6 b/app/assets/javascripts/diff_notes/components/jump_to_discussion.js.es6 index 82cdc5a7772..75c4376acd4 100644 --- a/app/assets/javascripts/diff_notes/components/jump_to_discussion.js.es6 +++ b/app/assets/javascripts/diff_notes/components/jump_to_discussion.js.es6 @@ -14,66 +14,77 @@ return discussion.isResolved(); }, discussionsCount: function () { - return Object.keys(this.discussions).length; + return CommentsStore.discussionCount(); + }, + unresolvedDiscussionCount: function () { + let unresolvedCount = 0; + for (const discussionId in this.discussions) { + const discussion = this.discussions[discussionId]; + + if (!discussion.isResolved()) { + unresolvedCount++; + } + } + + return unresolvedCount; }, showButton: function () { - return this.discussionsCount > 0 && (this.discussionsCount > 1 || !this.discussionId); + if (this.discussionId) { + if (this.unresolvedDiscussionCount > 1) { + return true; + } else { + return this.discussionId !== this.lastResolvedId(); + } + } else { + return this.unresolvedDiscussionCount >= 1; + } } }, methods: { + lastResolvedId: function () { + let lastId; + for (const discussionId in this.discussions) { + const discussion = this.discussions[discussionId]; + + if (!discussion.isResolved()) { + lastId = discussion.id; + } + } + return lastId; + }, jumpToNextUnresolvedDiscussion: function () { let nextUnresolvedDiscussionId, - firstUnresolvedDiscussionId; + firstUnresolvedDiscussionId, + useNextDiscussionId = false, + i = 0; - if (!this.discussionId) { - let i = 0; - for (const discussionId in this.discussions) { - const discussion = this.discussions[discussionId]; - const isResolved = discussion.isResolved(); + for (const discussionId in this.discussions) { + const discussion = this.discussions[discussionId]; - if (!firstUnresolvedDiscussionId && !isResolved) { - firstUnresolvedDiscussionId = discussionId; + if (!discussion.isResolved()) { + if (i === 0) { + firstUnresolvedDiscussionId = discussion.id; } - if (!isResolved) { - nextUnresolvedDiscussionId = discussionId; + if (useNextDiscussionId) { + nextUnresolvedDiscussionId = discussion.id; break; } - i++; - } - } else { - let nextDiscussionId; - const discussionKeys = Object.keys(this.discussions), - indexOfDiscussion = discussionKeys.indexOf(this.discussionId); - nextDiscussionIds = discussionKeys.splice(indexOfDiscussion); - - nextDiscussionIds.forEach((discussionId) => { - if (discussionId !== this.discussionId) { - const discussion = this.discussions[discussionId]; - - if (!discussion.isResolved()) { - nextDiscussionId = discussion.id; - } + if (this.discussionId && discussion.id === this.discussionId) { + useNextDiscussionId = true; } - }); - if (nextDiscussionId) { - nextUnresolvedDiscussionId = nextDiscussionId; - } else { - firstUnresolvedDiscussionId = discussionKeys[0]; + i++; } } - if (firstUnresolvedDiscussionId) { - // Jump to first unresolved discussion + if (!nextUnresolvedDiscussionId && firstUnresolvedDiscussionId) { nextUnresolvedDiscussionId = firstUnresolvedDiscussionId; } if (nextUnresolvedDiscussionId) { - $('#notes').addClass('active'); - $('#commits, #builds, #diffs').removeClass('active'); - mrTabs.setCurrentAction('notes'); + mrTabs.activateTab('notes'); $.scrollTo(`.discussion[data-discussion-id="${nextUnresolvedDiscussionId}"]`, { offset: -($('.navbar-gitlab').outerHeight() + $('.layout-nav').outerHeight()) |