member_webapp/src/packages/sensor/component/setting/setting.component.ts

97 lines
3.0 KiB
TypeScript
Raw Normal View History

2018-04-12 09:54:15 +00:00
import { Component, OnInit, Input, Inject, DoCheck, ViewEncapsulation, Output, EventEmitter, OnDestroy } from '@angular/core';
2018-04-11 12:54:05 +00:00
import { Target } from 'packages/target/model';
import { Infra } from 'packages/infra/model';
import { MetaCrawler } from 'packages/meta/crawler/model/MetaCrawler';
import { MetaSensorDisplayItem } from 'packages/meta/sensor-display-item/model/MetaSensorDisplayItem';
import { Store, select } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc/protocol';
import * as SensorItemKeyListStore from 'packages/sensor-item/store/key-list';
import { ReadSensorItemKeySelector } from 'packages/sensor-item/store';
import { MetaSensorItemKey } from 'packages/meta/sensor-item-key/model/MetaSensorItemKey';
2018-04-12 09:54:15 +00:00
import { TreeNode } from 'primeng/primeng';
2018-04-11 12:54:05 +00:00
@Component({
selector: 'of-sensor-setting',
templateUrl: './setting.component.html',
encapsulation: ViewEncapsulation.None
})
export class SettingComponent implements OnInit, DoCheck {
2018-04-12 09:54:15 +00:00
@Output() close = new EventEmitter();
nextable = false;
2018-04-11 12:54:05 +00:00
sensorItemKeys$ = this.keyListStore.pipe(select(ReadSensorItemKeySelector.select('list')));
2018-04-12 09:54:15 +00:00
@Input() selectedTarget: Target;
selectedCrawler: MetaCrawler;
credentialPassed: boolean;
selectedSensorDisplayItems: MetaSensorDisplayItem[];
itemNodes: TreeNode[];
2018-04-11 12:54:05 +00:00
constructor(
private keyListStore: Store<SensorItemKeyListStore.State>,
) {
}
ngOnInit() {
2018-04-12 09:54:15 +00:00
// this.sensorItemKeys$.subscribe(
// (list: MetaSensorItemKey[]) => {
// if (list !== null) {
// console.log(list);
// }
// },
// (error: RPCClientError) => {
// console.log(error.response.message);
// }
// );
2018-04-11 12:54:05 +00:00
}
ngDoCheck() {
2018-04-12 09:54:15 +00:00
try {
if (
this.selectedTarget === null ||
this.selectedCrawler === null ||
this.itemNodes === null ||
this.itemNodes.length === 0 ||
!this.credentialPassed
) {
this.nextable = false;
} else {
this.nextable = true;
}
} catch (exception) {}
}
onCancel() {
this.selectedTarget = null;
this.selectedCrawler = null;
this.credentialPassed = false;
this.selectedSensorDisplayItems = null;
this.close.emit();
}
onNext() {
this.selectedSensorDisplayItems = [];
for (const node of this.itemNodes) {
if (node.data && node.data !== undefined) {
this.selectedSensorDisplayItems.push(node.data);
}
}
console.log(this.selectedSensorDisplayItems);
}
onTargetSelect(t: Target) {
this.selectedTarget = t;
}
onCrawlerSelect(c: MetaCrawler) {
this.selectedCrawler = c;
}
onCredentialPass(b: boolean) {
this.credentialPassed = b;
}
onItemsSelect(nodes: TreeNode[]) {
this.itemNodes = nodes;
2018-04-11 12:54:05 +00:00
}
}