@ -11,10 +11,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' ;
@ -54,27 +56,29 @@ import { CreateOrUpdatePlatformDialogParams } from './create-or-update-platform-
templateUrl : './admin-platform.component.html'
templateUrl : './admin-platform.component.html'
} )
} )
export class GfAdminPlatformComponent implements OnInit {
export class GfAdminPlatformComponent implements OnInit {
@Input ( ) locale = getLocale ( ) ;
public readonly locale = input ( getLocale ( ) ) ;
@ViewChild ( MatSort ) sort : MatSort ;
protected dataSource = new MatTableDataSource < Platform > ( ) ;
protected readonly displayedColumns = [ 'name' , 'url' , 'accounts' , 'actions' ] ;
public dataSource = new MatTableDataSource < Platform > ( ) ;
protected platforms : Platform [ ] ;
public deviceType : string ;
public displayedColumns = [ 'name' , 'url' , 'accounts' , 'actions' ] ;
private readonly deviceType = computed (
public platforms : Platform [ ] ;
( ) = > this . deviceDetectorService . deviceInfo ( ) . deviceType
) ;
public constructor (
private readonly sort = viewChild . required ( MatSort ) ;
private adminService : AdminService ,
private changeDetectorRef : ChangeDetectorRef ,
private readonly adminService = inject ( AdminService ) ;
private dataService : DataService ,
private readonly changeDetectorRef = inject ( ChangeDetectorRef ) ;
private destroyRef : DestroyRef ,
private readonly dataService = inject ( DataService ) ;
private deviceDetectorService : DeviceDetectorService ,
private readonly destroyRef = inject ( DestroyRef ) ;
private dialog : MatDialog ,
private readonly deviceDetectorService = inject ( DeviceDetectorService ) ;
private notificationService : NotificationService ,
private readonly dialog = inject ( MatDialog ) ;
private route : ActivatedRoute ,
private readonly notificationService = inject ( NotificationService ) ;
private router : Router ,
private readonly route = inject ( ActivatedRoute ) ;
private userService : UserService
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 ) = > {
@ -86,7 +90,9 @@ export class GfAdminPlatformComponent implements OnInit {
return id === params [ 'platformId' ] ;
return id === params [ 'platformId' ] ;
} ) ;
} ) ;
this . openUpdatePlatformDialog ( platform ) ;
if ( platform ) {
this . openUpdatePlatformDialog ( platform ) ;
}
} else {
} else {
this . router . navigate ( [ '.' ] , { relativeTo : this.route } ) ;
this . router . navigate ( [ '.' ] , { relativeTo : this.route } ) ;
}
}
@ -97,12 +103,10 @@ export class GfAdminPlatformComponent implements OnInit {
}
}
public ngOnInit() {
public ngOnInit() {
this . deviceType = this . deviceDetectorService . getDeviceInfo ( ) . deviceType ;
this . fetchPlatforms ( ) ;
this . fetchPlatforms ( ) ;
}
}
public onDeletePlatform ( aId : string ) {
protected onDeletePlatform ( aId : string ) {
this . notificationService . confirm ( {
this . notificationService . confirm ( {
confirmFn : ( ) = > {
confirmFn : ( ) = > {
this . deletePlatform ( aId ) ;
this . deletePlatform ( aId ) ;
@ -112,7 +116,7 @@ export class GfAdminPlatformComponent implements OnInit {
} ) ;
} ) ;
}
}
public onUpdatePlatform ( { id } : Platform ) {
protected onUpdatePlatform ( { id } : Platform ) {
this . router . navigate ( [ ] , {
this . router . navigate ( [ ] , {
queryParams : { editPlatformDialog : true , platformId : id }
queryParams : { editPlatformDialog : true , platformId : id }
} ) ;
} ) ;
@ -142,7 +146,7 @@ export class GfAdminPlatformComponent implements OnInit {
this . platforms = platforms ;
this . platforms = platforms ;
this . dataSource = new MatTableDataSource ( platforms ) ;
this . dataSource = new MatTableDataSource ( platforms ) ;
this . dataSource . sort = this . sort ;
this . dataSource . sort = this . sort ( ) ;
this . dataSource . sortingDataAccessor = get ;
this . dataSource . sortingDataAccessor = get ;
this . dataService . updateInfo ( ) ;
this . dataService . updateInfo ( ) ;
@ -156,15 +160,9 @@ export class GfAdminPlatformComponent implements OnInit {
GfCreateOrUpdatePlatformDialogComponent ,
GfCreateOrUpdatePlatformDialogComponent ,
CreateOrUpdatePlatformDialogParams
CreateOrUpdatePlatformDialogParams
> ( GfCreateOrUpdatePlatformDialogComponent , {
> ( GfCreateOrUpdatePlatformDialogComponent , {
data : {
data : { } satisfies CreateOrUpdatePlatformDialogParams ,
platform : {
height : this.deviceType ( ) === 'mobile' ? '98vh' : undefined ,
id : null ,
width : this.deviceType ( ) === 'mobile' ? '100vw' : '50rem'
name : null ,
url : null
}
} ,
height : this.deviceType === 'mobile' ? '98vh' : undefined ,
width : this.deviceType === 'mobile' ? '100vw' : '50rem'
} ) ;
} ) ;
dialogRef
dialogRef
@ -191,15 +189,7 @@ export class GfAdminPlatformComponent implements OnInit {
} ) ;
} ) ;
}
}
private openUpdatePlatformDialog ( {
private openUpdatePlatformDialog ( { id , name , url } : Platform ) {
id ,
name ,
url
} : {
id : string ;
name : string ;
url : string ;
} ) {
const dialogRef = this . dialog . open <
const dialogRef = this . dialog . open <
GfCreateOrUpdatePlatformDialogComponent ,
GfCreateOrUpdatePlatformDialogComponent ,
CreateOrUpdatePlatformDialogParams
CreateOrUpdatePlatformDialogParams
@ -210,9 +200,9 @@ export class GfAdminPlatformComponent implements OnInit {
name ,
name ,
url
url
}
}
} ,
} satisfies CreateOrUpdatePlatformDialogParams ,
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