From 7155aaf6b96b964c1690b73e0958ccf66cc951d3 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Fri, 20 Sep 2024 08:52:56 +0200 Subject: [PATCH] update --- lib/api.dart | 29 +++++++++++++++++++++++++---- lib/main.dart | 19 +++++++++++++++++-- lib/pages/flow.dart | 35 ++++++++++++++++++++++++++++++----- 3 files changed, 72 insertions(+), 11 deletions(-) diff --git a/lib/api.dart b/lib/api.dart index a9fe7c7..72bc8e4 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -58,6 +58,11 @@ class API { return lst as List; } + Future getGlobalItemStat() async { + var resp = jsonDecode(await getRequest("$instance/items/stat")); + return GlobalItemStat(resp); + } + // /item///unique? Future> getUniqueField( String item, String variant, String field) async { @@ -112,10 +117,14 @@ class API { } // /item//inventory? - Future> getInventory(String item) async { - // todo : add origin param - var resp = jsonDecode(await getRequest("$instance/item/$item/inventory")) - as List; + Future> getInventory(String item, {String? origin}) async { + var url = "$instance/item/$item/inventory"; + + if (origin != null) { + url += "?origin=$origin"; + } + + var resp = jsonDecode(await getRequest(url)) as List; return resp.map((x) => Transaction(x)).toList(); } @@ -450,3 +459,15 @@ class FlowDone { produced = json["produced"]; } } + +class GlobalItemStat { + late int item_count; + late int total_transactions; + late double total_price; + + GlobalItemStat(Map json) { + item_count = json["item_count"]; + total_transactions = json["total_transactions"]; + total_price = json["total_price"]; + } +} diff --git a/lib/main.dart b/lib/main.dart index e7df1da..2ee0ade 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -29,8 +29,13 @@ class MyApp extends StatelessWidget { class StatsPage extends StatelessWidget { const StatsPage({super.key}); - Future<(List, List)> _fetchData() async { - return (await API().getItemsUnderMin(), await API().getExpiredItems()); + Future<(List, List, GlobalItemStat)> + _fetchData() async { + return ( + await API().getItemsUnderMin(), + await API().getExpiredItems(), + await API().getGlobalItemStat() + ); } @override @@ -50,9 +55,19 @@ class StatsPage extends StatelessWidget { var data = snapshot.data!; var min = data.$1; var expired = data.$2; + var global_stat = data.$3; return Column( children: [ + Card( + child: Column( + children: [ + Text("Items: ${global_stat.item_count}"), + Text("Inventory: ${global_stat.total_transactions}"), + Text("Price: ${global_stat.total_price} €") + ], + )), + if (min.isNotEmpty) const ListTile(title: Text("Items under Minimum")), ...min.map((item) { diff --git a/lib/pages/flow.dart b/lib/pages/flow.dart index b57b710..05c3b20 100644 --- a/lib/pages/flow.dart +++ b/lib/pages/flow.dart @@ -1,4 +1,4 @@ -import 'package:cdb_ui/api.dart'; +import 'package:cdb_ui/api.dart' as API; import 'package:flutter/material.dart'; class FlowsPage extends StatelessWidget { @@ -7,10 +7,13 @@ class FlowsPage extends StatelessWidget { @override Widget build(BuildContext context) { // todo : flows by item produced + // todo : list all flow kinds + // todo : list currently active + // todo : flows by item needed (show only avail) return Scaffold( appBar: AppBar(title: const Text("Flows")), body: FutureBuilder( - future: API().getFlows(), + future: API.API().getFlows(), builder: (ctx, snap) { if (!snap.hasData) { return const CircularProgressIndicator(); @@ -34,7 +37,7 @@ class FlowsPage extends StatelessWidget { } class FlowPage extends StatelessWidget { - final FlowInfo info; + final API.FlowInfo info; const FlowPage(this.info, {super.key}); @@ -64,7 +67,7 @@ class FlowPage extends StatelessWidget { ), const Divider(), FutureBuilder( - future: API().getActiveFlowsOf(info.id), + future: API.API().getActiveFlowsOf(info.id), builder: (context, snapshot) { if (!snapshot.hasData) { return const CircularProgressIndicator(); @@ -72,7 +75,15 @@ class FlowPage extends StatelessWidget { var data = snapshot.data!; - return ListView(children: data.map((x) => Text(x.id)).toList()); + return ListView( + children: data + .map((x) => ListTile( + title: Text(x.id), + onTap: () => + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => ActiveFlowPage(x), + )))) + .toList()); }, ) ], @@ -80,3 +91,17 @@ class FlowPage extends StatelessWidget { ); } } + +class ActiveFlowPage extends StatelessWidget { + late API.Flow flow; + + ActiveFlowPage(this.flow); + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Column( + children: [], + )); + } +}