portal: consolidate list templates

This commit is contained in:
Iain Learmonth 2022-05-04 13:01:46 +01:00
parent 473152fe19
commit a1aa252bc0
9 changed files with 90 additions and 75 deletions

View file

@ -46,7 +46,12 @@ def portal_home():
@portal.route("/groups")
def view_groups():
groups = Group.query.order_by(Group.group_name).all()
return render_template("groups.html.j2", section="group", groups=groups)
return render_template("list.html.j2",
section="group",
title="Groups",
item="group",
items=groups,
new_link=url_for("portal.new_group"))
@portal.route("/group/new", methods=['GET', 'POST'])
@ -154,13 +159,21 @@ def edit_origin(origin_id):
@portal.route("/origins")
def view_origins():
origins = Origin.query.order_by(Origin.domain_name).all()
return render_template("origins.html.j2", section="origin", origins=origins)
return render_template("list.html.j2",
section="origin",
title="Origins",
item="origin",
new_link=url_for("portal.new_origin"),
items=origins)
@portal.route("/proxies")
def view_proxies():
proxies = Proxy.query.filter(Proxy.destroyed == None).order_by(desc(Proxy.updated)).all()
return render_template("proxies.html.j2", section="proxy", proxies=proxies)
return render_template("list.html.j2",
section="proxy",
title="Proxies",
item="proxy",
items=proxies)
@portal.route("/proxy/block/<proxy_id>", methods=['GET', 'POST'])
@ -202,7 +215,12 @@ def view_alarms():
@portal.route('/lists')
def view_mirror_lists():
mirrorlists = MirrorList.query.filter(MirrorList.destroyed == None).all()
return render_template("mirrorlists.html.j2", section="list", mirrorlists=mirrorlists)
return render_template("list.html.j2",
section="list",
title="Mirror Lists",
item="mirror list",
new_link=url_for("portal.new_mirror_list"),
items=mirrorlists)
@portal.route("/list/destroy/<list_id>")
@ -254,7 +272,12 @@ def new_mirror_list(group_id=None):
@portal.route("/bridgeconfs")
def view_bridgeconfs():
bridgeconfs = BridgeConf.query.filter(BridgeConf.destroyed == None).all()
return render_template("bridgeconfs.html.j2", section="bridgeconf", bridgeconfs=bridgeconfs)
return render_template("list.html.j2",
section="bridgeconf",
title="Tor Bridge Configurations",
item="bridge configuration",
items=bridgeconfs,
new_link=url_for("portal.new_bridgeconf"))
@portal.route("/bridgeconf/new", methods=['GET', 'POST'])
@ -301,7 +324,11 @@ def new_bridgeconf(group_id=None):
@portal.route("/bridges")
def view_bridges():
bridges = Bridge.query.filter(Bridge.destroyed == None).all()
return render_template("bridges.html.j2", section="bridge", bridges=bridges)
return render_template("list.html.j2",
section="bridge",
title="Tor Bridges",
item="bridge",
items=bridges)
@portal.route('/bridgeconf/edit/<bridgeconf_id>', methods=['GET', 'POST'])

View file

@ -1,8 +0,0 @@
{% extends "base.html.j2" %}
{% from "tables.html.j2" import bridgeconfs_table %}
{% block content %}
<h1 class="h2 mt-3">Tor Bridge Configurations</h1>
<a href="{{ url_for("portal.new_bridgeconf") }}" class="btn btn-success">Create new configuration</a>
{{ bridgeconfs_table(bridgeconfs) }}
{% endblock %}

View file

@ -1,7 +0,0 @@
{% extends "base.html.j2" %}
{% from "tables.html.j2" import bridges_table %}
{% block content %}
<h1 class="h2 mt-3">Tor Bridges</h1>
{{ bridges_table(bridges) }}
{% endblock %}

View file

@ -1,30 +0,0 @@
{% extends "base.html.j2" %}
{% block content %}
<h1 class="h2 mt-3">Groups</h1>
<a href="{{ url_for("portal.new_group") }}" class="btn btn-success">Create new group</a>
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th scope="col">EOTK</th>
<th scope="col">Sites</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
{% for group in groups %}
<tr>
<td>{{ group.group_name }}</td>
<td>{{ group.description }}</td>
<td>{% if group.eotk %}✅{% else %}❌{% endif %}</td>
<td>{{ group.origins | length }}</td>
<td><a href="{{ url_for("portal.edit_group", group_id=group.id) }}" class="btn btn-primary btn-sm">View/Edit</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}

View file

@ -0,0 +1,25 @@
{% extends "base.html.j2" %}
{% from "tables.html.j2" import bridgeconfs_table, bridges_table,
groups_table, mirrorlists_table, origins_table, proxies_table %}
{% block content %}
<h1 class="h2 mt-3">{{ title }}</h1>
{% if new_link %}
<a href="{{ new_link }}" class="btn btn-success">Create new {{ item }}</a>
{% endif %}
{% if item == "bridge configuration" %}
{{ bridgeconfs_table(items) }}
{% elif item == "bridge" %}
{{ bridges_table(items) }}
{% elif item == "eotk" %}
{{ eotk_table(items) }}
{% elif item == "group" %}
{{ groups_table(items) }}
{% elif item == "mirror list" %}
{{ mirrorlists_table(items) }}
{% elif item == "origin" %}
{{ origins_table(items) }}
{% elif item == "proxy" %}
{{ proxies_table(items) }}
{% endif %}
{% endblock %}

View file

@ -1,8 +0,0 @@
{% extends "base.html.j2" %}
{% from "tables.html.j2" import mirrorlists_table %}
{% block content %}
<h1 class="h2 mt-3">Mirror Lists</h1>
<a href="{{ url_for("portal.new_mirror_list") }}" class="btn btn-success">Create new mirror list</a>
{{ mirrorlists_table(mirrorlists) }}
{% endblock %}

View file

@ -1,8 +0,0 @@
{% extends "base.html.j2" %}
{% from "tables.html.j2" import origins_table %}
{% block content %}
<h1 class="h2 mt-3">Origins</h1>
<a href="{{ url_for("portal.new_origin") }}" class="btn btn-success">Create new origin</a>
{{ origins_table(origins) }}
{% endblock %}

View file

@ -1,7 +0,0 @@
{% extends "base.html.j2" %}
{% from "tables.html.j2" import proxies_table %}
{% block content %}
<h1 class="h2 mt-3">Proxies</h1>
{{ proxies_table(proxies) }}
{% endblock %}

View file

@ -22,6 +22,37 @@
</svg>
{% endmacro %}
{% macro eotk_table(eotks) %}
<div class="alert alert-danger">Not implemented yet.</div>
{% endmacro %}
{% macro groups_table(groups) %}
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th scope="col">EOTK</th>
<th scope="col">Sites</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
{% for group in groups %}
<tr>
<td>{{ group.group_name }}</td>
<td>{{ group.description }}</td>
<td>{% if group.eotk %}✅{% else %}❌{% endif %}</td>
<td>{{ group.origins | length }}</td>
<td><a href="{{ url_for("portal.edit_group", group_id=group.id) }}" class="btn btn-primary btn-sm">View/Edit</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endmacro %}
{% macro origins_table(origins) %}
<div class="table-responsive">
<table class="table table-striped table-sm">