mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-14 09:17:37 +00:00
@ -16,7 +16,7 @@ class DeviceManagementBloc
|
||||
int _onlineCount = 0;
|
||||
int _offlineCount = 0;
|
||||
int _lowBatteryCount = 0;
|
||||
final List<AllDevicesModel> _selectedDevices = [];
|
||||
List<AllDevicesModel> _selectedDevices = [];
|
||||
List<AllDevicesModel> _filteredDevices = [];
|
||||
String currentProductName = '';
|
||||
String? currentCommunity;
|
||||
@ -37,21 +37,20 @@ class DeviceManagementBloc
|
||||
FetchDevices event, Emitter<DeviceManagementState> emit) async {
|
||||
emit(DeviceManagementLoading());
|
||||
try {
|
||||
var devices = <AllDevicesModel>[];
|
||||
List<AllDevicesModel> devices = [];
|
||||
_devices.clear();
|
||||
final spaceBloc = event.context.read<SpaceTreeBloc>();
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
var spaceBloc = event.context.read<SpaceTreeBloc>();
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
|
||||
if (spaceBloc.state.selectedCommunities.isEmpty) {
|
||||
devices =
|
||||
await DevicesManagementApi().fetchDevices('', '', projectUuid);
|
||||
devices = await DevicesManagementApi().fetchDevices('', '', projectUuid);
|
||||
} else {
|
||||
for (final community in spaceBloc.state.selectedCommunities) {
|
||||
final spacesList =
|
||||
for (var community in spaceBloc.state.selectedCommunities) {
|
||||
List<String> spacesList =
|
||||
spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
|
||||
for (final space in spacesList) {
|
||||
devices.addAll(await DevicesManagementApi()
|
||||
.fetchDevices(community, space, projectUuid));
|
||||
for (var space in spacesList) {
|
||||
devices.addAll(await DevicesManagementApi().fetchDevices(
|
||||
community, space, projectUuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -74,7 +73,7 @@ class DeviceManagementBloc
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onFilterDevices(
|
||||
void _onFilterDevices(
|
||||
FilterDevices event, Emitter<DeviceManagementState> emit) async {
|
||||
if (_devices.isNotEmpty) {
|
||||
_filteredDevices = List.from(_devices.where((device) {
|
||||
@ -166,9 +165,9 @@ class DeviceManagementBloc
|
||||
_selectedDevices.add(event.selectedDevice);
|
||||
}
|
||||
|
||||
final clonedSelectedDevices = List<AllDevicesModel>.from(_selectedDevices);
|
||||
List<AllDevicesModel> clonedSelectedDevices = List.from(_selectedDevices);
|
||||
|
||||
final isControlButtonEnabled =
|
||||
bool isControlButtonEnabled =
|
||||
_checkIfControlButtonEnabled(clonedSelectedDevices);
|
||||
|
||||
if (state is DeviceManagementLoaded) {
|
||||
@ -198,8 +197,8 @@ class DeviceManagementBloc
|
||||
|
||||
void _onUpdateSelection(
|
||||
UpdateSelection event, Emitter<DeviceManagementState> emit) {
|
||||
final selectedDevices = <AllDevicesModel>[];
|
||||
var devicesToSelectFrom = <AllDevicesModel>[];
|
||||
List<AllDevicesModel> selectedDevices = [];
|
||||
List<AllDevicesModel> devicesToSelectFrom = [];
|
||||
|
||||
if (state is DeviceManagementLoaded) {
|
||||
devicesToSelectFrom = (state as DeviceManagementLoaded).devices;
|
||||
@ -207,7 +206,7 @@ class DeviceManagementBloc
|
||||
devicesToSelectFrom = (state as DeviceManagementFiltered).filteredDevices;
|
||||
}
|
||||
|
||||
for (var i = 0; i < event.selectedRows.length; i++) {
|
||||
for (int i = 0; i < event.selectedRows.length; i++) {
|
||||
if (event.selectedRows[i]) {
|
||||
selectedDevices.add(devicesToSelectFrom[i]);
|
||||
}
|
||||
@ -295,7 +294,7 @@ class DeviceManagementBloc
|
||||
currentCommunity = event.community;
|
||||
currentUnitName = event.unitName;
|
||||
|
||||
final devicesToSearch = _filteredDevices;
|
||||
List<AllDevicesModel> devicesToSearch = _filteredDevices;
|
||||
|
||||
if (devicesToSearch.isNotEmpty) {
|
||||
final filteredDevices = devicesToSearch.where((device) {
|
||||
|
@ -18,7 +18,6 @@ import 'package:syncrow_web/pages/device_managment/gateway/view/gateway_view.dar
|
||||
import 'package:syncrow_web/pages/device_managment/main_door_sensor/view/main_door_control_view.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/main_door_sensor/view/main_door_sensor_batch_view.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/one_g_glass_switch/view/one_gang_glass_batch_control_view.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/one_g_glass_switch/view/one_gang_glass_switch_control_view.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_light_batch_control.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_light_device_control.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/power_clamp/view/power_clamp_batch_control_view.dart';
|
||||
@ -40,6 +39,8 @@ import 'package:syncrow_web/pages/device_managment/water_heater/view/water_heate
|
||||
import 'package:syncrow_web/pages/device_managment/water_leak/view/water_leak_batch_control_view.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/water_leak/view/water_leak_control_view.dart';
|
||||
|
||||
import '../../one_g_glass_switch/view/one_gang_glass_switch_control_view.dart';
|
||||
|
||||
mixin RouteControlsBasedCode {
|
||||
Widget routeControlsWidgets({required AllDevicesModel device}) {
|
||||
switch (device.productType) {
|
||||
@ -106,7 +107,7 @@ mixin RouteControlsBasedCode {
|
||||
case 'SOS':
|
||||
return SosDeviceControlsView(device: device);
|
||||
|
||||
case 'NCPS':
|
||||
case 'NCPS':
|
||||
return FlushMountedPresenceSensorControlView(device: device);
|
||||
default:
|
||||
return const SizedBox();
|
||||
@ -131,133 +132,76 @@ mixin RouteControlsBasedCode {
|
||||
switch (devices.first.productType) {
|
||||
case '1G':
|
||||
return WallLightBatchControlView(
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == '1G')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
deviceIds: devices.where((e) => (e.productType == '1G')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
case '2G':
|
||||
return TwoGangBatchControlView(
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == '2G')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
deviceIds: devices.where((e) => (e.productType == '2G')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
case '3G':
|
||||
return LivingRoomBatchControlsView(
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == '3G')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
deviceIds: devices.where((e) => (e.productType == '3G')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
case '1GT':
|
||||
return OneGangGlassSwitchBatchControlView(
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == '1GT')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
deviceIds: devices.where((e) => (e.productType == '1GT')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
case '2GT':
|
||||
return TwoGangGlassSwitchBatchControlView(
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == '2GT')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
deviceIds: devices.where((e) => (e.productType == '2GT')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
case '3GT':
|
||||
return ThreeGangGlassSwitchBatchControlView(
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == '3GT')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
deviceIds: devices.where((e) => (e.productType == '3GT')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
case 'GW':
|
||||
return GatewayBatchControlView(
|
||||
gatewayIds: devices
|
||||
.where((e) => e.productType == 'GW')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
gatewayIds: devices.where((e) => (e.productType == 'GW')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
case 'DL':
|
||||
return DoorLockBatchControlView(
|
||||
devicesIds: devices
|
||||
.where((e) => e.productType == 'DL')
|
||||
.map((e) => e.uuid!)
|
||||
.toList());
|
||||
devicesIds: devices.where((e) => (e.productType == 'DL')).map((e) => e.uuid!).toList());
|
||||
case 'WPS':
|
||||
return WallSensorBatchControlView(
|
||||
devicesIds: devices
|
||||
.where((e) => e.productType == 'WPS')
|
||||
.map((e) => e.uuid!)
|
||||
.toList());
|
||||
devicesIds: devices.where((e) => (e.productType == 'WPS')).map((e) => e.uuid!).toList());
|
||||
case 'CPS':
|
||||
return CeilingSensorBatchControlView(
|
||||
devicesIds: devices
|
||||
.where((e) => e.productType == 'CPS')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
devicesIds: devices.where((e) => (e.productType == 'CPS')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
case 'CUR':
|
||||
return CurtainBatchStatusView(
|
||||
devicesIds: devices
|
||||
.where((e) => e.productType == 'CUR')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
devicesIds: devices.where((e) => (e.productType == 'CUR')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
case 'AC':
|
||||
return AcDeviceBatchControlView(
|
||||
devicesIds: devices
|
||||
.where((e) => e.productType == 'AC')
|
||||
.map((e) => e.uuid!)
|
||||
.toList());
|
||||
devicesIds: devices.where((e) => (e.productType == 'AC')).map((e) => e.uuid!).toList());
|
||||
case 'WH':
|
||||
return WaterHEaterBatchControlView(
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == 'WH')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
deviceIds: devices.where((e) => (e.productType == 'WH')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
case 'DS':
|
||||
return MainDoorSensorBatchView(
|
||||
devicesIds: devices
|
||||
.where((e) => e.productType == 'DS')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
devicesIds: devices.where((e) => (e.productType == 'DS')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
case 'GD':
|
||||
return GarageDoorBatchControlView(
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == 'GD')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
deviceIds: devices.where((e) => (e.productType == 'GD')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
case 'WL':
|
||||
return WaterLeakBatchControlView(
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == 'WL')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
deviceIds: devices.where((e) => (e.productType == 'WL')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
case 'PC':
|
||||
return PowerClampBatchControlView(
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == 'PC')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
deviceIds: devices.where((e) => (e.productType == 'PC')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
case 'SOS':
|
||||
return SOSBatchControlView(
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == 'SOS')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
deviceIds: devices.where((e) => (e.productType == 'SOS')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
case 'NCPS':
|
||||
return FlushMountedPresenceSensorBatchControlView(
|
||||
devicesIds: devices
|
||||
.where((e) => e.productType == 'NCPS')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
devicesIds: devices.where((e) => (e.productType == 'NCPS')).map((e) => e.uuid!).toList(),
|
||||
);
|
||||
default:
|
||||
return const SizedBox();
|
||||
|
@ -5,12 +5,7 @@ class DeviceSubSpace {
|
||||
String? subspaceName;
|
||||
bool? disabled;
|
||||
|
||||
DeviceSubSpace(
|
||||
{this.id,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
this.subspaceName,
|
||||
this.disabled});
|
||||
DeviceSubSpace({this.id, this.createdAt, this.updatedAt, this.subspaceName, this.disabled});
|
||||
|
||||
DeviceSubSpace.fromJson(Map<String, dynamic> json) {
|
||||
id = json['uuid']?.toString() ?? '';
|
||||
|
@ -212,8 +212,8 @@ PC
|
||||
SOS
|
||||
|
||||
*/
|
||||
final type = devicesTypesMap[productType] ?? DeviceType.Other;
|
||||
var tempIcon = '';
|
||||
DeviceType type = devicesTypesMap[productType] ?? DeviceType.Other;
|
||||
String tempIcon = '';
|
||||
if (type == DeviceType.LightBulb) {
|
||||
tempIcon = Assets.lightBulb;
|
||||
} else if (type == DeviceType.CeilingSensor ||
|
||||
@ -441,9 +441,13 @@ SOS
|
||||
VoltageCStatusFunction(
|
||||
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
|
||||
CurrentCStatusFunction(
|
||||
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
|
||||
deviceId: uuid ?? '',
|
||||
deviceName: name ?? '',
|
||||
type: 'IF'),
|
||||
PowerFactorCStatusFunction(
|
||||
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
|
||||
deviceId: uuid ?? '',
|
||||
deviceName: name ?? '',
|
||||
type: 'IF'),
|
||||
];
|
||||
|
||||
default:
|
||||
@ -561,23 +565,23 @@ SOS
|
||||
}
|
||||
|
||||
Map<String, DeviceType> devicesTypesMap = {
|
||||
'AC': DeviceType.AC,
|
||||
'GW': DeviceType.Gateway,
|
||||
'CPS': DeviceType.CeilingSensor,
|
||||
'DL': DeviceType.DoorLock,
|
||||
'WPS': DeviceType.WallSensor,
|
||||
'3G': DeviceType.ThreeGang,
|
||||
'2G': DeviceType.TwoGang,
|
||||
'1G': DeviceType.OneGang,
|
||||
'CUR': DeviceType.Curtain,
|
||||
'WH': DeviceType.WH,
|
||||
'DS': DeviceType.DS,
|
||||
'1GT': DeviceType.OneTouch,
|
||||
'2GT': DeviceType.TowTouch,
|
||||
'3GT': DeviceType.ThreeTouch,
|
||||
'GD': DeviceType.GarageDoor,
|
||||
'WL': DeviceType.WaterLeak,
|
||||
'NCPS': DeviceType.NCPS,
|
||||
'PC': DeviceType.PC,
|
||||
"AC": DeviceType.AC,
|
||||
"GW": DeviceType.Gateway,
|
||||
"CPS": DeviceType.CeilingSensor,
|
||||
"DL": DeviceType.DoorLock,
|
||||
"WPS": DeviceType.WallSensor,
|
||||
"3G": DeviceType.ThreeGang,
|
||||
"2G": DeviceType.TwoGang,
|
||||
"1G": DeviceType.OneGang,
|
||||
"CUR": DeviceType.Curtain,
|
||||
"WH": DeviceType.WH,
|
||||
"DS": DeviceType.DS,
|
||||
"1GT": DeviceType.OneTouch,
|
||||
"2GT": DeviceType.TowTouch,
|
||||
"3GT": DeviceType.ThreeTouch,
|
||||
"GD": DeviceType.GarageDoor,
|
||||
"WL": DeviceType.WaterLeak,
|
||||
"NCPS": DeviceType.NCPS,
|
||||
"PC": DeviceType.PC,
|
||||
};
|
||||
}
|
||||
|
@ -6,13 +6,13 @@ class FactoryResetModel {
|
||||
|
||||
FactoryResetModel({
|
||||
required this.devicesUuid,
|
||||
this.operationType = 'RESET',
|
||||
this.operationType = "RESET",
|
||||
});
|
||||
|
||||
factory FactoryResetModel.fromJson(Map<String, dynamic> json) {
|
||||
return FactoryResetModel(
|
||||
devicesUuid: List<String>.from(json['devicesUuid']),
|
||||
operationType: 'RESET',
|
||||
operationType: "RESET",
|
||||
);
|
||||
}
|
||||
|
||||
@ -58,3 +58,4 @@ class FactoryResetModel {
|
||||
@override
|
||||
int get hashCode => devicesUuid.hashCode;
|
||||
}
|
||||
|
||||
|
@ -24,13 +24,13 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DeviceManagementBloc, DeviceManagementState>(
|
||||
builder: (context, state) {
|
||||
var devicesToShow = <AllDevicesModel>[];
|
||||
var selectedIndex = 0;
|
||||
var onlineCount = 0;
|
||||
var offlineCount = 0;
|
||||
var lowBatteryCount = 0;
|
||||
var isControlButtonEnabled = false;
|
||||
var selectedDevices = <AllDevicesModel>[];
|
||||
List<AllDevicesModel> devicesToShow = [];
|
||||
int selectedIndex = 0;
|
||||
int onlineCount = 0;
|
||||
int offlineCount = 0;
|
||||
int lowBatteryCount = 0;
|
||||
bool isControlButtonEnabled = false;
|
||||
List<AllDevicesModel> selectedDevices = [];
|
||||
|
||||
if (state is DeviceManagementLoaded) {
|
||||
devicesToShow = state.devices;
|
||||
@ -194,23 +194,18 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
||||
device.name ?? '',
|
||||
device.productName ?? '',
|
||||
device.uuid ?? '',
|
||||
if (device.spaces != null &&
|
||||
device.spaces!.isNotEmpty)
|
||||
device.spaces![0].spaceName
|
||||
else
|
||||
'',
|
||||
(device.spaces != null &&
|
||||
device.spaces!.isNotEmpty)
|
||||
? device.spaces![0].spaceName
|
||||
: '',
|
||||
combinedSpaceNames,
|
||||
if (device.batteryLevel != null)
|
||||
'${device.batteryLevel}%'
|
||||
else
|
||||
'-',
|
||||
device.batteryLevel != null
|
||||
? '${device.batteryLevel}%'
|
||||
: '-',
|
||||
formatDateTime(
|
||||
DateTime.fromMillisecondsSinceEpoch(
|
||||
(device.createTime ?? 0) * 1000)),
|
||||
if (device.online == true)
|
||||
'Online'
|
||||
else
|
||||
'Offline',
|
||||
device.online == true ? 'Online' : 'Offline',
|
||||
formatDateTime(
|
||||
DateTime.fromMillisecondsSinceEpoch(
|
||||
(device.updateTime ?? 0) * 1000)),
|
||||
@ -248,7 +243,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
||||
showGeneralDialog(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
barrierLabel: 'Device Settings',
|
||||
barrierLabel: "Device Settings",
|
||||
transitionDuration: const Duration(milliseconds: 300),
|
||||
pageBuilder: (context, anim1, anim2) {
|
||||
return Align(
|
||||
|
@ -33,9 +33,9 @@ class _DeviceSearchFiltersState extends State<DeviceSearchFilters>
|
||||
spacing: 20,
|
||||
runSpacing: 10,
|
||||
children: [
|
||||
_buildSearchField('Space Name', _unitNameController, 200),
|
||||
_buildSearchField("Space Name", _unitNameController, 200),
|
||||
_buildSearchField(
|
||||
'Device Name / Product Name', _productNameController, 300),
|
||||
"Device Name / Product Name", _productNameController, 300),
|
||||
_buildSearchResetButtons(),
|
||||
],
|
||||
);
|
||||
|
Reference in New Issue
Block a user