@ -10,10 +10,12 @@ import {
ChangeDetectionStrategy ,
ChangeDetectionStrategy ,
ChangeDetectorRef ,
ChangeDetectorRef ,
Component ,
Component ,
computed ,
DestroyRef ,
DestroyRef ,
Input ,
inject ,
input ,
OnInit ,
OnInit ,
V iewChild
v iewChild
} from '@angular/core' ;
} from '@angular/core' ;
import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
import { MatButtonModule } from '@angular/material/button' ;
import { MatButtonModule } from '@angular/material/button' ;
@ -52,26 +54,33 @@ import { CreateOrUpdateTagDialogParams } from './create-or-update-tag-dialog/int
templateUrl : './admin-tag.component.html'
templateUrl : './admin-tag.component.html'
} )
} )
export class GfAdminTagComponent implements OnInit {
export class GfAdminTagComponent implements OnInit {
@Input ( ) locale = getLocale ( ) ;
public readonly locale = input ( getLocale ( ) ) ;
@ViewChild ( MatSort ) sort : MatSort ;
protected dataSource = new MatTableDataSource < Tag > ( ) ;
protected readonly displayedColumns = [
public dataSource = new MatTableDataSource < Tag > ( ) ;
'name' ,
public deviceType : string ;
'userId' ,
public displayedColumns = [ 'name' , 'userId' , 'activities' , 'actions' ] ;
'activities' ,
public tags : Tag [ ] ;
'actions'
] ;
public constructor (
protected tags : Tag [ ] ;
private changeDetectorRef : ChangeDetectorRef ,
private dataService : DataService ,
private readonly deviceType = computed (
private destroyRef : DestroyRef ,
( ) = > this . deviceDetectorService . deviceInfo ( ) . deviceType
private deviceDetectorService : DeviceDetectorService ,
) ;
private dialog : MatDialog ,
private readonly sort = viewChild . required ( MatSort ) ;
private notificationService : NotificationService ,
private route : ActivatedRoute ,
private readonly changeDetectorRef = inject ( ChangeDetectorRef ) ;
private router : Router ,
private readonly dataService = inject ( DataService ) ;
private userService : UserService
private readonly destroyRef = inject ( DestroyRef ) ;
) {
private readonly deviceDetectorService = inject ( DeviceDetectorService ) ;
private readonly dialog = inject ( MatDialog ) ;
private readonly notificationService = inject ( NotificationService ) ;
private readonly route = inject ( ActivatedRoute ) ;
private readonly router = inject ( Router ) ;
private readonly userService = inject ( UserService ) ;
public constructor ( ) {
this . route . queryParams
this . route . queryParams
. pipe ( takeUntilDestroyed ( this . destroyRef ) )
. pipe ( takeUntilDestroyed ( this . destroyRef ) )
. subscribe ( ( params ) = > {
. subscribe ( ( params ) = > {
@ -83,7 +92,9 @@ export class GfAdminTagComponent implements OnInit {
return id === params [ 'tagId' ] ;
return id === params [ 'tagId' ] ;
} ) ;
} ) ;
this . openUpdateTagDialog ( tag ) ;
if ( tag ) {
this . openUpdateTagDialog ( tag ) ;
}
} else {
} else {
this . router . navigate ( [ '.' ] , { relativeTo : this.route } ) ;
this . router . navigate ( [ '.' ] , { relativeTo : this.route } ) ;
}
}
@ -94,12 +105,10 @@ export class GfAdminTagComponent implements OnInit {
}
}
public ngOnInit() {
public ngOnInit() {
this . deviceType = this . deviceDetectorService . getDeviceInfo ( ) . deviceType ;
this . fetchTags ( ) ;
this . fetchTags ( ) ;
}
}
public onDeleteTag ( aId : string ) {
protected onDeleteTag ( aId : string ) {
this . notificationService . confirm ( {
this . notificationService . confirm ( {
confirmFn : ( ) = > {
confirmFn : ( ) = > {
this . deleteTag ( aId ) ;
this . deleteTag ( aId ) ;
@ -109,7 +118,7 @@ export class GfAdminTagComponent implements OnInit {
} ) ;
} ) ;
}
}
public onUpdateTag ( { id } : Tag ) {
protected onUpdateTag ( { id } : Tag ) {
this . router . navigate ( [ ] , {
this . router . navigate ( [ ] , {
queryParams : { editTagDialog : true , tagId : id }
queryParams : { editTagDialog : true , tagId : id }
} ) ;
} ) ;
@ -139,7 +148,7 @@ export class GfAdminTagComponent implements OnInit {
this . tags = tags ;
this . tags = tags ;
this . dataSource = new MatTableDataSource ( this . tags ) ;
this . dataSource = new MatTableDataSource ( this . tags ) ;
this . dataSource . sort = this . sort ;
this . dataSource . sort = this . sort ( ) ;
this . dataSource . sortingDataAccessor = get ;
this . dataSource . sortingDataAccessor = get ;
this . dataService . updateInfo ( ) ;
this . dataService . updateInfo ( ) ;
@ -153,14 +162,9 @@ export class GfAdminTagComponent implements OnInit {
GfCreateOrUpdateTagDialogComponent ,
GfCreateOrUpdateTagDialogComponent ,
CreateOrUpdateTagDialogParams
CreateOrUpdateTagDialogParams
> ( GfCreateOrUpdateTagDialogComponent , {
> ( GfCreateOrUpdateTagDialogComponent , {
data : {
data : { } satisfies CreateOrUpdateTagDialogParams ,
tag : {
height : this.deviceType ( ) === 'mobile' ? '98vh' : undefined ,
id : null ,
width : this.deviceType ( ) === 'mobile' ? '100vw' : '50rem'
name : null
}
} ,
height : this.deviceType === 'mobile' ? '98vh' : undefined ,
width : this.deviceType === 'mobile' ? '100vw' : '50rem'
} ) ;
} ) ;
dialogRef
dialogRef
@ -197,9 +201,9 @@ export class GfAdminTagComponent implements OnInit {
id ,
id ,
name
name
}
}
} ,
} satisfies CreateOrUpdateTagDialogParams ,
height : this.deviceType === 'mobile' ? '98vh' : undefined ,
height : this.deviceType ( ) === 'mobile' ? '98vh' : undefined ,
width : this.deviceType === 'mobile' ? '100vw' : '50rem'
width : this.deviceType ( ) === 'mobile' ? '100vw' : '50rem'
} ) ;
} ) ;
dialogRef
dialogRef