Commit 8769fe3ad62bf80bc85c8c93a76ec5de0d44bcf4
Committed by
GitHub
Merge pull request #4739 from vvlladd28/imrovement/ota-package/component
UI: Add validation ota package URL; Improvement ota-package-autocompl…
Showing
5 changed files
with
23 additions
and
9 deletions
@@ -35,6 +35,7 @@ import { TranslateService } from '@ngx-translate/core'; | @@ -35,6 +35,7 @@ import { TranslateService } from '@ngx-translate/core'; | ||
35 | import { EntityTableConfig } from '@home/models/entity/entities-table-config.models'; | 35 | import { EntityTableConfig } from '@home/models/entity/entities-table-config.models'; |
36 | import { Subject } from 'rxjs'; | 36 | import { Subject } from 'rxjs'; |
37 | import { OtaUpdateType } from '@shared/models/ota-package.models'; | 37 | import { OtaUpdateType } from '@shared/models/ota-package.models'; |
38 | +import { distinctUntilChanged } from 'rxjs/operators'; | ||
38 | 39 | ||
39 | @Component({ | 40 | @Component({ |
40 | selector: 'tb-device', | 41 | selector: 'tb-device', |
@@ -78,7 +79,7 @@ export class DeviceComponent extends EntityComponent<DeviceInfo> { | @@ -78,7 +79,7 @@ export class DeviceComponent extends EntityComponent<DeviceInfo> { | ||
78 | } | 79 | } |
79 | 80 | ||
80 | buildForm(entity: DeviceInfo): FormGroup { | 81 | buildForm(entity: DeviceInfo): FormGroup { |
81 | - return this.fb.group( | 82 | + const form = this.fb.group( |
82 | { | 83 | { |
83 | name: [entity ? entity.name : '', [Validators.required]], | 84 | name: [entity ? entity.name : '', [Validators.required]], |
84 | deviceProfileId: [entity ? entity.deviceProfileId : null, [Validators.required]], | 85 | deviceProfileId: [entity ? entity.deviceProfileId : null, [Validators.required]], |
@@ -95,6 +96,17 @@ export class DeviceComponent extends EntityComponent<DeviceInfo> { | @@ -95,6 +96,17 @@ export class DeviceComponent extends EntityComponent<DeviceInfo> { | ||
95 | ) | 96 | ) |
96 | } | 97 | } |
97 | ); | 98 | ); |
99 | + form.get('deviceProfileId').valueChanges.pipe( | ||
100 | + distinctUntilChanged((prev, curr) => prev?.id === curr?.id) | ||
101 | + ).subscribe(profileId => { | ||
102 | + if (profileId && this.isEdit) { | ||
103 | + this.entityForm.patchValue({ | ||
104 | + firmwareId: null, | ||
105 | + softwareId: null | ||
106 | + }, {emitEvent: false}); | ||
107 | + } | ||
108 | + }); | ||
109 | + return form; | ||
98 | } | 110 | } |
99 | 111 | ||
100 | updateForm(entity: DeviceInfo) { | 112 | updateForm(entity: DeviceInfo) { |
@@ -156,10 +168,6 @@ export class DeviceComponent extends EntityComponent<DeviceInfo> { | @@ -156,10 +168,6 @@ export class DeviceComponent extends EntityComponent<DeviceInfo> { | ||
156 | this.entityForm.markAsDirty(); | 168 | this.entityForm.markAsDirty(); |
157 | } | 169 | } |
158 | } | 170 | } |
159 | - this.entityForm.patchValue({ | ||
160 | - firmwareId: null, | ||
161 | - softwareId: null | ||
162 | - }); | ||
163 | } | 171 | } |
164 | } | 172 | } |
165 | } | 173 | } |
@@ -149,7 +149,7 @@ | @@ -149,7 +149,7 @@ | ||
149 | <input matInput formControlName="url" | 149 | <input matInput formControlName="url" |
150 | type="text" | 150 | type="text" |
151 | [required]="entityForm.get('resource').value === 'url'"> | 151 | [required]="entityForm.get('resource').value === 'url'"> |
152 | - <mat-error *ngIf="entityForm.get('url').hasError('required')" translate> | 152 | + <mat-error *ngIf="entityForm.get('url').hasError('required') || entityForm.get('url').hasError('pattern')" translate> |
153 | ota-update.direct-url-required | 153 | ota-update.direct-url-required |
154 | </mat-error> | 154 | </mat-error> |
155 | </mat-form-field> | 155 | </mat-form-field> |
@@ -67,7 +67,7 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O | @@ -67,7 +67,7 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O | ||
67 | this.entityForm.get('file').updateValueAndValidity({emitEvent: false}); | 67 | this.entityForm.get('file').updateValueAndValidity({emitEvent: false}); |
68 | } else { | 68 | } else { |
69 | this.entityForm.get('file').clearValidators(); | 69 | this.entityForm.get('file').clearValidators(); |
70 | - this.entityForm.get('url').setValidators(Validators.required); | 70 | + this.entityForm.get('url').setValidators([Validators.required, Validators.pattern('(.|\\s)*\\S(.|\\s)*')]); |
71 | this.entityForm.get('file').updateValueAndValidity({emitEvent: false}); | 71 | this.entityForm.get('file').updateValueAndValidity({emitEvent: false}); |
72 | this.entityForm.get('url').updateValueAndValidity({emitEvent: false}); | 72 | this.entityForm.get('url').updateValueAndValidity({emitEvent: false}); |
73 | } | 73 | } |
@@ -172,6 +172,11 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O | @@ -172,6 +172,11 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O | ||
172 | } | 172 | } |
173 | 173 | ||
174 | prepareFormValue(formValue: any): any { | 174 | prepareFormValue(formValue: any): any { |
175 | + if (formValue.resource === 'url') { | ||
176 | + delete formValue.file; | ||
177 | + } else { | ||
178 | + delete formValue.url; | ||
179 | + } | ||
175 | delete formValue.resource; | 180 | delete formValue.resource; |
176 | delete formValue.generateChecksum; | 181 | delete formValue.generateChecksum; |
177 | return super.prepareFormValue(formValue); | 182 | return super.prepareFormValue(formValue); |
@@ -21,7 +21,8 @@ | @@ -21,7 +21,8 @@ | ||
21 | formControlName="packageId" | 21 | formControlName="packageId" |
22 | (focusin)="onFocus()" | 22 | (focusin)="onFocus()" |
23 | [required]="required" | 23 | [required]="required" |
24 | - [matAutocomplete]="packageAutocomplete"> | 24 | + [matAutocomplete]="packageAutocomplete" |
25 | + [matAutocompleteDisabled]="disabled"> | ||
25 | <button *ngIf="otaPackageFormGroup.get('packageId').value && !disabled" | 26 | <button *ngIf="otaPackageFormGroup.get('packageId').value && !disabled" |
26 | type="button" | 27 | type="button" |
27 | matSuffix mat-button mat-icon-button aria-label="Clear" | 28 | matSuffix mat-button mat-icon-button aria-label="Clear" |
@@ -222,7 +222,7 @@ export class OtaPackageAutocompleteComponent implements ControlValueAccessor, On | @@ -222,7 +222,7 @@ export class OtaPackageAutocompleteComponent implements ControlValueAccessor, On | ||
222 | } | 222 | } |
223 | 223 | ||
224 | clear() { | 224 | clear() { |
225 | - this.otaPackageFormGroup.get('packageId').patchValue('', {emitEvent: true}); | 225 | + this.otaPackageFormGroup.get('packageId').patchValue('', {emitEvent: false}); |
226 | setTimeout(() => { | 226 | setTimeout(() => { |
227 | this.packageInput.nativeElement.blur(); | 227 | this.packageInput.nativeElement.blur(); |
228 | this.packageInput.nativeElement.focus(); | 228 | this.packageInput.nativeElement.focus(); |