UI: Improvement Add asset dialog

This commit is contained in:
Artem Dzhereleiko 2023-07-13 12:56:51 +03:00
parent b076a89b58
commit efaaf9e791
9 changed files with 29 additions and 25 deletions

View File

@ -43,6 +43,11 @@
(click)="editAssetProfile($event)"> (click)="editAssetProfile($event)">
<mat-icon class="material-icons">edit</mat-icon> <mat-icon class="material-icons">edit</mat-icon>
</button> </button>
<button mat-button color="primary" matSuffix
(click)="createAssetProfile($event, '')"
*ngIf="!selectAssetProfileFormGroup.get('assetProfile').value && !disabled && addNewProfile">
<span style="white-space: nowrap">{{ 'notification.create-new' | translate }}</span>
</button>
<mat-autocomplete <mat-autocomplete
class="tb-autocomplete" class="tb-autocomplete"
(closed)="onPanelClosed()" (closed)="onPanelClosed()"

View File

@ -46,6 +46,7 @@ import { AssetProfile, AssetProfileInfo } from '@shared/models/asset.models';
import { AssetProfileService } from '@core/http/asset-profile.service'; import { AssetProfileService } from '@core/http/asset-profile.service';
import { AssetProfileDialogComponent, AssetProfileDialogData } from './asset-profile-dialog.component'; import { AssetProfileDialogComponent, AssetProfileDialogData } from './asset-profile-dialog.component';
import { SubscriptSizing } from '@angular/material/form-field'; import { SubscriptSizing } from '@angular/material/form-field';
import { coerceBoolean } from '@shared/decorators/coercion';
@Component({ @Component({
selector: 'tb-asset-profile-autocomplete', selector: 'tb-asset-profile-autocomplete',
@ -84,14 +85,9 @@ export class AssetProfileAutocompleteComponent implements ControlValueAccessor,
@Input() @Input()
showDetailsPageLink = false; showDetailsPageLink = false;
private requiredValue: boolean;
get required(): boolean {
return this.requiredValue;
}
@Input() @Input()
set required(value: boolean) { @coerceBoolean()
this.requiredValue = coerceBooleanProperty(value); required = false;
}
@Input() @Input()
disabled: boolean; disabled: boolean;

View File

@ -45,7 +45,7 @@
</button> </button>
<button mat-button color="primary" matSuffix <button mat-button color="primary" matSuffix
(click)="createDeviceProfile($event, '')" (click)="createDeviceProfile($event, '')"
*ngIf="!selectDeviceProfileFormGroup.get('deviceProfile').value && !disabled && addNewProfile && showCreateNewButton"> *ngIf="!selectDeviceProfileFormGroup.get('deviceProfile').value && !disabled && addNewProfile">
<span style="white-space: nowrap">{{ 'notification.create-new' | translate }}</span> <span style="white-space: nowrap">{{ 'notification.create-new' | translate }}</span>
</button> </button>
<mat-autocomplete <mat-autocomplete

View File

@ -88,10 +88,6 @@ export class DeviceProfileAutocompleteComponent implements ControlValueAccessor,
@coerceBoolean() @coerceBoolean()
addNewProfile = true; addNewProfile = true;
@Input()
@coerceBoolean()
showCreateNewButton = false;
@Input() @Input()
showDetailsPageLink = false; showDetailsPageLink = false;

View File

@ -60,7 +60,6 @@
<tb-device-profile-autocomplete <tb-device-profile-autocomplete
required required
addNewProfile addNewProfile
showCreateNewButton
selectDefaultProfile selectDefaultProfile
formControlName="deviceProfileId" formControlName="deviceProfileId"
(deviceProfileChanged)="deviceProfileChanged($event)"> (deviceProfileChanged)="deviceProfileChanged($event)">
@ -76,6 +75,7 @@
</div> </div>
<tb-entity-autocomplete <tb-entity-autocomplete
formControlName="customerId" formControlName="customerId"
useFullEntityId
labelText="device.wizard.customer-to-assign-device" labelText="device.wizard.customer-to-assign-device"
[entityType]="entityType.CUSTOMER"> [entityType]="entityType.CUSTOMER">
</tb-entity-autocomplete> </tb-entity-autocomplete>

View File

@ -147,11 +147,8 @@ export class DeviceWizardDialogComponent extends DialogComponent<DeviceWizardDia
overwriteActivityTime: this.deviceWizardFormGroup.get('overwriteActivityTime').value, overwriteActivityTime: this.deviceWizardFormGroup.get('overwriteActivityTime').value,
description: this.deviceWizardFormGroup.get('description').value description: this.deviceWizardFormGroup.get('description').value
}, },
customerId: null customerId: this.deviceWizardFormGroup.get('customerId').value
}; };
if (this.deviceWizardFormGroup.get('customerId').value) {
device.customerId = new CustomerId(this.deviceWizardFormGroup.get('customerId').value);
}
if (this.addDeviceWizardStepper.steps.last.completed || this.addDeviceWizardStepper.selectedIndex > 0) { if (this.addDeviceWizardStepper.steps.last.completed || this.addDeviceWizardStepper.selectedIndex > 0) {
return this.deviceService.saveDeviceWithCredentials(deepTrim(device), deepTrim(this.credentialsFormGroup.value.credential)).pipe( return this.deviceService.saveDeviceWithCredentials(deepTrim(device), deepTrim(this.credentialsFormGroup.value.credential)).pipe(
catchError((e: HttpErrorResponse) => { catchError((e: HttpErrorResponse) => {

View File

@ -86,13 +86,6 @@
{{ 'asset.name-max-length' | translate }} {{ 'asset.name-max-length' | translate }}
</mat-error> </mat-error>
</mat-form-field> </mat-form-field>
<tb-asset-profile-autocomplete
[selectDefaultProfile]="isAdd"
required
formControlName="assetProfileId"
[showDetailsPageLink]="true"
(assetProfileUpdated)="onAssetProfileUpdated()">
</tb-asset-profile-autocomplete>
<mat-form-field class="mat-block"> <mat-form-field class="mat-block">
<mat-label translate>asset.label</mat-label> <mat-label translate>asset.label</mat-label>
<input matInput formControlName="label"> <input matInput formControlName="label">
@ -100,6 +93,20 @@
{{ 'asset.label-max-length' | translate }} {{ 'asset.label-max-length' | translate }}
</mat-error> </mat-error>
</mat-form-field> </mat-form-field>
<tb-asset-profile-autocomplete
[selectDefaultProfile]="isAdd"
required
formControlName="assetProfileId"
[showDetailsPageLink]="true"
(assetProfileUpdated)="onAssetProfileUpdated()">
</tb-asset-profile-autocomplete>
<tb-entity-autocomplete
*ngIf="isAdd"
useFullEntityId
formControlName="customerId"
labelText="asset.customer-to-assign-asset"
[entityType]="entityType.CUSTOMER">
</tb-entity-autocomplete>
<div formGroupName="additionalInfo"> <div formGroupName="additionalInfo">
<mat-form-field class="mat-block"> <mat-form-field class="mat-block">
<mat-label translate>asset.description</mat-label> <mat-label translate>asset.description</mat-label>

View File

@ -69,6 +69,7 @@ export class AssetComponent extends EntityComponent<AssetInfo> {
name: [entity ? entity.name : '', [Validators.required, Validators.maxLength(255)]], name: [entity ? entity.name : '', [Validators.required, Validators.maxLength(255)]],
assetProfileId: [entity ? entity.assetProfileId : null, [Validators.required]], assetProfileId: [entity ? entity.assetProfileId : null, [Validators.required]],
label: [entity ? entity.label : '', Validators.maxLength(255)], label: [entity ? entity.label : '', Validators.maxLength(255)],
customerId: [entity ? entity.customerId : ''],
additionalInfo: this.fb.group( additionalInfo: this.fb.group(
{ {
description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''], description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''],
@ -82,6 +83,7 @@ export class AssetComponent extends EntityComponent<AssetInfo> {
this.entityForm.patchValue({name: entity.name}); this.entityForm.patchValue({name: entity.name});
this.entityForm.patchValue({assetProfileId: entity.assetProfileId}); this.entityForm.patchValue({assetProfileId: entity.assetProfileId});
this.entityForm.patchValue({label: entity.label}); this.entityForm.patchValue({label: entity.label});
this.entityForm.patchValue({customerId: entity.customerId});
this.entityForm.patchValue({additionalInfo: {description: entity.additionalInfo ? entity.additionalInfo.description : ''}}); this.entityForm.patchValue({additionalInfo: {description: entity.additionalInfo ? entity.additionalInfo.description : ''}});
} }

View File

@ -685,7 +685,8 @@
"unassign-asset-from-edge-text": "After the confirmation the asset will be unassigned and won't be accessible by the edge.", "unassign-asset-from-edge-text": "After the confirmation the asset will be unassigned and won't be accessible by the edge.",
"unassign-assets-from-edge-title": "Are you sure you want to unassign { count, plural, =1 {1 asset} other {# assets} }?", "unassign-assets-from-edge-title": "Are you sure you want to unassign { count, plural, =1 {1 asset} other {# assets} }?",
"unassign-assets-from-edge-text": "After the confirmation all selected assets will be unassigned and won't be accessible by the edge.", "unassign-assets-from-edge-text": "After the confirmation all selected assets will be unassigned and won't be accessible by the edge.",
"selected-assets": "{ count, plural, =1 {1 asset} other {# assets} } selected" "selected-assets": "{ count, plural, =1 {1 asset} other {# assets} } selected",
"customer-to-assign-asset": "Customer to assign the asset"
}, },
"attribute": { "attribute": {
"attributes": "Attributes", "attributes": "Attributes",