Commit 148f2434 authored by Nicolas Lenz's avatar Nicolas Lenz
Browse files

Locations, Deletion

parent 8d20b97c
Pipeline #435 passed with stage
in 6 minutes and 3 seconds
......@@ -21,14 +21,17 @@ final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
Future<List<LogEntry>> log = getLog();
Future<List<Container1>> containers = getContainers();
Future<List<Location1>> locations = getLocations();
class HomeState extends State<Home> {
int _currentIndex = 0;
final List<Widget> _children = [
ContainerList(key: PageStorageKey("page1")),
ContainerForm(addContainers, key: PageStorageKey("page2")),
ContainerForm(subContainers, key: PageStorageKey("page3")),
LogView(key: PageStorageKey("page4")),
LocationList(key: PageStorageKey("page2")),
ContainerForm(addContainers, key: PageStorageKey("page3")),
ContainerForm(subContainers, key: PageStorageKey("page4")),
LogView(key: PageStorageKey("page5")),
];
static const platformSpeech = const MethodChannel("com.eisfunke.wms/speech");
static const platformWms = const MethodChannel("com.eisfunke.wms/wms");
......@@ -103,7 +106,8 @@ class HomeState extends State<Home> {
onTap: (int index) => setState(() => _currentIndex = index),
currentIndex: _currentIndex,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(icon: Icon(Icons.search), title: Text("Container")),
BottomNavigationBarItem(icon: Icon(Icons.search), title: Text("Containers")),
BottomNavigationBarItem(icon: Icon(Icons.my_location), title: Text("Locations")),
BottomNavigationBarItem(icon: Icon(Icons.archive), title: Text("Put")),
BottomNavigationBarItem(icon: Icon(Icons.unarchive), title: Text("Pick")),
BottomNavigationBarItem(icon: Icon(Icons.list), title: Text("Log")),
......@@ -152,6 +156,40 @@ class _ContainerListState extends State<ContainerList> {
}
}
class LocationList extends StatefulWidget {
const LocationList({Key key}) : super(key: key);
@override
_LocationListState createState() => _LocationListState();
}
class _LocationListState extends State<LocationList> {
Future<void> _refresh() async {
setState(() {
locations = getLocations();
});
await locations;
}
@override
Widget build(BuildContext context) {
return RefreshIndicator(
onRefresh: _refresh,
child: FutureBuilder<List<Location1>>(
future: locations,
builder: (context, snapshot) {
if(snapshot.hasData) {
return ListView(children: snapshot.data.map((location) => LocationInfo(location)).toList());
} else if(snapshot.hasError) {
return ListView(children: <Widget>[Text("${snapshot.error}")]);
}
return Center(child: CircularProgressIndicator());
}
)
);
}
}
class ContainerInfo extends StatelessWidget {
final Container1 container;
......@@ -163,7 +201,91 @@ class ContainerInfo extends StatelessWidget {
title: Text("Container ${container.number}"),
subtitle: Column(
children: container.allocs.map((alloc) => Text("${alloc.amount} in ${alloc.location}")).toList(),
)
),
onLongPress: () {
showDialog(
context: context,
barrierDismissible: true,
builder: (BuildContext btx) {
return AlertDialog(
title: Text("Delete?"),
actions: <Widget>[
FlatButton(
child: Text("Cancel"),
onPressed: () {
Navigator.of(context).pop();
}
),
FlatButton(
child: Text("Delete"),
onPressed: () async {
Navigator.of(context).pop();
try {
await deleteContainer(this.container.number);
showMessage("Success!");
containers = getContainers();
locations = getLocations();
log = getLog();
} catch(e) {
showMessage(e.toString());
}
}
)
]
);
}
);
},
);
}
}
class LocationInfo extends StatelessWidget {
final Location1 location;
LocationInfo(this.location);
@override
Widget build(BuildContext context) {
return ListTile(
title: Text("Location ${location.name}"),
subtitle: Column(
children: location.allocs.map((alloc) => Text("${alloc.amount} of ${alloc.container}")).toList(),
),
onLongPress: () {
showDialog(
context: context,
barrierDismissible: true,
builder: (BuildContext btx) {
return AlertDialog(
title: Text("Delete?"),
actions: <Widget>[
FlatButton(
child: Text("Cancel"),
onPressed: () {
Navigator.of(context).pop();
}
),
FlatButton(
child: Text("Delete"),
onPressed: () async {
Navigator.of(context).pop();
try {
await deleteLocation(this.location.name);
showMessage("Success!");
containers = getContainers();
locations = getLocations();
log = getLog();
} catch(e) {
showMessage(e.toString());
}
}
)
]
);
}
);
}
);
}
}
......
......@@ -22,6 +22,37 @@ Future<List<Container1>> getContainers() async {
}
}
Future<List<Location1>> getLocations() async {
final response = await http.get(Uri.https(await getUrl(), "location"));
if(response.statusCode == 200) {
Iterable list = json.decode(response.body);
return list.map((alloc) => Location1.fromJson(alloc)).toList();
} else {
throw Exception("Connection error (HTTP ${response.statusCode}). Please check connection.");
}
}
Future<String> deleteContainer(int container) async {
final response = await http.delete(Uri.https(await getUrl(), "container/$container"));
if(response.statusCode == 200) {
return response.body;
} else {
throw Exception("Connection error (HTTP ${response.statusCode}). Please check connection.");
}
}
Future<String> deleteLocation(String location) async {
final response = await http.delete(Uri.https(await getUrl(), "container/$location"));
if(response.statusCode == 200) {
return response.body;
} else {
throw Exception("Connection error (HTTP ${response.statusCode}). Please check connection.");
}
}
Future<List<String>> getLocationsByContainer(int container) async {
final response = await http.get(Uri.https(await getUrl(), "container/$container"));
......@@ -120,6 +151,23 @@ class Container1 {
String toString() => "Container $number: $allocs";
}
class Location1 {
final String name;
final List<LocationAllocation> allocs;
Location1(this.name, this.allocs);
factory Location1.fromJson(Map<String, dynamic> json) {
var list = json["allocations"] as List;
List<LocationAllocation> allocs = list.map((alloc) => LocationAllocation.fromJson(alloc)).toList();
return new Location1(json["location"], allocs);
}
@override
String toString() => "Location $name: $allocs";
}
class ContainerAllocation {
final String location;
final int amount;
......@@ -138,3 +186,22 @@ class ContainerAllocation {
@override
String toString() => "$amount in $location";
}
class LocationAllocation {
final int container;
final int amount;
LocationAllocation(this.container, this.amount);
LocationAllocation.fromJson(Map<String, dynamic> json) :
container = json["container"],
amount = json["amount"];
Map<String, dynamic> fromJson() => {
"container": container,
"amount": amount,
};
@override
String toString() => "$amount of $container";
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment