Skip to content

Commit 2e4062e

Browse files
authored
Add the django-htmx app to the stack (#1917)
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 5382bbb commit 2e4062e

24 files changed

+333
-262
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ dependencies = [
4444
"django-filter==25.1",
4545
"djangorestframework==3.16.1",
4646
"django-taggit==6.1.0",
47+
"django-htmx==1.26.0",
4748
# Database
4849
"psycopg[binary]==3.2.10",
4950
# wait_for_database Django management command

scancodeio/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
"django_rq",
199199
"django_probes",
200200
"taggit",
201+
"django_htmx",
201202
]
202203

203204
MIDDLEWARE = [
@@ -208,6 +209,7 @@
208209
"django.contrib.auth.middleware.AuthenticationMiddleware",
209210
"django.contrib.messages.middleware.MessageMiddleware",
210211
"django.middleware.clickjacking.XFrameOptionsMiddleware",
212+
"django_htmx.middleware.HtmxMiddleware",
211213
"scancodeio.middleware.TimezoneMiddleware",
212214
]
213215

scancodeio/static/htmx-2.0.4.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

scancodeio/static/htmx-2.0.4.min.js.ABOUT

Lines changed: 0 additions & 13 deletions
This file was deleted.

scancodeio/static/main.css

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,21 @@ progress.file-upload::before {
367367
textarea.is-dynamic {
368368
min-height: 70px;
369369
}
370+
#project-list-header ul#id_is_archived {
371+
display: inline-flex;
372+
}
373+
#project-list-header ul#id_is_archived li {
374+
margin-right: 1rem;
375+
}
376+
#project-list-header ul#id_is_archived li a {
377+
color: var(--bulma-grey);
378+
}
379+
#project-list-header ul#id_is_archived li a:hover {
380+
text-decoration: underline;
381+
}
382+
#project-list-header ul#id_is_archived li a.is-active {
383+
color: var(--bulma-text);
384+
}
370385
#project-extra-data figure.highlight {
371386
overflow-y: scroll;
372387
}
@@ -406,3 +421,139 @@ textarea.is-dynamic {
406421
#codebase-relation-list th#column-map_type {
407422
width: 145px;
408423
}
424+
#dependency-tree.tree {
425+
line-height: 1.8rem;
426+
--spacing : 2rem;
427+
}
428+
#dependency-tree.tree summary {
429+
display: inline-block;
430+
}
431+
#dependency-tree.tree summary::before{
432+
background-color: rgb(72, 199, 142);
433+
background-image: url('{% static "iamkate-tree-views/expand-collapse.svg" %}');
434+
}
435+
#resource-viewer #editor {
436+
min-height:730px;
437+
border: var(--bulma-grey) 1px solid;
438+
}
439+
#resource-viewer .tag {
440+
height: 1.5em;
441+
padding-left: 0.5em;
442+
padding-right: 0.5em;
443+
}
444+
#resource-viewer .nav-button .button {
445+
height: auto;
446+
padding: 0 .25rem 0 .25rem;
447+
}
448+
#resource-viewer #detected-data-buttons {
449+
background-color: var(--bulma-pre-background);
450+
border-left: var(--bulma-grey) 1px solid;
451+
border-right: var(--bulma-grey) 1px solid;
452+
}
453+
#resource-viewer #detected-data-buttons p.control {
454+
border-right: var(--bulma-grey) 1px solid;
455+
}
456+
#resource-viewer .ace_tooltip .ace_icon {
457+
display: none;
458+
}
459+
460+
/* Full screen for #resource-viewer
461+
Inspired by ace/demo/scrollable-page.html */
462+
body.full-screen {
463+
overflow: hidden;
464+
/* transform breaks position fixed */
465+
transform: none !important;
466+
}
467+
body.full-screen #resource-viewer {
468+
height: auto;
469+
width: auto;
470+
border: 0;
471+
margin: 0;
472+
position: fixed !important;
473+
top: 0;
474+
bottom: 0;
475+
left: 0;
476+
right: 0;
477+
z-index: 100;
478+
}
479+
body.full-screen #resource-viewer .message-header {
480+
border-radius: 0 !important;
481+
}
482+
483+
#resource-tree-container .resizable-container {
484+
height: calc(100vh - 140px);
485+
}
486+
#resource-tree-container .chevron {
487+
transition: transform 0.2s ease;
488+
display: inline-block;
489+
}
490+
#resource-tree-container .chevron.rotated {
491+
transform: rotate(90deg);
492+
}
493+
#resource-tree-container .left-pane {
494+
min-width: 0;
495+
max-width: 100%;
496+
border-right: 1px solid #ccc;
497+
overflow-y: auto;
498+
overflow-x: hidden;
499+
flex-basis: 25%;
500+
transition: opacity 0.2s ease;
501+
text-overflow: ellipsis;
502+
white-space: nowrap;
503+
}
504+
#resource-tree-container .left-pane.collapsed {
505+
opacity: 0;
506+
pointer-events: none;
507+
}
508+
#resource-tree-container .resizer {
509+
width: 3px;
510+
background: var(--bulma-border);
511+
cursor: col-resize;
512+
position: relative;
513+
flex-shrink: 0;
514+
}
515+
#resource-tree-container .resizer:hover {
516+
background: var(--bulma-border-hover);
517+
}
518+
#resource-tree-container .resizer::before {
519+
content: '';
520+
position: absolute;
521+
top: 50%;
522+
left: 0px;
523+
transform: translateY(-50%);
524+
width: 2px;
525+
height: 30px;
526+
background: #999;
527+
border-radius: 2px;
528+
}
529+
#resource-tree-container .right-pane {
530+
flex: 1;
531+
min-width: 0;
532+
transition: opacity 0.2s ease;
533+
display: flex;
534+
flex-direction: column;
535+
height: 100%;
536+
}
537+
#resource-tree-container .right-pane .table-scroll-area {
538+
flex: 1;
539+
overflow-y: auto;
540+
overflow-x: hidden;
541+
}
542+
#resource-tree-container .right-pane.collapsed {
543+
opacity: 0;
544+
pointer-events: none;
545+
}
546+
#resource-tree-container .right-pane a:hover {
547+
text-decoration: underline;
548+
}
549+
#resource-tree-container .is-current, .is-current:hover {
550+
background-color: var(--bulma-background-hover) !important;
551+
border-radius: var(--bulma-radius);
552+
}
553+
#resource-tree-container .tree-node, .tree-node-file {
554+
padding: .25rem 0 .25rem 0;
555+
}
556+
#resource-tree-container .tree-node:hover, .tree-node-file:hover {
557+
background-color: var(--bulma-background);
558+
border-radius: var(--bulma-radius);
559+
}

