2021-04-12 16:56:00 +03:00
|
|
|
///
|
|
|
|
|
/// Copyright © 2016-2021 The Thingsboard Authors
|
|
|
|
|
///
|
|
|
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
/// you may not use this file except in compliance with the License.
|
|
|
|
|
/// You may obtain a copy of the License at
|
|
|
|
|
///
|
|
|
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
///
|
|
|
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
/// See the License for the specific language governing permissions and
|
|
|
|
|
/// limitations under the License.
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
|
|
|
|
|
import { Subject } from 'rxjs';
|
|
|
|
|
import { Store } from '@ngrx/store';
|
|
|
|
|
import { AppState } from '@core/core.state';
|
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
|
import { EntityTableConfig } from '@home/models/entity/entities-table-config.models';
|
|
|
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
|
|
|
import { EntityComponent } from '@home/components/entity/entity.component';
|
2021-04-29 16:01:47 +03:00
|
|
|
import {
|
|
|
|
|
ChecksumAlgorithm,
|
|
|
|
|
ChecksumAlgorithmTranslationMap,
|
2021-05-31 18:15:31 +03:00
|
|
|
OtaPackage,
|
|
|
|
|
OtaUpdateType,
|
|
|
|
|
OtaUpdateTypeTranslationMap
|
|
|
|
|
} from '@shared/models/ota-package.models';
|
2021-04-13 15:10:13 +03:00
|
|
|
import { ActionNotificationShow } from '@core/notification/notification.actions';
|
2021-04-12 16:56:00 +03:00
|
|
|
|
|
|
|
|
@Component({
|
2021-05-31 18:15:31 +03:00
|
|
|
selector: 'tb-ota-update',
|
|
|
|
|
templateUrl: './ota-update.component.html'
|
2021-04-12 16:56:00 +03:00
|
|
|
})
|
2021-05-31 18:15:31 +03:00
|
|
|
export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements OnInit, OnDestroy {
|
2021-04-12 16:56:00 +03:00
|
|
|
|
|
|
|
|
private destroy$ = new Subject();
|
|
|
|
|
|
|
|
|
|
checksumAlgorithms = Object.values(ChecksumAlgorithm);
|
|
|
|
|
checksumAlgorithmTranslationMap = ChecksumAlgorithmTranslationMap;
|
2021-05-31 18:15:31 +03:00
|
|
|
packageTypes = Object.values(OtaUpdateType);
|
|
|
|
|
otaUpdateTypeTranslationMap = OtaUpdateTypeTranslationMap;
|
2021-04-12 16:56:00 +03:00
|
|
|
|
|
|
|
|
constructor(protected store: Store<AppState>,
|
|
|
|
|
protected translate: TranslateService,
|
2021-05-31 18:15:31 +03:00
|
|
|
@Inject('entity') protected entityValue: OtaPackage,
|
|
|
|
|
@Inject('entitiesTableConfig') protected entitiesTableConfigValue: EntityTableConfig<OtaPackage>,
|
2021-04-12 16:56:00 +03:00
|
|
|
public fb: FormBuilder) {
|
|
|
|
|
super(store, fb, entityValue, entitiesTableConfigValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
|
super.ngOnDestroy();
|
|
|
|
|
this.destroy$.next();
|
|
|
|
|
this.destroy$.complete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hideDelete() {
|
|
|
|
|
if (this.entitiesTableConfig) {
|
|
|
|
|
return !this.entitiesTableConfig.deleteEnabled(this.entity);
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 18:15:31 +03:00
|
|
|
buildForm(entity: OtaPackage): FormGroup {
|
2021-04-12 16:56:00 +03:00
|
|
|
const form = this.fb.group({
|
|
|
|
|
title: [entity ? entity.title : '', [Validators.required, Validators.maxLength(255)]],
|
|
|
|
|
version: [entity ? entity.version : '', [Validators.required, Validators.maxLength(255)]],
|
2021-05-31 18:15:31 +03:00
|
|
|
type: [entity?.type ? entity.type : OtaUpdateType.FIRMWARE, Validators.required],
|
|
|
|
|
deviceProfileId: [entity ? entity.deviceProfileId : null, Validators.required],
|
2021-04-28 12:26:35 +03:00
|
|
|
checksumAlgorithm: [entity && entity.checksumAlgorithm ? entity.checksumAlgorithm : ChecksumAlgorithm.SHA256],
|
2021-04-23 17:38:26 +03:00
|
|
|
checksum: [entity ? entity.checksum : '', Validators.maxLength(1020)],
|
2021-04-12 16:56:00 +03:00
|
|
|
additionalInfo: this.fb.group(
|
|
|
|
|
{
|
|
|
|
|
description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''],
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
});
|
|
|
|
|
if (this.isAdd) {
|
|
|
|
|
form.addControl('file', this.fb.control(null, Validators.required));
|
2021-04-23 17:38:26 +03:00
|
|
|
} else {
|
|
|
|
|
form.addControl('fileName', this.fb.control(null));
|
|
|
|
|
form.addControl('dataSize', this.fb.control(null));
|
|
|
|
|
form.addControl('contentType', this.fb.control(null));
|
2021-04-12 16:56:00 +03:00
|
|
|
}
|
|
|
|
|
return form;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 18:15:31 +03:00
|
|
|
updateForm(entity: OtaPackage) {
|
2021-04-12 16:56:00 +03:00
|
|
|
this.entityForm.patchValue({
|
|
|
|
|
title: entity.title,
|
|
|
|
|
version: entity.version,
|
2021-04-29 16:01:47 +03:00
|
|
|
type: entity.type,
|
|
|
|
|
deviceProfileId: entity.deviceProfileId,
|
2021-04-23 17:38:26 +03:00
|
|
|
checksumAlgorithm: entity.checksumAlgorithm,
|
|
|
|
|
checksum: entity.checksum,
|
|
|
|
|
fileName: entity.fileName,
|
|
|
|
|
dataSize: entity.dataSize,
|
|
|
|
|
contentType: entity.contentType,
|
2021-04-12 16:56:00 +03:00
|
|
|
additionalInfo: {
|
|
|
|
|
description: entity.additionalInfo ? entity.additionalInfo.description : ''
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-05-31 18:15:31 +03:00
|
|
|
if (!this.isAdd && this.entityForm.enabled) {
|
|
|
|
|
this.entityForm.disable({emitEvent: false});
|
|
|
|
|
this.entityForm.get('additionalInfo').enable({emitEvent: false});
|
|
|
|
|
// this.entityForm.get('dataSize').disable({emitEvent: false});
|
|
|
|
|
// this.entityForm.get('contentType').disable({emitEvent: false});
|
|
|
|
|
}
|
2021-04-12 16:56:00 +03:00
|
|
|
}
|
2021-04-13 15:10:13 +03:00
|
|
|
|
2021-05-31 18:15:31 +03:00
|
|
|
onPackageIdCopied() {
|
2021-04-13 15:10:13 +03:00
|
|
|
this.store.dispatch(new ActionNotificationShow(
|
|
|
|
|
{
|
2021-05-31 18:15:31 +03:00
|
|
|
message: this.translate.instant('ota-update.idCopiedMessage'),
|
2021-04-13 15:10:13 +03:00
|
|
|
type: 'success',
|
|
|
|
|
duration: 750,
|
|
|
|
|
verticalPosition: 'bottom',
|
|
|
|
|
horizontalPosition: 'right'
|
|
|
|
|
}));
|
|
|
|
|
}
|
2021-04-23 17:38:26 +03:00
|
|
|
|
2021-05-31 18:15:31 +03:00
|
|
|
onPackageChecksumCopied() {
|
2021-04-23 17:38:26 +03:00
|
|
|
this.store.dispatch(new ActionNotificationShow(
|
|
|
|
|
{
|
2021-05-31 18:15:31 +03:00
|
|
|
message: this.translate.instant('ota-update.checksum-copied-message'),
|
2021-04-23 17:38:26 +03:00
|
|
|
type: 'success',
|
|
|
|
|
duration: 750,
|
|
|
|
|
verticalPosition: 'bottom',
|
|
|
|
|
horizontalPosition: 'right'
|
|
|
|
|
}));
|
|
|
|
|
}
|
2021-04-12 16:56:00 +03:00
|
|
|
}
|