repair add makanan page, addes socket io client for real time update data, added table status change page

This commit is contained in:
kicap
2023-08-25 04:22:48 +08:00
parent 24cc3d3bd7
commit b3781eb831
33 changed files with 1233 additions and 349 deletions

View File

@ -87,9 +87,9 @@ class MejaDetailView extends StatelessWidget {
style: regularTextStyle,
children: [
TextSpan(
text: 'Tersedia',
text: model.theBool ? 'Tidak Tersedia' : 'Tersedia',
style: regularTextStyle.copyWith(
color: Colors.green,
color: model.theBool ? Colors.red : Colors.green,
fontWeight: FontWeight.bold,
),
),
@ -145,58 +145,60 @@ class MejaDetailView extends StatelessWidget {
),
),
const SizedBox(height: 10),
Expanded(
child: ListView.builder(
itemCount: 2,
shrinkWrap: true,
itemBuilder: (context, index) {
// make the color random between red and blue
const color = Colors.blue;
String pesanStatus = 'Menunggu Pengesahan';
return Card(
color: color,
child: ListTile(
// leading: CircleAvatar(
// backgroundColor: Colors.white,
// child: Text(
// index.toString(),
// style: regularTextStyle,
// ),
// ),
title: Text(
'Nama Pemesan',
style: regularTextStyle.copyWith(
fontSize: 18,
color: Colors.white,
fontStyle: FontStyle.italic,
),
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'08:00.00 - 09:00.00',
style: TextStyle(
color: Colors.white,
),
),
Text(
pesanStatus,
style: const TextStyle(
color: Colors.white,
),
),
],
),
trailing: const Icon(Icons.arrow_forward_ios,
color: Colors.white),
onTap: () {
model.log.i('Meja 1');
},
),
);
},
),
const Expanded(
child: SizedBox(),
// ListView.builder(
// itemCount: 2,
// shrinkWrap: true,
// itemBuilder: (context, index) {
// // make the color random between red and blue
// const color = Colors.blue;
// String pesanStatus = 'Menunggu Pengesahan';
// return Card(
// color: color,
// child: ListTile(
// // leading: CircleAvatar(
// // backgroundColor: Colors.white,
// // child: Text(
// // index.toString(),
// // style: regularTextStyle,
// // ),
// // ),
// title: Text(
// 'Nama Pemesan',
// style: regularTextStyle.copyWith(
// fontSize: 18,
// color: Colors.white,
// fontStyle: FontStyle.italic,
// ),
// ),
// subtitle: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// const Text(
// '08:00.00 - 09:00.00',
// style: TextStyle(
// color: Colors.white,
// ),
// ),
// Text(
// pesanStatus,
// style: const TextStyle(
// color: Colors.white,
// ),
// ),
// ],
// ),
// trailing: const Icon(Icons.arrow_forward_ios,
// color: Colors.white),
// onTap: () {
// model.log.i('Meja 1');
// },
// ),
// );
// },
// ),
),
],
),
@ -262,8 +264,12 @@ class MejaDetailView extends StatelessWidget {
onTap: () {
model.log.i('List');
// model.navigationService.navigateToMakananListView();
model.navigationService
.navigateToMejaHistoryLogView(mejaId: mejaId);
// model.navigationService
// .navigateToMejaHistoryLogView(mejaId: mejaId);
model.snackbarService.showSnackbar(
message: 'Fitur ini belum tersedia',
title: 'Info',
duration: const Duration(seconds: 2));
},
child: const Column(
mainAxisAlignment: MainAxisAlignment.center,
@ -292,6 +298,7 @@ class MejaDetailView extends StatelessWidget {
backgroundColor: orangeColor,
onPressed: () {
// model.navigationService.navigateToAddEditMakananView();
model.editStatus();
},
// create a add product button
child: const Icon(

View File

@ -1,3 +1,6 @@
import 'package:reza_admin/model/my_model.dart';
import '../../../../../app/app.dialogs.dart';
import '../../../../../app/app.logger.dart';
import '../../../../../app/core/custom_base_view_model.dart';
@ -6,16 +9,20 @@ class MejaDetailViewModel extends CustomBaseViewModel {
late String mejaId;
late String namaMeja;
late int idMeja;
String? imgAsset;
bool theBool = false;
Future<void> init(String mejaId) async {
log.i('MejaDetailViewModel init');
log.i('mejaId : $mejaId');
// log.i('MejaDetailViewModel init');
// log.i('mejaId : $mejaId');
this.mejaId = mejaId;
globalVar.backPressed = 'backNormal';
// seperate the number from the string
var number = int.parse(mejaId.replaceAll(RegExp(r'[^0-9]'), ''));
idMeja = number;
// log.i('number : $number');
if (number <= 4) {
namaMeja = 'Gazebo';
@ -30,6 +37,35 @@ class MejaDetailViewModel extends CustomBaseViewModel {
namaMeja = '$namaMeja $number';
log.i('imgAsset : $imgAsset');
// log.i('imgAsset : $imgAsset');
getData();
}
getData() async {
easyLoading.showLoading();
setBusy(true);
try {
var response = await httpService.get('table/detail/$idMeja');
// log.i('response : $response');
MyModel myModel = MyModel.fromJson(response.data);
theBool = myModel.theBool!;
log.i('theBool : $theBool');
} catch (e) {
log.e('error : $e');
} finally {
setBusy(false);
easyLoading.dismiss();
}
}
editStatus() async {
var res = await dialogService.showCustomDialog(
variant: DialogType.mejaEditStatusDialogView,
data: {'idMeja': idMeja},
);
if (res!.confirmed) {
getData();
}
}
}

View File

@ -30,6 +30,7 @@ class MejaEditView extends StatelessWidget {
'backPressed : ${model.globalVar.backPressed} in MejaEditView');
if (model.globalVar.backPressed == 'backNormal') {
// model.globalVar.backPressed = 'exitApp';
// model.globalVar.backPressed = 'backNormal';
return true;
}
// model.quitApp(context);
@ -44,7 +45,7 @@ class MejaEditView extends StatelessWidget {
leading: IconButton(
onPressed: () {
if (model.globalVar.backPressed == 'backNormal') {
model.globalVar.backPressed = 'exitApp';
// model.globalVar.backPressed = 'exitApp';
model.navigationService.back();
// return true;
}

View File

@ -0,0 +1,102 @@
import 'package:flutter/material.dart';
import 'package:reza_admin/app/themes/app_colors.dart';
import 'package:reza_admin/app/themes/app_text.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';
import './meja_edit_status_dialog_view_model.dart';
class MejaEditStatusDialogView extends StatelessWidget {
final DialogRequest? request;
final Function(DialogResponse)? completer;
const MejaEditStatusDialogView({
Key? key,
this.request,
this.completer,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return ViewModelBuilder<MejaEditStatusDialogViewModel>.reactive(
viewModelBuilder: () => MejaEditStatusDialogViewModel(),
onViewModelReady: (MejaEditStatusDialogViewModel model) async {
await model.init(request!.data);
},
builder: (
BuildContext context,
MejaEditStatusDialogViewModel model,
Widget? child,
) {
return Dialog(
child: Container(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'Edit Status',
style: regularTextStyle,
),
const SizedBox(height: 20),
DropdownButtonFormField<String>(
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Status',
),
value: model.status,
onChanged: (String? value) {
model.status = value!;
},
items: model.statusList.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value, style: regularTextStyle),
);
}).toList(),
),
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () {
completer!(DialogResponse(confirmed: false));
},
child: Text(
'Batal',
style: regularTextStyle.copyWith(color: redColor),
),
),
TextButton(
onPressed: () async {
bool res = await model.editStatus();
if (res) {
completer!(DialogResponse(
confirmed: true,
));
} else {
completer!(DialogResponse(
confirmed: false,
));
}
completer!(DialogResponse(
confirmed: true,
// responseData: model.status,
));
},
child: Text(
'Simpan',
style: regularTextStyle.copyWith(color: greenColor),
),
),
],
),
],
),
),
);
},
);
}
}