scancodeio/static/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,14 @@ document.addEventListener('DOMContentLoaded', function () {
463463

464464
});
465465

466+
// HTMX
467+
468+
document.body.addEventListener("htmx:afterSwap", function(evt) {
469+
// Call the following functions after a HTMX swap is done.
470+
setupTabs();
471+
enableCopyToClipboard(".copy-to-clipboard");
472+
});
473+
466474
// Toasts (requires bulma-toast.js)
467475

468476
function displayPipelineStatusToast(run_status, pipeline_name, project_url) {

scanpipe/templates/scanpipe/base.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% load static %}
2+
{% load django_htmx %}
23
<!DOCTYPE html>
34
<html lang="en">
45
<head>
@@ -11,14 +12,14 @@
1112
<link rel="stylesheet" href="{% static 'main.css' %}" crossorigin="anonymous">
1213
{% block extrahead %}{% endblock %}
1314
</head>
14-
<body class="pb-5">
15+
<body class="pb-5" hx-headers='{"x-csrftoken": "{{ csrf_token }}"}'>
1516
{% block content %}{% endblock %}
1617
{% include 'scanpipe/modals/search_syntax_modal.html' %}
1718
<script src="{% static 'main.js' %}" crossorigin="anonymous"></script>
1819
<script src="{% static 'fontawesome-6.7.2/all.min.js' %}" crossorigin="anonymous" defer></script>
1920
<script src="{% static 'highlight-10.6.0.min.js' %}" crossorigin="anonymous"></script>
2021
<script src="{% static 'bulma-toast-2.4.1.min.js' %}" crossorigin="anonymous" defer></script>
21-
<script src="{% static 'htmx-2.0.4.min.js' %}" crossorigin="anonymous" defer></script>
22+
{% htmx_script %}
2223
{% block scripts %}{% endblock %}
2324
</body>
2425
</html>

scanpipe/templates/scanpipe/includes/run_status_tag.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{% if run.status == run.Status.RUNNING or run.status == run.Status.QUEUED %}
2-
<span class="tag is-info is-hoverable"
3-
hx-get="{% url 'run_status' run.uuid %}?current_status={{ run.status }}{% if display_current_step %}&display_current_step={{ display_current_step }}{% endif %}"
4-
hx-trigger="load delay:10s"
5-
hx-swap="outerHTML"
6-
>
2+
<span
3+
class="tag is-info is-hoverable"
4+
hx-get="{% url 'run_status' run.uuid %}?current_status={{ run.status }}{% if display_current_step %}&display_current_step={{ display_current_step }}{% endif %}"
5+
hx-trigger="load delay:10s"
6+
hx-swap="outerHTML">
77
{% if run.status == run.Status.RUNNING %}
88
<i class="fa-solid fa-spinner fa-pulse mr-1" aria-hidden="true"></i>Running
99
{% if display_current_step and run.current_step %}

scanpipe/templates/scanpipe/includes/run_step_selection_form.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
Removing steps may compromise data integrity. Use with caution.
55
</div>
66
{% include 'scanpipe/forms/form_errors.html' %}
7-
<form hx-post="{% url 'project_run_step_selection' run.uuid %}"
8-
hx-target="#run-step-selection-box"
9-
hx-swap="outerHTML"
10-
>{% csrf_token %}
7+
<form
8+
hx-post="{% url 'project_run_step_selection' run.uuid %}"
9+
hx-target="#run-step-selection-box"
10+
hx-swap="outerHTML">
1111
<div class="field">
1212
<label class="label">Select steps:</label>
1313
<div class="control">

scanpipe/templates/scanpipe/modals/add_labels_modal.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
<span class="tag is-info">
1717
<span class="has-text-weight-bold ml-1">{{ label.name }}</span>
1818
</span>
19-
<a class="tag is-delete"
20-
hx-post="{% url 'project_delete_label' project.slug label.name %}"
21-
hx-target="#label-{{ label.slug }}"
22-
hx-swap="delete"
23-
hx-on::after-request="this.parentElement.parentElement.remove()"
19+
<a
20+
class="tag is-delete"
21+
hx-post="{% url 'project_delete_label' project.slug label.name %}"
22+
hx-target="#label-{{ label.slug }}"
23+
hx-swap="delete"
24+
hx-on::after-request="this.parentElement.parentElement.remove()"
2425
>
2526
</a>
2627
</div>

0 commit comments

Comments
 (0)