diff --git a/src/components/schedule/tabs/other/other.component.html b/src/components/schedule/tabs/other/other.component.html index 9c7b0b5..606245e 100644 --- a/src/components/schedule/tabs/other/other.component.html +++ b/src/components/schedule/tabs/other/other.component.html @@ -1,24 +1,24 @@ - +
- -
- - + +

- @if (data.length === 0) { - } @else { diff --git a/src/components/schedule/tabs/other/other.component.ts b/src/components/schedule/tabs/other/other.component.ts index 68ed914..576f070 100644 --- a/src/components/schedule/tabs/other/other.component.ts +++ b/src/components/schedule/tabs/other/other.component.ts @@ -47,17 +47,19 @@ export interface SelectData { export class OtherComponent { private _searchQuery: string = ''; protected filteredData: BehaviorSubject = new BehaviorSubject([]); - protected data: SelectData[] = []; + protected data: SelectData[] | null = null; @Input() idButton!: string; @Input() textButton!: string; @ViewChild('menuTrigger') menuTrigger!: MatMenuTrigger; @ViewChild('chooseCheckbox') chooseCheckbox!: MatCheckbox; - @Input() dataLoaded: boolean | null = false; @Output() retryLoadData: EventEmitter = new EventEmitter(); get selectedIds(): number[] { + if (this.data === null) + return []; + return this.data.filter(x => x.selected).map(x => x.id); } @@ -72,6 +74,9 @@ export class OtherComponent { } private updateCheckBox() { + if (this.data === null) + return; + this.chooseCheckbox.checked = this.data.every(x => x.selected); this.chooseCheckbox.indeterminate = this.data.some(x => x.selected) && !this.chooseCheckbox.checked; } @@ -82,6 +87,9 @@ export class OtherComponent { } protected updateFilteredData(): void { + if (this.data === null) + return; + this.filteredData.next(this.data.filter(x => x.name.toLowerCase().includes(this.searchQuery.toLowerCase()) )); @@ -92,7 +100,7 @@ export class OtherComponent { } protected clearAll(): void { - this.data.forEach(x => x.selected = false); + this.data?.forEach(x => x.selected = false); if (this.searchQuery !== '') { const updatedData = this.filteredData.value.map(x => { @@ -109,7 +117,7 @@ export class OtherComponent { const check: boolean = this.filteredData.value.some(x => !x.selected) && !this.filteredData.value.every(x => x.selected); const updatedData = this.filteredData.value.map(data => { - this.data.find(x => x.id === data.id)!.selected = check; + this.data!.find(x => x.id === data.id)!.selected = check; return {...data, selected: check}; }); @@ -118,7 +126,7 @@ export class OtherComponent { } protected checkboxStateChange(item: number) { - const data = this.data.find(x => x.id === item)!; + const data = this.data!.find(x => x.id === item)!; data.selected = !data.selected; const updatedData = this.filteredData.value; updatedData.find(x => x.id === item)!.selected = data.selected; diff --git a/src/directives/has-role.directive.ts b/src/directives/has-role.directive.ts index ad98942..2080b60 100644 --- a/src/directives/has-role.directive.ts +++ b/src/directives/has-role.directive.ts @@ -20,7 +20,7 @@ export class HasRoleDirective { this.authService .getRole() - .pipe(catchError(error => { + .pipe(catchError(_ => { this.viewContainer.clear(); return of(null); })) diff --git a/src/pages/login/login.component.ts b/src/pages/login/login.component.ts index 0d2fac4..aab3260 100644 --- a/src/pages/login/login.component.ts +++ b/src/pages/login/login.component.ts @@ -40,11 +40,11 @@ export class LoginComponent { protected loginButtonIsDisable: boolean = true; protected errorText: string = ''; - constructor(private formBuilder: FormBuilder, private auth: AuthApiService, private route: Router) { + constructor(private formBuilder: FormBuilder, private auth: AuthApiService, private router: Router) { this.auth.getRole() .subscribe(data => { if (data !== null) - route.navigate(['admin']).then(); + router.navigate(['admin']).then(); }); this.loginForm = this.formBuilder.group({ @@ -89,7 +89,7 @@ export class LoginComponent { .subscribe(_ => { this.loaderActive = false; this.errorText = ''; - this.route.navigate(['admin']).then(); + this.router.navigate(['admin']).then(); }); } }