Skip to content

Commit

Permalink
Merge pull request #3531 from sap-labs-france/master-labs
Browse files Browse the repository at this point in the history
Version 2.7.6 - additional changes
  • Loading branch information
ClaudeROSSI authored Apr 4, 2023
2 parents a80a2c2 + f684f04 commit d61dfea
Show file tree
Hide file tree
Showing 19 changed files with 204 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"typescript"
],
"jest.jestCommandLine": "npm run test -- ",
"jest.autoRun": "false"
"jest.autoRun": { "watch": "false" }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="h-100 d-flex flex-column">
<app-statistics-filters (buttonOfScopeGroup)="scopeChanged($event)" (category)="categoryChanged($event)"
(dateRange)="dateRangeChange($event)" (year)="yearChanged($event)" [allYears]="allYears"
(dateRange)="dateRangeChange($event)" (year)="yearChanged($event)" [allYears]="allYears" [authorizations]="authorizations"
(filters)="filtersChanged($event)" (update)="updateCharts($event)" (export)="exportData()"></app-statistics-filters>
<h3>
<div class="chart">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { ChartData } from 'chart.js';
import { StatisticsAuthorizations } from 'types/Authorization';
import { ChartTypeValues } from 'types/Chart';
import { StatisticDataResult } from 'types/DataResult';
import { Utils } from 'utils/Utils';

