Skip to content

Commit 76a96fa

Browse files
committed
feat(core): changes condition script for passed by and coming in clauses
1 parent a44c298 commit 76a96fa

32 files changed

+515
-76
lines changed

projects/workflows-creator/src/lib/builder/builder.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
(add)="openPopup(types.GROUP)"
1212
(remove)="onGroupRemove(i)"
1313
(eventAdded)="onEventAdded($event)"
14-
(eventRemoved)="onEventRemoved()"
14+
(nodeRemoved)="onNodeRemoved()"
1515
(actionAdded)="onActionAdded($event)"
1616
(itemChanged)="onItemChanged($event)"
1717
></workflow-group>
@@ -30,6 +30,7 @@
3030
[allColumns]="allColumns"
3131
(eventAdded)="onEventAdded($event)"
3232
(eventRemoved)="onEventRemoved()"
33+
(nodeRemoved)="onNodeRemoved()"
3334
(actionAdded)="onActionAdded($event)"
3435
(itemChanged)="onItemChanged($event)"
3536
></workflow-group>

projects/workflows-creator/src/lib/builder/builder.component.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
}
2727
}
2828
.container {
29-
min-width: 46%;
29+
min-width: 52%;
3030
max-width: max-content;
3131
color: rgb(50, 51, 56);
3232
margin: auto;

projects/workflows-creator/src/lib/builder/builder.component.ts

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
ConditionTypes,
2727
EventTypes,
2828
LocalizedStringKeys,
29+
NUMBER,
2930
NodeTypes,
3031
NotificationRecipientTypesEnum,
3132
ValueTypes,
@@ -48,6 +49,12 @@ import {
4849
} from '../types';
4950
import {LocalizationProviderService} from '../services/localization-provider.service';
5051
import {LocalizationPipe} from '../pipes/localization.pipe';
52+
import {
53+
ReadColumnValue,
54+
TriggerWhenColumnChanges,
55+
} from '../services/bpmn/elements/tasks';
56+
import {GatewayElement} from '../services/bpmn/elements/gateways';
57+
5158
@Component({
5259
selector: 'workflow-builder',
5360
templateUrl: './builder.component.html',
@@ -107,6 +114,7 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
107114
stateChange = new EventEmitter<StateMap<RecordOfAnyType>>();
108115
@Output()
109116
diagramChange = new EventEmitter<Object>();
117+
110118
@Output()
111119
eventAdded = new EventEmitter<EventAddition<E>>();
112120
@Output()
@@ -276,7 +284,7 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
276284
this.updateDiagram();
277285
this.updateState(event.node, event.newNode.inputs);
278286
this.elseBlockHidden =
279-
!this.eventGroups[0]?.children?.length &&
287+
this.eventGroups[0]?.children?.length === 1 &&
280288
(event.node.getIdentifier() === EventTypes.OnIntervalEvent ||
281289
event.node.getIdentifier() === EventTypes.OnAddItemEvent);
282290
}
@@ -295,6 +303,11 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
295303
events[0].node.state.get('valueType') === ValueTypes.AnyValue)));
296304
this.updateDiagram();
297305
}
306+
307+
onNodeRemoved() {
308+
this.updateDiagram();
309+
if (this.eventGroups[0]?.children?.length) this.hideNodeElseBlockIfRequired();
310+
}
298311
/**
299312
* When an action is added, emit an event with the name of the action and the action itself, update
300313
* the diagram, and update the state of the action
@@ -321,9 +334,31 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
321334
item: item.element.node,
322335
});
323336
this.updateState(item.element.node, item.element.inputs);
324-
this.hideElseBlockIfRequired();
337+
this.hideNodeElseBlockIfRequired();
325338
this.updateDiagram();
326339
}
340+
/**
341+
* This function checks if the else block should be hidden based on the type and number of events in
342+
* the event group.
343+
*/
344+
hideNodeElseBlockIfRequired() {
345+
const events = this.eventGroups[0].children;
346+
let value = events[0].node.state.get('value');
347+
if (typeof value === 'object') {
348+
value = value.value;
349+
}
350+
if (events.length !== 1) {
351+
this.elseBlockHidden = false;
352+
} else {
353+
this.elseBlockHidden =
354+
events[0].node.getIdentifier() === EventTypes.OnIntervalEvent ||
355+
events[0].node.getIdentifier() === EventTypes.OnAddItemEvent ||
356+
(events[0].node.getIdentifier() === EventTypes.OnChangeEvent &&
357+
(value === ValueTypes.AnyValue ||
358+
events[0].node.state.get('valueType') === ValueTypes.AnyValue));
359+
}
360+
}
361+
327362
/**
328363
* "If the type is a group, then get the groups, otherwise throw an error."
329364
*
@@ -391,6 +426,31 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
391426
value: AllowedValues | AllowedValuesMap,
392427
select = false,
393428
) {
429+
if (
430+
(input.getIdentifier() === 'ValueTypeInput' ||
431+
input.getIdentifier() === 'ValueInput') &&
432+
element.node.getIdentifier() === 'OnChangeEvent'
433+
) {
434+
if (
435+
((value as AllowedValuesMap)?.value as AllowedValuesMap)?.value ===
436+
ValueTypes.AnyValue ||
437+
(value as AllowedValuesMap)?.value === ValueTypes.AnyValue
438+
) {
439+
/**
440+
* Remove node on changes event
441+
*/
442+
element.node.elements.splice(-NUMBER.TWO, NUMBER.TWO);
443+
// element.inputs[1].prefix = '';
444+
//this.enableActionIcon = false;
445+
} else {
446+
element.node.elements = [
447+
TriggerWhenColumnChanges.identifier,
448+
ReadColumnValue.identifier,
449+
GatewayElement.identifier,
450+
];
451+
}
452+
}
453+
394454
if (select && isSelectInput(input)) {
395455
element.node.state.change(
396456
`${input.inputKey}Name`,
@@ -496,9 +556,12 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
496556
} else {
497557
valueExists = !!node.node.state.get('value');
498558
}
499-
const valueTypeIsAnyValue =
500-
node.node.state.get('valueType') === ValueTypes.AnyValue;
501-
isValid = columnExists && (valueExists || valueTypeIsAnyValue);
559+
const valueTypeIsSufficient = [
560+
ValueTypes.AnyValue,
561+
ValueTypes.Today,
562+
ValueTypes.PastToday,
563+
].includes(node.node.state.get('valueType'));
564+
isValid = columnExists && (valueExists || valueTypeIsSufficient);
502565
break;
503566
case EventTypes.OnIntervalEvent:
504567
const intervalExists = !!node.node.state.get('interval');

projects/workflows-creator/src/lib/builder/group/group.component.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@
383383
let-appendEmailBody="appendEmailBody"
384384
let-setFocusKey="setFocusKey"
385385
let-hide="hide"
386+
let-setFocusOutPos="setFocusOutPos"
386387
>
387388
<div class="email-template" (document:click)="hide()">
388389
<input
@@ -391,14 +392,15 @@
391392
id="email-subject"
392393
autofocus
393394
(focus)="setFocusKey(emailInput, 'subject')"
395+
(focusout)="setFocusOutPos(emailInput, $event.target.selectionStart)"
394396
[placeholder]="typeSubjectPlaceholder"
395397
[(ngModel)]="emailInput.subject"
396398
/>
397399
<textarea
398400
[placeholder]="typeEmailPlaceholder"
399401
id="email-body"
400402
class="email-input email-body-input"
401-
(focus)="setFocusKey(emailInput, 'body')"
403+
(focusout)="setFocusOutPos(emailInput, $event.target.selectionStart)"
402404
[(ngModel)]="emailInput.body"
403405
></textarea>
404406
<div class="auto-populate">
@@ -414,7 +416,7 @@
414416
(click)="callback(emailInput)"
415417
[disabled]="!emailInput.subject || !emailInput.body"
416418
>
417-
{{ localizedStringKeys.SetLbl | localization }}
419+
{{ setLbl }}
418420
</button>
419421
</div>
420422
</div>

projects/workflows-creator/src/lib/builder/group/group.component.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ input[type="time"]:focus {
161161
.value-text {
162162
display: inline-block;
163163
overflow: hidden;
164-
max-width: 45%;
164+
max-width: 15rem;
165165
text-decoration: inherit;
166166
text-overflow: ellipsis;
167167
vertical-align: top;

projects/workflows-creator/src/lib/builder/group/group.component.ts

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
9393
eventAdded = new EventEmitter<unknown>();
9494

9595
@Output()
96-
eventRemoved = new EventEmitter<unknown>();
96+
nodeRemoved = new EventEmitter<unknown>();
9797

9898
@Output()
9999
actionAdded = new EventEmitter<unknown>();
@@ -110,6 +110,7 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
110110
subject: '',
111111
body: '',
112112
focusKey: '',
113+
caretPos: 0,
113114
};
114115

115116
dropdownSettings: IDropdownSettings = {
@@ -142,6 +143,9 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
142143

143144
typeSubjectPlaceholder = '';
144145
typeEmailPlaceholder = '';
146+
doThisLbl = '';
147+
whenThisHappensLbl = '';
148+
setLbl = '';
145149

146150
localizedStringKeys = LocalizedStringKeys;
147151

@@ -216,6 +220,14 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
216220
this.templateMap?.[InputTypes.Interval] || this.listTemplate,
217221
[InputTypes.Email]:
218222
this.templateMap?.[InputTypes.Email] || this.emailTemplate,
223+
[InputTypes.OptionList]:
224+
this.templateMap?.[InputTypes.OptionList] || this.listTemplate,
225+
[InputTypes.Stepper]:
226+
this.templateMap?.[InputTypes.Stepper] || this.listTemplate,
227+
[InputTypes.IntervalDate]:
228+
this.templateMap?.[InputTypes.IntervalDate] || this.listTemplate,
229+
[InputTypes.IntervalTime]:
230+
this.templateMap?.[InputTypes.IntervalTime] || this.listTemplate,
219231
};
220232
}
221233

@@ -229,6 +241,13 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
229241
if (allowedInputs.includes(input.getIdentifier())) {
230242
const value = input.getModelValue(nodeWithInput.node.state);
231243
if (nodeWithInput.node.state.get('email')) {
244+
(value as AllowedValuesMap).body = (
245+
(value as AllowedValuesMap).body as string
246+
).replace(/\\"/g, '"');
247+
(value as AllowedValuesMap).subject = (
248+
(value as AllowedValuesMap).subject as string
249+
).replace(/\\"/g, '"');
250+
232251
this.emailInput = value;
233252
} else {
234253
switch (nodeWithInput.node.state.get('valueInputType')) {
@@ -269,11 +288,21 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
269288
*/
270289
appendEmailBody(item: Select, emailInput: EmailInput) {
271290
if (emailInput.focusKey === 'subject') {
272-
emailInput.subject += ` ${item.value}`;
291+
emailInput.subject = [
292+
emailInput.subject.slice(0, emailInput.caretPos),
293+
`${item.value}`,
294+
emailInput.subject.slice(emailInput.caretPos),
295+
].join('');
273296
}
274297
if (emailInput.focusKey === 'body') {
275-
emailInput.body += ` ${item.value}`;
298+
emailInput.body = [
299+
emailInput.body.slice(0, emailInput.caretPos),
300+
`${item.value}`,
301+
emailInput.body.slice(emailInput.caretPos),
302+
].join('');
276303
}
304+
305+
emailInput.caretPos += `${item.value}`.length;
277306
}
278307

279308
/**
@@ -286,6 +315,14 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
286315
emailInput.focusKey = key;
287316
}
288317

318+
/**
319+
* @emailInput this is the object that contains the email input
320+
* @caretPosition pos caret position
321+
*/
322+
setFocusOutPos(emailInput: EmailInput, caretPosition: number) {
323+
emailInput.caretPos = caretPosition;
324+
}
325+
289326
/**
290327
* If the type is an action, set the node list to the actions, otherwise if the type is an event, set
291328
* the node list to the trigger events if there is only one event group and no children, otherwise
@@ -328,6 +365,7 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
328365
subject: '',
329366
body: '',
330367
focusKey: '',
368+
caretPos: 0,
331369
};
332370
const newNode = {
333371
node: this.nodes.getNodeByName(
@@ -340,20 +378,20 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
340378
inputs: this.nodes.mapInputs(node),
341379
};
342380
if (node.type === NodeTypes.EVENT) {
343-
this.eventAdded.emit({
344-
node: node,
345-
newNode: newNode,
346-
});
347381
if (newNode.node.getIdentifier() === 'OnIntervalEvent') {
348382
newNode.node.state.change('valueInputType', 'number');
349383
}
350384
this.group.children.push(newNode as EventWithInput<E>);
385+
this.eventAdded.emit({
386+
node: node,
387+
newNode: newNode,
388+
});
351389
} else if (node.type === NodeTypes.ACTION) {
390+
this.group.children.push(newNode as ActionWithInput<E>);
352391
this.actionAdded.emit({
353392
node: node,
354393
newNode: newNode,
355394
});
356-
this.group.children.push(newNode as ActionWithInput<E>);
357395
} else {
358396
throw new InvalidEntityError('Node');
359397
}
@@ -365,7 +403,7 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
365403
*/
366404
onNodeRemove(index: number) {
367405
this.group.children.splice(index, 1);
368-
this.eventRemoved.emit();
406+
this.nodeRemoved.emit();
369407
}
370408

371409
/**
@@ -387,13 +425,24 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
387425
element,
388426
input,
389427
input.setValue(element.node.state, value),
390-
input.typeFunction(element.node.state) === InputTypes.List,
428+
input.typeFunction(element.node.state) === InputTypes.List ||
429+
input.typeFunction(element.node.state) === InputTypes.OptionList,
391430
);
431+
this.clearValues();
392432
}
393433
popper.hide();
394434
};
395435
}
396436

437+
private clearValues() {
438+
this.emailInput = {
439+
subject: '',
440+
body: '',
441+
focusKey: '',
442+
caretPos: 0,
443+
};
444+
}
445+
397446
/**
398447
* It hides the previous popper and shows the current popper.
399448
* @param {MouseEvent} event - MouseEvent - The event that triggered the popper to show.
@@ -655,6 +704,9 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
655704
element: NodeWithInput<E>,
656705
input: WorkflowPrompt,
657706
) {
707+
if (input.inputKey === 'email') {
708+
return;
709+
}
658710
const currentIndex = element.inputs.findIndex(
659711
i => i.getIdentifier() === input.getIdentifier(),
660712
);

projects/workflows-creator/src/lib/builder/node/node.component.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
position: relative;
77
.workflow-content {
88
flex-grow: 1;
9+
height: 3rem;
910
}
1011
.action-icons {
1112
cursor: pointer;

0 commit comments

Comments
 (0)