Skip to content

Commit

Permalink
Merge pull request #128 from ia-toki/feature/proof-reading
Browse files Browse the repository at this point in the history
create feature proof reading latihan
  • Loading branch information
1234iqbal authored Feb 26, 2024
2 parents f22f2f5 + fc249c2 commit 7739f8c
Show file tree
Hide file tree
Showing 15 changed files with 455 additions and 47 deletions.
22 changes: 22 additions & 0 deletions app/lib/core/constants/status_task_set.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
List<Map<String, String>> dropdownItems = [
{
'value': 'draft',
'text': 'Draft',
},
{
'value': 'need_review',
'text': 'Need Review',
},
{
'value': 'ready',
'text': 'Ready',
},
{
'value': 'reserve',
'text': 'Reserve',
},
{
'value': 'canceled',
'text': 'Canceled',
},
];
2 changes: 1 addition & 1 deletion app/lib/features/main/presentation/pages/setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class _SettingPageState extends State<SettingPage> {
),
Button(
onTap: () {
context.push('/task_list');
context.push('/group_task_list');
},
buttonType: ButtonType.primary,
text: 'Lihat Bebras Task',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ class QuizExerciseCubit extends Cubit<QuizExerciseState> {
);
}

Future<bool> updateStatus(String taskId, String? status) async {
try {
quizExerciseRepository = QuizExerciseRepository();
await quizExerciseRepository.updateQuizExercise(taskId, status);
return true;
} catch (e) {
// Handle errors, log, etc.
print('Error updating status: $e');
return false; // Operation failed
}
}

