Skip to content

Commit

Permalink
Improve incidents file-path naming and template locations
Browse files Browse the repository at this point in the history
* Rename htmx/incidents directory and fix imports
* Rename templates/htmx/incidents and fix mentioned paths
* Move table cell templates to cells/ directory
* Standardize on singular in view names and url names
* Move badge dropdown widget out of incidents since it is generic
  • Loading branch information
hmpf authored Jan 7, 2025
1 parent e1b3474 commit 7f603f9
Show file tree
Hide file tree
Showing 57 changed files with 90 additions and 76 deletions.
14 changes: 14 additions & 0 deletions changelog.d/+singularize-incidents.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Htmx: Customizers beware: Major refactor in src/argus/htmx/incident(s) and
src/argus/htmx/templates/htmx/incident(s).

* All directories named "incidents" was changed to "incident".
* The templates that defines columns in the incident list was moved to
`htmx/incident/cells/`.
* The template for selecting sources in the filterbox was moved to
`htmx/incident/widgets/`.
* Whenever there were plural view-names or url-names for incident-related views
they were made singular.

There will be empty directories left behind, `git` cannot do anything with
these. Run `make clean` to delete cached files then find empty directories with
`find . -type d -empty`. Delete them manually.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You only need to add the column to the column config::
IncidentTableColumn(
"mytag",
"MYTAG",
"htmx/incidents/_incident_tag.html",
"htmx/incidents/cells/_incident_tag.html",
context={"tag": "MYTAG"},
)
..
Expand Down
2 changes: 1 addition & 1 deletion src/argus/htmx/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from argus.htmx.dateformat.constants import DATETIME_DEFAULT, DATETIME_FORMATS, DATETIME_CHOICES
from argus.htmx.incidents.constants import DEFAULT_PAGE_SIZE, ALLOWED_PAGE_SIZES, PAGE_SIZE_CHOICES
from argus.htmx.incident.constants import DEFAULT_PAGE_SIZE, ALLOWED_PAGE_SIZES, PAGE_SIZE_CHOICES
from argus.htmx.themes.constants import THEME_CHOICES, THEME_NAMES, THEME_DEFAULT


Expand Down
2 changes: 1 addition & 1 deletion src/argus/htmx/dateformat/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from argus.auth.utils import get_or_update_preference

from argus.htmx.incidents.views import HtmxHttpRequest
from argus.htmx.incident.views import HtmxHttpRequest
from .constants import DATETIME_FORMATS

LOG = logging.getLogger(__name__)
Expand Down
6 changes: 3 additions & 3 deletions src/argus/htmx/defaults.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# customize the displayed columns in the incident table
# items in INCIDENT_TABLE_COLUMNS can be either a `str` referring to a key in
# argus.htmx.incidents.customization.BUILTIN_COLUMNS or an instance of
# argus.htmx.incidents.customization.IncidentTableColumn
# argus.htmx.incident.customization.BUILTIN_COLUMNS or an instance of
# argus.htmx.incident.customization.IncidentTableColumn
from argus.site.settings import get_json_env, get_str_env

INCIDENT_TABLE_COLUMNS = [
Expand All @@ -14,7 +14,7 @@
"description",
"ticket",
]
ARGUS_HTMX_FILTER_FUNCTION = "argus.htmx.incidents.filter.incident_list_filter"
ARGUS_HTMX_FILTER_FUNCTION = "argus.htmx.incident.filter.incident_list_filter"

