mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
push schedules active enable api
This commit is contained in:
@ -540,27 +540,27 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
if (state is WaterHeaterDeviceStatusLoaded) {
|
||||
final currentState = state as WaterHeaterDeviceStatusLoaded;
|
||||
|
||||
ScheduleModel updatedSchedule = currentState.schedules[event.index]
|
||||
.copyWith(
|
||||
function: Status(code: 'switch_1', value: event.functionOn));
|
||||
|
||||
// emit(ScheduleLoadingState());
|
||||
final updatedSchedules = currentState.schedules.map((schedule) {
|
||||
if (schedule.scheduleId == event.scheduleId) {
|
||||
return schedule.copyWith(
|
||||
function: Status(code: 'switch_1', value: event.functionOn),
|
||||
enable: event.enable,
|
||||
);
|
||||
}
|
||||
return schedule;
|
||||
}).toList();
|
||||
|
||||
bool success = await DevicesManagementApi().updateScheduleRecord(
|
||||
enable: event.functionOn,
|
||||
enable: event.enable,
|
||||
uuid: currentState.status.uuid,
|
||||
scheduleId: event.scheduleId,
|
||||
);
|
||||
|
||||
if (success) {
|
||||
final updatedSchedules =
|
||||
List<ScheduleModel>.from(currentState.schedules)
|
||||
..[event.index] = updatedSchedule;
|
||||
|
||||
emit(currentState.copyWith(schedules: updatedSchedules));
|
||||
} else {
|
||||
emit(currentState);
|
||||
// emit(const WaterHeaterFailedState(error: 'Failed to update schedule.'));
|
||||
// emit(const WaterHeaterFailedState(error: 'Failed to update schedule.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -572,20 +572,20 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
if (state is WaterHeaterDeviceStatusLoaded) {
|
||||
final currentState = state as WaterHeaterDeviceStatusLoaded;
|
||||
|
||||
// emit(ScheduleLoadingState());
|
||||
// emit(ScheduleLoadingState());
|
||||
|
||||
bool success = await DevicesManagementApi()
|
||||
.deleteScheduleRecord(currentState.status.uuid, event.scheduleId);
|
||||
|
||||
if (success) {
|
||||
final updatedSchedules =
|
||||
List<ScheduleModel>.from(currentState.schedules)
|
||||
..removeAt(event.index);
|
||||
final updatedSchedules = currentState.schedules
|
||||
.where((schedule) => schedule.scheduleId != event.scheduleId)
|
||||
.toList();
|
||||
|
||||
emit(currentState.copyWith(schedules: updatedSchedules));
|
||||
} else {
|
||||
emit(currentState);
|
||||
// emit(const WaterHeaterFailedState(error: 'Failed to delete schedule.'));
|
||||
// emit(const WaterHeaterFailedState(error: 'Failed to delete schedule.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,22 +82,22 @@ final class DeleteScheduleEvent extends WaterHeaterEvent {
|
||||
}
|
||||
|
||||
final class UpdateScheduleEntryEvent extends WaterHeaterEvent {
|
||||
final bool functionOn;
|
||||
// final String category;
|
||||
final bool enable;
|
||||
final dynamic functionOn;
|
||||
final String deviceId;
|
||||
final int index;
|
||||
final String scheduleId;
|
||||
|
||||
const UpdateScheduleEntryEvent({
|
||||
required this.enable,
|
||||
required this.functionOn,
|
||||
// required this.category,
|
||||
required this.deviceId,
|
||||
required this.scheduleId,
|
||||
required this.index,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [functionOn, deviceId, scheduleId];
|
||||
List<Object?> get props => [enable, deviceId, scheduleId];
|
||||
}
|
||||
|
||||
class GetSchedulesEvent extends WaterHeaterEvent {
|
||||
|
@ -118,7 +118,7 @@ class ScheduleDialogHelper {
|
||||
_buildDayCheckboxes(context, state.selectedDays,
|
||||
isEdit: isEdit),
|
||||
const SizedBox(height: 16),
|
||||
_buildFunctionSwitch(context, state.functionOn),
|
||||
_buildFunctionSwitch(context, state.functionOn, isEdit),
|
||||
],
|
||||
),
|
||||
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(
|
||||
children: [
|
||||
Text(
|
||||
@ -234,9 +235,13 @@ class ScheduleDialogHelper {
|
||||
value: true,
|
||||
groupValue: isOn,
|
||||
onChanged: (bool? value) {
|
||||
// context
|
||||
// .read<WaterHeaterBloc>()
|
||||
// .add(const UpdateFunctionOnEvent(true));
|
||||
if (isEdit == true) {
|
||||
return;
|
||||
} else {
|
||||
context
|
||||
.read<WaterHeaterBloc>()
|
||||
.add(const UpdateFunctionOnEvent(true));
|
||||
}
|
||||
},
|
||||
),
|
||||
const Text('On'),
|
||||
@ -245,9 +250,13 @@ class ScheduleDialogHelper {
|
||||
value: false,
|
||||
groupValue: isOn,
|
||||
onChanged: (bool? value) {
|
||||
// context
|
||||
// .read<WaterHeaterBloc>()
|
||||
// .add(const UpdateFunctionOnEvent(false));
|
||||
if (isEdit == true) {
|
||||
return;
|
||||
} else {
|
||||
context
|
||||
.read<WaterHeaterBloc>()
|
||||
.add(const UpdateFunctionOnEvent(false));
|
||||
}
|
||||
},
|
||||
),
|
||||
const Text('Off'),
|
||||
|
@ -79,7 +79,9 @@ class _BuildScheduleViewState extends State<BuildScheduleView> {
|
||||
if (state.scheduleMode != ScheduleModes.countdown &&
|
||||
state.scheduleMode != ScheduleModes.inching)
|
||||
ScheduleModeButtons(
|
||||
onSave: () {},
|
||||
onSave: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
@ -87,9 +89,21 @@ class _BuildScheduleViewState extends State<BuildScheduleView> {
|
||||
if (state is WaterHeaterLoadingState) {
|
||||
return const SizedBox(
|
||||
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';
|
||||
|
||||
class ScheduleTableWidget extends StatefulWidget {
|
||||
class ScheduleTableWidget extends StatelessWidget {
|
||||
final WaterHeaterDeviceStatusLoaded state;
|
||||
|
||||
const ScheduleTableWidget({
|
||||
@ -18,26 +18,6 @@ class ScheduleTableWidget extends StatefulWidget {
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
@ -88,7 +68,9 @@ class _ScheduleTableWidgetState extends State<ScheduleTableWidget> {
|
||||
),
|
||||
child: _buildTableBody(state, context));
|
||||
}
|
||||
return const SizedBox();
|
||||
return const SizedBox(
|
||||
height: 200,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
@ -162,20 +144,27 @@ class _ScheduleTableWidgetState extends State<ScheduleTableWidget> {
|
||||
return TableRow(
|
||||
children: [
|
||||
Center(
|
||||
child: Radio<bool>(
|
||||
value: true,
|
||||
groupValue: _enabledStates[index],
|
||||
onChanged: (bool? value) {
|
||||
setState(() {
|
||||
_enabledStates[index] = value!;
|
||||
});
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
context.read<WaterHeaterBloc>().add(UpdateScheduleEntryEvent(
|
||||
index: index,
|
||||
functionOn: value ?? false,
|
||||
enable: !schedule.enable,
|
||||
scheduleId: schedule.scheduleId,
|
||||
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(
|
||||
|
Reference in New Issue
Block a user