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

55 lines
1.3 KiB
Vue
Raw Normal View History

2020-03-13 15:44:24 +05:30
<script>
import { mapActions, mapState } from 'vuex';
import Popover from './popover.vue';
2020-04-22 19:07:51 +05:30
import eventHub from '../../notes/event_hub';
2020-03-13 15:44:24 +05:30
export default {
components: {
Popover,
},
computed: {
2020-05-24 23:13:21 +05:30
...mapState([
'currentDefinition',
'currentDefinitionPosition',
'currentBlobPath',
'definitionPathPrefix',
]),
2020-03-13 15:44:24 +05:30
},
mounted() {
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: {
2020-04-22 19:07:51 +05:30
...mapActions(['fetchData', 'showDefinition', 'showBlobInteractionZones']),
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>