2018-09-17 07:17:00 -04:00
|
|
|
<script>
|
2020-01-21 16:08:54 -05:00
|
|
|
import Icon from '~/vue_shared/components/icon.vue';
|
2019-01-08 04:31:23 -05:00
|
|
|
import FileHeader from '~/vue_shared/components/file_row_header.vue';
|
2018-09-17 07:17:00 -04:00
|
|
|
import FileIcon from '~/vue_shared/components/file_icon.vue';
|
2018-10-03 05:05:43 -04:00
|
|
|
import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue';
|
2018-09-17 07:17:00 -04:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'FileRow',
|
|
|
|
components: {
|
2019-01-08 04:31:23 -05:00
|
|
|
FileHeader,
|
2018-09-17 07:17:00 -04:00
|
|
|
FileIcon,
|
2020-01-21 16:08:54 -05:00
|
|
|
Icon,
|
2018-10-03 05:05:43 -04:00
|
|
|
ChangedFileIcon,
|
2018-09-17 07:17:00 -04:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
file: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
level: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
extraComponent: {
|
|
|
|
type: Object,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
},
|
2018-10-03 05:05:43 -04:00
|
|
|
hideExtraOnTree: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
showChangedIcon: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2018-09-17 07:17:00 -04:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2019-04-04 14:55:49 -04:00
|
|
|
dropdownOpen: false,
|
2018-09-17 07:17:00 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
isTree() {
|
|
|
|
return this.file.type === 'tree';
|
|
|
|
},
|
|
|
|
isBlob() {
|
|
|
|
return this.file.type === 'blob';
|
|
|
|
},
|
|
|
|
levelIndentation() {
|
|
|
|
return {
|
2019-01-08 04:31:23 -05:00
|
|
|
marginLeft: this.level ? `${this.level * 16}px` : null,
|
2018-09-17 07:17:00 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
fileClass() {
|
|
|
|
return {
|
|
|
|
'file-open': this.isBlob && this.file.opened,
|
|
|
|
'is-active': this.isBlob && this.file.active,
|
|
|
|
folder: this.isTree,
|
|
|
|
'is-open': this.file.opened,
|
|
|
|
};
|
|
|
|
},
|
2019-01-08 04:31:23 -05:00
|
|
|
childFilesLevel() {
|
|
|
|
return this.file.isHeader ? 0 : this.level + 1;
|
2018-10-15 06:06:54 -04:00
|
|
|
},
|
2018-09-17 07:17:00 -04:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
'file.active': function fileActiveWatch(active) {
|
|
|
|
if (this.file.type === 'blob' && active) {
|
|
|
|
this.scrollIntoView();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
if (this.hasPathAtCurrentRoute()) {
|
|
|
|
this.scrollIntoView(true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
toggleTreeOpen(path) {
|
|
|
|
this.$emit('toggleTreeOpen', path);
|
|
|
|
},
|
2018-10-03 05:05:43 -04:00
|
|
|
clickedFile(path) {
|
|
|
|
this.$emit('clickFile', path);
|
|
|
|
},
|
2018-09-17 07:17:00 -04:00
|
|
|
clickFile() {
|
|
|
|
// Manual Action if a tree is selected/opened
|
|
|
|
if (this.isTree && this.hasUrlAtCurrentRoute()) {
|
|
|
|
this.toggleTreeOpen(this.file.path);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.$router) this.$router.push(`/project${this.file.url}`);
|
2018-10-03 05:05:43 -04:00
|
|
|
|
|
|
|
if (this.isBlob) this.clickedFile(this.file.path);
|
2018-09-17 07:17:00 -04:00
|
|
|
},
|
|
|
|
scrollIntoView(isInit = false) {
|
|
|
|
const block = isInit && this.isTree ? 'center' : 'nearest';
|
|
|
|
|
|
|
|
this.$el.scrollIntoView({
|
|
|
|
behavior: 'smooth',
|
|
|
|
block,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
hasPathAtCurrentRoute() {
|
|
|
|
if (!this.$router || !this.$router.currentRoute) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// - strip route up to "/-/" and ending "/"
|
|
|
|
const routePath = this.$router.currentRoute.path
|
|
|
|
.replace(/^.*?[/]-[/]/g, '')
|
|
|
|
.replace(/[/]$/g, '');
|
|
|
|
|
|
|
|
// - strip ending "/"
|
|
|
|
const filePath = this.file.path.replace(/[/]$/g, '');
|
|
|
|
|
|
|
|
return filePath === routePath;
|
|
|
|
},
|
|
|
|
hasUrlAtCurrentRoute() {
|
|
|
|
if (!this.$router || !this.$router.currentRoute) return true;
|
|
|
|
|
|
|
|
return this.$router.currentRoute.path === `/project${this.file.url}`;
|
|
|
|
},
|
2019-04-04 14:55:49 -04:00
|
|
|
toggleDropdown(val) {
|
|
|
|
this.dropdownOpen = val;
|
2018-09-17 07:17:00 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2019-10-04 11:06:38 -04:00
|
|
|
<div>
|
2019-01-08 04:31:23 -05:00
|
|
|
<file-header v-if="file.isHeader" :path="file.path" />
|
2018-09-17 07:17:00 -04:00
|
|
|
<div
|
2019-01-08 04:31:23 -05:00
|
|
|
v-else
|
2018-09-17 07:17:00 -04:00
|
|
|
:class="fileClass"
|
2019-02-13 07:42:29 -05:00
|
|
|
:title="file.name"
|
2018-09-17 07:17:00 -04:00
|
|
|
class="file-row"
|
|
|
|
role="button"
|
|
|
|
@click="clickFile"
|
2019-04-04 14:55:49 -04:00
|
|
|
@mouseleave="toggleDropdown(false)"
|
2018-09-17 07:17:00 -04:00
|
|
|
>
|
2018-11-16 15:07:38 -05:00
|
|
|
<div class="file-row-name-container">
|
2020-01-21 16:08:54 -05:00
|
|
|
<span ref="textOutput" :style="levelIndentation" class="file-row-name str-truncated">
|
2018-09-17 07:17:00 -04:00
|
|
|
<file-icon
|
2018-10-03 05:05:43 -04:00
|
|
|
v-if="!showChangedIcon || file.type === 'tree'"
|
2020-01-21 16:08:54 -05:00
|
|
|
class="file-row-icon"
|
2018-09-17 07:17:00 -04:00
|
|
|
:file-name="file.name"
|
|
|
|
:loading="file.loading"
|
|
|
|
:folder="isTree"
|
|
|
|
:opened="file.opened"
|
|
|
|
:size="16"
|
|
|
|
/>
|
2020-01-21 16:08:54 -05:00
|
|
|
<changed-file-icon v-else :file="file" :size="16" class="append-right-5" />
|
2019-01-08 04:31:23 -05:00
|
|
|
{{ file.name }}
|
2018-09-17 07:17:00 -04:00
|
|
|
</span>
|
|
|
|
<component
|
|
|
|
:is="extraComponent"
|
2018-10-03 05:05:43 -04:00
|
|
|
v-if="extraComponent && !(hideExtraOnTree && file.type === 'tree')"
|
2018-09-17 07:17:00 -04:00
|
|
|
:file="file"
|
2019-04-04 14:55:49 -04:00
|
|
|
:dropdown-open="dropdownOpen"
|
|
|
|
@toggle="toggleDropdown($event)"
|
2018-09-17 07:17:00 -04:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-01-08 04:31:23 -05:00
|
|
|
<template v-if="file.opened || file.isHeader">
|
2018-09-17 07:17:00 -04:00
|
|
|
<file-row
|
|
|
|
v-for="childFile in file.tree"
|
|
|
|
:key="childFile.key"
|
|
|
|
:file="childFile"
|
2019-01-08 04:31:23 -05:00
|
|
|
:level="childFilesLevel"
|
2018-10-03 05:05:43 -04:00
|
|
|
:hide-extra-on-tree="hideExtraOnTree"
|
2020-01-21 16:08:54 -05:00
|
|
|
:extra-component="extraComponent"
|
2018-10-03 05:05:43 -04:00
|
|
|
:show-changed-icon="showChangedIcon"
|
2018-09-17 07:17:00 -04:00
|
|
|
@toggleTreeOpen="toggleTreeOpen"
|
2018-10-03 05:05:43 -04:00
|
|
|
@clickFile="clickedFile"
|
2018-09-17 07:17:00 -04:00
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.file-row {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
height: 32px;
|
|
|
|
padding: 4px 8px;
|
|
|
|
margin-left: -8px;
|
|
|
|
margin-right: -8px;
|
|
|
|
border-radius: 3px;
|
|
|
|
text-align: left;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.file-row:hover,
|
|
|
|
.file-row:focus {
|
|
|
|
background: #f2f2f2;
|
|
|
|
}
|
|
|
|
|
|
|
|
.file-row:active {
|
|
|
|
background: #dfdfdf;
|
|
|
|
}
|
|
|
|
|
|
|
|
.file-row.is-active {
|
|
|
|
background: #f2f2f2;
|
|
|
|
}
|
|
|
|
|
|
|
|
.file-row-name-container {
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
align-items: center;
|
|
|
|
overflow: visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
.file-row-name {
|
|
|
|
display: inline-block;
|
|
|
|
flex: 1;
|
|
|
|
max-width: inherit;
|
2019-11-18 13:06:53 -05:00
|
|
|
height: 19px;
|
2018-09-17 07:17:00 -04:00
|
|
|
line-height: 16px;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: nowrap;
|
|
|
|
}
|
|
|
|
|
2019-08-15 22:52:15 -04:00
|
|
|
.file-row-name .file-row-icon {
|
2018-09-17 07:17:00 -04:00
|
|
|
margin-right: 2px;
|
|
|
|
vertical-align: middle;
|
|
|
|
}
|
|
|
|
</style>
|