2018-10-18 03:50:38 -04:00
|
|
|
<script>
|
|
|
|
import { mapActions, mapGetters } from 'vuex';
|
|
|
|
import _ from 'underscore';
|
2019-04-12 05:27:24 -04:00
|
|
|
import imageDiffMixin from 'ee_else_ce/diffs/mixins/image_diff';
|
2018-10-18 03:50:38 -04:00
|
|
|
import Icon from '~/vue_shared/components/icon.vue';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ImageDiffOverlay',
|
|
|
|
components: {
|
|
|
|
Icon,
|
|
|
|
},
|
2019-04-12 05:27:24 -04:00
|
|
|
mixins: [imageDiffMixin],
|
2018-10-18 03:50:38 -04:00
|
|
|
props: {
|
|
|
|
discussions: {
|
|
|
|
type: [Array, Object],
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
fileHash: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
canComment: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
showCommentIcon: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
badgeClass: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: 'badge badge-pill',
|
|
|
|
},
|
|
|
|
shouldToggleDiscussion: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters('diffs', ['getDiffFileByHash', 'getCommentFormForDiffFile']),
|
|
|
|
currentCommentForm() {
|
|
|
|
return this.getCommentFormForDiffFile(this.fileHash);
|
|
|
|
},
|
|
|
|
allDiscussions() {
|
|
|
|
return _.isArray(this.discussions) ? this.discussions : [this.discussions];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions('diffs', ['openDiffFileCommentForm']),
|
2018-11-06 04:40:03 -05:00
|
|
|
getImageDimensions() {
|
|
|
|
return {
|
|
|
|
width: this.$parent.width,
|
|
|
|
height: this.$parent.height,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
getPositionForObject(meta) {
|
|
|
|
const { x, y, width, height } = meta;
|
|
|
|
const imageWidth = this.getImageDimensions().width;
|
|
|
|
const imageHeight = this.getImageDimensions().height;
|
|
|
|
const widthRatio = imageWidth / width;
|
|
|
|
const heightRatio = imageHeight / height;
|
|
|
|
|
|
|
|
return {
|
|
|
|
x: Math.round(x * widthRatio),
|
|
|
|
y: Math.round(y * heightRatio),
|
|
|
|
};
|
|
|
|
},
|
2018-10-18 03:50:38 -04:00
|
|
|
getPosition(discussion) {
|
2018-11-06 04:40:03 -05:00
|
|
|
const { x, y } = this.getPositionForObject(discussion.position);
|
|
|
|
|
2018-10-18 03:50:38 -04:00
|
|
|
return {
|
2018-11-06 04:40:03 -05:00
|
|
|
left: `${x}px`,
|
|
|
|
top: `${y}px`,
|
2018-10-18 03:50:38 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
clickedImage(x, y) {
|
2018-11-06 04:40:03 -05:00
|
|
|
const { width, height } = this.getImageDimensions();
|
|
|
|
|
2018-10-18 03:50:38 -04:00
|
|
|
this.openDiffFileCommentForm({
|
|
|
|
fileHash: this.fileHash,
|
2018-11-06 04:40:03 -05:00
|
|
|
width,
|
|
|
|
height,
|
2018-10-18 03:50:38 -04:00
|
|
|
x,
|
|
|
|
y,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="position-absolute w-100 h-100 image-diff-overlay">
|
|
|
|
<button
|
|
|
|
v-if="canComment"
|
|
|
|
type="button"
|
|
|
|
class="btn-transparent position-absolute image-diff-overlay-add-comment w-100 h-100 js-add-image-diff-note-button"
|
2019-01-10 16:56:37 -05:00
|
|
|
@click="clickedImage($event.offsetX, $event.offsetY)"
|
2018-10-18 03:50:38 -04:00
|
|
|
>
|
2018-11-16 15:07:38 -05:00
|
|
|
<span class="sr-only"> {{ __('Add image comment') }} </span>
|
2018-10-18 03:50:38 -04:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-for="(discussion, index) in allDiscussions"
|
|
|
|
:key="discussion.id"
|
|
|
|
:style="getPosition(discussion)"
|
2019-04-12 05:27:24 -04:00
|
|
|
:class="[badgeClass, { 'is-draft': discussion.isDraft }]"
|
2018-10-18 03:50:38 -04:00
|
|
|
:disabled="!shouldToggleDiscussion"
|
|
|
|
class="js-image-badge"
|
|
|
|
type="button"
|
2019-04-12 05:27:24 -04:00
|
|
|
@click="clickedToggle(discussion)"
|
2018-10-18 03:50:38 -04:00
|
|
|
>
|
2018-11-16 15:07:38 -05:00
|
|
|
<icon v-if="showCommentIcon" name="image-comment-dark" />
|
2018-10-18 03:50:38 -04:00
|
|
|
<template v-else>
|
2019-04-12 05:27:24 -04:00
|
|
|
{{ toggleText(discussion, index) }}
|
2018-10-18 03:50:38 -04:00
|
|
|
</template>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-if="currentCommentForm"
|
|
|
|
:style="{
|
|
|
|
left: `${currentCommentForm.x}px`,
|
2018-11-16 15:07:38 -05:00
|
|
|
top: `${currentCommentForm.y}px`,
|
2018-10-18 03:50:38 -04:00
|
|
|
}"
|
|
|
|
:aria-label="__('Comment form position')"
|
|
|
|
class="btn-transparent comment-indicator"
|
|
|
|
type="button"
|
|
|
|
>
|
2018-11-16 15:07:38 -05:00
|
|
|
<icon name="image-comment-dark" />
|
2018-10-18 03:50:38 -04:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</template>
|