Skip to content

Commit

Permalink
change link to custom form when adding row
Browse files Browse the repository at this point in the history
  • Loading branch information
anitacaron committed Mar 11, 2024
1 parent d8735f1 commit b8f668c
Showing 1 changed file with 364 additions and 0 deletions.
364 changes: 364 additions & 0 deletions src/ontology/src/resources/table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,364 @@
{#
## This template is derived from https://github.com/ontodev/nanobot.rs/blob/main/src/resources/table.html
## This only redirects to another form template when adding a new row, which is the same as when editing a row.
## Issue requested in https://github.com/ontodev/nanobot.rs/issues/76
#}

{% extends "page.html" %}
{% block content %}
<h2>{{ table.table }}</h2>

<form class="modal fade" id="updateLoc" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Show Results</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="row py-2">
<div class="col-md-4">
<label class="col-form-label">Results per page</label>
</div>
<div class="col-auto">
<input type="number" name="limit" class="form-control" value="{{ page.select_params.limit }}">
</div>
</div>
<div class="row py-2">
<div class="col-md-4">
<label class="col-form-label">Skip rows</label>
</div>
<div class="col-auto">
<input type="number" class="form-control" name="offset" value="{{ page.select_params.offset or 0 }}">
</div>
</div>
</div>
<div class="modal-footer">
<a href="{{ table.first }}" class="btn btn-secondary">Reset</a>
<input type="submit" class="btn btn-primary" value="Update" />
</div>
</div>
</div>
{% for key, value in page.select_params|items %}
{% if key not in ["limit", "offset"] %}
<input type="hidden" name="{{ key }}" value="{{ value }}" />
{% endif %}
{% endfor %}
</form>

{% for name, value in column|items -%}
<form class="modal fade" id="{{ name|id }}Modal" tabindex="-1" aria-labelledby="{{ name|id }}ModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="{{ name|id }}ModalLabel">{{ value.label or name }}</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
{% if value.description %}
<div class="row">
<p>{{ value.description }}</p>
</div>

{% endif %}
<div class="row">
<div class="btn-group">
<a class="btn {{ 'btn-primary' if value.sorted == 'asc' else 'btn-outline-primary' }}"
href="{{ value.sort_ascending }}">A-Z</a>
<a class="btn {{ 'btn-primary' if value.sorted == 'desc' else 'btn-outline-primary' }}"
href="{{ value.sort_descending }}">Z-A</a>
<a class="btn {{ 'btn-outline-primary' if value.sorted else 'btn-primary' }}"
href="{{ value.sort_none }}">None</a>
</div>
</div>

{# TODO: Add support for hiding columns.
<hr />
<div class="row">
<a href="{{ value.hide }}"><i class="bi-eye-slash"></i> Hide column</a>
</div>
#}

<hr />
<div class="row">
<div class="col-auto pb-2">Filter by condition</div>
</div>

<div class="row">
<input type="hidden" name="nb.action" value="filter">
<input type="hidden" name="nb.column" value="{{ name }}">
<div class="col-md-6">
<select class="form-select" name="nb.operator">
<option value="eq" {% if value.filtered_operator=='eq' %}selected="true" {% endif %}>equals</option>
<option value="not_eq" {% if value.filtered_operator=='not_eq' %}selected="true" {% endif %}>not equals
</option>
{% if value.numeric %}
<option value="gt" {% if value.filtered_operator=='gt' %}selected="true" {% endif %}>greater than
</option>
<option value="gte" {% if value.filtered_operator=='gte' or not value.filtered_operator %}selected="true"
{% endif %}>greater than or
equal to</option>
<option value="lt" {% if value.filtered_operator=='lt' %}selected="true" {% endif %}>less than</option>
<option value="lte" {% if value.filtered_operator=='lte' %}selected="true" {% endif %}>less than or
equal to</option>
{% else %}
<option value="like" {% if value.filtered_operator=='like' %}selected="true" {% endif %}>like</option>
<option value="ilike" {% if value.filtered_operator=='ilike' or not value.filtered_operator
%}selected="true" {% endif %}>like (case
insensitive)</option>
{% endif %}
<option value="is" {% if value.filtered_operator=='is' %}selected="true" {% endif %}>is</option>
<option value="not_is" {% if value.filtered_operator=='not_is' %}selected="true" {% endif %}>is not
</option>
<option value="in" {% if value.filtered_operator=='in' %}selected="true" {% endif %}>in</option>
<option value="not_in" {% if value.filtered_operator=='not_in' %}selected="true" {% endif %}>not in
</option>
</select>
</div>
<div class="col-md-6">
<input class="form-control" name="nb.constraint" type="text" value="{{ value.filtered_constraint }}">
</div>
</div>
{% if not value.numeric %}
<div class="row">
<p class="mt-2 mb-0">
For <code>like</code> and <code>ilike</code> operators, use <code>*</code> to match any character (instead
of <code>%</code>).
</p>
</div>
{% endif %}

<div id="details-{{name}}" class="collapse">
<hr />
<pre><code>{{name}} -- {{ value|tojson(true) }}</code></pre>
</div>
</div>

<div class="modal-footer">
<a data-bs-toggle="collapse" href="#details-{{name}}" role="button" aria-expanded="false">Debug</a>
<a href="{{ value.reset }}" class="btn btn-secondary">Reset</a>
<input type="submit" class="btn btn-primary" value="Update" />
</div>
</div>
</div>

{% for key, value in page.select_params|items %}
{% if key not in ["offset"] %}
<input type="hidden" name="{{ key }}" value="{{ value }}" />
{% endif %}
{% endfor %}
</form>
{% endfor %}

<div class="row">
<div class="col">
<nav style="display: inline-block" aria-label="Page navigation">
<ul class="pagination justify-content-end">
<li class="page-item">
<a class="page-link {{ 'disabled' if not table.first }}" href="{{ table.first }}" aria-label="First">
<span aria-hidden="true"><i class="bi bi-chevron-bar-left"></i></span>
<span class="visually-hidden">First</span>
</a>
</li>
<li class="page-item">
<a class="page-link {{ 'disabled' if not table.previous }}" href="{{ table.previous }}" aria-label="Previous">
<span aria-hidden="true"><i class="bi bi-chevron-left"></i></span>
<span class="visually-hidden">Previous</span>
</a>
</li>
<li class="page-item">
<button class="page-link" data-bs-toggle="modal" data-bs-target="#updateLoc">
{{ table.start }}-{{ table.end }}
</button>
</li>
<li class="page-item">
<a class="page-link {{ 'disabled' if not table.next }}" href="{{ table.next }}" aria-label="Next">
<span aria-hidden="true"><i class="bi bi-chevron-right"></i></span>
<span class="visually-hidden">Next</span>
</a>
</li>
<li class="page-item">
<a class="page-link {{ 'disabled' if not table.last }}" href="{{ table.last }}" aria-label="Last">
<span aria-hidden="true"><i class="bi bi-chevron-bar-right"></i></span>
<span class="visually-hidden">Last</span>
</a>
</li>
</ul>
</nav>

{# range #}
<span class="mx-2">
Showing
{{ table.start }}-{{ table.end }} of
{% if table.counts.count == 1 %}
1 row
{% else %}
{{ table.counts.count }}
{% endif %}
{% if table.counts.total > table.counts.count %}
rows filtered from {{ table.counts.total }}.
{% else %}
rows.
{% endif %}
</span>

{# message_rows #}
<span>
{% if table.counts.message_row == 1 %}
1
<a href="{{ table.href }}?message=not_is.null">row</a>
has
{% elif table.counts.message_row > 1 %}
{{ table.counts.message_row }}
<a href="{{ table.href }}?message=not_is.null">rows</a>
have
{% endif %}
</span>

{# message counts #}
<span>
{% if table.counts.message == 1 %}
1
<a href="message?table=eq.{{ table.table }}">message</a>:
{% elif table.counts.message > 1 %}
{{ table.counts.message }}
<a href="message?table=eq.{{ table.table }}">messages</a>:
{% endif %}
</span>

{# message types #}
<span class="me-2">
{% if table.counts.message %}
{% if table.counts.error %}
<strong>{{ table.counts.error }}</strong>
<i class="bi bi-exclamation-octagon-fill text-danger"></i>
{% endif %}
{% if table.counts.warn %}
<strong>{{ table.counts.warn }}</strong>
<i class="bi bi-exclamation-triangle-fill text-warning"></i>
{% endif %}
{% if table.counts.info %}
<strong>{{ table.counts.info}}</strong>
<i class="bi bi-info-circle-fill text-info"></i>
{% endif %}
{% if table.counts.update %}
<strong>{{ table.counts.update}}</strong>
<i class="bi bi-clock-history text-secondary"></i>
{% endif %}
{% endif %}
</span>

<a class="btn btn-outline-secondary" href="{{ table.href }}">Reset</a>

<span>
<a class="btn btn-outline-secondary dropdown-toggle" href="" data-bs-toggle="dropdown" aria-expanded="false">
Format
</a>
<ul class="dropdown-menu">
{% for name, href in table.formats|items %}
<li><a class="dropdown-item" href="{{ href }}">{{ name }}</a></li>
{% endfor %}
</ul>
</span>

{% if table.table != "message" %}
<a class="btn btn-outline-success" href="{{ table.table }}?view={{ table.edit_view or 'form' }}">Add row</a>
{% endif %}

</div>
</div>

<table class="table table-sm">
<thead>
<tr>
<th />
{% for name, value in column|items -%}
<th>
<a class="" data-bs-toggle="modal" href="#{{ name|id }}Modal" role="button">
{{ value.label or name }}
</a>
{% if value.filtered_operator %}
<i class="bi bi-filter-circle-fill"></i>
{% elif value.sorted == "asc" %}
<i class="bi bi-sort-up"></i>
{% elif value.sorted == "desc" %}
<i class="bi bi-sort-down"></i>
{% endif %}
</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for r in row -%}
<tr>
{% for column, cell in r|items -%}
{% if column == "row_number" %}
<td>
<a class="btn btn-sm" href="{{ table.href }}/row/{{ cell.value }}?view={{ table.edit_view or 'form' }}"><i
class="bi-pencil" style="color: #adb5bd;"></i></a>
</td>
{% else %}
<td class="{{ cell.classes|join(" , ") }}">
{% if cell.nulltype %}
{% elif cell.href %}
<a href="{{ cell.href }}">{{ cell.value }}</a>
{% else %}
{{ cell.value }}
{% endif %}
{% if cell.messages or cell.history %}
<div class="dropdown float-end">
<a class="text-body" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="true">
{% if cell.messages and cell.messages|length > 1 %}
<strong>{{ cell.messages|length }}</strong>
{% endif %}
{% if cell.message_level == "error" %}
<i class="bi bi-exclamation-octagon-fill text-danger"></i>
{% elif cell.message_level == "warn" %}
<i class="bi bi-exclamation-triangle-fill text-warning"></i>
{% elif cell.message_level == "info" %}
<i class="bi bi-info-circle-fill text-info"></i>
{% endif %}
{% if cell.history %}
<i class="bi bi-clock-history text-secondary"></i>
{% endif %}
</a>
<ul class="dropdown-menu">
{% for message in cell.messages %}
<li>
<a class="dropdown-item" href="#">
{% if message.level == "error" %}
<i class="bi bi-exclamation-octagon-fill text-danger"></i>
{% elif message.level == "warn" %}
<i class="bi bi-exclamation-triangle-fill text-warning"></i>
{% elif message.level == "info" %}
<i class="bi bi-info-circle-fill text-info"></i>
{% elif message.level == "update" %}
<i class="bi bi-clock-history text-secondary"></i>
{% else %}
<i class="bi bi-question-circle-fill"></i>
{% endif %}
{{ message.message }}
</a>
</li>
{% endfor %}
{% for history in cell.history %}
<li>
<a class="dropdown-item" href="#">
<i class="bi bi-clock-history text-secondary"></i>
{{ history.message }}
</a>
</li>
{% endfor %}
</ul>
</div>
</td>
{% endif %}
</td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

0 comments on commit b8f668c

Please sign in to comment.