Skip to content

Commit

Permalink
Merge pull request #37 from aninarafath6/admin
Browse files Browse the repository at this point in the history
Admin
  • Loading branch information
aninarafath6 committed Dec 21, 2022
2 parents e48bb35 + e740781 commit 2d7b983
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 129 deletions.
8 changes: 4 additions & 4 deletions arnhss-app/lib/common/routes/app_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class AppRoutes {
return MaterialPageRoute(builder: (_) => const AdmissionView());
case CourseView.routeName:
return MaterialPageRoute(builder: (_) {
final Course args = settings.arguments as Course;
return CourseView(selectedCourse: args);
// final Course args = settings.arguments as Course;
return const CourseView();
});

// case UserRole.routeName:
Expand All @@ -39,8 +39,8 @@ class AppRoutes {
// return MaterialPageRoute(builder: (_) => const StudentAuthentication());
case SingleBatchView.routeName:
return MaterialPageRoute(builder: (_) {
var args = settings.arguments;
return SingleBatchView(selectedBatch: args as Batch);
// var args = settings.arguments;
return const SingleBatchView();
});

case SelectAccount.routeName:
Expand Down
4 changes: 3 additions & 1 deletion arnhss-app/lib/common/widgets/custom_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ class CustomInput extends StatelessWidget {
this.hintText,
this.size = Sizing.sm,
this.controller,
this.keyboardType = TextInputType.multiline,
}) : super(key: key);

final String? hintText;
final Sizing size;
final TextEditingController? controller;
final TextInputType keyboardType;

@override
Widget build(BuildContext context) {
Expand All @@ -32,12 +34,12 @@ class CustomInput extends StatelessWidget {
borderRadius: BorderRadius.circular(8),
),
child: TextField(
keyboardType: keyboardType,
maxLines: size == Sizing.xl
? 20
: size == Sizing.lg
? 5
: 1,
keyboardType: TextInputType.multiline,
controller: controller,
minLines: 1,
cursorColor: CustomColors.dark,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class AdmissionService with HandleException {
},
);
} catch (e) {
print(e);
handleException(
InvalidException(
"Batch cannot be added because there is something wrong with them 🤯",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import 'package:arnhss/extensions/string_extension.dart';
import 'package:arnhss/features/users/admin/admission/model/course_model.dart';
import 'package:arnhss/features/users/admin/admission/repo/admission_service.dart';
Expand All @@ -10,6 +9,7 @@ import 'package:flutter/material.dart';
class AdmissionViewModel with ChangeNotifier, HandleException {
//* admission service object.
final AdmissionService _admissionService = AdmissionService();
late Course selectedCourse;

late TextEditingController nameController = TextEditingController();
late TextEditingController courseCodeController = TextEditingController();
Expand All @@ -34,6 +34,11 @@ class AdmissionViewModel with ChangeNotifier, HandleException {
notifyListeners();
}

set setSelectedCourse(Course course) {
selectedCourse = course;
notifyListeners();
}

set _setToggleLoading(bool state) {
_setLoading = state;
notifyListeners();
Expand Down Expand Up @@ -194,6 +199,7 @@ class AdmissionViewModel with ChangeNotifier, HandleException {
var index =
_courses.indexWhere((element) => element.id == updatedCourse.id);
_courses[index] = updatedCourse;
selectedCourse = updatedCourse;
});
//* set loading as false
_setToggleLoading = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:intl/intl.dart';
class BatchViewModel extends ChangeNotifier with HandleException {
final AdmissionService _admissionService = AdmissionService();

late Batch selectedBatch;
late TextEditingController nameController = TextEditingController();
late TextEditingController batchCodeController = TextEditingController();
DateTime startDateController = DateTime.now();
Expand Down Expand Up @@ -69,7 +70,8 @@ class BatchViewModel extends ChangeNotifier with HandleException {
}

//* edit batch
void setUpToUpdate(Batch batch) {
void setUpToUpdate() {
var batch = selectedBatch;
nameController.text = batch.name;
endDateController = batch.endDate;
startDateController = batch.startDate;
Expand All @@ -79,6 +81,8 @@ class BatchViewModel extends ChangeNotifier with HandleException {
void clearControllers() {
nameController.clear();
batchCodeController.clear();
startDateController = DateTime.now();
endDateController = DateTime.utc(DateTime.now().year + 2);
}

void setUpForAdd(Course course) {
Expand All @@ -87,6 +91,12 @@ class BatchViewModel extends ChangeNotifier with HandleException {
"${formatter.format(startDateController).toString()}-${formatter.format(endDateController).toString()} ${course.d_code.toUpperCase()}";
}

void setupToAdd(String courseDc) {
nameController.text =
"${startDateController.year}-${endDateController.year} $courseDc";
batchCodeController.text = (hold.length + 1).toString();
}

void get toggleFilter {
_filter = !filter;
if (_filter) {
Expand Down Expand Up @@ -134,6 +144,7 @@ class BatchViewModel extends ChangeNotifier with HandleException {
}

//* validate

bool validate({String? id}) {
//* handling errors
try {
Expand All @@ -144,34 +155,23 @@ class BatchViewModel extends ChangeNotifier with HandleException {
if (batchCodeController.text.isEmpty) {
throw InvalidException("Please enter batch code..!!", false);
} else {
List<Batch> check = _batches.where(
List<Batch> check = hold.where(
(element) {
if (id == null) {
return element.code.toUpperCase() ==
batchCodeController.text.trim().toUpperCase() ||
element.name.toUpperCase() ==
nameController.text.trim().toUpperCase();
batchCodeController.text.trim().toUpperCase();
} else {
return element.code.toUpperCase() ==
batchCodeController.text.trim().toUpperCase() &&
element.id != id ||
element.name.toUpperCase() ==
nameController.text.trim().toUpperCase();
batchCodeController.text.trim().toUpperCase() &&
element.id != id;
}
},
).toList();

if (check.isNotEmpty) {
throw InvalidException(
"Batch id or name is already exist..", false);
throw InvalidException("Course id is already exist..", false);
} else {
if (startDateController.microsecondsSinceEpoch <
endDateController.microsecondsSinceEpoch) {
return true;
} else {
throw InvalidException(
"Start date must be greater than end date...", false);
}
return true;
}
}
}
Expand Down Expand Up @@ -220,6 +220,8 @@ class BatchViewModel extends ChangeNotifier with HandleException {
Future<void> deleteBatch(Batch? batch) async {
if (batch != null) {
_batches.removeWhere((element) => element.id == batch.id);
hold.removeWhere((element) => element.id == batch.id);

debugPrint("=== batch deletion process started =====");
_setToggleDeleteLoading = true;
await Future.delayed(const Duration(milliseconds: 300));
Expand All @@ -242,8 +244,6 @@ class BatchViewModel extends ChangeNotifier with HandleException {
Future<bool> update(Batch oldBatch) async {
bool isValid = validate(id: oldBatch.id);

print("here");

// * validate inputs fields
if (isValid) {
//* create new batch with new data
Expand All @@ -263,6 +263,8 @@ class BatchViewModel extends ChangeNotifier with HandleException {
var index =
_batches.indexWhere((element) => element.id == updatedBatch.id);
_batches[index] = updatedBatch;
selectedBatch = updatedBatch;
notifyListeners();
});
//* set loading as false
_setToggleLoading = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
import 'package:arnhss/common/routes/index_routes.dart';
import 'package:arnhss/extensions/string_extension.dart';
import 'package:arnhss/features/users/admin/admission/model/batch_model.dart';
import 'package:arnhss/features/users/admin/admission/model/course_model.dart';
import 'package:arnhss/features/users/admin/admission/repo/admission_service.dart';
import 'package:arnhss/services/base/exception/app_exceptions.dart';
import 'package:arnhss/services/base/exception/handle_exception.dart';
import 'package:intl/intl.dart';
// import 'package:arnhss/common/routes/index_routes.dart';
// import 'package:arnhss/extensions/string_extension.dart';
// import 'package:arnhss/features/users/admin/admission/model/batch_model.dart';
// import 'package:arnhss/features/users/admin/admission/model/course_model.dart';
// import 'package:arnhss/features/users/admin/admission/repo/admission_service.dart';
// import 'package:arnhss/services/base/exception/app_exceptions.dart';
// import 'package:arnhss/services/base/exception/handle_exception.dart';
// import 'package:intl/intl.dart';

class CourseViewModel with ChangeNotifier, HandleException {
final List<Batch> _batches = [];
// int get batchCount => _batches.length;
// class CourseViewModel with ChangeNotifier, HandleException {
// final List<Batch> _batches = [];
// // int get batchCount => _batches.length;

//* getters.
// List<Batch> get batches => _batches;
// //* getters.
// // List<Batch> get batches => _batches;

// //* setters.
// set _toggleLoading(bool state) {
// _loading = state;
// notifyListeners();
// }
// // //* setters.
// // set _toggleLoading(bool state) {
// // _loading = state;
// // notifyListeners();
// // }

// set _setBatch(List<Batch> newBatch) {
// // _batches.clear();
// _batches.addAll(newBatch);
// // set _setBatch(List<Batch> newBatch) {
// // // _batches.clear();
// // _batches.addAll(newBatch);

// notifyListeners();
// }
// // notifyListeners();
// // }

// //* add course functionality
// Future<bool> addBatch(Course course) async {
// bool isValid = validate();
// // //* add course functionality
// // Future<bool> addBatch(Course course) async {
// // bool isValid = validate();

// // * validate inputs fields
// if (isValid) {
// //* create new course with new data
// Batch newBatch = Batch(
// name: nameController.text.trim().capitalize,
// startDate: startDateController,
// code: batchCodeController.text.trim().toUpperCase(),
// endDate: endDateController,
// id: "",
// );
// // // * validate inputs fields
// // if (isValid) {
// // //* create new course with new data
// // Batch newBatch = Batch(
// // name: nameController.text.trim().capitalize,
// // startDate: startDateController,
// // code: batchCodeController.text.trim().toUpperCase(),
// // endDate: endDateController,
// // id: "",
// // );

// //* start loading
// //* and set course on firebase
// _setToggleLoading = true;
// await _admissionService.addBatch(newBatch, courseId: course.id).then(
// (course) => _setBatch = [
// ..._batches,
// course ?? newBatch,
// ],
// );
// //* set loading as false
// _setToggleLoading = false;
// // //* start loading
// // //* and set course on firebase
// // _setToggleLoading = true;
// // await _admissionService.addBatch(newBatch, courseId: course.id).then(
// // (course) => _setBatch = [
// // ..._batches,
// // course ?? newBatch,
// // ],
// // );
// // //* set loading as false
// // _setToggleLoading = false;

// //* clear input controllers's value
// clearControllers();
// return true;
// } else {
// return false;
// }
// }
// // //* clear input controllers's value
// // clearControllers();
// // return true;
// // } else {
// // return false;
// // }
// // }


}
// }
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class _AdmissionViewState extends State<AdmissionView> {
horizontal: AppSizes.default_padding - 10, vertical: 5),
child: Consumer<AdmissionViewModel>(
builder: (context, value, _) {

return value.loading
? ListView.builder(
itemCount: 5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:arnhss/common/widgets/not_found.dart';
import 'package:arnhss/features/authentication/otp_verification/view/index.dart';
import 'package:arnhss/features/users/admin/admission/model/batch_model.dart';
import 'package:arnhss/features/users/admin/admission/model/course_model.dart';
import 'package:arnhss/features/users/admin/admission/view_model/admission_view_model.dart';
import 'package:arnhss/features/users/admin/admission/view_model/batches_view_model.dart';
import 'package:arnhss/features/users/admin/admission/widgets/forms.dart';
import 'package:arnhss/features/users/admin/admission/widgets/batch_card.dart';
Expand Down Expand Up @@ -113,9 +112,14 @@ class _BatchesViewState extends State<BatchesView> {
),
floatingActionButton: TextButton(
onPressed: () {
context.read<AdmissionViewModel>().clearControllers();
context.read<BatchViewModel>().clearControllers();
context
.read<BatchViewModel>()
.setupToAdd(widget.selectedCourse.d_code);

showBatchForm(
context,
dc: widget.selectedCourse.d_code,
title: "New Batch",
onSubmit: () async {
bool status = await context
Expand Down
Loading

0 comments on commit 2d7b983

Please sign in to comment.