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