|
|
@@ -1,10 +1,10 @@
|
|
|
-import { ActivatedRoute, Router } from "@angular/router";
|
|
|
-import { Component, OnInit, NgZone, ViewChild } from "@angular/core";
|
|
|
-import { Plant } from "src/app/models/plant";
|
|
|
-import { Rate } from "src/app/models/rate";
|
|
|
+import { ActivatedRoute, Router } from '@angular/router';
|
|
|
+import { Component, OnInit, NgZone, ViewChild } from '@angular/core';
|
|
|
+import { Plant } from 'src/app/models/plant';
|
|
|
+import { Rate } from 'src/app/models/rate';
|
|
|
|
|
|
-import { PlantsService } from "src/app/services/plants.service";
|
|
|
-import { OrganizationsService } from "src/app/services/organizations.service";
|
|
|
+import { PlantsService } from 'src/app/services/plants.service';
|
|
|
+import { OrganizationsService } from 'src/app/services/organizations.service';
|
|
|
import {
|
|
|
latLng,
|
|
|
tileLayer,
|
|
|
@@ -15,26 +15,29 @@ import {
|
|
|
latLngBounds,
|
|
|
LatLng,
|
|
|
point,
|
|
|
-} from "leaflet";
|
|
|
+} from 'leaflet';
|
|
|
|
|
|
-import { MatPaginator } from "@angular/material/paginator";
|
|
|
-import { MatSort } from "@angular/material/sort";
|
|
|
-import { MatTableDataSource } from "@angular/material/table";
|
|
|
-import { AuthService } from "@app/services/auth2.service";
|
|
|
+import { MatPaginator } from '@angular/material/paginator';
|
|
|
+import { MatSort } from '@angular/material/sort';
|
|
|
+import { MatTableDataSource } from '@angular/material/table';
|
|
|
+import { AuthService } from '@app/services/auth2.service';
|
|
|
|
|
|
-import { of as observableOf, Observable, throwError, from } from "rxjs";
|
|
|
+import { of as observableOf, Observable, throwError, from } from 'rxjs';
|
|
|
|
|
|
-import * as moment from "moment";
|
|
|
-import Swal from "sweetalert2";
|
|
|
-import { RatesService } from "@app/services/rates.service";
|
|
|
+import * as moment from 'moment';
|
|
|
+import Swal from 'sweetalert2';
|
|
|
+import { RatesService } from '@app/services/rates.service';
|
|
|
+import { Tariff } from '@app/models/tariff';
|
|
|
+import { Cargo } from '@app/models/cargo';
|
|
|
+import { DatePipe } from '@angular/common';
|
|
|
|
|
|
@Component({
|
|
|
- selector: "app-dashboard",
|
|
|
- templateUrl: "./dashboard.component.html",
|
|
|
- styleUrls: ["./dashboard.component.scss"],
|
|
|
+ selector: 'app-dashboard',
|
|
|
+ templateUrl: './dashboard.component.html',
|
|
|
+ styleUrls: ['./dashboard.component.scss'],
|
|
|
})
|
|
|
export class DashboardComponent implements OnInit {
|
|
|
- title = "Dashboard";
|
|
|
+ title = 'Dashboard';
|
|
|
|
|
|
listData: any;
|
|
|
rows = [];
|
|
|
@@ -43,7 +46,7 @@ export class DashboardComponent implements OnInit {
|
|
|
|
|
|
listAssets: any;
|
|
|
dataSource = new MatTableDataSource(this.listAssets);
|
|
|
- displayedColumns: string[] = ["name", "country", "city", "id"];
|
|
|
+ displayedColumns: string[] = ['name', 'country', 'city', 'id'];
|
|
|
|
|
|
error: boolean;
|
|
|
listOrganizations: any;
|
|
|
@@ -68,14 +71,14 @@ export class DashboardComponent implements OnInit {
|
|
|
icon = icon({
|
|
|
iconSize: [25, 41],
|
|
|
iconAnchor: [13, 41],
|
|
|
- iconUrl: "assets/img/marker-icon.png",
|
|
|
+ iconUrl: 'assets/img/marker-icon.png',
|
|
|
//shadowUrl: 'marker-shadow.png'
|
|
|
});
|
|
|
|
|
|
// 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,
|
|
|
- attribution: "© OpenStreetMap contributors",
|
|
|
+ attribution: '© OpenStreetMap contributors',
|
|
|
});
|
|
|
|
|
|
// Values to bind to Leaflet Directive
|
|
|
@@ -91,8 +94,8 @@ export class DashboardComponent implements OnInit {
|
|
|
totalAssetsInstalled: any;
|
|
|
|
|
|
rates: Rate = {
|
|
|
- distribuidora: "-",
|
|
|
- codigo_tarifa: "-",
|
|
|
+ distribuidora: '-',
|
|
|
+ codigo_tarifa: '-',
|
|
|
tarifa_actual: {
|
|
|
dateMin: null,
|
|
|
dateMax: null,
|
|
|
@@ -116,6 +119,10 @@ export class DashboardComponent implements OnInit {
|
|
|
};
|
|
|
defaultRates: boolean;
|
|
|
|
|
|
+ tarifa: Tariff;
|
|
|
+ vigencia: string;
|
|
|
+ tarifaActual: Cargo[];
|
|
|
+
|
|
|
constructor(
|
|
|
private plantsService: PlantsService,
|
|
|
private route: ActivatedRoute,
|
|
|
@@ -123,22 +130,23 @@ export class DashboardComponent implements OnInit {
|
|
|
private router: Router,
|
|
|
private zone: NgZone,
|
|
|
private authService: AuthService,
|
|
|
- private ratesService: RatesService
|
|
|
+ private ratesService: RatesService,
|
|
|
+ private datePipe: DatePipe,
|
|
|
) {
|
|
|
//DEMO
|
|
|
this.userLevel = +this.authService.getUserLevel();
|
|
|
|
|
|
Swal.fire({
|
|
|
allowOutsideClick: false,
|
|
|
- type: "info",
|
|
|
- text: "Espere por favor...",
|
|
|
+ type: 'info',
|
|
|
+ text: 'Espere por favor...',
|
|
|
});
|
|
|
Swal.showLoading();
|
|
|
|
|
|
this.plantsService.getAllAssets().subscribe(
|
|
|
(res) => {
|
|
|
if (res != null) {
|
|
|
- this.listAssets = res["data"]["assets"];
|
|
|
+ this.listAssets = res.data.assets;
|
|
|
this.dataSource.data = this.listAssets;
|
|
|
this.dataSource.paginator = this.paginator;
|
|
|
this.dataSource.sort = this.sort;
|
|
|
@@ -152,13 +160,13 @@ export class DashboardComponent implements OnInit {
|
|
|
this.totalAssetsInstalled = this.listAssets.length || 0;
|
|
|
for (let prop in this.assetKeys) {
|
|
|
this.meterKeys2 = Object.keys(
|
|
|
- this.listAssets.map((item) => item["meters_installed"])[prop]
|
|
|
+ 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"])[
|
|
|
+ .map((item) => item['meters_installed'])
|
|
|
+ [prop].map((response) => response['installedCapacity_kW'])[
|
|
|
prop2
|
|
|
];
|
|
|
//this.totalMetersInstalled = this.sumarize.toString();
|
|
|
@@ -179,8 +187,8 @@ export class DashboardComponent implements OnInit {
|
|
|
},
|
|
|
(err) => {
|
|
|
Swal.fire({
|
|
|
- type: "error",
|
|
|
- title: "Error en el servidor",
|
|
|
+ type: 'error',
|
|
|
+ title: 'Error en el servidor',
|
|
|
text: err.message,
|
|
|
});
|
|
|
}
|
|
|
@@ -193,13 +201,14 @@ export class DashboardComponent implements OnInit {
|
|
|
}, 3000);
|
|
|
|
|
|
this.ratesService.getDefaultRate().subscribe((res) => {
|
|
|
- this.rates = res["data"];
|
|
|
- this.defaultRates = true;
|
|
|
+ this.tarifa = res.data;
|
|
|
+ this.tarifaActual = this.tarifa.tarifa_actual.cargos.filter(cargo => cargo.value !== '');
|
|
|
+ this.vigencia = this.getTariffPeriod(this.tarifa);
|
|
|
});
|
|
|
|
|
|
var responsiveOptions: any[] = [
|
|
|
[
|
|
|
- "screen and (max-width: 640px)",
|
|
|
+ 'screen and (max-width: 640px)',
|
|
|
{
|
|
|
seriesBarDistance: 5,
|
|
|
axisX: {
|
|
|
@@ -226,24 +235,24 @@ export class DashboardComponent implements OnInit {
|
|
|
addMarkers() {
|
|
|
let lat, long, address, name2;
|
|
|
for (const plant of this.listAssets) {
|
|
|
- if (plant["meters_installed"].length > 0) {
|
|
|
+ if (plant['meters_installed'].length > 0) {
|
|
|
// DEMO
|
|
|
if (this.userLevel == 0) {
|
|
|
- lat = "13.6613819";
|
|
|
- long = "-89.2514334";
|
|
|
+ lat = '13.6613819';
|
|
|
+ long = '-89.2514334';
|
|
|
address =
|
|
|
- "Urbanización Madre Selva Calle Llama del Bosque, Edificio Avante, Local 4-5/4-6, Antiguo Cuscatlán";
|
|
|
- name2 = "Inversiones MERELEC S.A de C.V";
|
|
|
+ 'Urbanización Madre Selva Calle Llama del Bosque, Edificio Avante, Local 4-5/4-6, Antiguo Cuscatlán';
|
|
|
+ name2 = 'Inversiones MERELEC S.A de C.V';
|
|
|
} else {
|
|
|
- lat = plant["meters_installed"][0].gpsLat;
|
|
|
- long = plant["meters_installed"][0].gpsLong;
|
|
|
+ lat = plant['meters_installed'][0].gpsLat;
|
|
|
+ long = plant['meters_installed'][0].gpsLong;
|
|
|
address = plant.address;
|
|
|
name2 = plant.name;
|
|
|
}
|
|
|
|
|
|
const newMarker = marker([lat, long], { icon: this.icon })
|
|
|
- .bindPopup("<b>" + name2 + "</b><br>Dirección: " + address)
|
|
|
- .on("click", () => {
|
|
|
+ .bindPopup('<b>' + name2 + '</b><br>Dirección: ' + address)
|
|
|
+ .on('click', () => {
|
|
|
this.zone.run(() => {
|
|
|
this.sendPlantId(plant.id);
|
|
|
});
|
|
|
@@ -259,11 +268,11 @@ export class DashboardComponent implements OnInit {
|
|
|
// DEMO
|
|
|
if (this.userLevel == 0) {
|
|
|
this.selectedPlant = {
|
|
|
- name: "Inversiones MERELEC S.A de C.V",
|
|
|
- country: "El Salvador",
|
|
|
- city: "La Libertad",
|
|
|
+ name: 'Inversiones MERELEC S.A de C.V',
|
|
|
+ country: 'El Salvador',
|
|
|
+ city: 'La Libertad',
|
|
|
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,
|
|
|
};
|
|
|
this.totalInstalled = 320;
|
|
|
@@ -272,12 +281,12 @@ export class DashboardComponent implements OnInit {
|
|
|
this.selectedPlant = this.listAssets.find((e) => e.id === this.plantId);
|
|
|
let keys = Object.keys(
|
|
|
this.selectedPlant.meters_installed.map(
|
|
|
- (item) => item["meters_installed"]
|
|
|
+ (item) => item['meters_installed']
|
|
|
)
|
|
|
);
|
|
|
for (let prop2 in keys) {
|
|
|
this.totalInstalled += this.selectedPlant.meters_installed.map(
|
|
|
- (response) => response["installedCapacity_kW"]
|
|
|
+ (response) => response['installedCapacity_kW']
|
|
|
)[prop2];
|
|
|
}
|
|
|
}
|
|
|
@@ -297,6 +306,13 @@ export class DashboardComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
goToAsset(id: string) {
|
|
|
- this.router.navigate(["/assets"], { queryParams: { id: id } });
|
|
|
+ this.router.navigate(['/assets'], { queryParams: { id: id } });
|
|
|
+ }
|
|
|
+
|
|
|
+ getTariffPeriod(tarifa: Tariff) {
|
|
|
+ const inicio = this.datePipe.transform(new Date(tarifa.tarifa_actual.vigencia.inicio), 'dd/MMM/yy', '+0000')
|
|
|
+ const fin = this.datePipe.transform(new Date(tarifa.tarifa_actual.vigencia.fin), 'dd/MMM/yy', '+0000')
|
|
|
+ const period = `Vigencia: ${inicio} - ${fin}`;
|
|
|
+ return period;
|
|
|
}
|
|
|
}
|