mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 23:27:25 +00:00
push schedules active enable api
This commit is contained in:
@ -540,23 +540,23 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
if (state is WaterHeaterDeviceStatusLoaded) {
|
if (state is WaterHeaterDeviceStatusLoaded) {
|
||||||
final currentState = state as WaterHeaterDeviceStatusLoaded;
|
final currentState = state as WaterHeaterDeviceStatusLoaded;
|
||||||
|
|
||||||
ScheduleModel updatedSchedule = currentState.schedules[event.index]
|
final updatedSchedules = currentState.schedules.map((schedule) {
|
||||||
.copyWith(
|
if (schedule.scheduleId == event.scheduleId) {
|
||||||
function: Status(code: 'switch_1', value: event.functionOn));
|
return schedule.copyWith(
|
||||||
|
function: Status(code: 'switch_1', value: event.functionOn),
|
||||||
// emit(ScheduleLoadingState());
|
enable: event.enable,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return schedule;
|
||||||
|
}).toList();
|
||||||
|
|
||||||
bool success = await DevicesManagementApi().updateScheduleRecord(
|
bool success = await DevicesManagementApi().updateScheduleRecord(
|
||||||
enable: event.functionOn,
|
enable: event.enable,
|
||||||
uuid: currentState.status.uuid,
|
uuid: currentState.status.uuid,
|
||||||
scheduleId: event.scheduleId,
|
scheduleId: event.scheduleId,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
final updatedSchedules =
|
|
||||||
List<ScheduleModel>.from(currentState.schedules)
|
|
||||||
..[event.index] = updatedSchedule;
|
|
||||||
|
|
||||||
emit(currentState.copyWith(schedules: updatedSchedules));
|
emit(currentState.copyWith(schedules: updatedSchedules));
|
||||||
} else {
|
} else {
|
||||||
emit(currentState);
|
emit(currentState);
|
||||||
@ -578,9 +578,9 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
.deleteScheduleRecord(currentState.status.uuid, event.scheduleId);
|
.deleteScheduleRecord(currentState.status.uuid, event.scheduleId);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
final updatedSchedules =
|
final updatedSchedules = currentState.schedules
|
||||||
List<ScheduleModel>.from(currentState.schedules)
|
.where((schedule) => schedule.scheduleId != event.scheduleId)
|
||||||
..removeAt(event.index);
|
.toList();
|
||||||
|
|
||||||
emit(currentState.copyWith(schedules: updatedSchedules));
|
emit(currentState.copyWith(schedules: updatedSchedules));
|
||||||
} else {
|
} else {
|
||||||
|
@ -82,22 +82,22 @@ final class DeleteScheduleEvent extends WaterHeaterEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final class UpdateScheduleEntryEvent extends WaterHeaterEvent {
|
final class UpdateScheduleEntryEvent extends WaterHeaterEvent {
|
||||||
final bool functionOn;
|
final bool enable;
|
||||||
// final String category;
|
final dynamic functionOn;
|
||||||
final String deviceId;
|
final String deviceId;
|
||||||
final int index;
|
final int index;
|
||||||
final String scheduleId;
|
final String scheduleId;
|
||||||
|
|
||||||
const UpdateScheduleEntryEvent({
|
const UpdateScheduleEntryEvent({
|
||||||
|
required this.enable,
|
||||||
required this.functionOn,
|
required this.functionOn,
|
||||||
// required this.category,
|
|
||||||
required this.deviceId,
|
required this.deviceId,
|
||||||
required this.scheduleId,
|
required this.scheduleId,
|
||||||
required this.index,
|
required this.index,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [functionOn, deviceId, scheduleId];
|
List<Object?> get props => [enable, deviceId, scheduleId];
|
||||||
}
|
}
|
||||||
|
|
||||||
class GetSchedulesEvent extends WaterHeaterEvent {
|
class GetSchedulesEvent extends WaterHeaterEvent {
|
||||||
|
@ -118,7 +118,7 @@ class ScheduleDialogHelper {
|
|||||||
_buildDayCheckboxes(context, state.selectedDays,
|
_buildDayCheckboxes(context, state.selectedDays,
|
||||||
isEdit: isEdit),
|
isEdit: isEdit),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
_buildFunctionSwitch(context, state.functionOn),
|
_buildFunctionSwitch(context, state.functionOn, isEdit),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
@ -221,7 +221,8 @@ class ScheduleDialogHelper {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Widget _buildFunctionSwitch(BuildContext context, bool isOn) {
|
static Widget _buildFunctionSwitch(
|
||||||
|
BuildContext context, bool isOn, bool? isEdit) {
|
||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
@ -234,9 +235,13 @@ class ScheduleDialogHelper {
|
|||||||
value: true,
|
value: true,
|
||||||
groupValue: isOn,
|
groupValue: isOn,
|
||||||
onChanged: (bool? value) {
|
onChanged: (bool? value) {
|
||||||
// context
|
if (isEdit == true) {
|
||||||
// .read<WaterHeaterBloc>()
|
return;
|
||||||
// .add(const UpdateFunctionOnEvent(true));
|
} else {
|
||||||
|
context
|
||||||
|
.read<WaterHeaterBloc>()
|
||||||
|
.add(const UpdateFunctionOnEvent(true));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const Text('On'),
|
const Text('On'),
|
||||||
@ -245,9 +250,13 @@ class ScheduleDialogHelper {
|
|||||||
value: false,
|
value: false,
|
||||||
groupValue: isOn,
|
groupValue: isOn,
|
||||||
onChanged: (bool? value) {
|
onChanged: (bool? value) {
|
||||||
// context
|
if (isEdit == true) {
|
||||||
// .read<WaterHeaterBloc>()
|
return;
|
||||||
// .add(const UpdateFunctionOnEvent(false));
|
} else {
|
||||||
|
context
|
||||||
|
.read<WaterHeaterBloc>()
|
||||||
|
.add(const UpdateFunctionOnEvent(false));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const Text('Off'),
|
const Text('Off'),
|
||||||
|
@ -79,7 +79,9 @@ class _BuildScheduleViewState extends State<BuildScheduleView> {
|
|||||||
if (state.scheduleMode != ScheduleModes.countdown &&
|
if (state.scheduleMode != ScheduleModes.countdown &&
|
||||||
state.scheduleMode != ScheduleModes.inching)
|
state.scheduleMode != ScheduleModes.inching)
|
||||||
ScheduleModeButtons(
|
ScheduleModeButtons(
|
||||||
onSave: () {},
|
onSave: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@ -87,9 +89,21 @@ class _BuildScheduleViewState extends State<BuildScheduleView> {
|
|||||||
if (state is WaterHeaterLoadingState) {
|
if (state is WaterHeaterLoadingState) {
|
||||||
return const SizedBox(
|
return const SizedBox(
|
||||||
height: 200,
|
height: 200,
|
||||||
child: Center(child: CircularProgressIndicator()));
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
ScheduleHeader(),
|
||||||
|
SizedBox(
|
||||||
|
height: 20,
|
||||||
|
),
|
||||||
|
Center(child: CircularProgressIndicator()),
|
||||||
|
],
|
||||||
|
));
|
||||||
}
|
}
|
||||||
return const SizedBox();
|
return const SizedBox(
|
||||||
|
height: 200,
|
||||||
|
child: ScheduleHeader(),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -10,7 +10,7 @@ import 'package:syncrow_web/utils/format_date_time.dart';
|
|||||||
|
|
||||||
import '../helper/add_schedule_dialog_helper.dart';
|
import '../helper/add_schedule_dialog_helper.dart';
|
||||||
|
|
||||||
class ScheduleTableWidget extends StatefulWidget {
|
class ScheduleTableWidget extends StatelessWidget {
|
||||||
final WaterHeaterDeviceStatusLoaded state;
|
final WaterHeaterDeviceStatusLoaded state;
|
||||||
|
|
||||||
const ScheduleTableWidget({
|
const ScheduleTableWidget({
|
||||||
@ -18,26 +18,6 @@ class ScheduleTableWidget extends StatefulWidget {
|
|||||||
required this.state,
|
required this.state,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
|
||||||
State<ScheduleTableWidget> createState() => _ScheduleTableWidgetState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ScheduleTableWidgetState extends State<ScheduleTableWidget> {
|
|
||||||
late Map<int, bool> _enabledStates;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_initializeEnabledStates();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _initializeEnabledStates() {
|
|
||||||
_enabledStates = {
|
|
||||||
for (int i = 0; i < widget.state.schedules.length; i++)
|
|
||||||
i: widget.state.schedules[i].enable
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return Column(
|
||||||
@ -88,7 +68,9 @@ class _ScheduleTableWidgetState extends State<ScheduleTableWidget> {
|
|||||||
),
|
),
|
||||||
child: _buildTableBody(state, context));
|
child: _buildTableBody(state, context));
|
||||||
}
|
}
|
||||||
return const SizedBox();
|
return const SizedBox(
|
||||||
|
height: 200,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -162,20 +144,27 @@ class _ScheduleTableWidgetState extends State<ScheduleTableWidget> {
|
|||||||
return TableRow(
|
return TableRow(
|
||||||
children: [
|
children: [
|
||||||
Center(
|
Center(
|
||||||
child: Radio<bool>(
|
child: GestureDetector(
|
||||||
value: true,
|
onTap: () {
|
||||||
groupValue: _enabledStates[index],
|
|
||||||
onChanged: (bool? value) {
|
|
||||||
setState(() {
|
|
||||||
_enabledStates[index] = value!;
|
|
||||||
});
|
|
||||||
context.read<WaterHeaterBloc>().add(UpdateScheduleEntryEvent(
|
context.read<WaterHeaterBloc>().add(UpdateScheduleEntryEvent(
|
||||||
index: index,
|
index: index,
|
||||||
functionOn: value ?? false,
|
enable: !schedule.enable,
|
||||||
scheduleId: schedule.scheduleId,
|
scheduleId: schedule.scheduleId,
|
||||||
deviceId: state.status.uuid,
|
deviceId: state.status.uuid,
|
||||||
|
functionOn: schedule.function.value,
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
|
child: SizedBox(
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
child: schedule.enable
|
||||||
|
? const Icon(Icons.radio_button_checked,
|
||||||
|
color: ColorsManager.blueColor)
|
||||||
|
: const Icon(
|
||||||
|
Icons.radio_button_unchecked,
|
||||||
|
color: ColorsManager.grayColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Center(
|
Center(
|
||||||
|
Reference in New Issue
Block a user