mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-17 04:35:26 +00:00
Allow model class to be filtered
- Each subclass should provide a custom filtering function
This commit is contained in:
@ -142,6 +142,25 @@ class InvenTreeModel {
|
||||
|
||||
// TODO - Define a 'save' / 'update' function
|
||||
|
||||
// Override this function for each sub-class
|
||||
bool matchAgainstString(String filter) => false;
|
||||
|
||||
// Filter this item against a list of provided filters
|
||||
// Each filter must be matched
|
||||
// Used for (e.g.) filtering returned results
|
||||
bool filter(String filterString) {
|
||||
|
||||
List<String> filters = filterString.trim().toLowerCase().split(" ");
|
||||
|
||||
for (var f in filters) {
|
||||
if (!matchAgainstString(f)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,15 @@ class InvenTreeStockLocation extends InvenTreeModel {
|
||||
var loc = InvenTreeStockLocation.fromJson(json);
|
||||
|
||||
return loc;
|
||||
}
|
||||
|
||||
@override
|
||||
bool matchAgainstString(String filter) {
|
||||
|
||||
if (name.toLowerCase().contains(filter)) return true;
|
||||
|
||||
if (description.toLowerCase().contains(filter)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user