mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Handle "filters" for related fields
This commit is contained in:
parent
2bdadc2140
commit
377da3c2fb
@ -46,6 +46,38 @@ class APIFormField {
|
|||||||
// Get the "default" as a string
|
// Get the "default" as a string
|
||||||
dynamic get defaultValue => data['default'];
|
dynamic get defaultValue => data['default'];
|
||||||
|
|
||||||
|
Map<String, String> get filters {
|
||||||
|
|
||||||
|
Map<String, String> _filters = {};
|
||||||
|
|
||||||
|
// Start with the provided "model" filters
|
||||||
|
if (data.containsKey("filters")) {
|
||||||
|
|
||||||
|
dynamic f = data["filters"];
|
||||||
|
|
||||||
|
if (f is Map) {
|
||||||
|
f.forEach((key, value) {
|
||||||
|
_filters[key] = value.toString();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now, look at the provided "instance_filters"
|
||||||
|
if (data.containsKey("instance_filters")) {
|
||||||
|
|
||||||
|
dynamic f = data["instance_filters"];
|
||||||
|
|
||||||
|
if (f is Map) {
|
||||||
|
f.forEach((key, value) {
|
||||||
|
_filters[key] = value.toString();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _filters;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool hasErrors() => errorMessages().length > 0;
|
bool hasErrors() => errorMessages().length > 0;
|
||||||
|
|
||||||
// Return the error message associated with this field
|
// Return the error message associated with this field
|
||||||
@ -61,9 +93,6 @@ class APIFormField {
|
|||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
dynamic get filters => null;
|
|
||||||
|
|
||||||
// Is this field required?
|
// Is this field required?
|
||||||
bool get required => (data['required'] ?? false) as bool;
|
bool get required => (data['required'] ?? false) as bool;
|
||||||
|
|
||||||
@ -107,11 +136,9 @@ class APIFormField {
|
|||||||
|
|
||||||
Map<String, String> _filters = {};
|
Map<String, String> _filters = {};
|
||||||
|
|
||||||
if (filters != null) {
|
filters.forEach((key, value) {
|
||||||
for (String key in filters) {
|
_filters[key] = value;
|
||||||
_filters[key] = filters[key].toString();
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_filters["search"] = filter;
|
_filters["search"] = filter;
|
||||||
_filters["offset"] = "0";
|
_filters["offset"] = "0";
|
||||||
@ -146,6 +173,19 @@ class APIFormField {
|
|||||||
itemAsString: (dynamic item) {
|
itemAsString: (dynamic item) {
|
||||||
return item['pathstring'];
|
return item['pathstring'];
|
||||||
},
|
},
|
||||||
|
popupItemBuilder: (context, item, isSelected) {
|
||||||
|
return ListTile(
|
||||||
|
title: Text(
|
||||||
|
item['pathstring'].toString(),
|
||||||
|
style: TextStyle(fontWeight: isSelected ? FontWeight.bold : FontWeight.normal),
|
||||||
|
),
|
||||||
|
subtitle: Text(item['description'].toString()),
|
||||||
|
trailing: Text(item['pk'].toString()),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onSaved: (item) {
|
||||||
|
data['value'] = item['pk'].toString();
|
||||||
|
},
|
||||||
isFilteredOnline: true,
|
isFilteredOnline: true,
|
||||||
showSearchBox: true,
|
showSearchBox: true,
|
||||||
autoFocusSearchBox: true,
|
autoFocusSearchBox: true,
|
||||||
@ -288,6 +328,19 @@ Future<void> launchApiForm(BuildContext context, String title, String url, Map<S
|
|||||||
for (String key in localField.keys) {
|
for (String key in localField.keys) {
|
||||||
// Special consideration must be taken here!
|
// Special consideration must be taken here!
|
||||||
if (key == "filters") {
|
if (key == "filters") {
|
||||||
|
|
||||||
|
if (!remoteField.containsKey("filters")) {
|
||||||
|
remoteField["filters"] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
var filters = localField["filters"];
|
||||||
|
|
||||||
|
if (filters is Map) {
|
||||||
|
filters.forEach((key, value) {
|
||||||
|
remoteField["filters"][key] = value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Custom filter updating
|
// TODO: Custom filter updating
|
||||||
} else {
|
} else {
|
||||||
remoteField[key] = localField[key];
|
remoteField[key] = localField[key];
|
||||||
|
@ -187,7 +187,10 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
"keywords": {},
|
"keywords": {},
|
||||||
"link": {},
|
"link": {},
|
||||||
|
|
||||||
"category": {},
|
"category": {
|
||||||
|
"filters": {
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// Checkbox fields
|
// Checkbox fields
|
||||||
"active": {},
|
"active": {},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user