Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorters search #207

Merged
merged 70 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
fd8087f
Update tables.py
cvzbynek Oct 31, 2024
cfc8343
Update partials.py
cvzbynek Oct 31, 2024
0d3e6bd
Debug output
cvzbynek Nov 1, 2024
a6c3150
Sorting
cvzbynek Nov 4, 2024
78cfbaf
Graphics overhaul
cvzbynek Nov 4, 2024
a75b7cf
Update index.html
cvzbynek Nov 4, 2024
61b592d
Search and debug
cvzbynek Nov 5, 2024
ceccdf6
Works with debugs
cvzbynek Nov 5, 2024
c171714
Debug gone
cvzbynek Nov 5, 2024
209e71d
Merge branch 'main' into Sorters_search
cvzbynek Nov 5, 2024
2057b27
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 5, 2024
10869e7
Update test_partial_views.py
cvzbynek Nov 5, 2024
97b02ff
Merge branch 'Sorters_search' of https://github.com/ImperialCollegeLo…
cvzbynek Nov 5, 2024
8868bde
PR fixes inline and test
cvzbynek Nov 5, 2024
e9f633e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 5, 2024
4ac9924
Update process_table.html
cvzbynek Nov 5, 2024
5207566
Update test_partial_views.py
cvzbynek Nov 5, 2024
3c328c5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 5, 2024
832d865
Update test_partial_views.py
cvzbynek Nov 5, 2024
7a1b442
Merge branch 'Sorters_search' of https://github.com/ImperialCollegeLo…
cvzbynek Nov 5, 2024
b0c9485
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 5, 2024
baa7cf5
Update test_partial_views.py
cvzbynek Nov 5, 2024
078c2d0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 5, 2024
7daf74a
Update test_partial_views.py
cvzbynek Nov 5, 2024
e306c54
Merge branch 'Sorters_search' of https://github.com/ImperialCollegeLo…
cvzbynek Nov 5, 2024
3ed4f7c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 5, 2024
5f2b15e
Update index.html
cvzbynek Nov 5, 2024
1dea93e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 5, 2024
82e1278
Merge branch 'main' into Sorters_search
cvzbynek Nov 11, 2024
8530c42
Merge branch 'Sorters_search' of https://github.com/ImperialCollegeLo…
cvzbynek Nov 11, 2024
2ed3d6e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 11, 2024
8549054
Merge branch 'main' into Sorters_search
cvzbynek Nov 12, 2024
0400987
Combined-search gone
cvzbynek Nov 14, 2024
313abad
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 14, 2024
21015f0
Update test_partial_views.py
cvzbynek Nov 14, 2024
7918d64
Merge branch 'Sorters_search' of https://github.com/ImperialCollegeLo…
cvzbynek Nov 14, 2024
36bfada
Update process_manager/templates/process_manager/index.html
cvzbynek Nov 14, 2024
8bea57f
Update partials.py
cvzbynek Nov 14, 2024
d27007d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 14, 2024
0ec521e
Update process_table.html
cvzbynek Nov 14, 2024
cc42a9a
Merge branch 'Sorters_search' of https://github.com/ImperialCollegeLo…
cvzbynek Nov 14, 2024
c901845
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 14, 2024
23a82e0
Update test_partial_views.py
cvzbynek Nov 14, 2024
a45db17
Merge branch 'Sorters_search' of https://github.com/ImperialCollegeLo…
cvzbynek Nov 14, 2024
d50ead7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 14, 2024
d5109e3
Merge branch 'main' into Sorters_search
cvzbynek Nov 15, 2024
58538a7
Merge branch 'main' into Sorters_search
cvzbynek Nov 21, 2024
abb4af9
Update process_table.html
cvzbynek Nov 21, 2024
fe64208
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
be9d755
Update process_table.html
cvzbynek Nov 21, 2024
13c78ec
Merge branch 'Sorters_search' of https://github.com/ImperialCollegeLo…
cvzbynek Nov 21, 2024
e796921
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
8a33ec1
Update process_table.html
cvzbynek Nov 21, 2024
429e905
Update process_table.html
cvzbynek Nov 21, 2024
7d5192d
Merge branch 'Sorters_search' of https://github.com/ImperialCollegeLo…
cvzbynek Nov 21, 2024
b844284
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
02b70a1
Update process_table.html
cvzbynek Nov 21, 2024
28ed1ac
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
efd27a7
Merge branch 'main' into Sorters_search
cvzbynek Nov 22, 2024
9424e8c
Merge branch 'main' into Sorters_search
cvzbynek Nov 25, 2024
d411c18
Merge branch 'main' into Sorters_search
cvzbynek Nov 27, 2024
044dd77
Flickering fix
cvzbynek Nov 28, 2024
fa2ef5c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 28, 2024
1f22c3e
Inline fix
cvzbynek Nov 28, 2024
555842d
Merge branch 'Sorters_search' of https://github.com/ImperialCollegeLo…
cvzbynek Nov 28, 2024
2ce2e17
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 28, 2024
89583cf
CSS fix
cvzbynek Nov 28, 2024
de722f3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 28, 2024
e384ffc
Merge branch 'main' into Sorters_search
cc-a Nov 29, 2024
0208262
Merge branch 'main' into Sorters_search
cc-a Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions process_manager/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,44 @@ class ProcessTable(tables.Table):

