2018-04-13 07:27:47 +00:00
|
|
|
import { Component, OnInit, Input, Inject, DoCheck, ViewEncapsulation, Output, EventEmitter, OnChanges } from '@angular/core';
|
2018-05-02 08:09:39 +00:00
|
|
|
import { Target } from '@overflow/commons-typescript/model/target';
|
|
|
|
import { Infra } from '@overflow/commons-typescript/model/infra';
|
|
|
|
import { MetaCrawler } from '@overflow/commons-typescript/model/meta';
|
|
|
|
import { MetaSensorDisplayItem } from '@overflow/commons-typescript/model/meta';
|
2018-04-11 12:54:05 +00:00
|
|
|
|
2018-05-10 08:56:30 +00:00
|
|
|
import { Store, select, StateObservable } from '@ngrx/store';
|
2018-05-24 06:44:13 +00:00
|
|
|
import { RPCClientError } from '@loafer/ng-rpc';
|
|
|
|
import * as SensorItemKeyListStore from '@overflow/sensor-item/store/key-list';
|
|
|
|
import { ReadSensorItemKeySelector } from '@overflow/sensor-item/store';
|
2018-05-02 08:09:39 +00:00
|
|
|
import { MetaSensorItemKey } from '@overflow/commons-typescript/model/meta';
|
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-13 08:59:48 +00:00
|
|
|
@Input() preTarget: Target;
|
2018-04-12 09:54:15 +00:00
|
|
|
@Output() close = new EventEmitter();
|
2018-05-10 08:56:30 +00:00
|
|
|
@Input() visible: boolean;
|
|
|
|
@Input() editMode: boolean;
|
2018-04-13 08:59:48 +00:00
|
|
|
|
2018-04-12 09:54:15 +00:00
|
|
|
nextable = false;
|
2018-04-13 08:59:48 +00:00
|
|
|
selectedTarget: Target;
|
2018-04-12 09:54:15 +00:00
|
|
|
selectedCrawler: MetaCrawler;
|
|
|
|
credentialPassed: boolean;
|
|
|
|
selectedSensorDisplayItems: MetaSensorDisplayItem[];
|
|
|
|
itemNodes: TreeNode[];
|
2018-04-13 11:37:05 +00:00
|
|
|
step = 0;
|
2018-04-16 03:52:51 +00:00
|
|
|
page = 1;
|
2018-04-11 12:54:05 +00:00
|
|
|
|
2018-05-10 08:56:30 +00:00
|
|
|
sensorItemKeys$: StateObservable;
|
2018-04-13 08:59:48 +00:00
|
|
|
|
|
|
|
|
2018-04-11 12:54:05 +00:00
|
|
|
constructor(
|
2018-05-10 08:56:30 +00:00
|
|
|
private keyListStore: Store<SensorItemKeyListStore.State>
|
2018-04-11 12:54:05 +00:00
|
|
|
) {
|
2018-05-10 08:56:30 +00:00
|
|
|
keyListStore.pipe(select(ReadSensorItemKeySelector.select('list')));
|
|
|
|
this.editMode = true;
|
2018-04-11 12:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2018-04-13 11:37:05 +00:00
|
|
|
this.step = this.preTarget ? 1 : 0;
|
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-13 08:59:48 +00:00
|
|
|
ngOnChanges(changes) {
|
2018-04-13 11:37:05 +00:00
|
|
|
this.step = this.preTarget ? 1 : 0;
|
2018-04-12 12:13:19 +00:00
|
|
|
}
|
|
|
|
|
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() {
|
2018-04-16 03:52:51 +00:00
|
|
|
this.page = 1;
|
2018-04-13 11:37:05 +00:00
|
|
|
this.step = 0;
|
|
|
|
this.visible = false;
|
|
|
|
this.nextable = false;
|
2018-04-13 08:59:48 +00:00
|
|
|
this.selectedTarget = null;
|
|
|
|
this.selectedCrawler = null;
|
|
|
|
this.credentialPassed = false;
|
|
|
|
this.selectedSensorDisplayItems = null;
|
2018-04-12 09:54:15 +00:00
|
|
|
this.close.emit();
|
|
|
|
}
|
|
|
|
|
|
|
|
onNext() {
|
2018-04-16 03:52:51 +00:00
|
|
|
this.page += 1;
|
2018-04-12 12:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onPrev() {
|
2018-04-16 03:52:51 +00:00
|
|
|
this.page -= 1;
|
2018-04-12 12:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2018-04-13 11:37:05 +00:00
|
|
|
this.step = 1;
|
2018-04-12 09:54:15 +00:00
|
|
|
}
|
|
|
|
onCrawlerSelect(c: MetaCrawler) {
|
|
|
|
this.selectedCrawler = c;
|
2018-04-13 11:37:05 +00:00
|
|
|
this.step = 2;
|
2018-04-12 09:54:15 +00:00
|
|
|
}
|
|
|
|
onCredentialPass(b: boolean) {
|
2018-04-13 11:37:05 +00:00
|
|
|
if (!b) {
|
|
|
|
return;
|
|
|
|
}
|
2018-04-12 09:54:15 +00:00
|
|
|
this.credentialPassed = b;
|
2018-04-13 11:37:05 +00:00
|
|
|
this.step = 3;
|
2018-04-12 09:54:15 +00:00
|
|
|
}
|
|
|
|
onItemsSelect(nodes: TreeNode[]) {
|
|
|
|
this.itemNodes = nodes;
|
2018-04-11 12:54:05 +00:00
|
|
|
}
|
2018-04-13 11:37:05 +00:00
|
|
|
|
|
|
|
onTabOpen(event) {
|
|
|
|
this.step = event.index;
|
|
|
|
}
|
|
|
|
|
|
|
|
getTitle(index) {
|
|
|
|
if (index === 0 && this.preTarget) {
|
|
|
|
return this.preTarget.displayName;
|
|
|
|
}
|
|
|
|
let title = '';
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
|
|
|
title = this.selectedTarget && this.step !== index ?
|
|
|
|
this.selectedTarget.displayName :
|
|
|
|
'Choose a Target to monitor.';
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
title = this.selectedCrawler && this.step !== index ?
|
|
|
|
this.selectedCrawler.name :
|
|
|
|
'Choose a Crawler.';
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
title = this.credentialPassed && this.step !== index ?
|
|
|
|
'Credentials test succeed.' :
|
|
|
|
'Credentials';
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
title = 'Choose Sensor Items.';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return title;
|
|
|
|
}
|
2018-04-11 12:54:05 +00:00
|
|
|
}
|