add flow notes

This commit is contained in:
JMARyA 2024-09-25 09:02:50 +02:00
parent 097e6a6de5
commit 20bc5a9ae6
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 190 additions and 72 deletions

View file

@ -289,6 +289,18 @@ class API {
var resp = jsonDecode(await getRequest("$instance/location/$id")); var resp = jsonDecode(await getRequest("$instance/location/$id"));
return Location(resp); return Location(resp);
} }
Future<String> addNoteToFlow(String flowID, String content) async {
var res = jsonDecode(
await postRequest("$instance/flow/$flowID/note", {"content": content}));
return res["uuid"];
}
Future<List<FlowNote>> getNotesOfFlow(String flowID) async {
var resp = jsonDecode(await getRequest("$instance/flow/$flowID/notes"))
as List<dynamic>;
return resp.map((x) => FlowNote(x)).toList();
}
} }
class FlowInfo { class FlowInfo {
@ -483,6 +495,20 @@ class FlowDone {
} }
} }
class FlowNote {
late String uuid;
late int timestamp;
late String content;
late String onFlow;
FlowNote(Map<String, dynamic> json) {
uuid = json["uuid"];
timestamp = json["timestamp"];
content = json["content"];
onFlow = json["on_flow"];
}
}
class GlobalItemStat { class GlobalItemStat {
late int item_count; late int item_count;
late int total_transactions; late int total_transactions;

View file

@ -1,26 +1,37 @@
import 'package:cdb_ui/api.dart' as API; import 'package:cdb_ui/api.dart' as API;
import 'package:cdb_ui/pages/flow/create_flow_page.dart'; 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/flow/end_flow_page.dart';
import 'package:cdb_ui/pages/flow/flow_note.dart';
import 'package:cdb_ui/pages/transaction.dart'; import 'package:cdb_ui/pages/transaction.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class ActiveFlowPage extends StatelessWidget { class ActiveFlowPage extends StatefulWidget {
final API.Flow flow; final API.Flow flow;
final API.FlowInfo info; final API.FlowInfo info;
const ActiveFlowPage(this.flow, this.info, {super.key}); const ActiveFlowPage(this.flow, this.info, {super.key});
@override
State<ActiveFlowPage> createState() => _ActiveFlowPageState();
}
class _ActiveFlowPageState extends State<ActiveFlowPage> {
_refresh() {
setState(() {});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(info.name), title: Text(widget.info.name),
actions: [ actions: [
IconButton( IconButton(
onPressed: () async { onPressed: () async {
if (info.produces?.isNotEmpty ?? false) { if (widget.info.produces?.isNotEmpty ?? false) {
Navigator.of(context).push(MaterialPageRoute( Navigator.of(context).push(MaterialPageRoute(
builder: (context) => EndFlowWithProduce(flow, info))); builder: (context) =>
EndFlowWithProduce(widget.flow, widget.info)));
return; return;
} }
@ -46,47 +57,71 @@ class ActiveFlowPage extends StatelessWidget {
if (confirm) { if (confirm) {
await API await API
.API() .API()
.endFlow(flow.id) .endFlow(widget.flow.id)
.then((x) => Navigator.of(context).pop()); .then((x) => Navigator.of(context).pop());
} }
}, },
icon: const Icon(Icons.stop)), icon: const Icon(Icons.stop)),
// todo : continue next flow // todo : continue next flow
if (info.next != null) if (widget.info.next != null)
IconButton( IconButton(
onPressed: () { onPressed: () {
API.API().getFlowInfo(info.next!).then((newInfo) { API.API().getFlowInfo(widget.info.next!).then((newInfo) {
Navigator.of(context).push(MaterialPageRoute( Navigator.of(context).push(MaterialPageRoute(
builder: (context) { builder: (context) {
return CreateFlowPage( return CreateFlowPage(
newInfo, newInfo,
() {}, () {},
previousFlow: flow, previousFlow: widget.flow,
); );
}, },
)); ));
}); });
}, },
icon: const Icon(Icons.arrow_forward)), icon: const Icon(Icons.arrow_forward)),
// todo : add notes to flow
IconButton(onPressed: () {}, icon: const Icon(Icons.note))
], ],
), ),
body: Column( body: Column(
children: [ children: [
Text("ID: ${flow.id}"), Text("ID: ${widget.flow.id}"),
Text("Started since: ${tsFormat(flow.started)}"), Text("Started since: ${tsFormat(widget.flow.started)}"),
...flow.input!.map((x) => Text("Input: $x")).toList(), ...widget.flow.input!.map((x) => Text("Input: $x")).toList(),
if (flow.done != null) ...[ if (widget.flow.done != null) ...[
Text("Ended: ${tsFormat(flow.done!.ended)}"), Text("Ended: ${tsFormat(widget.flow.done!.ended)}"),
if (flow.done!.next != null) Text("Next: ${flow.done!.next!}"), if (widget.flow.done!.next != null)
...flow.done!.produced!.map((x) => Text("Produced: $x")).toList(), Text("Next: ${widget.flow.done!.next!}"),
...widget.flow.done!.produced!
.map((x) => Text("Produced: $x"))
.toList(),
], ],
const Divider(), const Divider(),
// todo : show notes FutureBuilder(
future: API.API().getNotesOfFlow(widget.flow.id),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const CircularProgressIndicator();
}
var data = snapshot.data!;
return Expanded(
child: ListView(
children: data
.map(
(x) => FlowNoteCard(x),
)
.toList()));
},
)
], ],
)); ),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => AddNotePage(widget.flow, _refresh)));
},
child: const Icon(Icons.note_add),
),
);
} }
} }

View file

@ -0,0 +1,57 @@
import 'package:cdb_ui/pages/transaction.dart';
import 'package:flutter/material.dart';
import 'package:cdb_ui/api.dart' as API;
class AddNotePage extends StatelessWidget {
late final TextEditingController _noteController = TextEditingController();
final API.Flow flow;
final Function refresh;
AddNotePage(this.flow, this.refresh, {super.key});
_submit(BuildContext context) {
API.API().addNoteToFlow(flow.id, _noteController.text).then((x) {
refresh();
Navigator.of(context).pop();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Add Note"),
),
body: Column(
children: [
TextFormField(
decoration: const InputDecoration(labelText: 'Note'),
controller: _noteController,
maxLines: 10),
const SizedBox(
height: 14,
),
ElevatedButton(
onPressed: _submit(context), child: const Text("Add Note"))
],
),
);
}
}
class FlowNoteCard extends StatelessWidget {
final API.FlowNote note;
const FlowNoteCard(this.note, {super.key});
@override
Widget build(BuildContext context) {
return Card(
child: ListTile(
title: Text(tsFormat(note.timestamp),
style: const TextStyle(fontSize: 12)),
subtitle: Text(note.content, overflow: TextOverflow.ellipsis),
),
);
}
}

View file

@ -179,8 +179,8 @@ class _SupplyPageState extends State<SupplyPage> {
// Note // Note
TextFormField( TextFormField(
decoration: const InputDecoration(labelText: 'Note'), decoration: const InputDecoration(labelText: 'Note'),
keyboardType: TextInputType.number,
controller: _noteController, controller: _noteController,
maxLines: 5
), ),
const SizedBox(height: 20), const SizedBox(height: 20),