summaryrefslogtreecommitdiffstats
path: root/public/src/app/rule-engine/action-list/action-list.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'public/src/app/rule-engine/action-list/action-list.component.ts')
-rw-r--r--public/src/app/rule-engine/action-list/action-list.component.ts319
1 files changed, 250 insertions, 69 deletions
diff --git a/public/src/app/rule-engine/action-list/action-list.component.ts b/public/src/app/rule-engine/action-list/action-list.component.ts
index 27a74d4..f8fd6dd 100644
--- a/public/src/app/rule-engine/action-list/action-list.component.ts
+++ b/public/src/app/rule-engine/action-list/action-list.component.ts
@@ -6,11 +6,12 @@ import {
ViewChildren
} from '@angular/core';
import { NgForm } from '@angular/forms';
-import { cloneDeep } from 'lodash';
+import { cloneDeep, isEmpty } from 'lodash';
import { v1 as uuid } from 'uuid';
import { Store } from '../../store/store';
import { ActionComponent } from '../action/action.component';
import { RuleEngineApiService } from '../api/rule-engine-api.service';
+import { toJS } from 'mobx';
@Component({
selector: 'app-action-list',
@@ -23,6 +24,10 @@ export class ActionListComponent implements AfterViewInit {
condition: any;
eventType: string;
version: string;
+ entryPhase: string;
+ publishPhase: string;
+ groupId: string;
+ phase: string;
params;
selectedAction;
targetSource;
@@ -30,17 +35,29 @@ export class ActionListComponent implements AfterViewInit {
actions = new Array();
ifStatement = false;
uid = '';
+ isEnrich = false;
+ hoveredIndex = -1;
backupActionForCancel = new Array();
@ViewChild('actionListFrm') actionListFrm: NgForm;
- @ViewChild('condition') conditionRef;
+ @ViewChild('conditions') conditionRef;
@ViewChildren('actions') actionsRef: QueryList<ActionComponent>;
constructor(private _ruleApi: RuleEngineApiService, public store: Store) {
+ this.error = null;
this._ruleApi.editorData.subscribe(data => {
this.params = data.params;
console.log('update.. params', data.params);
this.targetSource = data.targetSource;
this.version = data.version;
+ this.groupId = data.groupId;
+ this.isEnrich =
+ !isEmpty(data.groupId) &&
+ data.groupId.substring(0, 1).toLowerCase() === 'e'
+ ? true
+ : false;
+ this.entryPhase = data.entryPhase;
+ this.publishPhase = data.publishPhase;
+ this.phase = data.phase;
this.eventType = data.eventType;
if (data.item) {
// edit mode set values to attributes
@@ -66,25 +83,46 @@ export class ActionListComponent implements AfterViewInit {
}
convertActionDataFromServer(actions) {
- return actions.map(item => {
- if (!item.hasOwnProperty('nodes')) {
- return Object.assign({}, item, { nodes: this.targetSource });
- }
- });
+ return actions
+ .map(item => {
+ if (!item.hasOwnProperty('nodes')) {
+ return Object.assign({}, item, { nodes: this.targetSource });
+ }
+ })
+ .map(item => {
+ if (item.hasOwnProperty('search')) {
+ console.log(toJS(item.search.enrich.fields));
+ console.log(toJS(item.search.updates));
+
+ return Object.assign({}, item, {
+ search: {
+ enrich: {
+ fields: toJS(item.search.enrich.fields),
+ prefix: item.search.enrich.prefix
+ },
+ radio: item.search.radio,
+ searchField: item.search.searchField,
+ searchFilter: {
+ left: item.search.searchFilter.left,
+ operator: item.search.searchFilter.operator,
+ right: toJS(item.search.searchFilter.right)
+ },
+ searchValue: item.search.searchValue,
+ updates: toJS(item.search.updates)
+ }
+ });
+ } else {
+ return item;
+ }
+ });
}
ngAfterViewInit() {
- // console.log(this.actionsRef.toArray());
- if (this.condition) {
- if (this.condition.name === 'condition') {
- this.conditionRef.updateMode(true, this.condition);
- } else {
- const convertedCondition = this.convertConditionFromServer(
- this.condition
- );
- this.conditionRef.updateMode(false, convertedCondition);
- }
- }
+ // console.log(this.actionsRef.toArray()); if (this.condition) { if
+ // (this.condition.name === 'condition') { this .conditionRef
+ // .updateMode(true, this.condition); } else { const convertedCondition =
+ // this.convertConditionFromServer(this.condition); this .conditionRef
+ // .updateMode(false, convertedCondition); } }
}
addAction2list(selectedAction) {
@@ -134,6 +172,36 @@ export class ActionListComponent implements AfterViewInit {
},
logEvent: {
title: ''
+ },
+ selectedHpMetric: '',
+ stringTransform: {
+ startValue: '',
+ targetCase: '',
+ isTrimString: false
+ },
+ search: {
+ searchField: '',
+ searchValue: '',
+ searchFilter: {
+ left: '',
+ right: '',
+ operator: null
+ },
+ radio: 'updates',
+ enrich: {
+ fields: [
+ {
+ value: ''
+ }
+ ],
+ prefix: ''
+ },
+ updates: [
+ {
+ key: '',
+ value: ''
+ }
+ ]
}
});
}
@@ -149,6 +217,20 @@ export class ActionListComponent implements AfterViewInit {
});
}
+ copyAction(action, index) {
+ const tmpAction = cloneDeep(action);
+ tmpAction.id = uuid();
+ tmpAction.target =
+ typeof tmpAction.selectedNode === 'string'
+ ? tmpAction.selectedNode
+ : typeof tmpAction.selectedNode === 'undefined'
+ ? tmpAction.target
+ : tmpAction.selectedNode.id;
+ // this .actions .splice(index, 0, tmpAction);
+ this.actions.push(tmpAction);
+ console.log(this.actions);
+ }
+
updateCondition(data) {
this.condition = data;
}
@@ -176,6 +258,10 @@ export class ActionListComponent implements AfterViewInit {
const actionSetData = this.actions.map(item => {
return {
id: item.id,
+ entryPhase: item.entryPhase,
+ publishPhase: item.publishPhase,
+ groupId: item.groupId,
+ phase: item.phase,
actionType: item.actionType,
from: item.from,
target:
@@ -188,7 +274,70 @@ export class ActionListComponent implements AfterViewInit {
dateFormatter: item.dateFormatter,
replaceText: item.replaceText,
logText: item.logText,
- logEvent: item.logEvent
+ logEvent: item.logEvent,
+ selectedHpMetric: item.selectedHpMetric,
+ stringTransform: {
+ startValue:
+ item.stringTransform !== undefined
+ ? item.stringTransform.startValue
+ : '',
+ targetCase:
+ item.stringTransform !== undefined
+ ? item.stringTransform.targetCase
+ : '',
+ isTrimString:
+ item.stringTransform !== undefined
+ ? item.stringTransform.isTrimString
+ : false
+ },
+ search: {
+ searchField: item.search !== undefined ? item.search.searchField : '',
+ searchValue: item.search !== undefined ? item.search.searchValue : '',
+ searchFilter: {
+ left:
+ item.search !== undefined ? item.search.searchFilter.left : '',
+ right:
+ item.search !== undefined
+ ? typeof item.search.searchFilter.right === 'string'
+ ? item.search.searchFilter.right.split(',')
+ : item.search.searchFilter.right
+ : [],
+ operator:
+ item.search !== undefined
+ ? item.search.searchFilter.operator
+ : null
+ },
+ radio: item.search !== undefined ? item.search.radio : 'updates',
+ enrich: {
+ fields:
+ item.search !== undefined
+ ? item.search.radio === 'enrich'
+ ? item.search.enrich.fields
+ : [
+ {
+ value: ''
+ }
+ ]
+ : '',
+ prefix:
+ item.search !== undefined
+ ? item.search.radio === 'enrich'
+ ? item.search.enrich.prefix
+ : ''
+ : ''
+ },
+ updates:
+ item.search !== undefined
+ ? item.search.radio === 'updates'
+ ? item.search.updates
+ : [
+ {
+ key: '',
+ value: ''
+ }
+ ]
+ : []
+ }
};
});
let conditionData2server = null;
@@ -208,7 +357,11 @@ export class ActionListComponent implements AfterViewInit {
uid: this.uid,
description: this.description,
actions: actionSetData,
- condition: this.ifStatement ? conditionData2server : null
+ condition: this.ifStatement ? conditionData2server : null,
+ entryPhase: this.entryPhase,
+ publishPhase: this.publishPhase,
+ groupId: this.groupId,
+ phase: this.phase
};
}
@@ -230,51 +383,90 @@ export class ActionListComponent implements AfterViewInit {
}
saveAndDone() {
- const data = this.prepareDataToSaveRule();
- this.store.loader = true;
- this._ruleApi.modifyRule(data).subscribe(
- response => {
- this.store.loader = false;
- this.store.updateRuleInList(response);
- this._ruleApi.callUpdateVersionLock();
- this.store.isLeftVisible = true;
- },
- error => {
- this.errorHandler(error);
- },
- () => {
- this.store.loader = false;
- }
- );
+ this.error = null;
+ const actionComp = this.actionsRef.toArray();
+ const filterInvalidActions = actionComp.filter(comp => {
+ return comp.actionFrm && comp.actionFrm.invalid;
+ });
+ if (this.actionListFrm.valid && filterInvalidActions.length === 0) {
+ const data = this.prepareDataToSaveRule();
+ this.store.loader = true;
+
+ this._ruleApi
+ .getLatestMcUuid({
+ contextType: this.store.sdcParmas.contextType,
+ serviceUuid: this.store.sdcParmas.uuid,
+ vfiName: this.store.vfiName,
+ vfcmtUuid: this.store.mcUuid
+ })
+ .subscribe(
+ res => {
+ this.store.mcUuid = res.uuid;
+ this._ruleApi.modifyRule(data, res.uuid).subscribe(
+ response => {
+ // clear temp copy rule.
+ this.clearCopyRuleFromList();
+ // then update the rule list and sync with server
+ this.store.updateRuleInList(response);
+ this._ruleApi.callUpdateVersionLock();
+ this.store.loader = false;
+ this.store.isLeftVisible = true;
+ },
+ error => {
+ this.errorHandler(error);
+ },
+ () => {}
+ );
+ },
+ error => this.errorHandler(error),
+ () => {}
+ );
+ }
+ }
+
+ private clearCopyRuleFromList() {
+ this.store.ruleList = this.store.ruleList.filter(item => item.uid !== '');
}
saveRole() {
+ this.error = null;
const actionComp = this.actionsRef.toArray();
const filterInvalidActions = actionComp.filter(comp => {
- return (
- // (comp.fromInstance && comp.fromInstance.fromFrm.invalid) ||
- // (comp.targetInstance && comp.targetInstance.targetFrm.invalid) ||
- comp.actionFrm && comp.actionFrm.invalid
- );
+ return comp.actionFrm && comp.actionFrm.invalid;
});
- if (this.actionListFrm.valid && filterInvalidActions.length == 0) {
+ if (this.actionListFrm.valid && filterInvalidActions.length === 0) {
const data = this.prepareDataToSaveRule();
this.store.loader = true;
- this._ruleApi.modifyRule(data).subscribe(
- response => {
- this.store.loader = false;
- this.store.updateRuleInList(response);
- this._ruleApi.callUpdateVersionLock();
- this.uid = response.uid;
- // add toast notification
- },
- error => {
- this.errorHandler(error);
- },
- () => {
- this.store.loader = false;
- }
- );
+ this._ruleApi
+ .getLatestMcUuid({
+ contextType: this.store.sdcParmas.contextType,
+ serviceUuid: this.store.sdcParmas.uuid,
+ vfiName: this.store.vfiName,
+ vfcmtUuid: this.store.mcUuid
+ })
+ .subscribe(
+ res => {
+ this.store.mcUuid = res.uuid;
+ this._ruleApi.modifyRule(data, res.uuid).subscribe(
+ response => {
+ // clear temp copy rule.
+ this.clearCopyRuleFromList();
+ // then update the rule list and sync with server
+ this.store.updateRuleInList(response);
+ this._ruleApi.callUpdateVersionLock();
+ this.uid = response.uid;
+ // add toast notification
+ this.store.loader = false;
+ },
+ error => {
+ this.errorHandler(error);
+ },
+ () => {}
+ );
+ },
+ error => this.errorHandler(error),
+ () => {}
+ );
} else {
// scroll to first invalid element const elId =
// filterInvalidActions[0].action.id; const el = document.getElementById(elId as
@@ -283,18 +475,6 @@ export class ActionListComponent implements AfterViewInit {
}
}
- public convertConditionFromServer(condition) {
- const temp = new Array();
- temp.push(condition);
- const cloneCondition = cloneDeep(temp);
- const conditionSetData = this.changeRightToArrayOrString(
- cloneCondition,
- false
- );
- console.log('condition to server:', conditionSetData);
- return conditionSetData;
- }
-
public convertConditionToServer(tree) {
const cloneCondition = cloneDeep(tree);
const conditionSetData = this.changeRightToArrayOrString(
@@ -311,6 +491,7 @@ export class ActionListComponent implements AfterViewInit {
closeDialog(): void {
this.actions = this.backupActionForCancel;
+ this.clearCopyRuleFromList();
this.store.isLeftVisible = true;
}
}