From 8d16949f403f6ef68cc43b56736585168a50e818 Mon Sep 17 00:00:00 2001 From: "Serik.Uvaissov" Date: Thu, 2 Jul 2020 15:21:36 +0600 Subject: [PATCH] - url redirect - auth message - update catalog --- lib/core/services/ApiService.dart | 16 +++++++--- lib/core/services/DataService.dart | 5 ---- lib/redux/actions/user_actions.dart | 13 +++++++-- lib/views/home/components/popup_menu.dart | 2 +- lib/views/home/tabs/AdditionalTab.dart | 29 +++++++++++++++++++ .../tabs/kassaView/ProductAddBottomSheet.dart | 4 +-- lib/views/login/login_view.dart | 22 ++++++++++---- lib/widgets/fields/aman_icon_button.dart | 28 +++++++++--------- 8 files changed, 85 insertions(+), 34 deletions(-) diff --git a/lib/core/services/ApiService.dart b/lib/core/services/ApiService.dart index 490fbe7..448b496 100644 --- a/lib/core/services/ApiService.dart +++ b/lib/core/services/ApiService.dart @@ -16,12 +16,17 @@ import 'package:http/http.dart' as http; /// The service responsible for networking requests class ApiService extends BaseService { - static const endpoint = 'https://kassa-test.aman.com.kz/ru/api/v2'; + static const test_endpoint = 'https://kassa-test.aman.com.kz/ru/api/v2'; + static const endpoint = 'https://kassa.aman.com.kz/ru/api/v2'; final NavigatorService _navigatorService = locator(); final DialogService _dialogService = locator(); var client = new http.Client(); + bool _test = false; + bool get test => this._test; + set test(bool value) => this._test = value; + Future authenticate(String email, String password, { bool statusCheck = true}) async { Map requestBody = { 'email': email, @@ -43,7 +48,7 @@ class ApiService extends BaseService { Future> isActive(String token) async { Map requestBody = {'api_token': token}; - var response = await requestFormData('/test_auth', requestBody); + var response = await requestFormData('/test_auth', requestBody, statusCheck: false); return Response.fromJson(json.decode(response), Message.fromJson); } @@ -129,8 +134,11 @@ class ApiService extends BaseService { HttpHeaders.userAgentHeader: iosInfo.utsname.machine, }); } - - var uri = Uri.parse('$endpoint$point'); + String url = '$endpoint$point'; + if(this._test) { + url = '$test_endpoint$point'; + } + var uri = Uri.parse(url); var request = http.MultipartRequest('POST', uri) ..headers.addAll(headers) ..fields.addAll(requestBody); diff --git a/lib/core/services/DataService.dart b/lib/core/services/DataService.dart index 4e47198..7d0cee8 100644 --- a/lib/core/services/DataService.dart +++ b/lib/core/services/DataService.dart @@ -63,7 +63,6 @@ class DataService extends BaseService { if ((paymentType ?? 'cash') == 'card') { checkData.card = summ; } - print(checkData); return checkData; } @@ -88,7 +87,6 @@ class DataService extends BaseService { if ((paymentType ?? 'cash') == 'card') { checkData.card = summ; } - print(checkData); return checkData; } @@ -167,21 +165,18 @@ class DataService extends BaseService { await _db.deleteAll(Service_tableName); log.i('All tables cleaned'); for (var key in goods.body.keys) { - print(goods.body[key]); Good row = Good.fromJson(goods.body[key]); await _db.insert(Goog_tableName, row.toMap()); } log.i('Inserted ${goods.body.length} to table $Goog_tableName'); for (var el in categories.body) { - print(el); Category row = Category.fromJson(el); await _db.insert(Category_tableName, row.toMap()); } log.i('Inserted ${categories.body.length} to table $Category_tableName'); for (var key in services.body.keys) { - print(services.body[key]); Service row = Service.fromJson(services.body[key]); await _db.insert(Service_tableName, row.toMap()); } diff --git a/lib/redux/actions/user_actions.dart b/lib/redux/actions/user_actions.dart index e7ce7ab..e659481 100644 --- a/lib/redux/actions/user_actions.dart +++ b/lib/redux/actions/user_actions.dart @@ -31,11 +31,18 @@ final DialogService _dialogService = locator(); Future checkUserAction(Store store) async { store.dispatch(SetUserStateAction(UserState(isLoading: true))); try { - String token = store.state.userState.user?.token; + User user = store.state.userState.user; + String token = user?.token; bool isAuthenticated = false; if (token != null) { + if(user.email!=null && user.email.toLowerCase().trim().startsWith('test')){ + _api.test = true; + } else { + _api.test = false; + } Response session = await _api.isActive(token); isAuthenticated = "OK" == session.body.message; + } else { await Future.delayed(Duration(milliseconds: 2000)); } @@ -114,7 +121,7 @@ ThunkAction authenticateToken(String token) { ))); if (result.user == null && result.message != null) { _dialogService.showDialog( - title: 'Warning', buttonTitle: 'Ok', description: result.message); + title: 'Внимание', buttonTitle: 'Ok', description: 'Ошибка авторизации'); } if (result.user != null) { _navigation.replace(HomeViewRoute); @@ -146,7 +153,7 @@ ThunkAction authenticate(String email, String password) { ))); if (result.user == null && result.message != null) { _dialogService.showDialog( - title: 'Warning', buttonTitle: 'Ok', description: result.message); + title: 'Внимание', buttonTitle: 'Ok', description: 'Ошибка авторизации'); } if (result.user != null) { _navigation.replace(HomeViewRoute); diff --git a/lib/views/home/components/popup_menu.dart b/lib/views/home/components/popup_menu.dart index 0d5b1c8..432159b 100644 --- a/lib/views/home/components/popup_menu.dart +++ b/lib/views/home/components/popup_menu.dart @@ -3,7 +3,7 @@ import 'package:aman_kassa_flutter/shared/app_colors.dart'; import 'package:flutter/material.dart'; const List choices = const [ - const Choice(title: 'Обновить номенклатуру', icon: Icons.update, command: 'update'), + //const Choice(title: 'Обновить номенклатуру', icon: Icons.update, command: 'update'), //const Choice(title: 'Помощь', icon: Icons.help, command: 'help'), //const Choice(title: 'О Программе', icon: Icons.info_outline, command: 'info'), //const Choice(title: 'Язык', icon: Icons.language, command: 'language'), diff --git a/lib/views/home/tabs/AdditionalTab.dart b/lib/views/home/tabs/AdditionalTab.dart index 481012f..155f7d9 100644 --- a/lib/views/home/tabs/AdditionalTab.dart +++ b/lib/views/home/tabs/AdditionalTab.dart @@ -4,6 +4,7 @@ import 'package:aman_kassa_flutter/core/models/response.dart'; import 'package:aman_kassa_flutter/core/models/dialog_models.dart'; import 'package:aman_kassa_flutter/core/route_names.dart'; import 'package:aman_kassa_flutter/core/services/ApiService.dart'; +import 'package:aman_kassa_flutter/core/services/DataService.dart'; import 'package:aman_kassa_flutter/core/services/dialog_service.dart'; import 'package:aman_kassa_flutter/core/services/navigator_service.dart'; import 'package:aman_kassa_flutter/redux/actions/user_actions.dart'; @@ -17,6 +18,7 @@ import 'package:aman_kassa_flutter/views/check/image_show_container.dart'; import 'package:aman_kassa_flutter/widgets/fields/aman_icon_button.dart'; import 'package:aman_kassa_flutter/widgets/fields/aman_icon_button_horizontal.dart'; import 'package:aman_kassa_flutter/widgets/fields/busy_button.dart'; +import 'package:aman_kassa_flutter/widgets/loader/Dialogs.dart'; import 'package:flutter/material.dart'; import 'package:flutter_redux/flutter_redux.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; @@ -34,6 +36,8 @@ class _AdditionalTabState extends State { ApiService _api = locator(); NavigatorService _navigator = locator(); DialogService _dialog = locator(); + DataService _dataService = locator(); + final GlobalKey _keyLoader = new GlobalKey(); bool isMoneyCheckBusy; bool closeSmenaBusy; @@ -41,6 +45,7 @@ class _AdditionalTabState extends State { bool depositBusy; bool withdrawalBusy; bool xReportBusy; + bool updateCatalog; @override void initState() { @@ -51,6 +56,7 @@ class _AdditionalTabState extends State { depositBusy = false; withdrawalBusy = false; xReportBusy = false; + updateCatalog = false; } void _closeSmena() async { @@ -90,6 +96,20 @@ class _AdditionalTabState extends State { }); } + void _updateCatalog() async { + setState(() { + updateCatalog = true; + }); + Dialogs.showLoadingDialog(context, _keyLoader); + bool result = await _dataService.getDataFromServer(Redux.store.state.userState.user); + Navigator.of(_keyLoader.currentContext, rootNavigator: true).pop(); + setState(() { + updateCatalog = false; + }); + } + + + void _deposit() async { setState(() { depositBusy = true; @@ -255,6 +275,7 @@ class _AdditionalTabState extends State { verticalSpaceMedium, Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, + crossAxisAlignment: CrossAxisAlignment.start, children: [ AmanIconButton( title: 'Открыть смену', @@ -282,6 +303,7 @@ class _AdditionalTabState extends State { verticalSpaceTiny, Row( mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, children: [ AmanIconButton( title: 'Х Отчет', @@ -290,6 +312,13 @@ class _AdditionalTabState extends State { mainColor: primaryColor, icon: Icons.description, ), + AmanIconButton( + title: 'Обновить номенклатуру', + onPressed: _updateCatalog, + busy: updateCatalog, + mainColor: greenColor, + icon: MdiIcons.databaseRefresh, + ), ], ), verticalSpaceMedium, diff --git a/lib/views/home/tabs/kassaView/ProductAddBottomSheet.dart b/lib/views/home/tabs/kassaView/ProductAddBottomSheet.dart index a78f246..e3282e7 100644 --- a/lib/views/home/tabs/kassaView/ProductAddBottomSheet.dart +++ b/lib/views/home/tabs/kassaView/ProductAddBottomSheet.dart @@ -74,7 +74,7 @@ class _ProductAddBottomSheetState extends State { labelText: 'Количество', prefixText: ' ', ), - keyboardType: TextInputType.number, + keyboardType: const TextInputType.numberWithOptions(decimal: false,), inputFormatters: [ WhitelistingTextInputFormatter.digitsOnly ], @@ -90,7 +90,7 @@ class _ProductAddBottomSheetState extends State { labelText: 'Стоимость', prefixText: ' ', ), - keyboardType: TextInputType.number, + keyboardType: const TextInputType.numberWithOptions(decimal: true), inputFormatters: [ WhitelistingTextInputFormatter(RegExp("^[0-9.]*")), ], diff --git a/lib/views/login/login_view.dart b/lib/views/login/login_view.dart index f87035f..f5c4d1e 100644 --- a/lib/views/login/login_view.dart +++ b/lib/views/login/login_view.dart @@ -1,6 +1,7 @@ import 'dart:ui'; import 'package:aman_kassa_flutter/core/locator.dart'; +import 'package:aman_kassa_flutter/core/services/ApiService.dart'; import 'package:aman_kassa_flutter/core/services/dialog_service.dart'; import 'package:aman_kassa_flutter/redux/actions/user_actions.dart'; import 'package:aman_kassa_flutter/redux/state/user_state.dart'; @@ -25,6 +26,7 @@ class LoginView extends StatelessWidget { final FocusNode passwordNode = new FocusNode(); final GlobalKey _scaffoldKey = new GlobalKey(); final DialogService _dialogService = locator(); + final ApiService _apiService = locator(); @override Widget build(BuildContext context) { @@ -97,6 +99,11 @@ class LoginView extends StatelessWidget { } _pressBtnEnter() async { + if(emailController.text!=null && emailController.text.toLowerCase().trim().startsWith('test')){ + _apiService.test = true; + } else { + _apiService.test = false; + } Redux.store .dispatch(authenticate(emailController.text, passwordController.text)); } @@ -109,13 +116,18 @@ class LoginView extends StatelessWidget { "flash_off": 'Выкл фонарик', }); var result = await BarcodeScanner.scan(options: options); - print(result.type); // The result type (barcode, cancelled, failed) - print(result.rawContent); // The barcode content - print(result.format); // The barcode format (as enum) - print(result - .formatNote); // If a unknown format was scanned this field contains a note + // print(result.type); // The result type (barcode, cancelled, failed) + // print(result.rawContent); // The barcode content + // print(result.format); // The barcode format (as enum) + // print(result + // .formatNote); // If a unknown format was scanned this field contains a note if (result.type == ResultType.Barcode && result.rawContent?.length == 60) { + if(result.rawContent.toLowerCase().trim().startsWith('test')){ + _apiService.test = true; + } else { + _apiService.test = false; + } Redux.store.dispatch(authenticateToken(result.rawContent)); } else if (result.type == ResultType.Error ) { _dialogService.showDialog(description: 'Не верный формат QR кода'); diff --git a/lib/widgets/fields/aman_icon_button.dart b/lib/widgets/fields/aman_icon_button.dart index cd905ae..26acb4e 100644 --- a/lib/widgets/fields/aman_icon_button.dart +++ b/lib/widgets/fields/aman_icon_button.dart @@ -36,7 +36,7 @@ class _AmanIconButtonState extends State { width: 120, alignment: Alignment.center, padding: EdgeInsets.symmetric( - horizontal: 25, + //horizontal: 25, vertical: 15), decoration: BoxDecoration( //color: widget.enabled ? ( whiteColor ) : blueColorLigth, @@ -44,19 +44,19 @@ class _AmanIconButtonState extends State { //boxShadow: [buttonShadowBox], ), child: Column( - children: [ - (!widget.busy - ? Icon( - widget.icon, - color: widget.mainColor, - size: 36, - ) - : CircularProgressIndicator( - strokeWidth: 3, - valueColor: AlwaysStoppedAnimation(widget.mainColor))), - Text(widget.title, style: TextStyle(color: widget.mainColor, fontSize: 15, fontWeight: FontWeight.bold, ), textAlign: TextAlign.center,) - ], - ), + children: [ + (!widget.busy + ? Icon( + widget.icon, + color: widget.mainColor, + size: 36, + ) + : CircularProgressIndicator( + strokeWidth: 3, + valueColor: AlwaysStoppedAnimation(widget.mainColor))), + Text(widget.title, overflow: TextOverflow.fade, maxLines: 2, style: TextStyle(color: widget.mainColor, fontSize: 14, fontWeight: FontWeight.w800, ), textAlign: TextAlign.center,) + ], + ), ), ), );