diff --git a/e2e-tests/data/example-procedure.jar b/e2e-tests/data/example-procedure.jar new file mode 100644 index 0000000000..89651b27ab Binary files /dev/null and b/e2e-tests/data/example-procedure.jar differ diff --git a/src/components/constraints/ConstraintForm.svelte b/src/components/constraints/ConstraintForm.svelte index a5c9662c57..14ce17d4df 100644 --- a/src/components/constraints/ConstraintForm.svelte +++ b/src/components/constraints/ConstraintForm.svelte @@ -4,6 +4,7 @@ import { goto } from '$app/navigation'; import { base } from '$app/paths'; import { createEventDispatcher } from 'svelte'; + import type { DefinitionType } from '../../enums/association'; import { SearchParameters } from '../../enums/searchParameters'; import { constraints } from '../../stores/constraints'; import type { User, UserId } from '../../types/app'; @@ -15,7 +16,7 @@ import AssociationForm from '../ui/Association/AssociationForm.svelte'; export let initialConstraintDefinitionAuthor: UserId | undefined = undefined; - export let initialConstraintDefinitionCode: string = 'export default (): Constraint => {\n\n}\n'; + export let initialConstraintDefinitionCode: string | null = ''; export let initialConstraintDescription: string = ''; export let initialConstraintId: number | null = null; export let initialConstraintName: string = ''; @@ -88,10 +89,10 @@ async function onCreateConstraint( event: CustomEvent<{ - definition: { - code: string; - tags: Tag[]; - }; + definitionCode: string | null; + definitionFile?: File | null; + definitionTags: Tag[]; + definitionType?: DefinitionType; description: string; name: string; public: boolean; @@ -99,14 +100,14 @@ }>, ) { const { - detail: { definition, description, name, public: isPublic, tags }, + detail: { definitionCode, definitionTags, description, name, public: isPublic }, } = event; const newConstraintId = await effects.createConstraint( name, isPublic, tags.map(({ id }) => ({ tag_id: id })), - definition.code, - definition.tags.map(({ id }) => ({ tag_id: id })), + definitionCode ?? '', + definitionTags.map(({ id }) => ({ tag_id: id })), user, description, ); @@ -122,8 +123,10 @@ async function onCreateNewConstraintDefinition( event: CustomEvent<{ - definitionCode: string; + definitionCode: string | null; + definitionFile?: File | null; definitionTags: Tag[]; + definitionType?: DefinitionType; }>, ) { const { @@ -132,7 +135,7 @@ if (initialConstraintId !== null) { const definition = await effects.createConstraintDefinition( initialConstraintId, - definitionCode, + definitionCode ?? '', definitionTags.map(({ id }) => ({ tag_id: id })), user, ); @@ -224,6 +227,7 @@ {\n\n}\n`} displayName="Constraint" {hasCreateDefinitionCodePermission} {hasWriteMetadataPermission} diff --git a/src/components/scheduling/conditions/SchedulingConditionForm.svelte b/src/components/scheduling/conditions/SchedulingConditionForm.svelte index e37a7b0740..8082e87739 100644 --- a/src/components/scheduling/conditions/SchedulingConditionForm.svelte +++ b/src/components/scheduling/conditions/SchedulingConditionForm.svelte @@ -4,6 +4,7 @@ import { goto } from '$app/navigation'; import { base } from '$app/paths'; import { createEventDispatcher } from 'svelte'; + import type { DefinitionType } from '../../../enums/association'; import { SearchParameters } from '../../../enums/searchParameters'; import { schedulingConditions } from '../../../stores/scheduling'; import type { User, UserId } from '../../../types/app'; @@ -18,7 +19,7 @@ import AssociationForm from '../../ui/Association/AssociationForm.svelte'; export let initialConditionDefinitionAuthor: UserId | undefined = undefined; - export let initialConditionDefinitionCode: string = 'export default (): GlobalSchedulingCondition => {\n\n}\n'; + export let initialConditionDefinitionCode: string | null = ''; export let initialConditionDescription: string = ''; export let initialConditionId: number | null = null; export let initialConditionName: string = ''; @@ -89,10 +90,10 @@ async function onCreateCondition( event: CustomEvent<{ - definition: { - code: string; - tags: Tag[]; - }; + definitionCode: string | null; + definitionFile?: File | null; + definitionTags: Tag[]; + definitionType?: DefinitionType; description: string; name: string; public: boolean; @@ -100,15 +101,15 @@ }>, ) { const { - detail: { definition, description, name, public: isPublic, tags }, + detail: { definitionCode, definitionTags, description, name, public: isPublic }, } = event; const newConditionId = await effects.createSchedulingCondition( name, isPublic, tags.map(({ id }) => ({ tag_id: id })), - definition.code, - definition.tags.map(({ id }) => ({ tag_id: id })), + definitionCode ?? '', + definitionTags.map(({ id }) => ({ tag_id: id })), user, description, ); @@ -124,8 +125,10 @@ async function onCreateNewConditionDefinition( event: CustomEvent<{ - definitionCode: string; + definitionCode: string | null; + definitionFile?: File | null; definitionTags: Tag[]; + definitionType?: DefinitionType; }>, ) { const { @@ -134,7 +137,7 @@ if (initialConditionId !== null) { const definition = await effects.createSchedulingConditionDefinition( initialConditionId, - definitionCode, + definitionCode ?? '', definitionTags.map(({ id }) => ({ tag_id: id })), user, ); @@ -224,6 +227,7 @@ {\n\n}\n`} displayName="Scheduling Condition" {hasCreateDefinitionCodePermission} {hasWriteDefinitionTagsPermission} diff --git a/src/components/scheduling/goals/SchedulingGoalForm.svelte b/src/components/scheduling/goals/SchedulingGoalForm.svelte index 19223d61a4..ee78e0176d 100644 --- a/src/components/scheduling/goals/SchedulingGoalForm.svelte +++ b/src/components/scheduling/goals/SchedulingGoalForm.svelte @@ -4,6 +4,8 @@ import { goto } from '$app/navigation'; import { base } from '$app/paths'; import { createEventDispatcher } from 'svelte'; + import { SchedulingType } from '../../../constants/scheduling'; + import { DefinitionType } from '../../../enums/association'; import { SearchParameters } from '../../../enums/searchParameters'; import { schedulingGoals } from '../../../stores/scheduling'; import type { User, UserId } from '../../../types/app'; @@ -18,12 +20,14 @@ import AssociationForm from '../../ui/Association/AssociationForm.svelte'; export let initialGoalDefinitionAuthor: UserId | undefined = undefined; - export let initialGoalDefinitionCode: string = 'export default (): GlobalSchedulingGoal => {\n\n}\n'; + export let initialGoalDefinitionCode: string | null = null; + export let initialGoalDefinitionFilename: string | null = null; export let initialGoalDescription: string = ''; export let initialGoalId: number | null = null; export let initialGoalName: string = ''; export let initialGoalPublic: boolean = true; export let initialGoalDefinitionTags: Tag[] = []; + export let initialGoalDefinitionType: SchedulingType = SchedulingType.EDSL; export let initialGoalMetadataTags: Tag[] = []; export let initialGoalOwner: UserId = null; export let initialGoalRevision: number | null = null; @@ -89,10 +93,10 @@ async function onCreateGoal( event: CustomEvent<{ - definition: { - code: string; - tags: Tag[]; - }; + definitionCode: string | null; + definitionFile?: File | null; + definitionTags: Tag[]; + definitionType?: DefinitionType; description: string; name: string; public: boolean; @@ -100,15 +104,26 @@ }>, ) { const { - detail: { definition, description, name, public: isPublic, tags }, + detail: { + definitionCode, + definitionFile, + definitionTags, + definitionType, + description, + name, + public: isPublic, + tags, + }, } = event; const newGoalId = await effects.createSchedulingGoal( name, isPublic, tags.map(({ id }) => ({ tag_id: id })), - definition.code, - definition.tags.map(({ id }) => ({ tag_id: id })), + definitionType === DefinitionType.CODE ? SchedulingType.EDSL : SchedulingType.JAR, + definitionCode, + definitionFile ?? null, + definitionTags.map(({ id }) => ({ tag_id: id })), user, description, ); @@ -124,17 +139,21 @@ async function onCreateNewGoalDefinition( event: CustomEvent<{ - definitionCode: string; + definitionCode: string | null; + definitionFile?: File | null; definitionTags: Tag[]; + definitionType?: DefinitionType; }>, ) { const { - detail: { definitionCode, definitionTags }, + detail: { definitionCode, definitionFile, definitionTags, definitionType }, } = event; if (initialGoalId !== null) { const definition = await effects.createSchedulingGoalDefinition( initialGoalId, + definitionType === DefinitionType.CODE ? SchedulingType.EDSL : SchedulingType.JAR, definitionCode, + definitionFile ?? null, definitionTags.map(({ id }) => ({ tag_id: id })), user, ); @@ -216,12 +235,19 @@ {\n\n}\n`} + definitionTypeConfigurations={{ + code: { label: 'EDSL' }, + file: { accept: '.jar', label: 'JAR File' }, + }} displayName="Scheduling Goal" {hasCreateDefinitionCodePermission} {hasWriteDefinitionTagsPermission} {hasWriteMetadataPermission} initialDefinitionAuthor={initialGoalDefinitionAuthor} + initialDefinitionType={initialGoalDefinitionType === SchedulingType.EDSL ? DefinitionType.CODE : DefinitionType.FILE} initialDefinitionCode={initialGoalDefinitionCode} + initialDefinitionFileName={initialGoalDefinitionFilename} initialDescription={initialGoalDescription} initialId={initialGoalId} initialName={initialGoalName} @@ -234,6 +260,7 @@ {permissionError} revisions={goalRevisions} {tags} + showDefinitionTypeSelector={true} tsFiles={goalsTsFiles} {mode} {user} diff --git a/src/components/ui/Association/AssociationForm.svelte b/src/components/ui/Association/AssociationForm.svelte index a3811ca2ca..2c89982080 100644 --- a/src/components/ui/Association/AssociationForm.svelte +++ b/src/components/ui/Association/AssociationForm.svelte @@ -1,6 +1,8 @@