debian-mirror-gitlab/app/assets/javascripts/notes/mixins/discussion_navigation.js

57 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-11-18 11:00:15 +05:30
import { scrollToElement } from '~/lib/utils/common_utils';
2019-02-15 15:39:39 +05:30
import eventHub from '../../notes/event_hub';
2018-11-18 11:00:15 +05:30
export default {
methods: {
2019-02-15 15:39:39 +05:30
diffsJump(id) {
const selector = `ul.notes[data-discussion-id="${id}"]`;
2018-11-18 11:00:15 +05:30
2019-02-15 15:39:39 +05:30
eventHub.$once('scrollToDiscussion', () => {
const el = document.querySelector(selector);
2019-01-03 12:48:30 +05:30
2018-11-18 11:00:15 +05:30
if (el) {
2019-01-03 12:48:30 +05:30
scrollToElement(el);
2019-02-15 15:39:39 +05:30
2018-11-18 11:00:15 +05:30
return true;
}
2019-02-15 15:39:39 +05:30
return false;
});
this.expandDiscussion({ discussionId: id });
},
discussionJump(id) {
const selector = `div.discussion[data-discussion-id="${id}"]`;
const el = document.querySelector(selector);
this.expandDiscussion({ discussionId: id });
if (el) {
scrollToElement(el);
return true;
2018-11-18 11:00:15 +05:30
}
return false;
},
2019-02-15 15:39:39 +05:30
jumpToDiscussion(id) {
if (id) {
const activeTab = window.mrTabs.currentAction;
if (activeTab === 'diffs') {
this.diffsJump(id);
} else if (activeTab === 'commits' || activeTab === 'pipelines') {
window.mrTabs.eventHub.$once('MergeRequestTabChange', () => {
setTimeout(() => this.discussionJump(id), 0);
});
window.mrTabs.tabShown('show');
} else {
this.discussionJump(id);
}
}
},
2018-11-18 11:00:15 +05:30
},
};