2022-09-27 08:22:19 +03:00
< script >
import DiffFileTreeItem from './DiffFileTreeItem.vue' ;
2023-05-30 13:53:15 +03:00
import { loadMoreFiles } from '../features/repo-diff.js' ;
2023-03-30 15:06:10 +03:00
import { toggleElem } from '../utils/dom.js' ;
2023-05-30 13:53:15 +03:00
import { diffTreeStore } from '../modules/stores.js' ;
2023-04-12 10:06:39 +03:00
import { setFileFolding } from '../features/file-fold.js' ;
2022-09-27 08:22:19 +03:00
const LOCAL _STORAGE _KEY = 'diff_file_tree_visible' ;
export default {
components : { DiffFileTreeItem } ,
data : ( ) => {
2023-05-30 13:53:15 +03:00
return { store : diffTreeStore ( ) } ;
2022-09-27 08:22:19 +03:00
} ,
computed : {
fileTree ( ) {
const result = [ ] ;
2023-05-30 13:53:15 +03:00
for ( const file of this . store . files ) {
2022-09-27 08:22:19 +03:00
// 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 17:06:53 +03:00
isFile ,
2022-09-27 08:22:19 +03:00
} ;
if ( isFile === true ) {
newParent . file = file ;
}
if ( parent ) {
// check if the folder already exists
const existingFolder = parent . children . find (
2024-03-22 17:06:53 +03:00
( x ) => x . name === split ,
2022-09-27 08:22:19 +03:00
) ;
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 17:06:53 +03:00
} ,
2022-09-27 08:22:19 +03:00
} ,
mounted ( ) {
2023-06-02 18:39:01 +03:00
// Default to true if unset
this . store . fileTreeIsVisible = localStorage . getItem ( LOCAL _STORAGE _KEY ) !== 'false' ;
2022-09-27 08:22:19 +03:00
document . querySelector ( '.diff-toggle-file-tree-button' ) . addEventListener ( 'click' , this . toggleVisibility ) ;
2023-04-07 21:27:10 +03:00
this . hashChangeListener = ( ) => {
2023-04-12 03:44:26 +03:00
this . store . selectedItem = window . location . hash ;
2023-04-12 10:06:39 +03:00
this . expandSelectedFile ( ) ;
2023-04-07 21:27:10 +03:00
} ;
2023-04-12 03:44:26 +03:00
this . hashChangeListener ( ) ;
window . addEventListener ( 'hashchange' , this . hashChangeListener ) ;
2022-09-27 08:22:19 +03:00
} ,
unmounted ( ) {
document . querySelector ( '.diff-toggle-file-tree-button' ) . removeEventListener ( 'click' , this . toggleVisibility ) ;
2023-04-07 21:27:10 +03:00
window . removeEventListener ( 'hashchange' , this . hashChangeListener ) ;
2022-09-27 08:22:19 +03:00
} ,
methods : {
2023-04-12 10:06:39 +03:00
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 08:22:19 +03:00
toggleVisibility ( ) {
2023-05-30 13:53:15 +03:00
this . updateVisibility ( ! this . store . fileTreeIsVisible ) ;
2022-09-27 08:22:19 +03:00
} ,
updateVisibility ( visible ) {
2023-05-30 13:53:15 +03:00
this . store . fileTreeIsVisible = visible ;
localStorage . setItem ( LOCAL _STORAGE _KEY , this . store . fileTreeIsVisible ) ;
this . updateState ( this . store . fileTreeIsVisible ) ;
2022-09-27 08:22:19 +03:00
} ,
2023-03-30 15:06:10 +03:00
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 08:22:19 +03:00
} ,
loadMoreData ( ) {
2023-05-30 13:53:15 +03:00
loadMoreFiles ( this . store . linkLoadMore ) ;
2022-12-23 19:03:11 +03:00
} ,
2022-09-27 08:22:19 +03:00
} ,
} ;
< / script >
2023-09-02 17:59:07 +03:00
< template >
2023-10-21 13:38:19 +03:00
< div v-if ="store.fileTreeIsVisible" class="diff-file-tree-items" >
2023-09-02 17:59:07 +03:00
<!-- 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 19:42:49 +03:00
< div v-if ="store.isIncomplete" class="tw-pt-1" >
2023-09-02 17:59:07 +03:00
< a : class = "['ui', 'basic', 'tiny', 'button', store.isLoadingNewData ? 'disabled' : '']" @click.stop ="loadMoreData" > { { store . showMoreMessage } } < / a >
< / div >
< / div >
< / template >
2023-10-21 13:38:19 +03:00
< style scoped >
. diff - file - tree - items {
display : flex ;
flex - direction : column ;
gap : 1 px ;
margin - right : .5 rem ;
}
< / style >