2018-09-17 11:17:00 +00:00
|
|
|
<script>
|
2019-01-08 09:31:23 +00:00
|
|
|
import FileHeader from '~/vue_shared/components/file_row_header.vue';
|
2018-09-17 11:17:00 +00:00
|
|
|
import FileIcon from '~/vue_shared/components/file_icon.vue';
|
2020-02-25 09:09:10 +00:00
|
|
|
import { escapeFileUrl } from '~/lib/utils/url_utility';
|
2018-09-17 11:17:00 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'FileRow',
|
|
|
|
components: {
|
2019-01-08 09:31:23 +00:00
|
|
|
FileHeader,
|
2018-09-17 11:17:00 +00:00
|
|
|
FileIcon,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
file: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
level: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
isTree() {
|
|
|
|
return this.file.type === 'tree';
|
|
|
|
},
|
|
|
|
isBlob() {
|
|
|
|
return this.file.type === 'blob';
|
|
|
|
},
|
|
|
|
levelIndentation() {
|
|
|
|
return {
|
2019-01-08 09:31:23 +00:00
|
|
|
marginLeft: this.level ? `${this.level * 16}px` : null,
|
2018-09-17 11:17:00 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
fileClass() {
|
|
|
|
return {
|
|
|
|
'file-open': this.isBlob && this.file.opened,
|
2020-03-24 21:07:54 +00:00
|
|
|
'is-active': this.isBlob && this.file.active,
|
|
|
|
folder: this.isTree,
|
2018-09-17 11:17:00 +00:00
|
|
|
'is-open': this.file.opened,
|
|
|
|
};
|
|
|
|
},
|
2020-03-30 21:08:01 +00:00
|
|
|
textForTitle() {
|
|
|
|
// don't output a title if we don't have the expanded path
|
|
|
|
return this.file?.tree?.length ? this.file.tree[0].parentPath : false;
|
|
|
|
},
|
2018-09-17 11:17:00 +00: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 09:05:43 +00:00
|
|
|
clickedFile(path) {
|
|
|
|
this.$emit('clickFile', path);
|
|
|
|
},
|
2018-09-17 11:17:00 +00: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 09:05:43 +00:00
|
|
|
|
|
|
|
if (this.isBlob) this.clickedFile(this.file.path);
|
2018-09-17 11:17:00 +00: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;
|
|
|
|
|
2020-02-25 09:09:10 +00:00
|
|
|
return this.$router.currentRoute.path === `/project${escapeFileUrl(this.file.url)}`;
|
2018-09-17 11:17:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2020-02-07 18:09:03 +00:00
|
|
|
<file-header v-if="file.isHeader" :path="file.path" />
|
|
|
|
<div
|
|
|
|
v-else
|
|
|
|
:class="fileClass"
|
2020-03-30 21:08:01 +00:00
|
|
|
:title="textForTitle"
|
2020-04-14 03:09:39 +00:00
|
|
|
:data-level="level"
|
2020-03-24 21:07:54 +00:00
|
|
|
class="file-row"
|
2020-02-07 18:09:03 +00:00
|
|
|
role="button"
|
|
|
|
@click="clickFile"
|
2020-02-17 15:09:01 +00:00
|
|
|
@mouseleave="$emit('mouseleave', $event)"
|
2020-02-07 18:09:03 +00:00
|
|
|
>
|
2020-03-24 21:07:54 +00:00
|
|
|
<div class="file-row-name-container">
|
|
|
|
<span ref="textOutput" :style="levelIndentation" class="file-row-name str-truncated">
|
2020-02-07 18:09:03 +00:00
|
|
|
<file-icon
|
2020-03-24 21:07:54 +00:00
|
|
|
class="file-row-icon"
|
2020-02-17 21:09:20 +00:00
|
|
|
:class="{ 'text-secondary': file.type === 'tree' }"
|
2020-02-07 18:09:03 +00:00
|
|
|
:file-name="file.name"
|
|
|
|
:loading="file.loading"
|
|
|
|
:folder="isTree"
|
|
|
|
:opened="file.opened"
|
|
|
|
:size="16"
|
2018-09-17 11:17:00 +00:00
|
|
|
/>
|
2020-02-07 18:09:03 +00:00
|
|
|
{{ file.name }}
|
|
|
|
</span>
|
2020-02-17 15:09:01 +00:00
|
|
|
<slot></slot>
|
2020-02-07 18:09:03 +00:00
|
|
|
</div>
|
2018-09-17 11:17:00 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.file-row {
|
2020-03-24 21:07:54 +00:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2018-09-17 11:17:00 +00:00
|
|
|
height: 32px;
|
2020-03-24 21:07:54 +00:00
|
|
|
padding: 4px 8px;
|
|
|
|
margin-left: -8px;
|
|
|
|
margin-right: -8px;
|
2018-09-17 11:17:00 +00:00
|
|
|
border-radius: 3px;
|
2020-03-24 21:07:54 +00:00
|
|
|
text-align: left;
|
2018-09-17 11:17:00 +00:00
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.file-row-name-container {
|
2020-03-24 21:07:54 +00:00
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
align-items: center;
|
2018-09-17 11:17:00 +00:00
|
|
|
overflow: visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
.file-row-name {
|
2020-03-24 21:07:54 +00:00
|
|
|
display: inline-block;
|
2018-09-17 11:17:00 +00:00
|
|
|
flex: 1;
|
|
|
|
max-width: inherit;
|
2020-03-24 21:07:54 +00:00
|
|
|
height: 19px;
|
2018-09-17 11:17:00 +00:00
|
|
|
line-height: 16px;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: nowrap;
|
|
|
|
}
|
2020-03-24 21:07:54 +00:00
|
|
|
|
|
|
|
.file-row-name .file-row-icon {
|
|
|
|
margin-right: 2px;
|
|
|
|
vertical-align: middle;
|
|
|
|
}
|
2018-09-17 11:17:00 +00:00
|
|
|
</style>
|