Merge branch 'dev' into hugo-shipping-notice
This commit is contained in:
commit
331cfdc361
14 files changed
+769
-83
No files matched your search
@@ -273,12 +273,26 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
));
|
||||
const canEnterResultStage = computed(() => stage.value === 'result');
|
||||
const safetyProgressPercent = computed(() => {
|
||||
if (safetyStage.value === 'company') return 25;
|
||||
if (safetyStage.value === 'department') return 50;
|
||||
if (safetyStage.value === 'team') return 75;
|
||||
if (safetyStage.value === 'exam') return 90;
|
||||
return 100;
|
||||
if (safetyStage.value === 'result') return 100;
|
||||
|
||||
let completedCount = 0;
|
||||
if (isStageCompleted('company')) completedCount++;
|
||||
if (isStageCompleted('department')) completedCount++;
|
||||
if (isStageCompleted('team')) completedCount++;
|
||||
|
||||
return Math.round((completedCount / 3) * 75) || 10; // Start at 10% or just based on completed
|
||||
});
|
||||
const isStageCompleted = (stageKey: SafetyLearningStage) => {
|
||||
const materials = resolveSafetyStageMaterials(stageKey);
|
||||
if (!materials.length) return true;
|
||||
return materials.every(m => {
|
||||
if (m.id == null) return true;
|
||||
const progress = safetyProgress.value.resource_progress?.[String(m.id)];
|
||||
return progress?.completed;
|
||||
});
|
||||
};
|
||||
|
||||
const safetyStepItems = computed(() => {
|
||||
const base: Array<{ id: SafetyStage extends infer U ? U : never; labelKey: string }> = [
|
||||
{ id: 'company', labelKey: 'chat.training.safety.steps.company' },
|
||||
@@ -288,26 +302,22 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
];
|
||||
return base.map((item) => {
|
||||
let status: 'completed' | 'active' | 'pending' | 'locked' = 'pending';
|
||||
if (item.id === 'company') {
|
||||
status = safetyProgress.value.company === 'completed'
|
||||
? 'completed'
|
||||
: safetyProgress.value.company === 'active' ? 'active' : 'pending';
|
||||
} else if (item.id === 'department') {
|
||||
status = safetyProgress.value.department === 'completed'
|
||||
? 'completed'
|
||||
: safetyProgress.value.department === 'active' ? 'active' : 'pending';
|
||||
} else if (item.id === 'team') {
|
||||
status = safetyProgress.value.team === 'completed'
|
||||
? 'completed'
|
||||
: safetyProgress.value.team === 'active' ? 'active' : 'pending';
|
||||
if (item.id === 'company' || item.id === 'department' || item.id === 'team') {
|
||||
const completed = isStageCompleted(item.id);
|
||||
if (safetyViewStage.value === item.id) {
|
||||
status = 'active';
|
||||
} else if (completed) {
|
||||
status = 'completed';
|
||||
} else {
|
||||
status = 'pending';
|
||||
}
|
||||
} else if (item.id === 'exam') {
|
||||
status = ['exam', 'result'].includes(safetyStage.value)
|
||||
? (safetyStage.value === 'exam' ? 'active' : 'completed')
|
||||
: (safetyProgress.value.company === 'completed'
|
||||
&& safetyProgress.value.department === 'completed'
|
||||
&& safetyProgress.value.team === 'completed'
|
||||
? 'pending'
|
||||
: 'locked');
|
||||
const allCompleted = isStageCompleted('company') && isStageCompleted('department') && isStageCompleted('team');
|
||||
if (['exam', 'result'].includes(safetyStage.value)) {
|
||||
status = safetyStage.value === 'exam' ? 'active' : 'completed';
|
||||
} else {
|
||||
status = allCompleted ? 'pending' : 'locked';
|
||||
}
|
||||
}
|
||||
return {
|
||||
id: item.id,
|
||||
@@ -519,8 +529,30 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
examMode.value = record.examMode || 'unified';
|
||||
if (learnerTab.value === 'safety') {
|
||||
safetyStage.value = record.safetyStage || 'company';
|
||||
safetyProgress.value = record.safetyProgress;
|
||||
safetyViewStage.value = record.safetyStage || 'company';
|
||||
// Ensure resource_progress is preserved when merging from backend
|
||||
safetyProgress.value = {
|
||||
...record.safetyProgress,
|
||||
resource_progress: record.safetyProgress?.resource_progress || safetyProgress.value.resource_progress || {}
|
||||
};
|
||||
|
||||
// Sync legacy fields with actual resource completion
|
||||
safetyProgress.value.company = isStageCompleted('company') ? 'completed' : 'active';
|
||||
safetyProgress.value.department = isStageCompleted('department') ? 'completed' : 'active';
|
||||
safetyProgress.value.team = isStageCompleted('team') ? 'completed' : 'active';
|
||||
|
||||
if (safetyStage.value !== 'exam' && safetyStage.value !== 'result') {
|
||||
if (!isStageCompleted('company')) {
|
||||
safetyViewStage.value = 'company';
|
||||
} else if (!isStageCompleted('department')) {
|
||||
safetyViewStage.value = 'department';
|
||||
} else if (!isStageCompleted('team')) {
|
||||
safetyViewStage.value = 'team';
|
||||
} else {
|
||||
safetyViewStage.value = 'company';
|
||||
}
|
||||
} else {
|
||||
safetyViewStage.value = record.safetyStage || 'company';
|
||||
}
|
||||
}
|
||||
stage.value = record.stage;
|
||||
syncExamQuestionIndex(record.currentQuestionIndex);
|
||||
@@ -735,15 +767,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
const markVideoCompleted = () => {
|
||||
if (!hasPublishedTrainingConfig.value || !videoUrl.value) return;
|
||||
if (learnerTab.value === 'safety') {
|
||||
if (safetyStage.value === 'company') {
|
||||
resetSafetyProgress('department');
|
||||
} else if (safetyStage.value === 'department') {
|
||||
resetSafetyProgress('team');
|
||||
} else if (safetyStage.value === 'team') {
|
||||
resetSafetyProgress('exam');
|
||||
enterSafetyExam();
|
||||
}
|
||||
void persistProgress();
|
||||
checkAndAdvanceStage();
|
||||
return;
|
||||
}
|
||||
stage.value = 'summary';
|
||||
@@ -861,7 +885,13 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
if (!hasPublishedTrainingConfig.value) return;
|
||||
const target = safetyStepItems.value.find((item) => item.id === nextStage);
|
||||
if (!target || target.status === 'locked') return;
|
||||
safetyViewStage.value = nextStage;
|
||||
|
||||
if (nextStage === 'exam' && safetyStage.value !== 'exam' && safetyStage.value !== 'result') {
|
||||
enterSafetyExam();
|
||||
void persistProgress();
|
||||
} else {
|
||||
safetyViewStage.value = nextStage;
|
||||
}
|
||||
};
|
||||
|
||||
const exportRecords = async () => {
|
||||
@@ -930,6 +960,12 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
const currentViewingMaterialId = ref<number | null>(null);
|
||||
const materialStartTime = ref<number>(0);
|
||||
|
||||
const currentViewingMaterialRequiredDuration = computed(() => {
|
||||
if (!currentViewingMaterialId.value) return 0;
|
||||
const resource = (publishedConfig.value?.resources || []).find((item) => String(item.id) === String(currentViewingMaterialId.value));
|
||||
return resource?.requiredDuration || 0;
|
||||
});
|
||||
|
||||
const startMaterialTimer = (materialId: number) => {
|
||||
currentViewingMaterialId.value = materialId;
|
||||
materialStartTime.value = Date.now();
|
||||
@@ -963,32 +999,32 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
};
|
||||
|
||||
const checkAndAdvanceStage = () => {
|
||||
const activeStageMaterials = learnerTab.value === 'safety'
|
||||
? resolveSafetyStageMaterials(activeSafetyLearningStage.value)
|
||||
: publishedTrainingMaterials.value;
|
||||
if (!activeStageMaterials.length) return;
|
||||
const allCompleted = activeStageMaterials.every(m => {
|
||||
if (m.id == null) return true;
|
||||
const progress = safetyProgress.value.resource_progress?.[String(m.id)];
|
||||
return progress?.completed;
|
||||
});
|
||||
|
||||
if (allCompleted) {
|
||||
if (learnerTab.value === 'safety') {
|
||||
if (safetyStage.value === 'company') {
|
||||
resetSafetyProgress('department');
|
||||
} else if (safetyStage.value === 'department') {
|
||||
resetSafetyProgress('team');
|
||||
} else if (safetyStage.value === 'team') {
|
||||
resetSafetyProgress('exam');
|
||||
enterSafetyExam();
|
||||
}
|
||||
} else {
|
||||
stage.value = 'summary';
|
||||
}
|
||||
void persistProgress();
|
||||
// Update legacy string fields to reflect real status based on resources
|
||||
safetyProgress.value.company = isStageCompleted('company') ? 'completed' : 'active';
|
||||
safetyProgress.value.department = isStageCompleted('department') ? 'completed' : 'active';
|
||||
safetyProgress.value.team = isStageCompleted('team') ? 'completed' : 'active';
|
||||
|
||||
if (learnerTab.value === 'safety') {
|
||||
const allSafetyCompleted = isStageCompleted('company') && isStageCompleted('department') && isStageCompleted('team');
|
||||
|
||||
if (allSafetyCompleted && safetyStage.value !== 'exam' && safetyStage.value !== 'result') {
|
||||
safetyStage.value = 'exam';
|
||||
enterSafetyExam();
|
||||
}
|
||||
void persistProgress();
|
||||
} else {
|
||||
void persistProgress();
|
||||
const activeStageMaterials = publishedTrainingMaterials.value;
|
||||
if (!activeStageMaterials.length) return;
|
||||
const allCompleted = activeStageMaterials.every(m => {
|
||||
if (m.id == null) return true;
|
||||
const progress = safetyProgress.value.resource_progress?.[String(m.id)];
|
||||
return progress?.completed;
|
||||
});
|
||||
|
||||
if (allCompleted) {
|
||||
stage.value = 'summary';
|
||||
}
|
||||
void persistProgress();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1084,6 +1120,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
startMaterialTimer,
|
||||
stopMaterialTimer,
|
||||
currentViewingMaterialId,
|
||||
currentViewingMaterialRequiredDuration,
|
||||
currentTrainingAgentId,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user