@@ -124,11 +124,6 @@ import { TableWidgetModel } from './table-widget.model';
124
124
export class TableWidgetRendererComponent
125
125
extends WidgetRenderer < TableWidgetBaseModel , TableDataSource < TableRow > | undefined >
126
126
implements OnInit {
127
- private static readonly DEFAULT_PREFERENCES : TableWidgetPreferences = {
128
- columns : [ ] ,
129
- checkboxes : [ ]
130
- } ;
131
-
132
127
private static readonly DEFAULT_TAB_INDEX : number = 0 ;
133
128
134
129
public viewItems : ToggleItem < string > [ ] = [ ] ;
@@ -228,7 +223,7 @@ export class TableWidgetRendererComponent
228
223
}
229
224
230
225
private getSelectControls ( changed ?: TableSelectControl ) : Observable < TableSelectControl [ ] > {
231
- return this . getPreferences ( ) . pipe (
226
+ return this . getSessionPreferences ( ) . pipe (
232
227
take ( 1 ) ,
233
228
switchMap ( preferences =>
234
229
forkJoinSafeEmpty (
@@ -300,7 +295,7 @@ export class TableWidgetRendererComponent
300
295
}
301
296
302
297
private getColumnConfigs ( ) : Observable < TableColumnConfig [ ] > {
303
- return this . getPreferences ( ) . pipe (
298
+ return this . getLocalPreferences ( ) . pipe (
304
299
switchMap ( preferences =>
305
300
combineLatest ( [ this . getScope ( ) , this . api . change$ . pipe ( mapTo ( true ) , startWith ( true ) ) ] ) . pipe (
306
301
switchMap ( ( [ scope ] ) => this . model . getColumns ( scope ) ) ,
@@ -366,8 +361,8 @@ export class TableWidgetRendererComponent
366
361
367
362
private updateSelectionPreferences ( tableSelectControls : TableSelectControl [ ] ) : void {
368
363
if ( isNonEmptyString ( this . model . getId ( ) ) ) {
369
- this . getPreferences ( ) . subscribe ( preferences =>
370
- this . setPreferences ( {
364
+ this . getSessionPreferences ( ) . subscribe ( preferences =>
365
+ this . setSessionPreferences ( {
371
366
...preferences ,
372
367
selections : tableSelectControls
373
368
} )
@@ -401,8 +396,8 @@ export class TableWidgetRendererComponent
401
396
402
397
private updateCheckboxPreferences ( tableCheckboxControls : TableCheckboxControl [ ] ) : void {
403
398
if ( isNonEmptyString ( this . model . getId ( ) ) ) {
404
- this . getPreferences ( ) . subscribe ( preferences =>
405
- this . setPreferences ( {
399
+ this . getSessionPreferences ( ) . subscribe ( preferences =>
400
+ this . setSessionPreferences ( {
406
401
...preferences ,
407
402
checkboxes : tableCheckboxControls
408
403
} )
@@ -411,7 +406,7 @@ export class TableWidgetRendererComponent
411
406
}
412
407
413
408
private getCheckboxControls ( changed ?: TableCheckboxChange ) : Observable < TableCheckboxControl [ ] > {
414
- return this . getPreferences ( ) . pipe (
409
+ return this . getSessionPreferences ( ) . pipe (
415
410
switchMap ( preferences =>
416
411
forkJoinSafeEmpty (
417
412
this . model
@@ -484,8 +479,8 @@ export class TableWidgetRendererComponent
484
479
485
480
public onColumnsChange ( columns : TableColumnConfig [ ] ) : void {
486
481
if ( isNonEmptyString ( this . model . getId ( ) ) ) {
487
- this . getPreferences ( ) . subscribe ( preferences =>
488
- this . setPreferences ( {
482
+ this . getLocalPreferences ( ) . subscribe ( preferences =>
483
+ this . setLocalPreferences ( {
489
484
...preferences ,
490
485
columns : columns . map ( column => this . dehydratePersistedColumnConfig ( column ) )
491
486
} )
@@ -500,7 +495,7 @@ export class TableWidgetRendererComponent
500
495
public onRowSelection ( selections : StatefulTableRow [ ] ) : void {
501
496
this . selectedRows = selections ;
502
497
/**
503
- * Todo: Stich this with selection handlers
498
+ * Todo: Stitch this with selection handlers
504
499
*/
505
500
}
506
501
@@ -552,27 +547,39 @@ export class TableWidgetRendererComponent
552
547
553
548
private getViewPreferences ( ) : Observable < TableWidgetViewPreferences > {
554
549
return isNonEmptyString ( this . model . viewId )
555
- ? this . preferenceService . get < TableWidgetViewPreferences > ( this . model . viewId , { } , StorageType . Session ) . pipe ( first ( ) )
550
+ ? this . preferenceService . get < TableWidgetViewPreferences > ( this . model . viewId , { } , StorageType . Local ) . pipe ( first ( ) )
556
551
: of ( { } ) ;
557
552
}
558
553
559
554
private setViewPreferences ( preferences : TableWidgetViewPreferences ) : void {
560
555
if ( isNonEmptyString ( this . model . viewId ) ) {
561
- this . preferenceService . set ( this . model . viewId , preferences , StorageType . Session ) ;
556
+ this . preferenceService . set ( this . model . viewId , preferences , StorageType . Local ) ;
557
+ }
558
+ }
559
+
560
+ private getLocalPreferences ( ) : Observable < TableWidgetLocalPreferences > {
561
+ return isNonEmptyString ( this . model . getId ( ) )
562
+ ? this . preferenceService
563
+ . get < TableWidgetLocalPreferences > ( this . model . getId ( ) ! , { } , StorageType . Local )
564
+ . pipe ( first ( ) )
565
+ : of ( { } ) ;
566
+ }
567
+
568
+ private setLocalPreferences ( preferences : TableWidgetLocalPreferences ) : void {
569
+ if ( isNonEmptyString ( this . model . getId ( ) ) ) {
570
+ this . preferenceService . set ( this . model . getId ( ) ! , preferences , StorageType . Local ) ;
562
571
}
563
572
}
564
573
565
- private getPreferences (
566
- defaultPreferences : TableWidgetPreferences = TableWidgetRendererComponent . DEFAULT_PREFERENCES
567
- ) : Observable < TableWidgetPreferences > {
574
+ private getSessionPreferences ( ) : Observable < TableWidgetSessionPreferences > {
568
575
return isNonEmptyString ( this . model . getId ( ) )
569
576
? this . preferenceService
570
- . get < TableWidgetPreferences > ( this . model . getId ( ) ! , defaultPreferences , StorageType . Session )
577
+ . get < TableWidgetSessionPreferences > ( this . model . getId ( ) ! , { } , StorageType . Session )
571
578
. pipe ( first ( ) )
572
- : of ( defaultPreferences ) ;
579
+ : of ( { } ) ;
573
580
}
574
581
575
- private setPreferences ( preferences : TableWidgetPreferences ) : void {
582
+ private setSessionPreferences ( preferences : TableWidgetSessionPreferences ) : void {
576
583
if ( isNonEmptyString ( this . model . getId ( ) ) ) {
577
584
this . preferenceService . set ( this . model . getId ( ) ! , preferences , StorageType . Session ) ;
578
585
}
@@ -607,8 +614,11 @@ interface TableWidgetViewPreferences {
607
614
activeView ?: string ;
608
615
}
609
616
610
- interface TableWidgetPreferences {
617
+ interface TableWidgetLocalPreferences {
611
618
columns ?: PersistedTableColumnConfig [ ] ;
619
+ }
620
+
621
+ interface TableWidgetSessionPreferences {
612
622
checkboxes ?: TableCheckboxControl [ ] ;
613
623
selections ?: TableSelectControl [ ] ;
614
624
}
0 commit comments