92 lines
3.3 KiB
Dart
92 lines
3.3 KiB
Dart
import 'package:cdb_ui/api.dart' as API;
|
|
import 'package:cdb_ui/pages/flow/create_flow_page.dart';
|
|
import 'package:cdb_ui/pages/flow/end_flow_page.dart';
|
|
import 'package:cdb_ui/pages/transaction.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class ActiveFlowPage extends StatelessWidget {
|
|
final API.Flow flow;
|
|
final API.FlowInfo info;
|
|
|
|
const ActiveFlowPage(this.flow, this.info, {super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(info.name),
|
|
actions: [
|
|
IconButton(
|
|
onPressed: () async {
|
|
if (info.produces?.isNotEmpty ?? false) {
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
builder: (context) => EndFlowWithProduce(flow, info)));
|
|
return;
|
|
}
|
|
|
|
// simple dialog
|
|
var confirm = await showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('Are you sure?'),
|
|
content: const Text('This will end the flow.'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(false),
|
|
child: const Text('Cancel'),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () => Navigator.of(context).pop(true),
|
|
child: const Text('End'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
if (confirm) {
|
|
await API
|
|
.API()
|
|
.endFlow(flow.id)
|
|
.then((x) => Navigator.of(context).pop());
|
|
}
|
|
},
|
|
icon: const Icon(Icons.stop)),
|
|
// todo : continue next flow
|
|
if (info.next != null)
|
|
IconButton(
|
|
onPressed: () {
|
|
API.API().getFlowInfo(info.next!).then((newInfo) {
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
builder: (context) {
|
|
return CreateFlowPage(
|
|
newInfo,
|
|
() {},
|
|
previousFlow: flow,
|
|
);
|
|
},
|
|
));
|
|
});
|
|
},
|
|
icon: const Icon(Icons.arrow_forward)),
|
|
|
|
// todo : add notes to flow
|
|
IconButton(onPressed: () {}, icon: const Icon(Icons.note))
|
|
],
|
|
),
|
|
body: Column(
|
|
children: [
|
|
Text("ID: ${flow.id}"),
|
|
Text("Started since: ${tsFormat(flow.started)}"),
|
|
...flow.input!.map((x) => Text("Input: $x")).toList(),
|
|
if (flow.done != null) ...[
|
|
Text("Ended: ${tsFormat(flow.done!.ended)}"),
|
|
if (flow.done!.next != null) Text("Next: ${flow.done!.next!}"),
|
|
...flow.done!.produced!.map((x) => Text("Produced: $x")).toList(),
|
|
],
|
|
|
|
const Divider(),
|
|
// todo : show notes
|
|
],
|
|
));
|
|
}
|
|
}
|