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

106 lines
3.1 KiB
TypeScript
Raw Normal View History

2018-04-12 12:13:19 +00:00
import { Component, OnInit, Input, Inject, DoCheck, ViewEncapsulation, Output, EventEmitter, OnDestroy, OnChanges } 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
})
2018-04-12 12:13:19 +00:00
export class SettingComponent implements OnInit, DoCheck, OnChanges {
2018-04-11 12:54:05 +00:00
2018-04-12 12:13:19 +00:00
@Input() isAllTarget: boolean;
@Input() selectedTarget: Target;
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
selectedCrawler: MetaCrawler;
credentialPassed: boolean;
selectedSensorDisplayItems: MetaSensorDisplayItem[];
itemNodes: TreeNode[];
2018-04-12 12:13:19 +00:00
step = 1;
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
}
2018-04-12 12:13:19 +00:00
ngOnChanges() {
}
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;
}
2018-04-12 12:13:19 +00:00
} catch (exception) {
this.nextable = false;
}
2018-04-12 09:54:15 +00:00
}
onCancel() {
this.close.emit();
}
onNext() {
2018-04-12 12:13:19 +00:00
this.step += 1;
}
onPrev() {
this.step -= 1;
}
onDone() {
2018-04-12 09:54:15 +00:00
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
}
}