Skip to content

Commit

Permalink
Scheduling jar upload (#1444)
Browse files Browse the repository at this point in the history
* add form element to specify file upload for scheduling goals
  • Loading branch information
duranb authored Sep 9, 2024
1 parent 7f568f7 commit 22ce741
Show file tree
Hide file tree
Showing 16 changed files with 353 additions and 102 deletions.
Binary file added e2e-tests/data/example-procedure.jar
Binary file not shown.
24 changes: 14 additions & 10 deletions src/components/constraints/ConstraintForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = '';
Expand Down Expand Up @@ -88,25 +89,25 @@
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;
tags: Tag[];
}>,
) {
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,
);
Expand All @@ -122,8 +123,10 @@
async function onCreateNewConstraintDefinition(
event: CustomEvent<{
definitionCode: string;
definitionCode: string | null;
definitionFile?: File | null;
definitionTags: Tag[];
definitionType?: DefinitionType;
}>,
) {
const {
Expand All @@ -132,7 +135,7 @@
if (initialConstraintId !== null) {
const definition = await effects.createConstraintDefinition(
initialConstraintId,
definitionCode,
definitionCode ?? '',
definitionTags.map(({ id }) => ({ tag_id: id })),
user,
);
Expand Down Expand Up @@ -224,6 +227,7 @@

<AssociationForm
allMetadata={$constraints}
defaultDefinitionCode={`export default (): Constraint => {\n\n}\n`}
displayName="Constraint"
{hasCreateDefinitionCodePermission}
{hasWriteMetadataPermission}
Expand Down
24 changes: 14 additions & 10 deletions src/components/scheduling/conditions/SchedulingConditionForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = '';
Expand Down Expand Up @@ -89,26 +90,26 @@
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;
tags: Tag[];
}>,
) {
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,
);
Expand All @@ -124,8 +125,10 @@
async function onCreateNewConditionDefinition(
event: CustomEvent<{
definitionCode: string;
definitionCode: string | null;
definitionFile?: File | null;
definitionTags: Tag[];
definitionType?: DefinitionType;
}>,
) {
const {
Expand All @@ -134,7 +137,7 @@
if (initialConditionId !== null) {
const definition = await effects.createSchedulingConditionDefinition(
initialConditionId,
definitionCode,
definitionCode ?? '',
definitionTags.map(({ id }) => ({ tag_id: id })),
user,
);
Expand Down Expand Up @@ -224,6 +227,7 @@

<AssociationForm
allMetadata={$schedulingConditions}
defaultDefinitionCode={`export default (): GlobalSchedulingCondition => {\n\n}\n`}
displayName="Scheduling Condition"
{hasCreateDefinitionCodePermission}
{hasWriteDefinitionTagsPermission}
Expand Down
47 changes: 37 additions & 10 deletions src/components/scheduling/goals/SchedulingGoalForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -89,26 +93,37 @@
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;
tags: Tag[];
}>,
) {
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,
);
Expand All @@ -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,
);
Expand Down Expand Up @@ -216,12 +235,19 @@

<AssociationForm
allMetadata={$schedulingGoals}
defaultDefinitionCode={`export default (): GlobalSchedulingGoal => {\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}
Expand All @@ -234,6 +260,7 @@
{permissionError}
revisions={goalRevisions}
{tags}
showDefinitionTypeSelector={true}
tsFiles={goalsTsFiles}
{mode}
{user}
Expand Down
Loading

0 comments on commit 22ce741

Please sign in to comment.