Browse Source

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

pull/4869/head
AndrewVolosytnykhThingsboard 5 years ago
parent
commit
6d0e6b3596
  1. 14
      ui-ngx/src/app/modules/home/pages/ota-update/ota-update.component.html
  2. 13
      ui-ngx/src/app/modules/home/pages/ota-update/ota-update.component.ts
  3. 1
      ui-ngx/src/app/shared/models/ota-package.models.ts

14
ui-ngx/src/app/modules/home/pages/ota-update/ota-update.component.html

@ -93,17 +93,17 @@
</mat-form-field>
<section *ngIf="isAdd">
<div class="mat-caption" style="margin: -8px 0 8px;" translate>ota-update.warning-after-save-no-edit</div>
<mat-radio-group formControlName="resource" fxLayoutGap="16px">
<mat-radio-button value="file">Upload binary file</mat-radio-button>
<mat-radio-button value="url">Use external URL</mat-radio-button>
<mat-radio-group formControlName="isURL" fxLayoutGap="16px">
<mat-radio-button [value]="false">Upload binary file</mat-radio-button>
<mat-radio-button [value]="true">Use external URL</mat-radio-button>
</mat-radio-group>
</section>
<section *ngIf="entityForm.get('resource').value === 'file'">
<section *ngIf="!entityForm.get('isURL').value">
<section *ngIf="isAdd">
<tb-file-input
formControlName="file"
workFromFileObj="true"
[required]="entityForm.get('resource').value === 'file'"
[required]="!entityForm.get('isURL').value"
dropLabel="{{'ota-update.drop-file' | translate}}">
</tb-file-input>
<mat-checkbox formControlName="generateChecksum" style="margin-top: 16px">
@ -143,12 +143,12 @@
</div>
</section>
</section>
<section *ngIf="entityForm.get('resource').value === 'url'" style="margin-top: 8px">
<section *ngIf="entityForm.get('isURL').value" style="margin-top: 8px">
<mat-form-field class="mat-block">
<mat-label translate>ota-update.direct-url</mat-label>
<input matInput formControlName="url"
type="text"
[required]="entityForm.get('resource').value === 'url'">
[required]="entityForm.get('isURL').value">
<mat-error *ngIf="entityForm.get('url').hasError('required') || entityForm.get('url').hasError('pattern')" translate>
ota-update.direct-url-required
</mat-error>

13
ui-ngx/src/app/modules/home/pages/ota-update/ota-update.component.ts

@ -56,11 +56,11 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O
ngOnInit() {
super.ngOnInit();
this.entityForm.get('resource').valueChanges.pipe(
this.entityForm.get('isURL').valueChanges.pipe(
filter(() => this.isAdd),
takeUntil(this.destroy$)
).subscribe((resource) => {
if (resource === 'file') {
).subscribe((isURL) => {
if (isURL === false) {
this.entityForm.get('url').clearValidators();
this.entityForm.get('file').setValidators(Validators.required);
this.entityForm.get('url').updateValueAndValidity({emitEvent: false});
@ -97,7 +97,7 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O
checksumAlgorithm: [entity && entity.checksumAlgorithm ? entity.checksumAlgorithm : ChecksumAlgorithm.SHA256],
checksum: [entity ? entity.checksum : '', Validators.maxLength(1020)],
url: [entity ? entity.url : ''],
resource: ['file'],
isURL: [false],
additionalInfo: this.fb.group(
{
description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''],
@ -127,7 +127,7 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O
dataSize: entity.dataSize,
contentType: entity.contentType,
url: entity.url,
resource: isNotEmptyStr(entity.url) ? 'url' : 'file',
isURL: isNotEmptyStr(entity.url),
additionalInfo: {
description: entity.additionalInfo ? entity.additionalInfo.description : ''
}
@ -172,12 +172,11 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O
}
prepareFormValue(formValue: any): any {
if (formValue.resource === 'url') {
if (formValue.isURL) {
delete formValue.file;
} else {
delete formValue.url;
}
delete formValue.resource;
delete formValue.generateChecksum;
return super.prepareFormValue(formValue);
}

1
ui-ngx/src/app/shared/models/ota-package.models.ts

@ -99,6 +99,7 @@ export interface OtaPackageInfo extends BaseData<OtaPackageId> {
contentType: string;
dataSize?: number;
additionalInfo?: any;
isURL?: boolean;
}
export interface OtaPackage extends OtaPackageInfo {

Loading…
Cancel
Save