aboutsummaryrefslogtreecommitdiffstats
path: root/templates
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-05-14 20:42:41 +0100
committerGravatar GitHub <[email protected]>2018-05-14 20:42:41 +0100
commitb7fe5de12be5c9f02adeedba45befee751ea68be (patch)
tree740be4b7dff4a8e70616e1663375ef1940604d53 /templates
parentSwitch from using abort to using werkzeug exception (diff)
Migration runner and migrations (#69)
* Migration runner and migrations * Remove demo wiki data * [Staff] Table management pages * Fix weird travis build omission * Address review and comments by @Volcyy * [Tables] Fix pagination * Move table definitions to new file with nameduple * Linting * Address lemon's review comments * Address @Volcyy's review * Address lemon's review * Update search placeholder * Search by key now available
Diffstat (limited to 'templates')
-rw-r--r--templates/staff/staff.html22
-rw-r--r--templates/staff/tables/edit.html51
-rw-r--r--templates/staff/tables/index.html32
-rw-r--r--templates/staff/tables/table.html165
4 files changed, 263 insertions, 7 deletions
diff --git a/templates/staff/staff.html b/templates/staff/staff.html
index 157bdf21..b22bfcec 100644
--- a/templates/staff/staff.html
+++ b/templates/staff/staff.html
@@ -3,12 +3,20 @@
{% block og_title %}Staff | Home{% endblock %}
{% block og_description %}Landing page for the staff management area{% endblock %}
{% block content %}
- <div class="uk-container uk-section">
- <h1 class="uk-title uk-text-center">
- App config
- </h1>
- <pre>
-{{ app_config | safe }}
- </pre>
+ <div class="uk-container uk-container-small uk-section">
+ <h1 class="uk-text-center">
+ Management links
+ </h1>
+ {% if manager %}
+ <a class="uk-button uk-button-primary" href="{{ url_for("staff.tables.index") }}">Table Management</a>
+ {% else %}
+ <p>Nothing for you yet, I'm afraid.</p>
+ {% endif %}
+ <h1 class="uk-title uk-text-center">
+ App config
+ </h1>
+ <pre>
+ {{ app_config | safe }}
+ </pre>
</div>
{% endblock %} \ No newline at end of file
diff --git a/templates/staff/tables/edit.html b/templates/staff/tables/edit.html
new file mode 100644
index 00000000..7b027884
--- /dev/null
+++ b/templates/staff/tables/edit.html
@@ -0,0 +1,51 @@
+{% extends "main/base.html" %}
+{% block title %}Staff | Home{% endblock %}
+{% block og_title %}Staff | Home{% endblock %}
+{% block og_description %}Landing page for the staff management area{% endblock %}
+{% block extra_head %}
+<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.3.3/ace.js" type="application/javascript"></script>
+{% endblock %}
+{% block content %}
+ <div class="uk-container uk-section uk-container-small">
+ {% if message %}
+ <div class="uk-alert uk-alert-warning">
+ {{ message }}
+ </div>
+ {% endif %}
+ <form uk-grid class="uk-grid-small" action="{{ url_for("staff.tables.edit", table=table) }}" method="post">
+ <div class="uk-width-expand">
+ <p>Primary key: <strong>"<span style="font-family: monospace">{{ primary_key }}</span>"</strong></p>
+ </div>
+ <div class="uk-width-auto">
+ <a class="uk-button uk-button-default" href="{{ url_for("staff.tables.table", table=table, page=1) }}"><i class="uk-icon fa-fw fas fa-arrow-left"></i>&nbsp; Back</a>
+ <input class="uk-button uk-button-primary" type="submit" id="submit" value="Save" />
+ </div>
+ <div class="uk-width-1-1">
+ <div id="editor" class="uk-textarea" style="resize: vertical; min-height: 15rem;">{{ document }}</div>
+ <input type="hidden" name="json" id="json" />
+ </div>
+
+ <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
+
+ {% if old_primary %}
+ <input type="hidden" name="old_primary" value="{{ old_primary }}"/>
+ {% endif %}
+ </form>
+
+ <script type="application/javascript">
+ "use strict";
+
+ let editor = ace.edit("editor");
+
+ editor.session.setMode("ace/mode/json");
+ editor.session.setUseWrapMode(true);
+
+ editor.setTheme("ace/theme/iplastic");
+ editor.setShowPrintMargin(false);
+
+ editor.on("input", function() {
+ document.getElementById("json").value = editor.getValue();
+ });
+ </script>
+ </div>
+{% endblock %}
diff --git a/templates/staff/tables/index.html b/templates/staff/tables/index.html
new file mode 100644
index 00000000..079ed306
--- /dev/null
+++ b/templates/staff/tables/index.html
@@ -0,0 +1,32 @@
+{% extends "main/base.html" %}
+{% block title %}Staff | Tables{% endblock %}
+{% block og_title %}Staff | Tables{% endblock %}
+{% block og_description %}Table management and editor{% endblock %}
+{% block content %}
+ <div class="uk-container uk-section uk-container-small">
+ <a class="uk-button uk-button-default" href="{{ url_for("staff.staff_index") }}"><i class="uk-icon fa-fw fas fa-arrow-left"></i> &nbsp;Back</a>
+ <h1 class="uk-title uk-text-center">
+ Table manager
+ </h1>
+ <p>
+ Click one of the tables below to manage its data:
+ </p>
+ <ul>
+ {% for table, obj in tables.items() %}
+ {% if obj.locked %}
+ <li>
+ <a href="{{ url_for("staff.tables.table", table=table, page=1) }}" title="Table locked for editing">
+ <i class="uk-icon fa-fw fas fa-lock"></i> &nbsp;{{ table }}
+ </a>
+ </li>
+ {% else %}
+ <li>
+ <a href="{{ url_for("staff.tables.table", table=table, page=1) }}">
+ <i class="uk-icon fa-fw fas fa-pencil"></i> &nbsp;{{ table }}
+ </a>
+ </li>
+ {% endif %}
+ {% endfor %}
+ </ul>
+ </div>
+{% endblock %} \ No newline at end of file
diff --git a/templates/staff/tables/table.html b/templates/staff/tables/table.html
new file mode 100644
index 00000000..aa26818f
--- /dev/null
+++ b/templates/staff/tables/table.html
@@ -0,0 +1,165 @@
+{% extends "main/base.html" %}
+{% block title %}Staff | Home{% endblock %}
+{% block og_title %}Staff | Home{% endblock %}
+{% block og_description %}Landing page for the staff management area{% endblock %}
+{% block content %}
+ <div class="uk-container uk-section uk-container-small">
+ <a class="uk-button uk-button-default" href="{{ url_for("staff.tables.index") }}"><i class="uk-icon fa-fw fas fa-arrow-left"></i> &nbsp;Back</a>
+
+ {% if page == "all" %}
+ <a class="uk-button uk-button-dark" href="{{ url_for("staff.tables.table", table=table, page=1) }}"><i class="uk-icon fa-fw fas fa-bars"></i> &nbsp;Page 1</a>
+ {% else %}
+ <a class="uk-button uk-button-dark" href="{{ url_for("staff.tables.table", table=table, page="all") }}"><i class="uk-icon fa-fw fas fa-bars"></i> &nbsp;All Data</a>
+ {% endif %}
+
+ {% if not table_obj.locked %}
+ <a class="uk-button uk-button-primary" href="{{ url_for("staff.tables.edit", table=table) }}"><i class="uk-icon fa-fw fas fa-plus"></i> &nbsp;Add</a>
+ {% endif %}
+
+ <h1 class="uk-title uk-text-center">
+ <span style="font-family: monospace">
+ {{ table }}
+
+ {% if table_obj.locked %}
+ <i class="uk-icon fa-fw fas fa-lock" title="Table locked for editing"></i>
+ {% endif %}
+ </span>
+ </h1>
+
+ <form action="{{ url_for("staff.tables.table", table=table, page="all") }}" method="get" class="uk-width-1-1">
+ <div class="uk-form-custom uk-width-1-1 uk-flex">
+ {% if search %}
+ <input class="uk-input uk-width-expand" name="search" type="text" placeholder="Search (RE2)" value="{{ search }}" />
+ {% else %}
+ <input class="uk-input uk-width-expand" name="search" type="text" placeholder="Search (RE2)" />
+ {% endif %}
+
+ <div class="uk-width-auto uk-flex-auto">
+ <select class="uk-select uk-width-1-1" name="search-key" title="Table Key">
+ <option style="font-weight: bold;">{{ table_obj.primary_key }}</option>
+ {% for key in table_obj.keys %}
+ {% if key != table_obj.primary_key %}
+ {% if search_key == key %}
+ <option selected>{{ key }}</option>
+ {% else %}
+ <option>{{ key }}</option>
+ {% endif %}
+ {% endif %}
+ {% endfor %}
+ </select>
+ </div>
+
+ <button class="uk-button uk-button-primary uk-width-auto" type="submit"><i class="uk-icon fas fa-search"></i></button>
+ <a class="uk-button uk-button-dark uk-width-auto" target="_blank" href="https://github.com/google/re2/wiki/Syntax"><i class="uk-icon fas fa-question-circle"></i></a>
+ </div>
+ </form>
+
+ {% macro paginate() %}
+ {% if pages != "all" %}
+ <ul class="uk-pagination uk-flex-center" uk-margin>
+ {% if page > 1 %}
+ <li><a href="{{ url_for("staff.tables.table", table=table, page=page - 1) }}"><span uk-pagination-previous></span></a></li>
+ {% else %}
+ <li class="uk-disabled"><a><span uk-pagination-previous></span></a></li>
+ {% endif %}
+
+ {% if page == 1 %}
+ <li class="uk-active"><a href="{{ url_for("staff.tables.table", table=table, page=1) }}">1</a></li>
+ {% else %}
+ <li><a href="{{ url_for("staff.tables.table", table=table, page=1) }}">1</a></li>
+ {% endif %}
+
+ {% if page >= 5 %}
+ <li class="uk-disabled"><a>...</a></li>
+ {% endif %}
+
+ {% set current_page = page - 2 %}
+
+ {% for num in range(5) %}
+ {% if current_page + num > 1 and current_page + num < pages %}
+ {% if current_page + num == page %}
+ <li class="uk-active"><a href="{{ url_for("staff.tables.table", table=table, page=current_page + num) }}">{{ current_page + num }}</a></li>
+ {% else %}
+ <li><a href="{{ url_for("staff.tables.table", table=table, page=current_page + num) }}">{{ current_page + num }}</a></li>
+ {% endif %}
+ {% endif %}
+ {% set current_page = current_page - 1 %}
+ {% endfor %}
+
+ {% if pages - page > 3 %}
+ <li class="uk-disabled"><a>...</a></li>
+ {% endif %}
+
+ {% if pages != 1 %}
+ {% if page == pages %}
+ <li class="uk-active"><a href="{{ url_for("staff.tables.table", table=table, page=pages) }}">{{ pages }}</a></li>
+ {% else %}
+ <li><a href="{{ url_for("staff.tables.table", table=table, page=pages) }}">{{ pages }}</a></li>
+ {% endif %}
+ {% endif %}
+
+ {% if page < pages %}
+ <li><a href="{{ url_for("staff.tables.table", table=table, page=page + 1) }}"><span uk-pagination-next></span></a></li>
+ {% else %}
+ <li class="uk-disabled"><a><span uk-pagination-next></span></a></li>
+ {% endif %}
+ </ul>
+ {% endif %}
+ {% endmacro %}
+
+ {{ paginate() }}
+
+ </div>
+ <div class="uk-container uk-section">
+ {% if documents %}
+ <table class="uk-table uk-table-striped uk-overflow-auto">
+ <thead>
+ <tr>
+ {% if not table_obj.locked %}
+ <th class="uk-table-shrink uk-text-center">
+ <i class="uk-icon fa-fw fas fa-pencil"></i>
+ </th>
+ {% endif %}
+
+ {% for key in table_obj.keys %}
+ <th title="{{ key }}">
+ {% if key == table_obj.primary_key %}
+ <strong>{{ key }}</strong>
+ {% else %}
+ {{ key }}
+ {% endif %}
+ </th>
+ {% endfor %}
+ </tr>
+ </thead>
+ <tbody>
+ {% for doc in documents %}
+ <tr>
+ {% if not table_obj.locked %}
+ <td class="uk-table-shrink">
+ <a href="{{ url_for("staff.tables.edit", table=table, key=doc[table_obj.primary_key]) }}">
+ <i class="uk-icon fa-fw fas fa-pencil"></i>
+ </a>
+ </td>
+ {% endif %}
+
+ {% for key in table_obj.keys %}
+ <td class="uk-text-truncate" style="font-family: monospace" title="{{ doc[key] }}">
+ {% if key == table_obj.primary_key %}
+ <strong>{{ doc[key] }}</strong>
+ {% else %}
+ {{ doc[key] }}
+ {% endif %}
+ </td>
+ {% endfor %}
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ {% else %}
+ <p class="uk-text-center">No documents found</p>
+ {% endif %}
+
+ {{ paginate() }}
+ </div>
+{% endblock %} \ No newline at end of file