View File

@ -0,0 +1,39 @@
import 'package:dio/dio.dart';
import '../../../../../app/app.logger.dart';
import '../../../../../app/core/custom_base_view_model.dart';
class MejaEditStatusDialogViewModel extends CustomBaseViewModel {
final log = getLogger('MejaEditStatusDialogViewModel');
int? idMeja;
String status = 'Tersedia';
List<String> statusList = ['Tersedia', 'Tidak Tersedia'];
Future<void> init(data) async {
log.i("data : ${data['idMeja']}");
idMeja = data['idMeja'];
}
Future<bool> editStatus() async {
easyLoading.showLoading();
setBusy(true);
try {
var formData = FormData.fromMap({
'id_meja': idMeja,
'status': status,
});
var response = await httpService.postWithFormData(
'table/reservation/$idMeja', formData);
log.i('response : $response');
return true;
} catch (e) {
log.e('error : $e');
return false;
} finally {
setBusy(false);
easyLoading.dismiss();
}
}
}

View File

@ -55,10 +55,7 @@ class MejaListView extends StatelessWidget {
// initialUrl: 'https://rekam-medis.airlangga-it.com/',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
// _controller.complete(webViewController);
// model.controllerCompleter.future
// .then((value) => model.webViewController = value);
// model.controllerCompleter.complete(webViewController);
model.webViewController = webViewController;
},
onProgress: (int progress) {
// model.log.i('WebView is loading (progress : $progress%)');
@ -101,7 +98,7 @@ class MejaListView extends StatelessWidget {
},
onPageFinished: (String url) {
model.log.i('Page finished loading: $url');
model.easyLoading.dismissLoading();
model.easyLoading.dismiss();
},
gestureNavigationEnabled: true,
backgroundColor: const Color(0x00000000),
@ -169,64 +166,89 @@ class MejaListView extends StatelessWidget {
height: 15,
),
Expanded(
child: ListView.builder(
itemCount: 15,
shrinkWrap: true,
itemBuilder: (context, index) {
// make the color random between red and blue
final color = index % 2 == 0 ? Colors.red : Colors.blue;
String pesanStatus =
index % 2 == 0 ? 'Dibooking' : 'Menunggu Pengesahan';
return Card(
color: color,
child: ListTile(
leading: CircleAvatar(
backgroundColor: Colors.white,
child: Text(
index.toString(),
style: regularTextStyle,
),
),
title: Text(
'Nama Pemesan',
style: regularTextStyle.copyWith(
fontSize: 18,
color: Colors.white,
fontStyle: FontStyle.italic,
),
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'08:00.00 - 09:00.00',
style: TextStyle(
color: Colors.white,
child: model.isBusy
? const Center(
child: CircularProgressIndicator(),
)
: ListView.builder(
itemCount: model.reservasiMejaList.length,
shrinkWrap: true,
itemBuilder: (context, index) {
// make the color random between red and blue
final color =
model.reservasiMejaList[index].status ==
'booking'
? Colors.red
: (model.reservasiMejaList[index].status ==
'Tidak Tersedia'
? Colors.grey[600]
: Colors.green);
String pesanStatus = model
.reservasiMejaList[index].status!
.toUpperCase();
return Card(
color: color,
child: ListTile(
leading: CircleAvatar(
backgroundColor: Colors.white,
child: Text(
model.reservasiMejaList[index].idMeja
.toString(),
style: regularTextStyle,
),
),
),
Text(
pesanStatus,
style: const TextStyle(
color: Colors.white,
title: Text(
model.userModelList[index] != null
? model.userModelList[index]!.nama ?? '-'
: '-',
style: regularTextStyle.copyWith(
fontSize: 18,
color: Colors.white,
fontStyle: FontStyle.italic,
),
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
model.reservasiMejaList[index]
.jamBooking ??
'',
style: const TextStyle(
color: Colors.white,
),
),
Text(
pesanStatus,
style: const TextStyle(
color: Colors.white,
),
),
],
),
trailing: const Icon(Icons.arrow_forward_ios,
color: Colors.white),
onTap: () {
model.log.i('Meja 1');
},
),
],
),
trailing: const Icon(Icons.arrow_forward_ios,
color: Colors.white),
onTap: () {
model.log.i('Meja 1');
);
},
),
);
},
),
),
const SizedBox(
height: 15,
),
],
),
// floatingActionButton: FloatingActionButton(
// onPressed: () async {
// await model.webViewController!.reload();
// },
// backgroundColor: mainColor,
// child: const Icon(Icons.add),
// ),
),
);
},

