Files
syncrow-web/lib/pages/access_management/view/access_management.dart
2024-08-22 00:09:42 +03:00

311 lines
14 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/access_management/bloc/access_bloc.dart';
import 'package:syncrow_web/pages/access_management/bloc/access_event.dart';
import 'package:syncrow_web/pages/access_management/bloc/access_state.dart';
import 'package:syncrow_web/pages/common/custom_table.dart';
import 'package:syncrow_web/pages/common/date_time_widget.dart';
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
import 'package:syncrow_web/pages/common/filter/filter_widget.dart';
import 'package:syncrow_web/pages/visitor_password/view/visitor_password_dialog.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/const.dart';
import 'package:syncrow_web/utils/style.dart';
import 'package:syncrow_web/web_layout/web_scaffold.dart';
class AccessManagementPage extends StatelessWidget {
const AccessManagementPage({super.key});
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return WebScaffold(
enableMenuSideba: false,
appBarTitle: Row(
children: [
Text(
'Access Management',
style: Theme.of(context).textTheme.headlineLarge,
)
],
),
appBarBody: [
Text(
'Physical Access',
style: Theme.of(context)
.textTheme
.headlineMedium!
.copyWith(color: Colors.white),
),
],
scaffoldBody: BlocProvider(
create: (BuildContext context) =>
AccessBloc()..add(FetchTableData()),
child: BlocConsumer<AccessBloc, AccessState>(
listener: (context, state) {
if (state is FailedState) {
// CustomSnackBar.displaySnackBar(
// state.errorMessage
// );
}
}, builder: (context, state) {
final accessBloc = BlocProvider.of<AccessBloc>(context);
return Container(
padding: EdgeInsets.all(30),
height: size.height,
width: size.width,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
FilterWidget(
size: size,
tabs: accessBloc.tabs,
selectedIndex: accessBloc.selectedIndex,
onTabChanged: (index) {
accessBloc.add(TabChangedEvent(index));
},
),
const SizedBox(
height: 20,
),
Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
const Text('Name'),
Container(
width: size.width * 0.15,
decoration: containerDecoration,
child: TextFormField(
controller: accessBloc.passwordName,
style: const TextStyle(color: Colors.black),
decoration: textBoxDecoration()!
.copyWith(hintText: 'Please enter'),
)),
],
),
const SizedBox(
width: 15,
),
DateTimeWebWidget(
isRequired: false,
title: 'Access Time',
size: size,
endTime: () {
accessBloc.add(
SelectTime(context: context, isStart: false));
},
startTime: () {
accessBloc.add(
SelectTime(context: context, isStart: true));
},
firstString:
BlocProvider.of<AccessBloc>(context).startTime,
secondString:
BlocProvider.of<AccessBloc>(context).endTime,
),
const SizedBox(
width: 15,
),
SizedBox(
width: size.width * 0.06,
child: Column(
children: [
Text(''),
Container(
decoration: containerDecoration,
child: DefaultButton(
onPressed: () {
accessBloc.add(FilterDataEvent(
passwordName:
accessBloc.passwordName.text,
startTime: accessBloc
.effectiveTimeTimeStamp,
endTime: accessBloc
.expirationTimeTimeStamp));
},
borderRadius: 9,
child: const Text('Search'))),
],
),
),
const SizedBox(
width: 10,
),
SizedBox(
width: size.width * 0.06,
child: Column(
children: [
Text(''),
Container(
decoration: containerDecoration,
child: DefaultButton(
onPressed: () {
accessBloc.add(ResetSearch());
},
backgroundColor: ColorsManager.whiteColors,
borderRadius: 9,
child: Text(
'Reset',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Colors.black),
),
),
),
],
),
),
],
),
const SizedBox(
height: 20,
),
Wrap(
children: [
Container(
width: size.width * 0.15,
decoration: containerDecoration,
child: DefaultButton(
onPressed: () {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return const VisitorPasswordDialog();
},
);
},
borderRadius: 8,
child:
const Text('+ Create Visitor Password ')),
),
const SizedBox(
width: 10,
),
Container(
width: size.width * 0.12,
decoration: containerDecoration,
child: DefaultButton(
borderRadius: 8,
backgroundColor: ColorsManager.whiteColors,
child: Text(
'Admin Password',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Colors.black),
)))
],
),
const SizedBox(
height: 20,
),
Expanded(
child: state is TableLoaded
? DynamicTable(
withCheckBox: false,
size: size,
cellDecoration: containerDecoration,
headers: const [
'Name',
'Access Type',
'Access Period',
'Device Id',
'Authorizer',
'Authorization Date & Time',
'Access Status'
],
data: state.data.map((item) {
return [
item.passwodName.toString(),
item.passwordType.value,
('${accessBloc.timestampToDate(item.effectiveTime)} - ${accessBloc.timestampToDate(item.invalidTime)}'),
item.deviceUuid.toString(),
'',
'',
''
];
}).toList(),
)
: const Center(child: CircularProgressIndicator()),
)
],
),
);
})));
}
// Container TableWidget(Size size, TableLoaded state,AccessBloc accessBloc) {
// return Container(
// decoration: containerDecoration,
// width: size.width,
// child: Padding(
// padding: const EdgeInsets.all(10.0),
// child: ListView(
// scrollDirection: Axis.horizontal,
// children: [
// Container(
// width: size.width,
// height: size.height,
// child: Column(
// children: [
// Container(
// color: ColorsManager.boxColor,
// child: Row(
// children: [
// _buildTableHeaderCell('Password name'),
// _buildTableHeaderCell(' Password Type'),
// _buildTableHeaderCell('Start Time'),
// _buildTableHeaderCell('End Time'),
// _buildTableHeaderCell('Device Id'),
// // _buildTableHeaderCell('Authorization Source'),
// // _buildTableHeaderCell('Authorizer'),
// _buildTableHeaderCell('Password Created'),
// // _buildTableHeaderCell('Access Status'),
// _buildTableHeaderCell('Password Status'),
// ],
// ),
// ),
// Expanded(
// child: Container(
// width: size.width,
// color: ColorsManager.whiteColors,
// child: ListView(
// shrinkWrap: true,
// children: [
// Column(
// children: state.data.map((item) {
// return Row(
// children: [
// _buildTableCell(item.passwodName),
// _buildTableCell(item.passwordType),
//
// _buildTableCell(accessBloc.timestampToDateTime(item.effectiveTime).toString()),
// _buildTableCell(accessBloc.timestampToDateTime(item.invalidTime).toString()),
// _buildTableCell(item.deviceUuid.toString()),
// // _buildTableCell(item.authorizationSource),
// // _buildTableCell(item.authorizer),
// _buildTableCell(item.passwordCreated!=null?accessBloc.timestampToDateTime(item.passwordCreated).toString():'no data'),
// // _buildTableCell(item.accessStatus),
// _buildTableCell(item.passwordStatus.toString()),
// ],
// );
// }).toList(),
// ),
// ],
// ),
// ),
// ),
// ],
// ),
// ),
// ],
// ),
// ),
// );
// }
}