Skip to content

Commit

Permalink
Merge pull request #2514 from sap-labs-france/master-qa
Browse files Browse the repository at this point in the history
Merge master-qa
  • Loading branch information
LucasBrazi06 authored Jul 29, 2021
2 parents fd1716a + 7352166 commit d567219
Show file tree
Hide file tree
Showing 22 changed files with 156 additions and 50 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ev-dashboard",
"description": "Dashboard for Electric Vehicle charging station",
"homepage": "https://github.com/sap-labs-france/ev-dashboard",
"version": "2.4.79",
"version": "2.4.80",
"engines": {
"npm": "6.x.x."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ export class CompaniesListTableDataSource extends TableDataSource<Company> {
isAngularComponent: true,
angularComponent: CompanyLogoFormatterCellComponent,
},
{
id: 'id',
name: 'general.id',
sortable: true,
headerClass: 'col-30p',
class: 'col-30p',
sorted: true,
direction: 'asc',
},
{
id: 'name',
name: 'companies.name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ export class SiteAreasListTableDataSource extends TableDataSource<SiteArea> {

public buildTableColumnDefs(): TableColumnDef[] {
const tableColumnDef: TableColumnDef[] = [
{
id: 'id',
name: 'general.id',
sortable: true,
headerClass: 'col-30p',
class: 'col-30p',
sorted: true,
direction: 'asc',
},
{
id: 'name',
name: 'site_areas.name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ export class SitesListTableDataSource extends TableDataSource<Site> {

public buildTableColumnDefs(): TableColumnDef[] {
return [
{
id: 'id',
name: 'general.id',
sortable: true,
headerClass: 'col-30p',
class: 'col-30p',
sorted: true,
direction: 'asc',
},
{
id: 'name',
name: 'sites.name',
Expand Down
16 changes: 15 additions & 1 deletion src/app/release-notes/release-notes.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ export class ReleaseNotesComponent {

public buildReleaseNotes() {
this.releaseNotes = [
{
version: '2.4.80',
date: new Date('2021-07-29'),
componentChanges: [
{
name: 'Dashboard',
changes: [
`Import Tags and Users with Sites + Auto activate Tags and Users' account`,
`Add Transaction endpoints to RESTfull public API`,
`Optimizaed Database performances on Charging Stations, Transactions, Users, Stats and Site Areas`,
`Display Web Socket protocol not provided in cumtomer's tenant`,
],
},
],
},
{
version: '2.4.79',
date: new Date('2021-07-26'),
Expand All @@ -40,7 +55,6 @@ export class ReleaseNotesComponent {
`Do not create a Transaction before checking Roaming Authorization`,
`Request OCPI Authorization Token also in OCPP Start Transaction in addition to OCPP Authorize`,
`Restrain OCPI Remote Authorization Token validity from 10 mins to 2 mins`

],
},
],
Expand Down
46 changes: 25 additions & 21 deletions src/app/services/central-server.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3038,12 +3038,11 @@ export class CentralServerService {
ampLimitValue,
forceUpdateChargingPlan,
},
{
headers: this.buildHttpHeaders(),
})
.pipe(
catchError(this.handleHttpError),
);
{
headers: this.buildHttpHeaders(),
}).pipe(
catchError(this.handleHttpError),
);
}

public chargingStationSetChargingProfile(charger: ChargingStation, connectorId: number, chargingProfile: any): Observable<ActionResponse> {
Expand Down Expand Up @@ -3201,20 +3200,35 @@ export class CentralServerService {
);
}

public buildHttpHeadersFile(tenantID?: string): { name: string; value: string }[] {
public buildImportTagsUsersHttpHeaders(
autoActivateUserAtImport?: string, autoActivateTagAtImport?: string): { name: string; value: string }[] {
// Build File Header
return [
{
name: 'Tenant',
value: tenantID
},
{
name: 'Authorization',
value: 'Bearer ' + this.getLoggedUserToken()
},
{
name: 'autoActivateUserAtImport',
value: autoActivateUserAtImport
},
{
name: 'autoActivateTagAtImport',
value: autoActivateTagAtImport
},
];
}

public buildRestEndpointUrl(urlPatternAsString: ServerRoute, params: {[name: string]: string | number | null } = {}) {
let resolvedUrlPattern = urlPatternAsString as string;
for (const key in params) {
if (Object.prototype.hasOwnProperty.call(params, key)) {
resolvedUrlPattern = resolvedUrlPattern.replace(`:${key}`, encodeURIComponent(params[key]));
}
}
return `${this.restServerSecuredURL}/${resolvedUrlPattern}`;
}

private getLoggedUserToken(): string {
// Get the token
if (!this.currentUserToken) {
Expand Down Expand Up @@ -3341,15 +3355,5 @@ export class CentralServerService {
}
return of(null);
}

private buildRestEndpointUrl(urlPatternAsString: ServerRoute, params: { [name: string]: string | number | null } = {}) {
let resolvedUrlPattern = urlPatternAsString as string;
for (const key in params) {
if (Object.prototype.hasOwnProperty.call(params, key)) {
resolvedUrlPattern = resolvedUrlPattern.replace(`:${key}`, encodeURIComponent(params[key]));
}
}
return `${this.restServerSecuredURL}/${resolvedUrlPattern}`;
}
}

10 changes: 10 additions & 0 deletions src/app/shared/dialogs/import/import-dialog.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ <h4 class="nav-tabs-title">{{title}}</h4>
</button>
<span class="pt-2">{{ fileName }}</span>
</div>
<div class="row pt-3">
<mat-checkbox (change)="handleAutoActivateUserAtImport($event.checked)" checked>
{{ "users.import_users_auto_activation" | translate }}
</mat-checkbox>
</div>
<div *ngIf="entity === 'tags'" class="row pt-3">
<mat-checkbox (change)="handleAutoActivateTagAtImport($event.checked)" checked>
{{ "tags.import_tags_auto_activation" | translate }}
</mat-checkbox>
</div>
<div class="row">
<mat-error *ngIf="!isFileValid">
<div class="pt-2" [translate]="'general.invalid_file_error'"></div>
Expand Down
32 changes: 26 additions & 6 deletions src/app/shared/dialogs/import/import-dialog.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Inject, OnInit } from '@angular/core';
import { Component, Inject, Input, OnInit } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { TranslateService } from '@ngx-translate/core';
import { StatusCodes } from 'http-status-codes';
Expand All @@ -9,7 +9,7 @@ import { DialogService } from 'services/dialog.service';
import { MessageService } from 'services/message.service';
import { ActionsResponse } from 'types/DataResult';
import { HTTPError } from 'types/HTTPError';
import { ServerAction } from 'types/Server';
import { ServerRoute } from 'types/Server';
import { ButtonType } from 'types/Table';
import { Utils } from 'utils/Utils';

Expand All @@ -26,8 +26,9 @@ export class ImportDialogComponent implements OnInit {
public importInstructionsOptionalFields: string;
public isFileValid = true;
public title: string;
public entity: string;
private ngxCsvParser: NgxCsvParser;
private endpoint: ServerAction;
private endpoint: ServerRoute;
private requiredProperties: string[];
private optionalProperties: string[];
private messageSuccess: string;
Expand All @@ -36,6 +37,9 @@ export class ImportDialogComponent implements OnInit {
private messageNoSuccessNoError: string;
private confirmImportTitle: string;
private confirmImportMessage: string;
private confirmImportMessageAutoActivate: string;
private autoActivateImportedUsers: string;
private autoActivateImportedTags: string;

public constructor(
protected dialogRef: MatDialogRef<ImportDialogComponent>,
Expand All @@ -46,6 +50,7 @@ export class ImportDialogComponent implements OnInit {
@Inject(MAT_DIALOG_DATA) data) {
if (data?.endpoint) {
this.endpoint = data.endpoint;
this.entity = data.entity;
this.title = translateService.instant(`${data.entity}.import_${data.entity}`);
this.messageSuccess = `${data.entity}.import_${data.entity}_success`;
this.messageError = `${data.entity}.import_${data.entity}_error`;
Expand All @@ -55,11 +60,12 @@ export class ImportDialogComponent implements OnInit {
this.optionalProperties = data.optionalProperties ?? [];
this.confirmImportTitle = `${data.entity}.import_${data.entity}`;
this.confirmImportMessage = `${data.entity}.import_${data.entity}_message`;
this.confirmImportMessageAutoActivate = `${data.entity}.import_${data.entity}_message_auto_activate`;
}
Utils.registerCloseKeyEvents(this.dialogRef);
this.uploader = new FileUploader({
headers: this.centralServerService.buildHttpHeadersFile(),
url: `${this.centralServerService.getCentralRestServerServiceSecuredURL()}/${this.endpoint}`
headers: this.centralServerService.buildImportTagsUsersHttpHeaders(this.autoActivateImportedUsers, this.autoActivateImportedTags),
url: `${this.centralServerService.buildRestEndpointUrl(this.endpoint)}`
});
this.uploader.response.subscribe(res => this.response = res);
this.ngxCsvParser = new NgxCsvParser();
Expand Down Expand Up @@ -120,11 +126,25 @@ export class ImportDialogComponent implements OnInit {
public upload(): void {
this.dialogService.createAndShowYesNoDialog(
this.translateService.instant(this.confirmImportTitle),
this.translateService.instant(this.confirmImportMessage),
this.autoActivateImportedUsers ? this.translateService.instant(this.confirmImportMessageAutoActivate) : this.translateService.instant(this.confirmImportMessage),
).subscribe((result) => {
if (result === ButtonType.YES) {
this.uploader.uploadAll();
}
});
}

public handleAutoActivateUserAtImport(checked) {
this.autoActivateImportedUsers = checked;
this.uploader.options.headers[this.uploader.options.headers.findIndex(
option => option.name === 'autoActivateUserAtImport'
)].value = this.autoActivateImportedUsers;
}

public handleAutoActivateTagAtImport(checked) {
this.autoActivateImportedTags = checked;
this.uploader.options.headers[this.uploader.options.headers.findIndex(
option => option.name === 'autoActivateTagAtImport'
)].value = this.autoActivateImportedTags;
}
}
4 changes: 2 additions & 2 deletions src/app/shared/table/actions/table-import-action.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentType } from '@angular/cdk/portal';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { ServerAction } from 'types/Server';
import { ServerRoute } from 'types/Server';

import { ButtonAction, PopupSize } from '../../../types/GlobalType';
import { ButtonColor, TableActionDef } from '../../../types/Table';
Expand All @@ -22,7 +22,7 @@ export class TableImportAction implements TableAction {
return this.action;
}

protected import(component: ComponentType<unknown>, dialog: MatDialog, endpoint: ServerAction,
protected import(component: ComponentType<unknown>, dialog: MatDialog, endpoint: ServerRoute,
entity: string,requiredProperties: string[], optionalProperties?: string[], size?: PopupSize) {
// Create the dialog
const dialogConfig = new MatDialogConfig();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentType } from '@angular/cdk/portal';
import { MatDialog } from '@angular/material/dialog';
import { ServerAction } from 'types/Server';
import { ServerAction, ServerRoute } from 'types/Server';
import { TagOptionalImportProperties, TagRequiredImportProperties } from 'types/Tag';

import { TableActionDef } from '../../../../types/Table';
Expand All @@ -21,6 +21,6 @@ export class TableImportTagsAction extends TableImportAction {
}

private importTags(tagDialogComponent: ComponentType<unknown>, dialog: MatDialog) {
super.import(tagDialogComponent, dialog, ServerAction.TAGS_IMPORT, 'tags', TagRequiredImportProperties, TagOptionalImportProperties);
super.import(tagDialogComponent, dialog, ServerRoute.REST_TAGS_IMPORT, 'tags', TagRequiredImportProperties, TagOptionalImportProperties);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ComponentType } from '@angular/cdk/portal';
import { MatDialog } from '@angular/material/dialog';
import { ServerAction } from 'types/Server';
import { ServerRoute } from 'types/Server';

import { TableActionDef } from '../../../../types/Table';
import { UserButtonAction, UserRequiredImportProperties } from '../../../../types/User';
import { UserButtonAction, UserOptionalImportProperties, UserRequiredImportProperties } from '../../../../types/User';
import { TableImportAction } from '../table-import-action';

export interface TableImportUsersActionDef extends TableActionDef {
Expand All @@ -20,6 +20,6 @@ export class TableImportUsersAction extends TableImportAction {
}

private importUsers(userDialogComponent: ComponentType<unknown>, dialog: MatDialog) {
super.import(userDialogComponent, dialog, ServerAction.USERS_IMPORT, 'users', UserRequiredImportProperties);
super.import(userDialogComponent, dialog, ServerRoute.REST_USERS_IMPORT, 'users', UserRequiredImportProperties, UserOptionalImportProperties);
}
}
1 change: 0 additions & 1 deletion src/app/types/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ export enum ServerRoute {
REST_TAG = 'tags/:id',
REST_TAGS_IMPORT = 'tags/action/import',
REST_TAGS_EXPORT = 'tags/action/export',

REST_ASSET_CONSUMPTION = 'assets/:assetID/consumption',

REST_PING = 'ping',
Expand Down
6 changes: 5 additions & 1 deletion src/app/types/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ export const TagRequiredImportProperties = [
'visualID'
];
export const TagOptionalImportProperties = [
'description'
'description',
'email',
'firstName',
'name',
'siteIDs'
];
4 changes: 4 additions & 0 deletions src/app/types/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,7 @@ export const UserRequiredImportProperties = [
'firstName',
'name'
];

export const UserOptionalImportProperties = [
'siteIDs'
];
2 changes: 1 addition & 1 deletion src/assets/configs-aws
6 changes: 5 additions & 1 deletion src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,8 @@
},
"import_users": "Nutzer Importieren",
"import_users_message": "Der Import wird alle hochgeladenen Nutzer die noch nicht importiert wurden verwerfen, möchten Sie fortfahren?",
"import_users_message_auto_activate": "The import will discard all other previously uploaded users not yet imported in the database and users will be automatically activated, do you want to continue?",
"import_users_auto_activation": "Automatically activate new users",
"import_users_success": "{{inSuccess}} Nutzer wurden erfolgreich hochgeladen und werden nun verarbeitet",
"import_users_partial": "{{inSuccess}} Nutzer wurden erfolgreich hochgeladen und werden nun verarbeitet und {{inError}} Nutzer sind fehlgeschlagen, bitte überprüfen Sie die Logs",
"import_users_error": "Das Hochladen von {{inError}} Nutzern ist fehlgeschlagen",
Expand Down Expand Up @@ -1379,10 +1381,12 @@
"delete_no_tag": "Es wurden keine Badges gelöscht",
"import_tags": "Badges Importieren",
"import_tags_message": "Der Import wird alle hochgeladenen Badges die noch nicht importiert wurden verwerfen, möchten Sie fortfahren?",
"import_tags_message_auto_activate": "The import will discard all other previously uploaded badges not yet imported in the database, do you want to continue?",
"import_tags_success": "{{inSuccess}} Badges wurden erfolgreich hochgeladen und werden nun verarbeitet",
"import_tags_partial": "{{inSuccess}} Badges wurden erfolgreich hochgeladen und werden nun verarbeitet und {{inError}} Badges sind fehlgeschlagen, bitte überprüfen Sie die Logs",
"import_tags_error": "Das Hochladen von {{inError}} Badges ist fehlgeschlagen",
"import_no_tags": "Es wurden keine Badges hochgeladen"
"import_no_tags": "Es wurden keine Badges hochgeladen",
"import_tags_auto_activation": "Automatically activate new tags"
},
"tenants": {
"title": "Organisation",
Expand Down
Loading

0 comments on commit d567219

Please sign in to comment.