mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 09:07:54 +01:00
add tree sidebar to file view
This commit is contained in:
parent
59e46d46e0
commit
c4e7f0c119
@ -1,4 +1,11 @@
|
|||||||
{{template "base/head" .}}
|
{{template "base/head" .}}
|
||||||
|
{{$treeNamesLen := len .TreeNames}}
|
||||||
|
{{$isTreePathRoot := eq $treeNamesLen 0}}
|
||||||
|
{{$showSidebar := $isTreePathRoot}}
|
||||||
|
{{$hasTreeSidebar := not $isTreePathRoot}}
|
||||||
|
{{$showTreeSidebar := .RepoPreferences.ShowFileViewTreeSidebar}}
|
||||||
|
{{$hideTreeSidebar := not $showTreeSidebar}}
|
||||||
|
{{$hasAndShowTreeSidebar := and $hasTreeSidebar $showTreeSidebar}}
|
||||||
<div role="main" aria-label="{{.Title}}" class="page-content repository file list {{if .IsBlame}}blame{{end}}">
|
<div role="main" aria-label="{{.Title}}" class="page-content repository file list {{if .IsBlame}}blame{{end}}">
|
||||||
{{template "repo/header" .}}
|
{{template "repo/header" .}}
|
||||||
<div class="ui container {{if .IsBlame}}fluid padded{{end}}">
|
<div class="ui container {{if .IsBlame}}fluid padded{{end}}">
|
||||||
@ -16,13 +23,6 @@
|
|||||||
|
|
||||||
{{template "repo/code/recently_pushed_new_branches" .}}
|
{{template "repo/code/recently_pushed_new_branches" .}}
|
||||||
|
|
||||||
{{$treeNamesLen := len .TreeNames}}
|
|
||||||
{{$isTreePathRoot := eq $treeNamesLen 0}}
|
|
||||||
{{$showSidebar := $isTreePathRoot}}
|
|
||||||
{{$hasTreeSidebar := not $isTreePathRoot}}
|
|
||||||
{{$showTreeSidebar := .RepoPreferences.ShowFileViewTreeSidebar}}
|
|
||||||
{{$hideTreeSidebar := not $showTreeSidebar}}
|
|
||||||
{{$hasAndShowTreeSidebar := and $hasTreeSidebar $showTreeSidebar}}
|
|
||||||
<div class="{{Iif $showSidebar "repo-grid-filelist-sidebar" (Iif $showTreeSidebar "repo-grid-tree-sidebar" "repo-grid-filelist-only")}}">
|
<div class="{{Iif $showSidebar "repo-grid-filelist-sidebar" (Iif $showTreeSidebar "repo-grid-tree-sidebar" "repo-grid-filelist-only")}}">
|
||||||
{{if $hasTreeSidebar}}
|
{{if $hasTreeSidebar}}
|
||||||
<div class="repo-view-file-tree-sidebar not-mobile {{if $hideTreeSidebar}}tw-hidden{{end}}">{{template "repo/view_file_tree_sidebar" .}}</div>
|
<div class="repo-view-file-tree-sidebar not-mobile {{if $hideTreeSidebar}}tw-hidden{{end}}">{{template "repo/view_file_tree_sidebar" .}}</div>
|
||||||
|
@ -3,15 +3,16 @@ import ViewFileTreeItem from './ViewFileTreeItem.vue';
|
|||||||
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
files: any,
|
files: any,
|
||||||
selectedItem: string,
|
selectedItem: any,
|
||||||
loadChildren: any,
|
loadChildren: any,
|
||||||
|
loadContent: any;
|
||||||
}>();
|
}>();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="view-file-tree-items">
|
<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 -->
|
<!-- 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"/>
|
<ViewFileTreeItem v-for="item in files" :key="item.name" :item="item" :selected-item="selectedItem" :load-content="loadContent" :load-children="loadChildren"/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -12,13 +12,14 @@ type Item = {
|
|||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
item: Item,
|
item: Item,
|
||||||
|
loadContent: any;
|
||||||
loadChildren: any;
|
loadChildren: any;
|
||||||
selectedItem?: string;
|
selectedItem?: any;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const isLoading = ref(false);
|
const isLoading = ref(false);
|
||||||
const collapsed = ref(!props.item.children);
|
|
||||||
const children = ref(props.item.children);
|
const children = ref(props.item.children);
|
||||||
|
const collapsed = ref(!props.item.children);
|
||||||
|
|
||||||
const doLoadChildren = async () => {
|
const doLoadChildren = async () => {
|
||||||
collapsed.value = !collapsed.value;
|
collapsed.value = !collapsed.value;
|
||||||
@ -32,11 +33,11 @@ const doLoadChildren = async () => {
|
|||||||
|
|
||||||
const doLoadDirContent = () => {
|
const doLoadDirContent = () => {
|
||||||
doLoadChildren();
|
doLoadChildren();
|
||||||
window.location.href = props.item.htmlUrl;
|
props.loadContent(props.item);
|
||||||
};
|
};
|
||||||
|
|
||||||
const doLoadFileContent = () => {
|
const doLoadFileContent = () => {
|
||||||
window.location.href = props.item.htmlUrl;
|
props.loadContent(props.item);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ const doLoadFileContent = () => {
|
|||||||
<!--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"-->
|
<!--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
|
<div
|
||||||
v-if="item.isFile" class="item-file"
|
v-if="item.isFile" class="item-file"
|
||||||
:class="{'selected': selectedItem === item.path}"
|
:class="{'selected': selectedItem.value === item.path}"
|
||||||
:title="item.name"
|
:title="item.name"
|
||||||
@click.stop="doLoadFileContent"
|
@click.stop="doLoadFileContent"
|
||||||
>
|
>
|
||||||
@ -54,7 +55,7 @@ const doLoadFileContent = () => {
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-else class="item-directory"
|
v-else class="item-directory"
|
||||||
:class="{'selected': selectedItem === item.path}"
|
:class="{'selected': selectedItem.value === item.path}"
|
||||||
:title="item.name"
|
:title="item.name"
|
||||||
@click.stop="doLoadDirContent"
|
@click.stop="doLoadDirContent"
|
||||||
>
|
>
|
||||||
@ -66,7 +67,7 @@ const doLoadFileContent = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="children?.length" v-show="!collapsed" class="sub-items">
|
<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"/>
|
<ViewFileTreeItem v-for="childItem in children" :key="childItem.name" :item="childItem" :selected-item="selectedItem" :load-content="loadContent" :load-children="loadChildren"/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {createApp} from 'vue';
|
import {createApp, ref} from 'vue';
|
||||||
import {toggleElem} from '../utils/dom.ts';
|
import {toggleElem} from '../utils/dom.ts';
|
||||||
import {GET, PUT} from '../modules/fetch.ts';
|
import {GET, PUT} from '../modules/fetch.ts';
|
||||||
import ViewFileTree from '../components/ViewFileTree.vue';
|
import ViewFileTree from '../components/ViewFileTree.vue';
|
||||||
@ -64,6 +64,10 @@ async function loadRecursive(treePath) {
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function loadContent(item) {
|
||||||
|
document.querySelector('.repo-home-filelist').innerHTML = `load content of ${item.path}`;
|
||||||
|
}
|
||||||
|
|
||||||
export async function initViewFileTreeSidebar() {
|
export async function initViewFileTreeSidebar() {
|
||||||
const sidebarElement = document.querySelector('.repo-view-file-tree-sidebar');
|
const sidebarElement = document.querySelector('.repo-view-file-tree-sidebar');
|
||||||
if (!sidebarElement) return;
|
if (!sidebarElement) return;
|
||||||
@ -78,10 +82,15 @@ export async function initViewFileTreeSidebar() {
|
|||||||
|
|
||||||
const fileTree = document.querySelector('#view-file-tree');
|
const fileTree = document.querySelector('#view-file-tree');
|
||||||
const treePath = fileTree.getAttribute('data-tree-path');
|
const treePath = fileTree.getAttribute('data-tree-path');
|
||||||
|
const selectedItem = ref(treePath);
|
||||||
|
|
||||||
const files = await loadRecursive(treePath);
|
const files = await loadRecursive(treePath);
|
||||||
|
|
||||||
fileTree.classList.remove('center');
|
fileTree.classList.remove('center');
|
||||||
const fileTreeView = createApp(ViewFileTree, {files, selectedItem: treePath, loadChildren});
|
const fileTreeView = createApp(ViewFileTree, {files, selectedItem, loadChildren, loadContent: (item) => {
|
||||||
|
window.history.pushState(null, null, item.htmlUrl);
|
||||||
|
selectedItem.value = item.path;
|
||||||
|
loadContent(item);
|
||||||
|
}});
|
||||||
fileTreeView.mount(fileTree);
|
fileTreeView.mount(fileTree);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user