diff --git a/lib/common/custom_expansion_tile.dart b/lib/common/widgets/custom_expansion_tile.dart similarity index 95% rename from lib/common/custom_expansion_tile.dart rename to lib/common/widgets/custom_expansion_tile.dart index 8df9b663..b6b33479 100644 --- a/lib/common/custom_expansion_tile.dart +++ b/lib/common/widgets/custom_expansion_tile.dart @@ -58,16 +58,18 @@ class CustomExpansionTileState extends State { children: [ // Checkbox with independent state management Checkbox( - value: false, + value: widget.isSelected, onChanged: (bool? value) { - setState(() {}); + if (widget.onItemSelected != null) { + widget.onItemSelected!(); + } }, side: WidgetStateBorderSide.resolveWith((states) { return const BorderSide(color: ColorsManager.grayBorder); }), fillColor: WidgetStateProperty.resolveWith((states) { if (states.contains(WidgetState.selected)) { - return ColorsManager.grayBorder; + return ColorsManager.blue1; } else { return ColorsManager.checkBoxFillColor; } diff --git a/lib/common/search_bar.dart b/lib/common/widgets/search_bar.dart similarity index 100% rename from lib/common/search_bar.dart rename to lib/common/widgets/search_bar.dart diff --git a/lib/common/widgets/spaces_side_tree.dart b/lib/common/widgets/spaces_side_tree.dart new file mode 100644 index 00000000..b77b0dc5 --- /dev/null +++ b/lib/common/widgets/spaces_side_tree.dart @@ -0,0 +1,25 @@ +import 'package:flutter/material.dart'; +import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart'; + +class SpacesSideTree extends StatefulWidget { + final List communities; + final String? selectedSpaceUuid; + const SpacesSideTree({ + super.key, + required this.communities, + this.selectedSpaceUuid, + }); + + @override + State createState() => _SpacesSideTreeState(); +} + +class _SpacesSideTreeState extends State { + String _searchQuery = ''; + String? _selectedSpaceUuid; + String? _selectedId; + @override + Widget build(BuildContext context) { + return const Placeholder(); + } +} diff --git a/lib/main.dart b/lib/main.dart index 2040d175..0bf0b9d3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,7 +6,9 @@ import 'package:go_router/go_router.dart'; import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart'; import 'package:syncrow_web/pages/home/bloc/home_bloc.dart'; import 'package:syncrow_web/pages/home/bloc/home_event.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart'; +import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart'; import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart'; import 'package:syncrow_web/services/locator.dart'; import 'package:syncrow_web/utils/app_routes.dart'; @@ -15,8 +17,7 @@ import 'package:syncrow_web/utils/theme/theme.dart'; Future main() async { try { - const environment = - String.fromEnvironment('FLAVOR', defaultValue: 'development'); + const environment = String.fromEnvironment('FLAVOR', defaultValue: 'development'); await dotenv.load(fileName: '.env.$environment'); WidgetsFlutterBinding.ensureInitialized(); initialSetup(); @@ -48,14 +49,16 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MultiBlocProvider( providers: [ - BlocProvider( - create: (context) => HomeBloc()..add(const FetchUserInfo())), + BlocProvider(create: (context) => HomeBloc()..add(const FetchUserInfo())), BlocProvider( create: (context) => VisitorPasswordBloc(), ), BlocProvider( create: (context) => RoutineBloc(), ), + BlocProvider( + create: (context) => SpaceTreeBloc()..add(InitialEvent()), + ), ], child: MaterialApp.router( debugShowCheckedModeBanner: false, diff --git a/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart b/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart index 8f6d085d..1fa61fc2 100644 --- a/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart +++ b/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart @@ -6,8 +6,7 @@ import 'package:syncrow_web/services/devices_mang_api.dart'; part 'device_managment_event.dart'; part 'device_managment_state.dart'; -class DeviceManagementBloc - extends Bloc { +class DeviceManagementBloc extends Bloc { int _selectedIndex = 0; List _devices = []; int _onlineCount = 0; @@ -18,6 +17,8 @@ class DeviceManagementBloc String currentProductName = ''; String? currentCommunity; String? currentUnitName; + String? communityId; + String? spaceId; DeviceManagementBloc() : super(DeviceManagementInitial()) { on(_onFetchDevices); @@ -30,11 +31,16 @@ class DeviceManagementBloc on(_onUpdateSelection); } - Future _onFetchDevices( - FetchDevices event, Emitter emit) async { + Future _onFetchDevices(FetchDevices event, Emitter emit) async { emit(DeviceManagementLoading()); try { - final devices = await DevicesManagementApi().fetchDevices(); + if (event.communityId.isNotEmpty) { + communityId = event.communityId; + } + if (event.spaceId.isNotEmpty) { + spaceId = event.spaceId; + } + final devices = await DevicesManagementApi().fetchDevices(communityId ?? '', spaceId ?? ''); _selectedDevices.clear(); _devices = devices; _filteredDevices = devices; @@ -53,8 +59,7 @@ class DeviceManagementBloc } } - void _onFilterDevices( - FilterDevices event, Emitter emit) async { + void _onFilterDevices(FilterDevices event, Emitter emit) async { if (_devices.isNotEmpty) { _filteredDevices = List.from(_devices.where((device) { switch (event.filter) { @@ -85,8 +90,7 @@ class DeviceManagementBloc } } - Future _onResetFilters( - ResetFilters event, Emitter emit) async { + Future _onResetFilters(ResetFilters event, Emitter emit) async { currentProductName = ''; _selectedDevices.clear(); _filteredDevices = List.from(_devices); @@ -102,8 +106,7 @@ class DeviceManagementBloc )); } - void _onResetSelectedDevices( - ResetSelectedDevices event, Emitter emit) { + void _onResetSelectedDevices(ResetSelectedDevices event, Emitter emit) { _selectedDevices.clear(); if (state is DeviceManagementLoaded) { @@ -129,14 +132,12 @@ class DeviceManagementBloc } } - void _onSelectedFilterChanged( - SelectedFilterChanged event, Emitter emit) { + void _onSelectedFilterChanged(SelectedFilterChanged event, Emitter emit) { _selectedIndex = event.selectedIndex; add(FilterDevices(_getFilterFromIndex(_selectedIndex))); } - void _onSelectDevice( - SelectDevice event, Emitter emit) { + void _onSelectDevice(SelectDevice event, Emitter emit) { final selectedUuid = event.selectedDevice.uuid; if (_selectedDevices.any((device) => device.uuid == selectedUuid)) { @@ -147,8 +148,7 @@ class DeviceManagementBloc List clonedSelectedDevices = List.from(_selectedDevices); - bool isControlButtonEnabled = - _checkIfControlButtonEnabled(clonedSelectedDevices); + bool isControlButtonEnabled = _checkIfControlButtonEnabled(clonedSelectedDevices); if (state is DeviceManagementLoaded) { emit(DeviceManagementLoaded( @@ -157,8 +157,7 @@ class DeviceManagementBloc onlineCount: _onlineCount, offlineCount: _offlineCount, lowBatteryCount: _lowBatteryCount, - selectedDevice: - clonedSelectedDevices.isNotEmpty ? clonedSelectedDevices : null, + selectedDevice: clonedSelectedDevices.isNotEmpty ? clonedSelectedDevices : null, isControlButtonEnabled: isControlButtonEnabled, )); } else if (state is DeviceManagementFiltered) { @@ -168,15 +167,13 @@ class DeviceManagementBloc onlineCount: _onlineCount, offlineCount: _offlineCount, lowBatteryCount: _lowBatteryCount, - selectedDevice: - clonedSelectedDevices.isNotEmpty ? clonedSelectedDevices : null, + selectedDevice: clonedSelectedDevices.isNotEmpty ? clonedSelectedDevices : null, isControlButtonEnabled: isControlButtonEnabled, )); } } - void _onUpdateSelection( - UpdateSelection event, Emitter emit) { + void _onUpdateSelection(UpdateSelection event, Emitter emit) { List selectedDevices = []; List devicesToSelectFrom = []; @@ -219,8 +216,7 @@ class DeviceManagementBloc bool _checkIfControlButtonEnabled(List selectedDevices) { if (selectedDevices.length > 1) { - final productTypes = - selectedDevices.map((device) => device.productType).toSet(); + final productTypes = selectedDevices.map((device) => device.productType).toSet(); return productTypes.length == 1; } else if (selectedDevices.length == 1) { return true; @@ -231,10 +227,8 @@ class DeviceManagementBloc void _calculateDeviceCounts() { _onlineCount = _devices.where((device) => device.online == true).length; _offlineCount = _devices.where((device) => device.online == false).length; - _lowBatteryCount = _devices - .where((device) => - device.batteryLevel != null && device.batteryLevel! < 20) - .length; + _lowBatteryCount = + _devices.where((device) => device.batteryLevel != null && device.batteryLevel! < 20).length; } String _getFilterFromIndex(int index) { @@ -250,8 +244,7 @@ class DeviceManagementBloc } } - void _onSearchDevices( - SearchDevices event, Emitter emit) { + void _onSearchDevices(SearchDevices event, Emitter emit) { if ((event.community == null || event.community!.isEmpty) && (event.unitName == null || event.unitName!.isEmpty) && (event.productName == null || event.productName!.isEmpty)) { @@ -280,33 +273,22 @@ class DeviceManagementBloc final filteredDevices = devicesToSearch.where((device) { final matchesCommunity = event.community == null || event.community!.isEmpty || - (device.community?.name - ?.toLowerCase() - .contains(event.community!.toLowerCase()) ?? + (device.community?.name?.toLowerCase().contains(event.community!.toLowerCase()) ?? false); final matchesUnit = event.unitName == null || event.unitName!.isEmpty || (device.spaces != null && device.spaces!.isNotEmpty && - device.spaces![0].spaceName - !.toLowerCase() - .contains(event.unitName!.toLowerCase())); + device.spaces![0].spaceName!.toLowerCase().contains(event.unitName!.toLowerCase())); final matchesProductName = event.productName == null || event.productName!.isEmpty || - (device.name - ?.toLowerCase() - .contains(event.productName!.toLowerCase()) ?? - false); + (device.name?.toLowerCase().contains(event.productName!.toLowerCase()) ?? false); final matchesDeviceName = event.productName == null || event.productName!.isEmpty || - (device.categoryName - ?.toLowerCase() - .contains(event.productName!.toLowerCase()) ?? + (device.categoryName?.toLowerCase().contains(event.productName!.toLowerCase()) ?? false); - return matchesCommunity && - matchesUnit && - (matchesProductName || matchesDeviceName); + return matchesCommunity && matchesUnit && (matchesProductName || matchesDeviceName); }).toList(); emit(DeviceManagementFiltered( diff --git a/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_event.dart b/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_event.dart index c7509080..da52249c 100644 --- a/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_event.dart +++ b/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_event.dart @@ -7,7 +7,14 @@ abstract class DeviceManagementEvent extends Equatable { List get props => []; } -class FetchDevices extends DeviceManagementEvent {} +class FetchDevices extends DeviceManagementEvent { + final String communityId; + final String spaceId; + + const FetchDevices(this.communityId, this.spaceId); + @override + List get props => [communityId, spaceId]; +} class FilterDevices extends DeviceManagementEvent { final String filter; diff --git a/lib/pages/device_managment/all_devices/models/devices_model.dart b/lib/pages/device_managment/all_devices/models/devices_model.dart index b7e4f010..d30afc03 100644 --- a/lib/pages/device_managment/all_devices/models/devices_model.dart +++ b/lib/pages/device_managment/all_devices/models/devices_model.dart @@ -2,11 +2,11 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/device_com import 'package:syncrow_web/pages/device_managment/all_devices/models/device_space_model.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/room.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/unit.dart'; -import 'package:syncrow_web/pages/routiens/models/ac/ac_function.dart'; -import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; -import 'package:syncrow_web/pages/routiens/models/gang_switches/one_gang_switch/one_gang_switch.dart'; -import 'package:syncrow_web/pages/routiens/models/gang_switches/three_gang_switch/three_gang_switch.dart'; -import 'package:syncrow_web/pages/routiens/models/gang_switches/two_gang_switch/two_gang_switch.dart'; +import 'package:syncrow_web/pages/routines/models/ac/ac_function.dart'; +import 'package:syncrow_web/pages/routines/models/device_functions.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/one_gang_switch/one_gang_switch.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/three_gang_switch/three_gang_switch.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/two_gang_switch/two_gang_switch.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; import 'package:syncrow_web/utils/enum/device_types.dart'; @@ -142,9 +142,7 @@ class AllDevicesModel { productName = json['productName']?.toString(); if (json['spaces'] != null && json['spaces'] is List) { - spaces = (json['spaces'] as List) - .map((space) => DeviceSpaceModel.fromJson(space)) - .toList(); + spaces = (json['spaces'] as List).map((space) => DeviceSpaceModel.fromJson(space)).toList(); } } @@ -192,8 +190,7 @@ SOS String tempIcon = ''; if (type == DeviceType.LightBulb) { tempIcon = Assets.lightBulb; - } else if (type == DeviceType.CeilingSensor || - type == DeviceType.WallSensor) { + } else if (type == DeviceType.CeilingSensor || type == DeviceType.WallSensor) { tempIcon = Assets.sensors; } else if (type == DeviceType.AC) { tempIcon = Assets.ac; @@ -248,34 +245,25 @@ SOS case '1G': return [ OneGangSwitchFunction(deviceId: uuid ?? '', deviceName: name ?? ''), - OneGangCountdownFunction( - deviceId: uuid ?? '', deviceName: name ?? ''), + OneGangCountdownFunction(deviceId: uuid ?? '', deviceName: name ?? ''), ]; case '2G': return [ TwoGangSwitch1Function(deviceId: uuid ?? '', deviceName: name ?? ''), TwoGangSwitch2Function(deviceId: uuid ?? '', deviceName: name ?? ''), - TwoGangCountdown1Function( - deviceId: uuid ?? '', deviceName: name ?? ''), - TwoGangCountdown2Function( - deviceId: uuid ?? '', deviceName: name ?? ''), + TwoGangCountdown1Function(deviceId: uuid ?? '', deviceName: name ?? ''), + TwoGangCountdown2Function(deviceId: uuid ?? '', deviceName: name ?? ''), ]; case '3G': return [ - ThreeGangSwitch1Function( - deviceId: uuid ?? '', deviceName: name ?? ''), - ThreeGangSwitch2Function( - deviceId: uuid ?? '', deviceName: name ?? ''), - ThreeGangSwitch3Function( - deviceId: uuid ?? '', deviceName: name ?? ''), - ThreeGangCountdown1Function( - deviceId: uuid ?? '', deviceName: name ?? ''), - ThreeGangCountdown2Function( - deviceId: uuid ?? '', deviceName: name ?? ''), - ThreeGangCountdown3Function( - deviceId: uuid ?? '', deviceName: name ?? ''), + ThreeGangSwitch1Function(deviceId: uuid ?? '', deviceName: name ?? ''), + ThreeGangSwitch2Function(deviceId: uuid ?? '', deviceName: name ?? ''), + ThreeGangSwitch3Function(deviceId: uuid ?? '', deviceName: name ?? ''), + ThreeGangCountdown1Function(deviceId: uuid ?? '', deviceName: name ?? ''), + ThreeGangCountdown2Function(deviceId: uuid ?? '', deviceName: name ?? ''), + ThreeGangCountdown3Function(deviceId: uuid ?? '', deviceName: name ?? ''), ]; default: diff --git a/lib/pages/device_managment/all_devices/view/device_managment_page.dart b/lib/pages/device_managment/all_devices/view/device_managment_page.dart index e8cbd4ca..f64ef734 100644 --- a/lib/pages/device_managment/all_devices/view/device_managment_page.dart +++ b/lib/pages/device_managment/all_devices/view/device_managment_page.dart @@ -3,9 +3,9 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/widgets/device_managment_body.dart'; import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/view/create_new_routine_view.dart'; -import 'package:syncrow_web/pages/routiens/view/routines_view.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/view/create_new_routine_view.dart'; +import 'package:syncrow_web/pages/routines/view/routines_view.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; @@ -19,7 +19,7 @@ class DeviceManagementPage extends StatelessWidget with HelperResponsiveLayout { return MultiBlocProvider( providers: [ BlocProvider( - create: (context) => DeviceManagementBloc()..add(FetchDevices()), + create: (context) => DeviceManagementBloc()..add(const FetchDevices('', '')), ), ], child: WebScaffold( diff --git a/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart b/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart index 0788e08d..9ae3b89f 100644 --- a/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart +++ b/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart @@ -8,6 +8,7 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_mo import 'package:syncrow_web/pages/device_managment/all_devices/widgets/device_search_filters.dart'; import 'package:syncrow_web/pages/device_managment/shared/device_batch_control_dialog.dart'; import 'package:syncrow_web/pages/device_managment/shared/device_control_dialog.dart'; +import 'package:syncrow_web/pages/space_tree/view/side_spaces_view.dart'; import 'package:syncrow_web/utils/format_date_time.dart'; import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; import 'package:syncrow_web/utils/style.dart'; @@ -59,118 +60,143 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout { final buttonLabel = (selectedDevices.length > 1) ? 'Batch Control' : 'Control'; - return Column( + return Row( children: [ - Container( - padding: isLargeScreenSize(context) ? const EdgeInsets.all(30) : const EdgeInsets.all(15), + Flexible(child: SideSpacesView( + onSelectAction: (String communityId, String spaceId) { + context.read().add(FetchDevices(communityId, spaceId)); + }, + )), + Flexible( + flex: 3, child: Column( - crossAxisAlignment: CrossAxisAlignment.start, children: [ - FilterWidget( - size: MediaQuery.of(context).size, - tabs: tabs, - selectedIndex: selectedIndex, - onTabChanged: (index) { - context.read().add(SelectedFilterChanged(index)); - }, - ), - const SizedBox(height: 20), - const DeviceSearchFilters(), - const SizedBox(height: 12), Container( - height: 45, - width: 125, - decoration: containerDecoration, - child: Center( - child: DefaultButton( - onPressed: isControlButtonEnabled - ? () { - if (selectedDevices.length == 1) { - showDialog( - context: context, - builder: (context) => DeviceControlDialog( - device: selectedDevices.first, - ), - ); - } else if (selectedDevices.length > 1) { - final productTypes = selectedDevices.map((device) => device.productType).toSet(); - if (productTypes.length == 1) { - showDialog( - context: context, - builder: (context) => DeviceBatchControlDialog( - devices: selectedDevices, - ), - ); - } - } - } - : null, - borderRadius: 9, - child: Text( - buttonLabel, - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 12, - color: isControlButtonEnabled ? Colors.white : Colors.grey, + padding: isLargeScreenSize(context) + ? const EdgeInsets.all(30) + : const EdgeInsets.all(15), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + FilterWidget( + size: MediaQuery.of(context).size, + tabs: tabs, + selectedIndex: selectedIndex, + onTabChanged: (index) { + context.read().add(SelectedFilterChanged(index)); + }, + ), + const SizedBox(height: 20), + const DeviceSearchFilters(), + const SizedBox(height: 12), + Container( + height: 45, + width: 125, + decoration: containerDecoration, + child: Center( + child: DefaultButton( + onPressed: isControlButtonEnabled + ? () { + if (selectedDevices.length == 1) { + showDialog( + context: context, + builder: (context) => DeviceControlDialog( + device: selectedDevices.first, + ), + ); + } else if (selectedDevices.length > 1) { + final productTypes = selectedDevices + .map((device) => device.productType) + .toSet(); + if (productTypes.length == 1) { + showDialog( + context: context, + builder: (context) => DeviceBatchControlDialog( + devices: selectedDevices, + ), + ); + } + } + } + : null, + borderRadius: 9, + child: Text( + buttonLabel, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 12, + color: isControlButtonEnabled ? Colors.white : Colors.grey, + ), + ), + ), ), ), - ), + ], ), ), + Expanded( + child: Padding( + padding: isLargeScreenSize(context) + ? const EdgeInsets.all(30) + : const EdgeInsets.all(15), + child: DynamicTable( + withSelectAll: true, + cellDecoration: containerDecoration, + onRowSelected: (index, isSelected, row) { + final selectedDevice = devicesToShow[index]; + context.read().add(SelectDevice(selectedDevice)); + }, + withCheckBox: true, + size: MediaQuery.of(context).size, + uuidIndex: 2, + headers: const [ + 'Device Name', + 'Product Name', + 'Device ID', + 'Space Name', + 'location', + 'Battery Level', + 'Installation Date and Time', + 'Status', + 'Last Offline Date and Time', + ], + data: devicesToShow.map((device) { + final combinedSpaceNames = device.spaces != null + ? device.spaces!.map((space) => space.spaceName).join(' > ') + + (device.community != null ? ' > ${device.community!.name}' : '') + : (device.community != null ? device.community!.name : ''); + + return [ + device.name ?? '', + device.productName ?? '', + device.uuid ?? '', + (device.spaces != null && device.spaces!.isNotEmpty) + ? device.spaces![0].spaceName + : '', + combinedSpaceNames, + device.batteryLevel != null ? '${device.batteryLevel}%' : '-', + formatDateTime(DateTime.fromMillisecondsSinceEpoch( + (device.createTime ?? 0) * 1000)), + device.online == true ? 'Online' : 'Offline', + formatDateTime(DateTime.fromMillisecondsSinceEpoch( + (device.updateTime ?? 0) * 1000)), + ]; + }).toList(), + onSelectionChanged: (selectedRows) { + context.read().add(UpdateSelection(selectedRows)); + }, + initialSelectedIds: context + .read() + .selectedDevices + .map((device) => device.uuid!) + .toList(), + isEmpty: devicesToShow.isEmpty, + ), + ), + ) ], ), ), - Expanded( - child: Padding( - padding: isLargeScreenSize(context) ? const EdgeInsets.all(30) : const EdgeInsets.all(15), - child: DynamicTable( - withSelectAll: true, - cellDecoration: containerDecoration, - onRowSelected: (index, isSelected, row) { - final selectedDevice = devicesToShow[index]; - context.read().add(SelectDevice(selectedDevice)); - }, - withCheckBox: true, - size: MediaQuery.of(context).size, - uuidIndex: 2, - headers: const [ - 'Device Name', - 'Product Name', - 'Device ID', - 'Space Name', - 'location', - 'Battery Level', - 'Installation Date and Time', - 'Status', - 'Last Offline Date and Time', - ], - data: devicesToShow.map((device) { - final combinedSpaceNames = device.spaces != null - ? device.spaces!.map((space) => space.spaceName).join(' > ') + - (device.community != null ? ' > ${device.community!.name}' : '') - : (device.community != null ? device.community!.name : ''); - - return [ - device.name ?? '', - device.productName ?? '', - device.uuid ?? '', - (device.spaces != null && device.spaces!.isNotEmpty) ? device.spaces![0].spaceName : '', - combinedSpaceNames, - device.batteryLevel != null ? '${device.batteryLevel}%' : '-', - formatDateTime(DateTime.fromMillisecondsSinceEpoch((device.createTime ?? 0) * 1000)), - device.online == true ? 'Online' : 'Offline', - formatDateTime(DateTime.fromMillisecondsSinceEpoch((device.updateTime ?? 0) * 1000)), - ]; - }).toList(), - onSelectionChanged: (selectedRows) { - context.read().add(UpdateSelection(selectedRows)); - }, - initialSelectedIds: - context.read().selectedDevices.map((device) => device.uuid!).toList(), - isEmpty: devicesToShow.isEmpty, - ), - ), - ) ], ); }, diff --git a/lib/pages/device_managment/all_devices/widgets/device_search_filters.dart b/lib/pages/device_managment/all_devices/widgets/device_search_filters.dart index b9e36c25..0f86ef15 100644 --- a/lib/pages/device_managment/all_devices/widgets/device_search_filters.dart +++ b/lib/pages/device_managment/all_devices/widgets/device_search_filters.dart @@ -12,8 +12,7 @@ class DeviceSearchFilters extends StatefulWidget { State createState() => _DeviceSearchFiltersState(); } -class _DeviceSearchFiltersState extends State - with HelperResponsiveLayout { +class _DeviceSearchFiltersState extends State with HelperResponsiveLayout { final TextEditingController communityController = TextEditingController(); final TextEditingController unitNameController = TextEditingController(); final TextEditingController productNameController = TextEditingController(); @@ -27,8 +26,7 @@ class _DeviceSearchFiltersState extends State const SizedBox(width: 20), _buildSearchField("Space Name", unitNameController, 200), const SizedBox(width: 20), - _buildSearchField( - "Device Name / Product Name", productNameController, 300), + _buildSearchField("Device Name / Product Name", productNameController, 300), const SizedBox(width: 20), _buildSearchResetButtons(), ], @@ -53,8 +51,7 @@ class _DeviceSearchFiltersState extends State ); } - Widget _buildSearchField( - String title, TextEditingController controller, double width) { + Widget _buildSearchField(String title, TextEditingController controller, double width) { return Container( child: StatefulTextField( title: title, @@ -88,7 +85,7 @@ class _DeviceSearchFiltersState extends State productNameController.clear(); context.read() ..add(ResetFilters()) - ..add(FetchDevices()); + ..add(const FetchDevices('', '')); }, ); } diff --git a/lib/pages/home/bloc/home_bloc.dart b/lib/pages/home/bloc/home_bloc.dart index 1772ef88..6863236b 100644 --- a/lib/pages/home/bloc/home_bloc.dart +++ b/lib/pages/home/bloc/home_bloc.dart @@ -1,44 +1,44 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:go_router/go_router.dart'; -import 'package:graphview/GraphView.dart'; +// import 'package:graphview/GraphView.dart'; import 'package:syncrow_web/pages/auth/model/user_model.dart'; import 'package:syncrow_web/pages/home/bloc/home_event.dart'; import 'package:syncrow_web/pages/home/bloc/home_state.dart'; import 'package:syncrow_web/pages/home/home_model/home_item_model.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; import 'package:syncrow_web/services/home_api.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; import 'package:syncrow_web/utils/constants/routes_const.dart'; class HomeBloc extends Bloc { - final Graph graph = Graph()..isTree = true; - final BuchheimWalkerConfiguration builder = BuchheimWalkerConfiguration(); - List sourcesList = []; - List destinationsList = []; + // final Graph graph = Graph()..isTree = true; + // final BuchheimWalkerConfiguration builder = BuchheimWalkerConfiguration(); + // List sourcesList = []; + // List destinationsList = []; UserModel? user; HomeBloc() : super((HomeInitial())) { - on(_createNode); + // on(_createNode); on(_fetchUserInfo); } - void _createNode(CreateNewNode event, Emitter emit) async { - emit(HomeInitial()); - sourcesList.add(event.sourceNode); - destinationsList.add(event.destinationNode); - for (int i = 0; i < sourcesList.length; i++) { - graph.addEdge(sourcesList[i], destinationsList[i]); - } + // void _createNode(CreateNewNode event, Emitter emit) async { + // emit(HomeInitial()); + // sourcesList.add(event.sourceNode); + // destinationsList.add(event.destinationNode); + // for (int i = 0; i < sourcesList.length; i++) { + // graph.addEdge(sourcesList[i], destinationsList[i]); + // } - builder - ..siblingSeparation = (100) - ..levelSeparation = (150) - ..subtreeSeparation = (150) - ..orientation = (BuchheimWalkerConfiguration.ORIENTATION_TOP_BOTTOM); - emit(HomeUpdateTree(graph: graph, builder: builder)); - } + // builder + // ..siblingSeparation = (100) + // ..levelSeparation = (150) + // ..subtreeSeparation = (150) + // ..orientation = (BuchheimWalkerConfiguration.ORIENTATION_TOP_BOTTOM); + // emit(HomeUpdateTree(graph: graph, builder: builder)); + // } Future _fetchUserInfo(FetchUserInfo event, Emitter emit) async { try { diff --git a/lib/pages/home/bloc/home_event.dart b/lib/pages/home/bloc/home_event.dart index 963202b9..50480602 100644 --- a/lib/pages/home/bloc/home_event.dart +++ b/lib/pages/home/bloc/home_event.dart @@ -1,5 +1,5 @@ import 'package:equatable/equatable.dart'; -import 'package:graphview/GraphView.dart'; +// import 'package:graphview/GraphView.dart'; abstract class HomeEvent extends Equatable { const HomeEvent(); @@ -8,16 +8,16 @@ abstract class HomeEvent extends Equatable { List get props => []; } -class CreateNewNode extends HomeEvent { - final Node sourceNode; - final Node destinationNode; - const CreateNewNode( - {required this.sourceNode, required this.destinationNode}); +// class CreateNewNode extends HomeEvent { +// final Node sourceNode; +// final Node destinationNode; +// const CreateNewNode( +// {required this.sourceNode, required this.destinationNode}); - @override - List get props => [sourceNode, destinationNode]; -} +// @override +// List get props => [sourceNode, destinationNode]; +// } class FetchUserInfo extends HomeEvent { const FetchUserInfo(); -} \ No newline at end of file +} diff --git a/lib/pages/home/bloc/home_state.dart b/lib/pages/home/bloc/home_state.dart index 10c50486..64c840ab 100644 --- a/lib/pages/home/bloc/home_state.dart +++ b/lib/pages/home/bloc/home_state.dart @@ -1,5 +1,5 @@ import 'package:equatable/equatable.dart'; -import 'package:graphview/GraphView.dart'; +// import 'package:graphview/GraphView.dart'; abstract class HomeState extends Equatable { const HomeState(); @@ -10,17 +10,17 @@ abstract class HomeState extends Equatable { class HomeInitial extends HomeState {} -class HomeCounterState extends HomeState { - final int counter; - const HomeCounterState(this.counter); -} +// class HomeCounterState extends HomeState { +// final int counter; +// const HomeCounterState(this.counter); +// } -class HomeUpdateTree extends HomeState { - final Graph graph; - final BuchheimWalkerConfiguration builder; +// class HomeUpdateTree extends HomeState { +// final Graph graph; +// final BuchheimWalkerConfiguration builder; - const HomeUpdateTree({required this.graph, required this.builder}); +// const HomeUpdateTree({required this.graph, required this.builder}); - @override - List get props => [graph, builder]; -} +// @override +// List get props => [graph, builder]; +// } diff --git a/lib/pages/home/view/home_page_mobile.dart b/lib/pages/home/view/home_page_mobile.dart index 8f72f8cb..17735409 100644 --- a/lib/pages/home/view/home_page_mobile.dart +++ b/lib/pages/home/view/home_page_mobile.dart @@ -41,8 +41,7 @@ class HomeMobilePage extends StatelessWidget { SizedBox(height: size.height * 0.05), const Text( 'ACCESS YOUR APPS', - style: - TextStyle(fontSize: 20, fontWeight: FontWeight.w700), + style: TextStyle(fontSize: 20, fontWeight: FontWeight.w700), ), const SizedBox(height: 30), Expanded( @@ -51,9 +50,8 @@ class HomeMobilePage extends StatelessWidget { height: size.height * 0.6, width: size.width * 0.68, child: GridView.builder( - itemCount: 8, - gridDelegate: - const SliverGridDelegateWithFixedCrossAxisCount( + itemCount: 3, + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2, crossAxisSpacing: 20.0, mainAxisSpacing: 20.0, @@ -65,8 +63,7 @@ class HomeMobilePage extends StatelessWidget { active: homeItems[index]['active'], name: homeItems[index]['title'], img: homeItems[index]['icon'], - onTap: () => - homeBloc.homeItems[index].onPress(context), + onTap: () => homeBloc.homeItems[index].onPress(context), ); }, ), @@ -97,33 +94,33 @@ class HomeMobilePage extends StatelessWidget { 'icon': Assets.devicesIcon, 'active': true, }, - { - 'title': 'Move in', - 'icon': Assets.moveinIcon, - 'active': false, - }, - { - 'title': 'Construction', - 'icon': Assets.constructionIcon, - 'active': false, - }, - { - 'title': 'Energy', - 'icon': Assets.energyIcon, - 'color': ColorsManager.slidingBlueColor.withOpacity(0.2), - 'active': false, - }, - { - 'title': 'Integrations', - 'icon': Assets.integrationsIcon, - 'color': ColorsManager.slidingBlueColor.withOpacity(0.2), - 'active': false, - }, - { - 'title': 'Asset', - 'icon': Assets.assetIcon, - 'color': ColorsManager.slidingBlueColor.withOpacity(0.2), - 'active': false, - }, + // { + // 'title': 'Move in', + // 'icon': Assets.moveinIcon, + // 'active': false, + // }, + // { + // 'title': 'Construction', + // 'icon': Assets.constructionIcon, + // 'active': false, + // }, + // { + // 'title': 'Energy', + // 'icon': Assets.energyIcon, + // 'color': ColorsManager.slidingBlueColor.withOpacity(0.2), + // 'active': false, + // }, + // { + // 'title': 'Integrations', + // 'icon': Assets.integrationsIcon, + // 'color': ColorsManager.slidingBlueColor.withOpacity(0.2), + // 'active': false, + // }, + // { + // 'title': 'Asset', + // 'icon': Assets.assetIcon, + // 'color': ColorsManager.slidingBlueColor.withOpacity(0.2), + // 'active': false, + // }, ]; } diff --git a/lib/pages/home/view/home_page_web.dart b/lib/pages/home/view/home_page_web.dart index a198fa76..866f9766 100644 --- a/lib/pages/home/view/home_page_web.dart +++ b/lib/pages/home/view/home_page_web.dart @@ -32,43 +32,48 @@ class HomeWebPage extends StatelessWidget { scaffoldBody: SizedBox( height: size.height, width: size.width, - child: Column( + child: Row( mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, children: [ - SizedBox(height: size.height * 0.1), - Text( - 'ACCESS YOUR APPS', - style: Theme.of(context) - .textTheme - .headlineLarge! - .copyWith(color: Colors.black, fontSize: 40), - ), - const SizedBox(height: 30), - Expanded( - flex: 4, - child: SizedBox( - height: size.height * 0.6, - width: size.width * 0.68, - child: GridView.builder( - itemCount: 3, //8 - gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 4, - crossAxisSpacing: 20.0, - mainAxisSpacing: 20.0, - childAspectRatio: 1.5, - ), - itemBuilder: (context, index) { - return HomeCard( - index: index, - active: homeBloc.homeItems[index].active!, - name: homeBloc.homeItems[index].title!, - img: homeBloc.homeItems[index].icon!, - onTap: () => homeBloc.homeItems[index].onPress(context), - ); - }, + Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SizedBox(height: size.height * 0.1), + Text( + 'ACCESS YOUR APPS', + style: Theme.of(context) + .textTheme + .headlineLarge! + .copyWith(color: Colors.black, fontSize: 40), ), - ), + const SizedBox(height: 30), + Expanded( + flex: 4, + child: SizedBox( + height: size.height * 0.6, + width: size.width * 0.68, + child: GridView.builder( + itemCount: 3, //8 + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 4, + crossAxisSpacing: 20.0, + mainAxisSpacing: 20.0, + childAspectRatio: 1.5, + ), + itemBuilder: (context, index) { + return HomeCard( + index: index, + active: homeBloc.homeItems[index].active!, + name: homeBloc.homeItems[index].title!, + img: homeBloc.homeItems[index].icon!, + onTap: () => homeBloc.homeItems[index].onPress(context), + ); + }, + ), + ), + ), + ], ), ], ), diff --git a/lib/pages/home/view/tree_page.dart b/lib/pages/home/view/tree_page.dart index 2166467f..9458e361 100644 --- a/lib/pages/home/view/tree_page.dart +++ b/lib/pages/home/view/tree_page.dart @@ -1,185 +1,185 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:graphview/GraphView.dart'; -import 'package:syncrow_web/pages/home/bloc/home_bloc.dart'; -import 'package:syncrow_web/pages/home/bloc/home_event.dart'; -import 'package:syncrow_web/pages/home/bloc/home_state.dart'; +// import 'package:flutter/material.dart'; +// import 'package:flutter_bloc/flutter_bloc.dart'; +// import 'package:graphview/GraphView.dart'; +// import 'package:syncrow_web/pages/home/bloc/home_bloc.dart'; +// import 'package:syncrow_web/pages/home/bloc/home_event.dart'; +// import 'package:syncrow_web/pages/home/bloc/home_state.dart'; -class TreeWidget extends StatelessWidget { - const TreeWidget({super.key}); +// class TreeWidget extends StatelessWidget { +// const TreeWidget({super.key}); - @override - Widget build(BuildContext context) { - // final HomeBloc homeBloc = BlocProvider.of(context); - String firstNodeName = ''; - String secondNodeName = ''; +// @override +// Widget build(BuildContext context) { +// // final HomeBloc homeBloc = BlocProvider.of(context); +// String firstNodeName = ''; +// String secondNodeName = ''; - return SafeArea( - child: Container( - padding: const EdgeInsets.all(24), - width: MediaQuery.sizeOf(context).width, - height: MediaQuery.sizeOf(context).height, - alignment: AlignmentDirectional.center, - child: Column( - mainAxisSize: MainAxisSize.max, - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - BlocBuilder(builder: (context, state) { - if (state is HomeInitial) { - return Wrap( - children: [ - SizedBox( - width: 100, - child: TextFormField( - decoration: const InputDecoration( - labelText: "Subtree separation"), - onChanged: (text) { - firstNodeName = text; - }, - ), - ), - const SizedBox( - width: 8, - ), - Container( - width: 100, - child: TextFormField( - decoration: InputDecoration(labelText: "Node Name"), - onChanged: (text) { - secondNodeName = text; - }, - ), - ), - ElevatedButton( - onPressed: () { - final node1 = Node.Id(firstNodeName); - final node2 = Node.Id(secondNodeName); - context.read().add(CreateNewNode( - sourceNode: node1, destinationNode: node2)); - }, - child: Text("Add"), - ) - ], - ); - } - if (state is HomeUpdateTree) { - return Expanded( - child: InteractiveViewer( - constrained: false, - boundaryMargin: const EdgeInsets.all(100), - minScale: 0.01, - maxScale: 5.6, - child: GraphView( - graph: state.graph, - algorithm: BuchheimWalkerAlgorithm( - state.builder, TreeEdgeRenderer(state.builder)), - paint: Paint() - ..color = Colors.green - ..strokeWidth = 1 - ..style = PaintingStyle.stroke, - builder: (Node node) { - // I can decide what widget should be shown here based on the id - var nodeName = node.key!.value; - return rectangleWidget(nodeName, node, context); - }, - )), - ); - } else { - return Container(); - } - }) - ], - ), - ), - ); - } -} +// return SafeArea( +// child: Container( +// padding: const EdgeInsets.all(24), +// width: MediaQuery.sizeOf(context).width, +// height: MediaQuery.sizeOf(context).height, +// alignment: AlignmentDirectional.center, +// child: Column( +// mainAxisSize: MainAxisSize.max, +// crossAxisAlignment: CrossAxisAlignment.center, +// mainAxisAlignment: MainAxisAlignment.center, +// children: [ +// BlocBuilder(builder: (context, state) { +// if (state is HomeInitial) { +// return Wrap( +// children: [ +// SizedBox( +// width: 100, +// child: TextFormField( +// decoration: const InputDecoration( +// labelText: "Subtree separation"), +// onChanged: (text) { +// firstNodeName = text; +// }, +// ), +// ), +// const SizedBox( +// width: 8, +// ), +// Container( +// width: 100, +// child: TextFormField( +// decoration: InputDecoration(labelText: "Node Name"), +// onChanged: (text) { +// secondNodeName = text; +// }, +// ), +// ), +// ElevatedButton( +// onPressed: () { +// final node1 = Node.Id(firstNodeName); +// final node2 = Node.Id(secondNodeName); +// context.read().add(CreateNewNode( +// sourceNode: node1, destinationNode: node2)); +// }, +// child: Text("Add"), +// ) +// ], +// ); +// } +// if (state is HomeUpdateTree) { +// return Expanded( +// child: InteractiveViewer( +// constrained: false, +// boundaryMargin: const EdgeInsets.all(100), +// minScale: 0.01, +// maxScale: 5.6, +// child: GraphView( +// graph: state.graph, +// algorithm: BuchheimWalkerAlgorithm( +// state.builder, TreeEdgeRenderer(state.builder)), +// paint: Paint() +// ..color = Colors.green +// ..strokeWidth = 1 +// ..style = PaintingStyle.stroke, +// builder: (Node node) { +// // I can decide what widget should be shown here based on the id +// var nodeName = node.key!.value; +// return rectangleWidget(nodeName, node, context); +// }, +// )), +// ); +// } else { +// return Container(); +// } +// }) +// ], +// ), +// ), +// ); +// } +// } -Widget rectangleWidget(String text, Node node, BuildContext blocContext) { - String nodeName = ''; - return InkWell( - onTap: () { - showDialog( - context: blocContext, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('Add a child'), - content: TextField( - decoration: - const InputDecoration(hintText: 'Enter your text here'), - onChanged: (value) { - nodeName = value; - }, - ), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: Text('Close'), - ), - TextButton( - onPressed: () { - if (nodeName.isNotEmpty) { - final newNode = Node.Id(nodeName); - blocContext.read().add(CreateNewNode( - sourceNode: node, destinationNode: newNode)); - } - Navigator.of(context).pop(); - }, - child: Text('Add'), - ), - ], - ); - }, - ); - }, - child: Container( - width: MediaQuery.of(blocContext).size.width * 0.2, - margin: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0), - padding: EdgeInsets.all(20.0), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(10.0), - boxShadow: [ - BoxShadow( - color: Colors.grey.withOpacity(0.5), - spreadRadius: 2, - blurRadius: 5, - offset: Offset(0, 3), // changes position of shadow - ), - ], - ), - child: Row( - children: [ - const SizedBox( - child: Icon( - Icons.location_on, - color: Colors.blue, - size: 40.0, - ), - ), - const SizedBox(width: 10.0), - SizedBox( - child: Text( - text, - style: const TextStyle( - fontSize: 24.0, - fontWeight: FontWeight.bold, - ), - ), - ), - const Spacer(), - Container( - child: const Icon( - Icons.add_circle_outline, - color: Colors.grey, - size: 24.0, - ), - ), - ], - ), - ), - ); -} +// Widget rectangleWidget(String text, Node node, BuildContext blocContext) { +// String nodeName = ''; +// return InkWell( +// onTap: () { +// showDialog( +// context: blocContext, +// builder: (BuildContext context) { +// return AlertDialog( +// title: const Text('Add a child'), +// content: TextField( +// decoration: +// const InputDecoration(hintText: 'Enter your text here'), +// onChanged: (value) { +// nodeName = value; +// }, +// ), +// actions: [ +// TextButton( +// onPressed: () { +// Navigator.of(context).pop(); +// }, +// child: Text('Close'), +// ), +// TextButton( +// onPressed: () { +// if (nodeName.isNotEmpty) { +// final newNode = Node.Id(nodeName); +// blocContext.read().add(CreateNewNode( +// sourceNode: node, destinationNode: newNode)); +// } +// Navigator.of(context).pop(); +// }, +// child: Text('Add'), +// ), +// ], +// ); +// }, +// ); +// }, +// child: Container( +// width: MediaQuery.of(blocContext).size.width * 0.2, +// margin: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0), +// padding: EdgeInsets.all(20.0), +// decoration: BoxDecoration( +// color: Colors.white, +// borderRadius: BorderRadius.circular(10.0), +// boxShadow: [ +// BoxShadow( +// color: Colors.grey.withOpacity(0.5), +// spreadRadius: 2, +// blurRadius: 5, +// offset: Offset(0, 3), // changes position of shadow +// ), +// ], +// ), +// child: Row( +// children: [ +// const SizedBox( +// child: Icon( +// Icons.location_on, +// color: Colors.blue, +// size: 40.0, +// ), +// ), +// const SizedBox(width: 10.0), +// SizedBox( +// child: Text( +// text, +// style: const TextStyle( +// fontSize: 24.0, +// fontWeight: FontWeight.bold, +// ), +// ), +// ), +// const Spacer(), +// Container( +// child: const Icon( +// Icons.add_circle_outline, +// color: Colors.grey, +// size: 24.0, +// ), +// ), +// ], +// ), +// ), +// ); +// } diff --git a/lib/pages/routiens/helper/dialog_helper/device_dialog_helper.dart b/lib/pages/routiens/helper/dialog_helper/device_dialog_helper.dart deleted file mode 100644 index 1dd84c19..00000000 --- a/lib/pages/routiens/helper/dialog_helper/device_dialog_helper.dart +++ /dev/null @@ -1,85 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/ac_dialog.dart'; -import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/one_gang_switch_dialog.dart'; -import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/three_gang_switch_dialog.dart'; -import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/two_gang_switch_dialog.dart'; -import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; - -class DeviceDialogHelper { - static Future?> showDeviceDialog( - BuildContext context, - Map data, { - required bool removeComparetors, - }) async { - final functions = data['functions'] as List; - - try { - final result = await _getDialogForDeviceType( - context, - data['productType'], - data, - functions, - removeComparetors: removeComparetors, - ); - - if (result != null) { - return result; - } - } catch (e) { - debugPrint('Error: $e'); - } - - return null; - } - - static Future?> _getDialogForDeviceType( - BuildContext context, - String productType, - Map data, - List functions, - {required bool removeComparetors}) async { - final routineBloc = context.read(); - final deviceSelectedFunctions = - routineBloc.state.selectedFunctions[data['uniqueCustomId']] ?? []; - - switch (productType) { - case 'AC': - return ACHelper.showACFunctionsDialog( - context, - functions, - data['device'], - deviceSelectedFunctions, - data['uniqueCustomId'], - removeComparetors); - - case '1G': - return OneGangSwitchHelper.showSwitchFunctionsDialog( - context, - functions, - data['device'], - deviceSelectedFunctions, - data['uniqueCustomId'], - removeComparetors); - case '2G': - return TwoGangSwitchHelper.showSwitchFunctionsDialog( - context, - functions, - data['device'], - deviceSelectedFunctions, - data['uniqueCustomId'], - removeComparetors); - case '3G': - return ThreeGangSwitchHelper.showSwitchFunctionsDialog( - context, - functions, - data['device'], - deviceSelectedFunctions, - data['uniqueCustomId'], - removeComparetors); - default: - return null; - } - } -} diff --git a/lib/pages/routiens/view/routines_view.dart b/lib/pages/routiens/view/routines_view.dart deleted file mode 100644 index 3dad14bf..00000000 --- a/lib/pages/routiens/view/routines_view.dart +++ /dev/null @@ -1,69 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/view/create_new_routine_view.dart'; -import 'package:syncrow_web/pages/routiens/widgets/main_routine_view/fetch_routine_scenes_automation.dart'; -import 'package:syncrow_web/pages/routiens/widgets/main_routine_view/routine_view_card.dart'; -import 'package:syncrow_web/utils/color_manager.dart'; - -class RoutinesView extends StatefulWidget { - const RoutinesView({super.key}); - - @override - State createState() => _RoutinesViewState(); -} - -class _RoutinesViewState extends State { - @override - void initState() { - super.initState(); - context.read().add(FetchDevicesInRoutine()); - } - - @override - Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - if (state.createRoutineView) { - return const CreateNewRoutineView(); - } - return Padding( - padding: const EdgeInsets.all(16), - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text( - "Create New Routines", - style: Theme.of(context).textTheme.titleLarge?.copyWith( - color: ColorsManager.grayColor, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox( - height: 10, - ), - RoutineViewCard( - onTap: () { - context.read().add( - (ResetRoutineState()), - ); - BlocProvider.of(context).add( - const CreateNewRoutineViewEvent(createRoutineView: true), - ); - }, - icon: Icons.add, - textString: '', - ), - const SizedBox( - height: 15, - ), - const Expanded(child: FetchRoutineScenesAutomation()), - ], - ), - ); - }, - ); - } -} diff --git a/lib/pages/routiens/widgets/main_routine_view/fetch_routine_scenes_automation.dart b/lib/pages/routiens/widgets/main_routine_view/fetch_routine_scenes_automation.dart deleted file mode 100644 index 62780d5f..00000000 --- a/lib/pages/routiens/widgets/main_routine_view/fetch_routine_scenes_automation.dart +++ /dev/null @@ -1,143 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/widgets/main_routine_view/routine_view_card.dart'; -import 'package:syncrow_web/utils/color_manager.dart'; -import 'package:syncrow_web/utils/constants/assets.dart'; -import 'package:syncrow_web/utils/extension/build_context_x.dart'; -import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; - -class FetchRoutineScenesAutomation extends StatefulWidget { - const FetchRoutineScenesAutomation({super.key}); - - @override - State createState() => _FetchRoutineScenesState(); -} - -class _FetchRoutineScenesState extends State - with HelperResponsiveLayout { - @override - void initState() { - super.initState(); - context.read() - ..add(const LoadScenes(spaceId, communityId)) - ..add(const LoadAutomation(spaceId)); - } - - @override - Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return state.isLoading - ? const Center( - child: CircularProgressIndicator(), - ) - : SingleChildScrollView( - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 16.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Text( - "Scenes (Tab to Run)", - style: Theme.of(context).textTheme.titleLarge?.copyWith( - color: ColorsManager.grayColor, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox(height: 10), - if (state.scenes.isEmpty) - Text( - "No scenes found", - style: context.textTheme.bodyMedium?.copyWith( - color: ColorsManager.grayColor, - ), - ), - if (state.scenes.isNotEmpty) - ConstrainedBox( - constraints: BoxConstraints( - maxHeight: isSmallScreenSize(context) ? 160 : 170, - ), - child: ListView.builder( - scrollDirection: Axis.horizontal, - itemCount: state.scenes.length, - itemBuilder: (context, index) => Padding( - padding: EdgeInsets.only( - right: isSmallScreenSize(context) ? 4.0 : 8.0, - ), - child: RoutineViewCard( - onTap: () { - BlocProvider.of(context).add( - const CreateNewRoutineViewEvent(createRoutineView: true), - ); - context.read().add( - GetSceneDetails( - sceneId: state.scenes[index].id, - isTabToRun: true, - isUpdate: true, - ), - ); - }, - textString: state.scenes[index].name, - icon: state.scenes[index].icon ?? Assets.logoHorizontal, - isFromScenes: true, - iconInBytes: state.scenes[index].iconInBytes, - ), - ), - ), - ), - const SizedBox(height: 15), - Text( - "Automations", - style: Theme.of(context).textTheme.titleLarge?.copyWith( - color: ColorsManager.grayColor, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox(height: 10), - if (state.automations.isEmpty) - Text( - "No automations found", - style: context.textTheme.bodyMedium?.copyWith( - color: ColorsManager.grayColor, - ), - ), - if (state.automations.isNotEmpty) - ConstrainedBox( - constraints: BoxConstraints( - maxHeight: isSmallScreenSize(context) ? 160 : 170, - ), - child: ListView.builder( - scrollDirection: Axis.horizontal, - itemCount: state.automations.length, - itemBuilder: (context, index) => Padding( - padding: EdgeInsets.only( - right: isSmallScreenSize(context) ? 4.0 : 8.0, - ), - child: RoutineViewCard( - onTap: () { - BlocProvider.of(context).add( - const CreateNewRoutineViewEvent(createRoutineView: true), - ); - context.read().add( - GetAutomationDetails( - automationId: state.automations[index].id, - isAutomation: true, - isUpdate: true), - ); - }, - textString: state.automations[index].name, - icon: state.automations[index].icon ?? Assets.automation, - ), - ), - ), - ), - ], - ), - ), - ); - }, - ); - } -} diff --git a/lib/pages/routiens/bloc/effective_period/effect_period_bloc.dart b/lib/pages/routines/bloc/effective_period/effect_period_bloc.dart similarity index 96% rename from lib/pages/routiens/bloc/effective_period/effect_period_bloc.dart rename to lib/pages/routines/bloc/effective_period/effect_period_bloc.dart index 7f4ca22e..fd56d232 100644 --- a/lib/pages/routiens/bloc/effective_period/effect_period_bloc.dart +++ b/lib/pages/routines/bloc/effective_period/effect_period_bloc.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_event.dart'; -import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_state.dart'; +import 'package:syncrow_web/pages/routines/bloc/effective_period/effect_period_event.dart'; +import 'package:syncrow_web/pages/routines/bloc/effective_period/effect_period_state.dart'; import 'package:syncrow_web/utils/constants/app_enum.dart'; class EffectPeriodBloc extends Bloc { diff --git a/lib/pages/routiens/bloc/effective_period/effect_period_event.dart b/lib/pages/routines/bloc/effective_period/effect_period_event.dart similarity index 95% rename from lib/pages/routiens/bloc/effective_period/effect_period_event.dart rename to lib/pages/routines/bloc/effective_period/effect_period_event.dart index 20f686d6..a7ae829b 100644 --- a/lib/pages/routiens/bloc/effective_period/effect_period_event.dart +++ b/lib/pages/routines/bloc/effective_period/effect_period_event.dart @@ -1,5 +1,5 @@ import 'package:equatable/equatable.dart'; -import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart'; +import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_automation_model.dart'; import 'package:syncrow_web/utils/constants/app_enum.dart'; abstract class EffectPeriodEvent extends Equatable { diff --git a/lib/pages/routiens/bloc/effective_period/effect_period_state.dart b/lib/pages/routines/bloc/effective_period/effect_period_state.dart similarity index 100% rename from lib/pages/routiens/bloc/effective_period/effect_period_state.dart rename to lib/pages/routines/bloc/effective_period/effect_period_state.dart diff --git a/lib/pages/routiens/bloc/functions_bloc/functions_bloc_bloc.dart b/lib/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart similarity index 86% rename from lib/pages/routiens/bloc/functions_bloc/functions_bloc_bloc.dart rename to lib/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart index 760d5697..a196ff27 100644 --- a/lib/pages/routiens/bloc/functions_bloc/functions_bloc_bloc.dart +++ b/lib/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; -import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; +import 'package:syncrow_web/pages/routines/models/device_functions.dart'; part 'functions_bloc_event.dart'; part 'functions_bloc_state.dart'; @@ -26,8 +26,7 @@ class FunctionBloc extends Bloc { functionCode: event.functionData.functionCode, operationName: event.functionData.operationName, value: event.functionData.value ?? existingData.value, - valueDescription: event.functionData.valueDescription ?? - existingData.valueDescription, + valueDescription: event.functionData.valueDescription ?? existingData.valueDescription, condition: event.functionData.condition ?? existingData.condition, ); } else { @@ -59,10 +58,8 @@ class FunctionBloc extends Bloc { ); } - FutureOr _onSelectFunction( - SelectFunction event, Emitter emit) { + FutureOr _onSelectFunction(SelectFunction event, Emitter emit) { emit(state.copyWith( - selectedFunction: event.functionCode, - selectedOperationName: event.operationName)); + selectedFunction: event.functionCode, selectedOperationName: event.operationName)); } } diff --git a/lib/pages/routiens/bloc/functions_bloc/functions_bloc_event.dart b/lib/pages/routines/bloc/functions_bloc/functions_bloc_event.dart similarity index 100% rename from lib/pages/routiens/bloc/functions_bloc/functions_bloc_event.dart rename to lib/pages/routines/bloc/functions_bloc/functions_bloc_event.dart diff --git a/lib/pages/routiens/bloc/functions_bloc/functions_bloc_state.dart b/lib/pages/routines/bloc/functions_bloc/functions_bloc_state.dart similarity index 100% rename from lib/pages/routiens/bloc/functions_bloc/functions_bloc_state.dart rename to lib/pages/routines/bloc/functions_bloc/functions_bloc_state.dart diff --git a/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart b/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart similarity index 96% rename from lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart rename to lib/pages/routines/bloc/routine_bloc/routine_bloc.dart index a90ea116..bc83c40f 100644 --- a/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart +++ b/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart @@ -4,12 +4,12 @@ import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart'; -import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart'; -import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_scene_model.dart'; -import 'package:syncrow_web/pages/routiens/models/delay/delay_fucntions.dart'; -import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; -import 'package:syncrow_web/pages/routiens/models/routine_details_model.dart'; -import 'package:syncrow_web/pages/routiens/models/routine_model.dart'; +import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_automation_model.dart'; +import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_scene_model.dart'; +import 'package:syncrow_web/pages/routines/models/delay/delay_fucntions.dart'; +import 'package:syncrow_web/pages/routines/models/device_functions.dart'; +import 'package:syncrow_web/pages/routines/models/routine_details_model.dart'; +import 'package:syncrow_web/pages/routines/models/routine_model.dart'; import 'package:syncrow_web/services/devices_mang_api.dart'; import 'package:syncrow_web/services/routines_api.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; @@ -19,8 +19,8 @@ import 'package:uuid/uuid.dart'; part 'routine_event.dart'; part 'routine_state.dart'; -const spaceId = '25c96044-fadf-44bb-93c7-3c079e527ce6'; -const communityId = 'aff21a57-2f91-4e5c-b99b-0182c3ab65a9'; +String spaceId = '25c96044-fadf-44bb-93c7-3c079e527ce6'; +String communityId = 'aff21a57-2f91-4e5c-b99b-0182c3ab65a9'; class RoutineBloc extends Bloc { RoutineBloc() : super(const RoutineState()) { @@ -57,8 +57,8 @@ class RoutineBloc extends Bloc { emit(state.copyWith(routineTab: event.isRoutineTab, createRoutineView: false)); add(ResetRoutineState()); if (event.isRoutineTab) { - add(const LoadScenes(spaceId, communityId)); - add(const LoadAutomation(spaceId)); + add(LoadScenes(spaceId, communityId)); + add(LoadAutomation(spaceId)); } } @@ -156,18 +156,25 @@ class RoutineBloc extends Bloc { emit(state.copyWith(isLoading: true, errorMessage: null)); try { - final scenes = await SceneApi.getScenesByUnitId(event.unitId, event.communityId); + spaceId = event.spaceId; + communityId = event.communityId; + + List scenes = []; + + if (communityId.isNotEmpty && spaceId.isNotEmpty) { + scenes = await SceneApi.getScenes(event.spaceId, event.communityId); + } emit(state.copyWith( scenes: scenes, isLoading: false, )); } catch (e) { emit(state.copyWith( - isLoading: false, - loadScenesErrorMessage: 'Failed to load scenes', - errorMessage: '', - loadAutomationErrorMessage: '', - )); + isLoading: false, + loadScenesErrorMessage: 'Failed to load scenes', + errorMessage: '', + loadAutomationErrorMessage: '', + scenes: [])); } } @@ -175,27 +182,22 @@ class RoutineBloc extends Bloc { emit(state.copyWith(isLoading: true, errorMessage: null)); try { - final automations = await SceneApi.getAutomationByUnitId(event.unitId); - if (automations.isNotEmpty) { - emit(state.copyWith( - automations: automations, - isLoading: false, - )); - } else { - emit(state.copyWith( + spaceId = event.spaceId; + List automations = []; + if (spaceId.isNotEmpty) { + automations = await SceneApi.getAutomation(event.spaceId); + } + emit(state.copyWith( + automations: automations, + isLoading: false, + )); + } catch (e) { + emit(state.copyWith( isLoading: false, loadAutomationErrorMessage: 'Failed to load automations', errorMessage: '', loadScenesErrorMessage: '', - )); - } - } catch (e) { - emit(state.copyWith( - isLoading: false, - loadAutomationErrorMessage: 'Failed to load automations', - errorMessage: '', - loadScenesErrorMessage: '', - )); + automations: [])); } } @@ -290,8 +292,8 @@ class RoutineBloc extends Bloc { final result = await SceneApi.createScene(createSceneModel); if (result['success']) { add(ResetRoutineState()); - add(const LoadScenes(spaceId, communityId)); - add(const LoadAutomation(spaceId)); + add(LoadScenes(spaceId, communityId)); + add(LoadAutomation(spaceId)); } else { emit(state.copyWith( isLoading: false, @@ -419,8 +421,8 @@ class RoutineBloc extends Bloc { final result = await SceneApi.createAutomation(createAutomationModel); if (result['success']) { add(ResetRoutineState()); - add(const LoadAutomation(spaceId)); - add(const LoadScenes(spaceId, communityId)); + add(LoadAutomation(spaceId)); + add(LoadScenes(spaceId, communityId)); } else { emit(state.copyWith( isLoading: false, @@ -785,8 +787,8 @@ class RoutineBloc extends Bloc { SceneApi.deleteAutomation(unitUuid: spaceId, automationId: state.automationId ?? ''); } - add(const LoadScenes(spaceId, communityId)); - add(const LoadAutomation(spaceId)); + add(LoadScenes(spaceId, communityId)); + add(LoadAutomation(spaceId)); add(ResetRoutineState()); emit(state.copyWith(isLoading: false, createRoutineView: false)); } catch (e) { @@ -814,7 +816,7 @@ class RoutineBloc extends Bloc { FutureOr _fetchDevices(FetchDevicesInRoutine event, Emitter emit) async { emit(state.copyWith(isLoading: true)); try { - final devices = await DevicesManagementApi().fetchDevices(); + final devices = await DevicesManagementApi().fetchDevices(communityId, spaceId); emit(state.copyWith(isLoading: false, devices: devices)); } catch (e) { @@ -892,8 +894,8 @@ class RoutineBloc extends Bloc { final result = await SceneApi.updateScene(createSceneModel, state.sceneId ?? ''); if (result['success']) { add(ResetRoutineState()); - add(const LoadScenes(spaceId, communityId)); - add(const LoadAutomation(spaceId)); + add(LoadScenes(spaceId, communityId)); + add(LoadAutomation(spaceId)); } else { emit(state.copyWith( isLoading: false, @@ -1021,8 +1023,8 @@ class RoutineBloc extends Bloc { if (result['success']) { add(ResetRoutineState()); - add(const LoadAutomation(spaceId)); - add(const LoadScenes(spaceId, communityId)); + add(LoadAutomation(spaceId)); + add(LoadScenes(spaceId, communityId)); } else { emit(state.copyWith( isLoading: false, diff --git a/lib/pages/routiens/bloc/routine_bloc/routine_event.dart b/lib/pages/routines/bloc/routine_bloc/routine_event.dart similarity index 95% rename from lib/pages/routiens/bloc/routine_bloc/routine_event.dart rename to lib/pages/routines/bloc/routine_bloc/routine_event.dart index f3d35eb8..e412aae6 100644 --- a/lib/pages/routiens/bloc/routine_bloc/routine_event.dart +++ b/lib/pages/routines/bloc/routine_bloc/routine_event.dart @@ -27,22 +27,22 @@ class AddToThenContainer extends RoutineEvent { } class LoadScenes extends RoutineEvent { - final String unitId; + final String spaceId; final String communityId; - const LoadScenes(this.unitId, this.communityId); + const LoadScenes(this.spaceId, this.communityId); @override - List get props => [unitId, communityId]; + List get props => [spaceId, communityId]; } class LoadAutomation extends RoutineEvent { - final String unitId; + final String spaceId; - const LoadAutomation(this.unitId); + const LoadAutomation(this.spaceId); @override - List get props => [unitId]; + List get props => [spaceId]; } class AddFunctionToRoutine extends RoutineEvent { diff --git a/lib/pages/routiens/bloc/routine_bloc/routine_state.dart b/lib/pages/routines/bloc/routine_bloc/routine_state.dart similarity index 100% rename from lib/pages/routiens/bloc/routine_bloc/routine_state.dart rename to lib/pages/routines/bloc/routine_bloc/routine_state.dart diff --git a/lib/pages/routiens/bloc/setting_bloc/setting_bloc.dart b/lib/pages/routines/bloc/setting_bloc/setting_bloc.dart similarity index 89% rename from lib/pages/routiens/bloc/setting_bloc/setting_bloc.dart rename to lib/pages/routines/bloc/setting_bloc/setting_bloc.dart index f70aed34..843b35df 100644 --- a/lib/pages/routiens/bloc/setting_bloc/setting_bloc.dart +++ b/lib/pages/routines/bloc/setting_bloc/setting_bloc.dart @@ -1,7 +1,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/setting_bloc/setting_event.dart'; -import 'package:syncrow_web/pages/routiens/bloc/setting_bloc/setting_state.dart'; -import 'package:syncrow_web/pages/routiens/models/icon_model.dart'; +import 'package:syncrow_web/pages/routines/bloc/setting_bloc/setting_event.dart'; +import 'package:syncrow_web/pages/routines/bloc/setting_bloc/setting_state.dart'; +import 'package:syncrow_web/pages/routines/models/icon_model.dart'; import 'package:syncrow_web/services/routines_api.dart'; class SettingBloc extends Bloc { diff --git a/lib/pages/routiens/bloc/setting_bloc/setting_event.dart b/lib/pages/routines/bloc/setting_bloc/setting_event.dart similarity index 100% rename from lib/pages/routiens/bloc/setting_bloc/setting_event.dart rename to lib/pages/routines/bloc/setting_bloc/setting_event.dart diff --git a/lib/pages/routiens/bloc/setting_bloc/setting_state.dart b/lib/pages/routines/bloc/setting_bloc/setting_state.dart similarity index 94% rename from lib/pages/routiens/bloc/setting_bloc/setting_state.dart rename to lib/pages/routines/bloc/setting_bloc/setting_state.dart index 7c88d67c..ae7571ce 100644 --- a/lib/pages/routiens/bloc/setting_bloc/setting_state.dart +++ b/lib/pages/routines/bloc/setting_bloc/setting_state.dart @@ -1,5 +1,5 @@ import 'package:equatable/equatable.dart'; -import 'package:syncrow_web/pages/routiens/models/icon_model.dart'; +import 'package:syncrow_web/pages/routines/models/icon_model.dart'; abstract class SettingState extends Equatable { const SettingState(); diff --git a/lib/pages/routines/helper/dialog_helper/device_dialog_helper.dart b/lib/pages/routines/helper/dialog_helper/device_dialog_helper.dart new file mode 100644 index 00000000..ed2af95a --- /dev/null +++ b/lib/pages/routines/helper/dialog_helper/device_dialog_helper.dart @@ -0,0 +1,62 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ac_dialog.dart'; +import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/one_gang_switch_dialog.dart'; +import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/three_gang_switch_dialog.dart'; +import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/two_gang_switch_dialog.dart'; +import 'package:syncrow_web/pages/routines/models/device_functions.dart'; + +class DeviceDialogHelper { + static Future?> showDeviceDialog( + BuildContext context, + Map data, { + required bool removeComparetors, + }) async { + final functions = data['functions'] as List; + + try { + final result = await _getDialogForDeviceType( + context, + data['productType'], + data, + functions, + removeComparetors: removeComparetors, + ); + + if (result != null) { + return result; + } + } catch (e) { + debugPrint('Error: $e'); + } + + return null; + } + + static Future?> _getDialogForDeviceType(BuildContext context, + String productType, Map data, List functions, + {required bool removeComparetors}) async { + final routineBloc = context.read(); + final deviceSelectedFunctions = + routineBloc.state.selectedFunctions[data['uniqueCustomId']] ?? []; + + switch (productType) { + case 'AC': + return ACHelper.showACFunctionsDialog(context, functions, data['device'], + deviceSelectedFunctions, data['uniqueCustomId'], removeComparetors); + + case '1G': + return OneGangSwitchHelper.showSwitchFunctionsDialog(context, functions, data['device'], + deviceSelectedFunctions, data['uniqueCustomId'], removeComparetors); + case '2G': + return TwoGangSwitchHelper.showSwitchFunctionsDialog(context, functions, data['device'], + deviceSelectedFunctions, data['uniqueCustomId'], removeComparetors); + case '3G': + return ThreeGangSwitchHelper.showSwitchFunctionsDialog(context, functions, data['device'], + deviceSelectedFunctions, data['uniqueCustomId'], removeComparetors); + default: + return null; + } + } +} diff --git a/lib/pages/routiens/helper/duration_format_helper.dart b/lib/pages/routines/helper/duration_format_helper.dart similarity index 100% rename from lib/pages/routiens/helper/duration_format_helper.dart rename to lib/pages/routines/helper/duration_format_helper.dart diff --git a/lib/pages/routiens/helper/save_routine_helper.dart b/lib/pages/routines/helper/save_routine_helper.dart similarity index 97% rename from lib/pages/routiens/helper/save_routine_helper.dart rename to lib/pages/routines/helper/save_routine_helper.dart index d73a69a7..e2ca5ede 100644 --- a/lib/pages/routiens/helper/save_routine_helper.dart +++ b/lib/pages/routines/helper/save_routine_helper.dart @@ -3,9 +3,9 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart'; +import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; diff --git a/lib/pages/routiens/models/ac/ac_function.dart b/lib/pages/routines/models/ac/ac_function.dart similarity index 96% rename from lib/pages/routiens/models/ac/ac_function.dart rename to lib/pages/routines/models/ac/ac_function.dart index 8feccda7..43b58394 100644 --- a/lib/pages/routiens/models/ac/ac_function.dart +++ b/lib/pages/routines/models/ac/ac_function.dart @@ -1,6 +1,6 @@ import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart'; -import 'package:syncrow_web/pages/routiens/models/ac/ac_operational_value.dart'; -import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; +import 'package:syncrow_web/pages/routines/models/ac/ac_operational_value.dart'; +import 'package:syncrow_web/pages/routines/models/device_functions.dart'; import 'package:syncrow_web/utils/constants/app_enum.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; diff --git a/lib/pages/routiens/models/ac/ac_operational_value.dart b/lib/pages/routines/models/ac/ac_operational_value.dart similarity index 100% rename from lib/pages/routiens/models/ac/ac_operational_value.dart rename to lib/pages/routines/models/ac/ac_operational_value.dart diff --git a/lib/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart b/lib/pages/routines/models/create_scene_and_autoamtion/create_automation_model.dart similarity index 100% rename from lib/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart rename to lib/pages/routines/models/create_scene_and_autoamtion/create_automation_model.dart diff --git a/lib/pages/routiens/models/create_scene_and_autoamtion/create_scene_model.dart b/lib/pages/routines/models/create_scene_and_autoamtion/create_scene_model.dart similarity index 100% rename from lib/pages/routiens/models/create_scene_and_autoamtion/create_scene_model.dart rename to lib/pages/routines/models/create_scene_and_autoamtion/create_scene_model.dart diff --git a/lib/pages/routiens/models/delay/delay_fucntions.dart b/lib/pages/routines/models/delay/delay_fucntions.dart similarity index 85% rename from lib/pages/routiens/models/delay/delay_fucntions.dart rename to lib/pages/routines/models/delay/delay_fucntions.dart index ff04251a..428825f4 100644 --- a/lib/pages/routiens/models/delay/delay_fucntions.dart +++ b/lib/pages/routines/models/delay/delay_fucntions.dart @@ -1,5 +1,5 @@ -import 'package:syncrow_web/pages/routiens/models/gang_switches/base_switch_function.dart'; -import 'package:syncrow_web/pages/routiens/models/gang_switches/switch_operational_value.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/base_switch_function.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/switch_operational_value.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; class DelayFunction extends BaseSwitchFunction { diff --git a/lib/pages/routiens/models/device_functions.dart b/lib/pages/routines/models/device_functions.dart similarity index 100% rename from lib/pages/routiens/models/device_functions.dart rename to lib/pages/routines/models/device_functions.dart diff --git a/lib/pages/routiens/models/gang_switches/base_switch_function.dart b/lib/pages/routines/models/gang_switches/base_switch_function.dart similarity index 72% rename from lib/pages/routiens/models/gang_switches/base_switch_function.dart rename to lib/pages/routines/models/gang_switches/base_switch_function.dart index f180b203..c124a8f7 100644 --- a/lib/pages/routiens/models/gang_switches/base_switch_function.dart +++ b/lib/pages/routines/models/gang_switches/base_switch_function.dart @@ -1,5 +1,5 @@ -import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; -import 'package:syncrow_web/pages/routiens/models/gang_switches/switch_operational_value.dart'; +import 'package:syncrow_web/pages/routines/models/device_functions.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/switch_operational_value.dart'; abstract class BaseSwitchFunction extends DeviceFunction { BaseSwitchFunction({ diff --git a/lib/pages/routiens/models/gang_switches/one_gang_switch/one_gang_switch.dart b/lib/pages/routines/models/gang_switches/one_gang_switch/one_gang_switch.dart similarity index 91% rename from lib/pages/routiens/models/gang_switches/one_gang_switch/one_gang_switch.dart rename to lib/pages/routines/models/gang_switches/one_gang_switch/one_gang_switch.dart index 2e20e40e..9451f89f 100644 --- a/lib/pages/routiens/models/gang_switches/one_gang_switch/one_gang_switch.dart +++ b/lib/pages/routines/models/gang_switches/one_gang_switch/one_gang_switch.dart @@ -1,5 +1,5 @@ -import 'package:syncrow_web/pages/routiens/models/gang_switches/base_switch_function.dart'; -import 'package:syncrow_web/pages/routiens/models/gang_switches/switch_operational_value.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/base_switch_function.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/switch_operational_value.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; class OneGangSwitchFunction extends BaseSwitchFunction { diff --git a/lib/pages/routiens/models/gang_switches/switch_operational_value.dart b/lib/pages/routines/models/gang_switches/switch_operational_value.dart similarity index 100% rename from lib/pages/routiens/models/gang_switches/switch_operational_value.dart rename to lib/pages/routines/models/gang_switches/switch_operational_value.dart diff --git a/lib/pages/routiens/models/gang_switches/three_gang_switch/three_gang_switch.dart b/lib/pages/routines/models/gang_switches/three_gang_switch/three_gang_switch.dart similarity index 89% rename from lib/pages/routiens/models/gang_switches/three_gang_switch/three_gang_switch.dart rename to lib/pages/routines/models/gang_switches/three_gang_switch/three_gang_switch.dart index 7f4710f0..ca0ed497 100644 --- a/lib/pages/routiens/models/gang_switches/three_gang_switch/three_gang_switch.dart +++ b/lib/pages/routines/models/gang_switches/three_gang_switch/three_gang_switch.dart @@ -1,5 +1,5 @@ -import 'package:syncrow_web/pages/routiens/models/gang_switches/base_switch_function.dart'; -import 'package:syncrow_web/pages/routiens/models/gang_switches/switch_operational_value.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/base_switch_function.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/switch_operational_value.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; class ThreeGangSwitch1Function extends BaseSwitchFunction { @@ -26,8 +26,7 @@ class ThreeGangSwitch1Function extends BaseSwitchFunction { } class ThreeGangCountdown1Function extends BaseSwitchFunction { - ThreeGangCountdown1Function( - {required super.deviceId, required super.deviceName}) + ThreeGangCountdown1Function({required super.deviceId, required super.deviceName}) : super( code: 'countdown_1', operationName: 'Light 1 Countdown', @@ -71,8 +70,7 @@ class ThreeGangSwitch2Function extends BaseSwitchFunction { } class ThreeGangCountdown2Function extends BaseSwitchFunction { - ThreeGangCountdown2Function( - {required super.deviceId, required super.deviceName}) + ThreeGangCountdown2Function({required super.deviceId, required super.deviceName}) : super( code: 'countdown_2', operationName: 'Light 2 Countdown', @@ -116,8 +114,7 @@ class ThreeGangSwitch3Function extends BaseSwitchFunction { } class ThreeGangCountdown3Function extends BaseSwitchFunction { - ThreeGangCountdown3Function( - {required super.deviceId, required super.deviceName}) + ThreeGangCountdown3Function({required super.deviceId, required super.deviceName}) : super( code: 'countdown_3', operationName: 'Light 3 Countdown', diff --git a/lib/pages/routiens/models/gang_switches/two_gang_switch/two_gang_switch.dart b/lib/pages/routines/models/gang_switches/two_gang_switch/two_gang_switch.dart similarity index 88% rename from lib/pages/routiens/models/gang_switches/two_gang_switch/two_gang_switch.dart rename to lib/pages/routines/models/gang_switches/two_gang_switch/two_gang_switch.dart index 91bda15c..95de1122 100644 --- a/lib/pages/routiens/models/gang_switches/two_gang_switch/two_gang_switch.dart +++ b/lib/pages/routines/models/gang_switches/two_gang_switch/two_gang_switch.dart @@ -1,5 +1,5 @@ -import 'package:syncrow_web/pages/routiens/models/gang_switches/base_switch_function.dart'; -import 'package:syncrow_web/pages/routiens/models/gang_switches/switch_operational_value.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/base_switch_function.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/switch_operational_value.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; class TwoGangSwitch1Function extends BaseSwitchFunction { @@ -49,8 +49,7 @@ class TwoGangSwitch2Function extends BaseSwitchFunction { } class TwoGangCountdown1Function extends BaseSwitchFunction { - TwoGangCountdown1Function( - {required super.deviceId, required super.deviceName}) + TwoGangCountdown1Function({required super.deviceId, required super.deviceName}) : super( code: 'countdown_1', operationName: 'Light 1 Countdown', @@ -71,8 +70,7 @@ class TwoGangCountdown1Function extends BaseSwitchFunction { } class TwoGangCountdown2Function extends BaseSwitchFunction { - TwoGangCountdown2Function( - {required super.deviceId, required super.deviceName}) + TwoGangCountdown2Function({required super.deviceId, required super.deviceName}) : super( code: 'countdown_2', operationName: 'Light 2 Countdown', diff --git a/lib/pages/routiens/models/icon_model.dart b/lib/pages/routines/models/icon_model.dart similarity index 100% rename from lib/pages/routiens/models/icon_model.dart rename to lib/pages/routines/models/icon_model.dart diff --git a/lib/pages/routiens/models/routine_details_model.dart b/lib/pages/routines/models/routine_details_model.dart similarity index 98% rename from lib/pages/routiens/models/routine_details_model.dart rename to lib/pages/routines/models/routine_details_model.dart index 8a4a1202..c42b4d36 100644 --- a/lib/pages/routiens/models/routine_details_model.dart +++ b/lib/pages/routines/models/routine_details_model.dart @@ -1,7 +1,7 @@ import 'dart:convert'; -import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart'; -import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_scene_model.dart'; +import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_automation_model.dart'; +import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_scene_model.dart'; class RoutineDetailsModel { final String spaceUuid; diff --git a/lib/pages/routiens/models/routine_item.dart b/lib/pages/routines/models/routine_item.dart similarity index 100% rename from lib/pages/routiens/models/routine_item.dart rename to lib/pages/routines/models/routine_item.dart diff --git a/lib/pages/routiens/models/routine_model.dart b/lib/pages/routines/models/routine_model.dart similarity index 100% rename from lib/pages/routiens/models/routine_model.dart rename to lib/pages/routines/models/routine_model.dart diff --git a/lib/pages/routiens/view/create_new_routine_view.dart b/lib/pages/routines/view/create_new_routine_view.dart similarity index 92% rename from lib/pages/routiens/view/create_new_routine_view.dart rename to lib/pages/routines/view/create_new_routine_view.dart index dedfada8..a2d5d892 100644 --- a/lib/pages/routiens/view/create_new_routine_view.dart +++ b/lib/pages/routines/view/create_new_routine_view.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:syncrow_web/pages/routiens/widgets/conditions_routines_devices_view.dart'; -import 'package:syncrow_web/pages/routiens/widgets/if_container.dart'; -import 'package:syncrow_web/pages/routiens/widgets/routine_search_and_buttons.dart'; -import 'package:syncrow_web/pages/routiens/widgets/then_container.dart'; +import 'package:syncrow_web/pages/routines/widgets/conditions_routines_devices_view.dart'; +import 'package:syncrow_web/pages/routines/widgets/if_container.dart'; +import 'package:syncrow_web/pages/routines/widgets/routine_search_and_buttons.dart'; +import 'package:syncrow_web/pages/routines/widgets/then_container.dart'; import 'package:syncrow_web/utils/color_manager.dart'; class CreateNewRoutineView extends StatelessWidget { @@ -68,7 +68,7 @@ class CreateNewRoutineView extends StatelessWidget { width: double.infinity, color: ColorsManager.dialogBlueTitle, ), - + /// THEN Container Expanded( child: Card( diff --git a/lib/pages/routiens/view/effective_period_view.dart b/lib/pages/routines/view/effective_period_view.dart similarity index 86% rename from lib/pages/routiens/view/effective_period_view.dart rename to lib/pages/routines/view/effective_period_view.dart index 5e6c33da..b54e4075 100644 --- a/lib/pages/routiens/view/effective_period_view.dart +++ b/lib/pages/routines/view/effective_period_view.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/effictive_period_dialog.dart'; -import 'package:syncrow_web/pages/routiens/widgets/period_option.dart'; -import 'package:syncrow_web/pages/routiens/widgets/repeat_days.dart'; +import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/effictive_period_dialog.dart'; +import 'package:syncrow_web/pages/routines/widgets/period_option.dart'; +import 'package:syncrow_web/pages/routines/widgets/repeat_days.dart'; import 'package:syncrow_web/utils/color_manager.dart'; class EffectivePeriodView extends StatelessWidget { diff --git a/lib/pages/routines/view/routines_view.dart b/lib/pages/routines/view/routines_view.dart new file mode 100644 index 00000000..f1befb05 --- /dev/null +++ b/lib/pages/routines/view/routines_view.dart @@ -0,0 +1,95 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/view/create_new_routine_view.dart'; +import 'package:syncrow_web/pages/routines/widgets/main_routine_view/fetch_routine_scenes_automation.dart'; +import 'package:syncrow_web/pages/routines/widgets/main_routine_view/routine_view_card.dart'; +import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart'; +import 'package:syncrow_web/pages/space_tree/view/side_spaces_view.dart'; +import 'package:syncrow_web/utils/color_manager.dart'; +import 'package:syncrow_web/utils/snack_bar.dart'; + +class RoutinesView extends StatefulWidget { + const RoutinesView({super.key}); + + @override + State createState() => _RoutinesViewState(); +} + +class _RoutinesViewState extends State { + @override + void initState() { + super.initState(); + context.read().add(FetchDevicesInRoutine()); + } + + @override + Widget build(BuildContext context) { + return BlocBuilder( + builder: (context, state) { + if (state.createRoutineView) { + return const CreateNewRoutineView(); + } + return Row( + children: [ + Expanded(child: SideSpacesView( + onSelectAction: (String communityId, String spaceId) { + context.read() + ..add(LoadScenes(spaceId, communityId)) + ..add(LoadAutomation(spaceId)); + }, + )), + Expanded( + flex: 3, + child: Padding( + padding: const EdgeInsets.all(16), + child: Row( + children: [ + Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text( + "Create New Routines", + style: Theme.of(context).textTheme.titleLarge?.copyWith( + color: ColorsManager.grayColor, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox( + height: 10, + ), + RoutineViewCard( + onTap: () { + if (context.read().selectedCommunityId.isNotEmpty && + context.read().selectedSpaceId.isNotEmpty) { + context.read().add( + (ResetRoutineState()), + ); + BlocProvider.of(context).add( + const CreateNewRoutineViewEvent(createRoutineView: true), + ); + } else { + CustomSnackBar.redSnackBar('Please select a space'); + } + }, + icon: Icons.add, + textString: '', + ), + const SizedBox( + height: 15, + ), + const Expanded(child: FetchRoutineScenesAutomation()), + ], + ), + ], + ), + ), + ), + ], + ); + }, + ); + } +} diff --git a/lib/pages/routiens/widgets/conditions_routines_devices_view.dart b/lib/pages/routines/widgets/conditions_routines_devices_view.dart similarity index 91% rename from lib/pages/routiens/widgets/conditions_routines_devices_view.dart rename to lib/pages/routines/widgets/conditions_routines_devices_view.dart index 5cc31bf3..3def44de 100644 --- a/lib/pages/routiens/widgets/conditions_routines_devices_view.dart +++ b/lib/pages/routines/widgets/conditions_routines_devices_view.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart'; -import 'package:syncrow_web/pages/routiens/widgets/routine_devices.dart'; -import 'package:syncrow_web/pages/routiens/widgets/routines_title_widget.dart'; -import 'package:syncrow_web/pages/routiens/widgets/scenes_and_automations.dart'; -import 'package:syncrow_web/pages/routiens/widgets/search_bar_condition_title.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/widgets/dragable_card.dart'; +import 'package:syncrow_web/pages/routines/widgets/routine_devices.dart'; +import 'package:syncrow_web/pages/routines/widgets/routines_title_widget.dart'; +import 'package:syncrow_web/pages/routines/widgets/scenes_and_automations.dart'; +import 'package:syncrow_web/pages/routines/widgets/search_bar_condition_title.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; class ConditionsRoutinesDevicesView extends StatelessWidget { diff --git a/lib/pages/routiens/widgets/delete_scene.dart b/lib/pages/routines/widgets/delete_scene.dart similarity index 97% rename from lib/pages/routiens/widgets/delete_scene.dart rename to lib/pages/routines/widgets/delete_scene.dart index d829696c..10eeb493 100644 --- a/lib/pages/routiens/widgets/delete_scene.dart +++ b/lib/pages/routines/widgets/delete_scene.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_web/pages/common/custom_dialog.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; import 'package:syncrow_web/utils/color_manager.dart'; class DeleteSceneWidget extends StatelessWidget { diff --git a/lib/pages/routiens/widgets/dialog_footer.dart b/lib/pages/routines/widgets/dialog_footer.dart similarity index 100% rename from lib/pages/routiens/widgets/dialog_footer.dart rename to lib/pages/routines/widgets/dialog_footer.dart diff --git a/lib/pages/routiens/widgets/dialog_header.dart b/lib/pages/routines/widgets/dialog_header.dart similarity index 100% rename from lib/pages/routiens/widgets/dialog_header.dart rename to lib/pages/routines/widgets/dialog_header.dart diff --git a/lib/pages/routiens/widgets/dragable_card.dart b/lib/pages/routines/widgets/dragable_card.dart similarity index 98% rename from lib/pages/routiens/widgets/dragable_card.dart rename to lib/pages/routines/widgets/dragable_card.dart index 56961892..bc6dae82 100644 --- a/lib/pages/routiens/widgets/dragable_card.dart +++ b/lib/pages/routines/widgets/dragable_card.dart @@ -3,8 +3,8 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/models/device_functions.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; diff --git a/lib/pages/routiens/widgets/if_container.dart b/lib/pages/routines/widgets/if_container.dart similarity index 68% rename from lib/pages/routiens/widgets/if_container.dart rename to lib/pages/routines/widgets/if_container.dart index 9c357a17..d1736240 100644 --- a/lib/pages/routiens/widgets/if_container.dart +++ b/lib/pages/routines/widgets/if_container.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/helper/dialog_helper/device_dialog_helper.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/helper/dialog_helper/device_dialog_helper.dart'; +import 'package:syncrow_web/pages/routines/widgets/dragable_card.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; @@ -26,9 +26,7 @@ class IfContainer extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - const Text('IF', - style: TextStyle( - fontSize: 18, fontWeight: FontWeight.bold)), + const Text('IF', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), if (state.isAutomation && state.ifItems.isNotEmpty) AutomationOperatorSelector( selectedOperator: state.selectedAutomationOperator), @@ -55,44 +53,34 @@ class IfContainer extends StatelessWidget { (index) => GestureDetector( onTap: () async { if (!state.isTabToRun) { - final result = await DeviceDialogHelper - .showDeviceDialog( - context, state.ifItems[index], - removeComparetors: false); + final result = await DeviceDialogHelper.showDeviceDialog( + context, state.ifItems[index], + removeComparetors: false); if (result != null) { - context.read().add( - AddToIfContainer( - state.ifItems[index], false)); - } else if (![ - 'AC', - '1G', - '2G', - '3G' - ].contains( - state.ifItems[index]['productType'])) { - context.read().add( - AddToIfContainer( - state.ifItems[index], false)); + context + .read() + .add(AddToIfContainer(state.ifItems[index], false)); + } else if (!['AC', '1G', '2G', '3G'] + .contains(state.ifItems[index]['productType'])) { + context + .read() + .add(AddToIfContainer(state.ifItems[index], false)); } } }, child: DraggableCard( - imagePath: - state.ifItems[index]['imagePath'] ?? '', + imagePath: state.ifItems[index]['imagePath'] ?? '', title: state.ifItems[index]['title'] ?? '', deviceData: state.ifItems[index], - padding: const EdgeInsets.symmetric( - horizontal: 4, vertical: 8), + padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8), isFromThen: false, isFromIf: true, onRemove: () { - context.read().add( - RemoveDragCard( - index: index, - isFromThen: false, - key: state.ifItems[index] - ['uniqueCustomId'])); + context.read().add(RemoveDragCard( + index: index, + isFromThen: false, + key: state.ifItems[index]['uniqueCustomId'])); }, ), )), @@ -113,23 +101,15 @@ class IfContainer extends StatelessWidget { if (!state.isTabToRun) { if (mutableData['deviceId'] == 'tab_to_run') { - context - .read() - .add(AddToIfContainer(mutableData, true)); + context.read().add(AddToIfContainer(mutableData, true)); } else { - final result = await DeviceDialogHelper.showDeviceDialog( - context, mutableData, + final result = await DeviceDialogHelper.showDeviceDialog(context, mutableData, removeComparetors: false); if (result != null) { - context - .read() - .add(AddToIfContainer(mutableData, false)); - } else if (!['AC', '1G', '2G', '3G'] - .contains(mutableData['productType'])) { - context - .read() - .add(AddToIfContainer(mutableData, false)); + context.read().add(AddToIfContainer(mutableData, false)); + } else if (!['AC', '1G', '2G', '3G'].contains(mutableData['productType'])) { + context.read().add(AddToIfContainer(mutableData, false)); } } } @@ -175,9 +155,7 @@ class AutomationOperatorSelector extends StatelessWidget { ), ), onPressed: () { - context - .read() - .add(const ChangeAutomationOperator(operator: 'or')); + context.read().add(const ChangeAutomationOperator(operator: 'or')); }, ), Container( @@ -203,9 +181,7 @@ class AutomationOperatorSelector extends StatelessWidget { ), ), onPressed: () { - context - .read() - .add(const ChangeAutomationOperator(operator: 'and')); + context.read().add(const ChangeAutomationOperator(operator: 'and')); }, ), ], diff --git a/lib/pages/routines/widgets/main_routine_view/fetch_routine_scenes_automation.dart b/lib/pages/routines/widgets/main_routine_view/fetch_routine_scenes_automation.dart new file mode 100644 index 00000000..ed2a9405 --- /dev/null +++ b/lib/pages/routines/widgets/main_routine_view/fetch_routine_scenes_automation.dart @@ -0,0 +1,143 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/widgets/main_routine_view/routine_view_card.dart'; +import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart'; +import 'package:syncrow_web/utils/color_manager.dart'; +import 'package:syncrow_web/utils/constants/assets.dart'; +import 'package:syncrow_web/utils/extension/build_context_x.dart'; +import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; + +class FetchRoutineScenesAutomation extends StatefulWidget { + const FetchRoutineScenesAutomation({super.key}); + + @override + State createState() => _FetchRoutineScenesState(); +} + +class _FetchRoutineScenesState extends State + with HelperResponsiveLayout { + @override + void initState() { + super.initState(); + context.read() + ..add(LoadScenes(context.read().selectedSpaceId, + context.read().selectedCommunityId)) + ..add(LoadAutomation(context.read().selectedSpaceId)); + } + + @override + Widget build(BuildContext context) { + return BlocBuilder( + builder: (context, state) { + return state.isLoading + ? const Center( + child: CircularProgressIndicator(), + ) + : Padding( + padding: const EdgeInsets.symmetric(vertical: 16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + "Scenes (Tab to Run)", + style: Theme.of(context).textTheme.titleLarge?.copyWith( + color: ColorsManager.grayColor, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 10), + if (state.scenes.isEmpty) + Text( + "No scenes found", + style: context.textTheme.bodyMedium?.copyWith( + color: ColorsManager.grayColor, + ), + ), + if (state.scenes.isNotEmpty) + ConstrainedBox( + constraints: BoxConstraints( + maxHeight: isSmallScreenSize(context) ? 160 : 170, + maxWidth: MediaQuery.sizeOf(context).width * 0.7), + child: ListView.builder( + scrollDirection: Axis.horizontal, + itemCount: state.scenes.length, + itemBuilder: (context, index) => Padding( + padding: EdgeInsets.only( + right: isSmallScreenSize(context) ? 4.0 : 8.0, + ), + child: RoutineViewCard( + onTap: () { + BlocProvider.of(context).add( + const CreateNewRoutineViewEvent(createRoutineView: true), + ); + context.read().add( + GetSceneDetails( + sceneId: state.scenes[index].id, + isTabToRun: true, + isUpdate: true, + ), + ); + }, + textString: state.scenes[index].name, + icon: state.scenes[index].icon ?? Assets.logoHorizontal, + isFromScenes: true, + iconInBytes: state.scenes[index].iconInBytes, + ), + ), + ), + ), + const SizedBox(height: 15), + Text( + "Automations", + style: Theme.of(context).textTheme.titleLarge?.copyWith( + color: ColorsManager.grayColor, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 10), + if (state.automations.isEmpty) + Text( + "No automations found", + style: context.textTheme.bodyMedium?.copyWith( + color: ColorsManager.grayColor, + ), + ), + if (state.automations.isNotEmpty) + ConstrainedBox( + constraints: BoxConstraints( + maxHeight: isSmallScreenSize(context) ? 160 : 170, + maxWidth: MediaQuery.sizeOf(context).width * 0.7), + child: ListView.builder( + scrollDirection: Axis.horizontal, + itemCount: state.automations.length, + itemBuilder: (context, index) => Padding( + padding: EdgeInsets.only( + right: isSmallScreenSize(context) ? 4.0 : 8.0, + ), + child: RoutineViewCard( + onTap: () { + BlocProvider.of(context).add( + const CreateNewRoutineViewEvent(createRoutineView: true), + ); + context.read().add( + GetAutomationDetails( + automationId: state.automations[index].id, + isAutomation: true, + isUpdate: true), + ); + }, + textString: state.automations[index].name, + icon: state.automations[index].icon ?? Assets.automation, + ), + ), + ), + ), + ], + ), + ); + }, + ); + } +} diff --git a/lib/pages/routiens/widgets/main_routine_view/routine_view_card.dart b/lib/pages/routines/widgets/main_routine_view/routine_view_card.dart similarity index 96% rename from lib/pages/routiens/widgets/main_routine_view/routine_view_card.dart rename to lib/pages/routines/widgets/main_routine_view/routine_view_card.dart index 7e446507..f8a2e358 100644 --- a/lib/pages/routiens/widgets/main_routine_view/routine_view_card.dart +++ b/lib/pages/routines/widgets/main_routine_view/routine_view_card.dart @@ -70,15 +70,13 @@ class RoutineViewCard extends StatelessWidget with HelperResponsiveLayout { height: iconSize, width: iconSize, child: (isFromScenes ?? false) - ? (iconInBytes != null && - iconInBytes?.isNotEmpty == true) + ? (iconInBytes != null && iconInBytes?.isNotEmpty == true) ? Image.memory( iconInBytes!, height: iconSize, width: iconSize, fit: BoxFit.contain, - errorBuilder: (context, error, stackTrace) => - Image.asset( + errorBuilder: (context, error, stackTrace) => Image.asset( Assets.logo, height: iconSize, width: iconSize, diff --git a/lib/pages/routiens/widgets/period_option.dart b/lib/pages/routines/widgets/period_option.dart similarity index 93% rename from lib/pages/routiens/widgets/period_option.dart rename to lib/pages/routines/widgets/period_option.dart index 1871ebda..09ec590e 100644 --- a/lib/pages/routiens/widgets/period_option.dart +++ b/lib/pages/routines/widgets/period_option.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_event.dart'; -import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_state.dart'; -import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/effictive_period_dialog.dart'; +import 'package:syncrow_web/pages/routines/bloc/effective_period/effect_period_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/effective_period/effect_period_event.dart'; +import 'package:syncrow_web/pages/routines/bloc/effective_period/effect_period_state.dart'; +import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/effictive_period_dialog.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/constants/app_enum.dart'; diff --git a/lib/pages/routiens/widgets/repeat_days.dart b/lib/pages/routines/widgets/repeat_days.dart similarity index 94% rename from lib/pages/routiens/widgets/repeat_days.dart rename to lib/pages/routines/widgets/repeat_days.dart index 8ee92367..4920408a 100644 --- a/lib/pages/routiens/widgets/repeat_days.dart +++ b/lib/pages/routines/widgets/repeat_days.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_event.dart'; -import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_state.dart'; +import 'package:syncrow_web/pages/routines/bloc/effective_period/effect_period_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/effective_period/effect_period_event.dart'; +import 'package:syncrow_web/pages/routines/bloc/effective_period/effect_period_state.dart'; import 'package:syncrow_web/utils/color_manager.dart'; class RepeatDays extends StatelessWidget { diff --git a/lib/pages/routiens/widgets/routine_devices.dart b/lib/pages/routines/widgets/routine_devices.dart similarity index 90% rename from lib/pages/routiens/widgets/routine_devices.dart rename to lib/pages/routines/widgets/routine_devices.dart index 63386b72..3515cc70 100644 --- a/lib/pages/routiens/widgets/routine_devices.dart +++ b/lib/pages/routines/widgets/routine_devices.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/widgets/dragable_card.dart'; class RoutineDevices extends StatelessWidget { const RoutineDevices({super.key}); @@ -35,9 +35,7 @@ class RoutineDevices extends StatelessWidget { children: deviceList.asMap().entries.map((entry) { final device = entry.value; if (state.searchText != null && state.searchText!.isNotEmpty) { - return device.name! - .toLowerCase() - .contains(state.searchText!.toLowerCase()) + return device.name!.toLowerCase().contains(state.searchText!.toLowerCase()) ? DraggableCard( imagePath: device.getDefaultIcon(device.productType), title: device.name ?? '', diff --git a/lib/pages/routiens/widgets/routine_dialogs/ac_dialog.dart b/lib/pages/routines/widgets/routine_dialogs/ac_dialog.dart similarity index 96% rename from lib/pages/routiens/widgets/routine_dialogs/ac_dialog.dart rename to lib/pages/routines/widgets/routine_dialogs/ac_dialog.dart index 7a630448..5f28e539 100644 --- a/lib/pages/routiens/widgets/routine_dialogs/ac_dialog.dart +++ b/lib/pages/routines/widgets/routine_dialogs/ac_dialog.dart @@ -1,16 +1,16 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/models/ac/ac_function.dart'; -import 'package:syncrow_web/pages/routiens/models/ac/ac_operational_value.dart'; -import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/models/ac/ac_function.dart'; +import 'package:syncrow_web/pages/routines/models/ac/ac_operational_value.dart'; +import 'package:syncrow_web/pages/routines/models/device_functions.dart'; +import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart'; +import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/functions_bloc/functions_bloc_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart'; class ACHelper { static Future?> showACFunctionsDialog( diff --git a/lib/pages/routiens/widgets/routine_dialogs/automation_dialog.dart b/lib/pages/routines/widgets/routine_dialogs/automation_dialog.dart similarity index 87% rename from lib/pages/routiens/widgets/routine_dialogs/automation_dialog.dart rename to lib/pages/routines/widgets/routine_dialogs/automation_dialog.dart index 84ed8fdd..3c1eb1c2 100644 --- a/lib/pages/routiens/widgets/routine_dialogs/automation_dialog.dart +++ b/lib/pages/routines/widgets/routine_dialogs/automation_dialog.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/models/device_functions.dart'; +import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart'; +import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; class AutomationDialog extends StatefulWidget { @@ -31,10 +31,8 @@ class _AutomationDialogState extends State { @override void initState() { super.initState(); - List? functions = context - .read() - .state - .selectedFunctions[widget.uniqueCustomId]; + List? functions = + context.read().state.selectedFunctions[widget.uniqueCustomId]; for (DeviceFunctionData data in functions ?? []) { if (data.entityId == widget.automationId) { selectedAutomationActionExecutor = data.value; @@ -67,8 +65,7 @@ class _AutomationDialogState extends State { }), ), ListTile( - leading: - SvgPicture.asset(Assets.acPowerOff, width: 24, height: 24), + leading: SvgPicture.asset(Assets.acPowerOff, width: 24, height: 24), title: const Text('Disable'), trailing: Radio( value: 'rule_disable', diff --git a/lib/pages/routiens/widgets/routine_dialogs/delay_dialog.dart b/lib/pages/routines/widgets/routine_dialogs/delay_dialog.dart similarity index 91% rename from lib/pages/routiens/widgets/routine_dialogs/delay_dialog.dart rename to lib/pages/routines/widgets/routine_dialogs/delay_dialog.dart index 6195a931..4580f6e1 100644 --- a/lib/pages/routiens/widgets/routine_dialogs/delay_dialog.dart +++ b/lib/pages/routines/widgets/routine_dialogs/delay_dialog.dart @@ -1,10 +1,10 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/models/device_functions.dart'; +import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart'; +import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart'; class DelayHelper { static Future?> showDelayPickerDialog( diff --git a/lib/pages/routiens/widgets/routine_dialogs/discard_dialog.dart b/lib/pages/routines/widgets/routine_dialogs/discard_dialog.dart similarity index 97% rename from lib/pages/routiens/widgets/routine_dialogs/discard_dialog.dart rename to lib/pages/routines/widgets/routine_dialogs/discard_dialog.dart index 7897faf6..40036d32 100644 --- a/lib/pages/routiens/widgets/routine_dialogs/discard_dialog.dart +++ b/lib/pages/routines/widgets/routine_dialogs/discard_dialog.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; diff --git a/lib/pages/routiens/widgets/routine_dialogs/effictive_period_dialog.dart b/lib/pages/routines/widgets/routine_dialogs/effictive_period_dialog.dart similarity index 97% rename from lib/pages/routiens/widgets/routine_dialogs/effictive_period_dialog.dart rename to lib/pages/routines/widgets/routine_dialogs/effictive_period_dialog.dart index 70a6776d..5fc31a96 100644 --- a/lib/pages/routiens/widgets/routine_dialogs/effictive_period_dialog.dart +++ b/lib/pages/routines/widgets/routine_dialogs/effictive_period_dialog.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_event.dart'; +import 'package:syncrow_web/pages/routines/bloc/effective_period/effect_period_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/effective_period/effect_period_event.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/constants/app_enum.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; diff --git a/lib/pages/routiens/widgets/routine_dialogs/one_gang_switch_dialog.dart b/lib/pages/routines/widgets/routine_dialogs/one_gang_switch_dialog.dart similarity index 86% rename from lib/pages/routiens/widgets/routine_dialogs/one_gang_switch_dialog.dart rename to lib/pages/routines/widgets/routine_dialogs/one_gang_switch_dialog.dart index e7d7209f..adccb33d 100644 --- a/lib/pages/routiens/widgets/routine_dialogs/one_gang_switch_dialog.dart +++ b/lib/pages/routines/widgets/routine_dialogs/one_gang_switch_dialog.dart @@ -2,14 +2,14 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart'; -import 'package:syncrow_web/pages/routiens/bloc/functions_bloc/functions_bloc_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/helper/duration_format_helper.dart'; -import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; -import 'package:syncrow_web/pages/routiens/models/gang_switches/base_switch_function.dart'; -import 'package:syncrow_web/pages/routiens/models/gang_switches/switch_operational_value.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart'; +import 'package:syncrow_web/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/helper/duration_format_helper.dart'; +import 'package:syncrow_web/pages/routines/models/device_functions.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/base_switch_function.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/switch_operational_value.dart'; +import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart'; +import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; @@ -22,23 +22,21 @@ class OneGangSwitchHelper { String uniqueCustomId, bool removeComparetors, ) async { - List acFunctions = - functions.whereType().toList(); + List acFunctions = functions.whereType().toList(); return showDialog?>( context: context, builder: (BuildContext context) { return BlocProvider( - create: (_) => FunctionBloc() - ..add(InitializeFunctions(deviceSelectedFunctions ?? [])), + create: (_) => FunctionBloc()..add(InitializeFunctions(deviceSelectedFunctions ?? [])), child: AlertDialog( contentPadding: EdgeInsets.zero, content: BlocBuilder( builder: (context, state) { final selectedFunction = state.selectedFunction; final selectedOperationName = state.selectedOperationName; - final selectedFunctionData = state.addedFunctions - .firstWhere((f) => f.functionCode == selectedFunction, + final selectedFunctionData = + state.addedFunctions.firstWhere((f) => f.functionCode == selectedFunction, orElse: () => DeviceFunctionData( entityId: '', functionCode: selectedFunction ?? '', @@ -85,12 +83,9 @@ class OneGangSwitchHelper { color: ColorsManager.textGray, ), onTap: () { - context - .read() - .add(SelectFunction( + context.read().add(SelectFunction( functionCode: function.code, - operationName: - function.operationName, + operationName: function.operationName, )); }, ); @@ -180,8 +175,7 @@ class OneGangSwitchHelper { ); } - final selectedFn = - acFunctions.firstWhere((f) => f.code == selectedFunction); + final selectedFn = acFunctions.firstWhere((f) => f.code == selectedFunction); final values = selectedFn.getOperationalValues(); return _buildOperationalValuesList( @@ -218,11 +212,11 @@ class OneGangSwitchHelper { selectedFunctionData, ), const SizedBox(height: 20), - _buildCountDownDisplay(context, initialValue, device, operationName, - selectedFunctionData, selectCode), + _buildCountDownDisplay( + context, initialValue, device, operationName, selectedFunctionData, selectCode), const SizedBox(height: 20), - _buildCountDownSlider(context, initialValue, device, operationName, - selectedFunctionData, selectCode), + _buildCountDownSlider( + context, initialValue, device, operationName, selectedFunctionData, selectCode), ], ); } @@ -263,8 +257,7 @@ class OneGangSwitchHelper { minHeight: 40.0, minWidth: 40.0, ), - isSelected: - conditions.map((c) => c == (currentCondition ?? "==")).toList(), + isSelected: conditions.map((c) => c == (currentCondition ?? "==")).toList(), children: conditions.map((c) => Text(c)).toList(), ); } @@ -312,8 +305,7 @@ class OneGangSwitchHelper { value: (initialValue ?? 0).toDouble(), min: operationalValues.minValue?.toDouble() ?? 0.0, max: operationalValues.maxValue?.toDouble() ?? 0.0, - divisions: (((operationalValues.maxValue ?? 0) - - (operationalValues.minValue ?? 0)) / + divisions: (((operationalValues.maxValue ?? 0) - (operationalValues.minValue ?? 0)) / (operationalValues.stepValue ?? 1)) .round(), onChanged: (value) { @@ -365,13 +357,9 @@ class OneGangSwitchHelper { style: context.textTheme.bodyMedium, ), trailing: Icon( - isSelected - ? Icons.radio_button_checked - : Icons.radio_button_unchecked, + isSelected ? Icons.radio_button_checked : Icons.radio_button_unchecked, size: 24, - color: isSelected - ? ColorsManager.primaryColorWithOpacity - : ColorsManager.textGray, + color: isSelected ? ColorsManager.primaryColorWithOpacity : ColorsManager.textGray, ), onTap: () { if (!isSelected) { @@ -383,8 +371,7 @@ class OneGangSwitchHelper { operationName: operationName, value: value.value, condition: selectedFunctionData?.condition, - valueDescription: - selectedFunctionData?.valueDescription, + valueDescription: selectedFunctionData?.valueDescription, ), ), ); diff --git a/lib/pages/routiens/widgets/routine_dialogs/setting_dialog.dart b/lib/pages/routines/widgets/routine_dialogs/setting_dialog.dart similarity index 97% rename from lib/pages/routiens/widgets/routine_dialogs/setting_dialog.dart rename to lib/pages/routines/widgets/routine_dialogs/setting_dialog.dart index aa4a407b..b8449838 100644 --- a/lib/pages/routiens/widgets/routine_dialogs/setting_dialog.dart +++ b/lib/pages/routines/widgets/routine_dialogs/setting_dialog.dart @@ -1,17 +1,17 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_event.dart'; -import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_state.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/setting_bloc/setting_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/setting_bloc/setting_event.dart'; -import 'package:syncrow_web/pages/routiens/bloc/setting_bloc/setting_state.dart'; -import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart'; -import 'package:syncrow_web/pages/routiens/models/icon_model.dart'; -import 'package:syncrow_web/pages/routiens/view/effective_period_view.dart'; -import 'package:syncrow_web/pages/routiens/widgets/delete_scene.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart'; +import 'package:syncrow_web/pages/routines/bloc/effective_period/effect_period_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/effective_period/effect_period_event.dart'; +import 'package:syncrow_web/pages/routines/bloc/effective_period/effect_period_state.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/setting_bloc/setting_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/setting_bloc/setting_event.dart'; +import 'package:syncrow_web/pages/routines/bloc/setting_bloc/setting_state.dart'; +import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_automation_model.dart'; +import 'package:syncrow_web/pages/routines/models/icon_model.dart'; +import 'package:syncrow_web/pages/routines/view/effective_period_view.dart'; +import 'package:syncrow_web/pages/routines/widgets/delete_scene.dart'; +import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:flutter/cupertino.dart'; diff --git a/lib/pages/routiens/widgets/routine_dialogs/three_gang_switch_dialog.dart b/lib/pages/routines/widgets/routine_dialogs/three_gang_switch_dialog.dart similarity index 86% rename from lib/pages/routiens/widgets/routine_dialogs/three_gang_switch_dialog.dart rename to lib/pages/routines/widgets/routine_dialogs/three_gang_switch_dialog.dart index bb23ece4..f565f07d 100644 --- a/lib/pages/routiens/widgets/routine_dialogs/three_gang_switch_dialog.dart +++ b/lib/pages/routines/widgets/routine_dialogs/three_gang_switch_dialog.dart @@ -2,14 +2,14 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart'; -import 'package:syncrow_web/pages/routiens/bloc/functions_bloc/functions_bloc_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/helper/duration_format_helper.dart'; -import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; -import 'package:syncrow_web/pages/routiens/models/gang_switches/base_switch_function.dart'; -import 'package:syncrow_web/pages/routiens/models/gang_switches/switch_operational_value.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart'; +import 'package:syncrow_web/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/helper/duration_format_helper.dart'; +import 'package:syncrow_web/pages/routines/models/device_functions.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/base_switch_function.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/switch_operational_value.dart'; +import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart'; +import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; @@ -22,23 +22,21 @@ class ThreeGangSwitchHelper { String uniqueCustomId, bool removeComparetors, ) async { - List switchFunctions = - functions.whereType().toList(); + List switchFunctions = functions.whereType().toList(); return showDialog?>( context: context, builder: (BuildContext context) { return BlocProvider( - create: (_) => FunctionBloc() - ..add(InitializeFunctions(deviceSelectedFunctions ?? [])), + create: (_) => FunctionBloc()..add(InitializeFunctions(deviceSelectedFunctions ?? [])), child: AlertDialog( contentPadding: EdgeInsets.zero, content: BlocBuilder( builder: (context, state) { final selectedFunction = state.selectedFunction; final selectedOperationName = state.selectedOperationName; - final selectedFunctionData = state.addedFunctions - .firstWhere((f) => f.functionCode == selectedFunction, + final selectedFunctionData = + state.addedFunctions.firstWhere((f) => f.functionCode == selectedFunction, orElse: () => DeviceFunctionData( entityId: '', functionCode: selectedFunction ?? '', @@ -85,12 +83,9 @@ class ThreeGangSwitchHelper { color: ColorsManager.textGray, ), onTap: () { - context - .read() - .add(SelectFunction( + context.read().add(SelectFunction( functionCode: function.code, - operationName: - function.operationName, + operationName: function.operationName, )); }, ); @@ -182,8 +177,7 @@ class ThreeGangSwitchHelper { ); } - final selectedFn = - switchFunctions.firstWhere((f) => f.code == selectedFunction); + final selectedFn = switchFunctions.firstWhere((f) => f.code == selectedFunction); final values = selectedFn.getOperationalValues(); return _buildOperationalValuesList( @@ -220,11 +214,11 @@ class ThreeGangSwitchHelper { selectedFunctionData, ), const SizedBox(height: 20), - _buildCountDownDisplay(context, initialValue, device, operationName, - selectedFunctionData, selectCode), + _buildCountDownDisplay( + context, initialValue, device, operationName, selectedFunctionData, selectCode), const SizedBox(height: 20), - _buildCountDownSlider(context, initialValue, device, operationName, - selectedFunctionData, selectCode), + _buildCountDownSlider( + context, initialValue, device, operationName, selectedFunctionData, selectCode), ], ); } @@ -265,8 +259,7 @@ class ThreeGangSwitchHelper { minHeight: 40.0, minWidth: 40.0, ), - isSelected: - conditions.map((c) => c == (currentCondition ?? "==")).toList(), + isSelected: conditions.map((c) => c == (currentCondition ?? "==")).toList(), children: conditions.map((c) => Text(c)).toList(), ); } @@ -314,8 +307,7 @@ class ThreeGangSwitchHelper { value: (initialValue ?? 0).toDouble(), min: operationalValues.minValue?.toDouble() ?? 0.0, max: operationalValues.maxValue?.toDouble() ?? 0.0, - divisions: (((operationalValues.maxValue ?? 0) - - (operationalValues.minValue ?? 0)) / + divisions: (((operationalValues.maxValue ?? 0) - (operationalValues.minValue ?? 0)) / (operationalValues.stepValue ?? 1)) .round(), onChanged: (value) { @@ -367,13 +359,9 @@ class ThreeGangSwitchHelper { style: context.textTheme.bodyMedium, ), trailing: Icon( - isSelected - ? Icons.radio_button_checked - : Icons.radio_button_unchecked, + isSelected ? Icons.radio_button_checked : Icons.radio_button_unchecked, size: 24, - color: isSelected - ? ColorsManager.primaryColorWithOpacity - : ColorsManager.textGray, + color: isSelected ? ColorsManager.primaryColorWithOpacity : ColorsManager.textGray, ), onTap: () { if (!isSelected) { @@ -385,8 +373,7 @@ class ThreeGangSwitchHelper { operationName: operationName, value: value.value, condition: selectedFunctionData?.condition, - valueDescription: - selectedFunctionData?.valueDescription, + valueDescription: selectedFunctionData?.valueDescription, ), ), ); diff --git a/lib/pages/routiens/widgets/routine_dialogs/two_gang_switch_dialog.dart b/lib/pages/routines/widgets/routine_dialogs/two_gang_switch_dialog.dart similarity index 86% rename from lib/pages/routiens/widgets/routine_dialogs/two_gang_switch_dialog.dart rename to lib/pages/routines/widgets/routine_dialogs/two_gang_switch_dialog.dart index f2a0ebd0..c894f65c 100644 --- a/lib/pages/routiens/widgets/routine_dialogs/two_gang_switch_dialog.dart +++ b/lib/pages/routines/widgets/routine_dialogs/two_gang_switch_dialog.dart @@ -2,14 +2,14 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart'; -import 'package:syncrow_web/pages/routiens/bloc/functions_bloc/functions_bloc_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/helper/duration_format_helper.dart'; -import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; -import 'package:syncrow_web/pages/routiens/models/gang_switches/base_switch_function.dart'; -import 'package:syncrow_web/pages/routiens/models/gang_switches/switch_operational_value.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart'; +import 'package:syncrow_web/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/helper/duration_format_helper.dart'; +import 'package:syncrow_web/pages/routines/models/device_functions.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/base_switch_function.dart'; +import 'package:syncrow_web/pages/routines/models/gang_switches/switch_operational_value.dart'; +import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart'; +import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; @@ -22,23 +22,21 @@ class TwoGangSwitchHelper { String uniqueCustomId, bool removeComparetors, ) async { - List switchFunctions = - functions.whereType().toList(); + List switchFunctions = functions.whereType().toList(); return showDialog?>( context: context, builder: (BuildContext context) { return BlocProvider( - create: (_) => FunctionBloc() - ..add(InitializeFunctions(deviceSelectedFunctions ?? [])), + create: (_) => FunctionBloc()..add(InitializeFunctions(deviceSelectedFunctions ?? [])), child: AlertDialog( contentPadding: EdgeInsets.zero, content: BlocBuilder( builder: (context, state) { final selectedFunction = state.selectedFunction; final selectedOperationName = state.selectedOperationName; - final selectedFunctionData = state.addedFunctions - .firstWhere((f) => f.functionCode == selectedFunction, + final selectedFunctionData = + state.addedFunctions.firstWhere((f) => f.functionCode == selectedFunction, orElse: () => DeviceFunctionData( entityId: '', functionCode: selectedFunction ?? '', @@ -85,12 +83,9 @@ class TwoGangSwitchHelper { color: ColorsManager.textGray, ), onTap: () { - context - .read() - .add(SelectFunction( + context.read().add(SelectFunction( functionCode: function.code, - operationName: - function.operationName, + operationName: function.operationName, )); }, ); @@ -166,8 +161,7 @@ class TwoGangSwitchHelper { required String operationName, required bool removeComparetors, }) { - if (selectedFunction == 'countdown_1' || - selectedFunction == 'countdown_2') { + if (selectedFunction == 'countdown_1' || selectedFunction == 'countdown_2') { final initialValue = selectedFunctionData?.value ?? 200; return _buildTemperatureSelector( context: context, @@ -181,8 +175,7 @@ class TwoGangSwitchHelper { ); } - final selectedFn = - switchFunctions.firstWhere((f) => f.code == selectedFunction); + final selectedFn = switchFunctions.firstWhere((f) => f.code == selectedFunction); final values = selectedFn.getOperationalValues(); return _buildOperationalValuesList( @@ -219,11 +212,11 @@ class TwoGangSwitchHelper { selectedFunctionData, ), const SizedBox(height: 20), - _buildCountDownDisplay(context, initialValue, device, operationName, - selectedFunctionData, selectCode), + _buildCountDownDisplay( + context, initialValue, device, operationName, selectedFunctionData, selectCode), const SizedBox(height: 20), - _buildCountDownSlider(context, initialValue, device, operationName, - selectedFunctionData, selectCode), + _buildCountDownSlider( + context, initialValue, device, operationName, selectedFunctionData, selectCode), ], ); } @@ -264,8 +257,7 @@ class TwoGangSwitchHelper { minHeight: 40.0, minWidth: 40.0, ), - isSelected: - conditions.map((c) => c == (currentCondition ?? "==")).toList(), + isSelected: conditions.map((c) => c == (currentCondition ?? "==")).toList(), children: conditions.map((c) => Text(c)).toList(), ); } @@ -313,8 +305,7 @@ class TwoGangSwitchHelper { value: (initialValue ?? 0).toDouble(), min: operationalValues.minValue?.toDouble() ?? 0.0, max: operationalValues.maxValue?.toDouble() ?? 0.0, - divisions: (((operationalValues.maxValue ?? 0) - - (operationalValues.minValue ?? 0)) / + divisions: (((operationalValues.maxValue ?? 0) - (operationalValues.minValue ?? 0)) / (operationalValues.stepValue ?? 1)) .round(), onChanged: (value) { @@ -366,13 +357,9 @@ class TwoGangSwitchHelper { style: context.textTheme.bodyMedium, ), trailing: Icon( - isSelected - ? Icons.radio_button_checked - : Icons.radio_button_unchecked, + isSelected ? Icons.radio_button_checked : Icons.radio_button_unchecked, size: 24, - color: isSelected - ? ColorsManager.primaryColorWithOpacity - : ColorsManager.textGray, + color: isSelected ? ColorsManager.primaryColorWithOpacity : ColorsManager.textGray, ), onTap: () { if (!isSelected) { @@ -384,8 +371,7 @@ class TwoGangSwitchHelper { operationName: operationName, value: value.value, condition: selectedFunctionData?.condition, - valueDescription: - selectedFunctionData?.valueDescription, + valueDescription: selectedFunctionData?.valueDescription, ), ), ); diff --git a/lib/pages/routiens/widgets/routine_search_and_buttons.dart b/lib/pages/routines/widgets/routine_search_and_buttons.dart similarity index 98% rename from lib/pages/routiens/widgets/routine_search_and_buttons.dart rename to lib/pages/routines/widgets/routine_search_and_buttons.dart index f10694b6..efeedf9d 100644 --- a/lib/pages/routiens/widgets/routine_search_and_buttons.dart +++ b/lib/pages/routines/widgets/routine_search_and_buttons.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_web/pages/common/buttons/default_button.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/helper/save_routine_helper.dart'; -import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/discard_dialog.dart'; -import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/setting_dialog.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/helper/save_routine_helper.dart'; +import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/discard_dialog.dart'; +import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/setting_dialog.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; import 'package:syncrow_web/utils/style.dart'; diff --git a/lib/pages/routiens/widgets/routines_title_widget.dart b/lib/pages/routines/widgets/routines_title_widget.dart similarity index 100% rename from lib/pages/routiens/widgets/routines_title_widget.dart rename to lib/pages/routines/widgets/routines_title_widget.dart diff --git a/lib/pages/routiens/widgets/scenes_and_automations.dart b/lib/pages/routines/widgets/scenes_and_automations.dart similarity index 80% rename from lib/pages/routiens/widgets/scenes_and_automations.dart rename to lib/pages/routines/widgets/scenes_and_automations.dart index a0bd1ed6..2e268b1c 100644 --- a/lib/pages/routiens/widgets/scenes_and_automations.dart +++ b/lib/pages/routines/widgets/scenes_and_automations.dart @@ -1,7 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/widgets/dragable_card.dart'; +import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; class ScenesAndAutomations extends StatefulWidget { @@ -18,8 +19,9 @@ class _ScenesAndAutomationsState extends State { void initState() { super.initState(); context.read() - ..add(const LoadScenes(spaceId, communityId)) - ..add(const LoadAutomation(spaceId)); + ..add(LoadScenes(context.read().selectedSpaceId, + context.read().selectedCommunityId)) + ..add(LoadAutomation(context.read().selectedSpaceId)); } @override @@ -34,9 +36,7 @@ class _ScenesAndAutomationsState extends State { children: scenes.asMap().entries.map((entry) { final scene = entry.value; if (state.searchText != null && state.searchText!.isNotEmpty) { - return scene.name - .toLowerCase() - .contains(state.searchText!.toLowerCase()) + return scene.name.toLowerCase().contains(state.searchText!.toLowerCase()) ? DraggableCard( imagePath: scene.icon ?? Assets.loginLogo, title: scene.name, diff --git a/lib/pages/routiens/widgets/search_bar_condition_title.dart b/lib/pages/routines/widgets/search_bar_condition_title.dart similarity index 95% rename from lib/pages/routiens/widgets/search_bar_condition_title.dart rename to lib/pages/routines/widgets/search_bar_condition_title.dart index c009f040..9ffcbf63 100644 --- a/lib/pages/routiens/widgets/search_bar_condition_title.dart +++ b/lib/pages/routines/widgets/search_bar_condition_title.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_web/pages/common/text_field/custom_text_field.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/widgets/routines_title_widget.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/widgets/routines_title_widget.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; diff --git a/lib/pages/routiens/widgets/then_container.dart b/lib/pages/routines/widgets/then_container.dart similarity index 96% rename from lib/pages/routiens/widgets/then_container.dart rename to lib/pages/routines/widgets/then_container.dart index 4746561a..2fcc62b8 100644 --- a/lib/pages/routiens/widgets/then_container.dart +++ b/lib/pages/routines/widgets/then_container.dart @@ -2,11 +2,11 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/automation_dialog.dart'; -import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/delay_dialog.dart'; -import 'package:syncrow_web/pages/routiens/helper/dialog_helper/device_dialog_helper.dart'; -import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/automation_dialog.dart'; +import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/delay_dialog.dart'; +import 'package:syncrow_web/pages/routines/helper/dialog_helper/device_dialog_helper.dart'; +import 'package:syncrow_web/pages/routines/widgets/dragable_card.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; import 'package:uuid/uuid.dart'; diff --git a/lib/pages/space_tree/bloc/space_tree_bloc.dart b/lib/pages/space_tree/bloc/space_tree_bloc.dart new file mode 100644 index 00000000..41b0d6b0 --- /dev/null +++ b/lib/pages/space_tree/bloc/space_tree_bloc.dart @@ -0,0 +1,69 @@ +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart'; +import 'package:syncrow_web/pages/space_tree/bloc/space_tree_state.dart'; +import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart'; +import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart'; +import 'package:syncrow_web/services/space_mana_api.dart'; + +class SpaceTreeBloc extends Bloc { + String selectedCommunityId = ''; + String selectedSpaceId = ''; + SpaceTreeBloc() : super(const SpaceTreeState()) { + on(_fetchSpaces); + on(_onSelectSpace); + } + + _fetchSpaces(InitialEvent event, Emitter emit) async { + emit(SpaceTreeLoadingState()); + try { + // _onloadProducts(); + List communities = await CommunitySpaceManagementApi().fetchCommunities(); + + List updatedCommunities = await Future.wait( + communities.map((community) async { + List spaces = + await CommunitySpaceManagementApi().getSpaceHierarchy(community.uuid); + return CommunityModel( + uuid: community.uuid, + createdAt: community.createdAt, + updatedAt: community.updatedAt, + name: community.name, + description: community.description, + spaces: spaces, + region: community.region, + ); + }).toList(), + ); + + if (updatedCommunities.isNotEmpty && + state.selectedSpace.isEmpty && + state.selectedCommunity.isEmpty) { + selectedCommunityId = updatedCommunities[0].uuid; + } else { + selectedCommunityId = state.selectedCommunity; + selectedSpaceId = state.selectedSpace; + } + + emit(state.copyWith( + communitiesList: updatedCommunities, + selectedCommunity: selectedCommunityId, + selectedSpace: selectedSpaceId)); + } catch (e) { + emit(SpaceTreeErrorState('Error loading communities and spaces: $e')); + } + } + + _onSelectSpace(OnSelectSpaceEvent event, Emitter emit) async { + try { + selectedCommunityId = event.communityId; + selectedSpaceId = event.spaceId; + + emit(state.copyWith( + communitiesList: state.spacesList, + selectedCommunity: event.communityId, + selectedSpace: event.spaceId)); + } catch (e) { + emit(const SpaceTreeErrorState('Something went wrong')); + } + } +} diff --git a/lib/pages/space_tree/bloc/space_tree_event.dart b/lib/pages/space_tree/bloc/space_tree_event.dart new file mode 100644 index 00000000..d6c95579 --- /dev/null +++ b/lib/pages/space_tree/bloc/space_tree_event.dart @@ -0,0 +1,29 @@ +import 'package:equatable/equatable.dart'; + +class SpaceTreeEvent extends Equatable { + const SpaceTreeEvent(); + + @override + List get props => []; +} + +class InitialEvent extends SpaceTreeEvent {} + +class OnSelectSpaceEvent extends SpaceTreeEvent { + final String communityId; + final String spaceId; + + const OnSelectSpaceEvent(this.communityId, this.spaceId); + + @override + List get props => [communityId, spaceId]; +} + +class SearchForSpace extends SpaceTreeEvent { + final String searchQuery; + + const SearchForSpace(this.searchQuery); + + @override + List get props => [searchQuery]; +} diff --git a/lib/pages/space_tree/bloc/space_tree_state.dart b/lib/pages/space_tree/bloc/space_tree_state.dart new file mode 100644 index 00000000..ab82f2dc --- /dev/null +++ b/lib/pages/space_tree/bloc/space_tree_state.dart @@ -0,0 +1,31 @@ +import 'package:equatable/equatable.dart'; +import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart'; + +class SpaceTreeState extends Equatable { + final List spacesList; + final String selectedSpace; + final String selectedCommunity; + + const SpaceTreeState( + {this.spacesList = const [], this.selectedSpace = '', this.selectedCommunity = ''}); + + SpaceTreeState copyWith( + {List? communitiesList, String? selectedSpace, String? selectedCommunity}) { + return SpaceTreeState( + spacesList: communitiesList ?? this.spacesList, + selectedSpace: selectedSpace ?? this.selectedSpace, + selectedCommunity: selectedCommunity ?? this.selectedCommunity); + } + + @override + List get props => [spacesList, selectedSpace, selectedCommunity]; +} + +class SpaceTreeLoadingState extends SpaceTreeState {} + +class SpaceTreeErrorState extends SpaceTreeState { + final String message; + const SpaceTreeErrorState(this.message); + @override + List get props => [message]; +} diff --git a/lib/pages/space_tree/view/side_spaces_view.dart b/lib/pages/space_tree/view/side_spaces_view.dart new file mode 100644 index 00000000..c890ef69 --- /dev/null +++ b/lib/pages/space_tree/view/side_spaces_view.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart'; +import 'package:syncrow_web/pages/space_tree/bloc/space_tree_state.dart'; +import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart'; + +class SideSpacesView extends StatelessWidget { + final Function onSelectAction; + const SideSpacesView({required this.onSelectAction, super.key}); + + @override + Widget build(BuildContext context) { + return BlocConsumer( + listener: (context, state) {}, + builder: (context, state) { + return SpaceTreeView( + communities: state.spacesList, + selectedSpaceUuid: state.selectedSpace, + selectedCommunityId: state.selectedCommunity, + buildContext: context, + action: onSelectAction, + isLoading: state is SpaceTreeLoadingState, + ); + }); + } +} diff --git a/lib/pages/space_tree/view/space_tree_view.dart b/lib/pages/space_tree/view/space_tree_view.dart new file mode 100644 index 00000000..59e7b73a --- /dev/null +++ b/lib/pages/space_tree/view/space_tree_view.dart @@ -0,0 +1,251 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:syncrow_web/common/widgets/search_bar.dart'; +import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart'; +import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart'; +import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart'; +import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart'; +import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/community_tile.dart'; +import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/space_tile_widget.dart'; +import 'package:syncrow_web/utils/color_manager.dart'; +import 'package:syncrow_web/utils/constants/assets.dart'; +import 'package:syncrow_web/utils/style.dart'; + +class SpaceTreeView extends StatefulWidget { + final List communities; + final String? selectedCommunityId; + final String? selectedSpaceUuid; + final BuildContext buildContext; + final Function action; + final bool isLoading; + + const SpaceTreeView( + {super.key, + this.selectedCommunityId, + required this.communities, + this.selectedSpaceUuid, + required this.buildContext, + required this.action, + required this.isLoading}); + + @override + State createState() => _SpaceTreeViewState(); +} + +class _SpaceTreeViewState extends State { + String _searchQuery = ''; // Track search query + String? _selectedSpaceUuid; + String? _selectedCommunityId; + String? _expandedId; + + @override + void initState() { + super.initState(); + // _selectedId = widget.selectedSpaceUuid; // Initialize with the passed selected space UUID + _selectedCommunityId = widget.selectedCommunityId; + _selectedSpaceUuid = widget.selectedSpaceUuid; + } + + @override + void didUpdateWidget(covariant SpaceTreeView oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.selectedSpaceUuid != oldWidget.selectedSpaceUuid || + widget.selectedCommunityId != oldWidget.selectedCommunityId) { + setState(() { + // _selectedId = widget.selectedSpaceUuid; + _selectedCommunityId = widget.selectedCommunityId; + _selectedSpaceUuid = widget.selectedSpaceUuid; + }); + } + } + + // Function to filter communities based on the search query + List _filterCommunities() { + _expandedId = null; + if (_searchQuery.isEmpty) { + // Reset the selected community and space UUIDs if there's no query + // _selectedSpaceUuid = null; + // _selectedCommunityId = null; + return widget.communities; + } + + // Filter communities and expand only those that match the query + return widget.communities.where((community) { + final containsQueryInCommunity = + community.name.toLowerCase().contains(_searchQuery.toLowerCase()); + final containsQueryInSpaces = + community.spaces.any((space) => _containsQuery(space, _searchQuery.toLowerCase())); + + return containsQueryInCommunity || containsQueryInSpaces; + }).toList(); + } + + // Helper function to determine if any space or its children match the search query + bool _containsQuery(SpaceModel space, String query) { + final matchesSpace = space.name.toLowerCase().contains(query); + final matchesChildren = + space.children.any((child) => _containsQuery(child, query)); // Recursive check for children + + // If the space or any of its children match the query, expand this space + if (matchesSpace || matchesChildren) { + _expandedId = space.uuid; + } + + return matchesSpace || matchesChildren; + } + + bool _isSpaceOrChildSelected(SpaceModel space) { + // Return true if the current space or any of its child spaces is selected + if (_expandedId == space.uuid) { + return true; + } + + // Recursively check if any child spaces match the query + for (var child in space.children) { + if (_isSpaceOrChildSelected(child)) { + return true; + } + } + + return false; + } + + @override + Widget build(BuildContext context) { + final filteredCommunities = _filterCommunities(); + + return Container( + // width: MediaQuery.sizeOf(context).width * 0.25, + height: MediaQuery.sizeOf(context).height, + margin: const EdgeInsets.only(right: 24), + decoration: subSectionContainerDecoration, + child: widget.isLoading + ? const Center(child: CircularProgressIndicator()) + : Column( + mainAxisSize: MainAxisSize.min, // Ensures the Column only takes necessary height + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // Communities title with the add button + Container( + decoration: subSectionContainerDecoration, + padding: const EdgeInsets.all(16.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text('Communities', + style: Theme.of(context).textTheme.titleMedium?.copyWith( + color: Colors.black, + )), + GestureDetector( + onTap: () => _navigateToBlank(context), + child: Container( + width: 30, + height: 30, + decoration: const BoxDecoration( + color: ColorsManager.whiteColors, + shape: BoxShape.circle, + ), + child: Center( + child: SvgPicture.asset( + Assets.roundedAddIcon, + width: 24, + height: 24, + ), + ), + ), + ), + ], + ), + ), + // Search bar + CustomSearchBar( + onSearchChanged: (query) { + setState(() { + _selectedSpaceUuid = null; + _searchQuery = query; + }); + }, + ), + const SizedBox(height: 16), + // Community list + Expanded( + child: ListView( + children: filteredCommunities.map((community) { + return _buildCommunityTile(context, community); + }).toList(), + ), + ), + ], + ), + ); + } + + void _navigateToBlank(BuildContext context) { + setState(() { + // _selectedId = ''; + _selectedSpaceUuid = ''; + }); + // context.read().add( + // NewCommunityEvent(communities: widget.communities), + // ); + } + + Widget _buildCommunityTile(BuildContext context, CommunityModel community) { + bool hasChildren = community.spaces.isNotEmpty; + + return CommunityTile( + title: community.name, + key: ValueKey(community.uuid), + isSelected: _selectedCommunityId == community.uuid, + isExpanded: false, + onItemSelected: () { + setState(() { + _selectedCommunityId = community.uuid; + _selectedSpaceUuid = null; + }); + + widget.buildContext.read().add( + OnSelectSpaceEvent(community.uuid, ''), + ); + + widget.action(community.uuid, ''); + }, + onExpansionChanged: (String title, bool expanded) { + _handleExpansionChange(community.uuid, expanded); + }, + children: hasChildren + ? community.spaces.map((space) => _buildSpaceTile(space, community)).toList() + : null, + ); + } + + Widget _buildSpaceTile(SpaceModel space, CommunityModel community) { + return SpaceTile( + title: space.name, + key: ValueKey(space.uuid), + isSelected: _selectedSpaceUuid == space.uuid, + initiallyExpanded: _isSpaceOrChildSelected(space), + onExpansionChanged: (bool expanded) { + _handleExpansionChange(space.uuid ?? '', expanded); + }, + onItemSelected: () { + setState(() { + _selectedSpaceUuid = space.uuid; + _selectedCommunityId = community.uuid; + }); + + widget.buildContext.read().add( + OnSelectSpaceEvent(community.uuid, space.uuid ?? ''), + ); + + widget.action(community.uuid, space.uuid); + }, + children: space.children.isNotEmpty + ? space.children.map((childSpace) => _buildSpaceTile(childSpace, community)).toList() + : [], + ); + } + + void _handleExpansionChange(String uuid, bool expanded) {} +} diff --git a/lib/pages/spaces_management/all_spaces/widgets/community_tile.dart b/lib/pages/spaces_management/all_spaces/widgets/community_tile.dart index 5b9f79f2..69a723c0 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/community_tile.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/community_tile.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:syncrow_web/common/custom_expansion_tile.dart'; +import 'package:syncrow_web/common/widgets/custom_expansion_tile.dart'; class CommunityTile extends StatelessWidget { final String title; @@ -24,7 +24,7 @@ class CommunityTile extends StatelessWidget { return CustomExpansionTile( title: title, initiallyExpanded: isExpanded, - isSelected: isSelected, + isSelected: isSelected, onExpansionChanged: (bool expanded) { onExpansionChanged(title, expanded); }, diff --git a/lib/pages/spaces_management/all_spaces/widgets/sidebar_widget.dart b/lib/pages/spaces_management/all_spaces/widgets/sidebar_widget.dart index a58d73e9..99ce3b1d 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/sidebar_widget.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/sidebar_widget.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/svg.dart'; -import 'package:syncrow_web/common/search_bar.dart'; +import 'package:syncrow_web/common/widgets/search_bar.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart'; @@ -34,8 +34,7 @@ class _SidebarWidgetState extends State { @override void initState() { super.initState(); - _selectedId = widget - .selectedSpaceUuid; // Initialize with the passed selected space UUID + _selectedId = widget.selectedSpaceUuid; // Initialize with the passed selected space UUID } @override @@ -60,8 +59,8 @@ class _SidebarWidgetState extends State { return widget.communities.where((community) { final containsQueryInCommunity = community.name.toLowerCase().contains(_searchQuery.toLowerCase()); - final containsQueryInSpaces = community.spaces - .any((space) => _containsQuery(space, _searchQuery.toLowerCase())); + final containsQueryInSpaces = + community.spaces.any((space) => _containsQuery(space, _searchQuery.toLowerCase())); return containsQueryInCommunity || containsQueryInSpaces; }).toList(); @@ -70,8 +69,8 @@ class _SidebarWidgetState extends State { // Helper function to determine if any space or its children match the search query bool _containsQuery(SpaceModel space, String query) { final matchesSpace = space.name.toLowerCase().contains(query); - final matchesChildren = space.children.any((child) => - _containsQuery(child, query)); // Recursive check for children + final matchesChildren = + space.children.any((child) => _containsQuery(child, query)); // Recursive check for children // If the space or any of its children match the query, expand this space if (matchesSpace || matchesChildren) { @@ -105,8 +104,7 @@ class _SidebarWidgetState extends State { width: 300, decoration: subSectionContainerDecoration, child: Column( - mainAxisSize: - MainAxisSize.min, // Ensures the Column only takes necessary height + mainAxisSize: MainAxisSize.min, // Ensures the Column only takes necessary height crossAxisAlignment: CrossAxisAlignment.start, children: [ // Communities title with the add button @@ -194,9 +192,7 @@ class _SidebarWidgetState extends State { _handleExpansionChange(community.uuid, expanded); }, children: hasChildren - ? community.spaces - .map((space) => _buildSpaceTile(space, community)) - .toList() + ? community.spaces.map((space) => _buildSpaceTile(space, community)).toList() : null, // Render spaces within the community ); } @@ -218,14 +214,11 @@ class _SidebarWidgetState extends State { }); context.read().add( - SelectSpaceEvent( - selectedCommunity: community, selectedSpace: space), + SelectSpaceEvent(selectedCommunity: community, selectedSpace: space), ); }, children: space.children.isNotEmpty - ? space.children - .map((childSpace) => _buildSpaceTile(childSpace, community)) - .toList() + ? space.children.map((childSpace) => _buildSpaceTile(childSpace, community)).toList() : [], // Recursively render child spaces if available ); } diff --git a/lib/pages/spaces_management/all_spaces/widgets/space_tile_widget.dart b/lib/pages/spaces_management/all_spaces/widgets/space_tile_widget.dart index 80753f9d..63cf9b7d 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/space_tile_widget.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/space_tile_widget.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:syncrow_web/common/custom_expansion_tile.dart'; +import 'package:syncrow_web/common/widgets/custom_expansion_tile.dart'; class SpaceTile extends StatefulWidget { final String title; diff --git a/lib/services/devices_mang_api.dart b/lib/services/devices_mang_api.dart index 5be1a9e4..cdddbbeb 100644 --- a/lib/services/devices_mang_api.dart +++ b/lib/services/devices_mang_api.dart @@ -9,12 +9,18 @@ import 'package:syncrow_web/pages/device_managment/water_heater/models/schedule_ import 'package:syncrow_web/pages/visitor_password/model/device_model.dart'; import 'package:syncrow_web/services/api/http_service.dart'; import 'package:syncrow_web/utils/constants/api_const.dart'; +import 'package:syncrow_web/utils/constants/temp_const.dart'; class DevicesManagementApi { - Future> fetchDevices() async { + Future> fetchDevices(String communityId, String spaceId) async { try { final response = await HTTPService().get( - path: ApiEndpoints.getAllDevices, + path: communityId.isNotEmpty && spaceId.isNotEmpty + ? ApiEndpoints.getSpaceDevices + .replaceAll('{spaceUuid}', spaceId) + .replaceAll('{communityUuid}', communityId) + .replaceAll('{projectId}', TempConst.projectId) + : ApiEndpoints.getAllDevices, showServerMessage: true, expectedResponseModel: (json) { List jsonData = json; @@ -85,8 +91,7 @@ class DevicesManagementApi { } } - Future deviceBatchControl( - List uuids, String code, dynamic value) async { + Future deviceBatchControl(List uuids, String code, dynamic value) async { try { final body = { 'devicesUuid': uuids, @@ -110,8 +115,7 @@ class DevicesManagementApi { } } - static Future> getDevicesByGatewayId( - String gatewayId) async { + static Future> getDevicesByGatewayId(String gatewayId) async { final response = await HTTPService().get( path: ApiEndpoints.gatewayApi.replaceAll('{gatewayUuid}', gatewayId), showServerMessage: false, @@ -145,9 +149,7 @@ class DevicesManagementApi { String code, ) async { final response = await HTTPService().get( - path: ApiEndpoints.getDeviceLogs - .replaceAll('{uuid}', uuid) - .replaceAll('{code}', code), + path: ApiEndpoints.getDeviceLogs.replaceAll('{uuid}', uuid).replaceAll('{code}', code), showServerMessage: false, expectedResponseModel: (json) { return DeviceReport.fromJson(json); @@ -220,8 +222,7 @@ class DevicesManagementApi { } } - Future addScheduleRecord( - ScheduleEntry sendSchedule, String uuid) async { + Future addScheduleRecord(ScheduleEntry sendSchedule, String uuid) async { try { final response = await HTTPService().post( path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid), @@ -238,8 +239,7 @@ class DevicesManagementApi { } } - Future> getDeviceSchedules( - String uuid, String category) async { + Future> getDeviceSchedules(String uuid, String category) async { try { final response = await HTTPService().get( path: ApiEndpoints.getScheduleByDeviceId @@ -262,9 +262,7 @@ class DevicesManagementApi { } Future updateScheduleRecord( - {required bool enable, - required String uuid, - required String scheduleId}) async { + {required bool enable, required String uuid, required String scheduleId}) async { try { final response = await HTTPService().put( path: ApiEndpoints.updateScheduleByDeviceId @@ -285,8 +283,7 @@ class DevicesManagementApi { } } - Future editScheduleRecord( - String uuid, ScheduleEntry newSchedule) async { + Future editScheduleRecord(String uuid, ScheduleEntry newSchedule) async { try { final response = await HTTPService().put( path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid), diff --git a/lib/services/routines_api.dart b/lib/services/routines_api.dart index 7be3ff11..551951ea 100644 --- a/lib/services/routines_api.dart +++ b/lib/services/routines_api.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; -import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart'; -import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_scene_model.dart'; -import 'package:syncrow_web/pages/routiens/models/icon_model.dart'; -import 'package:syncrow_web/pages/routiens/models/routine_details_model.dart'; -import 'package:syncrow_web/pages/routiens/models/routine_model.dart'; +import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_automation_model.dart'; +import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_scene_model.dart'; +import 'package:syncrow_web/pages/routines/models/icon_model.dart'; +import 'package:syncrow_web/pages/routines/models/routine_details_model.dart'; +import 'package:syncrow_web/pages/routines/models/routine_model.dart'; import 'package:syncrow_web/services/api/http_service.dart'; import 'package:syncrow_web/utils/constants/api_const.dart'; import 'package:syncrow_web/utils/constants/temp_const.dart'; @@ -12,8 +12,7 @@ class SceneApi { static final HTTPService _httpService = HTTPService(); // //create scene - static Future> createScene( - CreateSceneModel createSceneModel) async { + static Future> createScene(CreateSceneModel createSceneModel) async { try { debugPrint('create scene model: ${createSceneModel.toMap()}'); final response = await _httpService.post( @@ -70,13 +69,12 @@ class SceneApi { //get scenes by community id and space id - static Future> getScenesByUnitId( - String unitId, String communityId, + static Future> getScenes(String spaceId, String communityId, {showInDevice = false}) async { try { final response = await _httpService.get( - path: ApiEndpoints.getUnitScenes - .replaceAll('{spaceUuid}', unitId) + path: ApiEndpoints.getScenes + .replaceAll('{spaceUuid}', spaceId) .replaceAll('{communityUuid}', communityId) .replaceAll('{projectId}', TempConst.projectId), queryParameters: {'showInHomePage': showInDevice}, @@ -99,10 +97,10 @@ class SceneApi { //getAutomation - static Future> getAutomationByUnitId(String unitId) async { + static Future> getAutomation(String spaceId) async { try { final response = await _httpService.get( - path: ApiEndpoints.getSpaceAutomation.replaceAll('{unitUuid}', unitId), + path: ApiEndpoints.getSpaceAutomation.replaceAll('{spaceUuid}', spaceId), showServerMessage: false, expectedResponseModel: (json) { List scenes = []; @@ -132,12 +130,10 @@ class SceneApi { // } //automation details - static Future getAutomationDetails( - String automationId) async { + static Future getAutomationDetails(String automationId) async { try { final response = await _httpService.get( - path: ApiEndpoints.getAutomationDetails - .replaceAll('{automationId}', automationId), + path: ApiEndpoints.getAutomationDetails.replaceAll('{automationId}', automationId), showServerMessage: false, expectedResponseModel: (json) => RoutineDetailsModel.fromMap(json), ); @@ -152,8 +148,7 @@ class SceneApi { try { final response = await _httpService.put( path: ApiEndpoints.updateScene.replaceAll('{sceneId}', sceneId), - body: createSceneModel - .toJson(sceneId.isNotEmpty == true ? sceneId : null), + body: createSceneModel.toJson(sceneId.isNotEmpty == true ? sceneId : null), expectedResponseModel: (json) { return json; }, @@ -165,14 +160,11 @@ class SceneApi { } //update automation - static updateAutomation( - CreateAutomationModel createAutomationModel, String automationId) async { + static updateAutomation(CreateAutomationModel createAutomationModel, String automationId) async { try { final response = await _httpService.put( - path: ApiEndpoints.updateAutomation - .replaceAll('{automationId}', automationId), - body: createAutomationModel - .toJson(automationId.isNotEmpty == true ? automationId : null), + path: ApiEndpoints.updateAutomation.replaceAll('{automationId}', automationId), + body: createAutomationModel.toJson(automationId.isNotEmpty == true ? automationId : null), expectedResponseModel: (json) { return json; }, @@ -189,8 +181,7 @@ class SceneApi { final response = await _httpService.get( path: ApiEndpoints.getScene.replaceAll('{sceneId}', sceneId), showServerMessage: false, - expectedResponseModel: (json) => - RoutineDetailsModel.fromMap(json['data']), + expectedResponseModel: (json) => RoutineDetailsModel.fromMap(json['data']), ); return response; } catch (e) { @@ -199,8 +190,7 @@ class SceneApi { } //delete Scene - static Future deleteScene( - {required String unitUuid, required String sceneId}) async { + static Future deleteScene({required String unitUuid, required String sceneId}) async { try { final response = await _httpService.delete( path: ApiEndpoints.deleteScene diff --git a/lib/utils/constants/api_const.dart b/lib/utils/constants/api_const.dart index b8d23259..c5fc4506 100644 --- a/lib/utils/constants/api_const.dart +++ b/lib/utils/constants/api_const.dart @@ -25,6 +25,8 @@ abstract class ApiEndpoints { ////// Devices Management //////////////// static const String getAllDevices = '/device'; + static const String getSpaceDevices = + '/projects/{projectId}/communities/{communityUuid}/spaces/{spaceUuid}/devices'; static const String getDeviceStatus = '/device/{uuid}/functions/status'; static const String getBatchStatus = '/device/status/batch'; @@ -38,8 +40,10 @@ abstract class ApiEndpoints { // Space Module static const String createSpace = '/projects/{projectId}/communities/{communityId}/spaces'; static const String listSpaces = '/projects/{projectId}/communities/{communityId}/spaces'; - static const String deleteSpace = '/projects/{projectId}/communities/{communityId}/spaces/{spaceId}'; - static const String updateSpace = '/projects/{projectId}/communities/{communityId}/spaces/{spaceId}'; + static const String deleteSpace = + '/projects/{projectId}/communities/{communityId}/spaces/{spaceId}'; + static const String updateSpace = + '/projects/{projectId}/communities/{communityId}/spaces/{spaceId}'; static const String getSpace = '/projects/{projectId}/communities/{communityId}/spaces/{spaceId}'; static const String getSpaceHierarchy = '/projects/{projectId}/communities/{communityId}/spaces'; @@ -63,18 +67,19 @@ abstract class ApiEndpoints { //product static const String listProducts = '/products'; - static const String getSpaceScenes = '/scene/tap-to-run/{unitUuid}'; - static const String getSpaceAutomation = '/automation/{unitUuid}'; + static const String getSpaceScenes = '/scene/tap-to-run/{spaceUuid}'; + static const String getSpaceAutomation = '/automation/{spaceUuid}'; static const String getIconScene = '/scene/icon'; static const String createScene = '/scene/tap-to-run'; static const String createAutomation = '/automation'; - static const String getUnitScenes = '/projects/{projectId}/communities/{communityUuid}/spaces/{spaceUuid}/scenes'; + static const String getScenes = + '/projects/{projectId}/communities/{communityUuid}/spaces/{spaceUuid}/scenes'; static const String getAutomationDetails = '/automation/details/{automationId}'; static const String getScene = '/scene/tap-to-run/{sceneId}'; static const String deleteScene = '/scene/tap-to-run/{sceneId}'; static const String deleteAutomation = '/automation/{automationId}'; - static const String updateScene = '/scene/tap-to-run/{sceneId}'; + static const String updateScene = '/scene/tap-to-run/{sceneId}'; static const String updateAutomation = '/automation/{automationId}'; }