Skip to content

Commit 2a7d458

Browse files
authored
feat(core): add timeinterval for the interval trigger in workflow (#88)
* feat(core): add timeinterval for the interval trigger in workflow * refactor(core): add changes
1 parent 242eaeb commit 2a7d458

File tree

19 files changed

+201
-21
lines changed

19 files changed

+201
-21
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
373373
) {
374374
if (
375375
((value as AllowedValuesMap)?.value as AllowedValuesMap)?.value ===
376-
ValueTypes.AnyValue || ((value as AllowedValuesMap)?.value === ValueTypes.AnyValue)
376+
ValueTypes.AnyValue ||
377+
(value as AllowedValuesMap)?.value === ValueTypes.AnyValue
377378
) {
378379
/**
379380
* Remove node on changes event

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,13 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
213213
[InputTypes.Email]:
214214
this.templateMap?.[InputTypes.Email] || this.emailTemplate,
215215
[InputTypes.OptionList]:
216-
this.templateMap?.[InputTypes.OptionList] || this.listTemplate,
216+
this.templateMap?.[InputTypes.OptionList] || this.listTemplate,
217+
[InputTypes.Stepper]:
218+
this.templateMap?.[InputTypes.Stepper] || this.listTemplate,
219+
[InputTypes.IntervalDate]:
220+
this.templateMap?.[InputTypes.IntervalDate] || this.listTemplate,
221+
[InputTypes.IntervalTime]:
222+
this.templateMap?.[InputTypes.IntervalTime] || this.listTemplate,
217223
};
218224
}
219225

@@ -400,7 +406,8 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
400406
element,
401407
input,
402408
input.setValue(element.node.state, value),
403-
input.typeFunction(element.node.state) === InputTypes.List || input.typeFunction(element.node.state) === InputTypes.OptionList,
409+
input.typeFunction(element.node.state) === InputTypes.List ||
410+
input.typeFunction(element.node.state) === InputTypes.OptionList,
404411
);
405412
this.clearValues();
406413
}

projects/workflows-creator/src/lib/classes/nodes/abstract-prompt.class.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export abstract class WorkflowPrompt {
107107
case InputTypes.Text:
108108
case InputTypes.Boolean:
109109
case InputTypes.Percentage:
110+
case InputTypes.Stepper:
110111
default:
111112
if (value) {
112113
return (value as HTMLInputElement).value;
@@ -169,10 +170,14 @@ export abstract class WorkflowPrompt {
169170
.utc(state.get(this.inputKey), 'YYYY-MM-DD hh:mm')
170171
.format('MMM DD, YYYY hh:mm A')
171172
: '';
173+
case InputTypes.IntervalDate:
174+
case InputTypes.IntervalTime:
175+
return state.get(this.inputKey)?.value;
172176
case InputTypes.Number:
173177
case InputTypes.Text:
174178
case InputTypes.Boolean:
175179
case InputTypes.Percentage:
180+
case InputTypes.Stepper:
176181
default:
177182
return state.get(this.inputKey);
178183
}
@@ -209,6 +214,7 @@ export abstract class WorkflowPrompt {
209214
case InputTypes.Text:
210215
case InputTypes.Boolean:
211216
case InputTypes.Percentage:
217+
case InputTypes.Stepper:
212218
default:
213219
return state.get(this.inputKey);
214220
}

projects/workflows-creator/src/lib/const.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ export const typeTuppleList: Array<ConditionOperatorPair> = [
4848
{condition: ConditionTypes.LessThan, operator: '<', value: true},
4949
{condition: ConditionTypes.ComingIn, operator: '-', value: true},
5050
{condition: ConditionTypes.PastBy, operator: '+', value: true},
51-
];
51+
];

projects/workflows-creator/src/lib/enum.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ export enum InputTypes {
2020
People = 'people',
2121
Percentage = 'percentage',
2222
Text = 'text',
23-
OptionList = "optionList",
24-
Item = 'Item'
23+
OptionList = 'optionList',
24+
Item = 'Item',
25+
Stepper = 'Stepper',
26+
IntervalDate = 'IntervalDate',
27+
IntervalTime = 'IntervalTime',
2528
}
2629

2730
/* Defining the types of conditions that can be used in the application. */
@@ -108,3 +111,12 @@ export enum LocalizedStringKeys {
108111
SelectColumnTooltip = 'selectColumnTooltip',
109112
SetLbl = 'setLbl',
110113
}
114+
115+
export enum IntervalType {
116+
Day = 'day',
117+
Days = 'days',
118+
Weeks = 'weeks',
119+
Months = 'months',
120+
Week = 'week',
121+
Month = 'month',
122+
}

projects/workflows-creator/src/lib/services/bpmn/elements/gateways/gateway.element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ export class GatewayElement extends BpmnElement {
4040
getIdentifier(): string {
4141
return GatewayElement.identifier;
4242
}
43-
}
43+
}

projects/workflows-creator/src/lib/services/bpmn/elements/process/process.element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ export class ProcessElement extends BpmnElement {
3636
getIdentifier(): string {
3737
return ProcessElement.identifier;
3838
}
39-
}
39+
}

