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

56 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-06-21 12:22:40 +00:00
import Vue from 'vue';
import { mapActions, mapState } from 'vuex';
import { parseBoolean } from '~/lib/utils/common_utils';
import { getParameterValues } from '~/lib/utils/url_utility';
2018-06-21 12:22:40 +00:00
import diffsApp from './components/app.vue';
import { TREE_LIST_STORAGE_KEY } from './constants';
2018-06-21 12:22:40 +00:00
export default function initDiffsApp(store) {
return new Vue({
el: '#js-diffs-app',
name: 'MergeRequestDiffs',
components: {
diffsApp,
},
store,
data() {
const { dataset } = document.querySelector(this.$options.el);
return {
endpoint: dataset.endpoint,
projectPath: dataset.projectPath,
helpPagePath: dataset.helpPagePath,
currentUser: JSON.parse(dataset.currentUserData) || {},
changesEmptyStateIllustration: dataset.changesEmptyStateIllustration,
2018-06-21 12:22:40 +00:00
};
},
computed: {
...mapState({
activeTab: state => state.page.activeTab,
}),
},
created() {
const treeListStored = localStorage.getItem(TREE_LIST_STORAGE_KEY);
const renderTreeList = treeListStored !== null ? parseBoolean(treeListStored) : true;
this.setRenderTreeList(renderTreeList);
this.setShowWhitespace({ showWhitespace: getParameterValues('w')[0] !== '1' });
},
methods: {
...mapActions('diffs', ['setRenderTreeList', 'setShowWhitespace']),
},
2018-06-21 12:22:40 +00:00
render(createElement) {
return createElement('diffs-app', {
props: {
endpoint: this.endpoint,
currentUser: this.currentUser,
projectPath: this.projectPath,
helpPagePath: this.helpPagePath,
2018-06-21 12:22:40 +00:00
shouldShow: this.activeTab === 'diffs',
changesEmptyStateIllustration: this.changesEmptyStateIllustration,
2018-06-21 12:22:40 +00:00
},
});
},
});
}