flows
This commit is contained in:
parent
c1906abc5b
commit
80895d4d71
3 changed files with 118 additions and 27 deletions
35
lib/api.dart
35
lib/api.dart
|
@ -212,6 +212,13 @@ class API {
|
|||
return FlowInfo(jsonDecode(await getRequest("$instance/flow/$id/info")));
|
||||
}
|
||||
|
||||
Future<List<Flow>> getActiveFlowsOf(String id) async {
|
||||
var res = jsonDecode(await getRequest("$instance/flow/$id/active"))
|
||||
as List<dynamic>;
|
||||
|
||||
return res.map((x) => Flow(x)).toList();
|
||||
}
|
||||
|
||||
// /flow/<id>
|
||||
Future<String> startFlow(String id, {List<String>? 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<String>? input;
|
||||
late FlowDone? done;
|
||||
|
||||
Flow(Map<String, dynamic> 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<String>? produced;
|
||||
|
||||
FlowDone(Map<String, dynamic> json) {
|
||||
ended = json["ended"];
|
||||
next = json["next"];
|
||||
produced = json["produced"];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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});
|
||||
|
||||
|
|
82
lib/pages/flow.dart
Normal file
82
lib/pages/flow.dart
Normal file
|
@ -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());
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue