@@ -24,7 +24,7 @@ import {
2424 OnInit ,
2525 ViewChild
2626} from '@angular/core' ;
27- import { Subscription } from 'rxjs' ;
27+ import { BehaviorSubject , Subscription } from 'rxjs' ;
2828import { ComicFile } from '@app/comic-files/models/comic-file' ;
2929import { LoggerService } from '@angular-ru/cdk/logger' ;
3030import { Store } from '@ngrx/store' ;
@@ -34,7 +34,9 @@ import { filter } from 'rxjs/operators';
3434import { Title } from '@angular/platform-browser' ;
3535import {
3636 selectComicFileListState ,
37- selectComicFiles
37+ selectComicFiles ,
38+ selectComicFilesCurrentPath ,
39+ selectComicGroups
3840} from '@app/comic-files/selectors/comic-file-list.selectors' ;
3941import { selectImportComicFilesState } from '@app/comic-files/selectors/import-comic-files.selectors' ;
4042import { setBusyState } from '@app/core/actions/busy.actions' ;
@@ -68,7 +70,8 @@ import {
6870import { QueryParameterService } from '@app/core/services/query-parameter.service' ;
6971import {
7072 loadComicFilesFromSession ,
71- toggleComicFileSelections
73+ toggleComicFileSelections ,
74+ updateCurrentPath
7275} from '@app/comic-files/actions/comic-file-list.actions' ;
7376import { Router } from '@angular/router' ;
7477import { selectFeatureEnabledState } from '@app/admin/selectors/feature-enabled.selectors' ;
@@ -86,9 +89,13 @@ import {
8689} from '@angular/material/card' ;
8790import { ComicFileLoaderComponent } from '../../components/comic-file-loader/comic-file-loader.component' ;
8891import { MatCheckbox } from '@angular/material/checkbox' ;
89- import { MatLabel } from '@angular/material/form-field' ;
92+ import { MatFormField , MatLabel } from '@angular/material/form-field' ;
9093import { AsyncPipe , DecimalPipe } from '@angular/common' ;
9194import { ComicFileCoverUrlPipe } from '../../pipes/comic-file-cover-url.pipe' ;
95+ import { MatOption , MatSelect } from '@angular/material/select' ;
96+ import { ComicFileGroup } from '@app/comic-files/models/comic-file-group' ;
97+ import { SelectionOption } from '@app/core/models/ui/selection-option' ;
98+ import { MatInput } from '@angular/material/input' ;
9299
93100@Component ( {
94101 selector : 'cx-import-comics' ,
@@ -125,7 +132,11 @@ import { ComicFileCoverUrlPipe } from '../../pipes/comic-file-cover-url.pipe';
125132 AsyncPipe ,
126133 DecimalPipe ,
127134 TranslateModule ,
128- ComicFileCoverUrlPipe
135+ ComicFileCoverUrlPipe ,
136+ MatSelect ,
137+ MatOption ,
138+ MatFormField ,
139+ MatInput
129140 ]
130141} )
131142export class ImportComicsPageComponent
@@ -146,6 +157,8 @@ export class ImportComicsPageComponent
146157 langChangeSubscription : Subscription ;
147158 filesSubscription$ : Subscription ;
148159 files : ComicFile [ ] ;
160+ groupsSubscription$ : Subscription ;
161+ groups : ComicFileGroup [ ] ;
149162 translateSubscription$ : Subscription ;
150163 userSubscription$ : Subscription ;
151164 user : User ;
@@ -160,6 +173,9 @@ export class ImportComicsPageComponent
160173 comicFile : ComicFile = null ;
161174 featureEnabledSubscription$ : Subscription ;
162175 blockedPagesEnabled = false ;
176+ currentPathSubscription$ : Subscription ;
177+ currentPath : string | null = null ;
178+ pathOptions$ = new BehaviorSubject < SelectionOption < string > [ ] > ( [ ] ) ;
163179
164180 logger = inject ( LoggerService ) ;
165181 title = inject ( Title ) ;
@@ -185,18 +201,33 @@ export class ImportComicsPageComponent
185201 . select ( selectComicFiles )
186202 . subscribe ( files => {
187203 this . files = files ;
188- this . dataSource . data = files ;
189- this . updateSelectionState ( ) ;
204+ this . updateDisplayedFilesAndSelections ( ) ;
190205 this . showFinderForm = false ;
191206 this . selectedFileCount = this . files . filter (
192207 file => file . selected
193208 ) . length ;
194209 } ) ;
210+ this . groupsSubscription$ = this . store
211+ . select ( selectComicGroups )
212+ . subscribe ( groups => {
213+ this . groups = groups ;
214+ this . updateDisplayedFilesAndSelections ( ) ;
215+ } ) ;
195216 this . comicFileListStateSubscription$ = this . store
196217 . select ( selectComicFileListState )
197- . subscribe ( state =>
198- this . store . dispatch ( setBusyState ( { enabled : state . busy } ) )
199- ) ;
218+ . subscribe ( state => {
219+ this . store . dispatch ( setBusyState ( { enabled : state . busy } ) ) ;
220+ this . pathOptions$ . next (
221+ [ { label : 'comic-files.text.all-directories' , value : null } ] . concat (
222+ state . groups . map ( group => {
223+ return {
224+ label : group . directory ,
225+ value : group . directory
226+ } as SelectionOption < string > ;
227+ } )
228+ )
229+ ) ;
230+ } ) ;
200231 this . sendComicFilesStateSubscription$ = this . store
201232 . select ( selectImportComicFilesState )
202233 . subscribe ( state =>
@@ -217,6 +248,12 @@ export class ImportComicsPageComponent
217248 ) ;
218249 }
219250 } ) ;
251+ this . currentPathSubscription$ = this . store
252+ . select ( selectComicFilesCurrentPath )
253+ . subscribe ( path => {
254+ this . currentPath = path ;
255+ this . updateDisplayedFilesAndSelections ( ) ;
256+ } ) ;
220257 }
221258
222259 ngAfterViewInit ( ) : void {
@@ -252,12 +289,16 @@ export class ImportComicsPageComponent
252289 this . userSubscription$ . unsubscribe ( ) ;
253290 this . logger . trace ( 'Unsubscribing from comic file updates' ) ;
254291 this . filesSubscription$ . unsubscribe ( ) ;
292+ this . logger . trace ( 'Unsubscribing from comic group updates' ) ;
293+ this . groupsSubscription$ . unsubscribe ( ) ;
255294 this . logger . trace ( 'Unsubscribing from comic file list state updates' ) ;
256295 this . comicFileListStateSubscription$ . unsubscribe ( ) ;
257296 this . logger . trace ( 'Unsubscribing from send comic file state updates' ) ;
258297 this . sendComicFilesStateSubscription$ . unsubscribe ( ) ;
259298 this . logger . trace ( 'Unsubscribing from feature enabled updates' ) ;
260299 this . featureEnabledSubscription$ . unsubscribe ( ) ;
300+ this . logger . trace ( 'Unsubscribing from current path updates' ) ;
301+ this . currentPathSubscription$ . unsubscribe ( ) ;
261302 }
262303
263304 onStartImport ( ) : void {
@@ -302,14 +343,28 @@ export class ImportComicsPageComponent
302343 }
303344 }
304345
346+ onChangeCurrentPath ( path : string | null ) : void {
347+ this . logger . debug ( 'Changing current path:' , path ) ;
348+ this . store . dispatch ( updateCurrentPath ( { path } ) ) ;
349+ }
350+
305351 private loadTranslations ( ) : void {
306352 this . logger . trace ( 'Loading page title' ) ;
307353 this . titleService . setTitle (
308354 this . translateService . instant ( 'comic-files.tab-title' )
309355 ) ;
310356 }
311357
312- private updateSelectionState ( ) : void {
358+ private updateDisplayedFilesAndSelections ( ) : void {
359+ if ( ! ! this . currentPath ) {
360+ this . logger . info ( 'Showing comic files from group:' , this . currentPath ) ;
361+ this . dataSource . data =
362+ this . groups . find ( group => group . directory === this . currentPath )
363+ ?. files || [ ] ;
364+ } else {
365+ this . logger . info ( 'Showing all comic files' ) ;
366+ this . dataSource . data = this . files ;
367+ }
313368 this . allSelected = this . dataSource . data . every ( entry => entry . selected ) ;
314369 this . anySelected = this . dataSource . data . some ( entry => entry . selected ) ;
315370 }
0 commit comments