Compare commits
2 Commits
01d10171e9
...
14c8410ea7
Author | SHA1 | Date | |
---|---|---|---|
14c8410ea7 | |||
a430df72e4 |
@ -0,0 +1,3 @@
|
|||||||
|
export enum EnergyRateExceptionThresholdResetType {
|
||||||
|
daily
|
||||||
|
}
|
@ -1,3 +1,14 @@
|
|||||||
<p>default layout works !</p>
|
<button routerLink="/">
|
||||||
|
<label>Home</label>
|
||||||
|
</button>
|
||||||
|
<button routerLink="energy-provider">
|
||||||
|
<label>energy-provider</label>
|
||||||
|
</button>
|
||||||
|
<button routerLink="energy-rate">
|
||||||
|
<label>energy-rate</label>
|
||||||
|
</button>
|
||||||
|
<button routerLink="energy-rate-exception">
|
||||||
|
<label>energy-rate-exception</label>
|
||||||
|
</button>
|
||||||
<router-outlet />
|
<router-outlet />
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import {RouterOutlet} from '@angular/router';
|
import {RouterOutlet, RouterLink} from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-default-layout',
|
selector: 'app-default-layout',
|
||||||
imports: [
|
imports: [
|
||||||
RouterOutlet
|
RouterOutlet,
|
||||||
|
RouterLink
|
||||||
],
|
],
|
||||||
templateUrl: './default.layout.html',
|
templateUrl: './default.layout.html',
|
||||||
styleUrl: './default.layout.scss'
|
styleUrl: './default.layout.scss'
|
||||||
})
|
})
|
||||||
export class DefaultLayout {
|
export class DefaultLayout {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,31 @@ export const routes: Routes = [
|
|||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
pathMatch: 'full',
|
pathMatch: 'full',
|
||||||
redirectTo: 'home',
|
redirectTo: 'dashboard',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'home',
|
path: 'dashboard',
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import('../../pages/home/home.page')
|
import('../../pages/dashboard/dashboard.page')
|
||||||
.then(page => page.HomePage),
|
.then(page => page.DashboardPage),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'energy-provider',
|
||||||
|
loadComponent: () =>
|
||||||
|
import('../../pages/energy-provider/energy-provider.page')
|
||||||
|
.then(page => page.EnergyProviderPage),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'energy-rate',
|
||||||
|
loadComponent: () =>
|
||||||
|
import('../../pages/energy-rate/energy-rate.page')
|
||||||
|
.then(page => page.EnergyRatePage),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'energy-rate-exception',
|
||||||
|
loadComponent: () =>
|
||||||
|
import('../../pages/energy-rate-exception/energy-rate-exception.page')
|
||||||
|
.then(page => page.EnergyRateExceptionPage),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
1
src/app/pages/dashboard/dashboard.page.html
Normal file
1
src/app/pages/dashboard/dashboard.page.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<p>dashboard works!</p>
|
@ -1,18 +1,18 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
import { HomePage } from './home.page';
|
import { DashboardPage } from './dashboard.page';
|
||||||
|
|
||||||
describe('HomePage', () => {
|
describe('DashboardPage', () => {
|
||||||
let component: HomePage;
|
let component: DashboardPage;
|
||||||
let fixture: ComponentFixture<HomePage>;
|
let fixture: ComponentFixture<DashboardPage>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
imports: [HomePage]
|
imports: [DashboardPage]
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
|
|
||||||
fixture = TestBed.createComponent(HomePage);
|
fixture = TestBed.createComponent(DashboardPage);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
11
src/app/pages/dashboard/dashboard.page.ts
Normal file
11
src/app/pages/dashboard/dashboard.page.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-dashboard',
|
||||||
|
imports: [],
|
||||||
|
templateUrl: './dashboard.page.html',
|
||||||
|
styleUrl: './dashboard.page.scss'
|
||||||
|
})
|
||||||
|
export class DashboardPage {
|
||||||
|
|
||||||
|
}
|
58
src/app/pages/energy-provider/energy-provider.page.html
Normal file
58
src/app/pages/energy-provider/energy-provider.page.html
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<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>
|
23
src/app/pages/energy-provider/energy-provider.page.spec.ts
Normal file
23
src/app/pages/energy-provider/energy-provider.page.spec.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { EnergyProviderPage } from './energy-provider.page';
|
||||||
|
|
||||||
|
describe('EnergyProviderPage', () => {
|
||||||
|
let component: EnergyProviderPage;
|
||||||
|
let fixture: ComponentFixture<EnergyProviderPage>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [EnergyProviderPage]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(EnergyProviderPage);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
120
src/app/pages/energy-provider/energy-provider.page.ts
Normal file
120
src/app/pages/energy-provider/energy-provider.page.ts
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
import {finalize} from 'rxjs';
|
||||||
|
import {Router} from '@angular/router';
|
||||||
|
import {
|
||||||
|
IEnergyProvider,
|
||||||
|
EnergyProviderService,
|
||||||
|
ICreateEnergyProvider,
|
||||||
|
IDisabledEnergyProvider,
|
||||||
|
IEnableEnergyProvider,
|
||||||
|
IUpdateEnergyProvider
|
||||||
|
} from '../../services/energy-provider.service';
|
||||||
|
import {booleanAttribute, Component, inject, OnInit} from '@angular/core';
|
||||||
|
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-energy-provider',
|
||||||
|
imports: [
|
||||||
|
ReactiveFormsModule,
|
||||||
|
],
|
||||||
|
templateUrl: './energy-provider.page.html',
|
||||||
|
styleUrl: './energy-provider.page.scss'
|
||||||
|
})
|
||||||
|
export class EnergyProviderPage implements OnInit {
|
||||||
|
energyProviders: IEnergyProvider[] = [];
|
||||||
|
private energyProviderService = inject(EnergyProviderService);
|
||||||
|
private router = inject(Router);
|
||||||
|
loading: boolean = false;
|
||||||
|
|
||||||
|
createProviderForm: FormGroup;
|
||||||
|
disableProviderForm: FormGroup;
|
||||||
|
enableProviderForm: FormGroup;
|
||||||
|
updateProviderForm: FormGroup;
|
||||||
|
constructor(private _formBuilder: FormBuilder) {
|
||||||
|
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.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,
|
||||||
|
active,
|
||||||
|
})
|
||||||
|
.pipe(finalize(() => this.loading = false))
|
||||||
|
.subscribe(() => {
|
||||||
|
this.energyProviderService.dataSource?.refresh();
|
||||||
|
this.router.navigate(['/']);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
disable(): void {
|
||||||
|
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',
|
||||||
|
{
|
||||||
|
providerId,
|
||||||
|
disabledAt,
|
||||||
|
})
|
||||||
|
.pipe(finalize(() => this.loading = false))
|
||||||
|
.subscribe(() => {
|
||||||
|
this.energyProviderService.dataSource?.refresh();
|
||||||
|
this.router.navigate(['/']);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
enable(): void {
|
||||||
|
const providerId = this.enableProviderForm.value.providerId;
|
||||||
|
this.energyProviderService.dataSource?.executeCommandByName<IEnableEnergyProvider, void>(
|
||||||
|
'enableEnergyProvider',
|
||||||
|
{
|
||||||
|
providerId,
|
||||||
|
})
|
||||||
|
.pipe(finalize(() => this.loading = false))
|
||||||
|
.subscribe(() => {
|
||||||
|
this.energyProviderService.dataSource?.refresh();
|
||||||
|
this.router.navigate(['/']);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
update(): void {
|
||||||
|
if (this.updateProviderForm.valid) {
|
||||||
|
const providerId = this.updateProviderForm.value.providerId;
|
||||||
|
const name = this.updateProviderForm.value.updateName;
|
||||||
|
|
||||||
|
this.energyProviderService.dataSource?.executeCommandByName<IUpdateEnergyProvider, void>(
|
||||||
|
'updateEnergyProvider',
|
||||||
|
{
|
||||||
|
providerId,
|
||||||
|
name
|
||||||
|
})
|
||||||
|
.pipe(finalize(() => this.loading = false))
|
||||||
|
.subscribe(() => {
|
||||||
|
this.energyProviderService.dataSource?.refresh();
|
||||||
|
this.router.navigate(['/']);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
<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>
|
@ -0,0 +1,23 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { EnergyRateExceptionPage } from './energy-rate-exception.page';
|
||||||
|
|
||||||
|
describe('EnergyRateExceptionPage', () => {
|
||||||
|
let component: EnergyRateExceptionPage;
|
||||||
|
let fixture: ComponentFixture<EnergyRateExceptionPage>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [EnergyRateExceptionPage]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(EnergyRateExceptionPage);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,103 @@
|
|||||||
|
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: [
|
||||||
|
NgForOf,
|
||||||
|
ReactiveFormsModule
|
||||||
|
],
|
||||||
|
templateUrl: './energy-rate-exception.page.html',
|
||||||
|
styleUrl: './energy-rate-exception.page.scss'
|
||||||
|
})
|
||||||
|
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(['/']);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
73
src/app/pages/energy-rate/energy-rate.page.html
Normal file
73
src/app/pages/energy-rate/energy-rate.page.html
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<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>
|
0
src/app/pages/energy-rate/energy-rate.page.scss
Normal file
0
src/app/pages/energy-rate/energy-rate.page.scss
Normal file
23
src/app/pages/energy-rate/energy-rate.page.spec.ts
Normal file
23
src/app/pages/energy-rate/energy-rate.page.spec.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { EnergyRatePage } from './energy-rate.page';
|
||||||
|
|
||||||
|
describe('EnergyRatePage', () => {
|
||||||
|
let component: EnergyRatePage;
|
||||||
|
let fixture: ComponentFixture<EnergyRatePage>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [EnergyRatePage]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(EnergyRatePage);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
143
src/app/pages/energy-rate/energy-rate.page.ts
Normal file
143
src/app/pages/energy-rate/energy-rate.page.ts
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
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: [
|
||||||
|
ReactiveFormsModule,
|
||||||
|
NgForOf,
|
||||||
|
],
|
||||||
|
templateUrl: './energy-rate.page.html',
|
||||||
|
styleUrl: './energy-rate.page.scss'
|
||||||
|
})
|
||||||
|
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 +0,0 @@
|
|||||||
<p>home works!</p>
|
|
@ -1,11 +0,0 @@
|
|||||||
import { Component } from '@angular/core';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'app-home',
|
|
||||||
imports: [],
|
|
||||||
templateUrl: './home.page.html',
|
|
||||||
styleUrl: './home.page.scss'
|
|
||||||
})
|
|
||||||
export class HomePage {
|
|
||||||
|
|
||||||
}
|
|
@ -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,18 +10,19 @@ 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 IAddEnergyProvider
|
export interface ICreateEnergyProvider
|
||||||
{
|
{
|
||||||
name: string;
|
name: string;
|
||||||
|
active: boolean;
|
||||||
}
|
}
|
||||||
export interface IDisabledEnergyProvider
|
export interface IDisabledEnergyProvider
|
||||||
{
|
{
|
||||||
providerId: number;
|
providerId: number;
|
||||||
disabled_at: string;
|
disabledAt: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
export interface IEnableEnergyProvider
|
export interface IEnableEnergyProvider
|
||||||
@ -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,16 +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)
|
||||||
.addCommandByUrl<IAddEnergyProvider, void>(
|
.queryUrl(this.settingService.getMainQueryUrl('energyProvider'))
|
||||||
'addEnergyProvider',
|
.addCommandByUrl<ICreateEnergyProvider, void>(
|
||||||
this.settingService.getMainCommandUrl('addEnergyProvider'),
|
'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,7 +78,7 @@ export class EnergyProviderService {
|
|||||||
ev => {
|
ev => {
|
||||||
return of({
|
return of({
|
||||||
providerId: ev.model.id,
|
providerId: ev.model.id,
|
||||||
disabled_at: ev.model.disabled_at
|
disabledAt: ev.model.disabledAt
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -103,7 +102,9 @@ export class EnergyProviderService {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
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)
|
||||||
@ -130,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)
|
||||||
})
|
})
|
||||||
|
123
src/app/services/energy-rate-exception.service.ts
Normal file
123
src/app/services/energy-rate-exception.service.ts
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
import {BehaviorSubject, of} from 'rxjs';
|
||||||
|
import {SettingService} from './setting.service';
|
||||||
|
import { inject, Injectable } from '@angular/core';
|
||||||
|
import {HttpDataSourceService} from '@openharbor/ngx-data';
|
||||||
|
import {IDataSource, IQueryCriteria} from '@openharbor/data';
|
||||||
|
import {OidcSecurityService} from 'angular-auth-oidc-client';
|
||||||
|
import {EnergyRateExceptionThresholdResetType} from '../enum/energy-rate-exception-threshold-reset-type';
|
||||||
|
|
||||||
|
|
||||||
|
export interface IEnergyRateException
|
||||||
|
{
|
||||||
|
id: number;
|
||||||
|
rateId: number;
|
||||||
|
name: string;
|
||||||
|
energyThreshold: number;
|
||||||
|
resetType: EnergyRateExceptionThresholdResetType;
|
||||||
|
startedAt: string;
|
||||||
|
endedAt: string;
|
||||||
|
}
|
||||||
|
export interface ICreateEnergyRateException
|
||||||
|
{
|
||||||
|
rateId: number;
|
||||||
|
name: string;
|
||||||
|
energyThreshold: number;
|
||||||
|
resetType: EnergyRateExceptionThresholdResetType;
|
||||||
|
startedAt: string;
|
||||||
|
endedAt: string;
|
||||||
|
}
|
||||||
|
export interface IUpdateEnergyRateException
|
||||||
|
{
|
||||||
|
energyRateExceptionId: number;
|
||||||
|
energyThreshold: number;
|
||||||
|
resetType: EnergyRateExceptionThresholdResetType;
|
||||||
|
startedAt: string;
|
||||||
|
endedAt: string;
|
||||||
|
}
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class EnergyRateExceptionService {
|
||||||
|
private readonly hdss = inject(HttpDataSourceService);
|
||||||
|
private readonly settingService = inject(SettingService);
|
||||||
|
private readonly oidcSecurityService = inject(OidcSecurityService);
|
||||||
|
private energyRateExceptions: IEnergyRateException[] = [];
|
||||||
|
|
||||||
|
dataSource?: IDataSource<IQueryCriteria, IEnergyRateException>
|
||||||
|
|
||||||
|
current$ = new BehaviorSubject<IEnergyRateException | null>(null);
|
||||||
|
energyRateExceptions$ = new BehaviorSubject<IEnergyRateException[]>([]);
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.internalDataSource();
|
||||||
|
|
||||||
|
this.oidcSecurityService.isAuthenticated$
|
||||||
|
.subscribe(result => {
|
||||||
|
if (result.isAuthenticated) {
|
||||||
|
this.dataSource?.refresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dataSourceBuilder()
|
||||||
|
{
|
||||||
|
return this.hdss.builder<IQueryCriteria, IEnergyRateException>()
|
||||||
|
.keyResolver(model => model.id)
|
||||||
|
//.queryUrl(this.settingService.getMainQueryUrl())
|
||||||
|
.addCommandByUrl<ICreateEnergyRateException, void>(
|
||||||
|
'createEnergyRateException',
|
||||||
|
this.settingService.getMainCommandUrl('createEnergyRateException'),
|
||||||
|
ev => {
|
||||||
|
return of({
|
||||||
|
rateId: ev.model.rateId,
|
||||||
|
name: ev.model.name,
|
||||||
|
energyThreshold: ev.model.energyThreshold,
|
||||||
|
resetType: ev.model.resetType,
|
||||||
|
started_at: ev.model.startedAt,
|
||||||
|
ended_at: ev.model.endedAt,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.addCommandByUrl<IUpdateEnergyRateException, void>(
|
||||||
|
'updateEnergyRateException',
|
||||||
|
this.settingService.getMainCommandUrl('updateEnergyRateException'),
|
||||||
|
ev => {
|
||||||
|
return of({
|
||||||
|
energyRateExceptionId: ev.model.id,
|
||||||
|
energyThreshold: ev.model.energyThreshold,
|
||||||
|
resetType: ev.model.resetType,
|
||||||
|
started_at: ev.model.startedAt,
|
||||||
|
ended_at: ev.model.endedAt,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
selectEnergyRateException(id: number) {
|
||||||
|
const energyRateException = this.energyRateExceptions.find(energyRateException => energyRateException.id === id);
|
||||||
|
if (undefined === energyRateException)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.current$.next(energyRateException);
|
||||||
|
}
|
||||||
|
private internalDataSource() {
|
||||||
|
if (undefined !== this.dataSource)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.dataSource = this.dataSourceBuilder()
|
||||||
|
.createDataSource();
|
||||||
|
|
||||||
|
this.dataSource.data$
|
||||||
|
.subscribe(result => {
|
||||||
|
if (null === result || undefined === result.data)
|
||||||
|
return;
|
||||||
|
|
||||||
|
let updateSelection = false;
|
||||||
|
if (this.energyRateExceptions.length === 0) {
|
||||||
|
updateSelection = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.energyRateExceptions = result.data;
|
||||||
|
this.energyRateExceptions$.next(this.energyRateExceptions);
|
||||||
|
|
||||||
|
if (updateSelection && this.energyRateExceptions.length > 0)
|
||||||
|
this.selectEnergyRateException(this.energyRateExceptions[0].id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -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';
|
||||||
@ -6,12 +5,7 @@ import { inject, Injectable } from '@angular/core';
|
|||||||
import {HttpDataSourceService} from '@openharbor/ngx-data';
|
import {HttpDataSourceService} from '@openharbor/ngx-data';
|
||||||
import {IDataSource, IQueryCriteria} from '@openharbor/data';
|
import {IDataSource, IQueryCriteria} from '@openharbor/data';
|
||||||
import {OidcSecurityService} from 'angular-auth-oidc-client';
|
import {OidcSecurityService} from 'angular-auth-oidc-client';
|
||||||
import {
|
|
||||||
IAddEnergyProvider,
|
|
||||||
IDisabledEnergyProvider,
|
|
||||||
IEnableEnergyProvider,
|
|
||||||
IEnergyProvider, IUpdateEnergyProvider
|
|
||||||
} from './energy-provider.service';
|
|
||||||
|
|
||||||
export interface IEnergyRate
|
export interface IEnergyRate
|
||||||
{
|
{
|
||||||
@ -21,12 +15,12 @@ export interface IEnergyRate
|
|||||||
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 IAddEnergyRate
|
export interface ICreateEnergyRate
|
||||||
{
|
{
|
||||||
providerId: number;
|
providerId: number;
|
||||||
name: string;
|
name: string;
|
||||||
@ -37,7 +31,7 @@ export interface IAddEnergyRate
|
|||||||
export interface IDisabledEnergyRate
|
export interface IDisabledEnergyRate
|
||||||
{
|
{
|
||||||
rateId: number;
|
rateId: number;
|
||||||
disabled_at: string;
|
disabledAt: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
export interface IEnableEnergyRate
|
export interface IEnableEnergyRate
|
||||||
@ -47,7 +41,7 @@ export interface IEnableEnergyRate
|
|||||||
export interface IUpdateEnergyRate
|
export interface IUpdateEnergyRate
|
||||||
{
|
{
|
||||||
rateId: number;
|
rateId: number;
|
||||||
started_at : string;
|
startedAt : string;
|
||||||
name: string;
|
name: string;
|
||||||
rate: number;
|
rate: number;
|
||||||
|
|
||||||
@ -59,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[] = [];
|
||||||
|
|
||||||
@ -80,9 +73,10 @@ 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)
|
||||||
.addCommandByUrl<IAddEnergyRate, void>(
|
.queryUrl(this.settingService.getMainQueryUrl('energyRate'))
|
||||||
'addEnergyRate',
|
.addCommandByUrl<ICreateEnergyRate, void>(
|
||||||
this.settingService.getMainCommandUrl('addEnergyRate'),
|
'createEnergyRate',
|
||||||
|
this.settingService.getMainCommandUrl('createEnergyRate'),
|
||||||
ev => {
|
ev => {
|
||||||
return of({
|
return of({
|
||||||
providerId: ev.model.providerId,
|
providerId: ev.model.providerId,
|
||||||
@ -97,8 +91,8 @@ export class EnergyRateService {
|
|||||||
this.settingService.getMainCommandUrl('disableEnergyRate'),
|
this.settingService.getMainCommandUrl('disableEnergyRate'),
|
||||||
ev => {
|
ev => {
|
||||||
return of({
|
return of({
|
||||||
rateId: ev.model.id,
|
rateID: ev.model.id,
|
||||||
disabled_at: ev.model.disabled_at
|
disabledAt: ev.model.disabledAt
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -117,10 +111,9 @@ export class EnergyRateService {
|
|||||||
ev => {
|
ev => {
|
||||||
return of({
|
return of({
|
||||||
rateId: 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