From 0f1e545e675133dc28e7e712339ef6db75915559 Mon Sep 17 00:00:00 2001 From: bduran Date: Mon, 26 Aug 2024 16:06:49 -0700 Subject: [PATCH 1/5] add form element to specify file upload for scheduling goals (wip) --- .../conditions/SchedulingConditionForm.svelte | 21 +-- .../goals/SchedulingGoalForm.svelte | 46 ++++-- .../ui/Association/AssociationForm.svelte | 147 +++++++++++++++--- src/constants/scheduling.ts | 4 + src/enums/association.ts | 4 + src/routes/constraints/edit/[id]/+page.svelte | 2 +- .../conditions/edit/[id]/+page.svelte | 2 +- .../scheduling/goals/edit/[id]/+page.svelte | 58 ++++--- src/types/metadata.ts | 2 +- src/types/scheduling.ts | 12 +- src/utilities/effects.ts | 56 ++++++- src/utilities/gql.ts | 2 + src/utilities/permissions.ts | 10 +- 13 files changed, 283 insertions(+), 83 deletions(-) create mode 100644 src/constants/scheduling.ts create mode 100644 src/enums/association.ts diff --git a/src/components/scheduling/conditions/SchedulingConditionForm.svelte b/src/components/scheduling/conditions/SchedulingConditionForm.svelte index e37a7b0740..fb4843adeb 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'; @@ -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, ); diff --git a/src/components/scheduling/goals/SchedulingGoalForm.svelte b/src/components/scheduling/goals/SchedulingGoalForm.svelte index 19223d61a4..b0a4e2ea73 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 = 'export default (): GlobalSchedulingGoal => {\n\n}\n'; + 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,18 @@