-
-
-
- {{ "cars.car_connector_name" | translate }}
-
-
- {{carConnectorConnection.name}}
-
-
-
-
-
-
-
-
+
diff --git a/src/app/pages/cars/car/car.component.ts b/src/app/pages/cars/car/car.component.ts
index c3861252c1..f388e20e0f 100644
--- a/src/app/pages/cars/car/car.component.ts
+++ b/src/app/pages/cars/car/car.component.ts
@@ -1,70 +1,44 @@
-import { Component, Input, OnInit } from '@angular/core';
-import { AbstractControl, FormControl, FormGroup, Validators } from '@angular/forms';
-import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog';
-import { MatSelectChange } from '@angular/material/select';
-import { MatTabChangeEvent } from '@angular/material/tabs';
-import { Router } from '@angular/router';
+import { Component, Input, OnInit, ViewChild } from '@angular/core';
+import { FormGroup } from '@angular/forms';
+import { MatDialogRef } from '@angular/material/dialog';
+import { ActivatedRoute, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { ComponentService } from 'services/component.service';
-import { UsersDialogComponent } from 'shared/dialogs/users/users-dialog.component';
+import { WindowService } from 'services/window.service';
+import { AbstractTabComponent } from 'shared/component/abstract-tab/abstract-tab.component';
import { CarsAuthorizations, DialogMode } from 'types/Authorization';
-import { CarConnectorConnectionSetting } from 'types/Setting';
import { TenantComponents } from 'types/Tenant';
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 { CarCatalogsDialogComponent } from '../../../shared/dialogs/car-catalogs/car-catalogs-dialog.component';
-import { Car, CarCatalog, CarConverter, CarConverterType, CarType } from '../../../types/Car';
+import { Car } from '../../../types/Car';
import { ActionResponse } from '../../../types/DataResult';
-import { KeyValue, RestResponse } from '../../../types/GlobalType';
+import { RestResponse } from '../../../types/GlobalType';
import { HTTPError } from '../../../types/HTTPError';
-import { User } from '../../../types/User';
-import { Cars } from '../../../utils/Cars';
-import { Constants } from '../../../utils/Constants';
import { Utils } from '../../../utils/Utils';
+import { CarConnectorComponent } from './connector/car-connector.component';
+import { CarMainComponent } from './main/car-main.component';
@Component({
selector: 'app-car',
templateUrl: 'car.component.html',
})
-export class CarComponent implements OnInit {
+export class CarComponent extends AbstractTabComponent implements OnInit {
@Input() public currentCarID!: string;
@Input() public dialogMode!: DialogMode;
@Input() public dialogRef!: MatDialogRef
;
@Input() public carsAuthorizations!: CarsAuthorizations;
- public carCatalogImage: string;
- public selectedCarCatalog: CarCatalog;
- public carCatalogConverters: { type: CarConverterType; value: string; converter: CarConverter }[] = [];
- public canListUsers: boolean;
- public isCarConnectorComponentActive: boolean;
- public readOnly = true;
- public formGroup!: FormGroup;
- public id!: AbstractControl;
- public vin!: AbstractControl;
- public licensePlate!: AbstractControl;
- public isCompanyCar!: AbstractControl;
- public carCatalogID!: AbstractControl;
- public carCatalog!: AbstractControl;
- public converterType!: AbstractControl;
- public converter!: AbstractControl;
- public isDefault!: AbstractControl;
- public type!: AbstractControl;
- public noImage = Constants.NO_IMAGE;
- public user!: AbstractControl;
- public userID!: AbstractControl;
- public carTypes: KeyValue[] = [
- { key: CarType.COMPANY, value: 'cars.company_car' },
- { key: CarType.PRIVATE, value: 'cars.private_car' }
- ];
- public carConnectorName!: AbstractControl;
- public carConnectorID!: AbstractControl;
- public carConnectorMeterID!: AbstractControl;
- public carConnectorConnections!: CarConnectorConnectionSetting[];
+ @ViewChild('carMainComponent') public carMainComponent!: CarMainComponent;
+ @ViewChild('carConnectorComponent') public carConnectorComponent!: CarConnectorComponent;
- private car: Car;
+ public formGroup!: FormGroup;
+ public isCarConnectorComponentActive: boolean;
+ public canListUsers: boolean;
+ public readOnly = true;
+ public car: Car;
public constructor(
public spinnerService: SpinnerService,
@@ -73,101 +47,27 @@ export class CarComponent implements OnInit {
private translateService: TranslateService,
private dialogService: DialogService,
private router: Router,
- private dialog: MatDialog,
- private componentService: ComponentService ) {
+ private componentService: ComponentService,
+ protected activatedRoute: ActivatedRoute,
+ protected windowService: WindowService) {
+ super(activatedRoute, windowService, ['main', 'connector'], false);
this.isCarConnectorComponentActive = this.componentService.isActive(TenantComponents.CAR_CONNECTOR);
}
public ngOnInit() {
- this.carConnectorName = new FormControl('');
// Init the form
- this.formGroup = new FormGroup({
- id: new FormControl(''),
- vin: new FormControl('',
- Validators.compose([
- Validators.required,
- Cars.validateVIN
- ])),
- licensePlate: new FormControl('',
- Validators.compose([
- Validators.pattern('^[A-Z0-9- ]*$'),
- ])),
- carCatalog: new FormControl('',
- Validators.compose([
- Validators.required,
- ])),
- carCatalogID: new FormControl('',
- Validators.compose([
- Validators.required,
- ])),
- converterType: new FormControl('',
- Validators.compose([
- Validators.required,
- ])),
- converter: new FormControl('',
- Validators.compose([
- Validators.required,
- ])),
- user: new FormControl('',
- Validators.compose([
- ])),
- userID: new FormControl('',
- Validators.compose([
- ])),
- isDefault: new FormControl(''),
- type: new FormControl(CarType.COMPANY,
- Validators.compose([
- Validators.required,
- ])),
- });
- if(this.isCarConnectorComponentActive){
- this.formGroup.addControl(
- 'carConnectorData', new FormGroup({
- carConnectorID: new FormControl('',
- Validators.compose([
- ])),
- carConnectorMeterID: new FormControl('',
- Validators.compose([
- ])),
- }));
- }
- // Form
- this.id = this.formGroup.controls['id'];
- this.vin = this.formGroup.controls['vin'];
- this.licensePlate = this.formGroup.controls['licensePlate'];
- this.carCatalogID = this.formGroup.controls['carCatalogID'];
- this.carCatalog = this.formGroup.controls['carCatalog'];
- this.user = this.formGroup.controls['user'];
- this.userID = this.formGroup.controls['userID'];
- this.isDefault = this.formGroup.controls['isDefault'];
- this.converterType = this.formGroup.controls['converterType'];
- this.converter = this.formGroup.controls['converter'];
- this.type = this.formGroup.controls['type'];
- this.carConnectorID = this.formGroup.get('carConnectorData.carConnectorID');
- this.carConnectorMeterID = this.formGroup.get('carConnectorData.carConnectorMeterID');
- // Default
- this.converterType.disable();
- // Initialize authorization actions
- this.canListUsers = Utils.convertToBoolean(this.carsAuthorizations.canListUsers);
- // Car pool selection handled by cars metadata
- if(this.carsAuthorizations.metadata?.createPoolCar?.visible) {
- this.carTypes.push({ key: CarType.POOL_CAR, value: 'cars.pool_car' });
- }
+ this.formGroup = new FormGroup({});
// Handle Dialog mode
- this.readOnly = (this.dialogMode === DialogMode.VIEW);
+ this.readOnly = this.dialogMode === DialogMode.VIEW;
+ this.canListUsers = Utils.convertToBoolean(this.carsAuthorizations.canListUsers);
Utils.handleDialogMode(this.dialogMode, this.formGroup);
// Load Car
this.loadCar();
}
public onClose() {
- this.closeDialog();
- }
-
- public converterChanged(event: MatSelectChange) {
- this.converter.setValue(
- this.carCatalogConverters.find((converter) => converter.type === event.value).converter
- );
+ Utils.checkAndSaveAndCloseDialog(this.formGroup, this.dialogService,
+ this.translateService, this.saveCar.bind(this), this.closeDialog.bind(this));
}
public loadCar() {
@@ -176,32 +76,14 @@ export class CarComponent implements OnInit {
this.centralServerService.getCar(this.currentCarID).subscribe((car: Car) => {
this.spinnerService.hide();
this.car = car;
- // Init form
- this.id.setValue(car.id);
- this.carCatalogID.setValue(car.carCatalogID);
- this.selectedCarCatalog = car.carCatalog;
- this.buildCarCatalogConverter();
- this.vin.setValue(car.vin);
- this.licensePlate.setValue(car.licensePlate);
- this.type.setValue(car.type);
- this.converter.setValue(car.converter);
- this.converterType.setValue(car.converter.type);
- this.carCatalog.setValue(Utils.buildCarCatalogName(car.carCatalog));
- this.carCatalogImage = car.carCatalog.image;
- this.isDefault.setValue(car.default);
- this.userID.setValue(car.userID);
- if (car.user) {
- this.user.setValue(Utils.buildUserFullName(car.user));
- }
if (this.readOnly) {
// Async call for letting the sub form groups to init
setTimeout(() => this.formGroup.disable(), 0);
}
+ // Update form group
this.formGroup.updateValueAndValidity();
this.formGroup.markAsPristine();
this.formGroup.markAllAsTouched();
- // Update auhorization actions
- this.canListUsers = Utils.convertToBoolean(car.canListUsers);
}, (error) => {
this.spinnerService.hide();
switch (error.status) {
@@ -216,50 +98,6 @@ export class CarComponent implements OnInit {
}
}
- public clearUser() {
- this.car.user = null;
- this.car.userID = null;
- this.user.setValue(null);
- this.userID.setValue(null);
- this.formGroup.markAsDirty();
- }
-
- public clearCarConnectorMeterID() {
- this.car.carConnectorData.carConnectorMeterID = null;
- this.carConnectorMeterID.setValue(null);
- this.formGroup.markAsDirty();
- }
-
- public clearCarConnectorID() {
- this.car.carConnectorData.carConnectorID = null;
- this.carConnectorID.setValue(null);
- this.car.carConnectorData.carConnectorMeterID = null;
- this.carConnectorMeterID.setValue(null);
- this.carConnectorMeterID.disable();
- this.formGroup.markAsDirty();
- }
-
- public assignUser() {
- // Create the dialog
- const dialogConfig = new MatDialogConfig();
- dialogConfig.panelClass = 'transparent-dialog-container';
- dialogConfig.data = {
- title: 'cars.assign_user',
- validateButtonTitle: 'general.select',
- sitesAdminOnly: true,
- rowMultipleSelection: false,
- };
- // Open
- this.dialog.open(UsersDialogComponent, dialogConfig).afterClosed().subscribe((result) => {
- if (!Utils.isEmptyArray(result) && result[0].objectRef) {
- const user = ((result[0].objectRef) as User);
- this.user.setValue(Utils.buildUserFullName(user));
- this.userID.setValue(user.id);
- this.formGroup.markAsDirty();
- }
- });
- }
-
public closeDialog(saved: boolean = false) {
if (this.dialogRef) {
this.dialogRef.close(saved);
@@ -279,51 +117,13 @@ export class CarComponent implements OnInit {
}
}
- public changeCarCatalog() {
- // Create the dialog
- const dialogConfig = new MatDialogConfig();
- dialogConfig.panelClass = 'transparent-dialog-container';
- dialogConfig.data = {
- title: 'cars.assign_car_catalog',
- validateButtonTitle: 'general.select',
- rowMultipleSelection: false,
- };
- // Open
- this.dialog.open(CarCatalogsDialogComponent, dialogConfig).afterClosed().subscribe((result) => {
- if (!Utils.isEmptyArray(result) && result[0].objectRef) {
- const carCatalog: CarCatalog = (result[0].objectRef) as CarCatalog;
- this.carCatalogID.setValue(result[0].key);
- this.carCatalog.setValue(Utils.buildCarCatalogName(carCatalog));
- this.selectedCarCatalog = carCatalog;
- this.carCatalogImage = carCatalog.image;
- // Build drop down
- this.buildCarCatalogConverter();
- this.formGroup.markAsDirty();
- }
- });
- }
-
- public carConnectorChanged(event: MatSelectChange) {
- this.carConnectorID.setValue(event.value);
- if(this.carConnectorID){
- this.carConnectorMeterID.enable();
- } else {
- this.carConnectorMeterID.disable();
- }
- }
-
- public onTabChanged(event: MatTabChangeEvent) {
- if(event.index === 1 && Utils.isNullOrUndefined(this.carConnectorConnections)) {
- this.loadCarConnectors();
- }
- }
-
private updateCar(car: Car) {
this.spinnerService.show();
this.centralServerService.updateCar(car).subscribe((response: ActionResponse) => {
this.spinnerService.hide();
if (response.status === RestResponse.SUCCESS) {
- this.messageService.showSuccessMessage('cars.update_success', { carName: Utils.buildCarCatalogName(this.selectedCarCatalog) });
+ this.messageService.showSuccessMessage('cars.update_success', {
+ carName: this.formGroup.controls['carCatalog'].value });
this.closeDialog(true);
} else {
Utils.handleError(JSON.stringify(response), this.messageService, 'cars.update_error');
@@ -353,7 +153,8 @@ export class CarComponent implements OnInit {
this.centralServerService.createCar(car, forced).subscribe((response: ActionResponse) => {
this.spinnerService.hide();
if (response.status === RestResponse.SUCCESS) {
- this.messageService.showSuccessMessage('cars.create_success', { carName: Utils.buildCarCatalogName(this.selectedCarCatalog) });
+ this.messageService.showSuccessMessage('cars.create_success', {
+ carName: this.formGroup.controls['carCatalog'].value });
this.closeDialog(true);
} else {
Utils.handleError(JSON.stringify(response), this.messageService, 'cars.create_error');
@@ -375,79 +176,4 @@ export class CarComponent implements OnInit {
}
});
}
-
- private buildCarCatalogConverter() {
- const standardConverter: CarConverter = {
- type: CarConverterType.STANDARD,
- powerWatts: this.selectedCarCatalog.chargeStandardPower,
- amperagePerPhase: this.selectedCarCatalog.chargeStandardPhaseAmp,
- numberOfPhases: this.selectedCarCatalog.chargeStandardPhase,
- };
- const alternativeConverter: CarConverter = {
- type: CarConverterType.ALTERNATIVE,
- powerWatts: this.selectedCarCatalog.chargeAlternativePower,
- amperagePerPhase: this.selectedCarCatalog.chargeAlternativePhaseAmp,
- numberOfPhases: this.selectedCarCatalog.chargeAlternativePhase,
- };
- const optionalConverter: CarConverter = {
- type: CarConverterType.OPTION,
- powerWatts: this.selectedCarCatalog.chargeOptionPower,
- amperagePerPhase: this.selectedCarCatalog.chargeOptionPhaseAmp,
- numberOfPhases: this.selectedCarCatalog.chargeOptionPhase,
- };
- this.carCatalogConverters = [{
- type: CarConverterType.STANDARD,
- value: Utils.buildCarCatalogConverterName(standardConverter, this.translateService),
- converter: standardConverter,
- }];
- if (this.selectedCarCatalog.chargeAlternativePower) {
- this.carCatalogConverters.push({
- type: CarConverterType.ALTERNATIVE,
- value: Utils.buildCarCatalogConverterName(alternativeConverter, this.translateService),
- converter: alternativeConverter,
- });
- }
- if (this.selectedCarCatalog.chargeOptionPower > 0 &&
- this.selectedCarCatalog.chargeOptionPower !== this.selectedCarCatalog.chargeAlternativePower) {
- this.carCatalogConverters.push({
- type: CarConverterType.OPTION,
- value: Utils.buildCarCatalogConverterName(optionalConverter, this.translateService),
- converter: optionalConverter,
- });
- }
- // Set default
- if (this.carCatalogConverters.length === 1) {
- this.converterType.setValue(this.carCatalogConverters[0].type);
- this.converter.setValue(this.carCatalogConverters[0].converter);
- } else {
- this.converterType.setValue('');
- }
- this.converterType.enable();
- }
-
- private loadCarConnectors(){
- this.componentService.getCarConnectorSettings().subscribe((settings) => {
- // Keep
- this.carConnectorConnections = settings.carConnector.connections;
- const carConnectorID = this.carConnectorConnections.find((carConnectorConnection) =>
- carConnectorConnection.id === this.car.carConnectorData?.carConnectorID)?.id;
- // Set
- if(!Utils.isNullOrUndefined(carConnectorID)){
- this.carConnectorID.setValue(carConnectorID);
- this.carConnectorMeterID.setValue(this.car.carConnectorData?.carConnectorMeterID);
- } else {
- this.carConnectorMeterID.disable();
- }
- this.formGroup.markAsPristine();
- }, (error) => {
- switch (error.status) {
- case HTTPError.OBJECT_DOES_NOT_EXIST_ERROR:
- this.messageService.showErrorMessage('settings.car_connector.setting_not_found');
- break;
- default:
- Utils.handleHttpError(error, this.router, this.messageService,
- this.centralServerService, 'general.unexpected_error_backend');
- }
- });
- }
}
diff --git a/src/app/pages/cars/car/connector/car-connector.component.html b/src/app/pages/cars/car/connector/car-connector.component.html
new file mode 100644
index 0000000000..a289d94dce
--- /dev/null
+++ b/src/app/pages/cars/car/connector/car-connector.component.html
@@ -0,0 +1,27 @@
+
diff --git a/src/app/pages/cars/car/connector/car-connector.component.ts b/src/app/pages/cars/car/connector/car-connector.component.ts
new file mode 100644
index 0000000000..2253fe78b4
--- /dev/null
+++ b/src/app/pages/cars/car/connector/car-connector.component.ts
@@ -0,0 +1,113 @@
+import { Component, Input, OnChanges, OnInit } from '@angular/core';
+import { AbstractControl, FormControl, FormGroup, Validators } from '@angular/forms';
+import { MatSelectChange } from '@angular/material/select';
+import { Router } from '@angular/router';
+import { ComponentService } from 'services/component.service';
+import { CarsAuthorizations } from 'types/Authorization';
+import { CarConnectorConnectionSetting } from 'types/Setting';
+
+import { CentralServerService } from '../../../../services/central-server.service';
+import { MessageService } from '../../../../services/message.service';
+import { SpinnerService } from '../../../../services/spinner.service';
+import { Car } from '../../../../types/Car';
+import { HTTPError } from '../../../../types/HTTPError';
+import { Utils } from '../../../../utils/Utils';
+
+@Component({
+ selector: 'app-car-connector',
+ templateUrl: 'car-connector.component.html',
+})
+export class CarConnectorComponent implements OnInit, OnChanges {
+ @Input() public formGroup: FormGroup;
+ @Input() public car!: Car;
+ @Input() public readOnly: boolean;
+ @Input() public carsAuthorizations!: CarsAuthorizations;
+
+ public carConnectorName!: AbstractControl;
+ public carConnectorID!: AbstractControl;
+ public carConnectorMeterID!: AbstractControl;
+ public carConnectorConnections!: CarConnectorConnectionSetting[];
+
+ // eslint-disable-next-line no-useless-constructor
+ public constructor(
+ public spinnerService: SpinnerService,
+ private centralServerService: CentralServerService,
+ private messageService: MessageService,
+ private router: Router,
+ private componentService: ComponentService ) {
+ }
+
+ public ngOnInit() {
+ this.formGroup.addControl(
+ 'carConnectorData', new FormGroup({
+ carConnectorID: new FormControl('',
+ Validators.compose([
+ ])),
+ carConnectorMeterID: new FormControl('',
+ Validators.compose([
+ ])),
+ }));
+ this.carConnectorID = this.formGroup.get('carConnectorData.carConnectorID');
+ this.carConnectorMeterID = this.formGroup.get('carConnectorData.carConnectorMeterID');
+ // Load available connectors
+ this.loadCarConnectors();
+ }
+
+ public ngOnChanges() {
+ this.loadCar();
+ }
+
+ public loadCar() {
+ if (this.car && this.carConnectorConnections) {
+ const foundCarConnectorConnection = this.carConnectorConnections.find((carConnectorConnection) =>
+ carConnectorConnection.id === this.car.carConnectorData?.carConnectorID);
+ // Set
+ if(!Utils.isNullOrUndefined(foundCarConnectorConnection?.id)){
+ this.carConnectorID.setValue(foundCarConnectorConnection.id);
+ this.carConnectorMeterID.setValue(this.car.carConnectorData?.carConnectorMeterID);
+ } else {
+ this.carConnectorMeterID.disable();
+ }
+ }
+ }
+
+ public clearCarConnectorMeterID() {
+ this.car.carConnectorData.carConnectorMeterID = null;
+ this.carConnectorMeterID.setValue(null);
+ this.formGroup.markAsDirty();
+ }
+
+ public clearCarConnectorID() {
+ this.car.carConnectorData.carConnectorID = null;
+ this.carConnectorID.setValue(null);
+ this.car.carConnectorData.carConnectorMeterID = null;
+ this.carConnectorMeterID.setValue(null);
+ this.carConnectorMeterID.disable();
+ this.formGroup.markAsDirty();
+ }
+
+ public carConnectorChanged(event: MatSelectChange) {
+ this.carConnectorID.setValue(event.value);
+ if(this.carConnectorID){
+ this.carConnectorMeterID.enable();
+ } else {
+ this.carConnectorMeterID.disable();
+ }
+ }
+
+ private loadCarConnectors() {
+ this.componentService.getCarConnectorSettings().subscribe((settings) => {
+ this.carConnectorConnections = settings.carConnector.connections;
+ this.loadCar();
+ }, (error) => {
+ switch (error.status) {
+ case HTTPError.OBJECT_DOES_NOT_EXIST_ERROR:
+ this.messageService.showErrorMessage('settings.car_connector.setting_not_found');
+ break;
+ default:
+ Utils.handleHttpError(error, this.router, this.messageService,
+ this.centralServerService, 'general.unexpected_error_backend');
+ }
+ });
+ }
+}
diff --git a/src/app/pages/cars/car/main/car-main.component.html b/src/app/pages/cars/car/main/car-main.component.html
new file mode 100644
index 0000000000..2faca0b84b
--- /dev/null
+++ b/src/app/pages/cars/car/main/car-main.component.html
@@ -0,0 +1,86 @@
+
diff --git a/src/app/pages/cars/car/main/car-main.component.ts b/src/app/pages/cars/car/main/car-main.component.ts
new file mode 100644
index 0000000000..ed503000c7
--- /dev/null
+++ b/src/app/pages/cars/car/main/car-main.component.ts
@@ -0,0 +1,248 @@
+import { Component, Input, OnChanges, OnInit } from '@angular/core';
+import { AbstractControl, FormControl, FormGroup, Validators } from '@angular/forms';
+import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
+import { MatSelectChange } from '@angular/material/select';
+import { TranslateService } from '@ngx-translate/core';
+import { UsersDialogComponent } from 'shared/dialogs/users/users-dialog.component';
+import { CarsAuthorizations } from 'types/Authorization';
+
+import { SpinnerService } from '../../../../services/spinner.service';
+import { CarCatalogsDialogComponent } from '../../../../shared/dialogs/car-catalogs/car-catalogs-dialog.component';
+import { Car, CarCatalog, CarConverter, CarConverterType, CarType } from '../../../../types/Car';
+import { KeyValue } from '../../../../types/GlobalType';
+import { User } from '../../../../types/User';
+import { Cars } from '../../../../utils/Cars';
+import { Constants } from '../../../../utils/Constants';
+import { Utils } from '../../../../utils/Utils';
+
+@Component({
+ selector: 'app-car-main',
+ templateUrl: 'car-main.component.html',
+})
+export class CarMainComponent implements OnInit, OnChanges {
+ @Input() public formGroup: FormGroup;
+ @Input() public car!: Car;
+ @Input() public readOnly: boolean;
+ @Input() public carsAuthorizations!: CarsAuthorizations;
+
+ public carCatalogImage: string;
+ public selectedCarCatalog: CarCatalog;
+ public carCatalogConverters: { type: CarConverterType; value: string; converter: CarConverter }[] = [];
+ public canListUsers: boolean;
+ public isCarConnectorComponentActive: boolean;
+
+ public id!: AbstractControl;
+ public vin!: AbstractControl;
+ public licensePlate!: AbstractControl;
+ public isCompanyCar!: AbstractControl;
+ public carCatalogID!: AbstractControl;
+ public carCatalog!: AbstractControl;
+ public converterType!: AbstractControl;
+ public converter!: AbstractControl;
+ public isDefault!: AbstractControl;
+ public type!: AbstractControl;
+ public noImage = Constants.NO_IMAGE;
+ public user!: AbstractControl;
+ public userID!: AbstractControl;
+ public carTypes: KeyValue[] = [
+ { key: CarType.COMPANY, value: 'cars.company_car' },
+ { key: CarType.PRIVATE, value: 'cars.private_car' }
+ ];
+
+ // eslint-disable-next-line no-useless-constructor
+ public constructor(
+ public spinnerService: SpinnerService,
+ private translateService: TranslateService,
+ private dialog: MatDialog) {
+ }
+
+ public ngOnInit() {
+ this.formGroup.addControl('id', new FormControl(''));
+ this.formGroup.addControl('vin', new FormControl('',
+ Validators.compose([
+ Validators.required,
+ Cars.validateVIN
+ ])));
+ this.formGroup.addControl('licensePlate', new FormControl('',
+ Validators.compose([
+ Validators.pattern('^[A-Z0-9- ]*$'),
+ ])));
+ this.formGroup.addControl('carCatalog', new FormControl('',
+ Validators.compose([
+ Validators.required,
+ ])));
+ this.formGroup.addControl('carCatalogID', new FormControl('',
+ Validators.compose([
+ Validators.required,
+ ])));
+ this.formGroup.addControl('converterType', new FormControl('',
+ Validators.compose([
+ Validators.required,
+ ])));
+ this.formGroup.addControl('converter', new FormControl('',
+ Validators.compose([
+ Validators.required,
+ ])));
+ this.formGroup.addControl('user', new FormControl(''));
+ this.formGroup.addControl('userID', new FormControl(''));
+ this.formGroup.addControl('isDefault', new FormControl(''));
+ this.formGroup.addControl('type', new FormControl(CarType.COMPANY,
+ Validators.compose([
+ Validators.required,
+ ])));
+ // Form
+ this.id = this.formGroup.controls['id'];
+ this.vin = this.formGroup.controls['vin'];
+ this.licensePlate = this.formGroup.controls['licensePlate'];
+ this.carCatalogID = this.formGroup.controls['carCatalogID'];
+ this.carCatalog = this.formGroup.controls['carCatalog'];
+ this.user = this.formGroup.controls['user'];
+ this.userID = this.formGroup.controls['userID'];
+ this.isDefault = this.formGroup.controls['isDefault'];
+ this.converterType = this.formGroup.controls['converterType'];
+ this.converter = this.formGroup.controls['converter'];
+ this.type = this.formGroup.controls['type'];
+ // Default
+ this.converterType.disable();
+ // Car pool selection handled by cars metadata
+ if(this.carsAuthorizations.metadata?.createPoolCar?.visible) {
+ this.carTypes.push({ key: CarType.POOL_CAR, value: 'cars.pool_car' });
+ }
+ }
+
+ public ngOnChanges() {
+ this.loadCar();
+ }
+
+ public loadCar() {
+ if (this.car) {
+ this.id.setValue(this.car.id);
+ this.carCatalogID.setValue(this.car.carCatalogID);
+ this.selectedCarCatalog = this.car.carCatalog;
+ this.buildCarCatalogConverter();
+ this.vin.setValue(this.car.vin);
+ this.licensePlate.setValue(this.car.licensePlate);
+ this.type.setValue(this.car.type);
+ this.converter.setValue(this.car.converter);
+ this.converterType.setValue(this.car.converter.type);
+ this.carCatalog.setValue(Utils.buildCarCatalogName(this.car.carCatalog));
+ this.carCatalogImage = this.car.carCatalog.image;
+ this.isDefault.setValue(this.car.default);
+ this.userID.setValue(this.car.userID);
+ if (this.car.user) {
+ this.user.setValue(Utils.buildUserFullName(this.car.user));
+ }
+ this.canListUsers = Utils.convertToBoolean(this.car.canListUsers);
+ }
+ }
+
+ public converterChanged(event: MatSelectChange) {
+ this.converter.setValue(
+ this.carCatalogConverters.find((converter) => converter.type === event.value).converter
+ );
+ }
+
+ public clearUser() {
+ this.car.user = null;
+ this.car.userID = null;
+ this.user.setValue(null);
+ this.userID.setValue(null);
+ this.formGroup.markAsDirty();
+ }
+
+ public assignUser() {
+ // Create the dialog
+ const dialogConfig = new MatDialogConfig();
+ dialogConfig.panelClass = 'transparent-dialog-container';
+ dialogConfig.data = {
+ title: 'cars.assign_user',
+ validateButtonTitle: 'general.select',
+ sitesAdminOnly: true,
+ rowMultipleSelection: false,
+ };
+ // Open
+ this.dialog.open(UsersDialogComponent, dialogConfig).afterClosed().subscribe((result) => {
+ if (!Utils.isEmptyArray(result) && result[0].objectRef) {
+ const user = ((result[0].objectRef) as User);
+ this.user.setValue(Utils.buildUserFullName(user));
+ this.userID.setValue(user.id);
+ this.formGroup.markAsDirty();
+ }
+ });
+ }
+
+ public changeCarCatalog() {
+ // Create the dialog
+ const dialogConfig = new MatDialogConfig();
+ dialogConfig.panelClass = 'transparent-dialog-container';
+ dialogConfig.data = {
+ title: 'cars.assign_car_catalog',
+ validateButtonTitle: 'general.select',
+ rowMultipleSelection: false,
+ };
+ // Open
+ this.dialog.open(CarCatalogsDialogComponent, dialogConfig).afterClosed().subscribe((result) => {
+ if (!Utils.isEmptyArray(result) && result[0].objectRef) {
+ const carCatalog: CarCatalog = (result[0].objectRef) as CarCatalog;
+ this.carCatalogID.setValue(result[0].key);
+ this.carCatalog.setValue(Utils.buildCarCatalogName(carCatalog));
+ this.selectedCarCatalog = carCatalog;
+ this.carCatalogImage = carCatalog.image;
+ // Build drop down
+ this.buildCarCatalogConverter();
+ this.formGroup.markAsDirty();
+ }
+ });
+ }
+
+ private buildCarCatalogConverter() {
+ console.log(this.selectedCarCatalog);
+
+ const standardConverter: CarConverter = {
+ type: CarConverterType.STANDARD,
+ powerWatts: this.selectedCarCatalog.chargeStandardPower,
+ amperagePerPhase: this.selectedCarCatalog.chargeStandardPhaseAmp,
+ numberOfPhases: this.selectedCarCatalog.chargeStandardPhase,
+ };
+ const alternativeConverter: CarConverter = {
+ type: CarConverterType.ALTERNATIVE,
+ powerWatts: this.selectedCarCatalog.chargeAlternativePower,
+ amperagePerPhase: this.selectedCarCatalog.chargeAlternativePhaseAmp,
+ numberOfPhases: this.selectedCarCatalog.chargeAlternativePhase,
+ };
+ const optionalConverter: CarConverter = {
+ type: CarConverterType.OPTION,
+ powerWatts: this.selectedCarCatalog.chargeOptionPower,
+ amperagePerPhase: this.selectedCarCatalog.chargeOptionPhaseAmp,
+ numberOfPhases: this.selectedCarCatalog.chargeOptionPhase,
+ };
+ this.carCatalogConverters = [{
+ type: CarConverterType.STANDARD,
+ value: Utils.buildCarCatalogConverterName(standardConverter, this.translateService),
+ converter: standardConverter,
+ }];
+ if (this.selectedCarCatalog.chargeAlternativePower) {
+ this.carCatalogConverters.push({
+ type: CarConverterType.ALTERNATIVE,
+ value: Utils.buildCarCatalogConverterName(alternativeConverter, this.translateService),
+ converter: alternativeConverter,
+ });
+ }
+ if (this.selectedCarCatalog.chargeOptionPower > 0 &&
+ this.selectedCarCatalog.chargeOptionPower !== this.selectedCarCatalog.chargeAlternativePower) {
+ this.carCatalogConverters.push({
+ type: CarConverterType.OPTION,
+ value: Utils.buildCarCatalogConverterName(optionalConverter, this.translateService),
+ converter: optionalConverter,
+ });
+ }
+ // Set default
+ if (this.carCatalogConverters.length === 1) {
+ this.converterType.setValue(this.carCatalogConverters[0].type);
+ this.converter.setValue(this.carCatalogConverters[0].converter);
+ } else {
+ this.converterType.setValue('');
+ }
+ this.converterType.enable();
+ }
+}
diff --git a/src/app/pages/cars/cars.module.ts b/src/app/pages/cars/cars.module.ts
index 725102ed53..650b804362 100644
--- a/src/app/pages/cars/cars.module.ts
+++ b/src/app/pages/cars/cars.module.ts
@@ -15,6 +15,8 @@ import { CarCarouselComponent } from './car-catalog/carousel/car-carousel.compon
import { CarCatalogsListComponent } from './car-catalogs/car-catalogs-list.component';
import { CarDialogComponent } from './car/car-dialog.component';
import { CarComponent } from './car/car.component';
+import { CarConnectorComponent } from './car/connector/car-connector.component';
+import { CarMainComponent } from './car/main/car-main.component';
import { CarsComponent } from './cars.component';
import { CarsRoutes } from './cars.routing';
import { CarsListComponent } from './cars/cars-list.component';
@@ -43,6 +45,8 @@ import { CarImageFormatterCellComponent } from './cell-components/car-image-form
CarsListComponent,
CarDialogComponent,
CarComponent,
+ CarMainComponent,
+ CarConnectorComponent,
],
entryComponents: [
CarCatalogComponent,
@@ -53,6 +57,8 @@ import { CarImageFormatterCellComponent } from './cell-components/car-image-form
CarsListComponent,
CarDialogComponent,
CarComponent,
+ CarMainComponent,
+ CarConnectorComponent,
],
providers: [
],
diff --git a/src/app/pages/organization/companies/company/main/company-main.component.html b/src/app/pages/organization/companies/company/main/company-main.component.html
index 2614c2fa45..6304485b06 100644
--- a/src/app/pages/organization/companies/company/main/company-main.component.html
+++ b/src/app/pages/organization/companies/company/main/company-main.component.html
@@ -1,49 +1,47 @@
-