-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): changes condition script for passed by and coming in clauses #14
base: master
Are you sure you want to change the base?
Changes from 10 commits
ba583b0
b22334b
d5beb73
1b517c4
5851aab
0500568
422ffd6
315d7a5
5336a42
27880b4
b8d2878
090187c
242eaeb
2a7d458
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,16 @@ import { | |
} from '../classes'; | ||
import {AbstractBaseGroup} from '../classes/nodes'; | ||
import {BuilderService, ElementService, NodeService} from '../classes/services'; | ||
import {EventTypes, LocalizedStringKeys, NodeTypes, ValueTypes} from '../enum'; | ||
import { | ||
ActionTypes, | ||
ConditionTypes, | ||
EventTypes, | ||
LocalizedStringKeys, | ||
NUMBER, | ||
NodeTypes, | ||
NotificationRecipientTypesEnum, | ||
ValueTypes, | ||
} from '../enum'; | ||
import {InvalidEntityError} from '../errors/base.error'; | ||
import { | ||
ActionAddition, | ||
|
@@ -38,6 +47,11 @@ import { | |
WorkflowNode, | ||
} from '../types'; | ||
import {LocalizationProviderService} from '../services/localization-provider.service'; | ||
import { | ||
ReadColumnValue, | ||
TriggerWhenColumnChanges, | ||
} from '../services/bpmn/elements/tasks'; | ||
import {GatewayElement} from '../services/bpmn/elements/gateways'; | ||
|
||
@Component({ | ||
selector: 'workflow-builder', | ||
|
@@ -78,7 +92,7 @@ export class BuilderComponent<E> implements OnInit, OnChanges { | |
stateChange = new EventEmitter<StateMap<RecordOfAnyType>>(); | ||
|
||
@Output() | ||
diagramChange = new EventEmitter<string>(); | ||
diagramChange = new EventEmitter<Object>(); | ||
|
||
@Output() | ||
eventAdded = new EventEmitter<EventAddition<E>>(); | ||
|
@@ -217,7 +231,7 @@ export class BuilderComponent<E> implements OnInit, OnChanges { | |
this.updateDiagram(); | ||
this.updateState(event.node, event.newNode.inputs); | ||
this.elseBlockHidden = | ||
!this.eventGroups[0]?.children?.length && | ||
this.eventGroups[0]?.children?.length === 1 && | ||
(event.node.getIdentifier() === EventTypes.OnIntervalEvent || | ||
event.node.getIdentifier() === EventTypes.OnAddItemEvent); | ||
} | ||
|
@@ -226,16 +240,9 @@ export class BuilderComponent<E> implements OnInit, OnChanges { | |
* The function is called when an event is removed from the workflow. | ||
* Hides the else block when it is not needed. | ||
*/ | ||
onEventRemoved() { | ||
const events = this.eventGroups[0].children; | ||
|
||
this.elseBlockHidden = | ||
events.length === 1 && | ||
(events[0].node.getIdentifier() === EventTypes.OnIntervalEvent || | ||
events[0].node.getIdentifier() === EventTypes.OnAddItemEvent || | ||
(events[0].node.getIdentifier() === EventTypes.OnChangeEvent && | ||
(events[0].node.state.get('value') === ValueTypes.AnyValue || | ||
events[0].node.state.get('valueType') === ValueTypes.AnyValue))); | ||
onNodeRemoved() { | ||
this.updateDiagram(); | ||
if (this.eventGroups[0]?.children?.length) this.hideElseBlockIfRequired(); | ||
} | ||
|
||
/** | ||
|
@@ -264,19 +271,32 @@ export class BuilderComponent<E> implements OnInit, OnChanges { | |
item: item.element.node, | ||
}); | ||
this.updateState(item.element.node, item.element.inputs); | ||
// TODO: to be refactored | ||
// to hide else block when anything is selected in ValueInput or ValueTypeInput | ||
this.elseBlockHidden = | ||
this.eventGroups[0].children?.length === 1 && | ||
this.eventGroups[0].children[0].node.getIdentifier() === | ||
EventTypes.OnChangeEvent && | ||
(this.eventGroups[0].children[0].node.state.get('value') === | ||
ValueTypes.AnyValue || | ||
this.eventGroups[0].children[0].node.state.get('valueType') === | ||
ValueTypes.AnyValue); | ||
this.hideElseBlockIfRequired(); | ||
this.updateDiagram(); | ||
} | ||
|
||
/** | ||
* This function checks if the else block should be hidden based on the type and number of events in | ||
* the event group. | ||
*/ | ||
hideElseBlockIfRequired() { | ||
const events = this.eventGroups[0].children; | ||
let value = events[0].node.state.get('value'); | ||
if (typeof value === 'object') { | ||
value = value.value; | ||
} | ||
if (events.length !== 1) { | ||
this.elseBlockHidden = false; | ||
} else { | ||
this.elseBlockHidden = | ||
events[0].node.getIdentifier() === EventTypes.OnIntervalEvent || | ||
events[0].node.getIdentifier() === EventTypes.OnAddItemEvent || | ||
(events[0].node.getIdentifier() === EventTypes.OnChangeEvent && | ||
(value === ValueTypes.AnyValue || | ||
events[0].node.state.get('valueType') === ValueTypes.AnyValue)); | ||
} | ||
} | ||
|
||
/** | ||
* "If the type is a group, then get the groups, otherwise throw an error." | ||
* | ||
|
@@ -346,6 +366,30 @@ export class BuilderComponent<E> implements OnInit, OnChanges { | |
value: AllowedValues | AllowedValuesMap, | ||
select = false, | ||
) { | ||
if ( | ||
(input.getIdentifier() === 'ValueTypeInput' || | ||
input.getIdentifier() === 'ValueInput') && | ||
element.node.getIdentifier() === 'OnChangeEvent' | ||
) { | ||
if ( | ||
((value as AllowedValuesMap)?.value as AllowedValuesMap)?.value === | ||
ValueTypes.AnyValue | ||
) { | ||
/** | ||
* Remove node on changes event | ||
*/ | ||
element.node.elements.splice(-NUMBER.TWO, NUMBER.TWO); | ||
// element.inputs[1].prefix = ''; | ||
//this.enableActionIcon = false; | ||
} else { | ||
element.node.elements = [ | ||
TriggerWhenColumnChanges.identifier, | ||
ReadColumnValue.identifier, | ||
GatewayElement.identifier, | ||
]; | ||
} | ||
} | ||
|
||
if (select && isSelectInput(input)) { | ||
element.node.state.change( | ||
`${input.inputKey}Name`, | ||
|
@@ -429,8 +473,55 @@ export class BuilderComponent<E> implements OnInit, OnChanges { | |
* It builds a new diagram, emits the new diagram, and then tells Angular to update the view | ||
*/ | ||
async updateDiagram() { | ||
const nodes = [ | ||
...this.eventGroups[0].children, | ||
...this.actionGroups[0].children, | ||
...this.elseActionGroups[0].children, | ||
]; | ||
let isValid = | ||
!!this.eventGroups[0].children.length && | ||
(!!this.actionGroups[0].children.length || | ||
!!this.elseActionGroups[0].children.length); | ||
if (isValid) { | ||
for (const node of nodes) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for validation, we can use a separate service that gets the current state of diagram and just returns true or false and use that here, and this should be based on the default inputs provided. Anyone using the library should be able to replace it to write there own logic according to there own custom events/actions/inputs |
||
switch (node.node.getIdentifier()) { | ||
case EventTypes.OnChangeEvent: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as mentioned, the builder component should not have any code specific to event types |
||
case EventTypes.OnValueEvent: | ||
case ActionTypes.ChangeColumnValueAction: | ||
const columnExists = !!node.node.state.get('column'); | ||
const valueExists = | ||
node.node.state.get('condition') === ConditionTypes.PastToday | ||
? true | ||
: !!node.node.state.get('value'); | ||
const valueTypeIsAnyValue = | ||
node.node.state.get('valueType') === ValueTypes.AnyValue; | ||
isValid = columnExists && (valueExists || valueTypeIsAnyValue); | ||
break; | ||
case EventTypes.OnIntervalEvent: | ||
const intervalExists = !!node.node.state.get('interval'); | ||
const intervalValueExists = !!node.node.state.get('value'); | ||
isValid = intervalValueExists && intervalExists; | ||
break; | ||
case ActionTypes.SendEmailAction: | ||
const email = !!node.node.state.get('email'); | ||
const emailTo = !!node.node.state.get('emailTo'); | ||
const specificRecipientsRequired = [ | ||
NotificationRecipientTypesEnum.NotifySpecificColumn, | ||
NotificationRecipientTypesEnum.NotifySpecificPeople, | ||
].includes(node.node.state.get('emailTo')); | ||
const recipients = !!node.node.state.get('specificRecepient'); | ||
isValid = specificRecipientsRequired | ||
? email && emailTo && recipients | ||
: email && emailTo; | ||
break; | ||
} | ||
if (!isValid) { | ||
break; // exit the loop since we found an invalid input | ||
} | ||
} | ||
} | ||
this.diagram = await this.build(); | ||
this.diagramChange.emit(this.diagram); | ||
this.diagramChange.emit({diagram: this.diagram, isValid: isValid}); | ||
this.cdr.detectChanges(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should ideally not have any reference to input type here in this component