Skip to content

Commit

Permalink
Drop NaturalAbstractController in favor of DestroyRef #10746
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerKiKi committed Oct 2, 2024
1 parent 8c0f432 commit aa63a59
Showing 16 changed files with 91 additions and 107 deletions.
5 changes: 3 additions & 2 deletions client/app/admin/accounts/account/account.component.ts
Original file line number Diff line number Diff line change
@@ -25,9 +25,10 @@ import {MatTabsModule} from '@angular/material/tabs';
import {MoneyComponent} from '../../../shared/components/money/money.component';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import Big from 'big.js';
import {startWith, switchMap, takeUntil} from 'rxjs';
import {startWith, switchMap} from 'rxjs';
import {AccountType} from '../../../shared/generated-types';
import {MatTooltip, MatTooltipModule} from '@angular/material/tooltip';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';

@Component({
selector: 'app-account',
@@ -94,7 +95,7 @@ export class AccountComponent extends NaturalAbstractDetail<AccountService, Natu
parent.valueChanges
.pipe(
startWith(parent.value),
takeUntil(this.ngUnsubscribe),
takeUntilDestroyed(this.destroyRef),
switchMap(value => {
this.nextCodeAvailable = null; // Hide invalid code as soon as we can

5 changes: 3 additions & 2 deletions client/app/admin/bookables/bookable/bookable.component.ts
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ import {PermissionsService} from '../../../shared/services/permissions.service';
import {BookableTagService} from '../../bookableTags/services/bookableTag.service';
import {ImageService} from '../services/image.service';
import {accountHierarchicConfiguration} from '../../../shared/hierarchic-selector/AccountHierarchicConfiguration';
import {Observable, of, takeUntil} from 'rxjs';
import {Observable, of} from 'rxjs';
import {map, switchMap} from 'rxjs/operators';
import {
availableColumnsForBookingsWithOwnerOnlyTrainers,
@@ -50,6 +50,7 @@ import {MatTabsModule} from '@angular/material/tabs';
import {MatButtonModule} from '@angular/material/button';
import {CommonModule} from '@angular/common';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';

@Component({
selector: 'app-bookable',
@@ -108,7 +109,7 @@ export class BookableComponent extends NaturalAbstractDetail<BookableService, Na
const bookingType = this.form.controls.bookingType;
const simultaneousBookingMaximum = this.form.controls.simultaneousBookingMaximum;
bookingType.valueChanges
.pipe(takeUntil(this.ngUnsubscribe))
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(value => simultaneousBookingMaximum.setValue(value === BookingType.SelfApproved ? 1 : -1));
}

Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import {
import {CommonModule, DatePipe} from '@angular/common';
import {UsageBookables} from '../../../shared/generated-types';
import {BookingService} from '../../bookings/services/booking.service';
import {switchMap, takeUntil} from 'rxjs/operators';
import {switchMap} from 'rxjs/operators';
import {UserService} from '../../users/services/user.service';
import {ParentComponent} from './parent.component';
import {of} from 'rxjs';
@@ -28,6 +28,7 @@ import {MatSortModule} from '@angular/material/sort';
import {MatTableModule} from '@angular/material/table';
import {MatDialog} from '@angular/material/dialog';
import {MatSnackBar} from '@angular/material/snack-bar';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';

@Component({
selector: 'app-usage-bookables',
@@ -94,7 +95,7 @@ export class UsageBookablesComponent extends ParentComponent<UsageBookableServic

this.futureOwner$
.pipe(
takeUntil(this.ngUnsubscribe),
takeUntilDestroyed(this.destroyRef),
switchMap(futureOwner =>
futureOwner ? this.userService.getPendingApplications(futureOwner) : of({items: []}),
),
23 changes: 9 additions & 14 deletions client/app/admin/configurations/support/support.component.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import {Component, Inject, OnInit, Optional} from '@angular/core';
import {Component, DestroyRef, Inject, inject, OnInit, Optional} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogModule} from '@angular/material/dialog';
import {ActivatedRoute} from '@angular/router';
import {PermissionsService} from '../../../shared/services/permissions.service';
import {ConfigurationService} from '../services/configuration.service';
import {forkJoin} from 'rxjs';
import {
NaturalAbstractController,
NaturalAlertService,
NaturalDialogTriggerProvidedData,
NaturalFixedButtonComponent,
} from '@ecodev/natural';
import {finalize, takeUntil} from 'rxjs/operators';
import {NaturalAlertService, NaturalDialogTriggerProvidedData, NaturalFixedButtonComponent} from '@ecodev/natural';
import {finalize} from 'rxjs/operators';
import {MatButtonModule} from '@angular/material/button';
import {NaturalEditorComponent} from '@ecodev/natural-editor';
import {FormsModule} from '@angular/forms';
import {MatSlideToggleModule} from '@angular/material/slide-toggle';
import {AsyncPipe} from '@angular/common';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';

export type SupportComponentData = {
configurationKey: string;
@@ -38,7 +34,8 @@ export type SupportComponentData = {
AsyncPipe,
],
})
export class SupportComponent extends NaturalAbstractController implements OnInit {
export class SupportComponent implements OnInit {
private readonly destroyRef = inject(DestroyRef);
public text = '';

public readonly = false;
@@ -62,23 +59,21 @@ export class SupportComponent extends NaturalAbstractController implements OnIni
@Optional()
@Inject(MAT_DIALOG_DATA)
public readonly data?: NaturalDialogTriggerProvidedData<SupportComponentData>,
) {
super();
}
) {}

public ngOnInit(): void {
this.readonly = this.route.snapshot.data.readonly || this.data?.data?.readonly;
this.configurationService
.get(this.getConfigKey())
.pipe(takeUntil(this.ngUnsubscribe))
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(value => (this.text = value));

this.activable = this.route.snapshot.data.activable; // ignore modal mode

if (this.activable) {
this.configurationService
.get('announcement-active')
.pipe(takeUntil(this.ngUnsubscribe))
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(value => (this.active = value === '1'));
}
}
Original file line number Diff line number Diff line change
@@ -127,7 +127,7 @@ export class TransactionComponent
this.updateTransactionLines = true;
}

cancellableTimeout(this.ngUnsubscribe).subscribe(() => {
cancellableTimeout(this.destroyRef).subscribe(() => {
const expenseClaim = this.data.expenseClaim;
const duplicatedTransaction = this.data.duplicatedTransaction;

20 changes: 9 additions & 11 deletions client/app/booking/components/scan/scan.component.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import {Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {Component, DestroyRef, ElementRef, inject, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {NaturalAbstractController, NaturalAlertService} from '@ecodev/natural';
import {NaturalAlertService} from '@ecodev/natural';
import {QrService} from '../../../shared/services/qr.service';
import {takeUntil} from 'rxjs/operators';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';

@Component({
selector: 'app-scan',
templateUrl: './scan.component.html',
styleUrl: './scan.component.scss',
standalone: true,
})
export class ScanComponent extends NaturalAbstractController implements OnInit, OnDestroy {
export class ScanComponent implements OnInit, OnDestroy {
private readonly destroyRef = inject(DestroyRef);
@ViewChild('video', {static: true}) private videoRef!: ElementRef<HTMLVideoElement>;

public constructor(
public readonly router: Router,
private readonly route: ActivatedRoute,
private readonly alertService: NaturalAlertService,
private readonly qrService: QrService,
) {
super();
}
) {}

public ngOnInit(): void {
this.qrService.qrCode.pipe(takeUntil(this.ngUnsubscribe)).subscribe({
this.qrService.qrCode.pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
next: code => {
const parsedCode = code.toLowerCase().replace('https://ichtus.club/booking/', '');
this.router.navigate(['..', parsedCode], {relativeTo: this.route});
@@ -37,7 +36,7 @@ export class ScanComponent extends NaturalAbstractController implements OnInit,

this.qrService
.getStream()
.pipe(takeUntil(this.ngUnsubscribe))
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(stream => {
this.videoRef.nativeElement.srcObject = stream;
this.videoRef.nativeElement.setAttribute('playsinline', 'true'); // required to tell iOS safari we don't want fullscreen
@@ -49,8 +48,7 @@ export class ScanComponent extends NaturalAbstractController implements OnInit,
this.qrService.start();
}

public override ngOnDestroy(): void {
super.ngOnDestroy();
public ngOnDestroy(): void {
this.qrService.stop();
}
}
8 changes: 3 additions & 5 deletions client/app/door/door.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Component, OnInit} from '@angular/core';
import {DoorService} from './services/door.service';
import {Literal, NaturalAbstractController, NaturalAlertService} from '@ecodev/natural';
import {Literal, NaturalAlertService} from '@ecodev/natural';
import {UserService} from '../admin/users/services/user.service';
import {ActivatedRoute} from '@angular/router';
import {CurrentUserForProfile} from '../shared/generated-types';
@@ -15,17 +15,15 @@ import {CardComponent} from '../shared/components/card/card.component';
standalone: true,
imports: [CardComponent, MatButtonModule, MatIconModule],
})
export class DoorComponent extends NaturalAbstractController implements OnInit {
export class DoorComponent implements OnInit {
public viewer!: NonNullable<CurrentUserForProfile['viewer']>;

public constructor(
public readonly doorService: DoorService,
private readonly userService: UserService,
private readonly alertService: NaturalAlertService,
private readonly route: ActivatedRoute,
) {
super();
}
) {}

public open(door: Literal): void {
this.doorService.open({door: door.id}).subscribe({
21 changes: 10 additions & 11 deletions client/app/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import {Component, Inject, OnInit} from '@angular/core';
import {Component, DestroyRef, Inject, inject, OnInit} from '@angular/core';
import {UserService} from '../admin/users/services/user.service';
import {
LOCAL_STORAGE,
NaturalAbstractController,
NaturalAvatarComponent,
NaturalIconDirective,
NaturalSidenavContainerComponent,
NaturalSidenavStackService,
NaturalStorage,
NaturalIconDirective,
NaturalAvatarComponent,
} from '@ecodev/natural';
import {filter, switchMap, takeUntil} from 'rxjs/operators';
import {filter, switchMap} from 'rxjs/operators';
import {ActivatedRoute, Router, RouterLink, RouterOutlet} from '@angular/router';
import {ConfigurationService} from '../admin/configurations/services/configuration.service';
import {FormsModule} from '@angular/forms';
import {MatIconModule} from '@angular/material/icon';
import {MatButtonModule} from '@angular/material/button';
import {MatToolbarModule} from '@angular/material/toolbar';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';

@Component({
selector: 'app-home',
@@ -33,7 +33,8 @@ import {MatToolbarModule} from '@angular/material/toolbar';
RouterOutlet,
],
})
export class HomeComponent extends NaturalAbstractController implements OnInit {
export class HomeComponent implements OnInit {
private readonly destroyRef = inject(DestroyRef);
public menu: NaturalSidenavContainerComponent | undefined;

/**
@@ -50,16 +51,14 @@ export class HomeComponent extends NaturalAbstractController implements OnInit {
public readonly route: ActivatedRoute,
private readonly configurationService: ConfigurationService,
private readonly naturalSidenavStackService: NaturalSidenavStackService,
) {
super();
}
) {}

public ngOnInit(): void {
const announcementConfigKey = 'announcement-text';
this.configurationService
.get('announcement-active')
.pipe(
takeUntil(this.ngUnsubscribe),
takeUntilDestroyed(this.destroyRef),
filter(active => !!active),
switchMap(() => {
this.announcementActive = true;
@@ -77,7 +76,7 @@ export class HomeComponent extends NaturalAbstractController implements OnInit {
});

this.naturalSidenavStackService.currentSidenav
.pipe(takeUntil(this.ngUnsubscribe))
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(sidenav => setTimeout(() => (this.menu = sidenav)));
}

12 changes: 5 additions & 7 deletions client/app/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Component, OnDestroy, OnInit} from '@angular/core';
import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, Router, RouterLink} from '@angular/router';
import {MatSnackBar} from '@angular/material/snack-bar';
import {ifValid, NaturalAbstractController, NaturalIconDirective} from '@ecodev/natural';
import {ifValid, NaturalIconDirective} from '@ecodev/natural';
import {UserService} from '../admin/users/services/user.service';
import {finalize} from 'rxjs/operators';
import {FormsModule, ReactiveFormsModule, NonNullableFormBuilder, Validators} from '@angular/forms';
import {FormsModule, NonNullableFormBuilder, ReactiveFormsModule, Validators} from '@angular/forms';
import {MatDividerModule} from '@angular/material/divider';
import {MatIconModule} from '@angular/material/icon';
import {MatButtonModule} from '@angular/material/button';
@@ -28,7 +28,7 @@ import {MatFormFieldModule} from '@angular/material/form-field';
MatDividerModule,
],
})
export class LoginComponent extends NaturalAbstractController implements OnInit, OnDestroy {
export class LoginComponent implements OnInit {
/**
* Stores the received redirect URL until we need to use it (when login is successfull)
*/
@@ -45,9 +45,7 @@ export class LoginComponent extends NaturalAbstractController implements OnInit,
private readonly userService: UserService,
private readonly snackBar: MatSnackBar,
private readonly fb: NonNullableFormBuilder,
) {
super();
}
) {}

public ngOnInit(): void {
this.returnUrl = this.route.snapshot.queryParams.returnUrl || '/';
9 changes: 3 additions & 6 deletions client/app/profile/components/finances/finances.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges} from '@angular/core';
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
import {CurrentUserForProfile, ExpenseClaims, ExpenseClaimType} from '../../../shared/generated-types';
import {UserService} from '../../../admin/users/services/user.service';
import {ExpenseClaimService} from '../../../admin/expenseClaim/services/expenseClaim.service';
import {MatDialog} from '@angular/material/dialog';
import {CreateRefundComponent} from '../create-refund/create-refund.component';
import {ifValid, NaturalAbstractList, NaturalIconDirective, NaturalEnumPipe} from '@ecodev/natural';
import {ifValid, NaturalAbstractList, NaturalEnumPipe, NaturalIconDirective} from '@ecodev/natural';
import {TransactionLineService} from '../../../admin/transactions/services/transactionLine.service';
import {finalize} from 'rxjs/operators';
import {FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms';
@@ -47,10 +47,7 @@ import {CommonModule} from '@angular/common';
NaturalEnumPipe,
],
})
export class FinancesComponent
extends NaturalAbstractList<ExpenseClaimService>
implements OnInit, OnChanges, OnDestroy
{
export class FinancesComponent extends NaturalAbstractList<ExpenseClaimService> implements OnInit, OnChanges {
@Input({required: true}) public viewer!: NonNullable<CurrentUserForProfile['viewer']>;

public override selectedColumns = ['name', 'updateDate', 'status', 'type', 'remarks', 'amount', 'cancel'];
Loading

0 comments on commit aa63a59

Please sign in to comment.