Browse Source

Add plugin state to admin overview

Peter Justin 8 years ago
parent
commit
b6efeaf98c

+ 33 - 10
flaskbb/plugins/__init__.py

@@ -8,12 +8,20 @@
     :copyright: (c) 2014 by the FlaskBB Team.
     :license: BSD, see LICENSE for more details.
 """
+import warnings
 from flask import current_app
 from flask_plugins import Plugin
 
 from flaskbb.management.models import SettingsGroup
 
 
+class FlaskBBPluginDeprecationWarning(DeprecationWarning):
+    pass
+
+
+warnings.simplefilter("always", FlaskBBPluginDeprecationWarning)
+
+
 class FlaskBBPlugin(Plugin):
 
     #: This is the :class:`SettingsGroup` key - if your the plugin needs to
@@ -22,25 +30,40 @@ class FlaskBBPlugin(Plugin):
     settings_key = None
 
     @property
-    def installable(self):
-        """Is ``True`` if the Plugin can be installed."""
+    def has_settings(self):
+        """Is ``True`` if the Plugin **can** be installed."""
         if self.settings_key is not None:
             return True
         return False
 
     @property
-    def uninstallable(self):
-        """Is ``True`` if the Plugin can be uninstalled."""
-        if self.installable:
+    def installed(self):
+        is_installed = False
+        if self.has_settings:
             group = SettingsGroup.query.\
                 filter_by(key=self.settings_key).\
                 first()
-            if group and len(group.settings.all()) > 0:
-                return True
-            return False
-        return False
+            is_installed = group and len(group.settings.all()) > 0
+        return is_installed
+
+    @property
+    def uninstallable(self):
+        """Is ``True`` if the Plugin **can** be uninstalled."""
+        warnings.warn(
+            "self.uninstallable is deprecated. Use self.installed instead.",
+            FlaskBBPluginDeprecationWarning
+        )
+        return self.installed
+
+    @property
+    def installable(self):
+        warnings.warn(
+            "self.installable is deprecated. Use self.has_settings instead.",
+            FlaskBBPluginDeprecationWarning
+        )
+        return self.has_settings
 
-        # Some helpers
+    # Some helpers
     def register_blueprint(self, blueprint, **kwargs):
         """Registers a blueprint.
 

+ 17 - 2
flaskbb/templates/management/overview.html

@@ -132,9 +132,24 @@
                             <div class="row stats-heading">{% trans %}Plugins{% endtrans %}</div>
 
                             {% for plugin in plugins %}
-
                             <div class="row stats-item">
-                                <div class="key pull-left">{{ plugin.name }}</div><div class="value pull-right">{{ plugin.version }}</div>
+                                <div class="key pull-left">
+                                {% if plugin.uninstallable %}
+                                    <a href="{{ url_for('management.settings', slug=plugin.settings_key) }}">{{ plugin.name }}</a>
+                                {% else %}
+                                    <a href="{{ url_for('management.plugins') }}">{{ plugin.name }}</a>
+                                {% endif %}
+                                </div>
+                                <div class="value pull-right">
+                                    {% if not plugin.enabled %}
+                                        <span class="text-danger">not enabled</span>
+                                    {% elif plugin.enabled and plugin.installed %}
+                                        <span class="text-success">enabled &amp; installed</span>
+                                    {% elif plugin.enabled and not plugin.installed %}
+                                        <span class="text-warning">not installed</span>
+                                    {% endif %}
+                                    {{ plugin.version }}
+                                </div>
                             </div>
                             {% endfor %}
                         </div>

+ 12 - 2
flaskbb/templates/management/plugins.html

@@ -35,6 +35,15 @@
                     {% else %}
                       {{ plugin.name }}
                     {% endif %}
+                    <div class="pull-right">
+                    {% if not plugin.enabled %}
+                        <div class="label label-danger">not enabled</div>
+                    {% elif plugin.enabled and plugin.installed %}
+                        <div class="label label-success">enabled &amp; installed</div>
+                    {% elif plugin.enabled and not plugin.installed %}
+                        <div class="label label-warning">not installed</div>
+                    {% endif %}
+                    </div>
                     </div>
                     <div class="col-md-4 col-sm-4 col-xs-4">
                         <div class="plugin-version">{% trans %}Version{% endtrans %}: {{ plugin.version }}</div>
@@ -54,17 +63,18 @@
                         </form>
                         {% endif %}
 
-                        {% if plugin.installable and not plugin.uninstallable %}
+                        {% if not plugin.installed %}
                         <form class="inline-form" method="post" action="{{ url_for('management.install_plugin', plugin=plugin.identifier) }}">
                             <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
                             <button class="btn btn-info">{% trans %}Install{% endtrans %}</button>
                         </form>
                         {% endif %}
-                        {% if plugin.uninstallable %}
+                        {% if plugin.installed %}
                         <form class="inline-form" method="post" action="{{ url_for('management.uninstall_plugin', plugin=plugin.identifier) }}">
                             <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
                             <button class="btn btn-danger">{% trans %}Uninstall{% endtrans %}</button>
                         </form>
+                        <a class="btn btn-info" href="{{ url_for('management.settings', slug=plugin.settings_key) }}">Settings</a>
                         {% endif %}
                     </div>
                 </div>