uuid = tables.Column(
verbose_name="UUID",
orderable=True,
attrs={"td": {"class": "fw-bold text-break text-start"}},
)
name = tables.Column(
verbose_name="Process Name",
orderable=True,
attrs={
"td": {"class": "fw-bold text-primary text-center"},
"th": {"class": "text-center header-style"},
},
)
user = tables.Column(
verbose_name="User",
orderable=True,
attrs={
"td": {"class": "text-secondary text-center"},
"th": {"class": "text-center header-style"},
},
)
session = tables.Column(
verbose_name="Session",
orderable=True,
attrs={
"td": {"class": "text-secondary text-center"},
"th": {"class": "text-center header-style"},
},
)
status_code = tables.Column(
verbose_name="Status",
orderable=True,
attrs={
"td": {"class": "fw-bold text-center"},
"th": {"class": "text-center header-style"},
},
)
exit_code = tables.Column(
verbose_name="Exit Code",
orderable=True,
attrs={
"td": {"class": "text-center"},
"th": {"class": "text-center header-style"},
Expand All @@ -68,13 +74,15 @@ class ProcessTable(tables.Table):
logs = tables.TemplateColumn(
logs_column_template,
verbose_name="Logs",
orderable=False,
attrs={
"td": {"class": "text-center"},
"th": {"class": "text-center header-style"},
},
)
select = tables.CheckBoxColumn(
accessor="uuid",
orderable=False,
verbose_name="Select",
attrs={
"th__input": {
Expand Down
90 changes: 83 additions & 7 deletions process_manager/templates/process_manager/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,67 @@
max-height: 80vh;
overflow-y: auto;
}
#search-dropdown {
width: auto;
padding: 0.375rem 0.75rem;
font-size: 1rem;
border: 1px solid #ced4da;
border-radius: 0.25rem;
}
.custom-thead {
background-color: #f8f9fa;
border-radius: 8px;
}
.custom-th {
padding: 10px;
text-align: center;
font-weight: 600;
color: #495057;
}
.sort-link {
text-decoration: none;
color: #007bff;
display: flex;
align-items: center;
justify-content: center;
}

.sort-icon {
font-size: 0.9em;
margin-left: 5px;
opacity: 0.6;
}
.table-header {
font-weight: bold;
color: #6c757d;
}
.clear-sorting {
padding: 5px 12px;
background-color: #f8f9fa;
color: #495057;
border: 1px solid #ddd;
border-radius: 8px;
font-size: 0.9em;
font-weight: 600;
cursor: pointer;
text-decoration: none;
transition: background-color 0.3s ease;
}
.sort-link {
cursor: pointer;
text-decoration: none;
color: blue;
}


.sort-link:hover {
text-decoration: underline;
color: darkblue;
}

.clear-sorting:hover {
background-color: #e2e6ea;
}
.table-container {
border-radius: 10px;
}
Expand Down Expand Up @@ -171,13 +232,28 @@ <h5>Process Control</h5>
class="btn btn-info w-100 ms-2"
_="on click hide me toggle .hide-messages on #main-content">Show Messages</button>
</div>
<input class="form-control mb-3"
type="search"
name="search"
placeholder="Search processes..."
hx-get="{% url 'process_manager:process_table' %}"
hx-trigger="input changed delay:500ms, every 1s"
hx-target="div.table-container">
<div class="d-flex align-items-center mb-3">
<select id="search-dropdown" name="search-drp" class="form-control me-2">
<option value="">Search By</option>
<option value="uuid">UUID</option>
<option value="name">Process Name</option>
<option value="user">User</option>
<option value="session">Session</option>
<option value="status_code">Status</option>
<option value="exit_code">Exit Code</option>
</select>
<input id="search-input"
class="form-control"
type="search"
name="search"
placeholder="Search processes..."
style="flex: 1"
hx-get="{% url 'process_manager:process_table' %}"
hx-trigger="input changed delay:500ms, every 1s"
hx-target="div.table-container"
hx-include="#sort-field, #search-dropdown">
</div>
<input type="hidden" id="sort-field" name="sort" value="">
cvzbynek marked this conversation as resolved.
Show resolved Hide resolved
<div class="table-container"></div>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
{% extends "django_tables2/table.html" %}
{% load render_table from django_tables2 %}
{% load querystring from django_tables2 %}
{% block table.thead %}
<div>
<a href="{% url 'process_manager:process_table' %}?sort="
_="on click set #sort-field's value to '' set #sort-param-display's textContent to 'None'"
hx-get="{% url 'process_manager:process_table' %}?sort="
hx-target="div.table-container"
class="clear-sorting">Clear Sorting</a>
</div>
{% if table.show_header %}
<thead class="custom-thead" {{ table.attrs.thead.as_html }}>
<tr>
{% for column in table.columns %}
<th class="custom-th" {{ column.attrs.th.as_html }}>
{% if column.orderable %}
<a _="on click get #sort-field then set currentSort to its.value then if currentSort is '{{ column.name }}' set #sort-field's value to '-{{ column.name }}' else set #sort-field's value to '{{ column.name }}' end then set newSortUrl to '{% url 'process_manager:process_table' %}?sort=' + #sort-field.value then my.setAttribute('hx-get', newSortUrl) then call htmx.ajax('GET', newSortUrl, {target: 'div.table-container'})"
class="sort-link">
{{ column.header }}
<span class="sort-icon">⇅</span>
</a>
{% else %}
<span class="table-header">{{ column.header }}</span>
{% endif %}
</th>
{% endfor %}
</tr>
</thead>
{% endif %}
{% endblock table.thead %}
{% render_table table %}
75 changes: 35 additions & 40 deletions process_manager/views/partials.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""View functions for partials."""

import django_tables2
from django.contrib.auth.decorators import login_required
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
Expand All @@ -13,19 +12,18 @@


def filter_table(
search: str, table: list[dict[str, str | int]]
search: str, column: str, table: list[dict[str, str | int]]
) -> list[dict[str, str | int]]:
"""Filter table data based on search parameter.
"""Filter table data based on search and column parameters.

If the search parameter is empty, the table data is returned unfiltered. Otherwise,
the table data is filtered based on the search parameter. The search parameter can
be a string or a string with a column name and search string separated by a colon.
If the search parameter is a column name, the search string is matched against the
values in that column only. Otherwise, the search string is matched against all
columns.
the table data is filtered based on the search parameter. If the column parameter
is provided, the search string is matched against the values in that column only.
If no valid column is specified, the search string is matched against all columns.

Args:
search: The search string to filter the table data.
column: The column name to filter by, or an empty string to search all columns.
table: The table data to filter.

Returns:
Expand All @@ -35,17 +33,9 @@ def filter_table(
return table

all_cols = list(table[0].keys())
column, _, search = search.partition(":")
if not search:
# No column-based filtering
search = column
columns = all_cols
elif column not in all_cols:
# If column is unknown, search all columns
columns = all_cols
else:
# Search only the specified column
columns = [column]
columns = [column] if column in all_cols else all_cols

# Convert search string to lowercase for case-insensitive matching
search = search.lower()
return [row for row in table if any(search in str(row[k]).lower() for k in columns)]

Expand All @@ -63,31 +53,36 @@ def process_table(request: HttpRequest) -> HttpResponse:

status_enum_lookup = dict(item[::-1] for item in ProcessInstance.StatusCode.items())

table_data = []
process_instances = session_info.data.values
for process_instance in process_instances:
metadata = process_instance.process_description.metadata
uuid = process_instance.uuid.uuid
table_data.append(
{
"uuid": uuid,
"name": metadata.name,
"user": metadata.user,
"session": metadata.session,
"status_code": status_enum_lookup[process_instance.status_code],
"exit_code": process_instance.return_code,
}
)
# Filter table data based on search parameter
table_data = filter_table(request.GET.get("search", ""), table_data)
# Build the table data
table_data = [
{
"uuid": process_instance.uuid.uuid,
"name": process_instance.process_description.metadata.name,
"user": process_instance.process_description.metadata.user,
"session": process_instance.process_description.metadata.session,
"status_code": status_enum_lookup[process_instance.status_code],
"exit_code": process_instance.return_code,
}
for process_instance in session_info.data.values
]
# Get the values from the GET request
search_dropdown = request.GET.get("search-drp", "")
search_input = request.GET.get("search", "")

# Determine the column and search values for filtering
column = search_dropdown if search_dropdown else ""
search = search_input if search_input else ""

# Apply search filtering
table_data = filter_table(search, column, table_data)
table = ProcessTable(table_data)

# sort table data based on request parameters
table_configurator = django_tables2.RequestConfig(request)
table_configurator.configure(table)
# Set the order based on the 'sort' parameter in the GET request, defaulting to ''
sort_param = request.GET.get("sort", "")
table.order_by = sort_param

return render(
request=request,
context=dict(table=table),
context={"table": table},
template_name="process_manager/partials/process_table.html",
)
Loading
Loading