/m/doorboy: quick refactor

This commit is contained in:
2025-05-30 21:24:10 +03:00
parent b038f526ee
commit 88b8519ff6
8 changed files with 106 additions and 54 deletions

View File

@@ -199,7 +199,7 @@ def view_doorboy_slam():
def view_doorboy():
user = read_user()
workshop_access = "k-space:workshop" in g.users_lookup.get(user["username"], User()).groups
latest_events = db.eventlog.find({"component": "doorboy", "type":"open-door"}).sort([("timestamp", -1)]).limit(10);
# latest_events = db.eventlog.find({"component": "doorboy", "type":"open-door"}).sort([("timestamp", -1)]).limit(10);
latest_swipes = db.inventory.find({"component": "doorboy", "type":"token"}).sort([("last_seen", -1)]).limit(10);
return render_template("doorboy.html", **locals())

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@@ -69,12 +69,18 @@ span.tooltipped {
text-decoration-style: dotted;
}
.horizontalRow {
.horizontalRow {
display: flex;
justify-content: flex-start;
align-items: center;
gap: 20px;
padding: 10px;
}
}
.buttonExtra {
border: 4px solid #2bbbad;
text-align: center;
}
</style>
</head>
<body>

View File

@@ -1,21 +1,99 @@
{% extends 'base.html' %}
{% block content %}
<div class="container">
<!-- This page is referenced by https://wiki.k-space.ee/en/hosting/doors -->
<div class="container">
<p>Press to open:</p>
<ul>
<li><a class="waves-effect waves-light btn" href="/m/doorboy/grounddoor/open">Ground door</a> the one on street level facing KBFI</li>
<li><a class="waves-effect waves-light btn" href="/m/doorboy/frontdoor/open">Front door</a> the one from ground door 5 floors upward</li>
<li><a class="waves-effect waves-light btn" href="/m/doorboy/backdoor/open">Back door</a> on 5th floor on the Pancake cafeteria side. Note: ground door on cafeteria side is open whenever the cafeteria is open. Other times use the ground door listed above.</li>
<li><a class="waves-effect waves-light btn {% if not workshop_access%}disabled{%endif%}" href="/m/doorboy/workshopdoor/open">Workshop door</a> also known as the dirty room</li>
<!--
<li>Coming later: <a class="waves-effect waves-light btn" href="/m/doorboy/server/open">Server room door</a></li>
-->
</ul>
<div>
<h3>Open</h3>
<p>Manage your keycards or keyfobs here:</p>
<a href="/m/doorboy/me" class="waves-effect waves-light btn"><i class="material-icons left">person</i>My cards</a>
<div class="horizontalRow">
<div class="col s12 buttonExtra">
<div>
<div><img src="/static/backdoor.jpg"></div>
<div><a class="waves-effect waves-light btn" href="/m/doorboy/backdoor/open">Back door</a></div>
<div>k6.ee/0001</div>
</div>
</div>
<div class="col s12 buttonExtra horizontalRow">
<div>
<div><img src="/static/grounddoor.png"></div>
<div><a class="waves-effect waves-light btn" href="/m/doorboy/grounddoor/open">Ground door</a></div>
<div>k6.ee/????</div>
</div>
<div><img src="/static/doorstairs.png"></div>
<div>
<div><img src="/static/frontdoor.jpg"></div>
<div><a class="waves-effect waves-light btn" href="/m/doorboy/frontdoor/open">Front door</a></div>
<div>k6.ee/0079</div>
</div>
</div>
</div>
<div class="horizontalRow">
<div>
<div class="col s12 buttonExtra"><div><img src="/static/workshopdoor.jpg"></div><div><a class="waves-effect waves-light btn {% if not workshop_access%}disabled{%endif%}" href="/m/doorboy/workshopdoor/open">Workshop</a></div><div>k6.ee/0020</div></div>
</div>
</div>
</div>
<hr>
<div><ul>
<li>Doors locations: <a href="https://k-space.ee/where">k-space.ee/where</a></li>
<li>Hardware and stack are documented <a href="https://wiki.k-space.ee/en/hosting/doors">in Wiki</a>.</li>
<li><a href="https://wiki.k-space.ee/en/about/membership">Membership</a> determines door access.</li>
</ul></div>
<div>
<h3>Keycards</h3>
<a href="/m/doorboy/me" class="waves-effect waves-light btn"><i class="material-icons left">person</i>Linked keycards</a>
<p>Adding keycards:
<ol>
<li>Swipe keycard at any door listed above</li>
<li>Refresh this page</li>
<li>Find it below, click <pre style="display: inline;">Claim keycard</pre></li>
</ol>
</p>
<h4>Keycards last seen:</h4>
Does not include door opens by webhook.
<table>
<thead>
<tr>
<!-- <th>&nbsp;</th> -->
<th>Last seen</th>
<th>&nbsp;</th>
<th>Who</th>
<th>UID hash tail</th>
<!-- <th>Granted</th> -->
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
{% for o in latest_swipes %}
<tr>
<!-- Does not work -->
<!-- <td>
{% if o.inventory and o.inventory.owner %}
&nbsp;
{% else %}
<i class="material-icons">error</i>{% endif %}
</td> -->
<td>{{ (o.last_seen or o.timestamp) | timeago }}</td>
<td>{{ o.door }}</td>
<td>{% if o.inventory and o.inventory.owner %}<a href="/m/user/{{ o.inventory.owner.username }}">{{ o.inventory.owner.username | display_name }}</a>{% else %}Unknown{% endif %}</td>
<td><a href="/m/doorboy/{{ o._id }}/events">{{ o.token.uid_hash[-6:] }}</a></td>
<!-- <td>{% if o.success %}<i class="material-icons">check_circle</i>{% else %}&nbsp;{% endif %}</td> -->
<td>{% if o.inventory and o.inventory.owner %}{{ o.token.comment }}{% else %}<a class="waves-effect waves-light btn" href="/m/doorboy/{{ o._id }}/claim">Claim keycard</a>{% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if false %}
<!-- whole section commented out -->
<div>
<p>Recent door open requests via Slack or the buttons above</p>
@@ -40,40 +118,8 @@
{% endfor %}
</tbody>
</table>
<p>Please claim keycards or keyfobs associated with you here!</p>
<table>
<thead>
<tr>
<th>&nbsp;</th>
<th>Last seen</th>
<th>&nbsp;</th>
<th>Who</th>
<th>UID hash tail</th>
<th>Granted</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
{% for o in latest_swipes %}
<tr>
<td>
{% if o.inventory and o.inventory.owner %}
&nbsp;
{% else %}
<i class="material-icons">error</i>{% endif %}
</td>
<td>{{ (o.last_seen or o.timestamp) | timeago }}</td>
<td>{{ o.door }}</td>
<td>{% if o.inventory and o.inventory.owner %}<a href="/m/user/{{ o.inventory.owner.username }}">{{ o.inventory.owner.username | display_name }}</a>{% else %}Unknown{% endif %}</td>
<td><a href="/m/doorboy/{{ o._id }}/events">{{ o.token.uid_hash[-6:] }}</a></td>
<td>{% if o.success %}<i class="material-icons">check_circle</i>{% else %}&nbsp;{% endif %}</td>
<td>{% if o.inventory and o.inventory.owner %}{{ o.token.comment }}{% else %}<a class="waves-effect waves-light btn" href="/m/doorboy/{{ o._id }}/claim">This is mine!</a>{% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
</div>
{% endblock %}