mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Refactor locate function
This commit is contained in:
parent
03c6de8255
commit
5ba887d59b
78
lib/api.dart
78
lib/api.dart
@ -22,6 +22,8 @@ import "package:inventree/user_profile.dart";
|
|||||||
import "package:inventree/widget/snacks.dart";
|
import "package:inventree/widget/snacks.dart";
|
||||||
import "package:path_provider/path_provider.dart";
|
import "package:path_provider/path_provider.dart";
|
||||||
|
|
||||||
|
import 'api_form.dart';
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing an API response from the server
|
* Class representing an API response from the server
|
||||||
@ -1200,4 +1202,80 @@ class InvenTreeAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a request to the server to locate / identify either a StockItem or StockLocation
|
||||||
|
*/
|
||||||
|
Future<void> locateItemOrLocation(BuildContext context, {int? item, int? location}) async {
|
||||||
|
|
||||||
|
var plugins = getPlugins(mixin: "locate");
|
||||||
|
|
||||||
|
print("locateItemOrLocation");
|
||||||
|
|
||||||
|
if (plugins.isEmpty) {
|
||||||
|
// TODO: Error message
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String plugin_name = "";
|
||||||
|
|
||||||
|
if (plugins.length == 1) {
|
||||||
|
plugin_name = plugins.first.key;
|
||||||
|
} else {
|
||||||
|
// User selects which plugin to use
|
||||||
|
List<Map<String, dynamic>> plugin_options = [];
|
||||||
|
|
||||||
|
for (var plugin in plugins) {
|
||||||
|
plugin_options.add({
|
||||||
|
"display_name": plugin.humanName,
|
||||||
|
"value": plugin.key,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> fields = {
|
||||||
|
"plugin": {
|
||||||
|
"label": L10().plugin,
|
||||||
|
"type": "choice",
|
||||||
|
"value": plugins.first.key,
|
||||||
|
"choices": plugin_options,
|
||||||
|
"required": true,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await launchApiForm(
|
||||||
|
context,
|
||||||
|
L10().locateLocation,
|
||||||
|
"",
|
||||||
|
fields,
|
||||||
|
icon: FontAwesomeIcons.searchLocation,
|
||||||
|
onSuccess: (Map<String, dynamic> data) async {
|
||||||
|
plugin_name = (data["plugin"] ?? "") as String;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> body = {
|
||||||
|
"plugin": plugin_name,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (item != null) {
|
||||||
|
body["item"] = item.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location != null) {
|
||||||
|
body["location"] = location.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
post(
|
||||||
|
"/api/locate/",
|
||||||
|
body: body,
|
||||||
|
expectedStatusCode: 200,
|
||||||
|
).then((APIResponse response) {
|
||||||
|
if (response.successful()) {
|
||||||
|
showSnackIcon(
|
||||||
|
L10().requestSuccessful,
|
||||||
|
success: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -707,6 +707,9 @@
|
|||||||
"request": "Request",
|
"request": "Request",
|
||||||
"@request": {},
|
"@request": {},
|
||||||
|
|
||||||
|
"requestSuccessful": "Request successful",
|
||||||
|
"@requestSuccessful": {},
|
||||||
|
|
||||||
"requestingData": "Requesting Data",
|
"requestingData": "Requesting Data",
|
||||||
"@requestingData": {},
|
"@requestingData": {},
|
||||||
|
|
||||||
|
@ -92,69 +92,21 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Request identification of this location
|
||||||
|
*/
|
||||||
Future<void> _locateStockLocation(BuildContext context) async {
|
Future<void> _locateStockLocation(BuildContext context) async {
|
||||||
|
|
||||||
final _loc = location;
|
final _loc = location;
|
||||||
|
|
||||||
if (_loc != null) {
|
if (_loc != null) {
|
||||||
|
InvenTreeAPI().locateItemOrLocation(context, location: _loc.pk);
|
||||||
final plugins = InvenTreeAPI().getPlugins(mixin: "locate");
|
|
||||||
|
|
||||||
if (plugins.isEmpty) {
|
|
||||||
// TODO: Error message here
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String plugin_name = "";
|
|
||||||
|
|
||||||
if (plugins.length == 1) {
|
|
||||||
plugin_name = plugins.first.key;
|
|
||||||
} else {
|
|
||||||
// User selects which plugin to use
|
|
||||||
List<Map<String, dynamic>> plugin_options = [];
|
|
||||||
|
|
||||||
for (var plugin in plugins) {
|
|
||||||
plugin_options.add({
|
|
||||||
"display_name": plugin.humanName,
|
|
||||||
"value": plugin.key,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, dynamic> fields = {
|
|
||||||
"plugin": {
|
|
||||||
"label": L10().plugin,
|
|
||||||
"type": "choice",
|
|
||||||
"value": plugins.first.key,
|
|
||||||
"choices": plugin_options,
|
|
||||||
"required": true,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
await launchApiForm(
|
|
||||||
context,
|
|
||||||
L10().locateLocation,
|
|
||||||
"",
|
|
||||||
fields,
|
|
||||||
icon: FontAwesomeIcons.searchLocation,
|
|
||||||
onSuccess: (Map<String, dynamic> data) async {
|
|
||||||
plugin_name = (data["plugin"] ?? "") as String;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
print("plugin: ${plugin_name}");
|
|
||||||
|
|
||||||
InvenTreeAPI().post(
|
|
||||||
"/api/locate/",
|
|
||||||
body: {
|
|
||||||
"plugin": plugin_name,
|
|
||||||
"location": "${_loc.pk}",
|
|
||||||
},
|
|
||||||
expectedStatusCode: 200,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Launch a dialog form to edit this stock location
|
||||||
|
*/
|
||||||
void _editLocationDialog(BuildContext context) {
|
void _editLocationDialog(BuildContext context) {
|
||||||
|
|
||||||
final _loc = location;
|
final _loc = location;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user