From 9b2ceb347a3371819fcad6bbe2268203afecaf4e Mon Sep 17 00:00:00 2001 From: "Stone, Avi (as206k)" Date: Thu, 12 Apr 2018 16:36:39 +0300 Subject: DCAE-D fe initial commit DCAE-D fe initial commit Change-Id: Ica8ccb7c7ef769c969664d1e168d205eb9fc67f2 Issue-ID: SDC-1218 Signed-off-by: Stone, Avi (as206k) --- .../rule-engine/rule-list/rule-list.component.ts | 197 +++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 public/src/app/rule-engine/rule-list/rule-list.component.ts (limited to 'public/src/app/rule-engine/rule-list/rule-list.component.ts') diff --git a/public/src/app/rule-engine/rule-list/rule-list.component.ts b/public/src/app/rule-engine/rule-list/rule-list.component.ts new file mode 100644 index 0000000..45cfbd0 --- /dev/null +++ b/public/src/app/rule-engine/rule-list/rule-list.component.ts @@ -0,0 +1,197 @@ +import { Component, ViewEncapsulation, ViewChild } from '@angular/core'; +import { MatDialog } from '@angular/material'; +import { ActionListComponent } from '../action-list/action-list.component'; +import { RuleEngineApiService } from '../api/rule-engine-api.service'; +import { ConfirmPopupComponent } from '../confirm-popup/confirm-popup.component'; +import { Store } from '../../store/store'; +import { isEmpty } from 'lodash'; +import { ToastrService } from 'ngx-toastr'; +import { timer } from 'rxjs/observable/timer'; + +const primaryColor = '#009fdb'; + +@Component({ + selector: 'app-rule-list', + templateUrl: './rule-list.component.html', + styleUrls: ['./rule-list.component.scss'], + encapsulation: ViewEncapsulation.None +}) +export class RuleListComponent { + @ViewChild('versionEventType') versionType; + error: Array; + // list = new Array(); + schema; + targetSource; + dialogRef; + crud; + hoveredIndex; + params; + versions; + metaData; + + private errorHandler(error: any) { + this.store.loader = false; + console.log(error); + this.error = []; + if (typeof error === 'string') { + this.error.push(error); + } else { + console.log(error.notes); + const errorFromServer = Object.values(error)[0] as any; + if (Object.keys(error)[0] === 'serviceExceptions') { + this.error = errorFromServer.map(x => x.formattedErrorMessage); + } else { + this.error = errorFromServer.formattedErrorMessage; + } + } + } + + private getListOfRules() { + this._ruleApi.getListOfRules().subscribe( + response => { + console.log('res: %o', response); + if (response && Object.keys(response).length !== 0) { + this.versionType.updateData( + response.version, + response.eventType, + true + ); + this.store.updateRuleList(Object.values(response.rules)); + this.targetSource = response.schema; + } else { + this.store.resetRuleList(); + this.versionType.updateVersionTypeFlag(false); + this.targetSource = null; + // if the the list is empty then get version and domain events + this._ruleApi.getMetaData().subscribe(data => { + console.log(data); + this.versions = data.map(x => x.version); + this.metaData = data; + }); + } + this.store.loader = false; + }, + error => { + this.errorHandler(error); + } + ); + } + + constructor( + private _ruleApi: RuleEngineApiService, + public dialog: MatDialog, + private toastr: ToastrService, + public store: Store + ) { + this.store.loader = true; + this.params = { + vfcmtUuid: this.store.mcUuid, + nodeName: this.store.tabParmasForRule[0].name, + nodeId: this.store.tabParmasForRule[0].nid, + fieldName: this.store.configurationForm[0].name, + userId: 'ym903w', // this.store.sdcParmas.userId + flowType: this.store.cdump.flowType + }; + console.log('params: %o', this.params); + this.store.loader = true; + // set api params by iframe url query + this._ruleApi.setParams(this.params); + this.getListOfRules(); + } + + handlePropertyChange() { + this.store.loader = true; + this.error = null; + this.getListOfRules(); + } + + translateRules() { + this.store.loader = true; + // send translate JSON + this._ruleApi.translate().subscribe( + data => { + this.store.loader = false; + console.log(JSON.stringify(data)); + let domElementName: string; + this.store.configurationForm.forEach(property => { + console.log('mappingTarget ', this.versionType.mappingTarget); + if (property.name === this.versionType.mappingTarget) { + property.assignment.value = JSON.stringify(data); + domElementName = property.name; + console.log(property.name); + } + }); + this.toastr.success('', 'Translate succeeded'); + this.store.expandAdvancedSetting[this.store.tabIndex] = true; + const source = timer(500); + source.subscribe(val => { + const el = document.getElementById(domElementName); + const label = el.children.item(0) as HTMLElement; + label.style.color = primaryColor; + const input = el.children.item(1) as HTMLElement; + input.style.color = primaryColor; + input.style.borderColor = primaryColor; + el.scrollIntoView(); + }); + }, + error => { + this.errorHandler(error); + } + ); + } + + handleUpdateNode(data) { + this.targetSource = data.nodes; + this.store.resetRuleList(); + } + + removeItem(uid) { + this.dialogRef = this.dialog.open(ConfirmPopupComponent, { + panelClass: 'my-confrim-dialog', + disableClose: true + }); + this.dialogRef.afterClosed().subscribe(result => { + // if the user want to delete + if (result) { + // call be api + this.store.loader = true; + this._ruleApi.deleteRule(uid).subscribe( + success => { + this.store.removeRuleFromList(uid); + // if its the last rule + if (this.store.ruleList.length === 0) { + this._ruleApi.getMetaData().subscribe(data => { + console.log(data); + this.versions = data.map(x => x.version); + this.metaData = data; + this.versionType.updateVersionTypeFlag(false); + this.targetSource = null; + }); + } + this.store.loader = false; + }, + error => { + this.store.loader = false; + this.errorHandler(error); + } + ); + } + }); + } + + openAction(item): void { + this.crud = isEmpty(item) ? 'new' : 'edit'; + this._ruleApi.passDataToEditor({ + version: this.versionType.selectedVersion, + eventType: this.versionType.selectedEvent, + targetSource: this.targetSource, + item: isEmpty(item) ? null : item, + params: this.params + }); + this.store.isLeftVisible = false; + + this._ruleApi.updateVersionLock.subscribe(() => { + this.versionType.updateVersionTypeFlag(true); + }); + } +} -- cgit 1.2.3-korg