Skip to content

Commit a585ab7

Browse files
committed
clean up
1 parent 8818416 commit a585ab7

File tree

2 files changed

+42
-44
lines changed

2 files changed

+42
-44
lines changed

services/repository/files/tree.go

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -140,36 +140,31 @@ func entryModeString(entryMode git.EntryMode) string {
140140
}
141141

142142
type TreeViewNode struct {
143-
Name string `json:"name"`
144-
Type string `json:"type"`
145-
Path string `json:"path"`
146-
SubModuleURL string `json:"sub_module_url,omitempty"`
143+
EntryName string `json:"entryName"`
144+
EntryMode string `json:"entryMode"`
145+
FullPath string `json:"fullPath"`
146+
SubmoduleURL string `json:"submoduleUrl,omitempty"`
147147
Children []*TreeViewNode `json:"children,omitempty"`
148148
}
149149

150150
func (node *TreeViewNode) sortLevel() int {
151-
switch node.Type {
152-
case "tree", "commit":
153-
return 0
154-
default:
155-
return 1
156-
}
151+
return util.Iif(node.EntryMode == "tree" || node.EntryMode == "commit", 0, 1)
157152
}
158153

159154
func newTreeViewNodeFromEntry(ctx context.Context, commit *git.Commit, parentDir string, entry *git.TreeEntry) *TreeViewNode {
160155
node := &TreeViewNode{
161-
Name: entry.Name(),
162-
Type: entryModeString(entry.Mode()),
163-
Path: path.Join(parentDir, entry.Name()),
156+
EntryName: entry.Name(),
157+
EntryMode: entryModeString(entry.Mode()),
158+
FullPath: path.Join(parentDir, entry.Name()),
164159
}
165160

166-
if node.Type == "commit" {
167-
if subModule, err := commit.GetSubModule(node.Path); err != nil {
161+
if node.EntryMode == "commit" {
162+
if subModule, err := commit.GetSubModule(node.FullPath); err != nil {
168163
log.Error("GetSubModule: %v", err)
169164
} else if subModule != nil {
170165
submoduleFile := git.NewCommitSubmoduleFile(subModule.URL, entry.ID.String())
171166
webLink := submoduleFile.SubmoduleWebLink(ctx)
172-
node.SubModuleURL = webLink.CommitWebLink
167+
node.SubmoduleURL = webLink.CommitWebLink
173168
}
174169
}
175170

@@ -179,10 +174,11 @@ func newTreeViewNodeFromEntry(ctx context.Context, commit *git.Commit, parentDir
179174
// sortTreeViewNodes list directory first and with alpha sequence
180175
func sortTreeViewNodes(nodes []*TreeViewNode) {
181176
sort.Slice(nodes, func(i, j int) bool {
182-
if nodes[i].sortLevel() != nodes[j].sortLevel() {
183-
return nodes[i].sortLevel() < nodes[j].sortLevel()
177+
a, b := nodes[i].sortLevel(), nodes[j].sortLevel()
178+
if a != b {
179+
return a < b
184180
}
185-
return nodes[i].Name < nodes[j].Name
181+
return nodes[i].EntryName < nodes[j].EntryName
186182
})
187183
}
188184

@@ -198,7 +194,7 @@ func listTreeNodes(ctx context.Context, commit *git.Commit, tree *git.Tree, tree
198194
node := newTreeViewNodeFromEntry(ctx, commit, treePath, entry)
199195
nodes = append(nodes, node)
200196
if entry.IsDir() && subPathDirName == entry.Name() {
201-
subTreePath := treePath + "/" + node.Name
197+
subTreePath := treePath + "/" + node.EntryName
202198
if subTreePath[0] == '/' {
203199
subTreePath = subTreePath[1:]
204200
}

web_src/js/components/ViewFileTreeItem.vue

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {SvgIcon} from '../svg.ts';
33
import {ref} from 'vue';
44
55
type Item = {
6-
name: string;
7-
path: string;
8-
sub_module_url?: string;
9-
type: string;
6+
entryName: string;
7+
entryMode: string;
8+
fullPath: string;
9+
submoduleUrl?: string;
1010
children?: Item[];
1111
};
1212
@@ -26,7 +26,7 @@ const doLoadChildren = async () => {
2626
if (!collapsed.value && props.loadChildren) {
2727
isLoading.value = true;
2828
try {
29-
children.value = await props.loadChildren(props.item.path);
29+
children.value = await props.loadChildren(props.item.fullPath);
3030
} finally {
3131
isLoading.value = false;
3232
}
@@ -35,59 +35,59 @@ const doLoadChildren = async () => {
3535
3636
const doLoadDirContent = () => {
3737
doLoadChildren();
38-
props.loadContent(props.item.path);
38+
props.loadContent(props.item.fullPath);
3939
};
4040
4141
const doLoadFileContent = () => {
42-
props.loadContent(props.item.path);
42+
props.loadContent(props.item.fullPath);
4343
};
4444
4545
const doGotoSubModule = () => {
46-
location.href = props.item.sub_module_url;
46+
location.href = props.item.submoduleUrl;
4747
};
4848
</script>
4949

5050
<template>
5151
<!--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"-->
5252
<div
53-
v-if="item.type === 'commit'" class="tree-item type-submodule"
54-
:title="item.name"
53+
v-if="item.entryMode === 'commit'" class="tree-item type-submodule"
54+
:title="item.entryName"
5555
@click.stop="doGotoSubModule"
5656
>
5757
<!-- submodule -->
5858
<div class="item-content">
5959
<SvgIcon class="text primary" name="octicon-file-submodule"/>
60-
<span class="gt-ellipsis tw-flex-1">{{ item.name }}</span>
60+
<span class="gt-ellipsis tw-flex-1">{{ item.entryName }}</span>
6161
</div>
6262
</div>
6363
<div
64-
v-else-if="item.type === 'symlink'" class="tree-item type-symlink"
65-
:class="{'selected': selectedItem.value === item.path}"
66-
:title="item.name"
64+
v-else-if="item.entryMode === 'symlink'" class="tree-item type-symlink"
65+
:class="{'selected': selectedItem.value === item.fullPath}"
66+
:title="item.entryName"
6767
@click.stop="doLoadFileContent"
6868
>
6969
<!-- symlink -->
7070
<div class="item-content">
7171
<SvgIcon name="octicon-file-symlink-file"/>
72-
<span class="gt-ellipsis tw-flex-1">{{ item.name }}</span>
72+
<span class="gt-ellipsis tw-flex-1">{{ item.entryName }}</span>
7373
</div>
7474
</div>
7575
<div
76-
v-else-if="item.type !== 'tree'" class="tree-item type-file"
77-
:class="{'selected': selectedItem.value === item.path}"
78-
:title="item.name"
76+
v-else-if="item.entryMode !== 'tree'" class="tree-item type-file"
77+
:class="{'selected': selectedItem.value === item.fullPath}"
78+
:title="item.entryName"
7979
@click.stop="doLoadFileContent"
8080
>
8181
<!-- file -->
8282
<div class="item-content">
8383
<SvgIcon name="octicon-file"/>
84-
<span class="gt-ellipsis tw-flex-1">{{ item.name }}</span>
84+
<span class="gt-ellipsis tw-flex-1">{{ item.entryName }}</span>
8585
</div>
8686
</div>
8787
<div
8888
v-else class="tree-item type-directory"
89-
:class="{'selected': selectedItem.value === item.path}"
90-
:title="item.name"
89+
:class="{'selected': selectedItem.value === item.fullPath}"
90+
:title="item.entryName"
9191
@click.stop="doLoadDirContent"
9292
>
9393
<!-- directory -->
@@ -97,12 +97,12 @@ const doGotoSubModule = () => {
9797
</div>
9898
<div class="item-content">
9999
<SvgIcon class="text primary" :name="collapsed ? 'octicon-file-directory-fill' : 'octicon-file-directory-open-fill'"/>
100-
<span class="gt-ellipsis">{{ item.name }}</span>
100+
<span class="gt-ellipsis">{{ item.entryName }}</span>
101101
</div>
102102
</div>
103103

104104
<div v-if="children?.length" v-show="!collapsed" class="sub-items">
105-
<ViewFileTreeItem v-for="childItem in children" :key="childItem.name" :item="childItem" :selected-item="selectedItem" :load-content="loadContent" :load-children="loadChildren"/>
105+
<ViewFileTreeItem v-for="childItem in children" :key="childItem.entryName" :item="childItem" :selected-item="selectedItem" :load-content="loadContent" :load-children="loadChildren"/>
106106
</div>
107107
</template>
108108
<style scoped>
@@ -120,7 +120,7 @@ const doGotoSubModule = () => {
120120
border-radius: 4px;
121121
}
122122
123-
.tree-item.type-directory {
123+
.tree-item.entryMode-directory {
124124
user-select: none;
125125
}
126126
@@ -150,5 +150,7 @@ const doGotoSubModule = () => {
150150
display: flex;
151151
align-items: center;
152152
gap: 0.25em;
153+
text-overflow: ellipsis;
154+
min-width: 0;
153155
}
154156
</style>

0 commit comments

Comments
 (0)