import { NzModalSubject } from 'ng-zorro-antd';
|
import { Component, OnInit } from '@angular/core';
|
import { SensorsService } from '@business/services/http/sensors.service';
|
import { PageBean, Grid } from '@business/entity/grid';
|
import { Sensor } from '@business/entity/data';
|
import { Subject } from 'rxjs/Subject';
|
|
@Component({
|
selector: 'app-version-sensor-config',
|
templateUrl: './version-sensor-config.component.html',
|
styles: []
|
})
|
export class VersionSensorConfigComponent implements OnInit {
|
deviceVersionId: number;
|
selectedSensorIds: number[];
|
isSaving = false;
|
grid: Grid<Sensor> = new Grid(null);
|
private initPage() {
|
const sensor: Sensor = {
|
name: {
|
text: '名称',
|
width: '200px'
|
},
|
sensorKey: {
|
text: '键值',
|
width: '60px'
|
},
|
lower: {
|
text: '下限值',
|
width: '90px'
|
},
|
upper: {
|
text: '上限值',
|
width: '90px'
|
},
|
unit: {
|
text: '单位',
|
width: '100px'
|
},
|
description: {
|
text: '描述'
|
}
|
};
|
this.grid.title = '传感器';
|
this.grid.setColumns(sensor);
|
this.grid.pageSize = 0;
|
}
|
constructor(
|
private subject: NzModalSubject,
|
private sensorsService: SensorsService,
|
) { }
|
|
ngOnInit() {
|
this.initPage();
|
this.load();
|
}
|
load() {
|
// 延时加载避免ExpressionChangedAfterItHasBeenCheckedError
|
setTimeout(() => {
|
this.grid.loading = true;
|
}, 1);
|
this.sensorsService.getPagingList(this.grid, null).subscribe(
|
(res: PageBean) => {
|
this.grid.loading = true;
|
if (res != null && res.data != null) {
|
this.grid.initData(res);
|
this.grid.data.map(
|
(row: any) => {
|
row['checked'] = this.selectedSensorIds.filter(
|
(id: number) => {
|
return row.id === id;
|
}
|
).length > 0;
|
}
|
);
|
this.grid.refreshStatus();
|
setTimeout(() => {
|
this.grid.loading = false;
|
}, 1);
|
}
|
}
|
);
|
}
|
close() {
|
this.subject.destroy();
|
}
|
save($event, value, valid) {
|
$event.preventDefault();
|
this.subject.next( this );
|
}
|
|
sort(field: string, value: string) {
|
// 删除当前field
|
this.grid.sorts = this.grid.sorts.filter(
|
(fn: string) => {
|
return fn !== field;
|
}
|
);
|
// 如果value不为null,在排序数组最后加上filed
|
if (value != null) {
|
this.grid.sorts.push(field);
|
}
|
this.load();
|
}
|
}
|