diff --git a/lib/models/device/device_transfer_search.dart b/lib/models/device/device_transfer_search.dart index 14cf6956..8a7a24f4 100644 --- a/lib/models/device/device_transfer_search.dart +++ b/lib/models/device/device_transfer_search.dart @@ -1,49 +1,64 @@ -import '../lookup.dart'; +import 'package:test_sa/models/device/device.dart'; + +import '../hospital.dart'; class DeviceTransferSearch { - String assetName, assetNumber, site; + Device device; + String title, room; bool mostRecent; - Lookup dateOperator; - String from, to; + Hospital hospital; + Buildings building; + List buildingsList; + Floors floor; + List floorsList; + Departments department; + List departmentsList; DeviceTransferSearch({ - this.assetName, - this.assetNumber, - this.site, + this.device, + this.hospital, + this.building, + this.floor, + this.department, + this.room, + this.title, this.mostRecent, - this.dateOperator, - this.from, - this.to, }); Map toMap() { Map search = {}; - if (assetName != null && assetName.isNotEmpty) { - search["assetName"] = assetName; + if (title != null && title.isNotEmpty) { + search["transferCode"] = title; + } + if (device != null) { + search["assetId"] = device.id; + } + if (hospital?.id != null) { + search["destSiteId"] = hospital.id; } - if (assetNumber != null && assetNumber.isNotEmpty) { - search["assetNumber"] = assetNumber; + if (building?.id != null) { + search["destBuildingId"] = building.id; } - if (site != null && site.isNotEmpty) { - search["site"] = site; + if (floor?.id != null) { + search["destFloorId"] = floor.id; } - if (dateOperator != null && from != null) { - search["requestedDateSymbol"] = dateOperator.toMap(); - search["requestedDateFrom"] = from; + if (department?.id != null) { + search["destDepartmentId"] = department.id; } - if (dateOperator != null && to != null) { - search["requestedDateTo"] = to; + if (room != null && room.isNotEmpty) { + search["destRoom"] = department.id; } return search; } void fromSearch(DeviceTransferSearch newSearch) { - assetName = newSearch.assetName; - assetNumber = newSearch.assetNumber; - site = newSearch.site; + title = newSearch.title; + room = newSearch.room; mostRecent = newSearch.mostRecent; - from = newSearch.from; - to = newSearch.to; - dateOperator = newSearch.dateOperator; + device = newSearch.device; + hospital = newSearch.hospital; + building = newSearch.building; + floor = newSearch.floor; + department = newSearch.department; } } diff --git a/lib/views/pages/device_transfer/track_device_transfer.dart b/lib/views/pages/device_transfer/track_device_transfer.dart index 1610640c..34e81688 100644 --- a/lib/views/pages/device_transfer/track_device_transfer.dart +++ b/lib/views/pages/device_transfer/track_device_transfer.dart @@ -72,11 +72,12 @@ class _TrackDeviceTransferPageState extends State with backgroundColor: AColors.white, onPressed: () async { DeviceTransferSearch temp = await showModalBottomSheet( - context: context, - isScrollControlled: true, - builder: (context) { - return AssetTransferSearchDialog(initialSearchValue: _deviceTransferProvider.deviceTransferSearch); - }); + context: context, + isScrollControlled: true, + builder: (context) { + return AssetTransferSearchDialog(initialSearchValue: _deviceTransferProvider.deviceTransferSearch); + }, + ); if (temp != null) { _deviceTransferProvider.deviceTransferSearch = temp; _deviceTransferProvider.reset(); diff --git a/lib/views/widgets/gas_refill/department_type_menu.dart b/lib/views/widgets/gas_refill/department_type_menu.dart index bd887c74..3ea429b8 100644 --- a/lib/views/widgets/gas_refill/department_type_menu.dart +++ b/lib/views/widgets/gas_refill/department_type_menu.dart @@ -90,7 +90,7 @@ class _DepartmentTypeMenuState extends State { return DropdownMenuItem( value: value, child: Text( - value.name, + value?.name ?? "", style: Theme.of(context).textTheme.subtitle1.copyWith( color: Theme.of(context).primaryColor, fontSize: 11, diff --git a/lib/views/widgets/search/asset_transfer_search_dialog.dart b/lib/views/widgets/search/asset_transfer_search_dialog.dart index 59539238..20a88ece 100644 --- a/lib/views/widgets/search/asset_transfer_search_dialog.dart +++ b/lib/views/widgets/search/asset_transfer_search_dialog.dart @@ -5,12 +5,15 @@ import 'package:test_sa/models/subtitle.dart'; import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/widgets/buttons/app_button.dart'; import 'package:test_sa/views/widgets/buttons/app_small_button.dart'; +import 'package:test_sa/views/widgets/equipment/device_button.dart'; +import '../../../controllers/providers/api/hospitals_provider.dart'; import '../app_text_form_field.dart'; -import '../date_and_time/date_picker.dart'; -import '../status/report/service_report_visit_date_operator.dart'; +import '../gas_refill/building_type_menu.dart'; +import '../gas_refill/department_type_menu.dart'; +import '../gas_refill/floor_type_menu.dart'; +import '../hospitals/hospital_auto_complete_field.dart'; import '../switch_button.dart'; -import '../titles/app_sub_title.dart'; class AssetTransferSearchDialog extends StatefulWidget { final DeviceTransferSearch initialSearchValue; @@ -25,6 +28,7 @@ class AssetTransferSearchDialog extends StatefulWidget { class AssetTransferSearchDialogState extends State with TickerProviderStateMixin { DeviceTransferSearch _search; final GlobalKey _formKey = GlobalKey(); + bool _isLoading = false; @override void initState() { @@ -36,165 +40,161 @@ class AssetTransferSearchDialogState extends State wi @override Widget build(BuildContext context) { Subtitle subtitle = AppLocalization.of(context).subtitle; - return SizedBox( - height: MediaQuery.of(context).size.height / 1.3, - child: Form( - key: _formKey, - child: ListView( - padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16), - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + return Padding( + padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), + child: ClipRRect( + borderRadius: const BorderRadius.only(topLeft: Radius.circular(15), topRight: Radius.circular(15)), + clipBehavior: Clip.antiAliasWithSaveLayer, + child: Container( + color: Colors.white, + height: MediaQuery.of(context).size.height / 1.3, + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 20), + child: Form( + key: _formKey, + child: ListView( + padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16), children: [ - ASmallButton( - text: subtitle.cancel, - onPressed: () { - Navigator.of(context).pop(); + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + ASmallButton( + text: subtitle.cancel, + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ASmallButton( + text: subtitle.search, + onPressed: () { + if (!_formKey.currentState.validate()) { + return; + } + _formKey.currentState.save(); + Navigator.of(context).pop(_search); + }, + ) + ], + ), + ASwitchButton( + title: "Most Recent", + value: _search.mostRecent ?? false, + onChange: (value) { + _search.mostRecent = value; + setState(() {}); }, ), - ASmallButton( - text: subtitle.search, - onPressed: () { + SizedBox(height: 8.0 * AppStyle.getScaleFactor(context)), + DeviceButton( + device: _search.device, + onDevicePick: (device) { + _search.device = device; + setState(() {}); + }, + ), + SizedBox(height: 8.0 * AppStyle.getScaleFactor(context)), + ATextFormField( + initialValue: _search.title, + hintText: subtitle.title, + style: Theme.of(context).textTheme.titleLarge, + textInputAction: TextInputAction.search, + onAction: () { if (!_formKey.currentState.validate()) { return; } _formKey.currentState.save(); Navigator.of(context).pop(_search); }, - ) - ], - ), - ASwitchButton( - title: "Most Recent", - value: _search.mostRecent ?? false, - onChange: (value) { - _search.mostRecent = value; - setState(() {}); - }, - ), - SizedBox( - height: 8.0 * AppStyle.getScaleFactor(context), - ), - ATextFormField( - initialValue: _search.assetNumber, - hintText: subtitle.assetNumber, - style: Theme.of(context).textTheme.headline6, - textInputAction: TextInputAction.search, - onAction: () { - if (!_formKey.currentState.validate()) { - return; - } - _formKey.currentState.save(); - Navigator.of(context).pop(_search); - }, - onSaved: (value) { - _search.assetNumber = value; - }, - ), - SizedBox( - height: 8.0 * AppStyle.getScaleFactor(context), - ), - ATextFormField( - initialValue: _search.assetName, - hintText: subtitle.assetName, - style: Theme.of(context).textTheme.headline6, - textInputAction: TextInputAction.search, - onAction: () { - if (!_formKey.currentState.validate()) { - return; - } - _formKey.currentState.save(); - Navigator.of(context).pop(_search); - }, - onSaved: (value) { - _search.site = value; - }, - ), - SizedBox( - height: 8.0 * AppStyle.getScaleFactor(context), - ), - ATextFormField( - initialValue: _search.site, - hintText: subtitle.site, - style: Theme.of(context).textTheme.headline6, - textInputAction: TextInputAction.search, - onAction: () { - if (!_formKey.currentState.validate()) { - return; - } - _formKey.currentState.save(); - Navigator.of(context).pop(_search); - }, - onSaved: (value) { - _search.assetName = value; - }, - ), - SizedBox( - height: 8.0 * AppStyle.getScaleFactor(context), - ), - const ASubTitle("Request Date"), - const SizedBox(height: 4), - ServiceReportVisitDateOperator( - initialValue: _search.dateOperator, - onSelect: (status) { - _search.dateOperator = status; - setState(() {}); - }, - ), - Row( - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - if (_search?.dateOperator?.name?.toLowerCase()?.contains("between") ?? false) const ASubTitle("From"), - ADatePicker( - date: DateTime.tryParse(_search.from ?? ""), - from: DateTime(1950), - onDatePicker: (date) { - _search.from = date?.toIso8601String(); - setState(() {}); - }, - ), - ], - ), + onSaved: (value) { + _search.title = value; + }, ), - if (_search?.dateOperator?.name?.toLowerCase()?.contains("between") ?? false) const SizedBox(width: 16), - if (_search?.dateOperator?.name?.toLowerCase()?.contains("between") ?? false) - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - const ASubTitle("To"), - ADatePicker( - date: DateTime.tryParse(_search.to ?? ""), - from: DateTime(1950), - onDatePicker: (date) { - _search.to = date?.toIso8601String(); - setState(() {}); - }, - ), - ], - ), - ), - ], - ), - const SizedBox(width: 16), - Visibility( - visible: _search.toMap().isNotEmpty, - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16), - child: AButton( - padding: EdgeInsets.zero, - text: subtitle.clearSearch, - onPressed: () { - _search = DeviceTransferSearch(); + SizedBox(height: 8.0 * AppStyle.getScaleFactor(context)), + HospitalAutoCompleteField( + initialValue: _search?.hospital?.name, + onSearch: (selected) async { + _search.building = null; + _search.floor = null; + _search.department = null; + _search.buildingsList = null; + _search.floorsList = null; + _search.departmentsList = null; + _isLoading = true; + setState(() {}); + await HospitalsProvider().getHospitalsListByVal(searchVal: selected?.name ?? "").then((value) { + _search.hospital = value?.firstWhere((element) => element.name == selected.name, orElse: () => null); + _search.buildingsList = _search.hospital?.buildings; + }); + _isLoading = false; + setState(() {}); + }, + ), + const SizedBox(height: 8), + BuildingTypeMenu( + initialValue: _search?.building, + building: _search.buildingsList, + enabled: !_isLoading, + onSelect: (status) { + _search.building = status; + _search.floorsList = status?.floors; + setState(() {}); + }, + ), + const SizedBox(height: 8), + FloorTypeMenu( + initialValue: _search?.floor, + floors: _search.floorsList, + enabled: !_isLoading, + onSelect: (status) { + _search.floor = status; + _search.departmentsList = _search.floor?.departments; + setState(() {}); + }, + ), + const SizedBox(height: 8), + DepartmentTypeMenu( + initialValue: _search?.department, + departments: _search.departmentsList, + enabled: !_isLoading, + onSelect: (status) { + _search.department = status; + setState(() {}); + }, + ), + SizedBox(height: 8.0 * AppStyle.getScaleFactor(context)), + ATextFormField( + initialValue: _search.room, + hintText: subtitle.room, + style: Theme.of(context).textTheme.titleLarge, + textInputAction: TextInputAction.search, + onAction: () { + if (!_formKey.currentState.validate()) { + return; + } + _formKey.currentState.save(); Navigator.of(context).pop(_search); }, + onSaved: (value) { + _search.room = value; + }, ), - ), + SizedBox(height: 16.0 * AppStyle.getScaleFactor(context)), + Visibility( + visible: _search.toMap().isNotEmpty, + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16), + child: AButton( + padding: EdgeInsets.zero, + text: subtitle.clearSearch, + onPressed: () { + _search = DeviceTransferSearch(); + Navigator.of(context).pop(_search); + }, + ), + ), + ), + ], ), - ], + ), ), ), );