This commit is contained in:
JMARyA 2024-09-20 08:52:56 +02:00
parent 80895d4d71
commit 7155aaf6b9
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 72 additions and 11 deletions

View file

@ -58,6 +58,11 @@ class API {
return lst as List<dynamic>; return lst as List<dynamic>;
} }
Future<GlobalItemStat> getGlobalItemStat() async {
var resp = jsonDecode(await getRequest("$instance/items/stat"));
return GlobalItemStat(resp);
}
// /item/<item>/<variant>/unique?<field> // /item/<item>/<variant>/unique?<field>
Future<List<String>> getUniqueField( Future<List<String>> getUniqueField(
String item, String variant, String field) async { String item, String variant, String field) async {
@ -112,10 +117,14 @@ class API {
} }
// /item/<item_id>/inventory?<origin> // /item/<item_id>/inventory?<origin>
Future<List<Transaction>> getInventory(String item) async { Future<List<Transaction>> getInventory(String item, {String? origin}) async {
// todo : add origin param var url = "$instance/item/$item/inventory";
var resp = jsonDecode(await getRequest("$instance/item/$item/inventory"))
as List<dynamic>; if (origin != null) {
url += "?origin=$origin";
}
var resp = jsonDecode(await getRequest(url)) as List<dynamic>;
return resp.map((x) => Transaction(x)).toList(); return resp.map((x) => Transaction(x)).toList();
} }
@ -450,3 +459,15 @@ class FlowDone {
produced = json["produced"]; produced = json["produced"];
} }
} }
class GlobalItemStat {
late int item_count;
late int total_transactions;
late double total_price;
GlobalItemStat(Map<String, dynamic> json) {
item_count = json["item_count"];
total_transactions = json["total_transactions"];
total_price = json["total_price"];
}
}

View file

@ -29,8 +29,13 @@ class MyApp extends StatelessWidget {
class StatsPage extends StatelessWidget { class StatsPage extends StatelessWidget {
const StatsPage({super.key}); const StatsPage({super.key});
Future<(List<MinItem>, List<Transaction>)> _fetchData() async { Future<(List<MinItem>, List<Transaction>, GlobalItemStat)>
return (await API().getItemsUnderMin(), await API().getExpiredItems()); _fetchData() async {
return (
await API().getItemsUnderMin(),
await API().getExpiredItems(),
await API().getGlobalItemStat()
);
} }
@override @override
@ -50,9 +55,19 @@ class StatsPage extends StatelessWidget {
var data = snapshot.data!; var data = snapshot.data!;
var min = data.$1; var min = data.$1;
var expired = data.$2; var expired = data.$2;
var global_stat = data.$3;
return Column( return Column(
children: [ 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) if (min.isNotEmpty)
const ListTile(title: Text("Items under Minimum")), const ListTile(title: Text("Items under Minimum")),
...min.map((item) { ...min.map((item) {

View file

@ -1,4 +1,4 @@
import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/api.dart' as API;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class FlowsPage extends StatelessWidget { class FlowsPage extends StatelessWidget {
@ -7,10 +7,13 @@ class FlowsPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// todo : flows by item produced // todo : flows by item produced
// todo : list all flow kinds
// todo : list currently active
// todo : flows by item needed (show only avail)
return Scaffold( return Scaffold(
appBar: AppBar(title: const Text("Flows")), appBar: AppBar(title: const Text("Flows")),
body: FutureBuilder( body: FutureBuilder(
future: API().getFlows(), future: API.API().getFlows(),
builder: (ctx, snap) { builder: (ctx, snap) {
if (!snap.hasData) { if (!snap.hasData) {
return const CircularProgressIndicator(); return const CircularProgressIndicator();
@ -34,7 +37,7 @@ class FlowsPage extends StatelessWidget {
} }
class FlowPage extends StatelessWidget { class FlowPage extends StatelessWidget {
final FlowInfo info; final API.FlowInfo info;
const FlowPage(this.info, {super.key}); const FlowPage(this.info, {super.key});
@ -64,7 +67,7 @@ class FlowPage extends StatelessWidget {
), ),
const Divider(), const Divider(),
FutureBuilder( FutureBuilder(
future: API().getActiveFlowsOf(info.id), future: API.API().getActiveFlowsOf(info.id),
builder: (context, snapshot) { builder: (context, snapshot) {
if (!snapshot.hasData) { if (!snapshot.hasData) {
return const CircularProgressIndicator(); return const CircularProgressIndicator();
@ -72,7 +75,15 @@ class FlowPage extends StatelessWidget {
var data = snapshot.data!; 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: [],
));
}
}