fixed report table

This commit is contained in:
ashrafzarkanisala
2024-09-02 21:23:31 +03:00
parent 7bbae2d332
commit 3017a5d1f6
4 changed files with 60 additions and 53 deletions

View File

@ -82,7 +82,7 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout {
const SizedBox(height: 20), const SizedBox(height: 20),
Expanded( Expanded(
child: DynamicTable( child: DynamicTable(
uuidIndex: 0, uuidIndex: 1,
isEmpty: filteredData.isEmpty, isEmpty: filteredData.isEmpty,
withCheckBox: false, withCheckBox: false,
size: MediaQuery.of(context).size, size: MediaQuery.of(context).size,

View File

@ -6,6 +6,8 @@ import 'package:syncrow_web/pages/device_managment/shared/table/table_header.dar
class ReportsTable extends StatelessWidget { class ReportsTable extends StatelessWidget {
final DeviceReport report; final DeviceReport report;
final String? thirdColumnTitle;
final String? thirdColumnDescription;
final Function(int index) onRowTap; final Function(int index) onRowTap;
final VoidCallback onClose; final VoidCallback onClose;
@ -14,6 +16,8 @@ class ReportsTable extends StatelessWidget {
required this.report, required this.report,
required this.onRowTap, required this.onRowTap,
required this.onClose, required this.onClose,
this.thirdColumnTitle,
this.thirdColumnDescription,
}); });
@override @override
@ -32,33 +36,34 @@ class ReportsTable extends StatelessWidget {
children: [ children: [
TableRow( TableRow(
decoration: BoxDecoration(color: Colors.grey.shade200), decoration: BoxDecoration(color: Colors.grey.shade200),
children: const [ children: [
TableHeader(title: 'Date'), const TableHeader(title: 'Date'),
TableHeader(title: 'Time'), const TableHeader(title: 'Time'),
TableHeader(title: 'Status'), TableHeader(title: thirdColumnTitle ?? 'Status'),
], ],
), ),
...report.data!.asMap().entries.map((entry) { if (report.data != null)
int index = entry.key; ...report.data!.asMap().entries.map((entry) {
DeviceEvent data = entry.value; int index = entry.key;
DeviceEvent data = entry.value;
// Parse eventTime into Date and Time // Parse eventTime into Date and Time
DateTime eventDateTime = DateTime eventDateTime =
DateTime.fromMillisecondsSinceEpoch(data.eventTime!); DateTime.fromMillisecondsSinceEpoch(data.eventTime!);
String date = DateFormat('dd/MM/yyyy').format(eventDateTime); String date = DateFormat('dd/MM/yyyy').format(eventDateTime);
String time = DateFormat('HH:mm').format(eventDateTime); String time = DateFormat('HH:mm').format(eventDateTime);
return TableRow( return TableRow(
children: [ children: [
TableCellWidget(value: date), TableCellWidget(value: date),
TableCellWidget(value: time), TableCellWidget(value: time),
TableCellWidget( TableCellWidget(
value: data.value!, value: '${data.value!} $thirdColumnDescription',
onTap: () => onRowTap(index), onTap: () => onRowTap(index),
), ),
], ],
); );
}).toList(), }),
], ],
), ),
), ),

View File

@ -25,16 +25,21 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
final isLarge = isLargeScreenSize(context); final isLarge = isLargeScreenSize(context);
final isMedium = isMediumScreenSize(context); final isMedium = isMediumScreenSize(context);
return BlocProvider( return BlocProvider(
create: (context) => WallSensorBloc(deviceId: device.uuid!)..add(WallSensorInitialEvent()), create: (context) =>
WallSensorBloc(deviceId: device.uuid!)..add(WallSensorInitialEvent()),
child: BlocBuilder<WallSensorBloc, WallSensorState>( child: BlocBuilder<WallSensorBloc, WallSensorState>(
builder: (context, state) { builder: (context, state) {
if (state is WallSensorLoadingInitialState || state is DeviceReportsLoadingState) { if (state is WallSensorLoadingInitialState ||
state is DeviceReportsLoadingState) {
return const Center(child: CircularProgressIndicator()); return const Center(child: CircularProgressIndicator());
} else if (state is WallSensorUpdateState) { } else if (state is WallSensorUpdateState) {
return _buildGridView(context, state.wallSensorModel, isExtraLarge, isLarge, isMedium); return _buildGridView(context, state.wallSensorModel, isExtraLarge,
isLarge, isMedium);
} else if (state is DeviceReportsState) { } else if (state is DeviceReportsState) {
return ReportsTable( return ReportsTable(
report: state.deviceReport, report: state.deviceReport,
thirdColumnTitle: "Value",
thirdColumnDescription: "Lux",
onRowTap: (index) {}, onRowTap: (index) {},
onClose: () { onClose: () {
context.read<WallSensorBloc>().add(BackToGridViewEvent()); context.read<WallSensorBloc>().add(BackToGridViewEvent());
@ -49,7 +54,8 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
); );
} else if (state is DeviceReportsFailedState) { } else if (state is DeviceReportsFailedState) {
final model = context.read<WallSensorBloc>().deviceStatus; final model = context.read<WallSensorBloc>().deviceStatus;
return _buildGridView(context, model, isExtraLarge, isLarge, isMedium); return _buildGridView(
context, model, isExtraLarge, isLarge, isMedium);
} }
return const Center(child: Text('Error fetching status')); return const Center(child: Text('Error fetching status'));
}, },
@ -57,8 +63,8 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
); );
} }
Widget _buildGridView( Widget _buildGridView(BuildContext context, WallSensorModel model,
BuildContext context, WallSensorModel model, bool isExtraLarge, bool isLarge, bool isMedium) { bool isExtraLarge, bool isLarge, bool isMedium) {
return GridView( return GridView(
padding: const EdgeInsets.symmetric(horizontal: 50), padding: const EdgeInsets.symmetric(horizontal: 50),
shrinkWrap: true, shrinkWrap: true,
@ -127,10 +133,11 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
maxValue: 10000, maxValue: 10000,
steps: 1, steps: 1,
description: 'hr', description: 'hr',
action: (int value) => context.read<WallSensorBloc>().add(WallSensorChangeValueEvent( action: (int value) =>
code: 'no_one_time', context.read<WallSensorBloc>().add(WallSensorChangeValueEvent(
value: value, code: 'no_one_time',
))), value: value,
))),
PresenceUpdateData( PresenceUpdateData(
value: model.farDetection.toDouble(), value: model.farDetection.toDouble(),
title: 'Far Detection:', title: 'Far Detection:',
@ -147,9 +154,8 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
), ),
GestureDetector( GestureDetector(
onTap: () { onTap: () {
context context.read<WallSensorBloc>().add(GetDeviceReportsEvent(
.read<WallSensorBloc>() code: 'illuminance_value', deviceUuid: device.uuid!));
.add(GetDeviceReportsEvent(code: 'illuminance_value', deviceUuid: device.uuid!));
}, },
child: const PresenceStaticWidget( child: const PresenceStaticWidget(
icon: Assets.illuminanceRecordIcon, icon: Assets.illuminanceRecordIcon,
@ -158,9 +164,8 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
), ),
GestureDetector( GestureDetector(
onTap: () { onTap: () {
context context.read<WallSensorBloc>().add(GetDeviceReportsEvent(
.read<WallSensorBloc>() code: 'presence_state', deviceUuid: device.uuid!));
.add(GetDeviceReportsEvent(code: 'presence_state', deviceUuid: device.uuid!));
}, },
child: const PresenceStaticWidget( child: const PresenceStaticWidget(
icon: Assets.presenceRecordIcon, icon: Assets.presenceRecordIcon,

View File

@ -74,19 +74,16 @@ class WebAppBar extends StatelessWidget with HelperResponsiveLayout {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Align( Expanded(
alignment: Alignment.centerLeft, child: Row(
child: Expanded( children: [
child: Row( title!,
children: [ if (centerBody != null)
title!, Padding(
if (centerBody != null) padding: const EdgeInsets.only(left: 80),
Padding( child: centerBody!,
padding: const EdgeInsets.only(left: 80), ),
child: centerBody!, ],
),
],
),
), ),
), ),
Row( Row(