# These templates are auto-discovered by the templating engine and are relative
# to the argus.htmx's `templates/` directory
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@ class IncidentTableColumn:
IncidentTableColumn(
"row_select",
"Selected",
"htmx/incidents/_incident_checkbox.html",
"htmx/incidents/_incident_list_select_all_checkbox.html",
"htmx/incident/cells/_incident_checkbox.html",
"htmx/incident/cells/_incident_list_select_all_checkbox_header.html",
),
IncidentTableColumn("id", "ID", "htmx/incidents/_incident_pk.html"),
IncidentTableColumn("id", "ID", "htmx/incident/cells/_incident_pk.html"),
IncidentTableColumn(
"start_time",
"Timestamp",
"htmx/incidents/_incident_start_time.html",
"htmx/incidents/_incident_start_time_header.html",
"htmx/incident/cells/_incident_start_time.html",
"htmx/incident/cells/_incident_start_time_header.html",
),
IncidentTableColumn("status", "Status", "htmx/incidents/_incident_status.html"),
IncidentTableColumn("level", "Severity level", "htmx/incidents/_incident_level.html"),
IncidentTableColumn("source", "Source", "htmx/incidents/_incident_source.html"),
IncidentTableColumn("description", "Description", "htmx/incidents/_incident_description.html"),
IncidentTableColumn("ack", "Ack", "htmx/incidents/_incident_ack.html"),
IncidentTableColumn("combined_status", "Status", "htmx/incidents/_incident_combined_status.html"),
IncidentTableColumn("ticket", "Ticket", "htmx/incidents/_incident_ticket.html"),
IncidentTableColumn("links", "Actions", "htmx/incidents/_incident_actions.html"),
IncidentTableColumn("status", "Status", "htmx/incident/cells/_incident_status.html"),
IncidentTableColumn("level", "Severity level", "htmx/incident/cells/_incident_level.html"),
IncidentTableColumn("source", "Source", "htmx/incident/cells/_incident_source.html"),
IncidentTableColumn("description", "Description", "htmx/incident/cells/_incident_description.html"),
IncidentTableColumn("ack", "Ack", "htmx/incident/cells/_incident_ack.html"),
IncidentTableColumn("combined_status", "Status", "htmx/incident/cells/_incident_combined_status.html"),
IncidentTableColumn("ticket", "Ticket", "htmx/incident/cells/_incident_ticket.html"),
IncidentTableColumn("links", "Actions", "htmx/incident/cells/_incident_actions.html"),
]
BUILTIN_COLUMNS = {col.name: col for col in _BUILTIN_COLUMN_LIST}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
from argus.filter import get_filter_backend
from argus.incident.models import SourceSystem
from argus.incident.constants import Level
from argus.htmx.widgets import DropdownMultiSelect
from argus.htmx.widgets import BadgeDropdownMultiSelect


filter_backend = get_filter_backend()
QuerySetFilter = filter_backend.QuerySetFilter


class BadgeDropdownMultiSelect(DropdownMultiSelect):
template_name = "htmx/incidents/widgets/incident_source_select.html"


class IncidentFilterForm(forms.Form):
open = forms.BooleanField(required=False)
closed = forms.BooleanField(required=False)
Expand All @@ -23,7 +19,7 @@ class IncidentFilterForm(forms.Form):
widget=BadgeDropdownMultiSelect(
attrs={"placeholder": "select sources..."},
extra={
"hx_get": "htmx:incidents-filter",
"hx_get": "htmx:incident-filter",
},
),
choices=tuple(SourceSystem.objects.values_list("id", "name")),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
urlpatterns = [
path("", views.incident_list, name="incident-list"),
path("<int:pk>/", views.incident_detail, name="incident-detail"),
path("update/<str:action>/", views.incidents_update, name="incidents-update"),
path("filter/", views.filter_form, name="incidents-filter"),
path("update/<str:action>/", views.incident_update, name="incident-update"),
path("filter/", views.filter_form, name="incident-filter"),
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_filter_function(arg=None):
ARGUS_HTMX_FILTER_FUNCTION can be one of:
* a callable that takes a Request and a QuerySet argument, and returns a Form and an updated
QuerySet (see ``argus.htmx.incidents.filter.incident_list_filter``)
QuerySet (see ``argus.htmx.incident.filter.incident_list_filter``)
* a dotted path to an importable function that has the above signature
* a dotted path to a module. This module should then contain a function named
``incident_list_filter`` with the above signature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def incident_detail(request, pk: int):
"incident": incident,
"page_title": str(incident),
}
return render(request, "htmx/incidents/incident_detail.html", context=context)
return render(request, "htmx/incident/incident_detail.html", context=context)


def get_form_data(request, formclass: forms.Form):
Expand All @@ -77,7 +77,7 @@ def get_form_data(request, formclass: forms.Form):


@require_POST
def incidents_update(request: HtmxHttpRequest, action: str):
def incident_update(request: HtmxHttpRequest, action: str):
try:
formclass, callback_func = INCIDENT_UPDATE_ACTIONS[action]
except KeyError:
Expand All @@ -94,7 +94,7 @@ def filter_form(request: HtmxHttpRequest):
incident_list_filter = get_filter_function()
filter_form, _ = incident_list_filter(request, None)
context = {"filter_form": filter_form}
return render(request, "htmx/incidents/_incident_filterbox.html", context=context)
return render(request, "htmx/incident/_incident_filterbox.html", context=context)


@require_GET
Expand Down Expand Up @@ -124,9 +124,9 @@ def incident_list(request: HtmxHttpRequest) -> HttpResponse:
# requests, allowing us to skip rendering the unchanging parts of the
# template.
if request.htmx:
base_template = "htmx/incidents/responses/_incident_list_refresh.html"
base_template = "htmx/incident/responses/_incident_list_refresh.html"
else:
base_template = "htmx/incidents/_base.html"
base_template = "htmx/incident/_base.html"
context = {
"columns": columns,
"filtered_count": filtered_count,
Expand All @@ -140,4 +140,4 @@ def incident_list(request: HtmxHttpRequest) -> HttpResponse:
"all_page_sizes": ALLOWED_PAGE_SIZES,
}

