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';
import FileStatusIcon from './repo_file_status_icon.vue';
import ChangedFileIcon from './changed_file_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,
disabled: tab.pending
2018-10-15 14:42:47 +05:30
}"
2018-05-09 12:01:36 +05:30
@click="clickFile(tab)"
@mouseover="mouseOverTab"
@mouseout="mouseOutTab"
>
2018-10-15 14:42:47 +05:30
<div
:title="tab.url"
2018-11-08 19:23:39 +05:30
class="multi-file-tab"
2018-10-15 14:42:47 +05:30
>
<file-icon
:file-name="tab.name"
:size="16"
/>
{{ tab.name }}
<file-status-icon
:file="tab"
/>
</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"
@click.stop.prevent="closeFile(tab)"
>
<icon
v-if="!showChangedIcon"
:size="12"
2018-11-08 19:23:39 +05:30
name="close"
2018-05-09 12:01:36 +05:30
/>
<changed-file-icon
v-else
:file="tab"
/>
</button>
</li>
</template>