feat: add onboarding and calibration features to experiments, including UI updates and database schema changes
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import db from '@/lib/db';
|
||||
import { experiment_calibration } from '@/lib/model/experiment_calibration';
|
||||
import { experiment } from '@/lib/model/experiment';
|
||||
import { participant } from '@/lib/model/participant';
|
||||
import { eq, and } from 'drizzle-orm';
|
||||
import { auth } from '@/lib/auth';
|
||||
@@ -88,6 +89,22 @@ export async function isCalibrationDone(experimentId: number): Promise<boolean>
|
||||
const session = await auth.api.getSession({ headers: await headers() });
|
||||
if (!session) throw new Error('Nicht angemeldet');
|
||||
|
||||
// Check if calibration is enabled for this experiment
|
||||
const exp = await db
|
||||
.select()
|
||||
.from(experiment)
|
||||
.where(eq(experiment.id, experimentId))
|
||||
.limit(1);
|
||||
|
||||
if (exp.length === 0) {
|
||||
throw new Error('Experiment not found');
|
||||
}
|
||||
|
||||
// If calibration is not enabled, consider it done
|
||||
if (!exp[0].calibrationEnabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get calibration items for this experiment
|
||||
const calibrationItems = await db
|
||||
.select()
|
||||
|
||||
@@ -14,13 +14,17 @@ export async function createExperiment({
|
||||
description,
|
||||
datasetId,
|
||||
annotationTool,
|
||||
published = false
|
||||
published = false,
|
||||
onboardingEnabled = false,
|
||||
calibrationEnabled = false
|
||||
}: {
|
||||
name: string;
|
||||
description?: string;
|
||||
datasetId: number;
|
||||
annotationTool?: string;
|
||||
published?: boolean;
|
||||
onboardingEnabled?: boolean;
|
||||
calibrationEnabled?: boolean;
|
||||
}) {
|
||||
const result = await requireAdmin();
|
||||
if (!result.authenticated || !result.admin) {
|
||||
@@ -38,6 +42,8 @@ export async function createExperiment({
|
||||
datasetId,
|
||||
annotationTool: annotationTool?.trim(),
|
||||
published,
|
||||
onboardingEnabled,
|
||||
calibrationEnabled,
|
||||
});
|
||||
revalidatePath('/admin/experiments');
|
||||
return result;
|
||||
@@ -49,7 +55,7 @@ export async function createExperiment({
|
||||
|
||||
export async function updateExperiment(
|
||||
id: number,
|
||||
updates: { name?: string; description?: string, annotationTool?: string, published?: boolean }
|
||||
updates: { name?: string; description?: string, annotationTool?: string, published?: boolean, onboardingEnabled?: boolean, calibrationEnabled?: boolean }
|
||||
) {
|
||||
const result = await requireAdmin();
|
||||
if (!result.authenticated || !result.admin) {
|
||||
@@ -74,6 +80,12 @@ export async function updateExperiment(
|
||||
if (updates.published !== undefined) {
|
||||
updateData.published = updates.published;
|
||||
}
|
||||
if (updates.onboardingEnabled !== undefined) {
|
||||
updateData.onboardingEnabled = updates.onboardingEnabled;
|
||||
}
|
||||
if (updates.calibrationEnabled !== undefined) {
|
||||
updateData.calibrationEnabled = updates.calibrationEnabled;
|
||||
}
|
||||
updateData.updatedAt = new Date();
|
||||
|
||||
const result = await db
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import db from '@/lib/db';
|
||||
import { participant } from '@/lib/model/participant';
|
||||
import { experiment } from '@/lib/model/experiment';
|
||||
import { eq, and } from 'drizzle-orm';
|
||||
import { auth } from '@/lib/auth';
|
||||
import { headers } from 'next/headers';
|
||||
@@ -11,6 +12,22 @@ export async function isOnboardingDone(experimentId: number): Promise<boolean> {
|
||||
if (!session) throw new Error('Nicht angemeldet');
|
||||
|
||||
try {
|
||||
// Check if onboarding is enabled for this experiment
|
||||
const exp = await db
|
||||
.select()
|
||||
.from(experiment)
|
||||
.where(eq(experiment.id, experimentId))
|
||||
.limit(1);
|
||||
|
||||
if (exp.length === 0) {
|
||||
throw new Error('Experiment not found');
|
||||
}
|
||||
|
||||
// If onboarding is not enabled, consider it done
|
||||
if (!exp[0].onboardingEnabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const participantRecord = await db
|
||||
.select()
|
||||
.from(participant)
|
||||
|
||||
Reference in New Issue
Block a user