diff options
-rw-r--r-- | jimbrella/database.py | 6 | ||||
-rw-r--r-- | jimbrella/static/jimbrella.css | 2 | ||||
-rw-r--r-- | jimbrella/templates/admin/index.html | 12 | ||||
-rw-r--r-- | jimbrella/templates/admin/umbrellas.html | 40 | ||||
-rw-r--r-- | jimbrella/utils.py | 17 | ||||
-rw-r--r-- | jimbrella/web.py | 11 |
6 files changed, 78 insertions, 10 deletions
diff --git a/jimbrella/database.py b/jimbrella/database.py index 7f10c55..ab54a28 100644 --- a/jimbrella/database.py +++ b/jimbrella/database.py @@ -1,7 +1,7 @@ import csv import os from datetime import datetime, timedelta -from .utils import human_timedelta +from .utils import human_datetime, human_timedelta from .config import DUE_HOURS @@ -161,14 +161,16 @@ class Database: All exposed methods with a return value should use this method instead of `_read()`. Supplemental data: + - lent_at_str: string representation for lent_at. - lent_time_ago: time since umbrella was taken away by tenant. if umbrella is not taken away, its value is None. - - lent_time_ago_str: lent_time_ago as a string representation. + - lent_time_ago_str: string representation for lent_time_ago. """ umbrellas = self._read() now = datetime.now() for idx, umb in enumerate(umbrellas): if umb["status"] == "lent": + umbrellas[idx]["lent_at_str"] = human_datetime(umb["lent_at"]) lent_time_ago = now - umb["lent_at"] umbrellas[idx]["lent_time_ago"] = lent_time_ago umbrellas[idx]["lent_time_ago_str"] = human_timedelta(lent_time_ago) diff --git a/jimbrella/static/jimbrella.css b/jimbrella/static/jimbrella.css index f9ef7ae..8bb7fbd 100644 --- a/jimbrella/static/jimbrella.css +++ b/jimbrella/static/jimbrella.css @@ -38,7 +38,7 @@ h2.tile-heading, h2.banner-heading { margin-bottom: 2em; } -table { +table.data { border: 2px solid; } diff --git a/jimbrella/templates/admin/index.html b/jimbrella/templates/admin/index.html index 7a62a14..ddbe4e5 100644 --- a/jimbrella/templates/admin/index.html +++ b/jimbrella/templates/admin/index.html @@ -2,18 +2,26 @@ <html> <head> <title>JI Umbrella</title> - <link rel="stylesheet" href="static/jimbrella.css" /> + <link rel="stylesheet" href="/static/jimbrella.css" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> </head> <body> <h1>JI Umbrella Overview</h1> <div id="container"> + <header> + <table class="tabs"> + <tr> + <td><a href="/admin">Overview</a></td> + <td><a href="/admin/umbrellas">All</a></td> + </tr> + </table> + </header> <!--Takes up full width of container--> <div class="banner-container"> {% if overdue %} <div class="banner overdue"> <h2 class="banner-heading">Overdue</h2> - <table> + <table class="data"> <tr> <td>#</td> <td>Tenant</td> diff --git a/jimbrella/templates/admin/umbrellas.html b/jimbrella/templates/admin/umbrellas.html new file mode 100644 index 0000000..c64111e --- /dev/null +++ b/jimbrella/templates/admin/umbrellas.html @@ -0,0 +1,40 @@ +<!DOCTYPE html> +<html> + <head> + <title>JI Umbrella</title> + <link rel="stylesheet" href="/static/jimbrella.css" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + </head> + <body> + <h1>All Umbrellas</h1> + <div id="container"> + <table class="data"> + <thead> + <tr> + <th>#</th> + <th>Status</th> + <th>Tenant</th> + <th>ID</th> + <th>Phone</th> + <th colspan=2>Lent at</th> + </tr> + </thead> + <tbody> + {% for umb in umbrellas %} + <tr class="{{ umb.status }}"> + <td>{{ umb.serial }}</td> + <td>{{ umb.status }}</td> + <td>{{ umb.tenant_name }}</td> + <td>{{ umb.tenant_id }}</td> + <td>{{ umb.tenant_phone }}</td> + <td>{{ umb.lent_at_str }}</td> + <td>{{ umb.lent_time_ago_str }} + {% if umb.status == "lent" %} ago {% endif %} + </td> + </tr> + {% endfor %} + </tbody> + </table> + </div> + </body> +</html> diff --git a/jimbrella/utils.py b/jimbrella/utils.py index fc68206..c7e8176 100644 --- a/jimbrella/utils.py +++ b/jimbrella/utils.py @@ -1,9 +1,18 @@ -from datetime import timedelta +from datetime import datetime, timedelta + + +def human_datetime(time: datetime) -> str: + return "{:%Y-%m-%d %H:%M}".format(time) def human_timedelta(delta: timedelta) -> str: + if delta.days == 0: + days = "" + elif delta.days == 1: + days = "1 day, " + else: + days = f"{delta.days} days, " + hours = delta.seconds // 3600 minutes = delta.seconds % (hours * 3600) // 60 - return ( - f"{delta.days} days, " if delta.days else "" - ) + f"{hours:0>2}:{minutes:0>2}" # zero-pad to two digits + return days + f"{hours:0>2}:{minutes:0>2}" # zero-pad to two digits diff --git a/jimbrella/web.py b/jimbrella/web.py index 8b45309..e2de758 100644 --- a/jimbrella/web.py +++ b/jimbrella/web.py @@ -8,7 +8,7 @@ app = Flask("jimbrella") @app.route("/admin") -def index(): +def admin_index(): umbrellas = db.read() statuses = Database.group_by_status(umbrellas) return render_template( @@ -20,5 +20,14 @@ def index(): ) +@app.route("/admin/umbrellas") +def admin_umbrellas(): + umbrellas = db.read() + return render_template( + "admin/umbrellas.html", + umbrellas=umbrellas, + ) + + if __name__ == "__main__": app.run() |