From d88db002f1a7cbc8ebe294561c7c6593b3a4b2a1 Mon Sep 17 00:00:00 2001 From: jr-k Date: Sun, 4 Aug 2024 18:02:42 +0200 Subject: [PATCH] fully working api --- data/www/js/plugins.js | 2 +- plugins/system/CoreApi/CoreApi.py | 3 +++ plugins/system/CoreApi/lang/en.json | 3 ++- plugins/system/CoreApi/lang/es.json | 3 ++- plugins/system/CoreApi/lang/fr.json | 3 ++- plugins/system/CoreApi/lang/it.json | 3 ++- plugins/system/CoreUpdater/CoreUpdater.py | 3 +++ plugins/user/Dashboard/Dashboard.py | 3 +++ src/interface/ObPlugin.py | 9 ++++++++- src/service/PluginStore.py | 11 ++++++----- src/util/utils.py | 1 - views/configuration/plugins/modal/edit.jinja.html | 4 +--- 12 files changed, 33 insertions(+), 15 deletions(-) diff --git a/data/www/js/plugins.js b/data/www/js/plugins.js index c54d4e3..2c290ec 100644 --- a/data/www/js/plugins.js +++ b/data/www/js/plugins.js @@ -22,7 +22,7 @@ jQuery(document).ready(function ($) { $('.modal-variable-edit input:visible:eq(0)').focus().select(); $('#variable-edit-name').val(variable.name); $('#variable-edit-description').html(variable.description); - $('#variable-edit-description-edition').html(variable.description_edition).toggleClass('hidden', variable.description_edition === ''); + $('#variable-edit-description-edition').html(variable.description_edition).toggleClass('hidden', variable.description_edition === '' || variable.description_edition === null); $('#variable-edit-value').val(variable.value); $('#variable-edit-id').val(variable.id); }); diff --git a/plugins/system/CoreApi/CoreApi.py b/plugins/system/CoreApi/CoreApi.py index a5558f7..b1a654f 100644 --- a/plugins/system/CoreApi/CoreApi.py +++ b/plugins/system/CoreApi/CoreApi.py @@ -20,6 +20,9 @@ class CoreApi(ObPlugin): def use_description(self): return self.translate('plugin_description') + def use_help_on_activation(self): + return self.translate('plugin_help_on_activation') + def use_variables(self) -> List[Variable]: return [] diff --git a/plugins/system/CoreApi/lang/en.json b/plugins/system/CoreApi/lang/en.json index 231fe24..01d9c66 100644 --- a/plugins/system/CoreApi/lang/en.json +++ b/plugins/system/CoreApi/lang/en.json @@ -1,4 +1,5 @@ { "plugin_title": "Core API", - "plugin_description": "Adds api feature wrapping core features" + "plugin_description": "Adds api feature wrapping core features", + "plugin_help_on_activation": "Documentation will be available on the /api page" } diff --git a/plugins/system/CoreApi/lang/es.json b/plugins/system/CoreApi/lang/es.json index 91c3d59..b05e2f9 100644 --- a/plugins/system/CoreApi/lang/es.json +++ b/plugins/system/CoreApi/lang/es.json @@ -1,4 +1,5 @@ { "plugin_title": "Core API", - "plugin_description": "Agrega características de API que envuelven las características principales" + "plugin_description": "Agrega características de API que envuelven las características principales", + "plugin_help_on_activation": "La documentación estará disponible en la página /api" } \ No newline at end of file diff --git a/plugins/system/CoreApi/lang/fr.json b/plugins/system/CoreApi/lang/fr.json index 83b67e6..382c842 100644 --- a/plugins/system/CoreApi/lang/fr.json +++ b/plugins/system/CoreApi/lang/fr.json @@ -1,4 +1,5 @@ { "plugin_title": "Core API", - "plugin_description": "Ajoute des fonctionnalités d'API englobant les fonctionnalités principales" + "plugin_description": "Ajoute des fonctionnalités d'API englobant les fonctionnalités principales", + "plugin_help_on_activation": "La documentation sera disponible sur la page /api" } \ No newline at end of file diff --git a/plugins/system/CoreApi/lang/it.json b/plugins/system/CoreApi/lang/it.json index de1a4a3..8e3de5f 100644 --- a/plugins/system/CoreApi/lang/it.json +++ b/plugins/system/CoreApi/lang/it.json @@ -1,4 +1,5 @@ { "plugin_title": "Core API", - "plugin_description": "Aggiunge funzionalità API che racchiudono le funzionalità di base" + "plugin_description": "Aggiunge funzionalità API che racchiudono le funzionalità di base", + "plugin_help_on_activation": "La documentazione sarà disponibile nella pagina /api" } \ No newline at end of file diff --git a/plugins/system/CoreUpdater/CoreUpdater.py b/plugins/system/CoreUpdater/CoreUpdater.py index 787be47..52503b7 100644 --- a/plugins/system/CoreUpdater/CoreUpdater.py +++ b/plugins/system/CoreUpdater/CoreUpdater.py @@ -22,6 +22,9 @@ class GitUpdater(ObPlugin): def use_description(self): return self.translate('plugin_description') + def use_help_on_activation(self): + return None + def use_variables(self) -> List[Variable]: return [] diff --git a/plugins/user/Dashboard/Dashboard.py b/plugins/user/Dashboard/Dashboard.py index b85dcc7..1f0b9d7 100644 --- a/plugins/user/Dashboard/Dashboard.py +++ b/plugins/user/Dashboard/Dashboard.py @@ -20,6 +20,9 @@ class Dashboard(ObPlugin): def use_description(self): return self.translate('plugin_description') + def use_help_on_activation(self): + return None + def use_variables(self) -> List[Variable]: return [] diff --git a/src/interface/ObPlugin.py b/src/interface/ObPlugin.py index 54bca9f..374b1c7 100644 --- a/src/interface/ObPlugin.py +++ b/src/interface/ObPlugin.py @@ -38,6 +38,10 @@ class ObPlugin(abc.ABC): def use_description(self) -> str: pass + @abc.abstractmethod + def use_help_on_activation(self) -> Optional[str]: + pass + @abc.abstractmethod def use_variables(self) -> List[Variable]: pass @@ -86,7 +90,10 @@ class ObPlugin(abc.ABC): def add_functional_hook_registration(self, hook: HookType, priority: int = 0, function=None) -> FunctionalHookRegistration: return FunctionalHookRegistration(plugin=self, hook=hook, priority=priority, function=function) - def translate(self, token, resolve=False) -> Union[Dict, str]: + def translate(self, token, resolve=True) -> Union[Dict, str]: + if not token: + token = '' + token = token if token.startswith(self.use_id()) else "{}_{}".format(self.use_id(), token) return self._model_store.lang().translate(token) if resolve else token diff --git a/src/service/PluginStore.py b/src/service/PluginStore.py index e435c37..36aea5f 100644 --- a/src/service/PluginStore.py +++ b/src/service/PluginStore.py @@ -120,6 +120,10 @@ class PluginStore: self._hooks[hook_type] = sorted(self._hooks[hook_type], key=lambda hook_reg: hook_reg.priority, reverse=True) def setup_plugin(self, plugin: ObPlugin) -> None: + # LANGS + self._model_store.lang().load(directory=plugin.get_directory(), prefix=plugin.use_id()) + self._model_store.variable().reload() + # VARIABLES variables = plugin.use_variables() + [ plugin.add_variable( @@ -127,7 +131,8 @@ class PluginStore: value=False, type=VariableType.BOOL, editable=True, - description=self._model_store.lang().translate("common_enable_plugin") + description=self._model_store.lang().translate("common_enable_plugin"), + description_edition=plugin.use_help_on_activation() ) ] @@ -135,10 +140,6 @@ class PluginStore: if variable.name in self._dead_variables_candidates: del self._dead_variables_candidates[variable.name] - # LANGS - self._model_store.lang().load(directory=plugin.get_directory(), prefix=plugin.use_id()) - self._model_store.variable().reload() - if not self.is_plugin_enabled(plugin): return diff --git a/src/util/utils.py b/src/util/utils.py index c4fce2d..b937700 100644 --- a/src/util/utils.py +++ b/src/util/utils.py @@ -60,7 +60,6 @@ def camel_to_snake(camel: str) -> str: def str_datetime_to_cron(datetime_str: str) -> str: - print(datetime_str) datetime_obj = datetime.strptime(datetime_str, '%Y-%m-%d %H:%M') return "{} {} {} {} * {}".format( datetime_obj.minute, diff --git a/views/configuration/plugins/modal/edit.jinja.html b/views/configuration/plugins/modal/edit.jinja.html index 5610952..c5de667 100644 --- a/views/configuration/plugins/modal/edit.jinja.html +++ b/views/configuration/plugins/modal/edit.jinja.html @@ -13,9 +13,7 @@ -
- -
+