Commit 6d0e6b35964b7161a232857593b8a226e3a8a210

Authored by AndrewVolosytnykhThingsboard
2 parents 22933e54 f4c80414

Merge remote-tracking branch 'origin/ota-service-url-validation' into ota-service-url-validation

@@ -93,17 +93,17 @@ @@ -93,17 +93,17 @@
93 </mat-form-field> 93 </mat-form-field>
94 <section *ngIf="isAdd"> 94 <section *ngIf="isAdd">
95 <div class="mat-caption" style="margin: -8px 0 8px;" translate>ota-update.warning-after-save-no-edit</div> 95 <div class="mat-caption" style="margin: -8px 0 8px;" translate>ota-update.warning-after-save-no-edit</div>
96 - <mat-radio-group formControlName="resource" fxLayoutGap="16px">  
97 - <mat-radio-button value="file">Upload binary file</mat-radio-button>  
98 - <mat-radio-button value="url">Use external URL</mat-radio-button> 96 + <mat-radio-group formControlName="isURL" fxLayoutGap="16px">
  97 + <mat-radio-button [value]="false">Upload binary file</mat-radio-button>
  98 + <mat-radio-button [value]="true">Use external URL</mat-radio-button>
99 </mat-radio-group> 99 </mat-radio-group>
100 </section> 100 </section>
101 - <section *ngIf="entityForm.get('resource').value === 'file'"> 101 + <section *ngIf="!entityForm.get('isURL').value">
102 <section *ngIf="isAdd"> 102 <section *ngIf="isAdd">
103 <tb-file-input 103 <tb-file-input
104 formControlName="file" 104 formControlName="file"
105 workFromFileObj="true" 105 workFromFileObj="true"
106 - [required]="entityForm.get('resource').value === 'file'" 106 + [required]="!entityForm.get('isURL').value"
107 dropLabel="{{'ota-update.drop-file' | translate}}"> 107 dropLabel="{{'ota-update.drop-file' | translate}}">
108 </tb-file-input> 108 </tb-file-input>
109 <mat-checkbox formControlName="generateChecksum" style="margin-top: 16px"> 109 <mat-checkbox formControlName="generateChecksum" style="margin-top: 16px">
@@ -143,12 +143,12 @@ @@ -143,12 +143,12 @@
143 </div> 143 </div>
144 </section> 144 </section>
145 </section> 145 </section>
146 - <section *ngIf="entityForm.get('resource').value === 'url'" style="margin-top: 8px"> 146 + <section *ngIf="entityForm.get('isURL').value" style="margin-top: 8px">
147 <mat-form-field class="mat-block"> 147 <mat-form-field class="mat-block">
148 <mat-label translate>ota-update.direct-url</mat-label> 148 <mat-label translate>ota-update.direct-url</mat-label>
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('isURL').value">
152 <mat-error *ngIf="entityForm.get('url').hasError('required') || entityForm.get('url').hasError('pattern')" 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>
@@ -56,11 +56,11 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O @@ -56,11 +56,11 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O
56 56
57 ngOnInit() { 57 ngOnInit() {
58 super.ngOnInit(); 58 super.ngOnInit();
59 - this.entityForm.get('resource').valueChanges.pipe( 59 + this.entityForm.get('isURL').valueChanges.pipe(
60 filter(() => this.isAdd), 60 filter(() => this.isAdd),
61 takeUntil(this.destroy$) 61 takeUntil(this.destroy$)
62 - ).subscribe((resource) => {  
63 - if (resource === 'file') { 62 + ).subscribe((isURL) => {
  63 + if (isURL === false) {
64 this.entityForm.get('url').clearValidators(); 64 this.entityForm.get('url').clearValidators();
65 this.entityForm.get('file').setValidators(Validators.required); 65 this.entityForm.get('file').setValidators(Validators.required);
66 this.entityForm.get('url').updateValueAndValidity({emitEvent: false}); 66 this.entityForm.get('url').updateValueAndValidity({emitEvent: false});
@@ -97,7 +97,7 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O @@ -97,7 +97,7 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O
97 checksumAlgorithm: [entity && entity.checksumAlgorithm ? entity.checksumAlgorithm : ChecksumAlgorithm.SHA256], 97 checksumAlgorithm: [entity && entity.checksumAlgorithm ? entity.checksumAlgorithm : ChecksumAlgorithm.SHA256],
98 checksum: [entity ? entity.checksum : '', Validators.maxLength(1020)], 98 checksum: [entity ? entity.checksum : '', Validators.maxLength(1020)],
99 url: [entity ? entity.url : ''], 99 url: [entity ? entity.url : ''],
100 - resource: ['file'], 100 + isURL: [false],
101 additionalInfo: this.fb.group( 101 additionalInfo: this.fb.group(
102 { 102 {
103 description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''], 103 description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''],
@@ -127,7 +127,7 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O @@ -127,7 +127,7 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O
127 dataSize: entity.dataSize, 127 dataSize: entity.dataSize,
128 contentType: entity.contentType, 128 contentType: entity.contentType,
129 url: entity.url, 129 url: entity.url,
130 - resource: isNotEmptyStr(entity.url) ? 'url' : 'file', 130 + isURL: isNotEmptyStr(entity.url),
131 additionalInfo: { 131 additionalInfo: {
132 description: entity.additionalInfo ? entity.additionalInfo.description : '' 132 description: entity.additionalInfo ? entity.additionalInfo.description : ''
133 } 133 }
@@ -172,12 +172,11 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O @@ -172,12 +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') { 175 + if (formValue.isURL) {
176 delete formValue.file; 176 delete formValue.file;
177 } else { 177 } else {
178 delete formValue.url; 178 delete formValue.url;
179 } 179 }
180 - delete formValue.resource;  
181 delete formValue.generateChecksum; 180 delete formValue.generateChecksum;
182 return super.prepareFormValue(formValue); 181 return super.prepareFormValue(formValue);
183 } 182 }
@@ -99,6 +99,7 @@ export interface OtaPackageInfo extends BaseData<OtaPackageId> { @@ -99,6 +99,7 @@ export interface OtaPackageInfo extends BaseData<OtaPackageId> {
99 contentType: string; 99 contentType: string;
100 dataSize?: number; 100 dataSize?: number;
101 additionalInfo?: any; 101 additionalInfo?: any;
  102 + isURL?: boolean;
102 } 103 }
103 104
104 export interface OtaPackage extends OtaPackageInfo { 105 export interface OtaPackage extends OtaPackageInfo {