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

113 lines
2.3 KiB
Vue
Raw Normal View History

2018-05-09 12:01:36 +05:30
<script>
import { mapActions } from 'vuex';
import FileIcon from '~/vue_shared/components/file_icon.vue';
import Icon from '~/vue_shared/components/icon.vue';
2018-12-05 23:21:45 +05:30
import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue';
2018-05-09 12:01:36 +05:30
import FileStatusIcon from './repo_file_status_icon.vue';
export default {
components: {
FileStatusIcon,
FileIcon,
Icon,
ChangedFileIcon,
},
props: {
tab: {
type: Object,
required: true,
},
},
data() {
return {
tabMouseOver: false,
};
},
computed: {
closeLabel() {
2018-10-15 14:42:47 +05:30
if (this.fileHasChanged) {
2018-05-09 12:01:36 +05:30
return `${this.tab.name} changed`;
}
return `Close ${this.tab.name}`;
},
showChangedIcon() {
2018-10-15 14:42:47 +05:30
if (this.tab.pending) return true;
return this.fileHasChanged ? !this.tabMouseOver : false;
},
fileHasChanged() {
2018-11-18 11:00:15 +05:30
return this.tab.changed || this.tab.tempFile || this.tab.staged || this.tab.deleted;
2018-05-09 12:01:36 +05:30
},
},
methods: {
...mapActions(['closeFile', 'updateDelayViewerUpdated', 'openPendingTab']),
clickFile(tab) {
2018-11-08 19:23:39 +05:30
if (tab.active) return;
2018-05-09 12:01:36 +05:30
this.updateDelayViewerUpdated(true);
if (tab.pending) {
2018-10-15 14:42:47 +05:30
this.openPendingTab({ file: tab, keyPrefix: tab.staged ? 'staged' : 'unstaged' });
2018-05-09 12:01:36 +05:30
} else {
this.$router.push(`/project${tab.url}`);
}
},
mouseOverTab() {
2018-10-15 14:42:47 +05:30
if (this.fileHasChanged) {
2018-05-09 12:01:36 +05:30
this.tabMouseOver = true;
}
},
mouseOutTab() {
2018-10-15 14:42:47 +05:30
if (this.fileHasChanged) {
2018-05-09 12:01:36 +05:30
this.tabMouseOver = false;
}
},
},
};
</script>
<template>
<li
2018-10-15 14:42:47 +05:30
:class="{
2018-11-18 11:00:15 +05:30
active: tab.active,
2019-01-03 12:48:30 +05:30
disabled: tab.pending
2018-10-15 14:42:47 +05:30
}"
2019-01-03 12:48:30 +05:30
@click="clickFile(tab)"
2018-05-09 12:01:36 +05:30
@mouseover="mouseOverTab"
@mouseout="mouseOutTab"
>
2019-01-03 12:48:30 +05:30
<div
:title="tab.url"
class="multi-file-tab"
>
<file-icon
:file-name="tab.name"
:size="16"
/>
2018-10-15 14:42:47 +05:30
{{ tab.name }}
2019-01-03 12:48:30 +05:30
<file-status-icon
:file="tab"
/>
2018-10-15 14:42:47 +05:30
</div>
2018-05-09 12:01:36 +05:30
<button
2018-11-08 19:23:39 +05:30
:aria-label="closeLabel"
:disabled="tab.pending"
2018-05-09 12:01:36 +05:30
type="button"
class="multi-file-tab-close"
2019-01-03 12:48:30 +05:30
@click.stop.prevent="closeFile(tab)"
2018-05-09 12:01:36 +05:30
>
2019-01-03 12:48:30 +05:30
<icon
v-if="!showChangedIcon"
:size="12"
name="close"
/>
<changed-file-icon
v-else
:file="tab"
/>
2018-05-09 12:01:36 +05:30
</button>
</li>
</template>