From caa1f975ab833e33ae2be854c21db71b339d5bf1 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Wed, 21 Feb 2024 10:22:07 +0300 Subject: [PATCH] ppm timer & receiver name fixed. --- lib/models/ppm/ppm.dart | 168 +++++++++--------- .../update_device_transfer.dart | 4 +- .../pages/user/ppm/ppm_details_page.dart | 46 +++-- .../pages/user/ppm/update_ppm/edit_ppm.dart | 4 +- lib/views/widgets/pentry/pentry_tbs_form.dart | 71 ++++---- 5 files changed, 153 insertions(+), 140 deletions(-) diff --git a/lib/models/ppm/ppm.dart b/lib/models/ppm/ppm.dart index 2becf88..c6c5927 100644 --- a/lib/models/ppm/ppm.dart +++ b/lib/models/ppm/ppm.dart @@ -387,88 +387,92 @@ class Ppm { String visitStatusName, String warrantyEndDate, TimerModel tbsTimer, - }) => - Ppm( - id: id ?? this.id, - ppmScheduleId: ppmScheduleId ?? this.ppmScheduleId, - assetId: assetId ?? this.assetId, - jobSheetNo: jobSheetNo ?? this.jobSheetNo, - assignedEmployeeId: assignedEmployeeId ?? this.assignedEmployeeId, - expectedDate: expectedDate ?? this.expectedDate, - actualDate: actualDate ?? this.actualDate, - nextDate: nextDate ?? this.nextDate, - forwardToId: forwardToId ?? this.forwardToId, - maintenanceContractId: maintenanceContractId ?? this.maintenanceContractId, - typeOfServiceId: typeOfServiceId ?? this.typeOfServiceId, - executionTimeFrameId: executionTimeFrameId ?? this.executionTimeFrameId, - externalEngineer: externalEngineer ?? this.externalEngineer, - telephone: telephone ?? this.telephone, - groupLeaderReviewId: groupLeaderReviewId ?? this.groupLeaderReviewId, - timePeriodId: timePeriodId ?? this.timePeriodId, - assignedToId: assignedToId ?? this.assignedToId, - vCalibrationTools: vCalibrationTools ?? this.vCalibrationTools, - vKits: vKits ?? this.vKits, - vContacts: vContacts ?? this.vContacts, - vChecklists: vChecklists ?? this.vChecklists, - files: files ?? this.files, - visitStatusId: visitStatusId ?? this.visitStatusId, - startDate: startDate ?? this.startDate, - endDate: endDate ?? this.endDate, - workingHours: workingHours ?? this.workingHours, - travelingHours: travelingHours ?? this.travelingHours, - deviceStatusId: deviceStatusId ?? this.deviceStatusId, - comments: comments ?? this.comments, - workPerformed: workPerformed ?? this.workPerformed, - supplierId: supplierId ?? this.supplierId, - suppPersonId: suppPersonId ?? this.suppPersonId, - suppStartDate: suppStartDate ?? this.suppStartDate, - suppEndDate: suppEndDate ?? this.suppEndDate, - suppWorkingHours: suppWorkingHours ?? this.suppWorkingHours, - taskStatusId: taskStatusId ?? this.taskStatusId, - engSignature: engSignature ?? this.engSignature, - nurseSignature: nurseSignature ?? this.nurseSignature, - safetyId: safetyId ?? this.safetyId, - assetAvailabilityId: assetAvailabilityId ?? this.assetAvailabilityId, - assetAvailabilityName: assetAvailabilityName ?? this.assetAvailabilityName, - assetName: assetName ?? this.assetName, - assetNumber: assetNumber ?? this.assetNumber, - assetSerialNo: assetSerialNo ?? this.assetSerialNo, - assetSupplierId: assetSupplierId ?? this.assetSupplierId, - assetSupplierName: assetSupplierName ?? this.assetSupplierName, - assignedEmployeeName: assignedEmployeeName ?? this.assignedEmployeeName, - assignedToName: assignedToName ?? this.assignedToName, - createdOn: createdOn ?? this.createdOn, - departmentId: departmentId ?? this.departmentId, - departmentName: departmentName ?? this.departmentName, - deviceStatusName: deviceStatusName ?? this.deviceStatusName, - dueDate: dueDate ?? this.dueDate, - executionTimeFrameName: executionTimeFrameName ?? this.executionTimeFrameName, - forwardToName: forwardToName ?? this.forwardToName, - manufacturerId: manufacturerId ?? this.manufacturerId, - manufacturerName: manufacturerName ?? this.manufacturerName, - modifiedOn: modifiedOn ?? this.modifiedOn, - notified: notified ?? this.notified, - planCode: planCode ?? this.planCode, - planNo: planNo ?? this.planNo, - ppmId: ppmId ?? this.ppmId, - ppmScheduleCode: ppmScheduleCode ?? this.ppmScheduleCode, - ppmScheduleNo: ppmScheduleNo ?? this.ppmScheduleNo, - ppmSupplierId: ppmSupplierId ?? this.ppmSupplierId, - ppmSupplierName: ppmSupplierName ?? this.ppmSupplierName, - safetyName: safetyName ?? this.safetyName, - siteId: siteId ?? this.siteId, - siteName: siteName ?? this.siteName, - supplierName: supplierName ?? this.supplierName, - suppPerson: suppPerson ?? this.suppPerson, - taskStatusName: taskStatusName ?? this.taskStatusName, - timePeriodName: timePeriodName ?? this.timePeriodName, - timePeriodValue: timePeriodValue ?? this.timePeriodValue, - typeOfServiceName: typeOfServiceName ?? this.typeOfServiceName, - visitCode: visitCode ?? this.visitCode, - visitNo: visitNo ?? this.visitNo, - visitStatusName: visitStatusName ?? this.visitStatusName, - warrantyEndDate: warrantyEndDate ?? this.warrantyEndDate, - )..tbsTimer = tbsTimer ?? this.tbsTimer; + }) { + Ppm ppm = Ppm( + id: id ?? this.id, + ppmScheduleId: ppmScheduleId ?? this.ppmScheduleId, + assetId: assetId ?? this.assetId, + jobSheetNo: jobSheetNo ?? this.jobSheetNo, + assignedEmployeeId: assignedEmployeeId ?? this.assignedEmployeeId, + expectedDate: expectedDate ?? this.expectedDate, + actualDate: actualDate ?? this.actualDate, + nextDate: nextDate ?? this.nextDate, + forwardToId: forwardToId ?? this.forwardToId, + maintenanceContractId: maintenanceContractId ?? this.maintenanceContractId, + typeOfServiceId: typeOfServiceId ?? this.typeOfServiceId, + executionTimeFrameId: executionTimeFrameId ?? this.executionTimeFrameId, + externalEngineer: externalEngineer ?? this.externalEngineer, + telephone: telephone ?? this.telephone, + groupLeaderReviewId: groupLeaderReviewId ?? this.groupLeaderReviewId, + timePeriodId: timePeriodId ?? this.timePeriodId, + assignedToId: assignedToId ?? this.assignedToId, + vCalibrationTools: vCalibrationTools ?? this.vCalibrationTools, + vKits: vKits ?? this.vKits, + vContacts: vContacts ?? this.vContacts, + vChecklists: vChecklists ?? this.vChecklists, + files: files ?? this.files, + visitStatusId: visitStatusId ?? this.visitStatusId, + startDate: startDate ?? this.startDate, + endDate: endDate ?? this.endDate, + workingHours: workingHours ?? this.workingHours, + travelingHours: travelingHours ?? this.travelingHours, + deviceStatusId: deviceStatusId ?? this.deviceStatusId, + comments: comments ?? this.comments, + workPerformed: workPerformed ?? this.workPerformed, + supplierId: supplierId ?? this.supplierId, + suppPersonId: suppPersonId ?? this.suppPersonId, + suppStartDate: suppStartDate ?? this.suppStartDate, + suppEndDate: suppEndDate ?? this.suppEndDate, + suppWorkingHours: suppWorkingHours ?? this.suppWorkingHours, + taskStatusId: taskStatusId ?? this.taskStatusId, + engSignature: engSignature ?? this.engSignature, + nurseSignature: nurseSignature ?? this.nurseSignature, + safetyId: safetyId ?? this.safetyId, + assetAvailabilityId: assetAvailabilityId ?? this.assetAvailabilityId, + assetAvailabilityName: assetAvailabilityName ?? this.assetAvailabilityName, + assetName: assetName ?? this.assetName, + assetNumber: assetNumber ?? this.assetNumber, + assetSerialNo: assetSerialNo ?? this.assetSerialNo, + assetSupplierId: assetSupplierId ?? this.assetSupplierId, + assetSupplierName: assetSupplierName ?? this.assetSupplierName, + assignedEmployeeName: assignedEmployeeName ?? this.assignedEmployeeName, + assignedToName: assignedToName ?? this.assignedToName, + createdOn: createdOn ?? this.createdOn, + departmentId: departmentId ?? this.departmentId, + departmentName: departmentName ?? this.departmentName, + deviceStatusName: deviceStatusName ?? this.deviceStatusName, + dueDate: dueDate ?? this.dueDate, + executionTimeFrameName: executionTimeFrameName ?? this.executionTimeFrameName, + forwardToName: forwardToName ?? this.forwardToName, + manufacturerId: manufacturerId ?? this.manufacturerId, + manufacturerName: manufacturerName ?? this.manufacturerName, + modifiedOn: modifiedOn ?? this.modifiedOn, + notified: notified ?? this.notified, + planCode: planCode ?? this.planCode, + planNo: planNo ?? this.planNo, + ppmId: ppmId ?? this.ppmId, + ppmScheduleCode: ppmScheduleCode ?? this.ppmScheduleCode, + ppmScheduleNo: ppmScheduleNo ?? this.ppmScheduleNo, + ppmSupplierId: ppmSupplierId ?? this.ppmSupplierId, + ppmSupplierName: ppmSupplierName ?? this.ppmSupplierName, + safetyName: safetyName ?? this.safetyName, + siteId: siteId ?? this.siteId, + siteName: siteName ?? this.siteName, + supplierName: supplierName ?? this.supplierName, + suppPerson: suppPerson ?? this.suppPerson, + taskStatusName: taskStatusName ?? this.taskStatusName, + timePeriodName: timePeriodName ?? this.timePeriodName, + timePeriodValue: timePeriodValue ?? this.timePeriodValue, + typeOfServiceName: typeOfServiceName ?? this.typeOfServiceName, + visitCode: visitCode ?? this.visitCode, + visitNo: visitNo ?? this.visitNo, + visitStatusName: visitStatusName ?? this.visitStatusName, + warrantyEndDate: warrantyEndDate ?? this.warrantyEndDate, + ); + + ppm.tbsTimer = tbsTimer ?? this.tbsTimer; + return ppm; + } Map toJson() { final map = {}; diff --git a/lib/views/pages/device_transfer/update_device_transfer.dart b/lib/views/pages/device_transfer/update_device_transfer.dart index bb44a61..18802d3 100644 --- a/lib/views/pages/device_transfer/update_device_transfer.dart +++ b/lib/views/pages/device_transfer/update_device_transfer.dart @@ -261,9 +261,7 @@ class _UpdateDeviceTransferState extends State { context.translation.transferDetails.heading5(context), 8.height, '${context.translation.assetName}: ${_formModel.assetName.cleanupWhitespace.capitalizeFirstOfEach}'.bodyText(context), - - ///TBDZ - '${context.translation.requesterName}: '.bodyText(context), + '${context.translation.requesterName}: ${_formModel?.receiverEndUserName?.cleanupWhitespace?.capitalizeFirstOfEach??""}'.bodyText(context), ], ).toShadowContainer(context); } diff --git a/lib/views/pages/user/ppm/ppm_details_page.dart b/lib/views/pages/user/ppm/ppm_details_page.dart index a7cb28b..380c339 100644 --- a/lib/views/pages/user/ppm/ppm_details_page.dart +++ b/lib/views/pages/user/ppm/ppm_details_page.dart @@ -19,22 +19,43 @@ import '../../../../new_views/app_style/app_color.dart'; import '../../../../new_views/common_widgets/app_filled_button.dart'; import '../../../widgets/requests/request_status.dart'; -class PpmDetailsPage extends StatelessWidget { +class PpmDetailsPage extends StatefulWidget { static const String id = "/visit-details"; final RequestsDetails request; - const PpmDetailsPage({Key key, this.request}) : super(key: key); + PpmDetailsPage({Key key, this.request}) : super(key: key); + + @override + _PpmDetailsPageState createState() { + return _PpmDetailsPageState(); + } +} + +class _PpmDetailsPageState extends State { + UserProvider userProvider; + + PpmProvider ppmProvider; + + @override + void initState() { + super.initState(); + } + + @override + void dispose() { + super.dispose(); + } @override Widget build(BuildContext context) { - UserProvider userProvider = Provider.of(context); - PpmProvider ppmProvider = Provider.of(context); + userProvider ??= Provider.of(context, listen: false); + ppmProvider ??= Provider.of(context, listen: false); return Scaffold( appBar: DefaultAppBar(title: context.translation.preventiveMaintenance), body: SafeArea( child: FutureBuilder( - future: ppmProvider.getPpmById(request.id), + future: ppmProvider.getPpmById(widget.request.id), builder: (context, snap) { if (snap.connectionState == ConnectionState.waiting) { return const ALoading(); @@ -48,13 +69,13 @@ class PpmDetailsPage extends StatelessWidget { children: [ Row( children: [ - if (request.priority != null) + if (widget.request.priority != null) StatusLabel( - label: request.priority, - textColor: AppColor.getRequestStatusTextColorByName(context, request.priority), - backgroundColor: AppColor.getRequestStatusColorByName(context, request.priority), + label: widget.request.priority, + textColor: AppColor.getRequestStatusTextColorByName(context, widget.request.priority), + backgroundColor: AppColor.getRequestStatusColorByName(context, widget.request.priority), ), - if (request.priority != null) 8.width, + if (widget.request.priority != null) 8.width, StatusLabel( label: ppm.visitStatusName, id: ppm.deviceStatusId, @@ -82,8 +103,9 @@ class PpmDetailsPage extends StatelessWidget { ).expanded, if (userProvider.user.type == UsersTypes.engineer && (ppm.visitStatusId != 270 && ppm.visitStatusId != 269)) AppFilledButton( - onPressed: () { - Navigator.of(context).push(MaterialPageRoute(builder: (_) => EditPpm(ppm: ppm, details: request))); + onPressed: () async { + await Navigator.of(context).push(MaterialPageRoute(builder: (_) => EditPpm(ppm: ppm, details: widget.request))); + setState(() {}); }, label: context.translation.updateRequest, ).paddingAll(16) diff --git a/lib/views/pages/user/ppm/update_ppm/edit_ppm.dart b/lib/views/pages/user/ppm/update_ppm/edit_ppm.dart index c3928a3..99759f0 100644 --- a/lib/views/pages/user/ppm/update_ppm/edit_ppm.dart +++ b/lib/views/pages/user/ppm/update_ppm/edit_ppm.dart @@ -60,8 +60,8 @@ class _EditPpmState extends State with SingleTickerProviderStateMixin { @override Widget build(BuildContext context) { - _userProvider = Provider.of(context); - _regularVisitsProvider = Provider.of(context); + _userProvider = Provider.of(context,listen: false); + _regularVisitsProvider = Provider.of(context,listen: false); return Scaffold( appBar: DefaultAppBar(title: context.translation.preventiveMaintenance), key: _scaffoldKey, diff --git a/lib/views/widgets/pentry/pentry_tbs_form.dart b/lib/views/widgets/pentry/pentry_tbs_form.dart index 7394686..2b75875 100644 --- a/lib/views/widgets/pentry/pentry_tbs_form.dart +++ b/lib/views/widgets/pentry/pentry_tbs_form.dart @@ -28,24 +28,10 @@ class PentryTBSForm extends StatefulWidget { } class _PentryTBSFormState extends State { - Ppm _model; - - @override - void initState() { - _model = widget.model; - super.initState(); - } - - @override - void dispose() { - print("disposeddddddd"); - super.dispose(); - } - @override Widget build(BuildContext context) { - _model?.files ??= []; - _model?.files = (_model.files ?? []).where((element) => element.attachmentName != null && element.attachmentName.isNotEmpty).toList(); + widget.model?.files ??= []; + widget.model?.files = (widget.model.files ?? []).where((element) => element.attachmentName != null && element.attachmentName.isNotEmpty).toList(); return SingleChildScrollView( child: Column( @@ -54,7 +40,7 @@ class _PentryTBSFormState extends State { 8.height, SingleItemDropDownMenu( context: context, - initialValue: _model.visitStatusId == null ? null : Lookup(name: _model.visitStatusName ?? "", id: _model.visitStatusId), + initialValue: widget.model.visitStatusId == null ? null : Lookup(name: widget.model.visitStatusName ?? "", id: widget.model.visitStatusId), title: context.translation.ppmVisit, onSelect: (value) { if (value?.value == 4) { @@ -64,93 +50,96 @@ class _PentryTBSFormState extends State { } if (value != null) { - _model.visitStatusName = value.name; - _model.visitStatusId = value.id; + widget.model.visitStatusName = value.name; + widget.model.visitStatusId = value.id; } }, ), 8.height, AppTimer( label: context.translation.timer, - timer: _model.tbsTimer, - enabled: _model.tbsTimer.endAt == null, + timer: widget.model.tbsTimer, + enabled: widget.model.tbsTimer.endAt == null, + timerProgress: (isRunning) { + print("timerProgress:$isRunning"); + }, onChange: (timer) async { - _model.tbsTimer = timer; + widget.model.tbsTimer = timer; return true; }, ), 8.height, SingleItemDropDownMenu( context: context, - initialValue: _model.deviceStatusId == null ? null : Lookup(name: _model.deviceStatusName ?? "", id: _model.deviceStatusId), + initialValue: widget.model.deviceStatusId == null ? null : Lookup(name: widget.model.deviceStatusName ?? "", id: widget.model.deviceStatusId), title: context.translation.deviceStatus, onSelect: (value) { if (value != null) { - _model.deviceStatusId = value.id; - _model.deviceStatusName = value.name; + widget.model.deviceStatusId = value.id; + widget.model.deviceStatusName = value.name; } }, ), 8.height, ADatePicker( label: context.translation.actualVisitDate, - date: DateTime.tryParse(_model.actualDate ?? ""), + date: DateTime.tryParse(widget.model.actualDate ?? ""), from: DateTime.now().subtract(const Duration(days: 30)), onDatePicker: (date) { if (date == null) return; - _model.actualDate = date?.toIso8601String(); + widget.model.actualDate = date?.toIso8601String(); setState(() {}); }, ), 8.height, ADatePicker( label: context.translation.expectedVisitDate, - date: DateTime.tryParse(_model.expectedDate ?? ""), + date: DateTime.tryParse(widget.model.expectedDate ?? ""), from: DateTime.now().subtract(const Duration(days: 30)), enable: false, onDatePicker: (date) { if (date == null) return; - _model.expectedDate = date?.toIso8601String(); + widget.model.expectedDate = date?.toIso8601String(); setState(() {}); }, ), 8.height, AppTextFormField( labelText: context.translation.travelingHours, - initialValue: (_model.travelingHours ?? "").toString(), + initialValue: (widget.model.travelingHours ?? "").toString(), textAlign: TextAlign.center, style: Theme.of(context).textTheme.titleMedium, textInputType: TextInputType.number, onChange: (value) { - _model.travelingHours = value; + widget.model.travelingHours = value; }, ), 8.height, MultiFilesPicker( label: context.translation.attachImage, - files: _model.files.map((e) => File(e.attachmentName)).toList(), + files: widget.model.files.map((e) => File(e.attachmentName)).toList(), onChange: (files) { - _model.files = files.map((e) => PpmAttachments(attachmentName: e.path)).toList(); + widget.model.files = files.map((e) => PpmAttachments(attachmentName: e.path)).toList(); }, ), 8.height, ESignature( title: context.translation.nurseSignature, - oldSignature: _model.nurseSignature, - newSignature: _model.localNurseSignature, + oldSignature: widget.model.nurseSignature, + newSignature: widget.model.localNurseSignature, onChange: (signature) { - _model.localNurseSignature = signature; - _model.nurseSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + widget.model.localNurseSignature = signature; + widget.model.nurseSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; }, ), 8.height, ESignature( title: context.translation.engSign, - oldSignature: _model.engSignature, - newSignature: _model.localEngineerSignature, + oldSignature: widget.model.engSignature, + newSignature: widget.model.localEngineerSignature, onChange: (signature) { - _model.localEngineerSignature = signature; - _model.engSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + widget.model.localEngineerSignature = signature; + widget.model.engSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; }, ), 8.height,