2018-03-17 18:26:18 +05:30
|
|
|
import Vue from 'vue';
|
2023-05-27 22:25:52 +05:30
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import { apolloProvider } from '~/graphql_shared/issuable_client';
|
2023-06-20 00:43:36 +05:30
|
|
|
import { convertToGraphQLId } from '~/graphql_shared/utils';
|
2022-10-11 01:57:18 +05:30
|
|
|
import { parseBoolean } from '~/lib/utils/common_utils';
|
2023-03-04 22:38:38 +05:30
|
|
|
import { getLocationHash } from '~/lib/utils/url_utility';
|
2022-10-11 01:57:18 +05:30
|
|
|
import NotesApp from './components/notes_app.vue';
|
2020-05-24 23:13:21 +05:30
|
|
|
import { store } from './stores';
|
2022-11-25 23:54:43 +05:30
|
|
|
import { getNotesFilterData } from './utils/get_notes_filter_data';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
export default ({ editorAiActions = [] } = {}) => {
|
2021-10-27 15:23:28 +05:30
|
|
|
const el = document.getElementById('js-vue-notes');
|
|
|
|
if (!el) {
|
|
|
|
return;
|
|
|
|
}
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
const notesFilterProps = getNotesFilterData(el);
|
|
|
|
const showTimelineViewToggle = parseBoolean(el.dataset.showTimelineViewToggle);
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
const notesDataset = el.dataset;
|
|
|
|
const parsedUserData = JSON.parse(notesDataset.currentUserData);
|
|
|
|
const noteableData = JSON.parse(notesDataset.noteableData);
|
|
|
|
let currentUserData = {};
|
|
|
|
|
|
|
|
noteableData.noteableType = notesDataset.noteableType;
|
|
|
|
noteableData.targetType = notesDataset.targetType;
|
|
|
|
noteableData.discussion_locked = parseBoolean(noteableData.discussion_locked);
|
|
|
|
|
|
|
|
if (parsedUserData) {
|
|
|
|
currentUserData = {
|
|
|
|
id: parsedUserData.id,
|
|
|
|
name: parsedUserData.name,
|
|
|
|
username: parsedUserData.username,
|
|
|
|
avatar_url: parsedUserData.avatar_path || parsedUserData.avatar_url,
|
|
|
|
path: parsedUserData.path,
|
|
|
|
can_add_timeline_events: parseBoolean(notesDataset.canAddTimelineEvents),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const notesData = JSON.parse(notesDataset.notesData);
|
|
|
|
|
|
|
|
store.dispatch('setNotesData', notesData);
|
|
|
|
store.dispatch('setNoteableData', noteableData);
|
|
|
|
store.dispatch('setUserData', currentUserData);
|
|
|
|
store.dispatch('setTargetNoteHash', getLocationHash());
|
|
|
|
store.dispatch('fetchNotes');
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
2021-01-03 14:25:43 +05:30
|
|
|
el,
|
2022-04-04 11:22:00 +05:30
|
|
|
name: 'NotesRoot',
|
2018-11-08 19:23:39 +05:30
|
|
|
components: {
|
2022-10-11 01:57:18 +05:30
|
|
|
NotesApp,
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
store,
|
2023-05-27 22:25:52 +05:30
|
|
|
apolloProvider,
|
2022-11-25 23:54:43 +05:30
|
|
|
provide: {
|
|
|
|
showTimelineViewToggle,
|
2023-04-23 21:23:45 +05:30
|
|
|
reportAbusePath: notesDataset.reportAbusePath,
|
2023-06-20 00:43:36 +05:30
|
|
|
newCommentTemplatePath: notesDataset.newCommentTemplatePath,
|
|
|
|
resourceGlobalId: convertToGraphQLId(noteableData.noteableType, noteableData.id),
|
2023-07-09 08:55:56 +05:30
|
|
|
editorAiActions: editorAiActions.map((factory) => factory(noteableData)),
|
2022-11-25 23:54:43 +05:30
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
noteableData,
|
|
|
|
currentUserData,
|
|
|
|
notesData: JSON.parse(notesDataset.notesData),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
render(createElement) {
|
|
|
|
return createElement('notes-app', {
|
|
|
|
props: {
|
|
|
|
noteableData: this.noteableData,
|
|
|
|
notesData: this.notesData,
|
|
|
|
userData: this.currentUserData,
|
2022-11-25 23:54:43 +05:30
|
|
|
...notesFilterProps,
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2021-10-27 15:23:28 +05:30
|
|
|
};
|