debian-mirror-gitlab/app/assets/javascripts/code_navigation/components/app.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2 KiB
Vue
Raw Normal View History

2020-03-13 15:44:24 +05:30
<script>
import { mapActions, mapState } from 'vuex';
2022-06-21 17:19:12 +05:30
import eventHub from '~/notes/event_hub';
2021-03-11 19:13:27 +05:30
import Popover from './popover.vue';
2020-03-13 15:44:24 +05:30
export default {
components: {
Popover,
},
2022-05-07 20:08:51 +05:30
props: {
codeNavigationPath: {
type: String,
required: false,
default: null,
},
blobPath: {
type: String,
required: false,
default: null,
},
pathPrefix: {
type: String,
required: false,
default: null,
},
2022-06-21 17:19:12 +05:30
wrapTextNodes: {
type: Boolean,
required: false,
default: false,
},
2022-05-07 20:08:51 +05:30
},
2020-03-13 15:44:24 +05:30
computed: {
2020-05-24 23:13:21 +05:30
...mapState([
'currentDefinition',
'currentDefinitionPosition',
'currentBlobPath',
'definitionPathPrefix',
]),
2020-03-13 15:44:24 +05:30
},
mounted() {
2022-05-07 20:08:51 +05:30
if (this.codeNavigationPath && this.blobPath && this.pathPrefix) {
const initialData = {
blobs: [{ path: this.blobPath, codeNavigationPath: this.codeNavigationPath }],
definitionPathPrefix: this.pathPrefix,
2022-06-21 17:19:12 +05:30
wrapTextNodes: this.wrapTextNodes,
2022-05-07 20:08:51 +05:30
};
this.setInitialData(initialData);
}
2020-04-22 19:07:51 +05:30
this.body = document.body;
eventHub.$on('showBlobInteractionZones', this.showBlobInteractionZones);
2020-03-13 15:44:24 +05:30
this.addGlobalEventListeners();
this.fetchData();
},
beforeDestroy() {
2020-04-22 19:07:51 +05:30
eventHub.$off('showBlobInteractionZones', this.showBlobInteractionZones);
2020-03-13 15:44:24 +05:30
this.removeGlobalEventListeners();
},
methods: {
2022-05-07 20:08:51 +05:30
...mapActions(['fetchData', 'showDefinition', 'showBlobInteractionZones', 'setInitialData']),
2020-03-13 15:44:24 +05:30
addGlobalEventListeners() {
2020-04-22 19:07:51 +05:30
if (this.body) {
this.body.addEventListener('click', this.showDefinition);
2020-03-13 15:44:24 +05:30
}
},
removeGlobalEventListeners() {
2020-04-22 19:07:51 +05:30
if (this.body) {
this.body.removeEventListener('click', this.showDefinition);
2020-03-13 15:44:24 +05:30
}
},
},
};
</script>
<template>
<popover
v-if="currentDefinition"
:position="currentDefinitionPosition"
:data="currentDefinition"
2020-04-22 19:07:51 +05:30
:definition-path-prefix="definitionPathPrefix"
2020-05-24 23:13:21 +05:30
:blob-path="currentBlobPath"
2020-03-13 15:44:24 +05:30
/>
</template>