Adjust components to use inject
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { HttpErrorResponse } from '@angular/common/http';
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit, inject } from '@angular/core';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import { LoaderService } from 'src/app/components/loader/loader.service';
|
import { LoaderService } from 'src/app/components/loader/loader.service';
|
||||||
import {
|
import {
|
||||||
@@ -20,22 +20,20 @@ import { MeterDataAddDialogComponent } from 'src/app/dialogs/meter-data-add-dial
|
|||||||
})
|
})
|
||||||
export class DashboardComponent {
|
export class DashboardComponent {
|
||||||
usageTypes = UsageType;
|
usageTypes = UsageType;
|
||||||
|
|
||||||
preparedMeterData: PreparedMeterData[] = [];
|
preparedMeterData: PreparedMeterData[] = [];
|
||||||
|
|
||||||
meterDataEnergy: PreparedMeterData[] = [];
|
meterDataEnergy: PreparedMeterData[] = [];
|
||||||
meterDataWater: MeterData[] = [];
|
// meterDataWater: MeterData[] = [];
|
||||||
|
|
||||||
displayedColumns: string[] = ['date', 'amount', 'meter'];
|
displayedColumns: string[] = ['date', 'amount', 'meter'];
|
||||||
|
|
||||||
constructor(
|
// injects
|
||||||
private dataBaseService: DatabaseService,
|
private dataBaseService: DatabaseService = inject(DatabaseService);
|
||||||
public meterDataService: MeterDataService,
|
public meterDataService: MeterDataService = inject(MeterDataService);
|
||||||
private loaderService: LoaderService,
|
private loaderService: LoaderService = inject(LoaderService);
|
||||||
private globalService: GlobalService,
|
// private globalService: GlobalService = inject(GlobalService)
|
||||||
private errorService: ErrorService,
|
private errorService: ErrorService = inject(ErrorService);
|
||||||
private dialog: MatDialog
|
private dialog: MatDialog = inject(MatDialog);
|
||||||
) {}
|
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.loadMeterData();
|
this.loadMeterData();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { HttpErrorResponse } from '@angular/common/http';
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit, inject } from '@angular/core';
|
||||||
import { AuthService } from 'src/app/auth/auth.service';
|
import { AuthService } from 'src/app/auth/auth.service';
|
||||||
import { LoginService } from 'src/app/auth/login.service';
|
import { LoginService } from 'src/app/auth/login.service';
|
||||||
import { PageSecurityService } from 'src/app/auth/pageSecurity.service';
|
import { PageSecurityService } from 'src/app/auth/pageSecurity.service';
|
||||||
@@ -15,14 +15,16 @@ import { NotificationService } from 'src/app/core/services/notification.service'
|
|||||||
export class HeaderComponent implements OnInit {
|
export class HeaderComponent implements OnInit {
|
||||||
userLoggedIn: Boolean = false;
|
userLoggedIn: Boolean = false;
|
||||||
|
|
||||||
constructor(
|
//injects
|
||||||
private loginService: LoginService,
|
private loginService: LoginService = inject(LoginService);
|
||||||
private pageSecurityService: PageSecurityService,
|
private pageSecurityService: PageSecurityService =
|
||||||
private errorService: ErrorService,
|
inject(PageSecurityService);
|
||||||
private loaderService: LoaderService,
|
private errorService: ErrorService = inject(ErrorService);
|
||||||
private notificationService: NotificationService,
|
private loaderService: LoaderService = inject(LoaderService);
|
||||||
private authService: AuthService
|
private notificationService: NotificationService =
|
||||||
) {}
|
inject(NotificationService);
|
||||||
|
private authService: AuthService = inject(AuthService);
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.userLoggedIn = this.authService.checkUserLoggedIn();
|
this.userLoggedIn = this.authService.checkUserLoggedIn();
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component, inject } from '@angular/core';
|
||||||
import { LoaderService } from './loader.service';
|
import { LoaderService } from './loader.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-loader',
|
selector: 'app-loader',
|
||||||
templateUrl: './loader.component.html',
|
templateUrl: './loader.component.html',
|
||||||
styleUrls: ['./loader.component.scss']
|
styleUrls: ['./loader.component.scss'],
|
||||||
})
|
})
|
||||||
export class LoaderComponent {
|
export class LoaderComponent {
|
||||||
constructor(public loaderService: LoaderService) {
|
//injects
|
||||||
}
|
public loaderService: LoaderService = inject(LoaderService);
|
||||||
|
constructor() {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit, inject } from '@angular/core';
|
||||||
import { HttpErrorResponse } from '@angular/common/http';
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
@@ -21,14 +21,16 @@ export class LoginComponent implements OnInit {
|
|||||||
userPass: new FormControl('', Validators.required),
|
userPass: new FormControl('', Validators.required),
|
||||||
});
|
});
|
||||||
|
|
||||||
constructor(
|
//injects
|
||||||
private loginService: LoginService,
|
private loginService: LoginService = inject(LoginService);
|
||||||
private formsService: FormsService,
|
private formsService: FormsService = inject(FormsService);
|
||||||
private authService: AuthService,
|
private authService: AuthService = inject(AuthService);
|
||||||
private loaderService: LoaderService,
|
private loaderService: LoaderService = inject(LoaderService);
|
||||||
private notificationService: NotificationService,
|
private notificationService: NotificationService =
|
||||||
private router: Router
|
inject(NotificationService);
|
||||||
) {}
|
private router: Router = inject(Router);
|
||||||
|
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
let userLoggedIn: Boolean = this.authService.checkUserLoggedIn();
|
let userLoggedIn: Boolean = this.authService.checkUserLoggedIn();
|
||||||
|
|||||||
@@ -1,20 +1,7 @@
|
|||||||
import {
|
import { Component, Input } from '@angular/core';
|
||||||
Component,
|
import { MeterDataForYear } from 'src/app/core/dataModels/Meterdata';
|
||||||
ElementRef,
|
|
||||||
Input,
|
|
||||||
SimpleChanges,
|
|
||||||
ViewChild,
|
|
||||||
} from '@angular/core';
|
|
||||||
import {
|
|
||||||
MeterData,
|
|
||||||
MeterDataForYear,
|
|
||||||
PreparedMeterData,
|
|
||||||
} from 'src/app/core/dataModels/Meterdata';
|
|
||||||
import { ChartType, ChartOptions, ChartDataset } from 'chart.js';
|
import { ChartType, ChartOptions, ChartDataset } from 'chart.js';
|
||||||
|
|
||||||
// import Chart from 'chart.js/auto';
|
|
||||||
import { BaseChartDirective } from 'ng2-charts';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-chart',
|
selector: 'app-chart',
|
||||||
templateUrl: './chart.component.html',
|
templateUrl: './chart.component.html',
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
import { Component, Input, OnChanges, OnInit } from '@angular/core';
|
import { Component, Input, OnChanges, OnInit } from '@angular/core';
|
||||||
import { MatTableDataSource } from '@angular/material/table';
|
import { MatTableDataSource } from '@angular/material/table';
|
||||||
import { UsageType } from 'src/app/core/dataModels/UsageType';
|
import { UsageType } from 'src/app/core/dataModels/UsageType';
|
||||||
import {
|
import { MeterData } from 'src/app/core/dataModels/Meterdata';
|
||||||
MeterData,
|
|
||||||
PreparedMeterData,
|
|
||||||
} from 'src/app/core/dataModels/Meterdata';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-meter-data-list',
|
selector: 'app-meter-data-list',
|
||||||
@@ -17,9 +14,6 @@ export class MeterDataListComponent implements OnInit, OnChanges {
|
|||||||
@Input()
|
@Input()
|
||||||
type!: UsageType;
|
type!: UsageType;
|
||||||
amount: number | undefined;
|
amount: number | undefined;
|
||||||
// meterData: PreparedMeterData = new PreparedMeterData();
|
|
||||||
// @Input()
|
|
||||||
// type: UsageType = UsageType.ENERGY;
|
|
||||||
|
|
||||||
displayedColumns: string[] = ['id', 'date', 'amount', 'meter'];
|
displayedColumns: string[] = ['id', 'date', 'amount', 'meter'];
|
||||||
|
|
||||||
@@ -112,11 +106,6 @@ export class MeterDataListComponent implements OnInit, OnChanges {
|
|||||||
ngOnInit(): void {}
|
ngOnInit(): void {}
|
||||||
|
|
||||||
ngOnChanges(): void {
|
ngOnChanges(): void {
|
||||||
this.dataSource = new MatTableDataSource(
|
this.dataSource = new MatTableDataSource(this.meterData);
|
||||||
this.meterData
|
|
||||||
// this.meterData?.meterDataForYear[0].meterData
|
|
||||||
);
|
|
||||||
|
|
||||||
// this.amount = this.meterData?.meterDataForYear[0].amount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit, inject } from '@angular/core';
|
||||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
import { MatDialogRef } from '@angular/material/dialog';
|
import { MatDialogRef } from '@angular/material/dialog';
|
||||||
import { Meter, Meters } from 'src/app/core/dataModels/Meter';
|
import { Meter, Meters } from 'src/app/core/dataModels/Meter';
|
||||||
@@ -16,17 +16,20 @@ export class MeterDataAddDialogComponent implements OnInit {
|
|||||||
usageTypes = UsageType;
|
usageTypes = UsageType;
|
||||||
usageType: UsageType = UsageType.ENERGY;
|
usageType: UsageType = UsageType.ENERGY;
|
||||||
|
|
||||||
|
// injects
|
||||||
|
private fb: FormBuilder = inject(FormBuilder);
|
||||||
|
private dialogRef: MatDialogRef<MeterDataAddDialogComponent> = inject(
|
||||||
|
MatDialogRef<MeterDataAddDialogComponent>
|
||||||
|
);
|
||||||
|
private dataService: DatabaseService = inject(DatabaseService);
|
||||||
|
|
||||||
form: FormGroup = this.fb.group({
|
form: FormGroup = this.fb.group({
|
||||||
date: [new Date(), Validators.required],
|
date: [new Date(), Validators.required],
|
||||||
meter: ['', Validators.required],
|
meter: ['', Validators.required],
|
||||||
amount: ['', Validators.required],
|
amount: ['', Validators.required],
|
||||||
});
|
});
|
||||||
|
|
||||||
constructor(
|
constructor() {}
|
||||||
private fb: FormBuilder,
|
|
||||||
private dialogRef: MatDialogRef<MeterDataAddDialogComponent>,
|
|
||||||
private dataService: DatabaseService
|
|
||||||
) {}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.dataService.getMeters().subscribe({
|
this.dataService.getMeters().subscribe({
|
||||||
|
|||||||
Reference in New Issue
Block a user