gitlab-org--gitlab-foss/app/assets/javascripts/mr_notes/index.js

100 lines
2.9 KiB
JavaScript
Raw Normal View History

2018-06-21 12:22:40 +00:00
import $ from 'jquery';
import Vue from 'vue';
2018-06-21 12:22:40 +00:00
import { mapActions, mapState, mapGetters } from 'vuex';
import initDiffsApp from '../diffs';
import notesApp from '../notes/components/notes_app.vue';
import discussionCounter from '../notes/components/discussion_counter.vue';
import initDiscussionFilters from '../notes/discussion_filters';
2018-06-21 12:22:40 +00:00
import store from './stores';
import MergeRequest from '../merge_request';
import { resetServiceWorkersPublicPath } from '../lib/utils/webpack';
2018-03-02 21:16:11 +00:00
export default function initMrNotes() {
resetServiceWorkersPublicPath();
2018-06-21 12:22:40 +00:00
const mrShowNode = document.querySelector('.merge-request');
// eslint-disable-next-line no-new
new MergeRequest({
action: mrShowNode.dataset.mrAction,
});
2018-03-16 20:16:21 +00:00
// eslint-disable-next-line no-new
new Vue({
el: '#js-vue-mr-discussions',
2018-06-21 12:22:40 +00:00
name: 'MergeRequestDiscussions',
components: {
notesApp,
},
2018-06-21 12:22:40 +00:00
store,
data() {
2018-06-21 12:22:40 +00:00
const notesDataset = document.getElementById('js-vue-mr-discussions').dataset;
const noteableData = JSON.parse(notesDataset.noteableData);
noteableData.noteableType = notesDataset.noteableType;
2018-06-21 12:22:40 +00:00
noteableData.targetType = notesDataset.targetType;
return {
noteableData,
currentUserData: JSON.parse(notesDataset.currentUserData),
notesData: JSON.parse(notesDataset.notesData),
helpPagePath: notesDataset.helpPagePath,
};
},
2018-06-21 12:22:40 +00:00
computed: {
...mapGetters(['discussionTabCounter']),
...mapState({
activeTab: state => state.page.activeTab,
}),
},
watch: {
discussionTabCounter() {
this.updateDiscussionTabCounter();
},
},
created() {
this.setActiveTab(window.mrTabs.getCurrentAction());
},
2018-06-21 12:22:40 +00:00
mounted() {
this.notesCountBadge = $('.issuable-details').find('.notes-tab .badge');
$(document).on('visibilitychange', this.updateDiscussionTabCounter);
window.mrTabs.eventHub.$on('MergeRequestTabChange', this.setActiveTab);
2018-06-21 12:22:40 +00:00
},
beforeDestroy() {
$(document).off('visibilitychange', this.updateDiscussionTabCounter);
window.mrTabs.eventHub.$off('MergeRequestTabChange', this.setActiveTab);
2018-06-21 12:22:40 +00:00
},
methods: {
...mapActions(['setActiveTab']),
updateDiscussionTabCounter() {
this.notesCountBadge.text(this.discussionTabCounter);
},
},
render(createElement) {
return createElement('notes-app', {
props: {
noteableData: this.noteableData,
notesData: this.notesData,
userData: this.currentUserData,
2018-06-21 12:22:40 +00:00
shouldShow: this.activeTab === 'show',
helpPagePath: this.helpPagePath,
},
});
},
});
2018-03-16 20:16:21 +00:00
// eslint-disable-next-line no-new
new Vue({
el: '#js-vue-discussion-counter',
2018-06-21 12:22:40 +00:00
name: 'DiscussionCounter',
components: {
discussionCounter,
},
store,
render(createElement) {
return createElement('discussion-counter');
},
});
2018-06-21 12:22:40 +00:00
initDiscussionFilters(store);
2018-06-21 12:22:40 +00:00
initDiffsApp(store);
2018-03-02 21:16:11 +00:00
}