projects/workflows-creator/src/lib/services/bpmn/strategies/create/basic-interval-create.strategy.ts

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@ import {
77
ModdleElement,
88
RecordOfAnyType,
99
} from '../../../../types';
10-
import {WorkflowElement} from '../../../../classes';
10+
import {State, WorkflowElement} from '../../../../classes';
11+
12+
enum WeekDaysEnum {
13+
sunday = 1,
14+
monday = 2,
15+
tuesday = 3,
16+
wednesday = 4,
17+
thursday = 5,
18+
friday = 6,
19+
saturday = 7,
20+
}
1121

1222
@Injectable()
1323
export class CreateBasicIntervalStrategy
@@ -38,9 +48,7 @@ export class CreateBasicIntervalStrategy
3848
const state = workflowNode.state;
3949
const timeCycle = this.moddle.create('bpmn:FormalExpression', {
4050
'xsi:type': 'bpmn:tFormalExpression',
41-
body: `R/P${state.get('timescale')}${state.get('value')}${state.get(
42-
'interval',
43-
)}`,
51+
body: this.intervalBodyPrepare(state),
4452
});
4553

4654
timerEventDefinition['timeCycle'] = timeCycle;
@@ -53,6 +61,53 @@ export class CreateBasicIntervalStrategy
5361
});
5462
}
5563

64+
private intervalBodyPrepare(state: State<RecordOfAnyType>) {
65+
if (
66+
state.get('interval') === 'M' &&
67+
state.get('toInterval') &&
68+
state.get('TimeInterval')
69+
) {
70+
const val =
71+
state.get('value') == 1
72+
? '*'
73+
: `${state.get('toInterval').month}/${state.get('value')}`;
74+
const timeZoneDate = new Date();
75+
timeZoneDate.setHours(state.get('TimeInterval').hour);
76+
timeZoneDate.setMinutes(state.get('TimeInterval').min);
77+
return `0 timeZoneDate(${timeZoneDate})timeZoneDateEnd ${
78+
state.get('toInterval').date
79+
} ${val} ?`;
80+
} else if (
81+
state.get('interval') === 'W' &&
82+
state.get('toInterval') &&
83+
state.get('TimeInterval')
84+
) {
85+
const val = state.get('value') == 1 ? '' : `/${state.get('value')}`;
86+
let weekDays = state
87+
.get('toInterval')
88+
?.ids?.map(
89+
(day: string) => WeekDaysEnum[day as keyof typeof WeekDaysEnum],
90+
)
91+
.join(',');
92+
const timeZoneDate = new Date();
93+
timeZoneDate.setHours(state.get('TimeInterval').hour);
94+
timeZoneDate.setMinutes(state.get('TimeInterval').min);
95+
return `0 timeZoneDate(${timeZoneDate})timeZoneDateEnd ? * ${weekDays}${val}`;
96+
} else if (state.get('interval') === 'D' && state.get('TimeInterval')) {
97+
const today = new Date();
98+
today.setHours(state.get('TimeInterval').hour);
99+
today.setMinutes(state.get('TimeInterval').min);
100+
let isoString = '';
101+
if (today.getTime() < new Date().getTime()) {
102+
today.setDate(today.getDate() + 1);
103+
}
104+
isoString = today.toISOString();
105+
return `R/${isoString}/P${state.get('value')}${state.get('interval')}`;
106+
} else {
107+
return '0 0 0 ? * *';
108+
}
109+
}
110+
56111
/**
57112
* It takes an object of attributes and a node, and returns the same object of attributes, but with
58113
* any attribute that is a state reference replaced with the value of that state

projects/workflows-creator/src/lib/services/bpmn/strategies/create/task-create.strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,4 @@ export class CreateTaskStrategy implements CreateStrategy<ModdleElement> {
222222
return [node.prev[0].element.id];
223223
}
224224
}
225-
}
225+
}

projects/workflows-creator/src/lib/services/bpmn/strategies/link/gateway-link.strategy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ export class GatewayLinkStrategy implements LinkStrategy<ModdleElement> {
432432
const valueType = node.workflowNode.state.get('valueInputType');
433433
if (value)
434434
switch (valueType) {
435+
case InputTypes.Stepper:
435436
case InputTypes.Text:
436437
value = `'${value}'`;
437438
break;

0 commit comments

Comments
 (0)