diff --git a/src/app/enum/energy-rate-exception-threshold-reset-type.ts b/src/app/enum/energy-rate-exception-threshold-reset-type.ts
new file mode 100644
index 0000000..1a4189b
--- /dev/null
+++ b/src/app/enum/energy-rate-exception-threshold-reset-type.ts
@@ -0,0 +1,3 @@
+export enum EnergyRateExceptionThresholdResetType {
+ daily
+}
diff --git a/src/app/layouts/default/default.layout.html b/src/app/layouts/default/default.layout.html
index 7d1ef78..831d4e2 100644
--- a/src/app/layouts/default/default.layout.html
+++ b/src/app/layouts/default/default.layout.html
@@ -1,3 +1,14 @@
-
default layout works !
+
+
+
+
diff --git a/src/app/layouts/default/default.layout.ts b/src/app/layouts/default/default.layout.ts
index b35cdb9..3ab50d8 100644
--- a/src/app/layouts/default/default.layout.ts
+++ b/src/app/layouts/default/default.layout.ts
@@ -1,14 +1,14 @@
import { Component } from '@angular/core';
-import {RouterOutlet} from '@angular/router';
+import {RouterOutlet, RouterLink} from '@angular/router';
@Component({
selector: 'app-default-layout',
imports: [
- RouterOutlet
+ RouterOutlet,
+ RouterLink
],
templateUrl: './default.layout.html',
styleUrl: './default.layout.scss'
})
export class DefaultLayout {
-
}
diff --git a/src/app/layouts/default/default.routes.ts b/src/app/layouts/default/default.routes.ts
index a9b74dc..64b78ed 100644
--- a/src/app/layouts/default/default.routes.ts
+++ b/src/app/layouts/default/default.routes.ts
@@ -9,13 +9,31 @@ export const routes: Routes = [
{
path: '',
pathMatch: 'full',
- redirectTo: 'home',
+ redirectTo: 'dashboard',
},
{
- path: 'home',
+ path: 'dashboard',
loadComponent: () =>
- import('../../pages/home/home.page')
- .then(page => page.HomePage),
+ import('../../pages/dashboard/dashboard.page')
+ .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),
},
],
},
diff --git a/src/app/pages/dashboard/dashboard.page.html b/src/app/pages/dashboard/dashboard.page.html
new file mode 100644
index 0000000..9c5fce9
--- /dev/null
+++ b/src/app/pages/dashboard/dashboard.page.html
@@ -0,0 +1 @@
+dashboard works!
diff --git a/src/app/pages/home/home.page.scss b/src/app/pages/dashboard/dashboard.page.scss
similarity index 100%
rename from src/app/pages/home/home.page.scss
rename to src/app/pages/dashboard/dashboard.page.scss
diff --git a/src/app/pages/home/home.page.spec.ts b/src/app/pages/dashboard/dashboard.page.spec.ts
similarity index 56%
rename from src/app/pages/home/home.page.spec.ts
rename to src/app/pages/dashboard/dashboard.page.spec.ts
index 40ac737..64b66de 100644
--- a/src/app/pages/home/home.page.spec.ts
+++ b/src/app/pages/dashboard/dashboard.page.spec.ts
@@ -1,18 +1,18 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { HomePage } from './home.page';
+import { DashboardPage } from './dashboard.page';
-describe('HomePage', () => {
- let component: HomePage;
- let fixture: ComponentFixture;
+describe('DashboardPage', () => {
+ let component: DashboardPage;
+ let fixture: ComponentFixture;
beforeEach(async () => {
await TestBed.configureTestingModule({
- imports: [HomePage]
+ imports: [DashboardPage]
})
.compileComponents();
- fixture = TestBed.createComponent(HomePage);
+ fixture = TestBed.createComponent(DashboardPage);
component = fixture.componentInstance;
fixture.detectChanges();
});
diff --git a/src/app/pages/dashboard/dashboard.page.ts b/src/app/pages/dashboard/dashboard.page.ts
new file mode 100644
index 0000000..190cde1
--- /dev/null
+++ b/src/app/pages/dashboard/dashboard.page.ts
@@ -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 {
+
+}
diff --git a/src/app/pages/energy-provider/energy-provider.page.html b/src/app/pages/energy-provider/energy-provider.page.html
new file mode 100644
index 0000000..fdbf420
--- /dev/null
+++ b/src/app/pages/energy-provider/energy-provider.page.html
@@ -0,0 +1,7 @@
+
diff --git a/src/app/pages/energy-provider/energy-provider.page.scss b/src/app/pages/energy-provider/energy-provider.page.scss
new file mode 100644
index 0000000..e69de29
diff --git a/src/app/pages/energy-provider/energy-provider.page.spec.ts b/src/app/pages/energy-provider/energy-provider.page.spec.ts
new file mode 100644
index 0000000..2f9d8fa
--- /dev/null
+++ b/src/app/pages/energy-provider/energy-provider.page.spec.ts
@@ -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;
+
+ beforeEach(async () => {
+ await TestBed.configureTestingModule({
+ imports: [EnergyProviderPage]
+ })
+ .compileComponents();
+
+ fixture = TestBed.createComponent(EnergyProviderPage);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/src/app/pages/energy-provider/energy-provider.page.ts b/src/app/pages/energy-provider/energy-provider.page.ts
new file mode 100644
index 0000000..9b6b9bb
--- /dev/null
+++ b/src/app/pages/energy-provider/energy-provider.page.ts
@@ -0,0 +1,95 @@
+import {Router} from '@angular/router';
+import { Component, inject } from '@angular/core';
+import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
+import {
+ EnergyProviderService,
+ ICreateEnergyProvider,
+ IDisabledEnergyProvider, IEnableEnergyProvider, IUpdateEnergyProvider
+} from '../../services/energy-provider.service';
+import {finalize} from 'rxjs';
+@Component({
+ selector: 'app-energy-provider',
+ imports: [
+ ReactiveFormsModule,
+ ],
+ templateUrl: './energy-provider.page.html',
+ styleUrl: './energy-provider.page.scss'
+})
+export class EnergyProviderPage {
+ private energyProviderService = inject(EnergyProviderService);
+ private router = inject(Router);
+ loading: boolean = false;
+
+ formGroup: FormGroup;
+ constructor(private _formBuilder: FormBuilder) {
+ this.formGroup = this._formBuilder.group({
+ name: ['', [Validators.required, Validators.minLength(3)]],
+ });
+ }
+ submit(): void {
+ if (this.formGroup.valid) {
+ const name = this.formGroup.value.name;
+
+ this.energyProviderService.dataSource?.executeCommandByName(
+ 'createEnergyProvider',
+ {
+ name
+ })
+ .pipe(finalize(() => this.loading = false))
+ .subscribe(() => {
+ this.energyProviderService.dataSource?.refresh();
+ this.router.navigate(['/']);
+ })
+ }
+ }
+ disable(): void {
+ if (this.formGroup.valid) {
+ const provider_id = this.formGroup.value.provider_id;
+ const disabled_at = this.formGroup.value.disabled_at
+ this.energyProviderService.dataSource?.executeCommandByName(
+ 'disableEnergyProvider',
+ {
+ provider_id,
+ disabled_at,
+ })
+ .pipe(finalize(() => this.loading = false))
+ .subscribe(() => {
+ this.energyProviderService.dataSource?.refresh();
+ this.router.navigate(['/']);
+ })
+ }
+ }
+ enable(): void {
+ if (this.formGroup.valid) {
+ const provider_id = this.formGroup.value.provider_id;
+ this.energyProviderService.dataSource?.executeCommandByName(
+ 'enableEnergyProvider',
+ {
+ provider_id,
+ })
+ .pipe(finalize(() => this.loading = false))
+ .subscribe(() => {
+ this.energyProviderService.dataSource?.refresh();
+ this.router.navigate(['/']);
+ })
+ }
+ }
+ update(): void {
+ if (this.formGroup.valid) {
+ const provider_id = this.formGroup.value.provider_id;
+ const name = this.formGroup.value.name;
+
+ this.energyProviderService.dataSource?.executeCommandByName(
+ 'updateEnergyProvider',
+ {
+ provider_id,
+ name
+ })
+ .pipe(finalize(() => this.loading = false))
+ .subscribe(() => {
+ this.energyProviderService.dataSource?.refresh();
+ this.router.navigate(['/']);
+ })
+ }
+ }
+}
diff --git a/src/app/pages/energy-rate-exception/energy-rate-exception.page.html b/src/app/pages/energy-rate-exception/energy-rate-exception.page.html
new file mode 100644
index 0000000..48733a0
--- /dev/null
+++ b/src/app/pages/energy-rate-exception/energy-rate-exception.page.html
@@ -0,0 +1 @@
+energy-rate-exception works!
diff --git a/src/app/pages/energy-rate-exception/energy-rate-exception.page.scss b/src/app/pages/energy-rate-exception/energy-rate-exception.page.scss
new file mode 100644
index 0000000..e69de29
diff --git a/src/app/pages/energy-rate-exception/energy-rate-exception.page.spec.ts b/src/app/pages/energy-rate-exception/energy-rate-exception.page.spec.ts
new file mode 100644
index 0000000..b4cbfcf
--- /dev/null
+++ b/src/app/pages/energy-rate-exception/energy-rate-exception.page.spec.ts
@@ -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;
+
+ beforeEach(async () => {
+ await TestBed.configureTestingModule({
+ imports: [EnergyRateExceptionPage]
+ })
+ .compileComponents();
+
+ fixture = TestBed.createComponent(EnergyRateExceptionPage);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/src/app/pages/energy-rate-exception/energy-rate-exception.page.ts b/src/app/pages/energy-rate-exception/energy-rate-exception.page.ts
new file mode 100644
index 0000000..d9f7218
--- /dev/null
+++ b/src/app/pages/energy-rate-exception/energy-rate-exception.page.ts
@@ -0,0 +1,11 @@
+import { Component } from '@angular/core';
+
+@Component({
+ selector: 'app-energy-rate-exception',
+ imports: [],
+ templateUrl: './energy-rate-exception.page.html',
+ styleUrl: './energy-rate-exception.page.scss'
+})
+export class EnergyRateExceptionPage {
+
+}
diff --git a/src/app/pages/energy-rate/energy-rate.page.html b/src/app/pages/energy-rate/energy-rate.page.html
new file mode 100644
index 0000000..1f3aa25
--- /dev/null
+++ b/src/app/pages/energy-rate/energy-rate.page.html
@@ -0,0 +1 @@
+energy-rate works!
diff --git a/src/app/pages/energy-rate/energy-rate.page.scss b/src/app/pages/energy-rate/energy-rate.page.scss
new file mode 100644
index 0000000..e69de29
diff --git a/src/app/pages/energy-rate/energy-rate.page.spec.ts b/src/app/pages/energy-rate/energy-rate.page.spec.ts
new file mode 100644
index 0000000..147618c
--- /dev/null
+++ b/src/app/pages/energy-rate/energy-rate.page.spec.ts
@@ -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;
+
+ beforeEach(async () => {
+ await TestBed.configureTestingModule({
+ imports: [EnergyRatePage]
+ })
+ .compileComponents();
+
+ fixture = TestBed.createComponent(EnergyRatePage);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/src/app/pages/energy-rate/energy-rate.page.ts b/src/app/pages/energy-rate/energy-rate.page.ts
new file mode 100644
index 0000000..b4f520c
--- /dev/null
+++ b/src/app/pages/energy-rate/energy-rate.page.ts
@@ -0,0 +1,11 @@
+import { Component } from '@angular/core';
+
+@Component({
+ selector: 'app-energy-rate',
+ imports: [],
+ templateUrl: './energy-rate.page.html',
+ styleUrl: './energy-rate.page.scss'
+})
+export class EnergyRatePage {
+
+}
diff --git a/src/app/pages/home/home.page.html b/src/app/pages/home/home.page.html
deleted file mode 100644
index 5f2c53f..0000000
--- a/src/app/pages/home/home.page.html
+++ /dev/null
@@ -1 +0,0 @@
-home works!
diff --git a/src/app/pages/home/home.page.ts b/src/app/pages/home/home.page.ts
deleted file mode 100644
index c9baa5c..0000000
--- a/src/app/pages/home/home.page.ts
+++ /dev/null
@@ -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 {
-
-}
diff --git a/src/app/services/energy-provider.service.ts b/src/app/services/energy-provider.service.ts
index 0e205c8..5e7944c 100644
--- a/src/app/services/energy-provider.service.ts
+++ b/src/app/services/energy-provider.service.ts
@@ -15,23 +15,23 @@ export interface IEnergyProvider
created_at: string;
updated_at: string;
}
-export interface IAddEnergyProvider
+export interface ICreateEnergyProvider
{
name: string;
}
export interface IDisabledEnergyProvider
{
- providerId: number;
+ provider_id: number;
disabled_at: string;
}
export interface IEnableEnergyProvider
{
- providerId: number;
+ provider_id: number;
}
export interface IUpdateEnergyProvider
{
- providerId: number;
+ provider_id: number;
name: string;
}
@@ -65,9 +65,10 @@ export class EnergyProviderService {
dataSourceBuilder() {
return this.hdss.builder()
.keyResolver(model => model.id)
- .addCommandByUrl(
- 'addEnergyProvider',
- this.settingService.getMainCommandUrl('addEnergyProvider'),
+ //.queryUrl(this.settingService.getMainQueryUrl())
+ .addCommandByUrl(
+ 'createEnergyProvider',
+ this.settingService.getMainCommandUrl('createEnergyProvider'),
ev => {
return of({
name: ev.model.name
@@ -78,7 +79,7 @@ export class EnergyProviderService {
this.settingService.getMainCommandUrl('disableEnergyProvider'),
ev => {
return of({
- providerId: ev.model.id,
+ provider_id: ev.model.id,
disabled_at: ev.model.disabled_at
})
}
@@ -88,7 +89,7 @@ export class EnergyProviderService {
this.settingService.getMainCommandUrl('enableEnergyProvider'),
ev => {
return of({
- providerId: ev.model.id,
+ provider_id: ev.model.id,
})
}
)
@@ -97,7 +98,7 @@ export class EnergyProviderService {
this.settingService.getMainCommandUrl('updateEnergyProvider'),
ev => {
return of({
- providerId: ev.model.id,
+ provider_id: ev.model.id,
name: ev.model.name
})
}
diff --git a/src/app/services/energy-rate-exception.service.ts b/src/app/services/energy-rate-exception.service.ts
new file mode 100644
index 0000000..fb1cacf
--- /dev/null
+++ b/src/app/services/energy-rate-exception.service.ts
@@ -0,0 +1,126 @@
+import {Router} from '@angular/router';
+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;
+ rate_id: number;
+ name: string;
+ energyThreshold: number;
+ resetType: EnergyRateExceptionThresholdResetType;
+ started_at: string;
+ ended_at: string;
+}
+export interface ICreateEnergyRateException
+{
+ rate_id: number;
+ name: string;
+ energyThreshold: number;
+ resetType: EnergyRateExceptionThresholdResetType;
+ started_at: string;
+ ended_at: string;
+}
+export interface IUpdateEnergyRateException
+{
+ energyRateExceptionId: number;
+ energyThreshold: number;
+ resetType: EnergyRateExceptionThresholdResetType;
+ started_at: string;
+ ended_at: string;
+}
+@Injectable({
+ providedIn: 'root'
+})
+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
+
+ current$ = new BehaviorSubject(null);
+ energyRateExceptions$ = new BehaviorSubject([]);
+
+ constructor() {
+ this.internalDataSource();
+
+ this.oidcSecurityService.isAuthenticated$
+ .subscribe(result => {
+ if (result.isAuthenticated) {
+ this.dataSource?.refresh();
+ }
+ });
+ }
+ dataSourceBuilder()
+ {
+ return this.hdss.builder()
+ .keyResolver(model => model.id)
+ //.queryUrl(this.settingService.getMainQueryUrl())
+ .addCommandByUrl(
+ 'createEnergyRateException',
+ this.settingService.getMainCommandUrl('createEnergyRateException'),
+ ev => {
+ return of({
+ rate_id: ev.model.rate_id,
+ name: ev.model.name,
+ energyThreshold: ev.model.energyThreshold,
+ resetType: ev.model.resetType,
+ started_at: ev.model.started_at,
+ ended_at: ev.model.ended_at,
+ })
+ })
+ .addCommandByUrl(
+ 'updateEnergyRateException',
+ this.settingService.getMainCommandUrl('updateEnergyRateException'),
+ ev => {
+ return of({
+ energyRateExceptionId: ev.model.id,
+ energyThreshold: ev.model.energyThreshold,
+ resetType: ev.model.resetType,
+ started_at: ev.model.started_at,
+ ended_at: ev.model.ended_at,
+ })
+ })
+ }
+ 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)
+ })
+ }
+}
diff --git a/src/app/services/energy-rate.service.ts b/src/app/services/energy-rate.service.ts
index f026892..bbddbd3 100644
--- a/src/app/services/energy-rate.service.ts
+++ b/src/app/services/energy-rate.service.ts
@@ -6,17 +6,12 @@ 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 {
- IAddEnergyProvider,
- IDisabledEnergyProvider,
- IEnableEnergyProvider,
- IEnergyProvider, IUpdateEnergyProvider
-} from './energy-provider.service';
+
export interface IEnergyRate
{
id: number;
- providerId: number;
+ provider_id: number;
name: string;
rate: number;
currency: Currency;
@@ -26,9 +21,9 @@ export interface IEnergyRate
created_at: string;
updated_at: string;
}
-export interface IAddEnergyRate
+export interface ICreateEnergyRate
{
- providerId: number;
+ provider_id: number;
name: string;
rate: number;
currency: Currency;
@@ -36,17 +31,17 @@ export interface IAddEnergyRate
}
export interface IDisabledEnergyRate
{
- rateId: number;
+ rate_id: number;
disabled_at: string;
}
export interface IEnableEnergyRate
{
- rateId: number;
+ rate_id: number;
}
export interface IUpdateEnergyRate
{
- rateId: number;
+ rate_id: number;
started_at : string;
name: string;
rate: number;
@@ -80,12 +75,13 @@ export class EnergyRateService {
dataSourceBuilder() {
return this.hdss.builder()
.keyResolver(model => model.id)
- .addCommandByUrl(
- 'addEnergyRate',
- this.settingService.getMainCommandUrl('addEnergyRate'),
+ //.queryUrl(this.settingService.getMainQueryUrl())
+ .addCommandByUrl(
+ 'createEnergyRate',
+ this.settingService.getMainCommandUrl('createEnergyRate'),
ev => {
return of({
- providerId: ev.model.providerId,
+ provider_id: ev.model.provider_id,
name: ev.model.name,
rate: ev.model.rate,
currency: ev.model.currency,
@@ -97,7 +93,7 @@ export class EnergyRateService {
this.settingService.getMainCommandUrl('disableEnergyRate'),
ev => {
return of({
- rateId: ev.model.id,
+ rate_id: ev.model.id,
disabled_at: ev.model.disabled_at
})
}
@@ -116,7 +112,7 @@ export class EnergyRateService {
this.settingService.getMainCommandUrl('updateEnergyRate'),
ev => {
return of({
- rateId: ev.model.id,
+ rate_id: ev.model.id,
started_at: ev.model.started_at,
name: ev.model.name,
rate: ev.model.rate,