diff --git a/src/app/pages/energy-provider/energy-provider.page.html b/src/app/pages/energy-provider/energy-provider.page.html index fdbf420..59ec3c5 100644 --- a/src/app/pages/energy-provider/energy-provider.page.html +++ b/src/app/pages/energy-provider/energy-provider.page.html @@ -1,7 +1,58 @@ -
- - -
+
+ + + + + +
+
+ + + +
+ +
+ + + + + +
+ + + + + + + + + + + + + + @for (provider of energyProviders; track provider.id) { + + + + + + + + + } + + +
IDNameActiveDisabled AtCreated AtUpdated At
{{ provider.id }}{{ provider.name }}{{ provider.active ? 'Yes' : 'No' }}{{ provider.disabledAt }}{{ provider.createdAt }}{{ provider.updatedAt }}
diff --git a/src/app/pages/energy-provider/energy-provider.page.ts b/src/app/pages/energy-provider/energy-provider.page.ts index 9b6b9bb..7a1f514 100644 --- a/src/app/pages/energy-provider/energy-provider.page.ts +++ b/src/app/pages/energy-provider/energy-provider.page.ts @@ -1,12 +1,16 @@ +import {finalize} from 'rxjs'; import {Router} from '@angular/router'; -import { Component, inject } from '@angular/core'; -import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms'; import { + IEnergyProvider, EnergyProviderService, ICreateEnergyProvider, - IDisabledEnergyProvider, IEnableEnergyProvider, IUpdateEnergyProvider + IDisabledEnergyProvider, + IEnableEnergyProvider, + IUpdateEnergyProvider } from '../../services/energy-provider.service'; -import {finalize} from 'rxjs'; +import {booleanAttribute, Component, inject, OnInit} from '@angular/core'; +import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms'; + @Component({ selector: 'app-energy-provider', imports: [ @@ -15,25 +19,49 @@ import {finalize} from 'rxjs'; templateUrl: './energy-provider.page.html', styleUrl: './energy-provider.page.scss' }) -export class EnergyProviderPage { +export class EnergyProviderPage implements OnInit { + energyProviders: IEnergyProvider[] = []; private energyProviderService = inject(EnergyProviderService); private router = inject(Router); loading: boolean = false; - formGroup: FormGroup; + createProviderForm: FormGroup; + disableProviderForm: FormGroup; + enableProviderForm: FormGroup; + updateProviderForm: FormGroup; constructor(private _formBuilder: FormBuilder) { - this.formGroup = this._formBuilder.group({ + this.createProviderForm = this._formBuilder.group({ name: ['', [Validators.required, Validators.minLength(3)]], + active: [], + }) + this.disableProviderForm = this._formBuilder.group({ + providerId: [], + disabledAt: [], + }) + this.enableProviderForm = this._formBuilder.group({ + providerId: [], + }) + this.updateProviderForm = this._formBuilder.group({ + name: ['', [Validators.required, Validators.minLength(3)]], + providerId: [], + }); + } + ngOnInit(): void { + this.energyProviderService.energyProviders$.subscribe(data => { + this.energyProviders = data; }); } - submit(): void { - if (this.formGroup.valid) { - const name = this.formGroup.value.name; + submit(): void { + if (this.createProviderForm.valid) { + const name = this.createProviderForm.value.name; + const active = booleanAttribute(this.createProviderForm.value.active); + console.log(name, active); this.energyProviderService.dataSource?.executeCommandByName( 'createEnergyProvider', { - name + name, + active, }) .pipe(finalize(() => this.loading = false)) .subscribe(() => { @@ -43,46 +71,43 @@ export class EnergyProviderPage { } } disable(): void { - if (this.formGroup.valid) { - const provider_id = this.formGroup.value.provider_id; - const disabled_at = this.formGroup.value.disabled_at + const providerId = this.disableProviderForm.value.providerId; + const disabledAt = new Date(this.disableProviderForm.value.disabledAt).toISOString(); + console.log(providerId, disabledAt); this.energyProviderService.dataSource?.executeCommandByName( 'disableEnergyProvider', { - provider_id, - disabled_at, + providerId, + disabledAt, }) .pipe(finalize(() => this.loading = false)) .subscribe(() => { this.energyProviderService.dataSource?.refresh(); this.router.navigate(['/']); }) - } } enable(): void { - if (this.formGroup.valid) { - const provider_id = this.formGroup.value.provider_id; + const providerId = this.enableProviderForm.value.providerId; this.energyProviderService.dataSource?.executeCommandByName( 'enableEnergyProvider', { - provider_id, + providerId, }) .pipe(finalize(() => this.loading = false)) .subscribe(() => { this.energyProviderService.dataSource?.refresh(); this.router.navigate(['/']); }) - } } update(): void { - if (this.formGroup.valid) { - const provider_id = this.formGroup.value.provider_id; - const name = this.formGroup.value.name; + if (this.updateProviderForm.valid) { + const providerId = this.updateProviderForm.value.providerId; + const name = this.updateProviderForm.value.updateName; this.energyProviderService.dataSource?.executeCommandByName( 'updateEnergyProvider', { - provider_id, + providerId, name }) .pipe(finalize(() => this.loading = false)) diff --git a/src/app/pages/energy-rate-exception/energy-rate-exception.page.html b/src/app/pages/energy-rate-exception/energy-rate-exception.page.html index 48733a0..f625c53 100644 --- a/src/app/pages/energy-rate-exception/energy-rate-exception.page.html +++ b/src/app/pages/energy-rate-exception/energy-rate-exception.page.html @@ -1 +1,60 @@ -

energy-rate-exception works!

+
+ + + + + + + + + + + + +
+
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + @for (rateException of energyRateExceptions; track rateException.id) { + + + + + + + + + } + + +
IDNameReset TypeEnergy ThresholdStarted AtEnded At
{{ rateException.id }}{{ rateException.name }}{{rateException.resetType}}{{rateException.energyThreshold}}{{rateException.startedAt}}{{ rateException.endedAt }}
diff --git a/src/app/pages/energy-rate-exception/energy-rate-exception.page.ts b/src/app/pages/energy-rate-exception/energy-rate-exception.page.ts index d9f7218..bd30629 100644 --- a/src/app/pages/energy-rate-exception/energy-rate-exception.page.ts +++ b/src/app/pages/energy-rate-exception/energy-rate-exception.page.ts @@ -1,11 +1,103 @@ -import { Component } from '@angular/core'; - +import {finalize} from 'rxjs'; +import {Router} from '@angular/router'; +import {NgForOf} from '@angular/common'; +import { + EnergyRateExceptionService, + ICreateEnergyRateException, + IEnergyRateException, IUpdateEnergyRateException +} from '../../services/energy-rate-exception.service' +import {Component, inject, OnInit} from '@angular/core'; +import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms'; +import {EnergyRateExceptionThresholdResetType} from '../../enum/energy-rate-exception-threshold-reset-type'; @Component({ selector: 'app-energy-rate-exception', - imports: [], + imports: [ + NgForOf, + ReactiveFormsModule + ], templateUrl: './energy-rate-exception.page.html', styleUrl: './energy-rate-exception.page.scss' }) -export class EnergyRateExceptionPage { +export class EnergyRateExceptionPage implements OnInit{ + energyRateExceptions: IEnergyRateException[] = []; + resetTypes = Object.values(EnergyRateExceptionThresholdResetType); + private energyRateExceptionService = inject(EnergyRateExceptionService); + private router = inject(Router); + loading: boolean = false; + createRateExceptionForm: FormGroup; + updateRateExceptionForm: FormGroup; + + constructor(private _formBuilder: FormBuilder) { + this.createRateExceptionForm = this._formBuilder.group({ + rateId: [], + name: ['', [Validators.required, Validators.minLength(3)]], + energyThreshold: [], + resetType: [], + startedAt: [], + endedAt: [], + }) + + this.updateRateExceptionForm = this._formBuilder.group({ + energyRateExceptionId: [], + energyThreshold: [], + resetType: [], + startedAt: [], + endedAt: [], + }); + } + ngOnInit(): void { + this.energyRateExceptionService.energyRateExceptions$.subscribe(data => { + this.energyRateExceptions = data; + }); + } + submit(): void { + if (this.createRateExceptionForm.valid) { + const rateId = this.createRateExceptionForm.value.rateId + const name = this.createRateExceptionForm.value.name; + const energyThreshold = this.createRateExceptionForm.value.energyThreshold; + const resetType = this.createRateExceptionForm.value.resetType; + const startedAt = this.createRateExceptionForm.value.startedAt; + const endedAt = this.createRateExceptionForm.value.endedAt; + this.energyRateExceptionService.dataSource?.executeCommandByName( + 'createEnergyRateException', + { + rateId, + name, + energyThreshold, + resetType, + startedAt, + endedAt, + }) + .pipe(finalize(() => this.loading = false)) + .subscribe(() => { + this.energyRateExceptionService.dataSource?.refresh(); + this.router.navigate(['/']); + }) + } + } + + update(): void { + if (this.updateRateExceptionForm.valid) { + const energyRateExceptionId = this.createRateExceptionForm.value.energyRateExceptionId + const energyThreshold = this.createRateExceptionForm.value.energyThreshold; + const resetType = this.createRateExceptionForm.value.resetType; + const startedAt = this.createRateExceptionForm.value.startedAt; + const endedAt = this.createRateExceptionForm.value.endedAt; + this.energyRateExceptionService.dataSource?.executeCommandByName( + 'updateEnergyRateException', + { + energyRateExceptionId, + energyThreshold, + resetType, + startedAt, + endedAt + }) + .pipe(finalize(() => this.loading = false)) + .subscribe(() => { + this.energyRateExceptionService.dataSource?.refresh(); + this.router.navigate(['/']); + }) + } + } } diff --git a/src/app/pages/energy-rate/energy-rate.page.html b/src/app/pages/energy-rate/energy-rate.page.html index 1f3aa25..09e87ab 100644 --- a/src/app/pages/energy-rate/energy-rate.page.html +++ b/src/app/pages/energy-rate/energy-rate.page.html @@ -1 +1,73 @@ -

energy-rate works!

+
+ + + + + + + + + + + +
+
+ + + + + +
+
+ + + +
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + + @for (rate of energyRates; track rate.id) { + + + + + + + + + + + + } + + +
IDNameRateCurrencyActiveDisabled AtCreated AtUpdated At
{{ rate.id }}{{ rate.name }}{{rate.rate}}{{rate.providerId}}{{rate.currency}}{{ rate.active ? 'Yes' : 'No' }}{{ rate.disabledAt }}{{ rate.createdAt }}{{ rate.updatedAt }}
diff --git a/src/app/pages/energy-rate/energy-rate.page.ts b/src/app/pages/energy-rate/energy-rate.page.ts index b4f520c..4689fb4 100644 --- a/src/app/pages/energy-rate/energy-rate.page.ts +++ b/src/app/pages/energy-rate/energy-rate.page.ts @@ -1,11 +1,143 @@ -import { Component } from '@angular/core'; +import {finalize} from 'rxjs'; +import {Router} from '@angular/router'; +import {NgForOf} from '@angular/common'; +import {Currency} from '../../enum/currency'; +import { + IEnergyRate, + EnergyRateService, + ICreateEnergyRate, + IDisabledEnergyRate, + IEnableEnergyRate, + IUpdateEnergyRate, +} from '../../services/energy-rate.service'; +import {booleanAttribute, Component, inject, OnInit} from '@angular/core'; +import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms'; +import {EnergyProviderService, IEnergyProvider} from '../../services/energy-provider.service'; @Component({ selector: 'app-energy-rate', - imports: [], + imports: [ + ReactiveFormsModule, + NgForOf, + ], templateUrl: './energy-rate.page.html', styleUrl: './energy-rate.page.scss' }) -export class EnergyRatePage { +export class EnergyRatePage implements OnInit { + energyRates: IEnergyRate[] = []; + energyProviders: IEnergyProvider[] = []; + currencies = Object.values(Currency); + private energyProviderService = inject(EnergyProviderService); + private energyRateService = inject(EnergyRateService); + private router = inject(Router); + loading: boolean = false; + createRateForm: FormGroup; + disableRateForm: FormGroup; + enableRateForm: FormGroup; + updateRateForm: FormGroup; + constructor(private _formBuilder: FormBuilder) { + this.createRateForm = this._formBuilder.group({ + name: ['', [Validators.required, Validators.minLength(3)]], + providerId: [], + rate: [], + currency: [], + active: [], + }) + this.disableRateForm = this._formBuilder.group({ + rateId: [], + disabledAt: [], + }) + this.enableRateForm = this._formBuilder.group({ + rateId: [], + }) + this.updateRateForm = this._formBuilder.group({ + name: ['', [Validators.required, Validators.minLength(3)]], + rateId: [], + rate: [], + startedAt: [], + }); + } + ngOnInit(): void { + this.energyRateService.energyRates$.subscribe(data => { + this.energyRates = data; + }); + this.energyProviderService.energyProviders$.subscribe(data => { + this.energyProviders = data; + }); + } + submit(): void { + if (this.createRateForm.valid) { + const providerId = this.createRateForm.value.providerId + const name = this.createRateForm.value.name; + const rate = this.createRateForm.value.rate; + const currency = this.createRateForm.value.currency; + const active = booleanAttribute(this.createRateForm.value.active); + console.log(currency); + this.energyRateService.dataSource?.executeCommandByName( + 'createEnergyRate', + { + providerId, + name, + rate, + currency, + active, + }) + .pipe(finalize(() => this.loading = false)) + .subscribe(() => { + this.energyRateService.dataSource?.refresh(); + this.router.navigate(['/']); + }) + } + } + disable(): void { + const rateId = this.disableRateForm.value.rateId; + const disabledAt = new Date(this.disableRateForm.value.disabledAt).toISOString(); + console.log(rateId, disabledAt); + this.energyRateService.dataSource?.executeCommandByName( + 'disableEnergyRate', + { + rateId, + disabledAt, + }) + .pipe(finalize(() => this.loading = false)) + .subscribe(() => { + this.energyRateService.dataSource?.refresh(); + this.router.navigate(['/']); + }) + } + enable(): void { + const rateId = this.enableRateForm.value.rateId; + this.energyRateService.dataSource?.executeCommandByName( + 'enableEnergyRate', + { + rateId, + }) + .pipe(finalize(() => this.loading = false)) + .subscribe(() => { + this.energyRateService.dataSource?.refresh(); + this.router.navigate(['/']); + }) + } + update(): void { + if (this.updateRateForm.valid) { + const rateId = this.updateRateForm.value.rateId; + const startedAt = this.updateRateForm.value.startedAt; + const name = this.updateRateForm.value.updateName; + const rate = this.updateRateForm.value.rate; + this.energyRateService.dataSource?.executeCommandByName( + 'updateEnergyRate', + { + rateId, + startedAt, + name, + rate + }) + .pipe(finalize(() => this.loading = false)) + .subscribe(() => { + this.energyRateService.dataSource?.refresh(); + this.router.navigate(['/']); + }) + } + } } diff --git a/src/app/services/energy-provider.service.ts b/src/app/services/energy-provider.service.ts index 5e7944c..8deb480 100644 --- a/src/app/services/energy-provider.service.ts +++ b/src/app/services/energy-provider.service.ts @@ -1,4 +1,3 @@ -import {Router} from '@angular/router'; import {BehaviorSubject, of} from 'rxjs'; import {SettingService} from './setting.service'; import { inject, Injectable } from '@angular/core'; @@ -11,27 +10,28 @@ export interface IEnergyProvider id: number; name: string; active: boolean; - disabled_at: string; - created_at: string; - updated_at: string; + disabledAt: string; + createdAt: string; + updatedAt: string; } export interface ICreateEnergyProvider { name: string; + active: boolean; } export interface IDisabledEnergyProvider { - provider_id: number; - disabled_at: string; + providerId: number; + disabledAt: string; } export interface IEnableEnergyProvider { - provider_id: number; + providerId: number; } export interface IUpdateEnergyProvider { - provider_id: number; + providerId: number; name: string; } @@ -43,9 +43,8 @@ export class EnergyProviderService { private readonly hdss = inject(HttpDataSourceService); private readonly settingService = inject(SettingService); private readonly oidcSecurityService = inject(OidcSecurityService); - private readonly router = inject(Router); - private energyProviders: IEnergyProvider[] = []; + energyProviders: IEnergyProvider[] = []; dataSource?: IDataSource current$ = new BehaviorSubject(null); @@ -53,7 +52,6 @@ export class EnergyProviderService { constructor() { this.internalDataSource(); - this.oidcSecurityService.isAuthenticated$ .subscribe(result => { if (result.isAuthenticated) { @@ -61,17 +59,17 @@ export class EnergyProviderService { } }); } - dataSourceBuilder() { return this.hdss.builder() .keyResolver(model => model.id) - //.queryUrl(this.settingService.getMainQueryUrl()) + .queryUrl(this.settingService.getMainQueryUrl('energyProvider')) .addCommandByUrl( 'createEnergyProvider', this.settingService.getMainCommandUrl('createEnergyProvider'), ev => { return of({ - name: ev.model.name + name: ev.model.name, + active: ev.model.active }) }) .addCommandByUrl( @@ -79,8 +77,8 @@ export class EnergyProviderService { this.settingService.getMainCommandUrl('disableEnergyProvider'), ev => { return of({ - provider_id: ev.model.id, - disabled_at: ev.model.disabled_at + providerId: ev.model.id, + disabledAt: ev.model.disabledAt }) } ) @@ -89,7 +87,7 @@ export class EnergyProviderService { this.settingService.getMainCommandUrl('enableEnergyProvider'), ev => { return of({ - provider_id: ev.model.id, + providerId: ev.model.id, }) } ) @@ -98,13 +96,15 @@ export class EnergyProviderService { this.settingService.getMainCommandUrl('updateEnergyProvider'), ev => { return of({ - provider_id: ev.model.id, + providerId: ev.model.id, name: ev.model.name }) } ); } - + getEnergyProviders(): IEnergyProvider[] { + return this.energyProviders; + } selectEnergyProvider(id: number) { const energyProvider = this.energyProviders.find(energyProvider => energyProvider.id === id); if (undefined === energyProvider) @@ -131,7 +131,6 @@ export class EnergyProviderService { this.energyProviders = result.data; this.energyProviders$.next(this.energyProviders); - if (updateSelection && this.energyProviders.length > 0) this.selectEnergyProvider(this.energyProviders[0].id) }) diff --git a/src/app/services/energy-rate-exception.service.ts b/src/app/services/energy-rate-exception.service.ts index fb1cacf..bc2a2ba 100644 --- a/src/app/services/energy-rate-exception.service.ts +++ b/src/app/services/energy-rate-exception.service.ts @@ -1,4 +1,3 @@ -import {Router} from '@angular/router'; import {BehaviorSubject, of} from 'rxjs'; import {SettingService} from './setting.service'; import { inject, Injectable } from '@angular/core'; @@ -11,29 +10,29 @@ import {EnergyRateExceptionThresholdResetType} from '../enum/energy-rate-excepti export interface IEnergyRateException { id: number; - rate_id: number; + rateId: number; name: string; energyThreshold: number; resetType: EnergyRateExceptionThresholdResetType; - started_at: string; - ended_at: string; + startedAt: string; + endedAt: string; } export interface ICreateEnergyRateException { - rate_id: number; + rateId: number; name: string; energyThreshold: number; resetType: EnergyRateExceptionThresholdResetType; - started_at: string; - ended_at: string; + startedAt: string; + endedAt: string; } export interface IUpdateEnergyRateException { energyRateExceptionId: number; energyThreshold: number; resetType: EnergyRateExceptionThresholdResetType; - started_at: string; - ended_at: string; + startedAt: string; + endedAt: string; } @Injectable({ providedIn: 'root' @@ -42,8 +41,6 @@ export class EnergyRateExceptionService { private readonly hdss = inject(HttpDataSourceService); private readonly settingService = inject(SettingService); private readonly oidcSecurityService = inject(OidcSecurityService); - private readonly router = inject(Router); - private energyRateExceptions: IEnergyRateException[] = []; dataSource?: IDataSource @@ -71,12 +68,12 @@ export class EnergyRateExceptionService { this.settingService.getMainCommandUrl('createEnergyRateException'), ev => { return of({ - rate_id: ev.model.rate_id, + rateId: ev.model.rateId, name: ev.model.name, energyThreshold: ev.model.energyThreshold, resetType: ev.model.resetType, - started_at: ev.model.started_at, - ended_at: ev.model.ended_at, + started_at: ev.model.startedAt, + ended_at: ev.model.endedAt, }) }) .addCommandByUrl( @@ -87,8 +84,8 @@ export class EnergyRateExceptionService { energyRateExceptionId: ev.model.id, energyThreshold: ev.model.energyThreshold, resetType: ev.model.resetType, - started_at: ev.model.started_at, - ended_at: ev.model.ended_at, + started_at: ev.model.startedAt, + ended_at: ev.model.endedAt, }) }) } diff --git a/src/app/services/energy-rate.service.ts b/src/app/services/energy-rate.service.ts index bbddbd3..82c9372 100644 --- a/src/app/services/energy-rate.service.ts +++ b/src/app/services/energy-rate.service.ts @@ -1,4 +1,3 @@ -import {Router} from '@angular/router'; import {BehaviorSubject, of} from 'rxjs'; import {Currency} from '../enum/currency'; import {SettingService} from './setting.service'; @@ -11,19 +10,19 @@ import {OidcSecurityService} from 'angular-auth-oidc-client'; export interface IEnergyRate { id: number; - provider_id: number; + providerId: number; name: string; rate: number; currency: Currency; active: boolean; - started_at: string; - disabled_at: string; - created_at: string; - updated_at: string; + startedAt: string; + disabledAt: string; + createdAt: string; + updatedAt: string; } export interface ICreateEnergyRate { - provider_id: number; + providerId: number; name: string; rate: number; currency: Currency; @@ -31,18 +30,18 @@ export interface ICreateEnergyRate } export interface IDisabledEnergyRate { - rate_id: number; - disabled_at: string; + rateId: number; + disabledAt: string; } export interface IEnableEnergyRate { - rate_id: number; + rateId: number; } export interface IUpdateEnergyRate { - rate_id: number; - started_at : string; + rateId: number; + startedAt : string; name: string; rate: number; @@ -54,7 +53,6 @@ export class EnergyRateService { private readonly hdss = inject(HttpDataSourceService); private readonly settingService = inject(SettingService); private readonly oidcSecurityService = inject(OidcSecurityService); - private readonly router = inject(Router); private energyRates: IEnergyRate[] = []; @@ -75,13 +73,13 @@ export class EnergyRateService { dataSourceBuilder() { return this.hdss.builder() .keyResolver(model => model.id) - //.queryUrl(this.settingService.getMainQueryUrl()) + .queryUrl(this.settingService.getMainQueryUrl('energyRate')) .addCommandByUrl( 'createEnergyRate', this.settingService.getMainCommandUrl('createEnergyRate'), ev => { return of({ - provider_id: ev.model.provider_id, + providerId: ev.model.providerId, name: ev.model.name, rate: ev.model.rate, currency: ev.model.currency, @@ -93,8 +91,8 @@ export class EnergyRateService { this.settingService.getMainCommandUrl('disableEnergyRate'), ev => { return of({ - rate_id: ev.model.id, - disabled_at: ev.model.disabled_at + rateID: ev.model.id, + disabledAt: ev.model.disabledAt }) } ) @@ -112,11 +110,10 @@ export class EnergyRateService { this.settingService.getMainCommandUrl('updateEnergyRate'), ev => { return of({ - rate_id: ev.model.id, - started_at: ev.model.started_at, + rateId: ev.model.id, + startedAt: ev.model.startedAt, name: ev.model.name, rate: ev.model.rate, - }) } );