diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 15:09:37 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 15:09:37 +0000 |
commit | 2c89e169769ead722394a79ed67fcd08e96863dd (patch) | |
tree | 0dadb576846c484475b895f75fab41f71cdb952e /app/assets/javascripts/blob | |
parent | bd497e352ebd279536ae11855871162e82a3f88c (diff) | |
download | gitlab-ce-2c89e169769ead722394a79ed67fcd08e96863dd.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/blob')
4 files changed, 32 insertions, 38 deletions
diff --git a/app/assets/javascripts/blob/components/blob_header.vue b/app/assets/javascripts/blob/components/blob_header.vue index 61a66513838..b7d9600ec40 100644 --- a/app/assets/javascripts/blob/components/blob_header.vue +++ b/app/assets/javascripts/blob/components/blob_header.vue @@ -2,8 +2,7 @@ import ViewerSwitcher from './blob_header_viewer_switcher.vue'; import DefaultActions from './blob_header_default_actions.vue'; import BlobFilepath from './blob_header_filepath.vue'; -import eventHub from '../event_hub'; -import { RICH_BLOB_VIEWER, SIMPLE_BLOB_VIEWER } from './constants'; +import { SIMPLE_BLOB_VIEWER } from './constants'; export default { components: { @@ -26,10 +25,15 @@ export default { required: false, default: false, }, + activeViewerType: { + type: String, + required: false, + default: SIMPLE_BLOB_VIEWER, + }, }, data() { return { - activeViewer: this.blob.richViewer ? RICH_BLOB_VIEWER : SIMPLE_BLOB_VIEWER, + viewer: this.hideViewerSwitcher ? null : this.activeViewerType, }; }, computed: { @@ -40,19 +44,16 @@ export default { return !this.hideDefaultActions; }, }, - created() { - if (this.showViewerSwitcher) { - eventHub.$on('switch-viewer', this.setActiveViewer); - } - }, - beforeDestroy() { - if (this.showViewerSwitcher) { - eventHub.$off('switch-viewer', this.setActiveViewer); - } + watch: { + viewer(newVal, oldVal) { + if (!this.hideViewerSwitcher && newVal !== oldVal) { + this.$emit('viewer-changed', newVal); + } + }, }, methods: { - setActiveViewer(viewer) { - this.activeViewer = viewer; + proxyCopyRequest() { + this.$emit('copy'); }, }, }; @@ -66,11 +67,16 @@ export default { </blob-filepath> <div class="file-actions d-none d-sm-block"> - <viewer-switcher v-if="showViewerSwitcher" :blob="blob" :active-viewer="activeViewer" /> + <viewer-switcher v-if="showViewerSwitcher" v-model="viewer" /> <slot name="actions"></slot> - <default-actions v-if="showDefaultActions" :blob="blob" :active-viewer="activeViewer" /> + <default-actions + v-if="showDefaultActions" + :raw-path="blob.rawPath" + :active-viewer="viewer" + @copy="proxyCopyRequest" + /> </div> </div> </template> diff --git a/app/assets/javascripts/blob/components/blob_header_default_actions.vue b/app/assets/javascripts/blob/components/blob_header_default_actions.vue index e526fae0dba..f5157fba819 100644 --- a/app/assets/javascripts/blob/components/blob_header_default_actions.vue +++ b/app/assets/javascripts/blob/components/blob_header_default_actions.vue @@ -7,7 +7,6 @@ import { RICH_BLOB_VIEWER, SIMPLE_BLOB_VIEWER, } from './constants'; -import eventHub from '../event_hub'; export default { components: { @@ -19,8 +18,8 @@ export default { GlTooltip: GlTooltipDirective, }, props: { - blob: { - type: Object, + rawPath: { + type: String, required: true, }, activeViewer: { @@ -30,11 +29,8 @@ export default { }, }, computed: { - rawUrl() { - return this.blob.rawPath; - }, downloadUrl() { - return `${this.blob.rawPath}?inline=false`; + return `${this.rawPath}?inline=false`; }, copyDisabled() { return this.activeViewer === RICH_BLOB_VIEWER; @@ -42,7 +38,7 @@ export default { }, methods: { requestCopyContents() { - eventHub.$emit('copy'); + this.$emit('copy'); }, }, BTN_COPY_CONTENTS_TITLE, @@ -65,7 +61,7 @@ export default { v-gl-tooltip.hover :aria-label="$options.BTN_RAW_TITLE" :title="$options.BTN_RAW_TITLE" - :href="rawUrl" + :href="rawPath" target="_blank" > <gl-icon name="doc-code" :size="14" /> diff --git a/app/assets/javascripts/blob/components/blob_header_viewer_switcher.vue b/app/assets/javascripts/blob/components/blob_header_viewer_switcher.vue index 13ea87c99b1..689fa7638f0 100644 --- a/app/assets/javascripts/blob/components/blob_header_viewer_switcher.vue +++ b/app/assets/javascripts/blob/components/blob_header_viewer_switcher.vue @@ -6,7 +6,6 @@ import { SIMPLE_BLOB_VIEWER, SIMPLE_BLOB_VIEWER_TITLE, } from './constants'; -import eventHub from '../event_hub'; export default { components: { @@ -18,11 +17,7 @@ export default { GlTooltip: GlTooltipDirective, }, props: { - blob: { - type: Object, - required: true, - }, - activeViewer: { + value: { type: String, default: SIMPLE_BLOB_VIEWER, required: false, @@ -30,16 +25,16 @@ export default { }, computed: { isSimpleViewer() { - return this.activeViewer === SIMPLE_BLOB_VIEWER; + return this.value === SIMPLE_BLOB_VIEWER; }, isRichViewer() { - return this.activeViewer === RICH_BLOB_VIEWER; + return this.value === RICH_BLOB_VIEWER; }, }, methods: { switchToViewer(viewer) { - if (viewer !== this.activeViewer) { - eventHub.$emit('switch-viewer', viewer); + if (viewer !== this.value) { + this.$emit('input', viewer); } }, }, diff --git a/app/assets/javascripts/blob/event_hub.js b/app/assets/javascripts/blob/event_hub.js deleted file mode 100644 index 0948c2e5352..00000000000 --- a/app/assets/javascripts/blob/event_hub.js +++ /dev/null @@ -1,3 +0,0 @@ -import Vue from 'vue'; - -export default new Vue(); |