debian-mirror-gitlab/app/assets/javascripts/ide/components/changed_file_icon.vue

89 lines
2 KiB
Vue
Raw Normal View History

2018-05-09 12:01:36 +05:30
<script>
2018-10-15 14:42:47 +05:30
import tooltip from '~/vue_shared/directives/tooltip';
import Icon from '~/vue_shared/components/icon.vue';
import { pluralize } from '~/lib/utils/text_utility';
import { __, sprintf } from '~/locale';
2018-05-09 12:01:36 +05:30
export default {
components: {
2018-10-15 14:42:47 +05:30
Icon,
},
directives: {
tooltip,
2018-05-09 12:01:36 +05:30
},
props: {
file: {
type: Object,
required: true,
},
2018-10-15 14:42:47 +05:30
showTooltip: {
type: Boolean,
required: false,
default: false,
},
showStagedIcon: {
type: Boolean,
required: false,
default: false,
},
forceModifiedIcon: {
type: Boolean,
required: false,
default: false,
},
2018-05-09 12:01:36 +05:30
},
computed: {
changedIcon() {
2018-10-15 14:42:47 +05:30
const suffix = this.file.staged && !this.showStagedIcon ? '-solid' : '';
return this.file.tempFile && !this.forceModifiedIcon
? `file-addition${suffix}`
: `file-modified${suffix}`;
},
stagedIcon() {
return `${this.changedIcon}-solid`;
2018-05-09 12:01:36 +05:30
},
changedIconClass() {
2018-10-15 14:42:47 +05:30
return `multi-${this.changedIcon} pull-left`;
},
tooltipTitle() {
if (!this.showTooltip) return undefined;
const type = this.file.tempFile ? 'addition' : 'modification';
if (this.file.changed && !this.file.staged) {
return sprintf(__('Unstaged %{type}'), {
type,
});
} else if (!this.file.changed && this.file.staged) {
return sprintf(__('Staged %{type}'), {
type,
});
} else if (this.file.changed && this.file.staged) {
return sprintf(__('Unstaged and staged %{type}'), {
type: pluralize(type),
});
}
return undefined;
2018-05-09 12:01:36 +05:30
},
},
};
</script>
<template>
2018-10-15 14:42:47 +05:30
<span
v-tooltip
:title="tooltipTitle"
data-container="body"
data-placement="right"
class="ide-file-changed-icon"
>
<icon
v-if="file.changed || file.tempFile || file.staged"
:name="changedIcon"
:size="12"
:css-classes="changedIconClass"
/>
</span>
2018-05-09 12:01:36 +05:30
</template>