void fillAnswer(String answer) {
shortAnswer = answer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ class QuizExerciseBase {
final String id;
final String challengeGroup;
final String title;
final String? status;

QuizExerciseBase({
required this.id,
required this.challengeGroup,
required this.title,
this.status
});

factory QuizExerciseBase.fromJson(Map<String, dynamic> json) {
return QuizExerciseBase(
id: json['id'] as String,
challengeGroup: json['challenge_group'] as String,
title: json['title'] as String,
status: json['status'] as String?,
);
}
}
Expand All @@ -36,6 +39,7 @@ class QuizExercise extends QuizExerciseBase {
required super.id,
required super.challengeGroup,
required super.title,
required super.status,
required this.country,
required this.source,
required this.type,
Expand All @@ -49,6 +53,7 @@ class QuizExercise extends QuizExerciseBase {
id: json['id'] as String,
challengeGroup: json['challenge_group'] as String,
title: json['title'] as String,
status: json['status'] as String?,
country: json['country'] as String,
source: json['source'] as String,
type: json['type'] as String,
Expand Down
76 changes: 41 additions & 35 deletions app/lib/features/quiz_exercise/presentation/pages/task_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TaskDialog extends StatelessWidget {
// child: HtmlWithCachedImages(data: task.question.content),
// ),
// ),
if (!preview)
// if (!preview)
...task.question.options!.asMap().entries.map((e) {
final current = String.fromCharCode(65 + e.key);

Expand Down Expand Up @@ -85,7 +85,7 @@ class TaskDialog extends StatelessWidget {
},
);
}),
if (!preview)
// if (!preview)
task.type == 'SHORT_ANSWER'
? Container(
padding: const EdgeInsets.only(top: 20),
Expand All @@ -111,45 +111,51 @@ class TaskDialog extends StatelessWidget {
},
),
),
SizedBox(
width: 100,
height: 50,
child: Button(
buttonType: ButtonType.tertiary,
text: 'OK',
onTap: () {
var error = '';
if (task.type == 'SHORT_ANSWER') {
if (shortAnswer == '') {
error = 'Isi jawaban anda';
}
} else {
if (selectedAnswer == '') {
error = 'Pilih salah satu jawaban';

if (!preview)
SizedBox(
width: 100,
height: 50,
child: Button(
buttonType: ButtonType.tertiary,
text: 'OK',
onTap: () {
var error = '';
if (task.type == 'SHORT_ANSWER') {
if (shortAnswer == '') {
error = 'Isi jawaban anda';
}
} else {
if (selectedAnswer == '') {
error = 'Pilih salah satu jawaban';
}
}
}

if (error != '') {
final snackBar = SnackBar(
backgroundColor: Colors.red,
duration: const Duration(seconds: 1),
behavior: SnackBarBehavior.floating,
margin:
const EdgeInsets.only(bottom: 50, left: 10, right: 10),
content: Text(error),
);
if (error != '') {
final snackBar = SnackBar(
backgroundColor: Colors.red,
duration: const Duration(seconds: 1),
behavior: SnackBarBehavior.floating,
margin:
const EdgeInsets.only(
bottom: 50,
left: 10,
right: 10
),
content: Text(error),
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);
ScaffoldMessenger.of(context).showSnackBar(snackBar);

error = '';
return;
}
error = '';
return;
}

context.read<QuizExerciseCubit>().submitAnswer();
Navigator.pop(context);
},
context.read<QuizExerciseCubit>().submitAnswer();
Navigator.pop(context);
},
),
),
),
],
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ class QuizExerciseRepository {
}
}

Future<List<QuizExerciseBase>> getListQuizExerciseBase() async {
Future<List<QuizExerciseBase>> getListQuizExerciseBase(String group) async {
final quizExerciseBaseList = <QuizExerciseBase>[];
try {
final globalResult =
await db.collection('configuration').doc('global_variables').get();

final taskSet = globalResult.get('task_set_doc_index') as List<dynamic>;
for (final element in taskSet) {
quizExerciseBaseList
final challengeGroup = element['challenge_group'] as String;
if (challengeGroup == group) {
quizExerciseBaseList
.add(QuizExerciseBase.fromJson(element as Map<String, dynamic>));
}
}

return quizExerciseBaseList;
Expand All @@ -87,14 +91,26 @@ class QuizExerciseRepository {
}
}

Future<List<QuizExerciseBase>> getListQuizExerciseNew() async {
final quizExerciseBaseList = <QuizExerciseBase>[];
try {

return quizExerciseBaseList;
} catch (e) {
throw Exception(e.toString());
}
}

Future<QuizExercise> getQuizExercise(String taskId) async {
try {
final result =
await db.collection('task_set').where('id', isEqualTo: taskId).get();
if (result.docs.isEmpty) {
throw Exception('Task ID not found');
}

final data = result.docs.first;

return QuizExercise.fromJson(data.data());
} catch (e) {
throw Exception(e.toString());
Expand All @@ -116,4 +132,54 @@ class QuizExerciseRepository {
rethrow;
}
}

Future<void> updateQuizExercise(
String taskId,
String? status,
) async {
try {
// Update Status Task Set
await FirebaseFirestore.instance
.collection('task_set')
.doc(taskId)
.update({
'status': status,
});

// Dapatkan referensi ke dokumen yang akan diperbarui
final globalResult = FirebaseFirestore.instance
.collection('configuration')
.doc('global_variables');

// Dapatkan data saat ini dari dokumen
final snapshot = await globalResult.get();

// Dapatkan list task_set_doc_index
final taskSet = snapshot['task_set_doc_index'] as List<dynamic>;
final weeklyQuizNumber = snapshot['weeklyquiz_number'] as int;

// Temukan indeks dari dokumen dengan doc_id yang sesuai
var indexToUpdate = -1;
for (var i = 0; i < taskSet.length; i++) {
if (taskSet[i]['doc_id'] == taskId) {
indexToUpdate = i;
break;
}
}

// Jika indeks ditemukan, lakukan pembaruan
if (indexToUpdate != -1) {
taskSet[indexToUpdate]['status'] = status;
}

// Update Status Configuration
await globalResult.update({
'task_set_doc_index': taskSet,
'weeklyquiz_number' : weeklyQuizNumber
});

} catch (e) {
throw Exception(e.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class TaskDetailCubit extends Cubit<TaskDetailState> {
}
final quizExerciseRepository = QuizExerciseRepository();
final task = await quizExerciseRepository.getQuizExercise(taskId);

emit(TaskDetailSuccess(task: task));
} catch (e) {
emit(TaskDetailFailed(e.toString()));
Expand Down
9 changes: 8 additions & 1 deletion app/lib/features/task_detail/presentation/pages/_pages.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../../core/bases/enum/button_type.dart';
import '../../../../core/bases/widgets/atoms/button.dart';
import '../../../../core/bases/widgets/atoms/html_cached_image.dart';
import '../../../../core/bases/widgets/layout/bebras_scaffold.dart';
import '../../../../core/constants/assets.dart';
import '../../../../core/constants/status_task_set.dart';
import '../../../../core/theme/font_theme.dart';
import '../../../quiz_exercise/presentation/bloc/quiz_exercise_cubit.dart';
import '../../../quiz_exercise/presentation/model/quiz_exercise.dart';
import '../../../quiz_exercise/presentation/pages/task_dialog.dart';
import '../../../quiz_exercise/presentation/pages/task_view.dart';
import '../bloc/task_detail_cubit.dart';

part 'task_detail_page.dart';
part 'task_view_detail_page.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class _TaskDetailPageState extends State<TaskDetailPage> {
BlocBuilder<TaskDetailCubit, TaskDetailState>(
builder: (context, state) {
if (state is TaskDetailSuccess) {
return TaskView(
return TaskViewDetail(
task: state.task,
context: context,
onTap: () {
Expand Down Expand Up @@ -72,6 +72,7 @@ class _TaskDetailPageState extends State<TaskDetailPage> {
return TaskDialog(
task: state.task,
preview: true,

);
}
return const SizedBox(
Expand Down
Loading

0 comments on commit 7739f8c

Please sign in to comment.