2018-06-21 08:22:40 -04:00
|
|
|
import Vue from 'vue';
|
2019-01-16 10:17:10 -05:00
|
|
|
import { mapActions, mapState, mapGetters } from 'vuex';
|
2019-01-24 09:48:03 -05:00
|
|
|
import { parseBoolean } from '~/lib/utils/common_utils';
|
|
|
|
import { getParameterValues } from '~/lib/utils/url_utility';
|
2019-01-16 10:17:10 -05:00
|
|
|
import FindFile from '~/vue_shared/components/file_finder/index.vue';
|
|
|
|
import eventHub from '../notes/event_hub';
|
2018-06-21 08:22:40 -04:00
|
|
|
import diffsApp from './components/app.vue';
|
2019-01-24 09:48:03 -05:00
|
|
|
import { TREE_LIST_STORAGE_KEY } from './constants';
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
export default function initDiffsApp(store) {
|
2019-01-16 10:17:10 -05:00
|
|
|
const fileFinderEl = document.getElementById('js-diff-file-finder');
|
|
|
|
|
|
|
|
if (fileFinderEl) {
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
|
|
|
el: fileFinderEl,
|
|
|
|
store,
|
|
|
|
computed: {
|
|
|
|
...mapState('diffs', ['fileFinderVisible', 'isLoading']),
|
|
|
|
...mapGetters('diffs', ['flatBlobsList']),
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
fileFinderVisible(newVal, oldVal) {
|
|
|
|
if (newVal && !oldVal && !this.flatBlobsList.length) {
|
|
|
|
eventHub.$emit('fetchDiffData');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions('diffs', ['toggleFileFinder', 'scrollToFile']),
|
|
|
|
openFile(file) {
|
|
|
|
window.mrTabs.tabShown('diffs');
|
|
|
|
this.scrollToFile(file.path);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
render(createElement) {
|
|
|
|
return createElement(FindFile, {
|
|
|
|
props: {
|
|
|
|
files: this.flatBlobsList,
|
|
|
|
visible: this.fileFinderVisible,
|
|
|
|
loading: this.isLoading,
|
|
|
|
showDiffStats: true,
|
|
|
|
clearSearchOnClose: false,
|
|
|
|
},
|
|
|
|
on: {
|
|
|
|
toggle: this.toggleFileFinder,
|
|
|
|
click: this.openFile,
|
|
|
|
},
|
|
|
|
class: ['diff-file-finder'],
|
|
|
|
style: {
|
|
|
|
display: this.fileFinderVisible ? '' : 'none',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
return new Vue({
|
|
|
|
el: '#js-diffs-app',
|
|
|
|
name: 'MergeRequestDiffs',
|
|
|
|
components: {
|
|
|
|
diffsApp,
|
|
|
|
},
|
|
|
|
store,
|
|
|
|
data() {
|
|
|
|
const { dataset } = document.querySelector(this.$options.el);
|
|
|
|
|
|
|
|
return {
|
|
|
|
endpoint: dataset.endpoint,
|
2018-06-26 14:49:22 -04:00
|
|
|
projectPath: dataset.projectPath,
|
2018-12-13 14:17:19 -05:00
|
|
|
helpPagePath: dataset.helpPagePath,
|
2018-11-09 14:48:41 -05:00
|
|
|
currentUser: JSON.parse(dataset.currentUserData) || {},
|
2018-12-13 05:57:45 -05:00
|
|
|
changesEmptyStateIllustration: dataset.changesEmptyStateIllustration,
|
2019-04-12 04:32:05 -04:00
|
|
|
isFluidLayout: parseBoolean(dataset.isFluidLayout),
|
2019-06-14 09:01:24 -04:00
|
|
|
dismissEndpoint: dataset.dismissEndpoint,
|
|
|
|
showSuggestPopover: parseBoolean(dataset.showSuggestPopover),
|
2019-09-16 05:06:25 -04:00
|
|
|
showWhitespaceDefault: parseBoolean(dataset.showWhitespaceDefault),
|
2018-06-21 08:22:40 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
activeTab: state => state.page.activeTab,
|
|
|
|
}),
|
|
|
|
},
|
2019-01-24 09:48:03 -05:00
|
|
|
created() {
|
2019-09-16 05:06:25 -04:00
|
|
|
let hideWhitespace = getParameterValues('w')[0];
|
2019-01-24 09:48:03 -05:00
|
|
|
const treeListStored = localStorage.getItem(TREE_LIST_STORAGE_KEY);
|
|
|
|
const renderTreeList = treeListStored !== null ? parseBoolean(treeListStored) : true;
|
|
|
|
|
|
|
|
this.setRenderTreeList(renderTreeList);
|
2019-09-16 05:06:25 -04:00
|
|
|
if (!hideWhitespace) {
|
|
|
|
hideWhitespace = this.showWhitespaceDefault ? '0' : '1';
|
|
|
|
}
|
|
|
|
this.setShowWhitespace({ showWhitespace: hideWhitespace !== '1' });
|
2019-01-24 09:48:03 -05:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions('diffs', ['setRenderTreeList', 'setShowWhitespace']),
|
|
|
|
},
|
2018-06-21 08:22:40 -04:00
|
|
|
render(createElement) {
|
|
|
|
return createElement('diffs-app', {
|
|
|
|
props: {
|
|
|
|
endpoint: this.endpoint,
|
|
|
|
currentUser: this.currentUser,
|
2018-06-26 14:49:22 -04:00
|
|
|
projectPath: this.projectPath,
|
2018-12-13 14:17:19 -05:00
|
|
|
helpPagePath: this.helpPagePath,
|
2018-06-21 08:22:40 -04:00
|
|
|
shouldShow: this.activeTab === 'diffs',
|
2018-12-13 05:57:45 -05:00
|
|
|
changesEmptyStateIllustration: this.changesEmptyStateIllustration,
|
2019-04-12 04:32:05 -04:00
|
|
|
isFluidLayout: this.isFluidLayout,
|
2019-06-14 09:01:24 -04:00
|
|
|
dismissEndpoint: this.dismissEndpoint,
|
|
|
|
showSuggestPopover: this.showSuggestPopover,
|
2019-09-16 05:06:25 -04:00
|
|
|
showWhitespaceDefault: this.showWhitespaceDefault,
|
2018-06-21 08:22:40 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|