|
@@ -12,7 +12,7 @@ import {
|
|
|
Map,
|
|
Map,
|
|
|
latLngBounds,
|
|
latLngBounds,
|
|
|
LatLng,
|
|
LatLng,
|
|
|
- point
|
|
|
|
|
|
|
+ point,
|
|
|
} from "leaflet";
|
|
} from "leaflet";
|
|
|
|
|
|
|
|
import { MatPaginator } from "@angular/material/paginator";
|
|
import { MatPaginator } from "@angular/material/paginator";
|
|
@@ -24,11 +24,12 @@ import { of as observableOf, Observable, throwError, from } from "rxjs";
|
|
|
|
|
|
|
|
import * as moment from "moment";
|
|
import * as moment from "moment";
|
|
|
import Swal from "sweetalert2";
|
|
import Swal from "sweetalert2";
|
|
|
|
|
+import { RatesService } from "@app/services/rates.service";
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
|
selector: "app-dashboard",
|
|
selector: "app-dashboard",
|
|
|
templateUrl: "./dashboard.component.html",
|
|
templateUrl: "./dashboard.component.html",
|
|
|
- styleUrls: ["./dashboard.component.scss"]
|
|
|
|
|
|
|
+ styleUrls: ["./dashboard.component.scss"],
|
|
|
})
|
|
})
|
|
|
export class DashboardComponent implements OnInit {
|
|
export class DashboardComponent implements OnInit {
|
|
|
title = "Dashboard";
|
|
title = "Dashboard";
|
|
@@ -65,21 +66,21 @@ export class DashboardComponent implements OnInit {
|
|
|
icon = icon({
|
|
icon = icon({
|
|
|
iconSize: [25, 41],
|
|
iconSize: [25, 41],
|
|
|
iconAnchor: [13, 41],
|
|
iconAnchor: [13, 41],
|
|
|
- iconUrl: "assets/img/marker-icon.png"
|
|
|
|
|
|
|
+ iconUrl: "assets/img/marker-icon.png",
|
|
|
//shadowUrl: 'marker-shadow.png'
|
|
//shadowUrl: 'marker-shadow.png'
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// Open Street Map definitions
|
|
// Open Street Map definitions
|
|
|
LAYER_OSM = tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
|
LAYER_OSM = tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
|
|
maxZoom: 18,
|
|
maxZoom: 18,
|
|
|
- attribution: "© OpenStreetMap contributors"
|
|
|
|
|
|
|
+ attribution: "© OpenStreetMap contributors",
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// Values to bind to Leaflet Directive
|
|
// Values to bind to Leaflet Directive
|
|
|
options = {
|
|
options = {
|
|
|
layers: [this.LAYER_OSM],
|
|
layers: [this.LAYER_OSM],
|
|
|
zoom: 10,
|
|
zoom: 10,
|
|
|
- center: latLng([13.661714, -89.25153])
|
|
|
|
|
|
|
+ center: latLng([13.661714, -89.25153]),
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
|
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
|
@@ -87,13 +88,40 @@ export class DashboardComponent implements OnInit {
|
|
|
userLevel: number;
|
|
userLevel: number;
|
|
|
totalAssetsInstalled: any;
|
|
totalAssetsInstalled: any;
|
|
|
|
|
|
|
|
|
|
+ rates: Object = {
|
|
|
|
|
+ distribuidora: "-",
|
|
|
|
|
+ codigo_tarifa: "-",
|
|
|
|
|
+ tarifa_actual: {
|
|
|
|
|
+ dateMin: null,
|
|
|
|
|
+ dateMax: null,
|
|
|
|
|
+ cargo_energia: null,
|
|
|
|
|
+ cargo_energia_b1: null,
|
|
|
|
|
+ cargo_energia_b2: null,
|
|
|
|
|
+ cargo_energia_b3: null,
|
|
|
|
|
+ cargo_energia_punta: null,
|
|
|
|
|
+ cargo_energia_resto: null,
|
|
|
|
|
+ cargo_energia_valle: null,
|
|
|
|
|
+ },
|
|
|
|
|
+ incremento_porcentaje: {
|
|
|
|
|
+ cargo_energia: null,
|
|
|
|
|
+ cargo_energia_b1: null,
|
|
|
|
|
+ cargo_energia_b2: null,
|
|
|
|
|
+ cargo_energia_b3: null,
|
|
|
|
|
+ cargo_energia_punta: null,
|
|
|
|
|
+ cargo_energia_resto: null,
|
|
|
|
|
+ cargo_energia_valle: null,
|
|
|
|
|
+ },
|
|
|
|
|
+ };
|
|
|
|
|
+ defaultRates: boolean;
|
|
|
|
|
+
|
|
|
constructor(
|
|
constructor(
|
|
|
private plantsService: PlantsService,
|
|
private plantsService: PlantsService,
|
|
|
private route: ActivatedRoute,
|
|
private route: ActivatedRoute,
|
|
|
private orgService: OrganizationsService,
|
|
private orgService: OrganizationsService,
|
|
|
private router: Router,
|
|
private router: Router,
|
|
|
private zone: NgZone,
|
|
private zone: NgZone,
|
|
|
- private authService: AuthService
|
|
|
|
|
|
|
+ private authService: AuthService,
|
|
|
|
|
+ private ratesService: RatesService
|
|
|
) {
|
|
) {
|
|
|
//DEMO
|
|
//DEMO
|
|
|
this.userLevel = +this.authService.getUserLevel();
|
|
this.userLevel = +this.authService.getUserLevel();
|
|
@@ -101,37 +129,39 @@ export class DashboardComponent implements OnInit {
|
|
|
Swal.fire({
|
|
Swal.fire({
|
|
|
allowOutsideClick: false,
|
|
allowOutsideClick: false,
|
|
|
type: "info",
|
|
type: "info",
|
|
|
- text: "Espere por favor..."
|
|
|
|
|
|
|
+ text: "Espere por favor...",
|
|
|
});
|
|
});
|
|
|
Swal.showLoading();
|
|
Swal.showLoading();
|
|
|
|
|
|
|
|
this.plantsService.getAllAssets().subscribe(
|
|
this.plantsService.getAllAssets().subscribe(
|
|
|
- res => {
|
|
|
|
|
- this.listAssets = res["data"]["assets"];
|
|
|
|
|
- this.dataSource.data = this.listAssets;
|
|
|
|
|
- this.dataSource.paginator = this.paginator;
|
|
|
|
|
- this.dataSource.sort = this.sort;
|
|
|
|
|
- this.assetKeys = Object.keys(this.listAssets);
|
|
|
|
|
|
|
+ (res) => {
|
|
|
|
|
+ if (res != null) {
|
|
|
|
|
+ this.listAssets = res["data"]["assets"];
|
|
|
|
|
+ this.dataSource.data = this.listAssets;
|
|
|
|
|
+ this.dataSource.paginator = this.paginator;
|
|
|
|
|
+ this.dataSource.sort = this.sort;
|
|
|
|
|
+ this.assetKeys = Object.keys(this.listAssets);
|
|
|
|
|
|
|
|
- //DEMO
|
|
|
|
|
- if (this.userLevel == 0) {
|
|
|
|
|
- this.sumarize = 320;
|
|
|
|
|
- this.totalAssetsInstalled = 1;
|
|
|
|
|
- } else {
|
|
|
|
|
- this.totalAssetsInstalled = this.listAssets.length || 0;
|
|
|
|
|
- for (let prop in this.assetKeys) {
|
|
|
|
|
- this.meterKeys2 = Object.keys(
|
|
|
|
|
- this.listAssets.map(item => item["meters_installed"])[prop]
|
|
|
|
|
- );
|
|
|
|
|
- if (this.meterKeys2.length > 0) {
|
|
|
|
|
- for (let prop2 in this.meterKeys2) {
|
|
|
|
|
- this.sumarize += this.listAssets
|
|
|
|
|
- .map(item => item["meters_installed"])
|
|
|
|
|
- [prop].map(response => response["installedCapacity_kW"])[
|
|
|
|
|
- prop2
|
|
|
|
|
- ];
|
|
|
|
|
- //this.totalMetersInstalled = this.sumarize.toString();
|
|
|
|
|
- //localStorage.setItem("installedCapacityTotal_kW", this.totalMetersInstalled);
|
|
|
|
|
|
|
+ //DEMO
|
|
|
|
|
+ if (this.userLevel == 0) {
|
|
|
|
|
+ this.sumarize = 320;
|
|
|
|
|
+ this.totalAssetsInstalled = 1;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.totalAssetsInstalled = this.listAssets.length || 0;
|
|
|
|
|
+ for (let prop in this.assetKeys) {
|
|
|
|
|
+ this.meterKeys2 = Object.keys(
|
|
|
|
|
+ this.listAssets.map((item) => item["meters_installed"])[prop]
|
|
|
|
|
+ );
|
|
|
|
|
+ if (this.meterKeys2.length > 0) {
|
|
|
|
|
+ for (let prop2 in this.meterKeys2) {
|
|
|
|
|
+ this.sumarize += this.listAssets
|
|
|
|
|
+ .map((item) => item["meters_installed"])
|
|
|
|
|
+ [prop].map((response) => response["installedCapacity_kW"])[
|
|
|
|
|
+ prop2
|
|
|
|
|
+ ];
|
|
|
|
|
+ //this.totalMetersInstalled = this.sumarize.toString();
|
|
|
|
|
+ //localStorage.setItem("installedCapacityTotal_kW", this.totalMetersInstalled);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -145,11 +175,11 @@ export class DashboardComponent implements OnInit {
|
|
|
Swal.close();
|
|
Swal.close();
|
|
|
}, 1800);
|
|
}, 1800);
|
|
|
},
|
|
},
|
|
|
- err => {
|
|
|
|
|
|
|
+ (err) => {
|
|
|
Swal.fire({
|
|
Swal.fire({
|
|
|
type: "error",
|
|
type: "error",
|
|
|
title: "Error en el servidor",
|
|
title: "Error en el servidor",
|
|
|
- text: err.message
|
|
|
|
|
|
|
+ text: err.message,
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
@@ -160,18 +190,23 @@ export class DashboardComponent implements OnInit {
|
|
|
Swal.close();
|
|
Swal.close();
|
|
|
}, 3000);
|
|
}, 3000);
|
|
|
|
|
|
|
|
|
|
+ this.ratesService.getDefaultRate().subscribe((res) => {
|
|
|
|
|
+ this.rates = res["data"];
|
|
|
|
|
+ this.defaultRates = true;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
var responsiveOptions: any[] = [
|
|
var responsiveOptions: any[] = [
|
|
|
[
|
|
[
|
|
|
"screen and (max-width: 640px)",
|
|
"screen and (max-width: 640px)",
|
|
|
{
|
|
{
|
|
|
seriesBarDistance: 5,
|
|
seriesBarDistance: 5,
|
|
|
axisX: {
|
|
axisX: {
|
|
|
- labelInterpolationFnc: function(value) {
|
|
|
|
|
|
|
+ labelInterpolationFnc: function (value) {
|
|
|
return value[0];
|
|
return value[0];
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- ]
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -183,7 +218,7 @@ export class DashboardComponent implements OnInit {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
getAsset(id: string) {
|
|
getAsset(id: string) {
|
|
|
- return observableOf(this.listAssets.find(e => e.id === id));
|
|
|
|
|
|
|
+ return observableOf(this.listAssets.find((e) => e.id === id));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
addMarkers() {
|
|
addMarkers() {
|
|
@@ -227,20 +262,20 @@ export class DashboardComponent implements OnInit {
|
|
|
city: "La Libertad",
|
|
city: "La Libertad",
|
|
|
address:
|
|
address:
|
|
|
"Urbanización Madre Selva Calle Llama del Bosque, Edificio Avante, Local 4-5/4-6, Antiguo Cuscatlán",
|
|
"Urbanización Madre Selva Calle Llama del Bosque, Edificio Avante, Local 4-5/4-6, Antiguo Cuscatlán",
|
|
|
- installedCapacity_kW: 300
|
|
|
|
|
|
|
+ installedCapacity_kW: 300,
|
|
|
};
|
|
};
|
|
|
this.totalInstalled = 320;
|
|
this.totalInstalled = 320;
|
|
|
} else {
|
|
} else {
|
|
|
this.totalInstalled = 0;
|
|
this.totalInstalled = 0;
|
|
|
- this.selectedPlant = this.listAssets.find(e => e.id === this.plantId);
|
|
|
|
|
|
|
+ this.selectedPlant = this.listAssets.find((e) => e.id === this.plantId);
|
|
|
let keys = Object.keys(
|
|
let keys = Object.keys(
|
|
|
this.selectedPlant.meters_installed.map(
|
|
this.selectedPlant.meters_installed.map(
|
|
|
- item => item["meters_installed"]
|
|
|
|
|
|
|
+ (item) => item["meters_installed"]
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|
|
|
for (let prop2 in keys) {
|
|
for (let prop2 in keys) {
|
|
|
this.totalInstalled += this.selectedPlant.meters_installed.map(
|
|
this.totalInstalled += this.selectedPlant.meters_installed.map(
|
|
|
- response => response["installedCapacity_kW"]
|
|
|
|
|
|
|
+ (response) => response["installedCapacity_kW"]
|
|
|
)[prop2];
|
|
)[prop2];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|