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

123 lines
4 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
import Vue from 'vue';
2019-03-02 22:35:43 +05:30
import { mapActions, mapState, mapGetters } from 'vuex';
import { parseBoolean } from '~/lib/utils/common_utils';
import { getParameterValues } from '~/lib/utils/url_utility';
import FindFile from '~/vue_shared/components/file_finder/index.vue';
import eventHub from '../notes/event_hub';
2018-11-08 19:23:39 +05:30
import diffsApp from './components/app.vue';
2019-03-02 22:35:43 +05:30
import { TREE_LIST_STORAGE_KEY } from './constants';
2018-11-08 19:23:39 +05:30
export default function initDiffsApp(store) {
2019-03-02 22:35:43 +05:30
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-11-08 19:23:39 +05:30
return new Vue({
el: '#js-diffs-app',
name: 'MergeRequestDiffs',
components: {
diffsApp,
},
store,
data() {
const { dataset } = document.querySelector(this.$options.el);
return {
endpoint: dataset.endpoint,
2020-01-01 13:55:28 +05:30
endpointMetadata: dataset.endpointMetadata || '',
endpointBatch: dataset.endpointBatch || '',
2020-04-08 14:13:33 +05:30
endpointCoverage: dataset.endpointCoverage || '',
2018-11-08 19:23:39 +05:30
projectPath: dataset.projectPath,
2019-02-15 15:39:39 +05:30
helpPagePath: dataset.helpPagePath,
currentUser: JSON.parse(dataset.currentUserData) || {},
changesEmptyStateIllustration: dataset.changesEmptyStateIllustration,
2019-07-07 11:18:12 +05:30
isFluidLayout: parseBoolean(dataset.isFluidLayout),
2019-09-04 21:01:54 +05:30
dismissEndpoint: dataset.dismissEndpoint,
showSuggestPopover: parseBoolean(dataset.showSuggestPopover),
2019-12-04 20:38:33 +05:30
showWhitespaceDefault: parseBoolean(dataset.showWhitespaceDefault),
2018-11-08 19:23:39 +05:30
};
},
computed: {
...mapState({
activeTab: state => state.page.activeTab,
}),
},
2019-03-02 22:35:43 +05:30
created() {
2019-12-04 20:38:33 +05:30
let hideWhitespace = getParameterValues('w')[0];
2019-03-02 22:35:43 +05:30
const treeListStored = localStorage.getItem(TREE_LIST_STORAGE_KEY);
const renderTreeList = treeListStored !== null ? parseBoolean(treeListStored) : true;
this.setRenderTreeList(renderTreeList);
2019-12-04 20:38:33 +05:30
if (!hideWhitespace) {
hideWhitespace = this.showWhitespaceDefault ? '0' : '1';
}
this.setShowWhitespace({ showWhitespace: hideWhitespace !== '1' });
2019-03-02 22:35:43 +05:30
},
methods: {
...mapActions('diffs', ['setRenderTreeList', 'setShowWhitespace']),
},
2018-11-08 19:23:39 +05:30
render(createElement) {
return createElement('diffs-app', {
props: {
endpoint: this.endpoint,
2020-01-01 13:55:28 +05:30
endpointMetadata: this.endpointMetadata,
endpointBatch: this.endpointBatch,
2020-04-08 14:13:33 +05:30
endpointCoverage: this.endpointCoverage,
2018-11-08 19:23:39 +05:30
currentUser: this.currentUser,
projectPath: this.projectPath,
2019-02-15 15:39:39 +05:30
helpPagePath: this.helpPagePath,
2018-11-08 19:23:39 +05:30
shouldShow: this.activeTab === 'diffs',
2019-02-15 15:39:39 +05:30
changesEmptyStateIllustration: this.changesEmptyStateIllustration,
2019-07-07 11:18:12 +05:30
isFluidLayout: this.isFluidLayout,
2019-09-04 21:01:54 +05:30
dismissEndpoint: this.dismissEndpoint,
showSuggestPopover: this.showSuggestPopover,
2019-12-04 20:38:33 +05:30
showWhitespaceDefault: this.showWhitespaceDefault,
2018-11-08 19:23:39 +05:30
},
});
},
});
}