import { CentralServerService } from '../../../services/central-server.service';
import { LocaleService } from '../../../services/locale.service';
Expand All @@ -27,6 +30,7 @@ export class StatisticsConsumptionComponent implements OnInit {
public selectedYear!: number;
public allYears = true;
public chartsInitialized = false;
public authorizations: StatisticsAuthorizations;

private filterParams!: FilterParams;
private barChart!: SimpleChart;
Expand Down Expand Up @@ -156,11 +160,14 @@ export class StatisticsConsumptionComponent implements OnInit {
}

public buildCharts(): void {
// Append withAuth filter to retrieve auth - this also changes the response into datasource
this.filterParams['WithAuth'] = 'true';
this.spinnerService.show();
if (this.selectedCategory === 'C') {
this.centralServerService.getChargingStationConsumptionStatistics(this.selectedYear, this.filterParams)
.subscribe((statisticsData) => {
this.barChartData = this.statisticsBuildService.buildStackedChartDataForMonths(statisticsData, 2);
this.initAuth(statisticsData);
this.barChartData = this.statisticsBuildService.buildStackedChartDataForMonths(statisticsData.result, 2);
this.pieChartData = this.statisticsBuildService.calculateTotalChartDataFromStackedChartData(this.barChartData);
this.totalConsumption = this.statisticsBuildService.calculateTotalValueFromChartData(this.barChartData);
if (this.selectedChart === 'month') {
Expand All @@ -173,7 +180,8 @@ export class StatisticsConsumptionComponent implements OnInit {
} else {
this.centralServerService.getUserConsumptionStatistics(this.selectedYear, this.filterParams)
.subscribe((statisticsData) => {
this.barChartData = this.statisticsBuildService.buildStackedChartDataForMonths(statisticsData, 2);
this.initAuth(statisticsData);
this.barChartData = this.statisticsBuildService.buildStackedChartDataForMonths(statisticsData.result, 2);
this.pieChartData = this.statisticsBuildService.calculateTotalChartDataFromStackedChartData(this.barChartData);
this.totalConsumption = this.statisticsBuildService.calculateTotalValueFromChartData(this.barChartData);

Expand All @@ -186,4 +194,14 @@ export class StatisticsConsumptionComponent implements OnInit {
});
}
}

private initAuth(statisticsData: StatisticDataResult) {
this.authorizations = {
canListUsers: Utils.convertToBoolean(statisticsData.canListUsers),
canListChargingStations: Utils.convertToBoolean(statisticsData.canListChargingStations),
canListSites: Utils.convertToBoolean(statisticsData.canListSites),
canListSiteAreas: Utils.convertToBoolean(statisticsData.canListSiteAreas),
canExport: Utils.convertToBoolean(statisticsData.canExport),
};
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="h-100 d-flex flex-column">
<app-statistics-filters (buttonOfScopeGroup)="scopeChanged($event)" (category)="categoryChanged($event)"
(dateRange)="dateRangeChange($event)" (year)="yearChanged($event)" [allYears]="allYears"
(dateRange)="dateRangeChange($event)" (year)="yearChanged($event)" [allYears]="allYears" [authorizations]="authorizations"
(filters)="filtersChanged($event)" (update)="updateCharts($event)" (export)="exportData()"></app-statistics-filters>
<h3>
<div class="chart">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { ChartData } from 'chart.js';
import { StatisticsAuthorizations } from 'types/Authorization';
import { ChartTypeValues } from 'types/Chart';
import { StatisticDataResult } from 'types/DataResult';
import { Utils } from 'utils/Utils';

import { CentralServerService } from '../../../services/central-server.service';
import { LocaleService } from '../../../services/locale.service';
import { SpinnerService } from '../../../services/spinner.service';
import { FilterParams } from '../../../types/GlobalType';
import { TableFilterDef } from '../../../types/Table';
import { SimpleChart } from '../shared/chart-utilities';
import { StatisticsBuildService } from '../shared/statistics-build.service';
import { StatisticsExportService } from '../shared/statistics-export.service';
Expand All @@ -28,6 +30,7 @@ export class StatisticsInactivityComponent implements OnInit {
public selectedYear!: number;
public allYears = true;
public chartsInitialized = false;
public authorizations: StatisticsAuthorizations;

private filterParams!: FilterParams;
private barChart!: SimpleChart;
Expand Down Expand Up @@ -157,11 +160,14 @@ export class StatisticsInactivityComponent implements OnInit {
}

public buildCharts(): void {
// Append withAuth filter to retrieve auth - this also changes the response into datasource
this.filterParams['WithAuth'] = 'true';
this.spinnerService.show();
if (this.selectedCategory === 'C') {
this.centralServerService.getChargingStationInactivityStatistics(this.selectedYear, this.filterParams)
.subscribe((statisticsData) => {
this.barChartData = this.statisticsBuildService.buildStackedChartDataForMonths(statisticsData, 2);
this.initAuth(statisticsData);
this.barChartData = this.statisticsBuildService.buildStackedChartDataForMonths(statisticsData.result, 2);
this.pieChartData = this.statisticsBuildService.calculateTotalChartDataFromStackedChartData(this.barChartData);
this.totalInactivity = this.statisticsBuildService.calculateTotalValueFromChartData(this.barChartData);
if (this.selectedChart === 'month') {
Expand All @@ -174,7 +180,8 @@ export class StatisticsInactivityComponent implements OnInit {
} else {
this.centralServerService.getUserInactivityStatistics(this.selectedYear, this.filterParams)
.subscribe((statisticsData) => {
this.barChartData = this.statisticsBuildService.buildStackedChartDataForMonths(statisticsData, 2);
this.initAuth(statisticsData);
this.barChartData = this.statisticsBuildService.buildStackedChartDataForMonths(statisticsData.result, 2);
this.pieChartData = this.statisticsBuildService.calculateTotalChartDataFromStackedChartData(this.barChartData);
this.totalInactivity = this.statisticsBuildService.calculateTotalValueFromChartData(this.barChartData);
if (this.selectedChart === 'month') {
Expand All @@ -186,4 +193,14 @@ export class StatisticsInactivityComponent implements OnInit {
});
}
}

private initAuth(statisticsData: StatisticDataResult) {
this.authorizations = {
canListUsers: Utils.convertToBoolean(statisticsData.canListUsers),
canListChargingStations: Utils.convertToBoolean(statisticsData.canListChargingStations),
canListSites: Utils.convertToBoolean(statisticsData.canListSites),
canListSiteAreas: Utils.convertToBoolean(statisticsData.canListSiteAreas),
canExport: Utils.convertToBoolean(statisticsData.canExport),
};
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="h-100 d-flex flex-column"> <!-- *ngIf is not compatible with @ViewChild for charts in <canvas> -->
<app-statistics-filters (buttonOfScopeGroup)="scopeChanged($event)" (category)="categoryChanged($event)"
(dateRange)="dateRangeChange($event)" (year)="yearChanged($event)" [allYears]="allYears"
(dateRange)="dateRangeChange($event)" (year)="yearChanged($event)" [allYears]="allYears" [authorizations]="authorizations"
(filters)="filtersChanged($event)" (update)="updateCharts($event)" (export)="exportData()"></app-statistics-filters>
<h3>
<div [hidden]="!isPricingActive" class="chart">
Expand Down
25 changes: 21 additions & 4 deletions src/app/pages/statistics/pricing/statistics-pricing.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { ChartData } from 'chart.js';
import { StatisticsAuthorizations } from 'types/Authorization';
import { ChartTypeValues } from 'types/Chart';
import { StatisticDataResult } from 'types/DataResult';
import { Utils } from 'utils/Utils';

import { CentralServerService } from '../../../services/central-server.service';
import { ComponentService } from '../../../services/component.service';
import { LocaleService } from '../../../services/locale.service';
import { SpinnerService } from '../../../services/spinner.service';
import { FilterParams } from '../../../types/GlobalType';
import { TableFilterDef } from '../../../types/Table';
import { TenantComponents } from '../../../types/Tenant';
import { SimpleChart } from '../shared/chart-utilities';
import { StatisticsBuildService, StatisticsBuildValueWithUnit } from '../shared/statistics-build.service';
Expand All @@ -31,6 +33,7 @@ export class StatisticsPricingComponent implements OnInit {
public selectedYear!: number;
public allYears = true;
public chartsInitialized = false;
public authorizations: StatisticsAuthorizations;

private filterParams!: FilterParams;
private barChart!: SimpleChart;
Expand Down Expand Up @@ -178,13 +181,16 @@ export class StatisticsPricingComponent implements OnInit {
}

public buildCharts(): void {
// Append withAuth filter to retrieve auth - this also changes the response into datasource
this.filterParams['WithAuth'] = 'true';
this.spinnerService.show();
let newToolTipUnit: string;
let newLabelYAxis: string;
let addUnitToLabel = false;
if (this.selectedCategory === 'C') {
this.centralServerService.getChargingStationPricingStatistics(this.selectedYear, this.filterParams)
.subscribe((statisticsData) => {
this.initAuth(statisticsData);
this.totalPriceWithUnit = this.statisticsBuildService.calculateTotalsWithUnits(statisticsData, 2);
if (this.totalPriceWithUnit.length > 1) {
addUnitToLabel = true;
Expand All @@ -193,7 +199,7 @@ export class StatisticsPricingComponent implements OnInit {
newToolTipUnit = this.totalPriceWithUnit[0].unit;
}
newLabelYAxis = this.translateService.instant('statistics.graphic_title_pricing_y_axis', { currency: newToolTipUnit });
this.barChartData = this.statisticsBuildService.buildStackedChartDataForMonths(statisticsData, 2, addUnitToLabel);
this.barChartData = this.statisticsBuildService.buildStackedChartDataForMonths(statisticsData.result, 2, addUnitToLabel);
this.pieChartData = this.statisticsBuildService.calculateTotalChartDataFromStackedChartData(this.barChartData);
this.barChart.updateChart(this.barChartData, this.getChartLabel(), newToolTipUnit, newLabelYAxis);
this.pieChart.updateChart(this.pieChartData, this.getChartLabel(), newToolTipUnit);
Expand All @@ -202,7 +208,8 @@ export class StatisticsPricingComponent implements OnInit {
} else {
this.centralServerService.getUserPricingStatistics(this.selectedYear, this.filterParams)
.subscribe((statisticsData) => {
if (statisticsData.length > 1) {
this.initAuth(statisticsData);
if (statisticsData.count > 1) {
this.totalPriceWithUnit = this.statisticsBuildService.calculateTotalsWithUnits(statisticsData, 2);
}
if (this.totalPriceWithUnit.length > 1) {
Expand All @@ -212,12 +219,22 @@ export class StatisticsPricingComponent implements OnInit {
newToolTipUnit = this.totalPriceWithUnit[0].unit;
}
newLabelYAxis = this.translateService.instant('statistics.graphic_title_pricing_y_axis', { currency: newToolTipUnit });
this.barChartData = this.statisticsBuildService.buildStackedChartDataForMonths(statisticsData, 2, addUnitToLabel);
this.barChartData = this.statisticsBuildService.buildStackedChartDataForMonths(statisticsData.result, 2, addUnitToLabel);
this.pieChartData = this.statisticsBuildService.calculateTotalChartDataFromStackedChartData(this.barChartData);
this.barChart.updateChart(this.barChartData, this.getChartLabel(), newToolTipUnit, newLabelYAxis);
this.pieChart.updateChart(this.pieChartData, this.getChartLabel(), newToolTipUnit);
this.spinnerService.hide();
});
}
}

private initAuth(statisticsData: StatisticDataResult) {
this.authorizations = {
canListUsers: Utils.convertToBoolean(statisticsData.canListUsers),
canListChargingStations: Utils.convertToBoolean(statisticsData.canListChargingStations),
canListSites: Utils.convertToBoolean(statisticsData.canListSites),
canListSiteAreas: Utils.convertToBoolean(statisticsData.canListSiteAreas),
canExport: Utils.convertToBoolean(statisticsData.canExport),
};
}
}
5 changes: 3 additions & 2 deletions src/app/pages/statistics/shared/statistics-build.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { ChartData, ChartDataset } from 'chart.js';
import * as moment from 'moment';
import { StatisticDataResult } from 'types/DataResult';

import { LocaleService } from '../../../services/locale.service';
import { StatisticData } from '../../../types/Statistic';
Expand Down Expand Up @@ -312,7 +313,7 @@ export class StatisticsBuildService {
return count;
}

public calculateTotalsWithUnits(statisticsData: any, roundingDecimals: number = 0, ignoreEmptyUnit = true): StatisticsBuildValueWithUnit[] {
public calculateTotalsWithUnits(statisticsData: StatisticDataResult, roundingDecimals: number = 0, ignoreEmptyUnit = true): StatisticsBuildValueWithUnit[] {
let roundingFactor = 1;
let index = 0;
let localString: any;
Expand All @@ -322,7 +323,7 @@ export class StatisticsBuildService {
let totalOfLastUnit = 0;
let totalWithUnit: StatisticsBuildValueWithUnit;
const totalsWithUnit: StatisticsBuildValueWithUnit[] = [];
const transactionValues = statisticsData;
const transactionValues = statisticsData.result;
if (roundingDecimals !== 0) {
if (roundingDecimals > 0) {
for (let i = 0; i < roundingDecimals; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="left-actions d-flex flex-row mat-toolbar-row ">
<!-- Create Left Actions -->
<!-- Export data -->
<button mat-raised-button (click)="exportData()" [color]="'primary'" appTooltip
<button *ngIf="authorizations?.canExport" mat-raised-button (click)="exportData()" [color]="'primary'" appTooltip
[title]="'general.export' | translate">
<mat-icon>cloud_download</mat-icon><span>{{'general.export' | translate}}</span>
</button>
Expand Down Expand Up @@ -61,7 +61,7 @@
<!-- filters -->
<div class="d-flex flex-row me-auto flex-wrap mat-toolbar-row filter-row">
<!-- Category of statistics -->
<div *ngIf="isAdmin" class="col-sm-4 col-md-3 col-lg-2 col-xl-2">
<div *ngIf="authorizations?.canListUsers && authorizations?.canListChargingStations" class="col-sm-4 col-md-3 col-lg-2 col-xl-2">
<mat-form-field>
<mat-select (selectionChange)="categoryChanged()" [(value)]="selectedCategory"
[placeholder]="'statistics.category_label' | translate">
Expand Down
Loading

0 comments on commit d61dfea

Please sign in to comment.