From 8b0bae0891657a227fef46a691ad1d1d3602a8ba Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Tue, 25 Oct 2022 17:49:16 +0300 Subject: [PATCH 1/2] Worklist updates --- lib/api/api_client.dart | 4 +- lib/classes/utils.dart | 8 +- lib/provider/dashboard_provider_model.dart | 6 +- lib/ui/landing/widget/app_drawer.dart | 1 + .../offers_and_discounts_home.dart | 9 +- lib/ui/work_list/work_list_screen.dart | 29 +++--- lib/ui/work_list/worklist_detail_screen.dart | 96 +++++++++---------- .../dialogs/accept_reject_input_dialog.dart | 4 +- 8 files changed, 83 insertions(+), 74 deletions(-) diff --git a/lib/api/api_client.dart b/lib/api/api_client.dart index 7a6f668..dc9375d 100644 --- a/lib/api/api_client.dart +++ b/lib/api/api_client.dart @@ -81,8 +81,8 @@ class ApiClient { } if (!kReleaseMode) { print("Url:$url"); - var bodyJson = json.encode(jsonObject); - print("body:$bodyJson"); + // var bodyJson = json.encode(jsonObject); + // print("body:$bodyJson"); } var response = await postJsonForResponse(url, jsonObject, token: token, diff --git a/lib/classes/utils.dart b/lib/classes/utils.dart index dbe451c..af9e340 100644 --- a/lib/classes/utils.dart +++ b/lib/classes/utils.dart @@ -52,6 +52,10 @@ class Utils { } } + static Future delay(int millis) async { + return await Future.delayed(Duration(milliseconds: millis)); + } + static void showLoading(BuildContext context) { WidgetsBinding.instance.addPostFrameCallback((_) { _isLoadingVisible = true; @@ -65,10 +69,6 @@ class Utils { }); } - static Future delay(int millis) async { - return await Future.delayed(Duration(milliseconds: millis)); - } - static void hideLoading(BuildContext context) { if (_isLoadingVisible) { _isLoadingVisible = false; diff --git a/lib/provider/dashboard_provider_model.dart b/lib/provider/dashboard_provider_model.dart index c5286ef..eaa6277 100644 --- a/lib/provider/dashboard_provider_model.dart +++ b/lib/provider/dashboard_provider_model.dart @@ -134,15 +134,15 @@ class DashboardProviderModel with ChangeNotifier, DiagnosticableTreeMixin { workListCounter = genericResponseModel?.pOPENNTFNUMBER ?? 0; - itgFormsModel = await DashboardApiClient().getItgFormsPendingTask(); - workListCounter = workListCounter + (itgFormsModel?.totalCount ?? 0); + if (showLoading) Utils.hideLoading(context); GenericResponseModel? cocGenericResponseModel = await DashboardApiClient().getCOCNotifications(); cocCount = cocGenericResponseModel?.mohemmITGPendingTaskResponseItem; if (cocCount != null) { cocFinalCount = (cocCount?.escalation ?? 0) + (cocCount?.waitingToClose ?? 0) + (cocCount?.waitingForAcceptance ?? 0) + (cocCount?.extendTATRequest ?? 0); workListCounter += cocFinalCount; } - if (showLoading) Utils.hideLoading(context); + itgFormsModel = await DashboardApiClient().getItgFormsPendingTask(); + workListCounter = workListCounter + (itgFormsModel?.totalCount ?? 0); notifyListeners(); } catch (ex) { isWorkListLoading = false; diff --git a/lib/ui/landing/widget/app_drawer.dart b/lib/ui/landing/widget/app_drawer.dart index 67adfcb..ac70035 100644 --- a/lib/ui/landing/widget/app_drawer.dart +++ b/lib/ui/landing/widget/app_drawer.dart @@ -164,6 +164,7 @@ class _AppDrawerState extends State { AppState().setPostParamsModel(obj!); Navigator.pop(context); widget.onLanguageChange(); + setState(() {}); } void performLogout() async { diff --git a/lib/ui/screens/offers_and_discounts/offers_and_discounts_home.dart b/lib/ui/screens/offers_and_discounts/offers_and_discounts_home.dart index e33a161..45247dc 100644 --- a/lib/ui/screens/offers_and_discounts/offers_and_discounts_home.dart +++ b/lib/ui/screens/offers_and_discounts/offers_and_discounts_home.dart @@ -183,7 +183,6 @@ class _OffersAndDiscountsHomeState extends State { ), ), ), - 10.height, AppState().isArabic(context) ? getOffersList.titleAR!.toText16(isBold: true, color: const Color(0xff2B353E), maxlines: 1) : getOffersList.title!.toText16(isBold: true, color: const Color(0xff2B353E), maxlines: 1), @@ -194,7 +193,7 @@ class _OffersAndDiscountsHomeState extends State { // // } // ), getOffersList.description!.toText12(maxLine: 2, color: const Color(0xff535353)), - 16.height, + // 8.height, getOffersList.discount!.toText14(isBold: true, maxlines: 1), 10.height, Row( @@ -212,7 +211,11 @@ class _OffersAndDiscountsHomeState extends State { if (enteredKeyword.isEmpty) { results = getOffersList; } else { - results = getOffersList.where((offer) => offer.title!.toLowerCase().contains(enteredKeyword.toLowerCase())).toList(); + if(AppState().isArabic(context)) { + results = getOffersList.where((offer) => offer.titleAR!.toLowerCase().contains(enteredKeyword.toLowerCase())).toList(); + } else { + results = getOffersList.where((offer) => offer.title!.toLowerCase().contains(enteredKeyword.toLowerCase())).toList(); + } } setState(() { _foundOffersList = results; diff --git a/lib/ui/work_list/work_list_screen.dart b/lib/ui/work_list/work_list_screen.dart index 369bf0c..190ac71 100644 --- a/lib/ui/work_list/work_list_screen.dart +++ b/lib/ui/work_list/work_list_screen.dart @@ -120,9 +120,8 @@ class _WorkListScreenState extends State { ItgFormsModel? itgFormsModel; int? itgRequestTypeIndex; - Future getWorkList({bool showLoading = true}) async { + Future getWorkList({bool showLoading = true, bool callWorkList = true}) async { try { - if (showLoading) Utils.showLoading(context); if (workListItemTypes[workListItemIndex].key == "ITG") { itgFormsModel = await WorkListApiClient().getITGTaskCountRequestType(); List requestAllList = []; @@ -138,31 +137,36 @@ class _WorkListScreenState extends State { itgRequestTypeIndex = 0; } } else { + if (showLoading) Utils.showLoading(context); itgRequestTypeIndex = null; - workList = await WorkListApiClient().getWorkList(pageNumber, workListItemTypes[workListItemIndex].key, pNotificationType.toString()); - AppState().setWorkList = workList; + if (callWorkList) { + workList = await WorkListApiClient().getWorkList(pageNumber, workListItemTypes[workListItemIndex].key, pNotificationType.toString()); + AppState().setWorkList = workList; + } + if (showLoading) Utils.hideLoading(context); + setState(() {}); } - if (showLoading) Utils.hideLoading(context); - if (showLoading) setState(() {}); } catch (ex) { if (showLoading) Utils.hideLoading(context); if (showLoading) Utils.handleException(ex, context, null); } } - void _onRefresh() async { + void _onRefresh({bool callWorkList = true}) async { try { _refreshController.refreshCompleted(); - Utils.showLoading(context); + if(callWorkList) Utils.showLoading(context); List dataOnRefresh = await Future.wait([ - providerData.fetchWorkListCounter(context, showLoading: false), - getWorkList(showLoading: false), + providerData.fetchWorkListCounter(context, showLoading: true).then((value) { + setState(() {}); + }), + getWorkList(showLoading: false, callWorkList: callWorkList), ]); calculateCounter(); - Utils.hideLoading(context); + if(callWorkList) Utils.hideLoading(context); setState(() {}); } catch (ex) { - Utils.hideLoading(context); + if(callWorkList) Utils.hideLoading(context); Utils.handleException(ex, context, null); } } @@ -443,6 +447,7 @@ class _WorkListScreenState extends State { if (mounted) setState(() {}); } } else { + _onRefresh(callWorkList: false); if (mounted) setState(() {}); } }, diff --git a/lib/ui/work_list/worklist_detail_screen.dart b/lib/ui/work_list/worklist_detail_screen.dart index 7aea35e..feb424e 100644 --- a/lib/ui/work_list/worklist_detail_screen.dart +++ b/lib/ui/work_list/worklist_detail_screen.dart @@ -40,6 +40,7 @@ import 'package:mohem_flutter_app/widgets/dialogs/accept_reject_input_dialog.dar import 'package:mohem_flutter_app/widgets/dialogs/confirm_dialog.dart'; class WorkListDetailScreen extends StatefulWidget { + WorkListDetailScreen({Key? key}) : super(key: key); @override @@ -98,6 +99,12 @@ class _WorkListDetailScreenState extends State { if (workListData!.iTEMTYPE == "HRSSA" || workListData!.iTEMTYPE == "STAMP") { getUserInformation(); } + + getNotificationButtons(); + notificationGetRespondAttributes(); + getAttachments(); + getActionHistory(); + if (workListData!.iTEMTYPE == "HRSSA") { if (workListData!.rEQUESTTYPE == "EIT") { getEitNotificationBody(); @@ -130,8 +137,6 @@ class _WorkListDetailScreenState extends State { getPRNotification(); } - notificationGetRespondAttributes(); - // List dataToFetch = await Future.wait([ // // WorkListApiClient().getActionHistory(workListData!.nOTIFICATIONID!), @@ -142,10 +147,6 @@ class _WorkListDetailScreenState extends State { // actionHistoryList = dataToFetch[1]; // getAttachmentList = dataToFetch[2]; - getNotificationButtons(); - getActionHistory(); - getAttachments(); - // if (notificationButtonsList.isNotEmpty) { // isCloseAvailable = notificationButtonsList.any((element) => element.bUTTONACTION == "CLOSE"); // isApproveAvailable = notificationButtonsList.any((element) => element.bUTTONACTION == "APPROVED"); @@ -487,7 +488,6 @@ class _WorkListDetailScreenState extends State { builder: (cxt) => AcceptRejectInputDialog( message: LocaleKeys.requestedItems.tr(), notificationGetRespond: notificationNoteInput, - textEditingController: textEditingController, onTap: (note) { Map payload = { "P_ACTION_MODE": actionMode, @@ -503,7 +503,7 @@ class _WorkListDetailScreenState extends State { } ], }; - if (actionMode == "APPROVED" || actionMode == "APPROVE") { + if (actionMode == "APPROVED" || actionMode == "APPROVE" || actionMode == "CLOSE") { performNotificationAction(payload); } else if (note.isNotEmpty && (actionMode != "APPROVED" || actionMode != "APPROVE")) { performNotificationAction(payload); @@ -540,34 +540,34 @@ class _WorkListDetailScreenState extends State { void getEitNotificationBody() async { try { - if (apiCallCount == 0) Utils.showLoading(context); - apiCallCount++; + // if (apiCallCount == 0) Utils.showLoading(context); + // apiCallCount++; getEitCollectionNotificationBodyList = await WorkListApiClient().GetEitNotificationBody(workListData!.nOTIFICATIONID); - apiCallCount--; - if (apiCallCount == 0) { - Utils.hideLoading(context); + // apiCallCount--; + // if (apiCallCount == 0) { + // Utils.hideLoading(context); setState(() {}); - } + // } } catch (ex) { - apiCallCount--; - Utils.hideLoading(context); + // apiCallCount--; + // Utils.hideLoading(context); Utils.handleException(ex, context, null); } } void getUserInformation() async { try { - if (apiCallCount == 0) Utils.showLoading(context); - apiCallCount++; + // if (apiCallCount == 0) Utils.showLoading(context); + // apiCallCount++; memberInformationListModel = await WorkListApiClient().getUserInformation(-999, workListData!.sELECTEDEMPLOYEENUMBER!); - apiCallCount--; - if (apiCallCount == 0) { - Utils.hideLoading(context); + // apiCallCount--; + // if (apiCallCount == 0) { + // Utils.hideLoading(context); setState(() {}); - } + // } } catch (ex) { - apiCallCount--; - Utils.hideLoading(context); + // apiCallCount--; + // Utils.hideLoading(context); Utils.handleException(ex, context, null); } } @@ -608,17 +608,17 @@ class _WorkListDetailScreenState extends State { void getAbsenceNotificationBody() async { try { - if (apiCallCount == 0) Utils.showLoading(context); - apiCallCount++; + // if (apiCallCount == 0) Utils.showLoading(context); + // apiCallCount++; getAbsenceCollectionNotificationBodyList = await WorkListApiClient().getAbsenceNotificationBody(workListData!.nOTIFICATIONID); - apiCallCount--; - if (apiCallCount == 0) { - Utils.hideLoading(context); + // apiCallCount--; + // if (apiCallCount == 0) { + // Utils.hideLoading(context); setState(() {}); - } + // } } catch (ex) { - apiCallCount--; - Utils.hideLoading(context); + // apiCallCount--; + // Utils.hideLoading(context); Utils.handleException(ex, context, null); } } @@ -731,20 +731,20 @@ class _WorkListDetailScreenState extends State { void notificationGetRespondAttributes() async { try { - if (apiCallCount == 0) Utils.showLoading(context); - apiCallCount++; + // if (apiCallCount == 0) Utils.showLoading(context); + // apiCallCount++; getNotificationRespondAttributes = await WorkListApiClient().notificationGetRespondAttributes(workListData!.nOTIFICATIONID!); if (getNotificationRespondAttributes.isNotEmpty) { notificationNoteInput = getNotificationRespondAttributes.first; } - apiCallCount--; - if (apiCallCount == 0) { - Utils.hideLoading(context); + // apiCallCount--; + // if (apiCallCount == 0) { + // Utils.hideLoading(context); setState(() {}); - } + // } } catch (ex) { - apiCallCount--; - Utils.hideLoading(context); + // apiCallCount--; + // Utils.hideLoading(context); Utils.handleException(ex, context, null); } } @@ -773,17 +773,17 @@ class _WorkListDetailScreenState extends State { void getActionHistory() async { try { - if (apiCallCount == 0) Utils.showLoading(context); - apiCallCount++; + // if (apiCallCount == 0) Utils.showLoading(context); + // apiCallCount++; actionHistoryList = await WorkListApiClient().getActionHistory(workListData!.nOTIFICATIONID!); - apiCallCount--; - if (apiCallCount == 0) { - Utils.hideLoading(context); + // apiCallCount--; + // if (apiCallCount == 0) { + // Utils.hideLoading(context); setState(() {}); - } + // } } catch (ex) { - apiCallCount--; - Utils.hideLoading(context); + // apiCallCount--; + // Utils.hideLoading(context); Utils.handleException(ex, context, null); } } diff --git a/lib/widgets/dialogs/accept_reject_input_dialog.dart b/lib/widgets/dialogs/accept_reject_input_dialog.dart index ea84484..ef2cfaa 100644 --- a/lib/widgets/dialogs/accept_reject_input_dialog.dart +++ b/lib/widgets/dialogs/accept_reject_input_dialog.dart @@ -15,9 +15,9 @@ class AcceptRejectInputDialog extends StatelessWidget { final String? okTitle; final NotificationGetRespondAttributesList? notificationGetRespond; final Function(String) onTap; - final TextEditingController textEditingController; + // final TextEditingController textEditingController; - AcceptRejectInputDialog({Key? key, this.title, @required this.message, this.okTitle, required this.onTap, this.notificationGetRespond, required this.textEditingController}) : super(key: key); + AcceptRejectInputDialog({Key? key, this.title, @required this.message, this.okTitle, required this.onTap, this.notificationGetRespond}) : super(key: key); String note = ""; From b2810b53babcdfff0d23e134fe5ba02c1fb552f6 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Wed, 26 Oct 2022 10:13:30 +0300 Subject: [PATCH 2/2] Revert yesterday changes --- lib/provider/dashboard_provider_model.dart | 6 +- lib/ui/work_list/work_list_screen.dart | 29 ++++---- lib/ui/work_list/worklist_detail_screen.dart | 69 ++++++++++---------- 3 files changed, 49 insertions(+), 55 deletions(-) diff --git a/lib/provider/dashboard_provider_model.dart b/lib/provider/dashboard_provider_model.dart index eaa6277..c5286ef 100644 --- a/lib/provider/dashboard_provider_model.dart +++ b/lib/provider/dashboard_provider_model.dart @@ -134,15 +134,15 @@ class DashboardProviderModel with ChangeNotifier, DiagnosticableTreeMixin { workListCounter = genericResponseModel?.pOPENNTFNUMBER ?? 0; - if (showLoading) Utils.hideLoading(context); + itgFormsModel = await DashboardApiClient().getItgFormsPendingTask(); + workListCounter = workListCounter + (itgFormsModel?.totalCount ?? 0); GenericResponseModel? cocGenericResponseModel = await DashboardApiClient().getCOCNotifications(); cocCount = cocGenericResponseModel?.mohemmITGPendingTaskResponseItem; if (cocCount != null) { cocFinalCount = (cocCount?.escalation ?? 0) + (cocCount?.waitingToClose ?? 0) + (cocCount?.waitingForAcceptance ?? 0) + (cocCount?.extendTATRequest ?? 0); workListCounter += cocFinalCount; } - itgFormsModel = await DashboardApiClient().getItgFormsPendingTask(); - workListCounter = workListCounter + (itgFormsModel?.totalCount ?? 0); + if (showLoading) Utils.hideLoading(context); notifyListeners(); } catch (ex) { isWorkListLoading = false; diff --git a/lib/ui/work_list/work_list_screen.dart b/lib/ui/work_list/work_list_screen.dart index 190ac71..369bf0c 100644 --- a/lib/ui/work_list/work_list_screen.dart +++ b/lib/ui/work_list/work_list_screen.dart @@ -120,8 +120,9 @@ class _WorkListScreenState extends State { ItgFormsModel? itgFormsModel; int? itgRequestTypeIndex; - Future getWorkList({bool showLoading = true, bool callWorkList = true}) async { + Future getWorkList({bool showLoading = true}) async { try { + if (showLoading) Utils.showLoading(context); if (workListItemTypes[workListItemIndex].key == "ITG") { itgFormsModel = await WorkListApiClient().getITGTaskCountRequestType(); List requestAllList = []; @@ -137,36 +138,31 @@ class _WorkListScreenState extends State { itgRequestTypeIndex = 0; } } else { - if (showLoading) Utils.showLoading(context); itgRequestTypeIndex = null; - if (callWorkList) { - workList = await WorkListApiClient().getWorkList(pageNumber, workListItemTypes[workListItemIndex].key, pNotificationType.toString()); - AppState().setWorkList = workList; - } - if (showLoading) Utils.hideLoading(context); - setState(() {}); + workList = await WorkListApiClient().getWorkList(pageNumber, workListItemTypes[workListItemIndex].key, pNotificationType.toString()); + AppState().setWorkList = workList; } + if (showLoading) Utils.hideLoading(context); + if (showLoading) setState(() {}); } catch (ex) { if (showLoading) Utils.hideLoading(context); if (showLoading) Utils.handleException(ex, context, null); } } - void _onRefresh({bool callWorkList = true}) async { + void _onRefresh() async { try { _refreshController.refreshCompleted(); - if(callWorkList) Utils.showLoading(context); + Utils.showLoading(context); List dataOnRefresh = await Future.wait([ - providerData.fetchWorkListCounter(context, showLoading: true).then((value) { - setState(() {}); - }), - getWorkList(showLoading: false, callWorkList: callWorkList), + providerData.fetchWorkListCounter(context, showLoading: false), + getWorkList(showLoading: false), ]); calculateCounter(); - if(callWorkList) Utils.hideLoading(context); + Utils.hideLoading(context); setState(() {}); } catch (ex) { - if(callWorkList) Utils.hideLoading(context); + Utils.hideLoading(context); Utils.handleException(ex, context, null); } } @@ -447,7 +443,6 @@ class _WorkListScreenState extends State { if (mounted) setState(() {}); } } else { - _onRefresh(callWorkList: false); if (mounted) setState(() {}); } }, diff --git a/lib/ui/work_list/worklist_detail_screen.dart b/lib/ui/work_list/worklist_detail_screen.dart index feb424e..f2cd760 100644 --- a/lib/ui/work_list/worklist_detail_screen.dart +++ b/lib/ui/work_list/worklist_detail_screen.dart @@ -40,7 +40,6 @@ import 'package:mohem_flutter_app/widgets/dialogs/accept_reject_input_dialog.dar import 'package:mohem_flutter_app/widgets/dialogs/confirm_dialog.dart'; class WorkListDetailScreen extends StatefulWidget { - WorkListDetailScreen({Key? key}) : super(key: key); @override @@ -100,8 +99,8 @@ class _WorkListDetailScreenState extends State { getUserInformation(); } - getNotificationButtons(); notificationGetRespondAttributes(); + getNotificationButtons(); getAttachments(); getActionHistory(); @@ -503,7 +502,7 @@ class _WorkListDetailScreenState extends State { } ], }; - if (actionMode == "APPROVED" || actionMode == "APPROVE" || actionMode == "CLOSE") { + if (actionMode == "APPROVED" || actionMode == "APPROVE") { performNotificationAction(payload); } else if (note.isNotEmpty && (actionMode != "APPROVED" || actionMode != "APPROVE")) { performNotificationAction(payload); @@ -540,34 +539,34 @@ class _WorkListDetailScreenState extends State { void getEitNotificationBody() async { try { - // if (apiCallCount == 0) Utils.showLoading(context); - // apiCallCount++; + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; getEitCollectionNotificationBodyList = await WorkListApiClient().GetEitNotificationBody(workListData!.nOTIFICATIONID); - // apiCallCount--; - // if (apiCallCount == 0) { - // Utils.hideLoading(context); + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); setState(() {}); - // } + } } catch (ex) { - // apiCallCount--; - // Utils.hideLoading(context); + apiCallCount--; + Utils.hideLoading(context); Utils.handleException(ex, context, null); } } void getUserInformation() async { try { - // if (apiCallCount == 0) Utils.showLoading(context); - // apiCallCount++; + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; memberInformationListModel = await WorkListApiClient().getUserInformation(-999, workListData!.sELECTEDEMPLOYEENUMBER!); - // apiCallCount--; - // if (apiCallCount == 0) { - // Utils.hideLoading(context); + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); setState(() {}); - // } + } } catch (ex) { - // apiCallCount--; - // Utils.hideLoading(context); + apiCallCount--; + Utils.hideLoading(context); Utils.handleException(ex, context, null); } } @@ -608,17 +607,17 @@ class _WorkListDetailScreenState extends State { void getAbsenceNotificationBody() async { try { - // if (apiCallCount == 0) Utils.showLoading(context); - // apiCallCount++; + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; getAbsenceCollectionNotificationBodyList = await WorkListApiClient().getAbsenceNotificationBody(workListData!.nOTIFICATIONID); - // apiCallCount--; - // if (apiCallCount == 0) { - // Utils.hideLoading(context); + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); setState(() {}); - // } + } } catch (ex) { - // apiCallCount--; - // Utils.hideLoading(context); + apiCallCount--; + Utils.hideLoading(context); Utils.handleException(ex, context, null); } } @@ -731,20 +730,20 @@ class _WorkListDetailScreenState extends State { void notificationGetRespondAttributes() async { try { - // if (apiCallCount == 0) Utils.showLoading(context); - // apiCallCount++; + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; getNotificationRespondAttributes = await WorkListApiClient().notificationGetRespondAttributes(workListData!.nOTIFICATIONID!); if (getNotificationRespondAttributes.isNotEmpty) { notificationNoteInput = getNotificationRespondAttributes.first; } - // apiCallCount--; - // if (apiCallCount == 0) { - // Utils.hideLoading(context); + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); setState(() {}); - // } + } } catch (ex) { - // apiCallCount--; - // Utils.hideLoading(context); + apiCallCount--; + Utils.hideLoading(context); Utils.handleException(ex, context, null); } }