aboutsummaryrefslogtreecommitdiffstats
path: root/templates/staff/tables/table.html
blob: aa26818fea921f3975528ebcf0d91b5445ab7df4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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 %}