Skip to content

Commit

Permalink
Migrate to inject() for most usages #10706
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerKiKi committed Oct 2, 2024
1 parent 1040573 commit 6780d18
Show file tree
Hide file tree
Showing 81 changed files with 496 additions and 486 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Input, OnInit} from '@angular/core';
import {Component, Input, OnInit, inject} from '@angular/core';
import {
AccountingDocumentInput,
ExpenseClaim,
Expand All @@ -21,6 +21,8 @@ import {MatButtonModule} from '@angular/material/button';
imports: [NaturalFileComponent, MatButtonModule, MatIconModule, NaturalIconDirective],
})
export class AccountingDocumentsComponent implements OnInit {
public readonly accountingDocumentService = inject(AccountingDocumentService);

@Input({required: true}) public model!:
| Transaction['transaction']
| ExpenseClaim['expenseClaim']
Expand Down Expand Up @@ -52,8 +54,6 @@ export class AccountingDocumentsComponent implements OnInit {
private readonly removedFiles: WithId<FileModel>[] = [];
private _disabled = false;

public constructor(public readonly accountingDocumentService: AccountingDocumentService) {}

public ngOnInit(): void {
if ('accountingDocuments' in this.model) {
this.files = [...this.model.accountingDocuments];
Expand Down
13 changes: 8 additions & 5 deletions client/app/admin/accounts/account/account.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, OnInit} from '@angular/core';
import {Component, OnInit, inject} from '@angular/core';
import {
NaturalAbstractDetail,
NaturalDetailHeaderComponent,
Expand Down Expand Up @@ -59,15 +59,18 @@ import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
],
})
export class AccountComponent extends NaturalAbstractDetail<AccountService, NaturalSeoResolveData> implements OnInit {
public readonly accountService: AccountService;
public readonly userService = inject(UserService);

public nextCodeAvailable: number | null = null;
public accountHierarchicConfig = groupAccountHierarchicConfiguration;
public readonly AccountType = AccountType;

public constructor(
public readonly accountService: AccountService,
public readonly userService: UserService,
) {
public constructor() {
const accountService = inject(AccountService);

super('account', accountService);
this.accountService = accountService;
}

public override ngOnInit(): void {
Expand Down
22 changes: 13 additions & 9 deletions client/app/admin/accounts/accounts/accounts.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, OnInit} from '@angular/core';
import {Component, OnInit, inject} from '@angular/core';
import {
AvailableColumn,
Button,
Expand Down Expand Up @@ -66,6 +66,12 @@ type AccountingExportDialogResult = {
],
})
export class AccountsComponent extends NaturalAbstractNavigableList<AccountService> implements OnInit {
private readonly accountService: AccountService;
private readonly dialog = inject(MatDialog);
public readonly permissionsService = inject(PermissionsService);
public readonly transactionLineService = inject(TransactionLineService);
public readonly userService = inject(UserService);

public override availableColumns: AvailableColumn[] = [
{id: 'navigation', label: 'Navigation'},
{id: 'code', label: 'Code'},
Expand Down Expand Up @@ -107,15 +113,13 @@ export class AccountsComponent extends NaturalAbstractNavigableList<AccountServi
maxWidth: '60vw',
};

public constructor(
naturalSearchFacetsService: NaturalSearchFacetsService,
private readonly accountService: AccountService,
private readonly dialog: MatDialog,
public readonly permissionsService: PermissionsService,
public readonly transactionLineService: TransactionLineService,
public readonly userService: UserService,
) {
public constructor() {
const naturalSearchFacetsService = inject(NaturalSearchFacetsService);
const accountService = inject(AccountService);

super(accountService);
this.accountService = accountService;

this.naturalSearchFacets = naturalSearchFacetsService.get('accounts');
}

Expand Down
13 changes: 7 additions & 6 deletions client/app/admin/admin/admin.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component} from '@angular/core';
import {Component, inject} from '@angular/core';
import {PermissionsService} from '../../shared/services/permissions.service';
import {ActivatedRoute, NavigationEnd, Router, RouterLinkActive, RouterLink, RouterOutlet} from '@angular/router';
import {UserRole} from '../../shared/generated-types';
Expand Down Expand Up @@ -30,16 +30,17 @@ import {AsyncPipe} from '@angular/common';
],
})
export class AdminComponent {
public readonly permissionsService = inject(PermissionsService);
public readonly route = inject(ActivatedRoute);

public adminUserRouteActive = false;
public adminBookableRouteActive = false;
public adminBookingRouteActive = false;
public UserRole = UserRole;

public constructor(
router: Router,
public readonly permissionsService: PermissionsService,
public readonly route: ActivatedRoute,
) {
public constructor() {
const router = inject(Router);

// Update active route status
router.events.pipe(takeUntilDestroyed()).subscribe(e => {
if (!(e instanceof NavigationEnd)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Input, OnInit} from '@angular/core';
import {Component, Input, OnInit, inject} from '@angular/core';
import {BookableMetadataService} from './bookable-metadata.service';
import {
NaturalAlertService,
Expand Down Expand Up @@ -32,6 +32,9 @@ import {MatTableModule} from '@angular/material/table';
],
})
export class BookableMetadataComponent implements OnInit {
private readonly bookableMetaService = inject(BookableMetadataService);
private readonly alertService = inject(NaturalAlertService);

@Input({required: true}) public bookable!: Bookable['bookable'];
@Input() public edit = false;
public readonly deleting = new Map<BookableMetadatas['bookableMetadatas']['items'][0], true>();
Expand All @@ -40,11 +43,6 @@ export class BookableMetadataComponent implements OnInit {

public columns: string[] = [];

public constructor(
private readonly bookableMetaService: BookableMetadataService,
private readonly alertService: NaturalAlertService,
) {}

public ngOnInit(): void {
if (this.edit) {
this.columns = ['name', 'value', 'delete'];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component} from '@angular/core';
import {Component, inject} from '@angular/core';
import {
NaturalAbstractDetail,
NaturalDetailHeaderComponent,
Expand Down Expand Up @@ -33,7 +33,9 @@ import {MatDividerModule} from '@angular/material/divider';
],
})
export class BookableTagComponent extends NaturalAbstractDetail<BookableTagService, NaturalSeoResolveData> {
public constructor(bookableTagService: BookableTagService) {
public constructor() {
const bookableTagService = inject(BookableTagService);

super('bookableTag', bookableTagService);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, OnInit} from '@angular/core';
import {Component, OnInit, inject} from '@angular/core';
import {
AvailableColumn,
NaturalAbstractList,
Expand Down Expand Up @@ -39,14 +39,15 @@ import {AsyncPipe} from '@angular/common';
],
})
export class BookableTagsComponent extends NaturalAbstractList<BookableTagService> implements OnInit {
public readonly permissionsService = inject(PermissionsService);

public override availableColumns: AvailableColumn[] = [
{id: 'color', label: 'Couleur'},
{id: 'name', label: 'Nom'},
];
public constructor(
bookableTagService: BookableTagService,
public readonly permissionsService: PermissionsService,
) {
public constructor() {
const bookableTagService = inject(BookableTagService);

super(bookableTagService);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {Component, Inject} from '@angular/core';
import {MatDialogRef, MAT_DIALOG_DATA, MatDialogModule} from '@angular/material/dialog';
import {Component, inject} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogModule} from '@angular/material/dialog';
import {MatButton} from '@angular/material/button';
import {FormControl, ReactiveFormsModule, Validators} from '@angular/forms';
import {MatError, MatFormField, MatHint, MatLabel, MatSuffix} from '@angular/material/form-field';
import {MatDatepicker, MatDatepickerInput, MatDatepickerToggle} from '@angular/material/datepicker';
import {MatInput} from '@angular/material/input';
import {ApplicationConfirmData} from '../bookables/parent.component';
import {UsersVariables} from '../../../shared/generated-types';
import {ActivatedRoute} from '@angular/router';
import {UserService} from '../../users/services/user.service';
import {NaturalQueryVariablesManager} from '@ecodev/natural';
import {MatOption, MatSelect} from '@angular/material/select';
Expand Down Expand Up @@ -35,15 +34,15 @@ import {MatOption, MatSelect} from '@angular/material/select';
})
// This dialog is only displayed when the user submits an application for a COURSE
export class ApplicationConfirmComponent {
private readonly userService = inject(UserService);
private readonly futureOwner = inject<ApplicationConfirmData>(MAT_DIALOG_DATA);

public readonly participant = new FormControl<string | null>(null, [Validators.required]);
public familyMembers: string[] = [];

public constructor(
private readonly route: ActivatedRoute,
private readonly userService: UserService,
public dialogRef: MatDialogRef<ApplicationConfirmComponent>,
@Inject(MAT_DIALOG_DATA) private readonly futureOwner: ApplicationConfirmData,
) {
public constructor() {
const futureOwner = this.futureOwner;

if (futureOwner) {
// Populate the select menu with his/her family members
const qvm = new NaturalQueryVariablesManager<UsersVariables>();
Expand Down
17 changes: 9 additions & 8 deletions client/app/admin/bookables/bookable/bookable.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, OnInit} from '@angular/core';
import {Component, OnInit, inject} from '@angular/core';
import {
formatIsoDateTime,
IEnum,
Expand Down Expand Up @@ -84,20 +84,21 @@ import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
],
})
export class BookableComponent extends NaturalAbstractDetail<BookableService, NaturalSeoResolveData> implements OnInit {
public readonly bookableTagService = inject(BookableTagService);
public readonly licenseService = inject(LicenseService);
private readonly imageService = inject(ImageService);
public readonly permissionsService = inject(PermissionsService);

public accountHierarchicConfig = accountHierarchicConfiguration;
public bookingsVariables: BookingsVariables = {};
public viewer!: NonNullable<CurrentUserForProfile['viewer']>;
public readonly availableColumnsForBookingsWithOwnerWithoutTrainers =
availableColumnsForBookingsWithOwnerWithoutTrainers;
public readonly availableColumnsForBookingsWithOwnerOnlyTrainers = availableColumnsForBookingsWithOwnerOnlyTrainers;

public constructor(
bookableService: BookableService,
public readonly bookableTagService: BookableTagService,
public readonly licenseService: LicenseService,
private readonly imageService: ImageService,
public readonly permissionsService: PermissionsService,
) {
public constructor() {
const bookableService = inject(BookableService);

super('bookable', bookableService);
}

Expand Down
19 changes: 10 additions & 9 deletions client/app/admin/bookables/bookables/bookables.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {Component, EventEmitter, OnInit, Output, inject} from '@angular/core';
import {NaturalSearchFacetsService} from '../../../shared/natural-search/natural-search-facets.service';
import {Bookables} from '../../../shared/generated-types';
import {BookableService} from '../services/bookable.service';
Expand Down Expand Up @@ -50,16 +50,17 @@ import {MatSnackBar} from '@angular/material/snack-bar';
],
})
export class BookablesComponent extends ParentComponent<BookableService> implements OnInit {
public readonly permissionsService = inject(PermissionsService);

@Output() public readonly bookableClick = new EventEmitter<Bookables['bookables']['items'][0]>();

public constructor(
bookableService: BookableService,
naturalSearchFacetsService: NaturalSearchFacetsService,
public readonly permissionsService: PermissionsService,
dialog: MatDialog,
snackbar: MatSnackBar,
bookingService: BookingService,
) {
public constructor() {
const bookableService = inject(BookableService);
const naturalSearchFacetsService = inject(NaturalSearchFacetsService);
const dialog = inject(MatDialog);
const snackbar = inject(MatSnackBar);
const bookingService = inject(BookingService);

super(bookableService, dialog, snackbar, bookingService);
this.naturalSearchFacets = naturalSearchFacetsService.get(
this.route.snapshot.data.isEquipment ? 'equipment' : 'bookables',
Expand Down
21 changes: 11 additions & 10 deletions client/app/admin/bookables/bookables/usage-bookables.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {Component, EventEmitter, Input, OnInit, Output, inject} from '@angular/core';
import {NaturalSearchFacetsService} from '../../../shared/natural-search/natural-search-facets.service';
import {PermissionsService} from '../../../shared/services/permissions.service';
import {UsageBookableService} from '../services/usage-bookable.service';
Expand Down Expand Up @@ -55,6 +55,9 @@ import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
],
})
export class UsageBookablesComponent extends ParentComponent<UsageBookableService> implements OnInit {
public readonly permissionsService = inject(PermissionsService);
private readonly userService = inject(UserService);

@Output() public readonly bookableClick = new EventEmitter<UsageBookables['bookables']['items'][0]>();

@Input()
Expand All @@ -68,15 +71,13 @@ export class UsageBookablesComponent extends ParentComponent<UsageBookableServic
public override readonly hasUsage = true;
private searchInitialized = false;

public constructor(
usageBookableService: UsageBookableService,
naturalSearchFacetsService: NaturalSearchFacetsService,
public readonly permissionsService: PermissionsService,
private readonly userService: UserService,
dialog: MatDialog,
snackbar: MatSnackBar,
bookingService: BookingService,
) {
public constructor() {
const usageBookableService = inject(UsageBookableService);
const naturalSearchFacetsService = inject(NaturalSearchFacetsService);
const dialog = inject(MatDialog);
const snackbar = inject(MatSnackBar);
const bookingService = inject(BookingService);

super(usageBookableService, dialog, snackbar, bookingService);

if (this.route.snapshot.data.isAdmin) {
Expand Down
6 changes: 4 additions & 2 deletions client/app/admin/bookables/services/bookable.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Injectable} from '@angular/core';
import {Injectable, inject} from '@angular/core';
import {bookableQuery, bookablesQuery, createBookable, deleteBookables, updateBookable} from './bookable.queries';
import {
Bookable,
Expand Down Expand Up @@ -62,6 +62,8 @@ export class BookableService extends NaturalAbstractModelService<
DeleteBookables,
DeleteBookablesVariables
> {
private readonly bookingService = inject(BookingService);

public static readonly membershipServices: BookablesVariables = {
filter: {
groups: [
Expand Down Expand Up @@ -98,7 +100,7 @@ export class BookableService extends NaturalAbstractModelService<
filter: {groups: [{conditions: [{bookingType: {in: {values: [BookingType.Application]}}}]}]},
};

public constructor(private readonly bookingService: BookingService) {
public constructor() {
super('bookable', bookableQuery, bookablesQuery, createBookable, updateBookable, deleteBookables);
}

Expand Down
6 changes: 4 additions & 2 deletions client/app/admin/bookables/services/usage-bookable.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Injectable} from '@angular/core';
import {Injectable, inject} from '@angular/core';
import {bookableQuery, createBookable, deleteBookables, updateBookable, usageBookablesQuery} from './bookable.queries';
import {
Bookable,
Expand Down Expand Up @@ -33,7 +33,9 @@ export class UsageBookableService extends NaturalAbstractModelService<
DeleteBookables,
DeleteBookablesVariables
> {
public constructor(protected readonly bookingService: BookingService) {
protected readonly bookingService = inject(BookingService);

public constructor() {
super('bookable', bookableQuery, usageBookablesQuery, createBookable, updateBookable, deleteBookables);
}

Expand Down
Loading

0 comments on commit 6780d18

Please sign in to comment.