@@ -4,13 +4,13 @@ import { TranslatePipe, TranslateService } from '@ngx-translate/core';
44
55import { Button } from 'primeng/button' ;
66import { DynamicDialogConfig , DynamicDialogRef } from 'primeng/dynamicdialog' ;
7+ import { PaginatorState } from 'primeng/paginator' ;
78import { Tooltip } from 'primeng/tooltip' ;
89
9- import { finalize , take , throwError } from 'rxjs' ;
10+ import { finalize , throwError } from 'rxjs' ;
1011import { catchError } from 'rxjs/operators' ;
1112
12- import { NgOptimizedImage } from '@angular/common' ;
13- import { ChangeDetectionStrategy , Component , computed , DestroyRef , inject , signal } from '@angular/core' ;
13+ import { ChangeDetectionStrategy , Component , computed , DestroyRef , effect , inject , signal } from '@angular/core' ;
1414import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
1515
1616import {
@@ -21,13 +21,13 @@ import {
2121 SetCurrentFolder ,
2222 SetMoveFileCurrentFolder ,
2323} from '@osf/features/files/store' ;
24- import { IconComponent , LoadingSpinnerComponent } from '@shared/components' ;
24+ import { CustomPaginatorComponent , IconComponent , LoadingSpinnerComponent } from '@shared/components' ;
2525import { OsfFile } from '@shared/models' ;
2626import { FilesService , ToastService } from '@shared/services' ;
2727
2828@Component ( {
2929 selector : 'osf-move-file-dialog' ,
30- imports : [ Button , LoadingSpinnerComponent , NgOptimizedImage , Tooltip , TranslatePipe , IconComponent ] ,
30+ imports : [ Button , LoadingSpinnerComponent , Tooltip , TranslatePipe , IconComponent , CustomPaginatorComponent ] ,
3131 templateUrl : './move-file-dialog.component.html' ,
3232 styleUrl : './move-file-dialog.component.scss' ,
3333 changeDetection : ChangeDetectionStrategy . OnPush ,
@@ -41,64 +41,83 @@ export class MoveFileDialogComponent {
4141 private readonly translateService = inject ( TranslateService ) ;
4242 private readonly toastService = inject ( ToastService ) ;
4343
44- protected readonly files = select ( FilesSelectors . getMoveFileFiles ) ;
45- protected readonly isLoading = select ( FilesSelectors . isMoveFileFilesLoading ) ;
46- protected readonly currentFolder = select ( FilesSelectors . getMoveFileCurrentFolder ) ;
47- private readonly rootFolders = select ( FilesSelectors . getRootFolders ) ;
48- protected readonly isFilesUpdating = signal ( false ) ;
49- protected readonly isFolderSame = computed ( ( ) => {
44+ readonly files = select ( FilesSelectors . getMoveFileFiles ) ;
45+ readonly filesTotalCount = select ( FilesSelectors . getMoveFileFilesTotalCount ) ;
46+ readonly isLoading = select ( FilesSelectors . isMoveFileFilesLoading ) ;
47+ readonly currentFolder = select ( FilesSelectors . getMoveFileCurrentFolder ) ;
48+ readonly isFilesUpdating = signal ( false ) ;
49+ readonly rootFolders = select ( FilesSelectors . getRootFolders ) ;
50+
51+ readonly isFolderSame = computed ( ( ) => {
5052 return this . currentFolder ( ) ?. id === this . config . data . file . relationships . parentFolderId ;
5153 } ) ;
52- protected readonly provider = select ( FilesSelectors . getProvider ) ;
5354
54- protected readonly dispatch = createDispatchMap ( {
55+ readonly storageName =
56+ this . config . data . storageName || this . translateService . instant ( 'files.dialogs.moveFile.osfStorage' ) ;
57+
58+ readonly provider = select ( FilesSelectors . getProvider ) ;
59+
60+ readonly dispatch = createDispatchMap ( {
5561 getMoveFileFiles : GetMoveFileFiles ,
5662 setMoveFileCurrentFolder : SetMoveFileCurrentFolder ,
5763 setCurrentFolder : SetCurrentFolder ,
5864 getFiles : GetFiles ,
5965 getRootFolderFiles : GetRootFolderFiles ,
6066 } ) ;
6167
68+ foldersStack : OsfFile [ ] = this . config . data . foldersStack ?? [ ] ;
69+ previousFolder : OsfFile | null = null ;
70+
71+ pageNumber = signal ( 1 ) ;
72+
73+ itemsPerPage = 10 ;
74+ first = 0 ;
75+ filesLink = '' ;
76+
6277 constructor ( ) {
63- const filesLink = this . currentFolder ( ) ?. relationships . filesLink ;
78+ this . initPreviousFolder ( ) ;
79+ const filesLink = this . currentFolder ( ) ?. relationships ?. filesLink ;
6480 const rootFolders = this . rootFolders ( ) ;
65- if ( filesLink ) {
66- this . dispatch . getMoveFileFiles ( filesLink ) ;
67- } else if ( rootFolders ) {
68- this . dispatch . getMoveFileFiles ( rootFolders [ 0 ] . relationships . filesLink ) ;
81+ this . filesLink = filesLink ?? rootFolders ?. [ 0 ] . relationships ?. filesLink ?? '' ;
82+ if ( this . filesLink ) {
83+ this . dispatch . getMoveFileFiles ( this . filesLink , this . pageNumber ( ) ) ;
84+ }
85+
86+ effect ( ( ) => {
87+ const page = this . pageNumber ( ) ;
88+ if ( this . filesLink ) {
89+ this . dispatch . getMoveFileFiles ( this . filesLink , page ) ;
90+ }
91+ } ) ;
92+ }
93+
94+ initPreviousFolder ( ) {
95+ const foldersStack = this . foldersStack ;
96+ if ( foldersStack . length === 0 ) {
97+ this . previousFolder = null ;
98+ } else {
99+ this . previousFolder = foldersStack [ foldersStack . length - 1 ] ;
69100 }
70101 }
71102
72103 openFolder ( file : OsfFile ) {
73104 if ( file . kind !== 'folder' ) return ;
74-
105+ const current = this . currentFolder ( ) ;
106+ if ( current ) {
107+ this . previousFolder = current ;
108+ this . foldersStack . push ( current ) ;
109+ }
75110 this . dispatch . getMoveFileFiles ( file . relationships . filesLink ) ;
76111 this . dispatch . setMoveFileCurrentFolder ( file ) ;
77112 }
78113
79114 openParentFolder ( ) {
80- const currentFolder = this . currentFolder ( ) ;
81-
82- if ( ! currentFolder ) return ;
83-
84- this . isFilesUpdating . set ( true ) ;
85- this . filesService
86- . getFolder ( currentFolder . relationships . parentFolderLink )
87- . pipe (
88- take ( 1 ) ,
89- takeUntilDestroyed ( this . destroyRef ) ,
90- finalize ( ( ) => {
91- this . isFilesUpdating . set ( false ) ;
92- } ) ,
93- catchError ( ( error ) => {
94- this . toastService . showError ( error . error . message ) ;
95- return throwError ( ( ) => error ) ;
96- } )
97- )
98- . subscribe ( ( folder ) => {
99- this . dispatch . setMoveFileCurrentFolder ( folder ) ;
100- this . dispatch . getMoveFileFiles ( folder . relationships . filesLink ) ;
101- } ) ;
115+ const previous = this . foldersStack . pop ( ) ?? null ;
116+ this . previousFolder = this . foldersStack . length > 0 ? this . foldersStack [ this . foldersStack . length - 1 ] : null ;
117+ if ( previous ) {
118+ this . dispatch . setMoveFileCurrentFolder ( previous ) ;
119+ this . dispatch . getMoveFileFiles ( previous . relationships . filesLink ) ;
120+ }
102121 }
103122
104123 moveFile ( ) : void {
@@ -148,4 +167,9 @@ export class MoveFileDialogComponent {
148167 }
149168 } ) ;
150169 }
170+
171+ onFilesPageChange ( event : PaginatorState ) : void {
172+ this . pageNumber . set ( event . page ! + 1 ) ;
173+ this . first = event . first ! ;
174+ }
151175}
0 commit comments