Update Saqel Platform: 2026-09-10 12:26:22
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'dart:math';
|
||||
import 'dart:typed_data';
|
||||
import '../../data/models/teacher_models.dart';
|
||||
import '../../data/repositories/teacher_repository.dart';
|
||||
@@ -267,6 +268,20 @@ class TeacherStudioCubit extends Cubit<TeacherStudioState> {
|
||||
state.unitKey,
|
||||
state.lessonKey
|
||||
].where((e) => e.isNotEmpty).join('/');
|
||||
|
||||
String? get selectedCurriculumLessonId {
|
||||
final lessons = _units[state.unitKey]?['lessons'];
|
||||
if (lessons is! List) return null;
|
||||
for (final item in lessons) {
|
||||
if (item is Map && item['id']?.toString() == state.lessonKey) {
|
||||
final id = item['curriculum_lesson_id']?.toString();
|
||||
return id != null && id.isNotEmpty ? id : null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String _newIdempotencyKey() => 'teacher_${DateTime.now().microsecondsSinceEpoch}_${Random.secure().nextInt(1 << 32)}';
|
||||
void reportError(String message) =>
|
||||
emit(state.copyWith(errorMessage: message));
|
||||
|
||||
@@ -300,6 +315,11 @@ class TeacherStudioCubit extends Cubit<TeacherStudioState> {
|
||||
errorMessage: 'اختر الصف والمبحث والفصل والوحدة والدرس أولاً.'));
|
||||
return;
|
||||
}
|
||||
if (selectedCurriculumLessonId == null) {
|
||||
emit(state.copyWith(
|
||||
errorMessage: 'هذا الدرس غير معتمد للنشر بعد، لذلك لا يمكن رفع حصة له.'));
|
||||
return;
|
||||
}
|
||||
await uploadAndPublishLesson();
|
||||
}
|
||||
|
||||
@@ -316,12 +336,31 @@ class TeacherStudioCubit extends Cubit<TeacherStudioState> {
|
||||
clearError: true,
|
||||
));
|
||||
try {
|
||||
final preflight = await repository.preflightSubmission(
|
||||
curriculumLessonId: selectedCurriculumLessonId!,
|
||||
idempotencyKey: _newIdempotencyKey(),
|
||||
);
|
||||
if (preflight['status']?.toString() != 'ready_for_upload') {
|
||||
emit(state.copyWith(
|
||||
isAuditing: false,
|
||||
isUploading: false,
|
||||
uploadProgress: 0.0,
|
||||
uploadPhase: 'idle',
|
||||
errorMessage: preflight['message']?.toString() ?? 'تعذر تجهيز نسخة الحصة للرفع.',
|
||||
));
|
||||
return false;
|
||||
}
|
||||
final videoVersionId = preflight['video_version_id']?.toString();
|
||||
if (videoVersionId == null || videoVersionId.isEmpty) {
|
||||
throw StateError('لم ينشئ الخادم نسخة فيديو صالحة للرفع.');
|
||||
}
|
||||
final res = await repository.uploadLesson(
|
||||
title: state.lessonTitle,
|
||||
durationMinutes: state.durationMinutes,
|
||||
gradeLevel: state.gradeLevel,
|
||||
subject: selectedSubjectName,
|
||||
curriculumKey: curriculumKey,
|
||||
videoVersionId: videoVersionId,
|
||||
fileName: state.selectedFileName!,
|
||||
fileSizeMb: state.selectedFileSizeMb,
|
||||
filePath: state.selectedFilePath,
|
||||
@@ -368,7 +407,7 @@ class TeacherStudioCubit extends Cubit<TeacherStudioState> {
|
||||
return false;
|
||||
}
|
||||
|
||||
final msg = res['message']?.toString() ?? 'تم اعتماد الحصة ورفعها بنجاح.';
|
||||
final msg = res['message']?.toString() ?? 'تم رفع الحصة إلى طابور المراجعة.';
|
||||
emit(state.copyWith(
|
||||
isAuditing: false,
|
||||
isUploading: false,
|
||||
|
||||
Reference in New Issue
Block a user