Skip to content
This repository was archived by the owner on Apr 9, 2021. It is now read-only.

Commit 22b6ac9

Browse files
committed
GHOST-625: Add some UI list filter
1 parent 834d75a commit 22b6ac9

File tree

4 files changed

+68
-13
lines changed

4 files changed

+68
-13
lines changed

app.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,16 +1027,26 @@ def web_deployment_redeploy(deployment_id):
10271027
def web_webhook_list():
10281028
query = request.args.get('where', None)
10291029
page = request.args.get('page', '1')
1030-
webhooks = get_ghost_webhooks(query, page)
1030+
application_name = request.args.get('application') or None
1031+
module = request.args.get('module') or None
1032+
webhook_revision = request.args.get('revision') or None
1033+
1034+
query_values = {
1035+
'application_name': application_name,
1036+
'webhook_revision': webhook_revision,
1037+
'module': module,
1038+
}
1039+
1040+
webhooks = get_ghost_webhooks(query, page, application_name, module, webhook_revision)
10311041

10321042
# Generate error message if at least one of the webhook configs is invalid
10331043
if not ui_helpers.check_webhooks_validity(webhooks):
10341044
flash('At least one of your webhooks is invalid: invalid app or module.', 'danger')
10351045

10361046
if request.is_xhr:
1037-
return render_template('webhook_list_content.html', webhooks=webhooks, page=int(page))
1047+
return render_template('webhook_list_content.html', webhooks=webhooks, page=int(page), query_values=query_values)
10381048

1039-
return render_template('webhook_list.html', webhooks=webhooks, page=int(page))
1049+
return render_template('webhook_list.html', webhooks=webhooks, page=int(page), query_values=query_values)
10401050

10411051

10421052
@app.route('/web/webhooks/all/invocations', methods=['GET'])

ghost_client.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,30 @@ def normalize_app_object(app, embed_features_params_as_yml):
586586
return app
587587

588588

589-
def get_ghost_webhooks(query=None, page=None):
589+
def get_ghost_webhooks(query=None, page=None, application_name=None, module_name=None, webhook_rev=None):
590590
try:
591591
url = url_webhooks + API_QUERY_SORT_UPDATED_DESCENDING + '&embedded={"app_id": 1}'
592592
if query:
593593
url += "&where=" + query
594+
else:
595+
query = {}
596+
if application_name:
597+
applications = ['{{"app_id":"{app_id}"}}'.format(app_id=application['_id'])
598+
for application in get_ghost_apps(name=application_name)]
599+
if len(applications) > 0:
600+
query['$or'] = '[{}]'.format(','.join(applications))
601+
else:
602+
query['$or'] = '[{"app_id":"null"}]'
603+
604+
if module_name:
605+
query['module'] = '"{}"'.format(module_name)
606+
607+
if webhook_rev:
608+
query['rev'] = '"{}"'.format(webhook_rev)
609+
610+
querystr = '{{{query}}}'.format(query=','.join('"{key}":{value}'.format(key=key, value=value)
611+
for key, value in query.items()))
612+
url += "&where=" + querystr
594613
if page:
595614
url += "&page=" + page
596615
result = requests.get(url, headers=headers, auth=current_user.auth)

templates/webhook_list.html

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,40 @@
66
{% include 'partial_list_top_right.html' %}
77
<caption>Sorted by last modification date</caption>
88

9-
<ul class="nav nav-stacked action-btns">
10-
<li>
11-
<a href="/web/webhooks/create" id="createWebhook"><button class="btn btn-raised btn-primary"><span class="glyphicon glyphicon-plus"></span> Create a Webhook</button></a>
12-
</li>
13-
<li>
14-
<a href="/web/webhooks/all/invocations" id="webhookInvocations"><button class="btn btn-raised btn-success"><span class="glyphicon glyphicon-th-list"></span> See all invocations</button></a>
15-
</li>
16-
</ul>
9+
<form method="get" class="filter-form">
10+
<ul class="list-inline">
11+
<li class="list-button">
12+
<a href="/web/webhooks/create" id="createWebhook" class="btn btn-raised btn-primary"><span class="glyphicon glyphicon-plus"></span> Create a Webhook</a>
13+
</li>
14+
<li class="list-button">
15+
<a href="/web/webhooks/all/invocations" id="webhookInvocations" class="btn btn-raised btn-success"><span class="glyphicon glyphicon-th-list"></span> See all invocations</a>
16+
</li>
17+
<li>
18+
<ul class="nav nav-stacked action-btns-filter nav navbar-nav filter-group">
19+
<li role="presentation" class="filter">
20+
<div class="form-group filter-row">
21+
<input type="text" name="application" class="form-control" placeholder="Search application..." value="{{ query_values['application_name'] or '' }}"/>
22+
</div>
23+
</li>
24+
<li role="presentation" class="filter">
25+
<div class="form-group filter-row">
26+
<input type="text" name="module" class="form-control" placeholder="Search module..." value="{{ query_values['module'] or '' }}"/>
27+
</div>
28+
</li>
29+
<li role="presentation" class="filter">
30+
<div class="form-group filter-row">
31+
<input type="text" name="revision" class="form-control" placeholder="Search revision..." value="{{ query_values['webhook_revision'] or '' }}"/>
32+
</div>
33+
</li>
34+
<li class="filter">
35+
<div class="form-group filter-row">
36+
<button class="btn btn-default btn-simple btn-xs"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></button>
37+
</div>
38+
</li>
39+
</ul>
40+
</li>
41+
</ul>
42+
</form>
1743
{% endblock %}"
1844

1945
{% block page_content %}

ui_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def get_app_module_by_name(app, name):
153153

154154
def check_webhooks_validity(webhooks):
155155
for webhook in webhooks:
156-
if not webhook['module_object']:
156+
if not webhook.get('module_object'):
157157
return False
158158

159159
return True

0 commit comments

Comments
 (0)