diff --git a/playground/src/components/view_mode/evaluation_mode/expert_evaluation/evaluation_management.tsx b/playground/src/components/view_mode/evaluation_mode/expert_evaluation/evaluation_management.tsx index fc9c5752..da87b68c 100644 --- a/playground/src/components/view_mode/evaluation_mode/expert_evaluation/evaluation_management.tsx +++ b/playground/src/components/view_mode/evaluation_mode/expert_evaluation/evaluation_management.tsx @@ -66,7 +66,7 @@ export default function EvaluationManagement() { return newConfig; }; - const saveExpertEvaluationConfig = (configToSave = selectedConfig) => { + const saveExpertEvaluationConfig = (configToSave = selectedConfig, isAnonymize = false) => { const isNewConfig = configToSave.id === "new"; const newConfig = isNewConfig ? { ...configToSave, id: uuidv4() } : configToSave; setExpertEvaluationConfigs((prevConfigs) => { @@ -81,7 +81,7 @@ export default function EvaluationManagement() { }); setSelectedConfig(newConfig); - externalSaveExpertEvaluationConfig(dataMode, newConfig, isNewConfig); + externalSaveExpertEvaluationConfig(dataMode, newConfig, isAnonymize); setHasUnsavedChanges(false); }; @@ -122,7 +122,7 @@ export default function EvaluationManagement() { const startEvaluation = () => { if (confirm("Are you sure you want to start the evaluation? Once started, you can add new expert links but no other changes can be made to the configuration!")) { const updatedConfig = updateSelectedConfig({ started: true }); - saveExpertEvaluationConfig(updatedConfig); + saveExpertEvaluationConfig(updatedConfig, true); } }; diff --git a/playground/src/helpers/get_data.ts b/playground/src/helpers/get_data.ts index 19c0b33e..4cc1790a 100644 --- a/playground/src/helpers/get_data.ts +++ b/playground/src/helpers/get_data.ts @@ -364,8 +364,18 @@ export function anonymizeFeedbackCategoriesAndShuffle( export function saveConfigToFileSync( dataMode: DataMode, expertEvaluation: ExpertEvaluationConfig, -) { - const configData = JSON.stringify(expertEvaluation, null, 2); + isAddExpertLinksAfterStart = false +){ + + if (isAddExpertLinksAfterStart) { + let config = getConfigFromFileSync(dataMode, expertEvaluation.id); + if (config && config.expertIds) { + config.expertIds = expertEvaluation.expertIds; + expertEvaluation = config; + } + } + + let configData = JSON.stringify(expertEvaluation, null, 2); const configPath = path.join( process.cwd(), @@ -410,7 +420,8 @@ export function saveConfigToFileSync( } // Create or update config file with exercises and data - return fs.writeFileSync(configPath, configData, 'utf8'); + fs.writeFileSync(configPath, configData, 'utf8'); + return configData; } export function getProgressStatsFromFileSync( diff --git a/playground/src/hooks/playground/expert_evaluation_config.ts b/playground/src/hooks/playground/expert_evaluation_config.ts index 5e54d865..d58d4c33 100644 --- a/playground/src/hooks/playground/expert_evaluation_config.ts +++ b/playground/src/hooks/playground/expert_evaluation_config.ts @@ -6,10 +6,10 @@ import { DataMode } from "@/model/data_mode"; export async function saveExpertEvaluationConfig( dataMode: DataMode, config: ExpertEvaluationConfig, - isCreate: boolean) { + isAnonymize: boolean) { - const response = await fetch(`${baseUrl}/api/data/${dataMode}/expert_evaluation/${config.id}/config`, { - method: isCreate ? 'POST' : 'PUT', + const response = await fetch(`${baseUrl}/api/data/${dataMode}/expert_evaluation/${config.id}/config?isAnonymize=${isAnonymize}`, { + method: 'POST', headers: { "Content-Type": "application/json" }, body: JSON.stringify(config), }); diff --git a/playground/src/pages/api/data/[dataMode]/expert_evaluation/[expertEvaluationId]/config.ts b/playground/src/pages/api/data/[dataMode]/expert_evaluation/[expertEvaluationId]/config.ts index 1bc5a2a6..3d69d347 100644 --- a/playground/src/pages/api/data/[dataMode]/expert_evaluation/[expertEvaluationId]/config.ts +++ b/playground/src/pages/api/data/[dataMode]/expert_evaluation/[expertEvaluationId]/config.ts @@ -11,19 +11,19 @@ import { ExpertEvaluationConfig } from "@/model/expert_evaluation_config"; function handler(req: NextApiRequest, res: NextApiResponse) { if (req.method == 'POST') { - const { dataMode } = req.query as { dataMode: DataMode }; + const { dataMode, isAnonymize } = req.query as { dataMode: DataMode, isAnonymize: string }; const expertEvaluationConfig: ExpertEvaluationConfig = req.body; - anonymizeFeedbackCategoriesAndShuffle(expertEvaluationConfig); - saveConfigToFileSync(dataMode, expertEvaluationConfig); - return res.status(200).json({ message: 'Config created successfully' }); + if (isAnonymize == "true") { + anonymizeFeedbackCategoriesAndShuffle(expertEvaluationConfig); + saveConfigToFileSync(dataMode, expertEvaluationConfig); - } else if (req.method == 'PUT') { - const { dataMode } = req.query as { dataMode: DataMode }; - const expertEvaluationConfig: ExpertEvaluationConfig = req.body; + // Add expert links after the evaluation has already started + } else { + saveConfigToFileSync(dataMode, expertEvaluationConfig, expertEvaluationConfig.started); + } - saveConfigToFileSync(dataMode, expertEvaluationConfig); - return res.status(200).json({ message: 'Config saved successfully' }); + return res.status(200).json({expertEvaluationConfig}); } else if (req.method == 'GET') { const { dataMode, expertEvaluationId } = req.query as { dataMode: DataMode; expertEvaluationId: string }; @@ -33,7 +33,7 @@ function handler(req: NextApiRequest, res: NextApiResponse) { return res.status(200).json(config); } else { res.setHeader('Allow', ['POST']); - return res.status(405).json({ message: 'Only GET, POST and PUT requests allowed' }); + return res.status(405).json({ message: 'Only GET and POST requests allowed' }); } }