From 80895d4d71401bf41646ac52df67d9099f737a84 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Thu, 19 Sep 2024 08:46:48 +0200 Subject: [PATCH] flows --- lib/api.dart | 35 +++++++++++++++++++ lib/main.dart | 28 +--------------- lib/pages/flow.dart | 82 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 27 deletions(-) create mode 100644 lib/pages/flow.dart diff --git a/lib/api.dart b/lib/api.dart index dc7b14b..a9fe7c7 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -212,6 +212,13 @@ class API { return FlowInfo(jsonDecode(await getRequest("$instance/flow/$id/info"))); } + Future> getActiveFlowsOf(String id) async { + var res = jsonDecode(await getRequest("$instance/flow/$id/active")) + as List; + + return res.map((x) => Flow(x)).toList(); + } + // /flow/ Future startFlow(String id, {List? input}) async { var resp = @@ -415,3 +422,31 @@ class MinItem { need = json["need"]; } } + +class Flow { + late String id; + late int started; + late String kind; + late List? input; + late FlowDone? done; + + Flow(Map json) { + id = json["id"]; + started = json["started"]; + kind = json["kind"]; + input = json["input"]; + done = (json["done"] != null) ? FlowDone(json["done"]) : null; + } +} + +class FlowDone { + late int ended; + late String? next; + late List? produced; + + FlowDone(Map json) { + ended = json["ended"]; + next = json["next"]; + produced = json["produced"]; + } +} diff --git a/lib/main.dart b/lib/main.dart index 1f079ec..e7df1da 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'package:cdb_ui/api.dart'; +import 'package:cdb_ui/pages/flow.dart'; import 'package:cdb_ui/pages/itemview.dart'; import 'package:cdb_ui/pages/setup.dart'; import 'package:flutter/material.dart'; @@ -78,33 +79,6 @@ class StatsPage extends StatelessWidget { } } -class FlowsPage extends StatelessWidget { - const FlowsPage({super.key}); - - @override - Widget build(BuildContext context) { - // todo : add flow list - // todo : flows by item produced - // todo : flow page - return Scaffold( - appBar: AppBar(title: const Text("Flows")), - body: FutureBuilder( - future: API().getFlows(), - builder: (ctx, snap) { - if (!snap.hasData) { - return const CircularProgressIndicator(); - } - - var data = snap.data!; - - return ListView( - children: data.values.map((x) { - return ListTile(title: Text(x.name)); - }).toList()); - })); - } -} - class LocationsPage extends StatelessWidget { const LocationsPage({super.key}); diff --git a/lib/pages/flow.dart b/lib/pages/flow.dart new file mode 100644 index 0000000..b57b710 --- /dev/null +++ b/lib/pages/flow.dart @@ -0,0 +1,82 @@ +import 'package:cdb_ui/api.dart'; +import 'package:flutter/material.dart'; + +class FlowsPage extends StatelessWidget { + const FlowsPage({super.key}); + + @override + Widget build(BuildContext context) { + // todo : flows by item produced + return Scaffold( + appBar: AppBar(title: const Text("Flows")), + body: FutureBuilder( + future: API().getFlows(), + builder: (ctx, snap) { + if (!snap.hasData) { + return const CircularProgressIndicator(); + } + + var data = snap.data!; + + return ListView( + children: data.values.map((x) { + return ListTile( + title: Text(x.name), + onTap: () { + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => FlowPage(x), + )); + }, + ); + }).toList()); + })); + } +} + +class FlowPage extends StatelessWidget { + final FlowInfo info; + + const FlowPage(this.info, {super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: Text(info.name)), + body: Column( + children: [ + // todo : ui improve + if (info.next != null) Text("Next: ${info.next}"), + if (info.depends.isNotEmpty) + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + const Text("Flow can use: "), + ...info.depends.map((x) => Text(x)).toList(), + ], + ), + if (info.produces?.isNotEmpty ?? false) + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + const Text("Flow can produce: "), + ...info.produces!.map((x) => Text(x)).toList(), + ], + ), + const Divider(), + FutureBuilder( + future: API().getActiveFlowsOf(info.id), + builder: (context, snapshot) { + if (!snapshot.hasData) { + return const CircularProgressIndicator(); + } + + var data = snapshot.data!; + + return ListView(children: data.map((x) => Text(x.id)).toList()); + }, + ) + ], + ), + ); + } +}