mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-13 02:35:27 +00:00
Adds a function to return a list of plugins which support a specified mixin
This commit is contained in:
31
lib/api.dart
31
lib/api.dart
@ -235,7 +235,28 @@ class InvenTreeAPI {
|
|||||||
// Returns True only if the server API version is new enough, and plugins are enabled
|
// Returns True only if the server API version is new enough, and plugins are enabled
|
||||||
bool pluginsEnabled() => apiVersion >= 34 && _pluginsEnabled;
|
bool pluginsEnabled() => apiVersion >= 34 && _pluginsEnabled;
|
||||||
|
|
||||||
List<InvenTreePlugin> plugins = [];
|
// Cached list of plugins (refreshed when we connect to the server)
|
||||||
|
List<InvenTreePlugin> _plugins = [];
|
||||||
|
|
||||||
|
// Return a list of plugins enabled on the server
|
||||||
|
// Can optionally filter by a particular 'mixin' type
|
||||||
|
List<InvenTreePlugin> getPlugins({String mixin = ""}) {
|
||||||
|
List<InvenTreePlugin> plugins = [];
|
||||||
|
|
||||||
|
for (var plugin in _plugins) {
|
||||||
|
// Do we wish to filter by a particular mixin?
|
||||||
|
if (mixin.isNotEmpty) {
|
||||||
|
if (!plugin.supportsMixin(mixin)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins.add(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return list of matching plugins
|
||||||
|
return plugins;
|
||||||
|
}
|
||||||
|
|
||||||
// Getter for server version information
|
// Getter for server version information
|
||||||
String get version => _version;
|
String get version => _version;
|
||||||
@ -305,7 +326,7 @@ class InvenTreeAPI {
|
|||||||
_BASE_URL = address;
|
_BASE_URL = address;
|
||||||
|
|
||||||
// Clear the list of available plugins
|
// Clear the list of available plugins
|
||||||
plugins.clear();
|
_plugins.clear();
|
||||||
|
|
||||||
print("Connecting to ${apiUrl} -> username=${username}");
|
print("Connecting to ${apiUrl} -> username=${username}");
|
||||||
|
|
||||||
@ -486,7 +507,7 @@ class InvenTreeAPI {
|
|||||||
|
|
||||||
// The server does not support plugins, or they are not enabled
|
// The server does not support plugins, or they are not enabled
|
||||||
if (!pluginsEnabled()) {
|
if (!pluginsEnabled()) {
|
||||||
plugins.clear();
|
_plugins.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,12 +518,12 @@ class InvenTreeAPI {
|
|||||||
if (result is InvenTreePlugin) {
|
if (result is InvenTreePlugin) {
|
||||||
if (result.active) {
|
if (result.active) {
|
||||||
// Only add plugins that are active
|
// Only add plugins that are active
|
||||||
plugins.add(result);
|
_plugins.add(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print("Discovered ${plugins.length} active plugins!");
|
print("Discovered ${_plugins.length} active plugins!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user