Skip to content

Commit

Permalink
Initial implementation of the add_operation and remove_operation in t…
Browse files Browse the repository at this point in the history
…he admin_part
  • Loading branch information
joamag committed Nov 27, 2018
1 parent ffbbfb2 commit 5870ae0
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 28 deletions.
59 changes: 59 additions & 0 deletions src/appier_extras/parts/admin/part.py
Expand Up @@ -103,6 +103,7 @@ def __init__(
self._last_login = None
self._login_count = 0
self._sections = appier.OrderedDict()
self._operations = appier.OrderedDict()

def version(self):
return base.VERSION
Expand Down Expand Up @@ -170,6 +171,7 @@ def load(self):
method()

self.load_settings()
self.load_operations()

self.account_c.bind_g("touch_login", self._on_touch_login)

Expand Down Expand Up @@ -328,6 +330,38 @@ def dump_settings(self):
def flush_settings(self):
self.dump_settings()

def load_operations(self):
self.add_operation(
"build_index", "admin.build_index",
description = "Build search index",
message = "Are you really sure you want to re-build the search index?",
note = "Re-building the complete search index, may take some time",
level = 3
)
self.add_operation(
"build_index_db", "admin.build_index_db",
description = "Build database index",
message = "Are you really sure you want to re-build the database index?",
note = "Re-building the complete database index, may take some time",
level = 3
)
self.add_operation(
"test_email", "admin.test_email",
description = "Send test email",
note = "Sending this email is going to use loaded SMTP configuration"
)
self.add_operation(
"test_event", "admin.test_event",
description = "Trigger test event",
note = "All handlers for the event are going to be triggered"
)

def unload_operations(self):
self.remove_operation("build_index")
self.remove_operation("build_index_db")
self.remove_operation("test_email")
self.remove_operation("test_event")

def add_section(self, name):
self._sections[name] = appier.OrderedDict()

Expand All @@ -344,6 +378,31 @@ def remove_section_item(self, name, section = None):
if self._sections[section]: return
del self._sections[section]

def add_operation(
self,
name,
route,
description = None,
message = None,
note = None,
level = 1,
args = [],
kwargs = {}
):
self._operations[name] = dict(
name = name,
route = route,
description = description,
message = message,
note = note,
level = level,
args = args,
kwargs = kwargs
)

def remove_operation(self, name):
del self._operations[name]

def index(self):
return self.list_models()

Expand Down
38 changes: 10 additions & 28 deletions src/appier_extras/parts/admin/templates/fluid/operations.html.tpl
Expand Up @@ -3,33 +3,15 @@
{% block name %}Operations{% endblock %}
{% block content %}
<ul class="sections-list">
<li>
<div class="name">
<a class="link link-confirm warning" href="{{ url_for('admin.build_index', context = 'global', next = location) }}"
data-message="Are you really sure you want to re-build the search index ?">Build search index
</a>
</div>
<div class="description"><span>Re-building the complete search index, may take some time</span></div>
</li>
<li>
<div class="name">
<a class="link link-confirm warning" href="{{ url_for('admin.build_index_db', context = 'global', next = location) }}"
data-message="Are you really sure you want to re-build the database index ?">Build database index
</a>
</div>
<div class="description"><span>Re-building the complete database index, may take some time</span></div>
</li>
<li>
<div class="name">
<a class="link" href="{{ url_for('admin.test_email', context = 'global', next = location) }}">Send test email</a>
</div>
<div class="description"><span>Sending this email is going to use loaded SMTP configuration</span></div>
</li>
<li>
<div class="name">
<a class="link" href="{{ url_for('admin.test_event', context = 'global', next = location) }}">Trigger test event</a>
</div>
<div class="description"><span>All handlers for the event are going to be triggered</span></div>
</li>
{% for key, value in own.admin_part._operations %}
<li>
<div class="name">
<a class="link {% if value.message %}link-confirm{% endif %} {% if value.level > 1 %}warning{% endif %}" href="{{ url_for(value.route, context = 'global', next = location) }}"
data-message="{{ value.message }}">{{ value.description }}
</a>
</div>
<div class="description"><span>{{ value.note }}</span></div>
</li>
{% endfor %}
</ul>
{% endblock %}

0 comments on commit 5870ae0

Please sign in to comment.