Commit 807a543d1c66ff11da387baccc357cb0025e52af
1 parent
633ab7d3
UI: Add validation ota package URL; Improvement ota-package-autocomplete; Refact…
…oring update ota-packages in device-component
Showing
5 changed files
with
23 additions
and
9 deletions
... | ... | @@ -35,6 +35,7 @@ import { TranslateService } from '@ngx-translate/core'; |
35 | 35 | import { EntityTableConfig } from '@home/models/entity/entities-table-config.models'; |
36 | 36 | import { Subject } from 'rxjs'; |
37 | 37 | import { OtaUpdateType } from '@shared/models/ota-package.models'; |
38 | +import { distinctUntilChanged } from 'rxjs/operators'; | |
38 | 39 | |
39 | 40 | @Component({ |
40 | 41 | selector: 'tb-device', |
... | ... | @@ -78,7 +79,7 @@ export class DeviceComponent extends EntityComponent<DeviceInfo> { |
78 | 79 | } |
79 | 80 | |
80 | 81 | buildForm(entity: DeviceInfo): FormGroup { |
81 | - return this.fb.group( | |
82 | + const form = this.fb.group( | |
82 | 83 | { |
83 | 84 | name: [entity ? entity.name : '', [Validators.required]], |
84 | 85 | deviceProfileId: [entity ? entity.deviceProfileId : null, [Validators.required]], |
... | ... | @@ -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 | 112 | updateForm(entity: DeviceInfo) { |
... | ... | @@ -156,10 +168,6 @@ export class DeviceComponent extends EntityComponent<DeviceInfo> { |
156 | 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 | 149 | <input matInput formControlName="url" |
150 | 150 | type="text" |
151 | 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 | 153 | ota-update.direct-url-required |
154 | 154 | </mat-error> |
155 | 155 | </mat-form-field> | ... | ... |
... | ... | @@ -67,7 +67,7 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O |
67 | 67 | this.entityForm.get('file').updateValueAndValidity({emitEvent: false}); |
68 | 68 | } else { |
69 | 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 | 71 | this.entityForm.get('file').updateValueAndValidity({emitEvent: false}); |
72 | 72 | this.entityForm.get('url').updateValueAndValidity({emitEvent: false}); |
73 | 73 | } |
... | ... | @@ -172,6 +172,11 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O |
172 | 172 | } |
173 | 173 | |
174 | 174 | prepareFormValue(formValue: any): any { |
175 | + if (formValue.resource === 'url') { | |
176 | + delete formValue.file; | |
177 | + } else { | |
178 | + delete formValue.url; | |
179 | + } | |
175 | 180 | delete formValue.resource; |
176 | 181 | delete formValue.generateChecksum; |
177 | 182 | return super.prepareFormValue(formValue); | ... | ... |
... | ... | @@ -21,7 +21,8 @@ |
21 | 21 | formControlName="packageId" |
22 | 22 | (focusin)="onFocus()" |
23 | 23 | [required]="required" |
24 | - [matAutocomplete]="packageAutocomplete"> | |
24 | + [matAutocomplete]="packageAutocomplete" | |
25 | + [matAutocompleteDisabled]="disabled"> | |
25 | 26 | <button *ngIf="otaPackageFormGroup.get('packageId').value && !disabled" |
26 | 27 | type="button" |
27 | 28 | matSuffix mat-button mat-icon-button aria-label="Clear" | ... | ... |
... | ... | @@ -222,7 +222,7 @@ export class OtaPackageAutocompleteComponent implements ControlValueAccessor, On |
222 | 222 | } |
223 | 223 | |
224 | 224 | clear() { |
225 | - this.otaPackageFormGroup.get('packageId').patchValue('', {emitEvent: true}); | |
225 | + this.otaPackageFormGroup.get('packageId').patchValue('', {emitEvent: false}); | |
226 | 226 | setTimeout(() => { |
227 | 227 | this.packageInput.nativeElement.blur(); |
228 | 228 | this.packageInput.nativeElement.focus(); | ... | ... |