return render(request, "htmx/incidents/incident_list.html", context=context)
return render(request, "htmx/incident/incident_list.html", context=context)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "htmx/_base_form_modal.html" %}
{% block form_control %}
hx-post="{% url endpoint|default:'htmx:incidents-update' action=action %}"
hx-post="{% url endpoint|default:'htmx:incident-update' action=action %}"
hx-indicator="#{{ dialog_id }} .htmx-indicator"
{% if action_type == "bulk-update" %}
hx-include="[name='incident_ids']"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "htmx/incidents/_base_incident_update_modal.html" %}
{% extends "htmx/incident/_base_incident_update_modal.html" %}
{% block dialogform %}
<label class="indicator input input-bordered flex items-center gap-2 w-full">
Message
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "htmx/incidents/_base_incident_update_modal.html" %}
{% extends "htmx/incident/_base_incident_update_modal.html" %}
{% block dialogform %}
<label>
Reason for closing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
checked="checked" />
<div role="tabpanel"
class="filterbox tab-content border-primary [--tab-border:theme(borderWidth.DEFAULT)] rounded-box p-2">
{% include "htmx/incidents/_incident_filterbox.html" %}
{% include "htmx/incident/_incident_filterbox.html" %}
</div>
<input type="radio"
name="incident_menus"
Expand All @@ -17,7 +17,7 @@
aria-label="Update Incidents" />
<div role="tabpanel"
class="tab-content border-primary [--tab-border:theme(borderWidth.DEFAULT)] rounded-box p-2">
{% include "htmx/incidents/_incident_list_update_menu.html" %}
{% include "htmx/incident/_incident_list_update_menu.html" %}
</div>
{% endblock menu_tabs %}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="menu menu-horizontal gap-2">
{% block update_menu_content %}
{% with action_type="bulk-update" endpoint="htmx:incident-update" %}
{% include "htmx/incident/_incident_ticket_edit_modal.html" with action="update-ticket" dialog_id="add-ticket-dialog" button_class="btn-accent" button_title="Change ticket" header="Update ticket URL" explanation="Write an URL of an existing ticket, or nothing to remove existing ticket URLs" cancel_text="Cancel" submit_text="Submit" %}
{% include "htmx/incident/_incident_acknowledge_modal.html" with action="ack" dialog_id="create-acknowledgment-dialog" button_class="btn-accent" button_title="Acknowledge" header="Submit acknowledgment" explanation="Write a message describing why these incidents were acknowledged" cancel_text="Cancel" submit_text="Submit" %}
{% include "htmx/incident/_incident_close_modal.html" with action="close" dialog_id="close_incident-dialog" button_class="btn-accent" button_title="Close" header="Manually close incidents" explanation="Write a message describing why these incidents were manually closed" cancel_text="Cancel" submit_text="Close now" %}
{% include "htmx/incident/_incident_reopen_modal.html" with action="reopen" dialog_id="reopen-incident-dialog" button_class="btn-accent" button_title="Reopen" header="Manually reopen incidents" explanation="Write a message describing why these incidents were manually reopened" cancel_text="Cancel" submit_text="Reopen now" %}
{% endwith %}
{% endblock update_menu_content %}
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "htmx/incidents/_base_incident_update_modal.html" %}
{% extends "htmx/incident/_base_incident_update_modal.html" %}
{% block dialogform %}
<label>
Reason for reopening
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{% if col.header_template %}
{% include col.header_template with label=col.label %}
{% elif col.filter_field %}
{% include "htmx/incidents/_incident_filterable_column.html" with column=col %}
{% include "htmx/incident/cells/_incident_filterable_column_header.html" with column=col %}
{% else %}
{{ col.label }}
{% endif %}
Expand All @@ -27,15 +27,15 @@
</thead>
<tbody id="table-body">
{% block incident_rows %}
{% include "htmx/incidents/_incident_table_rows.html" with incident_list=page.object_list %}
{% include "htmx/incident/_incident_table_rows.html" with incident_list=page.object_list %}
{% endblock incident_rows %}
</tbody>
<tfoot>
<tr>
<td colspan="{{ columns|length }}" class="border-t border-primary">
<div class="flex justify-between items-center">
{% block refresh_info %}
{% include "htmx/incidents/_incident_list_refresh_info.html" %}
{% include "htmx/incident/_incident_list_refresh_info.html" %}
{% endblock refresh_info %}
<!--
The htmx attributes set on the nav here are inherited by the child links.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% for incident in incident_list %}
{% block incident %}
{% include "htmx/incidents/_incident_table_row.html" %}
{% include "htmx/incident/_incident_table_row.html" %}
{% endblock incident %}
{% empty %}
<tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends "htmx/incident/_base_incident_update_modal.html" %}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "htmx/incidents/_base_incident_update_modal.html" %}
{% extends "htmx/incident/_base_incident_update_modal.html" %}
{% block dialogform %}
<label>
Change ticket
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "htmx/incidents/_base_incident_update_modal.html" %}
{% extends "htmx/incident/_base_incident_update_modal.html" %}
{% block dialogform %}
<label>
Ticket url
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% include "htmx/incident/cells/_incident_status.html" %}
{% include "htmx/incident/cells/_incident_ack.html" %}
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ <h3 class="font-bold">Ticket</h3>
<div class="card-actions">
{% if incident.stateful %}
{% if incident.open %}
{% include "htmx/incidents/_incident_close_modal.html" with action="close" dialog_id="close-incident-dialog" button_title="Close" header="Manually close incident" explanation="Write a message describing why the incident was manually closed" cancel_text="Cancel" submit_text="Close now" %}
{% include "htmx/incident/_incident_close_modal.html" with action="close" dialog_id="close-incident-dialog" button_title="Close" header="Manually close incident" explanation="Write a message describing why the incident was manually closed" cancel_text="Cancel" submit_text="Close now" %}
{% else %}
{% include "htmx/incidents/_incident_reopen_modal.html" with action="reopen" dialog_id="reopen-incident-dialog" button_title="Reopen" header="Manually reopen incident" explanation="Write a message describing why the incident was manually reopend" cancel_text="Cancel" submit_text="Reopen now" %}
{% include "htmx/incident/_incident_reopen_modal.html" with action="reopen" dialog_id="reopen-incident-dialog" button_title="Reopen" header="Manually reopen incident" explanation="Write a message describing why the incident was manually reopend" cancel_text="Cancel" submit_text="Reopen now" %}
{% endif %}
{% endif %}
{% if incident.ticket_url %}
{% include "htmx/incidents/_incident_ticket_edit_modal.html" with action="update-ticket" dialog_id="edit-ticket-dialog" button_title="Edit ticket url" header="Edit ticket" explanation="" cancel_text="Cancel" submit_text="Update" %}
{% include "htmx/incident/_incident_ticket_edit_modal.html" with action="update-ticket" dialog_id="edit-ticket-dialog" button_title="Edit ticket url" header="Edit ticket" explanation="" cancel_text="Cancel" submit_text="Update" %}
{% else %}
<!-- Manually create ticket dialog -->
{% include "htmx/incidents/_incident_ticket_edit_modal.html" with action="add-ticket" dialog_id="manual-create-ticket-dialog" button_title="Add ticket url" header="Add url to existing ticket" explanation="Are you sure you want to store this url to an existing ticket on this incident?" cancel_text="Cancel" submit_text="Add ticket" %}
{% include "htmx/incident/_incident_ticket_edit_modal.html" with action="add-ticket" dialog_id="manual-create-ticket-dialog" button_title="Add ticket url" header="Add url to existing ticket" explanation="Are you sure you want to store this url to an existing ticket on this incident?" cancel_text="Cancel" submit_text="Add ticket" %}
{% endif %}
</div>
</div>
Expand All @@ -96,7 +96,7 @@ <h2 class="card-title">Acknowledgements</h2>
</div>
{% endfor %}
<div class="card-actions divide-none">
{% include "htmx/incidents/_incident_acknowledge_modal.html" with action="ack" dialog_id="create-acknowledgment-dialog" button_title="Create acknowledgment" header="Submit acknowledgment" explanation="Write a message describing why this incident was acknowledged" cancel_text="Cancel" submit_text="Submit" %}
{% include "htmx/incident/_incident_acknowledge_modal.html" with action="ack" dialog_id="create-acknowledgment-dialog" button_title="Create acknowledgment" header="Submit acknowledgment" explanation="Write a message describing why this incident was acknowledged" cancel_text="Cancel" submit_text="Submit" %}
</div>
</div>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<section>
{% if incidents_extra_widget %}
<div class="flex">
<div class="w-2/3">{% include "htmx/incidents/_incident_list_menubar.html" %}</div>
<div class="w-2/3">{% include "htmx/incident/_incident_list_menubar.html" %}</div>
<div class="w-1/3 ml-2">{% include incidents_extra_widget %}</div>
</div>
{% else %}
{% include "htmx/incidents/_incident_list_menubar.html" %}
{% include "htmx/incident/_incident_list_menubar.html" %}
{% endif %}
</section>
<section id="incident-list" class="loading-box overflow-x-auto">
{% block table %}
{% include "htmx/incidents/_incident_table.html" %}
{% include "htmx/incident/_incident_table.html" %}
{% endblock table %}
<div class="htmx-indicator loading loading-spinner loading-lg text-primary"></div>
</section>
Expand Down

This file was deleted.

Loading

0 comments on commit 7f603f9

Please sign in to comment.