Skip to content

Commit

Permalink
Merge pull request #3495 from sap-labs-france/master-labs
Browse files Browse the repository at this point in the history
Version 2.7.5 - hot fixes - ocpi endpoint UI
  • Loading branch information
Claude ROSSI authored Jan 10, 2023
2 parents dc8d653 + d2fd800 commit 72e9236
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
</div>
</div>
<div class="col-md-4 text-end">
<button mat-raised-button color="primary" *ngIf="currentEndpoint.canGenerateLocalToken" (click)="generateLocalToken(formGroup.value)">
<button mat-raised-button color="primary" *ngIf="canGenerateLocalToken" (click)="generateLocalToken(formGroup.value)">
<mat-icon>vpn_key</mat-icon>
<span>{{'ocpiendpoints.generate_new_token' | translate}}</span>
</button>
Expand All @@ -117,7 +117,7 @@
</div>
</div>
<div class="col-md-4 text-end">
<button mat-raised-button color="primary" *ngIf="currentEndpoint.canPing" (click)="testConnection(formGroup.value)"
<button mat-raised-button color="primary" *ngIf="canPing" (click)="testConnection(formGroup.value)"
[disabled]="!token.value || baseUrl.errors?.required || baseUrl.errors?.pattern">
<mat-icon>touch_app</mat-icon>
<span>{{'ocpiendpoints.test_connection' | translate}}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { MatDialogRef } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { StatusCodes } from 'http-status-codes';
import { DialogMode } from 'types/Authorization';
import { OCPIEndpoint } from 'types/ocpi/OCPIEndpoint';

import { CentralServerService } from '../../../../../services/central-server.service';
import { DialogService } from '../../../../../services/dialog.service';
import { MessageService } from '../../../../../services/message.service';
import { SpinnerService } from '../../../../../services/spinner.service';
import { DialogMode, OcpiEndpointsAuthorizations } from '../../../../../types/Authorization';
import { RestResponse } from '../../../../../types/GlobalType';
import { OCPIEndpoint } from '../../../../../types/ocpi/OCPIEndpoint';
import { Constants } from '../../../../../utils/Constants';
import { Utils } from '../../../../../utils/Utils';

Expand All @@ -24,6 +24,7 @@ export class SettingsOcpiEndpointComponent implements OnInit {
@Input() public currentEndpoint!: OCPIEndpoint;
@Input() public dialogRef!: MatDialogRef<any>;
@Input() public dialogMode!: DialogMode;
@Input() public authorizations!: OcpiEndpointsAuthorizations;

public formGroup!: FormGroup;
public id!: AbstractControl;
Expand All @@ -37,7 +38,8 @@ export class SettingsOcpiEndpointComponent implements OnInit {
public token!: AbstractControl;
public isBackgroundPatchJobActive!: AbstractControl;
public readOnly = true;

public canGenerateLocalToken: boolean;
public canPing: boolean;

// eslint-disable-next-line no-useless-constructor
public constructor(
Expand Down Expand Up @@ -97,6 +99,8 @@ export class SettingsOcpiEndpointComponent implements OnInit {
this.localToken = this.formGroup.controls['localToken'];
this.token = this.formGroup.controls['token'];
this.isBackgroundPatchJobActive = this.formGroup.controls['backgroundPatchJob'];
this.canGenerateLocalToken = Utils.convertToBoolean(this.authorizations.canGenerateLocalToken);
this.canPing = Utils.convertToBoolean(this.authorizations.canPing);
// Handle Dialog mode
this.readOnly = this.dialogMode === DialogMode.VIEW;
Utils.handleDialogMode(this.dialogMode, this.formGroup);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { AfterViewInit, Component, Inject, ViewChild } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { DialogMode, DialogParams } from 'types/Authorization';

import { DialogMode, DialogParamsWithAuth, OcpiEndpointsAuthorizations } from '../../../../../types/Authorization';
import { OCPIEndpoint } from '../../../../../types/ocpi/OCPIEndpoint';
import { Utils } from '../../../../../utils/Utils';
import { SettingsOcpiEndpointComponent } from './settings-ocpi-endpoint.component';

@Component({
template: '<app-ocpi-endpoint #appRef [currentEndpoint]="currentEndpoint" [dialogMode]="dialogMode" [dialogRef]="dialogRef"></app-ocpi-endpoint>',
template: '<app-ocpi-endpoint #appRef [currentEndpoint]="currentEndpoint" [dialogMode]="dialogMode" [dialogRef]="dialogRef" [authorizations]="authorizations"></app-ocpi-endpoint>',
})
export class SettingsOcpiEndpointDialogComponent implements AfterViewInit {
@ViewChild('appRef') public appRef!: SettingsOcpiEndpointComponent;
public currentEndpoint!: OCPIEndpoint;
public dialogMode!: DialogMode;

public authorizations!: OcpiEndpointsAuthorizations;

public constructor(
public dialogRef: MatDialogRef<SettingsOcpiEndpointDialogComponent>,
@Inject(MAT_DIALOG_DATA) dialogParams: DialogParams<OCPIEndpoint>) {
@Inject(MAT_DIALOG_DATA) dialogParams: DialogParamsWithAuth<OCPIEndpoint, OcpiEndpointsAuthorizations>) {
this.currentEndpoint = dialogParams.dialogData;
this.dialogMode = dialogParams.dialogMode;
this.authorizations = dialogParams.authorizations;
}

public ngAfterViewInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export class SettingsOcpiEndpointsTableDataSource extends TableDataSource<OCPIEn
next: (ocpiEndpoints) => {
// Init auth
this.authorizations = {
canCreate: Utils.convertToBoolean(ocpiEndpoints.canCreate)
canCreate: Utils.convertToBoolean(ocpiEndpoints.canCreate),
canGenerateLocalToken: Utils.convertToBoolean(ocpiEndpoints.canGenerateLocalToken),
canPing: Utils.convertToBoolean(ocpiEndpoints.canPing),
};
// Set visibility
this.createAction.visible = this.authorizations.canCreate;
Expand Down Expand Up @@ -241,7 +243,10 @@ export class SettingsOcpiEndpointsTableDataSource extends TableDataSource<OCPIEn
const dialogConfig = new MatDialogConfig();
dialogConfig.minWidth = '50vw';
dialogConfig.panelClass = 'transparent-dialog-container';
dialogConfig.data = { dialogData: endpoint, dialogMode };
dialogConfig.data = {
dialogData: endpoint,
dialogMode,
authorizations: this.authorizations };
// disable outside click close
dialogConfig.disableClose = true;
// Open
Expand Down
2 changes: 2 additions & 0 deletions src/app/types/Authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ export interface OcpiEndpointsAuthorizations extends AuthorizationAttributes, Oc
}

export interface OcpiEndpointsAuthorizationActions extends DataResultAuthorizationActions {
canPing?: boolean;
canGenerateLocalToken?: boolean;
}

export interface OcpiEndpointAuthorizationActions extends AuthorizationActions {
Expand Down

0 comments on commit 72e9236

Please sign in to comment.