forked from forgejo/forgejo
Add filetree on left of diff view (#21012)
This PR adds a filetree to the left side of the files/diff view. Initially the filetree will not be shown and may be shown via a new "Show file tree" button. Showing and hiding is using the same icon as github. Folders are collapsible. On small devices (max-width 991 PX) the file tree will be hidden. Close #18192 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
525751243e
commit
31f934c1d8
13 changed files with 591 additions and 159 deletions
81
web_src/js/components/DiffFileList.vue
Normal file
81
web_src/js/components/DiffFileList.vue
Normal file
|
@ -0,0 +1,81 @@
|
|||
<template>
|
||||
<ol class="diff-detail-box diff-stats m-0" id="diff-files" v-if="fileListIsVisible">
|
||||
<li v-for="file in files" :key="file.NameHash">
|
||||
<div class="bold df ac pull-right">
|
||||
<span v-if="file.IsBin" class="ml-1 mr-3">{{ binaryFileMessage }}</span>
|
||||
{{ file.IsBin ? '' : file.Addition + file.Deletion }}
|
||||
<span v-if="!file.IsBin" class="diff-stats-bar tooltip mx-3" :data-content="statisticsMessage.replace('%d', (file.Addition + file.Deletion)).replace('%d', file.Addition).replace('%d', file.Deletion)">
|
||||
<div class="diff-stats-add-bar" :style="{ 'width': diffStatsWidth(file.Addition, file.Deletion) }" />
|
||||
</span>
|
||||
</div>
|
||||
<!-- todo finish all file status, now modify, add, delete and rename -->
|
||||
<span :class="['status', diffTypeToString(file.Type), 'tooltip']" :data-content="diffTypeToString(file.Type)" data-position="right center"> </span>
|
||||
<a class="file mono" :href="'#diff-' + file.NameHash">{{ file.Name }}</a>
|
||||
</li>
|
||||
<li v-if="isIncomplete" id="diff-too-many-files-stats" class="pt-2">
|
||||
<span class="file df ac sb">{{ tooManyFilesMessage }}
|
||||
<a :class="['ui', 'basic', 'tiny', 'button', isLoadingNewData === true ? 'disabled' : '']" id="diff-show-more-files-stats" @click.stop="loadMoreData">{{ showMoreMessage }}</a>
|
||||
</span>
|
||||
</li>
|
||||
</ol>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {initTooltip} from '../modules/tippy.js';
|
||||
import {doLoadMoreFiles} from '../features/repo-diff.js';
|
||||
|
||||
const {pageData} = window.config;
|
||||
|
||||
export default {
|
||||
name: 'DiffFileList',
|
||||
|
||||
data: () => {
|
||||
return pageData.diffFileInfo;
|
||||
},
|
||||
|
||||
watch: {
|
||||
fileListIsVisible(newValue) {
|
||||
if (newValue === true) {
|
||||
this.$nextTick(() => {
|
||||
for (const el of this.$el.querySelectorAll('.tooltip')) {
|
||||
initTooltip(el);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
document.getElementById('show-file-list-btn').addEventListener('click', this.toggleFileList);
|
||||
},
|
||||
|
||||
unmounted() {
|
||||
document.getElementById('show-file-list-btn').removeEventListener('click', this.toggleFileList);
|
||||
},
|
||||
|
||||
methods: {
|
||||
toggleFileList() {
|
||||
this.fileListIsVisible = !this.fileListIsVisible;
|
||||
},
|
||||
diffTypeToString(pType) {
|
||||
const diffTypes = {
|
||||
1: 'add',
|
||||
2: 'modify',
|
||||
3: 'del',
|
||||
4: 'rename',
|
||||
5: 'copy',
|
||||
};
|
||||
return diffTypes[pType];
|
||||
},
|
||||
diffStatsWidth(adds, dels) {
|
||||
return `${adds / (adds + dels) * 100}%`;
|
||||
},
|
||||
loadMoreData() {
|
||||
this.isLoadingNewData = true;
|
||||
doLoadMoreFiles(this.link, this.diffEnd, () => {
|
||||
this.isLoadingNewData = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue