2022-09-27 10:52:19 +05:30
|
|
|
<script>
|
|
|
|
import DiffFileTreeItem from './DiffFileTreeItem.vue';
|
2023-05-30 16:23:15 +05:30
|
|
|
import {loadMoreFiles} from '../features/repo-diff.js';
|
2023-03-30 17:36:10 +05:30
|
|
|
import {toggleElem} from '../utils/dom.js';
|
2023-05-30 16:23:15 +05:30
|
|
|
import {diffTreeStore} from '../modules/stores.js';
|
2023-04-12 12:36:39 +05:30
|
|
|
import {setFileFolding} from '../features/file-fold.js';
|
2022-09-27 10:52:19 +05:30
|
|
|
|
|
|
|
const LOCAL_STORAGE_KEY = 'diff_file_tree_visible';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {DiffFileTreeItem},
|
|
|
|
data: () => {
|
2023-05-30 16:23:15 +05:30
|
|
|
return {store: diffTreeStore()};
|
2022-09-27 10:52:19 +05:30
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
fileTree() {
|
|
|
|
const result = [];
|
2023-05-30 16:23:15 +05:30
|
|
|
for (const file of this.store.files) {
|
2022-09-27 10:52:19 +05:30
|
|
|
// Split file into directories
|
|
|
|
const splits = file.Name.split('/');
|
|
|
|
let index = 0;
|
|
|
|
let parent = null;
|
|
|
|
let isFile = false;
|
|
|
|
for (const split of splits) {
|
|
|
|
index += 1;
|
|
|
|
// reached the end
|
|
|
|
if (index === splits.length) {
|
|
|
|
isFile = true;
|
|
|
|
}
|
|
|
|
let newParent = {
|
|
|
|
name: split,
|
|
|
|
children: [],
|
2024-03-22 19:36:53 +05:30
|
|
|
isFile,
|
2022-09-27 10:52:19 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
if (isFile === true) {
|
|
|
|
newParent.file = file;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
// check if the folder already exists
|
|
|
|
const existingFolder = parent.children.find(
|
2024-03-22 19:36:53 +05:30
|
|
|
(x) => x.name === split,
|
2022-09-27 10:52:19 +05:30
|
|
|
);
|
|
|
|
if (existingFolder) {
|
|
|
|
newParent = existingFolder;
|
|
|
|
} else {
|
|
|
|
parent.children.push(newParent);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const existingFolder = result.find((x) => x.name === split);
|
|
|
|
if (existingFolder) {
|
|
|
|
newParent = existingFolder;
|
|
|
|
} else {
|
|
|
|
result.push(newParent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parent = newParent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const mergeChildIfOnlyOneDir = (entries) => {
|
|
|
|
for (const entry of entries) {
|
|
|
|
if (entry.children) {
|
|
|
|
mergeChildIfOnlyOneDir(entry.children);
|
|
|
|
}
|
|
|
|
if (entry.children.length === 1 && entry.children[0].isFile === false) {
|
|
|
|
// Merge it to the parent
|
|
|
|
entry.name = `${entry.name}/${entry.children[0].name}`;
|
|
|
|
entry.children = entry.children[0].children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// Merge folders with just a folder as children in order to
|
|
|
|
// reduce the depth of our tree.
|
|
|
|
mergeChildIfOnlyOneDir(result);
|
|
|
|
return result;
|
2024-03-22 19:36:53 +05:30
|
|
|
},
|
2022-09-27 10:52:19 +05:30
|
|
|
},
|
|
|
|
mounted() {
|
2023-06-02 21:09:01 +05:30
|
|
|
// Default to true if unset
|
|
|
|
this.store.fileTreeIsVisible = localStorage.getItem(LOCAL_STORAGE_KEY) !== 'false';
|
2022-09-27 10:52:19 +05:30
|
|
|
document.querySelector('.diff-toggle-file-tree-button').addEventListener('click', this.toggleVisibility);
|
2023-04-07 23:57:10 +05:30
|
|
|
|
|
|
|
this.hashChangeListener = () => {
|
2023-04-12 06:14:26 +05:30
|
|
|
this.store.selectedItem = window.location.hash;
|
2023-04-12 12:36:39 +05:30
|
|
|
this.expandSelectedFile();
|
2023-04-07 23:57:10 +05:30
|
|
|
};
|
2023-04-12 06:14:26 +05:30
|
|
|
this.hashChangeListener();
|
|
|
|
window.addEventListener('hashchange', this.hashChangeListener);
|
2022-09-27 10:52:19 +05:30
|
|
|
},
|
|
|
|
unmounted() {
|
|
|
|
document.querySelector('.diff-toggle-file-tree-button').removeEventListener('click', this.toggleVisibility);
|
2023-04-07 23:57:10 +05:30
|
|
|
window.removeEventListener('hashchange', this.hashChangeListener);
|
2022-09-27 10:52:19 +05:30
|
|
|
},
|
|
|
|
methods: {
|
2023-04-12 12:36:39 +05:30
|
|
|
expandSelectedFile() {
|
|
|
|
// expand file if the selected file is folded
|
|
|
|
if (this.store.selectedItem) {
|
|
|
|
const box = document.querySelector(this.store.selectedItem);
|
|
|
|
const folded = box?.getAttribute('data-folded') === 'true';
|
|
|
|
if (folded) setFileFolding(box, box.querySelector('.fold-file'), false);
|
|
|
|
}
|
|
|
|
},
|
2022-09-27 10:52:19 +05:30
|
|
|
toggleVisibility() {
|
2023-05-30 16:23:15 +05:30
|
|
|
this.updateVisibility(!this.store.fileTreeIsVisible);
|
2022-09-27 10:52:19 +05:30
|
|
|
},
|
|
|
|
updateVisibility(visible) {
|
2023-05-30 16:23:15 +05:30
|
|
|
this.store.fileTreeIsVisible = visible;
|
|
|
|
localStorage.setItem(LOCAL_STORAGE_KEY, this.store.fileTreeIsVisible);
|
|
|
|
this.updateState(this.store.fileTreeIsVisible);
|
2022-09-27 10:52:19 +05:30
|
|
|
},
|
2023-03-30 17:36:10 +05:30
|
|
|
updateState(visible) {
|
|
|
|
const btn = document.querySelector('.diff-toggle-file-tree-button');
|
|
|
|
const [toShow, toHide] = btn.querySelectorAll('.icon');
|
|
|
|
const tree = document.getElementById('diff-file-tree');
|
|
|
|
const newTooltip = btn.getAttribute(visible ? 'data-hide-text' : 'data-show-text');
|
|
|
|
btn.setAttribute('data-tooltip-content', newTooltip);
|
|
|
|
toggleElem(tree, visible);
|
|
|
|
toggleElem(toShow, !visible);
|
|
|
|
toggleElem(toHide, visible);
|
2022-09-27 10:52:19 +05:30
|
|
|
},
|
|
|
|
loadMoreData() {
|
2023-05-30 16:23:15 +05:30
|
|
|
loadMoreFiles(this.store.linkLoadMore);
|
2022-12-23 21:33:11 +05:30
|
|
|
},
|
2022-09-27 10:52:19 +05:30
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
2023-09-02 20:29:07 +05:30
|
|
|
<template>
|
2023-10-21 16:08:19 +05:30
|
|
|
<div v-if="store.fileTreeIsVisible" class="diff-file-tree-items">
|
2023-09-02 20:29:07 +05:30
|
|
|
<!-- only render the tree if we're visible. in many cases this is something that doesn't change very often -->
|
|
|
|
<DiffFileTreeItem v-for="item in fileTree" :key="item.name" :item="item"/>
|
Migrate margin and padding helpers to tailwind (#30043)
This will conclude the refactor of 1:1 class replacements to tailwind,
except `gt-hidden`. Commands ran:
```bash
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-0#tw-$1$2-0#g' {web_src/js,templates,routers,services}/**/*
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-1#tw-$1$2-0.5#g' {web_src/js,templates,routers,services}/**/*
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-2#tw-$1$2-1#g' {web_src/js,templates,routers,services}/**/*
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-3#tw-$1$2-2#g' {web_src/js,templates,routers,services}/**/*
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-4#tw-$1$2-4#g' {web_src/js,templates,routers,services}/**/*
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-5#tw-$1$2-8#g' {web_src/js,templates,routers,services}/**/*
```
(cherry picked from commit 68ec9b48592fe88765bcc3a73093d43c98b315de)
Conflicts:
routers/web/repo/view.go
templates/base/head_navbar.tmpl
templates/repo/code/recently_pushed_new_branches.tmpl
templates/repo/diff/box.tmpl
templates/repo/diff/compare.tmpl
templates/repo/diff/conversation.tmpl
templates/repo/header.tmpl
templates/repo/issue/filter_list.tmpl
templates/repo/issue/view_content/conversation.tmpl
templates/repo/issue/view_content/sidebar.tmpl
templates/repo/settings/options.tmpl
templates/repo/view_file.tmpl
templates/shared/user/blocked_users.tmpl
templates/status/500.tmpl
web_src/js/components/DashboardRepoList.vue
resolved by prefering Forgejo version and applying the
commands to all files
2024-03-24 22:12:49 +05:30
|
|
|
<div v-if="store.isIncomplete" class="tw-pt-1">
|
2023-09-02 20:29:07 +05:30
|
|
|
<a :class="['ui', 'basic', 'tiny', 'button', store.isLoadingNewData ? 'disabled' : '']" @click.stop="loadMoreData">{{ store.showMoreMessage }}</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
2023-10-21 16:08:19 +05:30
|
|
|
<style scoped>
|
|
|
|
.diff-file-tree-items {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
gap: 1px;
|
|
|
|
margin-right: .5rem;
|
|
|
|
}
|
|
|
|
</style>
|