View File

@ -1,10 +1,78 @@
import 'package:reza_admin/app/app.locator.dart';
import 'package:reza_admin/app/app.logger.dart';
import 'package:reza_admin/model/my_model.dart';
import 'package:reza_admin/model/reservasi_meja_model.dart';
import 'package:reza_admin/model/user_model.dart';
import 'package:webview_flutter/webview_flutter.dart';
import '../../../../app/core/custom_base_view_model.dart';
import '../../../../services/my_socket_io_client.dart';
class MejaListViewModel extends CustomBaseViewModel {
final log = getLogger('MejaListViewModel');
WebViewController? webViewController;
final socketIoClient = locator<MySocketIoClient>();
List<ReservasiMejaModel> reservasiMejaList = [];
List<UserModel?> userModelList = [];
Future<void> init() async {
globalVar.backPressed = 'exitApp';
socketIoClient.on('table_admin', (data) {
log.i('data : $data');
getData();
webViewController!.reload();
});
getData();
}
getData() async {
setBusy(true);
easyLoading.showLoading();
try {
var response = await httpService.get('table/detail');
// log.i('response : ${response.data}');
MyModel myModel = MyModel.fromJson(response.data);
if (myModel.data != null) {
for (var item in myModel.data!) {
reservasiMejaList.add(ReservasiMejaModel.fromJson(item));
}
// log.i('reservasiMejaList : $reservasiMejaList');
}
for (var item in reservasiMejaList) {
if (item.idUser != null) {
UserModel? userModel = await getUserDetail(item.idUser!);
userModelList.add(userModel!);
} else {
userModelList.add(null);
}
}
log.i('userModelList : $userModelList');
} catch (e) {
log.e(e);
} finally {
setBusy(false);
easyLoading.dismiss();
}
}
Future<UserModel?> getUserDetail(int id) async {
setBusy(true);
easyLoading.showLoading();
try {
var response = await httpService.get('table/user/$id');
log.i('response : ${response.data}');
MyModel myModel = MyModel.fromJson(response.data);
return UserModel.fromJson(myModel.data);
} catch (e) {
log.e(e);
return null;
} finally {
setBusy(false);
easyLoading.dismiss();
// return null;
}
}
}