Skip to content
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): add timeinterval for the interval trigger in workflow #88

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
) {
if (
((value as AllowedValuesMap)?.value as AllowedValuesMap)?.value ===
ValueTypes.AnyValue || ((value as AllowedValuesMap)?.value === ValueTypes.AnyValue)
ValueTypes.AnyValue ||
(value as AllowedValuesMap)?.value === ValueTypes.AnyValue
) {
/**
* Remove node on changes event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,13 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
[InputTypes.Email]:
this.templateMap?.[InputTypes.Email] || this.emailTemplate,
[InputTypes.OptionList]:
this.templateMap?.[InputTypes.OptionList] || this.listTemplate,
this.templateMap?.[InputTypes.OptionList] || this.listTemplate,
[InputTypes.Stepper]:
this.templateMap?.[InputTypes.Stepper] || this.listTemplate,
[InputTypes.IntervalDate]:
this.templateMap?.[InputTypes.IntervalDate] || this.listTemplate,
[InputTypes.IntervalTime]:
this.templateMap?.[InputTypes.IntervalTime] || this.listTemplate,
};
}

Expand Down Expand Up @@ -400,7 +406,8 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
element,
input,
input.setValue(element.node.state, value),
input.typeFunction(element.node.state) === InputTypes.List || input.typeFunction(element.node.state) === InputTypes.OptionList,
input.typeFunction(element.node.state) === InputTypes.List ||
input.typeFunction(element.node.state) === InputTypes.OptionList,
);
this.clearValues();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export abstract class WorkflowPrompt {
case InputTypes.Text:
case InputTypes.Boolean:
case InputTypes.Percentage:
case InputTypes.Stepper:
default:
if (value) {
return (value as HTMLInputElement).value;
Expand Down Expand Up @@ -169,10 +170,14 @@ export abstract class WorkflowPrompt {
.utc(state.get(this.inputKey), 'YYYY-MM-DD hh:mm')
.format('MMM DD, YYYY hh:mm A')
: '';
case InputTypes.IntervalDate:
case InputTypes.IntervalTime:
return state.get(this.inputKey)?.value;
case InputTypes.Number:
case InputTypes.Text:
case InputTypes.Boolean:
case InputTypes.Percentage:
case InputTypes.Stepper:
default:
return state.get(this.inputKey);
}
Expand Down Expand Up @@ -209,6 +214,7 @@ export abstract class WorkflowPrompt {
case InputTypes.Text:
case InputTypes.Boolean:
case InputTypes.Percentage:
case InputTypes.Stepper:
default:
return state.get(this.inputKey);
}
Expand Down
2 changes: 1 addition & 1 deletion projects/workflows-creator/src/lib/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ export const typeTuppleList: Array<ConditionOperatorPair> = [
{condition: ConditionTypes.LessThan, operator: '<', value: true},
{condition: ConditionTypes.ComingIn, operator: '-', value: true},
{condition: ConditionTypes.PastBy, operator: '+', value: true},
];
];
16 changes: 14 additions & 2 deletions projects/workflows-creator/src/lib/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ export enum InputTypes {
People = 'people',
Percentage = 'percentage',
Text = 'text',
OptionList = "optionList",
Item = 'Item'
OptionList = 'optionList',
Item = 'Item',
Stepper = 'Stepper',
IntervalDate = 'IntervalDate',
IntervalTime = 'IntervalTime',
}

/* Defining the types of conditions that can be used in the application. */
Expand Down Expand Up @@ -108,3 +111,12 @@ export enum LocalizedStringKeys {
SelectColumnTooltip = 'selectColumnTooltip',
SetLbl = 'setLbl',
}

export enum IntervalType {
Day = 'day',
Days = 'days',
Weeks = 'weeks',
Months = 'months',
Week = 'week',
Month = 'month',
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ export class GatewayElement extends BpmnElement {
getIdentifier(): string {
return GatewayElement.identifier;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ export class ProcessElement extends BpmnElement {
getIdentifier(): string {
return ProcessElement.identifier;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ import {
ModdleElement,
RecordOfAnyType,
} from '../../../../types';
import {WorkflowElement} from '../../../../classes';
import {State, WorkflowElement} from '../../../../classes';

enum WeekDaysEnum {
sunday = 1,
monday = 2,
tuesday = 3,
wednesday = 4,
thursday = 5,
friday = 6,
saturday = 7,
}

@Injectable()
export class CreateBasicIntervalStrategy
Expand Down Expand Up @@ -38,9 +48,7 @@ export class CreateBasicIntervalStrategy
const state = workflowNode.state;
const timeCycle = this.moddle.create('bpmn:FormalExpression', {
'xsi:type': 'bpmn:tFormalExpression',
body: `R/P${state.get('timescale')}${state.get('value')}${state.get(
'interval',
)}`,
body: this.intervalBodyPrepare(state),
});

timerEventDefinition['timeCycle'] = timeCycle;
Expand All @@ -53,6 +61,53 @@ export class CreateBasicIntervalStrategy
});
}

private intervalBodyPrepare(state: State<RecordOfAnyType>) {
if (
state.get('interval') === 'M' &&
state.get('toInterval') &&
state.get('TimeInterval')
) {
const val =
state.get('value') == 1
? '*'
: `${state.get('toInterval').month}/${state.get('value')}`;
const timeZoneDate = new Date();
timeZoneDate.setHours(state.get('TimeInterval').hour);
timeZoneDate.setMinutes(state.get('TimeInterval').min);
return `0 timeZoneDate(${timeZoneDate})timeZoneDateEnd ${
state.get('toInterval').date
} ${val} ?`;
} else if (
state.get('interval') === 'W' &&
state.get('toInterval') &&
state.get('TimeInterval')
) {
const val = state.get('value') == 1 ? '' : `/${state.get('value')}`;
let weekDays = state
.get('toInterval')
?.ids?.map(
(day: string) => WeekDaysEnum[day as keyof typeof WeekDaysEnum],
)
.join(',');
const timeZoneDate = new Date();
timeZoneDate.setHours(state.get('TimeInterval').hour);
timeZoneDate.setMinutes(state.get('TimeInterval').min);
return `0 timeZoneDate(${timeZoneDate})timeZoneDateEnd ? * ${weekDays}${val}`;
} else if (state.get('interval') === 'D' && state.get('TimeInterval')) {
const today = new Date();
today.setHours(state.get('TimeInterval').hour);
today.setMinutes(state.get('TimeInterval').min);
let isoString = '';
if (today.getTime() < new Date().getTime()) {
today.setDate(today.getDate() + 1);
}
isoString = today.toISOString();
return `R/${isoString}/P${state.get('value')}${state.get('interval')}`;
} else {
return '0 0 0 ? * *';
}
}

/**
* It takes an object of attributes and a node, and returns the same object of attributes, but with
* any attribute that is a state reference replaced with the value of that state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,4 @@ export class CreateTaskStrategy implements CreateStrategy<ModdleElement> {
return [node.prev[0].element.id];
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ export class GatewayLinkStrategy implements LinkStrategy<ModdleElement> {
const valueType = node.workflowNode.state.get('valueInputType');
if (value)
switch (valueType) {
case InputTypes.Stepper:
case InputTypes.Text:
value = `'${value}'`;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,4 @@ export class OrGatewayLinkStrategy implements LinkStrategy<ModdleElement> {
return `${pair.operator}`;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {LocalizedStringKeys, StartElementTypes} from '../../../enum';
import {RecordOfAnyType} from '../../../types';
import {BpmnEvent} from '../../../types/bpmn.types';
import {TriggerOnInterval} from '../../bpmn/elements/tasks/trigger-on-interval.task';
import {TimeIntervalInput, ToIntervalInput} from '../inputs';
import {IntervalInput} from '../inputs/interval.input';
import {ValueInput} from '../inputs/value.input';
import {StepperInput} from '../inputs/stepper.input';

export class OnIntervalEvent extends BpmnEvent {
groupType: string;
Expand All @@ -14,7 +15,12 @@ export class OnIntervalEvent extends BpmnEvent {
name = 'On Interval';
statement = 'Every ';
properties = {};
prompts = [ValueInput.identifier, IntervalInput.identifier];
prompts = [
StepperInput.identifier,
IntervalInput.identifier,
ToIntervalInput.identifier,
TimeIntervalInput.identifier,
];
static identifier = 'OnIntervalEvent';
constructor(
localizedStringMap: RecordOfAnyType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {BpmnEvent} from '../../../types/bpmn.types';
import {GatewayElement} from '../../bpmn/elements/gateways/gateway.element';
import {ReadColumnValue} from '../../bpmn/elements/tasks/read-column.task';
import {ConditionInput} from '../inputs/condition.input';
import { CriteriaInput } from '../inputs/criteria.input';
import {CriteriaInput} from '../inputs/criteria.input';
import {ValueInput} from '../inputs/value.input';

export class OnValueEvent extends BpmnEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ export * from './value.input';
export * from './interval.input';
export * from './triggercolumn.input';
export * from './valuetype.input';
export * from './criteria.input';
export * from './criteria.input';
export * from './stepper.input';
export * from './tointerval.input';
export * from './timeinterval.input';
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {InputTypes} from '../../../enum';
import {RecordOfAnyType} from '../../../types';

export class IntervalInput extends WorkflowPrompt {
prefix = '';
suffix = '';
prefix: string | {state: string} = {state: 'valuePrefix'};
suffix: string | {state: string} = {state: 'intervalValueSuffix'};
typeFunction = () => InputTypes.List;
inputKey = 'interval';
listNameField = 'text';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {State, WorkflowPrompt} from '../../../classes';
import {InputTypes} from '../../../enum';
import {RecordOfAnyType} from '../../../types';

export class StepperInput extends WorkflowPrompt {
prefix = '';
suffix = '';
typeFunction = () => InputTypes.Stepper;
inputKey = 'value';
listNameField = 'text';
listValueField = 'value';
placeholder = 'n';
customPlaceholder: string | {state: string} = {state: 'stepperPlaceholder'};
options = <S extends RecordOfAnyType>(state: State<S>) =>
state.get('stepperCount') as [];
static identifier = 'StepperInput';

getIdentifier(): string {
return StepperInput.identifier;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {State, WorkflowPrompt} from '../../../classes';
import {InputTypes, IntervalType} from '../../../enum';
import {BpmnNode, RecordOfAnyType} from '../../../types';
export class TimeIntervalInput extends WorkflowPrompt {
prefix: string | {state: string} = {state: 'timeIntervalSuffix'};
suffix = '';
typeFunction = () => InputTypes.IntervalTime;
inputKey = 'TimeInterval';
listNameField = 'text';
listValueField = 'value';
placeholder = 'hh:mm';
customPlaceholder: string | {state: string} = {state: 'timeStatePlaceholder'};
isHidden = (node: BpmnNode) => {
return ![
IntervalType.Weeks,
IntervalType.Months,
IntervalType.Week,
IntervalType.Month,
IntervalType.Days,
IntervalType.Day,
].includes(node.state.get('intervalType'));
};
options = <S extends RecordOfAnyType>(state: State<S>) =>
state.get('timevalues');
static identifier = 'TimeIntervalInput';

getIdentifier(): string {
return TimeIntervalInput.identifier;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {State, WorkflowPrompt} from '../../../classes';
import {InputTypes, IntervalType} from '../../../enum';
import {BpmnNode, RecordOfAnyType} from '../../../types';

export class ToIntervalInput extends WorkflowPrompt {
prefix = '';
suffix = '';
typeFunction = <S extends RecordOfAnyType>(state: State<S>) =>
state.get('valueInputTypes') as InputTypes;
inputKey = 'toInterval';
listNameField = 'text';
listValueField = 'value';
placeholder = 'weekday';
customPlaceholder: string | {state: string} = {state: 'dateStatePlaceholder'};
isHidden = (node: BpmnNode) => {
return ![
IntervalType.Weeks,
IntervalType.Months,
IntervalType.Week,
IntervalType.Month,
].includes(node.state.get('intervalType'));
};
options = <S extends RecordOfAnyType>(state: State<S>) =>
state.get('intervalOption');
static identifier = 'ToIntervalInput';

getIdentifier(): string {
return ToIntervalInput.identifier;
}
}
10 changes: 9 additions & 1 deletion projects/workflows-creator/src/lib/workflow-builder.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ import {TriggerColumnInput} from './services/statement/inputs/triggercolumn.inpu
import {ValueTypeInput} from './services/statement/inputs/valuetype.input';
import {TooltipRenderComponent} from './builder/tooltip-render/tooltip-render.component';
import {LocalizationPipe} from './pipes/localization.pipe';
import { CriteriaInput } from './services';
import {
CriteriaInput,
StepperInput,
TimeIntervalInput,
ToIntervalInput,
} from './services';
@NgModule({
declarations: [
BuilderComponent,
Expand Down Expand Up @@ -145,7 +150,10 @@ import { CriteriaInput } from './services';
{provide: BPMN_ELEMENTS, useClass: ProcessPropertiesElement, multi: true},
{provide: BPMN_INPUTS, useClass: ColumnInput, multi: true},
{provide: BPMN_INPUTS, useClass: CriteriaInput, multi: true},
{provide: BPMN_INPUTS, useClass: StepperInput, multi: true},
{provide: BPMN_INPUTS, useClass: TimeIntervalInput, multi: true},
{provide: BPMN_INPUTS, useClass: TriggerColumnInput, multi: true},
{provide: BPMN_INPUTS, useClass: ToIntervalInput, multi: true},
{provide: BPMN_INPUTS, useClass: IntervalInput, multi: true},
{provide: BPMN_INPUTS, useClass: ConditionInput, multi: true},
{provide: BPMN_INPUTS, useClass: EmailDataInput, multi: true},
Expand Down
Loading