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()">
|
||||
<label for="name">Provider Name</label>
|
||||
<input id="name" formControlName="name" type="text" />
|
||||
<button type="submit" [disabled]="formGroup.invalid || loading">
|
||||
<form [formGroup]="createProviderForm" (ngSubmit)="submit()">
|
||||
<label>Provider Name</label>
|
||||
<input formControlName="name" type="text" />
|
||||
<label>Active</label>
|
||||
<select formControlName="active">
|
||||
<option>true</option>
|
||||
<option>false</option>
|
||||
</select>
|
||||
<button type="submit" [disabled]="createProviderForm.invalid || loading">
|
||||
{{ loading ? 'Adding...' : 'Add Provider' }}
|
||||
</button>
|
||||
</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 { 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<ICreateEnergyProvider, void>(
|
||||
'createEnergyProvider',
|
||||
{
|
||||
name
|
||||
name,
|
||||
active,
|
||||
})
|
||||
.pipe(finalize(() => this.loading = false))
|
||||
.subscribe(() => {
|
||||
@ -43,14 +71,14 @@ 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<IDisabledEnergyProvider, void>(
|
||||
'disableEnergyProvider',
|
||||
{
|
||||
provider_id,
|
||||
disabled_at,
|
||||
providerId,
|
||||
disabledAt,
|
||||
})
|
||||
.pipe(finalize(() => this.loading = false))
|
||||
.subscribe(() => {
|
||||
@ -58,14 +86,12 @@ export class EnergyProviderPage {
|
||||
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<IEnableEnergyProvider, void>(
|
||||
'enableEnergyProvider',
|
||||
{
|
||||
provider_id,
|
||||
providerId,
|
||||
})
|
||||
.pipe(finalize(() => this.loading = false))
|
||||
.subscribe(() => {
|
||||
@ -73,16 +99,15 @@ export class EnergyProviderPage {
|
||||
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<IUpdateEnergyProvider, void>(
|
||||
'updateEnergyProvider',
|
||||
{
|
||||
provider_id,
|
||||
providerId,
|
||||
name
|
||||
})
|
||||
.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({
|
||||
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<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({
|
||||
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<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 {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<IQueryCriteria, IEnergyProvider>
|
||||
|
||||
current$ = new BehaviorSubject<IEnergyProvider | null>(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<IQueryCriteria, IEnergyProvider>()
|
||||
.keyResolver(model => model.id)
|
||||
//.queryUrl(this.settingService.getMainQueryUrl())
|
||||
.queryUrl(this.settingService.getMainQueryUrl('energyProvider'))
|
||||
.addCommandByUrl<ICreateEnergyProvider, void>(
|
||||
'createEnergyProvider',
|
||||
this.settingService.getMainCommandUrl('createEnergyProvider'),
|
||||
ev => {
|
||||
return of({
|
||||
name: ev.model.name
|
||||
name: ev.model.name,
|
||||
active: ev.model.active
|
||||
})
|
||||
})
|
||||
.addCommandByUrl<IDisabledEnergyProvider, void>(
|
||||
@ -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)
|
||||
})
|
||||
|
@ -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<IQueryCriteria, IEnergyRateException>
|
||||
@ -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<IUpdateEnergyRateException, void>(
|
||||
@ -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,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -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<IQueryCriteria, IEnergyRate>()
|
||||
.keyResolver(model => model.id)
|
||||
//.queryUrl(this.settingService.getMainQueryUrl())
|
||||
.queryUrl(this.settingService.getMainQueryUrl('energyRate'))
|
||||
.addCommandByUrl<ICreateEnergyRate, void>(
|
||||
'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,
|
||||
|
||||
})
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user