add page and formgroup energy rate energy rate exception
This commit is contained in:
parent
a430df72e4
commit
14c8410ea7
@ -1,7 +1,58 @@
|
|||||||
<form [formGroup]="formGroup" (ngSubmit)="submit()">
|
<form [formGroup]="createProviderForm" (ngSubmit)="submit()">
|
||||||
<label for="name">Provider Name</label>
|
<label>Provider Name</label>
|
||||||
<input id="name" formControlName="name" type="text" />
|
<input formControlName="name" type="text" />
|
||||||
<button type="submit" [disabled]="formGroup.invalid || loading">
|
<label>Active</label>
|
||||||
|
<select formControlName="active">
|
||||||
|
<option>true</option>
|
||||||
|
<option>false</option>
|
||||||
|
</select>
|
||||||
|
<button type="submit" [disabled]="createProviderForm.invalid || loading">
|
||||||
{{ loading ? 'Adding...' : 'Add Provider' }}
|
{{ loading ? 'Adding...' : 'Add Provider' }}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
<form [formGroup]="disableProviderForm" (ngSubmit)="disable()">
|
||||||
|
<label>Provider Id</label>
|
||||||
|
<input formControlName="providerId" type="text" />
|
||||||
|
<label>Disable At</label>
|
||||||
|
<input formControlName="disabledAt" type="datetime-local" />
|
||||||
|
<button type="submit">Disable Provider</button>
|
||||||
|
</form>
|
||||||
|
<form [formGroup]="enableProviderForm" (ngSubmit)="enable()">
|
||||||
|
<label>Provider Id</label>
|
||||||
|
<input formControlName="providerId" type="text" />
|
||||||
|
<button type="submit">Enable Provider</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form [formGroup]="updateProviderForm" (ngSubmit)="update()">
|
||||||
|
<label>Provider Id</label>
|
||||||
|
<input formControlName="providerId" type="text" />
|
||||||
|
<label>Provider Name</label>
|
||||||
|
<input formControlName="name" type="text" />
|
||||||
|
<button type="submit">Update Provider</button>
|
||||||
|
</form>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Active</th>
|
||||||
|
<th>Disabled At</th>
|
||||||
|
<th>Created At</th>
|
||||||
|
<th>Updated At</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
|
||||||
|
@for (provider of energyProviders; track provider.id) {
|
||||||
|
<tr>
|
||||||
|
<td>{{ provider.id }}</td>
|
||||||
|
<td>{{ provider.name }}</td>
|
||||||
|
<td>{{ provider.active ? 'Yes' : 'No' }}</td>
|
||||||
|
<td>{{ provider.disabledAt }}</td>
|
||||||
|
<td>{{ provider.createdAt }}</td>
|
||||||
|
<td>{{ provider.updatedAt }}</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
|
import {finalize} from 'rxjs';
|
||||||
import {Router} from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
import { Component, inject } from '@angular/core';
|
|
||||||
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
|
||||||
import {
|
import {
|
||||||
|
IEnergyProvider,
|
||||||
EnergyProviderService,
|
EnergyProviderService,
|
||||||
ICreateEnergyProvider,
|
ICreateEnergyProvider,
|
||||||
IDisabledEnergyProvider, IEnableEnergyProvider, IUpdateEnergyProvider
|
IDisabledEnergyProvider,
|
||||||
|
IEnableEnergyProvider,
|
||||||
|
IUpdateEnergyProvider
|
||||||
} from '../../services/energy-provider.service';
|
} 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({
|
@Component({
|
||||||
selector: 'app-energy-provider',
|
selector: 'app-energy-provider',
|
||||||
imports: [
|
imports: [
|
||||||
@ -15,25 +19,49 @@ import {finalize} from 'rxjs';
|
|||||||
templateUrl: './energy-provider.page.html',
|
templateUrl: './energy-provider.page.html',
|
||||||
styleUrl: './energy-provider.page.scss'
|
styleUrl: './energy-provider.page.scss'
|
||||||
})
|
})
|
||||||
export class EnergyProviderPage {
|
export class EnergyProviderPage implements OnInit {
|
||||||
|
energyProviders: IEnergyProvider[] = [];
|
||||||
private energyProviderService = inject(EnergyProviderService);
|
private energyProviderService = inject(EnergyProviderService);
|
||||||
private router = inject(Router);
|
private router = inject(Router);
|
||||||
loading: boolean = false;
|
loading: boolean = false;
|
||||||
|
|
||||||
formGroup: FormGroup;
|
createProviderForm: FormGroup;
|
||||||
|
disableProviderForm: FormGroup;
|
||||||
|
enableProviderForm: FormGroup;
|
||||||
|
updateProviderForm: FormGroup;
|
||||||
constructor(private _formBuilder: FormBuilder) {
|
constructor(private _formBuilder: FormBuilder) {
|
||||||
this.formGroup = this._formBuilder.group({
|
this.createProviderForm = this._formBuilder.group({
|
||||||
name: ['', [Validators.required, Validators.minLength(3)]],
|
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<ICreateEnergyProvider, void>(
|
this.energyProviderService.dataSource?.executeCommandByName<ICreateEnergyProvider, void>(
|
||||||
'createEnergyProvider',
|
'createEnergyProvider',
|
||||||
{
|
{
|
||||||
name
|
name,
|
||||||
|
active,
|
||||||
})
|
})
|
||||||
.pipe(finalize(() => this.loading = false))
|
.pipe(finalize(() => this.loading = false))
|
||||||
.subscribe(() => {
|
.subscribe(() => {
|
||||||
@ -43,14 +71,14 @@ export class EnergyProviderPage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
disable(): void {
|
disable(): void {
|
||||||
if (this.formGroup.valid) {
|
const providerId = this.disableProviderForm.value.providerId;
|
||||||
const provider_id = this.formGroup.value.provider_id;
|
const disabledAt = new Date(this.disableProviderForm.value.disabledAt).toISOString();
|
||||||
const disabled_at = this.formGroup.value.disabled_at
|
console.log(providerId, disabledAt);
|
||||||
this.energyProviderService.dataSource?.executeCommandByName<IDisabledEnergyProvider, void>(
|
this.energyProviderService.dataSource?.executeCommandByName<IDisabledEnergyProvider, void>(
|
||||||
'disableEnergyProvider',
|
'disableEnergyProvider',
|
||||||
{
|
{
|
||||||
provider_id,
|
providerId,
|
||||||
disabled_at,
|
disabledAt,
|
||||||
})
|
})
|
||||||
.pipe(finalize(() => this.loading = false))
|
.pipe(finalize(() => this.loading = false))
|
||||||
.subscribe(() => {
|
.subscribe(() => {
|
||||||
@ -58,14 +86,12 @@ export class EnergyProviderPage {
|
|||||||
this.router.navigate(['/']);
|
this.router.navigate(['/']);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
enable(): void {
|
enable(): void {
|
||||||
if (this.formGroup.valid) {
|
const providerId = this.enableProviderForm.value.providerId;
|
||||||
const provider_id = this.formGroup.value.provider_id;
|
|
||||||
this.energyProviderService.dataSource?.executeCommandByName<IEnableEnergyProvider, void>(
|
this.energyProviderService.dataSource?.executeCommandByName<IEnableEnergyProvider, void>(
|
||||||
'enableEnergyProvider',
|
'enableEnergyProvider',
|
||||||
{
|
{
|
||||||
provider_id,
|
providerId,
|
||||||
})
|
})
|
||||||
.pipe(finalize(() => this.loading = false))
|
.pipe(finalize(() => this.loading = false))
|
||||||
.subscribe(() => {
|
.subscribe(() => {
|
||||||
@ -73,16 +99,15 @@ export class EnergyProviderPage {
|
|||||||
this.router.navigate(['/']);
|
this.router.navigate(['/']);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
update(): void {
|
update(): void {
|
||||||
if (this.formGroup.valid) {
|
if (this.updateProviderForm.valid) {
|
||||||
const provider_id = this.formGroup.value.provider_id;
|
const providerId = this.updateProviderForm.value.providerId;
|
||||||
const name = this.formGroup.value.name;
|
const name = this.updateProviderForm.value.updateName;
|
||||||
|
|
||||||
this.energyProviderService.dataSource?.executeCommandByName<IUpdateEnergyProvider, void>(
|
this.energyProviderService.dataSource?.executeCommandByName<IUpdateEnergyProvider, void>(
|
||||||
'updateEnergyProvider',
|
'updateEnergyProvider',
|
||||||
{
|
{
|
||||||
provider_id,
|
providerId,
|
||||||
name
|
name
|
||||||
})
|
})
|
||||||
.pipe(finalize(() => this.loading = false))
|
.pipe(finalize(() => this.loading = false))
|
||||||
|
@ -1 +1,60 @@
|
|||||||
<p>energy-rate-exception works!</p>
|
<form [formGroup]="createRateExceptionForm" (ngSubmit)="submit()">
|
||||||
|
<label>Rate Id</label>
|
||||||
|
<input formControlName="rateId"/>
|
||||||
|
<label>Energy Rate Exception Name</label>
|
||||||
|
<input formControlName="name" type="text" />
|
||||||
|
<label>Energy Threshold</label>
|
||||||
|
<input formControlName="energyThreshold" type="number" />
|
||||||
|
<select formControlName="resetType">
|
||||||
|
<option *ngFor="let resetType of resetTypes" [value]="resetType">{{ resetType }}</option>
|
||||||
|
</select>
|
||||||
|
<label>Started At</label>
|
||||||
|
<input formControlName="startedAt" type="datetime-local" />
|
||||||
|
<label>Ended At</label>
|
||||||
|
<input formControlName="endedAt" type="datetime-local" />
|
||||||
|
<button type="submit" [disabled]="createRateExceptionForm.invalid || loading">
|
||||||
|
{{ loading ? 'Adding...' : 'Add Energy Rate' }}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<form [formGroup]="updateRateExceptionForm" (ngSubmit)="update()">
|
||||||
|
<label>Energy Rate Exception Id</label>
|
||||||
|
<input formControlName="energyRateExceptionId" type="text" />
|
||||||
|
|
||||||
|
<label>Energy Threshold</label>
|
||||||
|
<input formControlName="energyThreshold" type="number" />
|
||||||
|
|
||||||
|
<select formControlName="resetType">
|
||||||
|
<option *ngFor="let resetType of resetTypes" [value]="resetType">{{ resetType }}</option>
|
||||||
|
</select>
|
||||||
|
<label>Started At</label>
|
||||||
|
<input formControlName="startedAt" type="datetime-local" />
|
||||||
|
<label>Ended At</label>
|
||||||
|
<input formControlName="endedAt" type="datetime-local" />
|
||||||
|
<button type="submit">Update Rate</button>
|
||||||
|
</form>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Reset Type</th>
|
||||||
|
<th>Energy Threshold</th>
|
||||||
|
<th>Started At</th>
|
||||||
|
<th>Ended At</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
|
||||||
|
@for (rateException of energyRateExceptions; track rateException.id) {
|
||||||
|
<tr>
|
||||||
|
<td>{{ rateException.id }}</td>
|
||||||
|
<td>{{ rateException.name }}</td>
|
||||||
|
<td>{{rateException.resetType}}</td>
|
||||||
|
<td>{{rateException.energyThreshold}}</td>
|
||||||
|
<td>{{rateException.startedAt}}</td>
|
||||||
|
<td>{{ rateException.endedAt }}</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
@ -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({
|
@Component({
|
||||||
selector: 'app-energy-rate-exception',
|
selector: 'app-energy-rate-exception',
|
||||||
imports: [],
|
imports: [
|
||||||
|
NgForOf,
|
||||||
|
ReactiveFormsModule
|
||||||
|
],
|
||||||
templateUrl: './energy-rate-exception.page.html',
|
templateUrl: './energy-rate-exception.page.html',
|
||||||
styleUrl: './energy-rate-exception.page.scss'
|
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<ICreateEnergyRateException, void>(
|
||||||
|
'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<IUpdateEnergyRateException, void>(
|
||||||
|
'updateEnergyRateException',
|
||||||
|
{
|
||||||
|
energyRateExceptionId,
|
||||||
|
energyThreshold,
|
||||||
|
resetType,
|
||||||
|
startedAt,
|
||||||
|
endedAt
|
||||||
|
})
|
||||||
|
.pipe(finalize(() => this.loading = false))
|
||||||
|
.subscribe(() => {
|
||||||
|
this.energyRateExceptionService.dataSource?.refresh();
|
||||||
|
this.router.navigate(['/']);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1,73 @@
|
|||||||
<p>energy-rate works!</p>
|
<form [formGroup]="createRateForm" (ngSubmit)="submit()">
|
||||||
|
<label>Provider Id</label>
|
||||||
|
<input formControlName="providerId"/>
|
||||||
|
<label>Energy Rate Name</label>
|
||||||
|
<input formControlName="name" type="text" />
|
||||||
|
<label>Rate</label>
|
||||||
|
<input formControlName="rate" type="number" />
|
||||||
|
<select formControlName="currency">
|
||||||
|
<option *ngFor="let currency of currencies" [value]="currency">{{ currency }}</option>
|
||||||
|
</select>
|
||||||
|
<label>Active</label>
|
||||||
|
<select formControlName="active">
|
||||||
|
<option>true</option>
|
||||||
|
<option>false</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<button type="submit" [disabled]="createRateForm.invalid || loading">
|
||||||
|
{{ loading ? 'Adding...' : 'Add Energy Rate' }}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<form [formGroup]="disableRateForm" (ngSubmit)="disable()">
|
||||||
|
<label>Energy Rate Id</label>
|
||||||
|
<input formControlName="rateId" type="text" />
|
||||||
|
<label>Disable At</label>
|
||||||
|
<input formControlName="disabledAt" type="datetime-local" />
|
||||||
|
<button type="submit">Disable Rate</button>
|
||||||
|
</form>
|
||||||
|
<form [formGroup]="enableRateForm" (ngSubmit)="enable()">
|
||||||
|
<label>Energy Rate Id</label>
|
||||||
|
<input formControlName="rateId" type="text" />
|
||||||
|
<button type="submit">Enable Rate</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form [formGroup]="updateRateForm" (ngSubmit)="update()">
|
||||||
|
<label>Energy Rate Id</label>
|
||||||
|
<input formControlName="rateId" type="text" />
|
||||||
|
<label>Energy Rate Name</label>
|
||||||
|
<input formControlName="name" type="text" />
|
||||||
|
<label>Energy Rate Price</label>
|
||||||
|
<input formControlName="rate" type="number" />
|
||||||
|
<button type="submit">Update Rate</button>
|
||||||
|
</form>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Rate</th>
|
||||||
|
<th>Currency</th>
|
||||||
|
<th>Active</th>
|
||||||
|
<th>Disabled At</th>
|
||||||
|
<th>Created At</th>
|
||||||
|
<th>Updated At</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
|
||||||
|
@for (rate of energyRates; track rate.id) {
|
||||||
|
<tr>
|
||||||
|
<td>{{ rate.id }}</td>
|
||||||
|
<td>{{ rate.name }}</td>
|
||||||
|
<td>{{rate.rate}}</td>
|
||||||
|
<td>{{rate.providerId}}</td>
|
||||||
|
<td>{{rate.currency}}</td>
|
||||||
|
<td>{{ rate.active ? 'Yes' : 'No' }}</td>
|
||||||
|
<td>{{ rate.disabledAt }}</td>
|
||||||
|
<td>{{ rate.createdAt }}</td>
|
||||||
|
<td>{{ rate.updatedAt }}</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
@ -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({
|
@Component({
|
||||||
selector: 'app-energy-rate',
|
selector: 'app-energy-rate',
|
||||||
imports: [],
|
imports: [
|
||||||
|
ReactiveFormsModule,
|
||||||
|
NgForOf,
|
||||||
|
],
|
||||||
templateUrl: './energy-rate.page.html',
|
templateUrl: './energy-rate.page.html',
|
||||||
styleUrl: './energy-rate.page.scss'
|
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<ICreateEnergyRate, void>(
|
||||||
|
'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<IDisabledEnergyRate, void>(
|
||||||
|
'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<IEnableEnergyRate, void>(
|
||||||
|
'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<IUpdateEnergyRate, void>(
|
||||||
|
'updateEnergyRate',
|
||||||
|
{
|
||||||
|
rateId,
|
||||||
|
startedAt,
|
||||||
|
name,
|
||||||
|
rate
|
||||||
|
})
|
||||||
|
.pipe(finalize(() => this.loading = false))
|
||||||
|
.subscribe(() => {
|
||||||
|
this.energyRateService.dataSource?.refresh();
|
||||||
|
this.router.navigate(['/']);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import {Router} from '@angular/router';
|
|
||||||
import {BehaviorSubject, of} from 'rxjs';
|
import {BehaviorSubject, of} from 'rxjs';
|
||||||
import {SettingService} from './setting.service';
|
import {SettingService} from './setting.service';
|
||||||
import { inject, Injectable } from '@angular/core';
|
import { inject, Injectable } from '@angular/core';
|
||||||
@ -11,27 +10,28 @@ export interface IEnergyProvider
|
|||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
disabled_at: string;
|
disabledAt: string;
|
||||||
created_at: string;
|
createdAt: string;
|
||||||
updated_at: string;
|
updatedAt: string;
|
||||||
}
|
}
|
||||||
export interface ICreateEnergyProvider
|
export interface ICreateEnergyProvider
|
||||||
{
|
{
|
||||||
name: string;
|
name: string;
|
||||||
|
active: boolean;
|
||||||
}
|
}
|
||||||
export interface IDisabledEnergyProvider
|
export interface IDisabledEnergyProvider
|
||||||
{
|
{
|
||||||
provider_id: number;
|
providerId: number;
|
||||||
disabled_at: string;
|
disabledAt: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
export interface IEnableEnergyProvider
|
export interface IEnableEnergyProvider
|
||||||
{
|
{
|
||||||
provider_id: number;
|
providerId: number;
|
||||||
}
|
}
|
||||||
export interface IUpdateEnergyProvider
|
export interface IUpdateEnergyProvider
|
||||||
{
|
{
|
||||||
provider_id: number;
|
providerId: number;
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,9 +43,8 @@ export class EnergyProviderService {
|
|||||||
private readonly hdss = inject(HttpDataSourceService);
|
private readonly hdss = inject(HttpDataSourceService);
|
||||||
private readonly settingService = inject(SettingService);
|
private readonly settingService = inject(SettingService);
|
||||||
private readonly oidcSecurityService = inject(OidcSecurityService);
|
private readonly oidcSecurityService = inject(OidcSecurityService);
|
||||||
private readonly router = inject(Router);
|
|
||||||
|
|
||||||
private energyProviders: IEnergyProvider[] = [];
|
energyProviders: IEnergyProvider[] = [];
|
||||||
dataSource?: IDataSource<IQueryCriteria, IEnergyProvider>
|
dataSource?: IDataSource<IQueryCriteria, IEnergyProvider>
|
||||||
|
|
||||||
current$ = new BehaviorSubject<IEnergyProvider | null>(null);
|
current$ = new BehaviorSubject<IEnergyProvider | null>(null);
|
||||||
@ -53,7 +52,6 @@ export class EnergyProviderService {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.internalDataSource();
|
this.internalDataSource();
|
||||||
|
|
||||||
this.oidcSecurityService.isAuthenticated$
|
this.oidcSecurityService.isAuthenticated$
|
||||||
.subscribe(result => {
|
.subscribe(result => {
|
||||||
if (result.isAuthenticated) {
|
if (result.isAuthenticated) {
|
||||||
@ -61,17 +59,17 @@ export class EnergyProviderService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
dataSourceBuilder() {
|
dataSourceBuilder() {
|
||||||
return this.hdss.builder<IQueryCriteria, IEnergyProvider>()
|
return this.hdss.builder<IQueryCriteria, IEnergyProvider>()
|
||||||
.keyResolver(model => model.id)
|
.keyResolver(model => model.id)
|
||||||
//.queryUrl(this.settingService.getMainQueryUrl())
|
.queryUrl(this.settingService.getMainQueryUrl('energyProvider'))
|
||||||
.addCommandByUrl<ICreateEnergyProvider, void>(
|
.addCommandByUrl<ICreateEnergyProvider, void>(
|
||||||
'createEnergyProvider',
|
'createEnergyProvider',
|
||||||
this.settingService.getMainCommandUrl('createEnergyProvider'),
|
this.settingService.getMainCommandUrl('createEnergyProvider'),
|
||||||
ev => {
|
ev => {
|
||||||
return of({
|
return of({
|
||||||
name: ev.model.name
|
name: ev.model.name,
|
||||||
|
active: ev.model.active
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.addCommandByUrl<IDisabledEnergyProvider, void>(
|
.addCommandByUrl<IDisabledEnergyProvider, void>(
|
||||||
@ -79,8 +77,8 @@ export class EnergyProviderService {
|
|||||||
this.settingService.getMainCommandUrl('disableEnergyProvider'),
|
this.settingService.getMainCommandUrl('disableEnergyProvider'),
|
||||||
ev => {
|
ev => {
|
||||||
return of({
|
return of({
|
||||||
provider_id: ev.model.id,
|
providerId: ev.model.id,
|
||||||
disabled_at: ev.model.disabled_at
|
disabledAt: ev.model.disabledAt
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -89,7 +87,7 @@ export class EnergyProviderService {
|
|||||||
this.settingService.getMainCommandUrl('enableEnergyProvider'),
|
this.settingService.getMainCommandUrl('enableEnergyProvider'),
|
||||||
ev => {
|
ev => {
|
||||||
return of({
|
return of({
|
||||||
provider_id: ev.model.id,
|
providerId: ev.model.id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -98,13 +96,15 @@ export class EnergyProviderService {
|
|||||||
this.settingService.getMainCommandUrl('updateEnergyProvider'),
|
this.settingService.getMainCommandUrl('updateEnergyProvider'),
|
||||||
ev => {
|
ev => {
|
||||||
return of({
|
return of({
|
||||||
provider_id: ev.model.id,
|
providerId: ev.model.id,
|
||||||
name: ev.model.name
|
name: ev.model.name
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
getEnergyProviders(): IEnergyProvider[] {
|
||||||
|
return this.energyProviders;
|
||||||
|
}
|
||||||
selectEnergyProvider(id: number) {
|
selectEnergyProvider(id: number) {
|
||||||
const energyProvider = this.energyProviders.find(energyProvider => energyProvider.id === id);
|
const energyProvider = this.energyProviders.find(energyProvider => energyProvider.id === id);
|
||||||
if (undefined === energyProvider)
|
if (undefined === energyProvider)
|
||||||
@ -131,7 +131,6 @@ export class EnergyProviderService {
|
|||||||
|
|
||||||
this.energyProviders = result.data;
|
this.energyProviders = result.data;
|
||||||
this.energyProviders$.next(this.energyProviders);
|
this.energyProviders$.next(this.energyProviders);
|
||||||
|
|
||||||
if (updateSelection && this.energyProviders.length > 0)
|
if (updateSelection && this.energyProviders.length > 0)
|
||||||
this.selectEnergyProvider(this.energyProviders[0].id)
|
this.selectEnergyProvider(this.energyProviders[0].id)
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import {Router} from '@angular/router';
|
|
||||||
import {BehaviorSubject, of} from 'rxjs';
|
import {BehaviorSubject, of} from 'rxjs';
|
||||||
import {SettingService} from './setting.service';
|
import {SettingService} from './setting.service';
|
||||||
import { inject, Injectable } from '@angular/core';
|
import { inject, Injectable } from '@angular/core';
|
||||||
@ -11,29 +10,29 @@ import {EnergyRateExceptionThresholdResetType} from '../enum/energy-rate-excepti
|
|||||||
export interface IEnergyRateException
|
export interface IEnergyRateException
|
||||||
{
|
{
|
||||||
id: number;
|
id: number;
|
||||||
rate_id: number;
|
rateId: number;
|
||||||
name: string;
|
name: string;
|
||||||
energyThreshold: number;
|
energyThreshold: number;
|
||||||
resetType: EnergyRateExceptionThresholdResetType;
|
resetType: EnergyRateExceptionThresholdResetType;
|
||||||
started_at: string;
|
startedAt: string;
|
||||||
ended_at: string;
|
endedAt: string;
|
||||||
}
|
}
|
||||||
export interface ICreateEnergyRateException
|
export interface ICreateEnergyRateException
|
||||||
{
|
{
|
||||||
rate_id: number;
|
rateId: number;
|
||||||
name: string;
|
name: string;
|
||||||
energyThreshold: number;
|
energyThreshold: number;
|
||||||
resetType: EnergyRateExceptionThresholdResetType;
|
resetType: EnergyRateExceptionThresholdResetType;
|
||||||
started_at: string;
|
startedAt: string;
|
||||||
ended_at: string;
|
endedAt: string;
|
||||||
}
|
}
|
||||||
export interface IUpdateEnergyRateException
|
export interface IUpdateEnergyRateException
|
||||||
{
|
{
|
||||||
energyRateExceptionId: number;
|
energyRateExceptionId: number;
|
||||||
energyThreshold: number;
|
energyThreshold: number;
|
||||||
resetType: EnergyRateExceptionThresholdResetType;
|
resetType: EnergyRateExceptionThresholdResetType;
|
||||||
started_at: string;
|
startedAt: string;
|
||||||
ended_at: string;
|
endedAt: string;
|
||||||
}
|
}
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@ -42,8 +41,6 @@ export class EnergyRateExceptionService {
|
|||||||
private readonly hdss = inject(HttpDataSourceService);
|
private readonly hdss = inject(HttpDataSourceService);
|
||||||
private readonly settingService = inject(SettingService);
|
private readonly settingService = inject(SettingService);
|
||||||
private readonly oidcSecurityService = inject(OidcSecurityService);
|
private readonly oidcSecurityService = inject(OidcSecurityService);
|
||||||
private readonly router = inject(Router);
|
|
||||||
|
|
||||||
private energyRateExceptions: IEnergyRateException[] = [];
|
private energyRateExceptions: IEnergyRateException[] = [];
|
||||||
|
|
||||||
dataSource?: IDataSource<IQueryCriteria, IEnergyRateException>
|
dataSource?: IDataSource<IQueryCriteria, IEnergyRateException>
|
||||||
@ -71,12 +68,12 @@ export class EnergyRateExceptionService {
|
|||||||
this.settingService.getMainCommandUrl('createEnergyRateException'),
|
this.settingService.getMainCommandUrl('createEnergyRateException'),
|
||||||
ev => {
|
ev => {
|
||||||
return of({
|
return of({
|
||||||
rate_id: ev.model.rate_id,
|
rateId: ev.model.rateId,
|
||||||
name: ev.model.name,
|
name: ev.model.name,
|
||||||
energyThreshold: ev.model.energyThreshold,
|
energyThreshold: ev.model.energyThreshold,
|
||||||
resetType: ev.model.resetType,
|
resetType: ev.model.resetType,
|
||||||
started_at: ev.model.started_at,
|
started_at: ev.model.startedAt,
|
||||||
ended_at: ev.model.ended_at,
|
ended_at: ev.model.endedAt,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.addCommandByUrl<IUpdateEnergyRateException, void>(
|
.addCommandByUrl<IUpdateEnergyRateException, void>(
|
||||||
@ -87,8 +84,8 @@ export class EnergyRateExceptionService {
|
|||||||
energyRateExceptionId: ev.model.id,
|
energyRateExceptionId: ev.model.id,
|
||||||
energyThreshold: ev.model.energyThreshold,
|
energyThreshold: ev.model.energyThreshold,
|
||||||
resetType: ev.model.resetType,
|
resetType: ev.model.resetType,
|
||||||
started_at: ev.model.started_at,
|
started_at: ev.model.startedAt,
|
||||||
ended_at: ev.model.ended_at,
|
ended_at: ev.model.endedAt,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import {Router} from '@angular/router';
|
|
||||||
import {BehaviorSubject, of} from 'rxjs';
|
import {BehaviorSubject, of} from 'rxjs';
|
||||||
import {Currency} from '../enum/currency';
|
import {Currency} from '../enum/currency';
|
||||||
import {SettingService} from './setting.service';
|
import {SettingService} from './setting.service';
|
||||||
@ -11,19 +10,19 @@ import {OidcSecurityService} from 'angular-auth-oidc-client';
|
|||||||
export interface IEnergyRate
|
export interface IEnergyRate
|
||||||
{
|
{
|
||||||
id: number;
|
id: number;
|
||||||
provider_id: number;
|
providerId: number;
|
||||||
name: string;
|
name: string;
|
||||||
rate: number;
|
rate: number;
|
||||||
currency: Currency;
|
currency: Currency;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
started_at: string;
|
startedAt: string;
|
||||||
disabled_at: string;
|
disabledAt: string;
|
||||||
created_at: string;
|
createdAt: string;
|
||||||
updated_at: string;
|
updatedAt: string;
|
||||||
}
|
}
|
||||||
export interface ICreateEnergyRate
|
export interface ICreateEnergyRate
|
||||||
{
|
{
|
||||||
provider_id: number;
|
providerId: number;
|
||||||
name: string;
|
name: string;
|
||||||
rate: number;
|
rate: number;
|
||||||
currency: Currency;
|
currency: Currency;
|
||||||
@ -31,18 +30,18 @@ export interface ICreateEnergyRate
|
|||||||
}
|
}
|
||||||
export interface IDisabledEnergyRate
|
export interface IDisabledEnergyRate
|
||||||
{
|
{
|
||||||
rate_id: number;
|
rateId: number;
|
||||||
disabled_at: string;
|
disabledAt: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
export interface IEnableEnergyRate
|
export interface IEnableEnergyRate
|
||||||
{
|
{
|
||||||
rate_id: number;
|
rateId: number;
|
||||||
}
|
}
|
||||||
export interface IUpdateEnergyRate
|
export interface IUpdateEnergyRate
|
||||||
{
|
{
|
||||||
rate_id: number;
|
rateId: number;
|
||||||
started_at : string;
|
startedAt : string;
|
||||||
name: string;
|
name: string;
|
||||||
rate: number;
|
rate: number;
|
||||||
|
|
||||||
@ -54,7 +53,6 @@ export class EnergyRateService {
|
|||||||
private readonly hdss = inject(HttpDataSourceService);
|
private readonly hdss = inject(HttpDataSourceService);
|
||||||
private readonly settingService = inject(SettingService);
|
private readonly settingService = inject(SettingService);
|
||||||
private readonly oidcSecurityService = inject(OidcSecurityService);
|
private readonly oidcSecurityService = inject(OidcSecurityService);
|
||||||
private readonly router = inject(Router);
|
|
||||||
|
|
||||||
private energyRates: IEnergyRate[] = [];
|
private energyRates: IEnergyRate[] = [];
|
||||||
|
|
||||||
@ -75,13 +73,13 @@ export class EnergyRateService {
|
|||||||
dataSourceBuilder() {
|
dataSourceBuilder() {
|
||||||
return this.hdss.builder<IQueryCriteria, IEnergyRate>()
|
return this.hdss.builder<IQueryCriteria, IEnergyRate>()
|
||||||
.keyResolver(model => model.id)
|
.keyResolver(model => model.id)
|
||||||
//.queryUrl(this.settingService.getMainQueryUrl())
|
.queryUrl(this.settingService.getMainQueryUrl('energyRate'))
|
||||||
.addCommandByUrl<ICreateEnergyRate, void>(
|
.addCommandByUrl<ICreateEnergyRate, void>(
|
||||||
'createEnergyRate',
|
'createEnergyRate',
|
||||||
this.settingService.getMainCommandUrl('createEnergyRate'),
|
this.settingService.getMainCommandUrl('createEnergyRate'),
|
||||||
ev => {
|
ev => {
|
||||||
return of({
|
return of({
|
||||||
provider_id: ev.model.provider_id,
|
providerId: ev.model.providerId,
|
||||||
name: ev.model.name,
|
name: ev.model.name,
|
||||||
rate: ev.model.rate,
|
rate: ev.model.rate,
|
||||||
currency: ev.model.currency,
|
currency: ev.model.currency,
|
||||||
@ -93,8 +91,8 @@ export class EnergyRateService {
|
|||||||
this.settingService.getMainCommandUrl('disableEnergyRate'),
|
this.settingService.getMainCommandUrl('disableEnergyRate'),
|
||||||
ev => {
|
ev => {
|
||||||
return of({
|
return of({
|
||||||
rate_id: ev.model.id,
|
rateID: ev.model.id,
|
||||||
disabled_at: ev.model.disabled_at
|
disabledAt: ev.model.disabledAt
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -112,11 +110,10 @@ export class EnergyRateService {
|
|||||||
this.settingService.getMainCommandUrl('updateEnergyRate'),
|
this.settingService.getMainCommandUrl('updateEnergyRate'),
|
||||||
ev => {
|
ev => {
|
||||||
return of({
|
return of({
|
||||||
rate_id: ev.model.id,
|
rateId: ev.model.id,
|
||||||
started_at: ev.model.started_at,
|
startedAt: ev.model.startedAt,
|
||||||
name: ev.model.name,
|
name: ev.model.name,
|
||||||
rate: ev.model.rate,
|
rate: ev.model.rate,
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user