Skip to content

Commit

Permalink
DEV-41047
Browse files Browse the repository at this point in the history
  • Loading branch information
DCrow committed Mar 31, 2022
1 parent 787e2c6 commit 1c7449d
Show file tree
Hide file tree
Showing 21 changed files with 316 additions and 110 deletions.
2 changes: 1 addition & 1 deletion lib/app/data/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class AppStorage extends _$AppStorage {
}

@override
int get schemaVersion => 1;
int get schemaVersion => 2;

@override
MigrationStrategy get migration => MigrationStrategy(
Expand Down
58 changes: 49 additions & 9 deletions lib/app/data/database.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/app/data/order_storages_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class OrderStoragesDao extends DatabaseAccessor<AppStorage> with _$OrderStorages
OrderStoragesDao(AppStorage db) : super(db);

Future<List<OrderStorage>> getOrderStorages() async {
return (select(orderStorages)..orderBy([(u) => OrderingTerm(expression: u.name)])).get();
return (select(orderStorages)..orderBy([(u) => OrderingTerm(expression: u.sequenceNumber)])).get();
}

Future<void> loadOrderStorages(List<OrderStorage> orderStorageList) async {
Expand Down
1 change: 1 addition & 0 deletions lib/app/data/schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class OrderLines extends Table {
class OrderStorages extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get name => text()();
IntColumn get sequenceNumber => integer()();
}

class JsonConverter extends TypeConverter<List<String>, String> {
Expand Down
8 changes: 6 additions & 2 deletions lib/app/entities/api_order_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ part of 'entities.dart';
class ApiOrderStorage {
final int id;
final String name;
final int sequenceNumber;

const ApiOrderStorage({
required this.id,
required this.name,
required this.sequenceNumber
});

factory ApiOrderStorage.fromJson(dynamic json) {
return ApiOrderStorage(
id: json['id'],
name: json['name']
name: json['name'],
sequenceNumber: json['sequenceNumber']
);
}

OrderStorage toDatabaseEnt() {
return OrderStorage(
id: id,
name: name
name: name,
sequenceNumber: sequenceNumber
);
}
}
8 changes: 6 additions & 2 deletions lib/app/pages/accept_payment/accept_payment_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AcceptPaymentViewModel extends PageViewModel<AcceptPaymentState, AcceptPay
Future<void> cancelPayment() async {
await iboxpro.cancelPayment();

emit(state.copyWith(message: 'Платеж отменен', canceled: true));
emit(state.copyWith(message: 'Платеж отменен', canceled: true, status: AcceptPaymentStateStatus.failure));
}

Future<void> _connectToDevice() async {
Expand Down Expand Up @@ -124,7 +124,11 @@ class AcceptPaymentViewModel extends PageViewModel<AcceptPaymentState, AcceptPay
}

Future<void> _savePayment([Map<dynamic, dynamic>? transaction]) async {
emit(state.copyWith(message: 'Сохранение информации об оплате', status: AcceptPaymentStateStatus.savingPayment));
emit(state.copyWith(
message: 'Сохранение информации об оплате',
status: AcceptPaymentStateStatus.savingPayment,
isCancelable: false
));

try {
await _acceptPayment(transaction);
Expand Down
2 changes: 2 additions & 0 deletions lib/app/pages/info/info_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class _InfoViewState extends State<_InfoView> {
return Card(
child: ListTile(
onTap: () {
if (vm.state.loading) return;

Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) => OrdersPage()));
},
isThreeLine: true,
Expand Down
10 changes: 7 additions & 3 deletions lib/app/pages/info/info_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,29 @@ class InfoState {
this.status = InfoStateStatus.initial,
this.ordersWithLines = const [],
this.newVersionAvailable = false,
this.message = ''
this.message = '',
this.loading = false
});

final List<OrderWithLines> ordersWithLines;
final bool newVersionAvailable;
final InfoStateStatus status;
final String message;
final bool loading;

InfoState copyWith({
InfoStateStatus? status,
List<OrderWithLines>? ordersWithLines,
bool? newVersionAvailable,
String? message
String? message,
bool? loading
}) {
return InfoState(
status: status ?? this.status,
ordersWithLines: ordersWithLines ?? this.ordersWithLines,
newVersionAvailable: newVersionAvailable ?? this.newVersionAvailable,
message: message ?? this.message
message: message ?? this.message,
loading: loading ?? this.loading
);
}
}
8 changes: 4 additions & 4 deletions lib/app/pages/info/info_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ class InfoViewModel extends PageViewModel<InfoState, InfoStateStatus> {
emit(state.copyWith(
status: InfoStateStatus.dataLoaded,
newVersionAvailable: await app.newVersionAvailable,
ordersWithLines: await app.storage.ordersDao.getOrdersWithLines(),
ordersWithLines: await app.storage.ordersDao.getOrdersWithLines()
));
}

Future<void> getData() async {
if (state.status == InfoStateStatus.inProgress) return;

emit(state.copyWith(status: InfoStateStatus.inProgress));
emit(state.copyWith(status: InfoStateStatus.inProgress, loading: true));

try {
await app.loadUserData();
await _getData();

emit(state.copyWith(status: InfoStateStatus.success, message: 'Данные успешно обновлены'));
emit(state.copyWith(status: InfoStateStatus.success, message: 'Данные успешно обновлены', loading: false));
} on AppError catch(e) {
emit(state.copyWith(status: InfoStateStatus.failure, message: e.message));
emit(state.copyWith(status: InfoStateStatus.failure, message: e.message, loading: false));
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/app/pages/login/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class _LoginViewState extends State<_LoginView> {
final TextEditingController _urlController = TextEditingController();

Future<void> openDialog() async {
showDialog(
showDialog<void>(
context: context,
builder: (_) => const Center(child: CircularProgressIndicator()),
barrierDismissible: false
Expand Down
Loading

0 comments on commit 1c7449d

Please sign in to comment.