Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: favor usage of inject() for DI over constructor args where … #354

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"@fortawesome/fontawesome-free": "^6.2.1",
"@ng-select/ng-select": "~11.2.0",
"@ng-web-apis/common": "^3.0.2",
"@ngneat/until-destroy": "~9.0.0",
"bootstrap": "4.6.1",
"lodash": "~4.17.21",
"luxon": "~3.2.1",
Expand Down Expand Up @@ -91,4 +90,4 @@
"*.ts": "eslint --fix",
"*.html": "eslint --fix"
}
}
}
14 changes: 7 additions & 7 deletions src/app/common/breadcrumb/breadcrumb.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NgFor, NgIf } from '@angular/common';
import { Component, Input } from '@angular/core';
import { Component, Input, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { ActivatedRoute, Event, NavigationEnd, Router, RouterLink } from '@angular/router';

Expand All @@ -26,11 +26,11 @@ export class BreadcrumbComponent {

breadcrumbs: Breadcrumb[] = [];

constructor(
private route: ActivatedRoute,
private router: Router
) {
const navEnd$: Observable<Event> = router.events.pipe(
private route = inject(ActivatedRoute);
private router = inject(Router);

constructor() {
const navEnd$: Observable<Event> = this.router.events.pipe(
filter((event) => event instanceof NavigationEnd)
);
merge(navEnd$, this.homeBreadcrumbChanged$)
Expand All @@ -40,7 +40,7 @@ export class BreadcrumbComponent {
this.breadcrumbs = [this._homeBreadcrumb];
this.breadcrumbs = this.breadcrumbs.concat(
BreadcrumbService.getBreadcrumbs(
route.root.snapshot,
this.route.root.snapshot,
this._homeBreadcrumb.url
)
);
Expand Down
1 change: 1 addition & 0 deletions src/app/common/cdk-menu-item-href.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Directive, inject } from '@angular/core';
})
export class CdkMenuItemHrefDirective {
menuItem = inject(CdkMenuItem);

constructor() {
this.menuItem.triggered.subscribe(() => {
this.menuItem._elementRef.nativeElement.click();
Expand Down
1 change: 1 addition & 0 deletions src/app/common/cdk-menu-item-router-link.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { RouterLink } from '@angular/router';
export class CdkMenuItemRouterLinkDirective {
menuItem = inject(CdkMenuItem);
routerLink = inject(RouterLink);

constructor() {
this.menuItem.triggered.subscribe(() => {
this.routerLink.onClick(0, false, false, false, false);
Expand Down
14 changes: 7 additions & 7 deletions src/app/common/directives/link-accessibility.directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Directive, ElementRef, HostListener, Renderer2 } from '@angular/core';
import { Directive, ElementRef, HostListener, Renderer2, inject } from '@angular/core';

/**
* Used to enable link for keyboard accessibility.
Expand All @@ -11,12 +11,12 @@ import { Directive, ElementRef, HostListener, Renderer2 } from '@angular/core';
standalone: true
})
export class LinkAccessibilityDirective {
constructor(
private elRef: ElementRef,
private renderer: Renderer2
) {
const el = elRef.nativeElement;
renderer.setAttribute(el, 'tabIndex', '0');
private elRef = inject(ElementRef);
private renderer = inject(Renderer2);

constructor() {
const el = this.elRef.nativeElement;
this.renderer.setAttribute(el, 'tabIndex', '0');
}

@HostListener('keydown.enter', ['$event'])
Expand Down
3 changes: 2 additions & 1 deletion src/app/common/directives/not-whitespace.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { AbstractControl, NG_VALIDATORS, ValidationErrors, Validator } from '@an
useExisting: forwardRef(() => NotWhitespaceValidator),
multi: true
}
]
],
standalone: true
})
export class NotWhitespaceValidator implements Validator {
constructor(@Attribute('notWhitespace') public notWhitespace: string) {}
Expand Down
16 changes: 8 additions & 8 deletions src/app/common/directives/skip-to.directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Directive, ElementRef, Renderer2 } from '@angular/core';
import { Directive, ElementRef, Renderer2, inject } from '@angular/core';

/**
* Used to mark where in a page the "Skip to main content" link
Expand All @@ -10,12 +10,12 @@ import { Directive, ElementRef, Renderer2 } from '@angular/core';
standalone: true
})
export class SkipToDirective {
constructor(
private elRef: ElementRef,
private renderer: Renderer2
) {
const el = elRef.nativeElement;
renderer.addClass(el, 'skip-to');
renderer.setAttribute(el, 'tabindex', '-1');
private elRef = inject(ElementRef);
private renderer = inject(Renderer2);

constructor() {
const el = this.elRef.nativeElement;
this.renderer.addClass(el, 'skip-to');
this.renderer.setAttribute(el, 'tabindex', '-1');
}
}
12 changes: 10 additions & 2 deletions src/app/common/flyout/flyout.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { NgClass } from '@angular/common';
import { Component, ContentChild, ElementRef, Input, Renderer2, ViewChild } from '@angular/core';
import {
Component,
ContentChild,
ElementRef,
Input,
Renderer2,
ViewChild,
inject
} from '@angular/core';

@Component({
selector: 'app-flyout',
Expand All @@ -20,7 +28,7 @@ export class FlyoutComponent {

isOpen = false;

constructor(private renderer: Renderer2) {}
private renderer = inject(Renderer2);

toggle() {
if (this.content && this.container) {
Expand Down
4 changes: 0 additions & 4 deletions src/app/common/modal/abstract-modal.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ export abstract class AbstractModalDirective {
/* eslint-disable-next-line rxjs/finnish */
onClose: Subject<ModalCloseEvent> = new Subject();

constructor() {
// do nothing
}

ok() {
this.modalRef.hide();
this.onClose.next({ action: ModalAction.OK });
Expand Down
4 changes: 2 additions & 2 deletions src/app/common/modal/modal.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 { BsModalRef, BsModalService, ModalOptions } from 'ngx-bootstrap/modal';
import { Observable } from 'rxjs';
Expand All @@ -15,7 +15,7 @@ import { ContainerModalConfig, ModalAction, ModalCloseEvent, ModalConfig } from
export class ModalService {
private modalRef: BsModalRef | null = null;

constructor(private modalService: BsModalService) {}
private modalService = inject(BsModalService);

alert(
title: string,
Expand Down
4 changes: 0 additions & 4 deletions src/app/common/modal/modal/modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,4 @@ export class ModalComponent {

@Output()
readonly cancel = new EventEmitter<void>();

constructor() {
// do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ export class MultiSelectInputComponent implements ControlValueAccessor {
// do nothing
};

constructor() {
// do nothing
}

onSearch($event: { term: string }) {
this.autocompleteOpen = $event.term.trim().length > 0;
}
Expand Down
4 changes: 0 additions & 4 deletions src/app/common/system-alert/system-alert.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ export class SystemAlertService {
private alerts: SystemAlert[] = [];
alerts$: BehaviorSubject<SystemAlert[]> = new BehaviorSubject(this.alerts);

constructor() {
// do nothing
}

clearAllAlerts() {
this.alerts.length = 0;
this.alerts$.next(this.alerts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ export class ColumnChooserComponent implements OnInit {

private storage = new LocalStorageService();

constructor() {
// do nothing
}

ngOnInit(): void {
this._loadState();
}
Expand Down
4 changes: 0 additions & 4 deletions src/app/common/table/filter/asy-filter.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ export class AsyFilterDirective {
this.filterables.delete(filterable.id);
}

constructor() {
// do nothing
}

filter(id: string, query: any): void {
this.filters.set(id, query);
this.dataSource.filter(this._buildFilter());
Expand Down
4 changes: 0 additions & 4 deletions src/app/common/table/paginator/paginator.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ export class PaginatorComponent<T> implements OnInit {

@Output() readonly pageChange: EventEmitter<PageChange> = new EventEmitter();

constructor() {
// do nothing
}

ngOnInit() {
// Constrain the max page size
this.maxPageSize = this._constrain(this.maxPageSize, 100, 1);
Expand Down
4 changes: 0 additions & 4 deletions src/app/common/table/sort/asy-sort.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ export class AsySortDirective {
this.sortables.delete(sortable.id);
}

constructor() {
// do nothing
}

sort(sortChange: SortChange): void {
this.dataSource.sort(sortChange);
}
Expand Down
8 changes: 3 additions & 5 deletions src/app/core/admin/cache-entries/cache-entries.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';

import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
Expand All @@ -10,10 +10,8 @@ import { CacheEntry } from './cache-entry.model';

@Injectable({ providedIn: 'root' })
export class CacheEntriesService {
constructor(
private http: HttpClient,
private alertService: SystemAlertService
) {}
private http = inject(HttpClient);
private alertService = inject(SystemAlertService);

public match(
query: any,
Expand Down
4 changes: 0 additions & 4 deletions src/app/core/audit/audit-object.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ export class AuditObjectComponent implements OnInit {
@Input() auditObject: any = {};
@Input() auditType = '';

constructor() {
// do nothing
}

ngOnInit() {
if (!AuditObjectTypes.objects.hasOwnProperty(this.auditType)) {
this.auditType = 'default';
Expand Down
8 changes: 3 additions & 5 deletions src/app/core/audit/audit.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';

import { Observable, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
Expand All @@ -11,10 +11,8 @@ import { AuditActionTypes } from './audit.classes';

@Injectable()
export class AuditService {
constructor(
private http: HttpClient,
private alertService: SystemAlertService
) {}
private http = inject(HttpClient);
private alertService = inject(SystemAlertService);

public getDistinctAuditValues(field: string): Observable<string[]> {
return this.http.get<string[]>('api/audit/distinctValues', { params: { field } });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Directive, OnInit } from '@angular/core';
import { Directive, OnInit, inject } from '@angular/core';

import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { PagingOptions } from '../../../common/paging.model';
Expand All @@ -12,10 +11,8 @@ import { AuditService } from '../audit.service';
standalone: true
})
export class AuditActorFilterDirective implements OnInit {
constructor(
private typeaheadFilter: AsyHeaderTypeaheadFilterComponent,
private auditService: AuditService
) {}
private typeaheadFilter = inject(AsyHeaderTypeaheadFilterComponent);
private auditService = inject(AuditService);

ngOnInit() {
this.typeaheadFilter.typeaheadFunc = this.typeaheadSearch.bind(this);
Expand Down
7 changes: 5 additions & 2 deletions src/app/core/auth/abstract.interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';
import { Router } from '@angular/router';

import { Observable, throwError } from 'rxjs';
Expand All @@ -12,7 +12,10 @@ import { catchError } from 'rxjs/operators';
*/
@Injectable()
export abstract class AbstractHttpInterceptor implements HttpInterceptor {
protected constructor(public router: Router) {}
public router = inject(Router);
protected constructor() {
// no-op
}

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req).pipe(
Expand Down
10 changes: 4 additions & 6 deletions src/app/core/auth/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ export function authGuard(configOrRoles?: string | string[] | Partial<AuthGuardC
providedIn: 'root'
})
export class AuthGuard {
constructor(
private router: Router,
private configService: ConfigService,
private sessionService: SessionService,
private authorizationService: AuthorizationService
) {}
private router = inject(Router);
private configService = inject(ConfigService);
private sessionService = inject(SessionService);
private authorizationService = inject(AuthorizationService);

canActivate(
route: ActivatedRouteSnapshot,
Expand Down
Loading
Loading