From 41eb330716f20b5c6eb07e5d2904f9bcc3a00fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Tainon?= Date: Mon, 24 Jul 2023 18:08:43 +0200 Subject: [PATCH 1/2] Use PEMTaskMetaData object for task grader metadata --- frontend/index.tsx | 1 + frontend/task/platform/platform.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/index.tsx b/frontend/index.tsx index f3b6b233..57f21368 100644 --- a/frontend/index.tsx +++ b/frontend/index.tsx @@ -127,6 +127,7 @@ declare global { task: any, // task object defined to receive data from platform platform: any, // platform object defined to send data to platform json: any, // object that contains the data of a task, defined in the index.html of such task + PEMTaskMetaData: any, // same usage, bue for task grader tasks task_token: any, // instance that can generate a task token options: any, // this is used to store default data about task Blockly: any, diff --git a/frontend/task/platform/platform.ts b/frontend/task/platform/platform.ts index d663e791..6cb8fb1f 100644 --- a/frontend/task/platform/platform.ts +++ b/frontend/task/platform/platform.ts @@ -77,7 +77,7 @@ export function* getTaskAnswerAggregated () { } export function getTaskMetadata() { - const metadata = window.json ? window.json : { + const metadata = window.json ?? window.PEMTaskMetaData ?? { fullFeedback: true, minWidth: "auto", }; From a50f49c57fd1f56cd98ce5754b8e33837958e287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Tainon?= Date: Wed, 26 Jul 2023 17:40:41 +0200 Subject: [PATCH 2/2] Use script animation to get task data --- frontend/index.tsx | 1 + frontend/submission/task_platform.ts | 16 ++++++++++++++++ .../libs/smart_contract/SmartContractStorage.tsx | 2 +- frontend/task/task_slice.ts | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/frontend/index.tsx b/frontend/index.tsx index 57f21368..2ff3d037 100644 --- a/frontend/index.tsx +++ b/frontend/index.tsx @@ -156,6 +156,7 @@ declare global { quickAlgoLanguageStrings: any, taskStrings?: any, SmartContractConfig?: SmartContractConfigType, + taskData?: any, } } diff --git a/frontend/submission/task_platform.ts b/frontend/submission/task_platform.ts index 4690d5f1..1fe0708a 100644 --- a/frontend/submission/task_platform.ts +++ b/frontend/submission/task_platform.ts @@ -136,6 +136,22 @@ export function* getTaskFromId(taskId: string): Generator } export function convertServerTaskToCodecastFormat(task: TaskServer): Task { + // task.scriptAnimation = "\n window.taskData = subTask = {};\n subTask.gridInfos = {\n context: 'smart_contract',\n importModules: ['smart_contract_config'],\n showLabels: true,\n conceptViewer: true,\n includeBlocks: {\n groupByCategory: true,\n standardBlocks: {\n wholeCategories: ['smart_contract_main_blocks', 'smart_contract_types'],\n },\n },\n expectedStorage: \"(string %names)\",\n taskStrings: {\n \"storageDescription\": {\n \"names\": \"it should contain its initial value then the list of names of the callers, all separated with commas\",\n },\n },\n // expectedStorage: \"(Pair (string %names) (nat %nb_calls))\",\n };\n "; + if (task.scriptAnimation) { + try { + eval(task.scriptAnimation); + } catch (ex) { + console.error("Couldn't execute script animation", ex); + } + + if (window.taskData?.gridInfos) { + return { + ...task, + gridInfos: window.taskData.gridInfos, + }; + } + } + // Use this for now to check if it's a Smart Contract task. Change this in the future if (smartContractPlatforms.find(platform => -1 !== task.supportedLanguages.indexOf(platform))) { return { diff --git a/frontend/task/libs/smart_contract/SmartContractStorage.tsx b/frontend/task/libs/smart_contract/SmartContractStorage.tsx index 2ea4694c..47e232e6 100644 --- a/frontend/task/libs/smart_contract/SmartContractStorage.tsx +++ b/frontend/task/libs/smart_contract/SmartContractStorage.tsx @@ -22,7 +22,7 @@ export function SmartContractStorage() {

    {storageVariables.map(({name, type}) => -
  • {name} should be a {type}{window?.taskStrings?.storageDescription[name] ? ': ' + window?.taskStrings?.storageDescription[name] : ''}
  • +
  • {name} should be a {type}{task.gridInfos.taskStrings?.storageDescription[name] ? ': ' + task.gridInfos.taskStrings?.storageDescription[name] : ''}
  • )}
diff --git a/frontend/task/task_slice.ts b/frontend/task/task_slice.ts index 5c2f6061..5d92c723 100644 --- a/frontend/task/task_slice.ts +++ b/frontend/task/task_slice.ts @@ -149,6 +149,7 @@ export interface QuickalgoTaskGridInfosNotLevelDependent { expectedStorage?: string, initActionDelay?: number, hints?: TaskHint[], + taskStrings?: any, } export interface QuickalgoTaskGridInfos extends QuickalgoTaskGridInfosNotLevelDependent {