|
|
|
@ -15,7 +15,7 @@ |
|
|
|
///
|
|
|
|
|
|
|
|
import { Component, Inject, OnDestroy, OnInit } from '@angular/core'; |
|
|
|
import { Subject } from 'rxjs'; |
|
|
|
import { combineLatest, Subject } from 'rxjs'; |
|
|
|
import { Store } from '@ngrx/store'; |
|
|
|
import { AppState } from '@core/core.state'; |
|
|
|
import { TranslateService } from '@ngx-translate/core'; |
|
|
|
@ -30,7 +30,7 @@ import { |
|
|
|
OtaUpdateTypeTranslationMap |
|
|
|
} from '@shared/models/ota-package.models'; |
|
|
|
import { ActionNotificationShow } from '@core/notification/notification.actions'; |
|
|
|
import { filter, takeUntil } from 'rxjs/operators'; |
|
|
|
import { filter, startWith, takeUntil } from 'rxjs/operators'; |
|
|
|
import { isNotEmptyStr } from '@core/utils'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
@ -56,22 +56,36 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O |
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
super.ngOnInit(); |
|
|
|
this.entityForm.get('isURL').valueChanges.pipe( |
|
|
|
filter(() => this.isAdd), |
|
|
|
takeUntil(this.destroy$) |
|
|
|
).subscribe((isURL) => { |
|
|
|
if (isURL === false) { |
|
|
|
this.entityForm.get('url').clearValidators(); |
|
|
|
this.entityForm.get('file').setValidators(Validators.required); |
|
|
|
this.entityForm.get('url').updateValueAndValidity({emitEvent: false}); |
|
|
|
this.entityForm.get('file').updateValueAndValidity({emitEvent: false}); |
|
|
|
} else { |
|
|
|
this.entityForm.get('file').clearValidators(); |
|
|
|
this.entityForm.get('url').setValidators([Validators.required, Validators.pattern('(.|\\s)*\\S(.|\\s)*')]); |
|
|
|
this.entityForm.get('file').updateValueAndValidity({emitEvent: false}); |
|
|
|
this.entityForm.get('url').updateValueAndValidity({emitEvent: false}); |
|
|
|
} |
|
|
|
}); |
|
|
|
if (this.isAdd) { |
|
|
|
this.entityForm.get('isURL').valueChanges.pipe( |
|
|
|
takeUntil(this.destroy$) |
|
|
|
).subscribe((isURL) => { |
|
|
|
if (isURL === false) { |
|
|
|
this.entityForm.get('url').clearValidators(); |
|
|
|
this.entityForm.get('file').setValidators(Validators.required); |
|
|
|
this.entityForm.get('url').updateValueAndValidity({emitEvent: false}); |
|
|
|
this.entityForm.get('file').updateValueAndValidity({emitEvent: false}); |
|
|
|
} else { |
|
|
|
this.entityForm.get('file').clearValidators(); |
|
|
|
this.entityForm.get('url').setValidators([Validators.required, Validators.pattern('(.|\\s)*\\S(.|\\s)*')]); |
|
|
|
this.entityForm.get('file').updateValueAndValidity({emitEvent: false}); |
|
|
|
this.entityForm.get('url').updateValueAndValidity({emitEvent: false}); |
|
|
|
} |
|
|
|
}); |
|
|
|
combineLatest([ |
|
|
|
this.entityForm.get('title').valueChanges.pipe(startWith(''), takeUntil(this.destroy$)), |
|
|
|
this.entityForm.get('version').valueChanges.pipe(startWith(''), takeUntil(this.destroy$)) |
|
|
|
]).pipe( |
|
|
|
filter(() => this.entityForm.get('tag').pristine), |
|
|
|
takeUntil(this.destroy$) |
|
|
|
).subscribe(([title, version]) => { |
|
|
|
let tag = `${title} ${version}`.trim(); |
|
|
|
if (tag === '') { |
|
|
|
tag = ''; |
|
|
|
} |
|
|
|
this.entityForm.get('tag').patchValue(tag); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ngOnDestroy() { |
|
|
|
@ -92,6 +106,7 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O |
|
|
|
const form = this.fb.group({ |
|
|
|
title: [entity ? entity.title : '', [Validators.required, Validators.maxLength(255)]], |
|
|
|
version: [entity ? entity.version : '', [Validators.required, Validators.maxLength(255)]], |
|
|
|
tag: [entity ? entity.tag : '', [Validators.maxLength(255)]], |
|
|
|
type: [entity?.type ? entity.type : OtaUpdateType.FIRMWARE, Validators.required], |
|
|
|
deviceProfileId: [entity ? entity.deviceProfileId : null, Validators.required], |
|
|
|
checksumAlgorithm: [entity && entity.checksumAlgorithm ? entity.checksumAlgorithm : ChecksumAlgorithm.SHA256], |
|
|
|
@ -119,6 +134,7 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O |
|
|
|
this.entityForm.patchValue({ |
|
|
|
title: entity.title, |
|
|
|
version: entity.version, |
|
|
|
tag: entity.tag, |
|
|
|
type: entity.type, |
|
|
|
deviceProfileId: entity.deviceProfileId, |
|
|
|
checksumAlgorithm: entity.checksumAlgorithm, |
|
|
|
|