debian-mirror-gitlab/app/assets/javascripts/mr_notes/index.js

95 lines
2.8 KiB
JavaScript
Raw Normal View History

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