mirror of
https://github.com/go-gitea/gitea
synced 2025-12-07 13:28:25 +00:00
add tree sidebar to file view
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
<script lang="ts" setup>
|
||||
import ViewFileTreeItem from './ViewFileTreeItem.vue';
|
||||
|
||||
defineProps<{
|
||||
files: any,
|
||||
selectedItem: string,
|
||||
loadChildren: any,
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="view-file-tree-items">
|
||||
<!-- only render the tree if we're visible. in many cases this is something that doesn't change very often -->
|
||||
<ViewFileTreeItem v-for="item in files" :key="item.name" :item="item" :selected-item="selectedItem" :load-children="loadChildren"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.view-file-tree-items {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
margin-right: .5rem;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,119 @@
|
||||
<script lang="ts" setup>
|
||||
import {SvgIcon} from '../svg.ts';
|
||||
import {ref} from 'vue';
|
||||
|
||||
type Item = {
|
||||
name: string;
|
||||
path: string;
|
||||
htmlUrl: string;
|
||||
isFile: boolean;
|
||||
children?: Item[];
|
||||
};
|
||||
|
||||
const props = defineProps<{
|
||||
item: Item,
|
||||
loadChildren: any;
|
||||
selectedItem?: string;
|
||||
}>();
|
||||
|
||||
const isLoading = ref(false);
|
||||
const collapsed = ref(!props.item.children);
|
||||
const children = ref(props.item.children);
|
||||
|
||||
const doLoadChildren = async () => {
|
||||
collapsed.value = !collapsed.value;
|
||||
if (!collapsed.value && props.loadChildren) {
|
||||
isLoading.value = true;
|
||||
const _children = await props.loadChildren(props.item);
|
||||
children.value = _children;
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const doLoadDirContent = () => {
|
||||
doLoadChildren();
|
||||
window.location.href = props.item.htmlUrl;
|
||||
};
|
||||
|
||||
const doLoadFileContent = () => {
|
||||
window.location.href = props.item.htmlUrl;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!--title instead of tooltip above as the tooltip needs too much work with the current methods, i.e. not being loaded or staying open for "too long"-->
|
||||
<div
|
||||
v-if="item.isFile" class="item-file"
|
||||
:class="{'selected': selectedItem === item.path}"
|
||||
:title="item.name"
|
||||
@click.stop="doLoadFileContent"
|
||||
>
|
||||
<!-- file -->
|
||||
<SvgIcon name="octicon-file"/>
|
||||
<span class="gt-ellipsis tw-flex-1">{{ item.name }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-else class="item-directory"
|
||||
:class="{'selected': selectedItem === item.path}"
|
||||
:title="item.name"
|
||||
@click.stop="doLoadDirContent"
|
||||
>
|
||||
<!-- directory -->
|
||||
<SvgIcon v-if="isLoading" name="octicon-sync" class="job-status-rotate"/>
|
||||
<SvgIcon v-else :name="collapsed ? 'octicon-chevron-right' : 'octicon-chevron-down'" @click.stop="doLoadChildren"/>
|
||||
<SvgIcon class="text primary" :name="collapsed ? 'octicon-file-directory-fill' : 'octicon-file-directory-open-fill'"/>
|
||||
<span class="gt-ellipsis">{{ item.name }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="children?.length" v-show="!collapsed" class="sub-items">
|
||||
<ViewFileTreeItem v-for="childItem in children" :key="childItem.name" :item="childItem" :selected-item="selectedItem" :load-children="loadChildren"/>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
a, a:hover {
|
||||
text-decoration: none;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.sub-items {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
margin-left: 13px;
|
||||
border-left: 1px solid var(--color-secondary);
|
||||
}
|
||||
|
||||
.sub-items .item-file {
|
||||
padding-left: 18px;
|
||||
}
|
||||
|
||||
.item-directory.selected, .item-file.selected {
|
||||
color: var(--color-text);
|
||||
background: var(--color-active);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.item-file.viewed {
|
||||
color: var(--color-text-light-3);
|
||||
}
|
||||
|
||||
.item-directory {
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.item-file,
|
||||
.item-directory {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25em;
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
.item-file:hover,
|
||||
.item-directory:hover {
|
||||
color: var(--color-text);
|
||||
background: var(--color-hover);
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user