Skip to content

Commit

Permalink
Merge branch 'main' into code-cleanup-db
Browse files Browse the repository at this point in the history
  • Loading branch information
TreyWW authored Apr 28, 2024
2 parents 25eb5ed + fabbae2 commit 0128465
Show file tree
Hide file tree
Showing 21 changed files with 256 additions and 140 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ jobs:
echo "output.css is not created"
exit 1
fi
if [ -f frontend/static/js/bundle.js ] && [ -f frontend/static/js/bundle.js.map ]; then
echo "bundle.js and bundle.js.map are created"
if [ -d frontend/static/js/c/ ]; then
echo "webpack has been built"
else
echo "bundle.js and/or bundle.js.map are not created"
echo "frontend/static/js/c/ was not created from webpack build"
exit 1
fi
if [ -f webpack-stats.json ]; then
echo "webpack has built webpack-stats to work with chunks"
else
echo "webpack-stats was not built so cannot work with chunks"
exit 1
fi
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ Writerside/**
frontend/static/src/output.css
frontend/static/js/bundle.js
frontend/static/js/bundle.js.map
frontend/static/js/c/*

# Webpack
webpack-stats.json

# Pulumi
infrastructure/aws/pulumi/Pulumi.dev.yaml
Expand Down
4 changes: 4 additions & 0 deletions assets/scripts/font_awesome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import '@fortawesome/fontawesome-free/js/fontawesome'
import '@fortawesome/fontawesome-free/js/solid'
import '@fortawesome/fontawesome-free/js/regular'
import '@fortawesome/fontawesome-free/js/brands'
49 changes: 49 additions & 0 deletions assets/scripts/htmx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'htmx.org';
import 'hyperscript.org';

window.htmx = require('htmx.org');
window._hyperscript = require('hyperscript.org');
window._hyperscript.browserInit();

function htmx_resend(event) {
let eventType;
if (event.detail.requestConfig.triggeringEvent) {
eventType = event.detail.requestConfig.triggeringEvent.type
} else {
eventType = "retry"
}

let timeout;

if (event.detail.error.includes("429")) {
timeout = 4000;
} else {
timeout = 2000;
}

setTimeout(function () {
console.log("Sending HTMX retry event")
htmx.trigger(event.detail.elt, eventType);
}, timeout);
}

// https://htmx.org/docs/#config
htmx.config.globalViewTransitions = true
htmx.config.useTemplateFragments = true // for swapping of table items


window.addEventListener("DOMContentLoaded", (event) => {
document.body.addEventListener("htmx:sendError", htmx_resend);
document.body.addEventListener("htmx:responseError", htmx_resend);
document.body.addEventListener("htmx:loadError", htmx_resend);
document.body.addEventListener("htmx:afterRequest", () => {
const drawer = document.getElementById("service_list_drawer");

if (drawer) {
drawer.checked = false;
}
});
document.body.addEventListener('htmx:configRequest', (event) => {
event.detail.headers['X-CSRFToken'] = '{{ csrf_token }}';
})
});
28 changes: 23 additions & 5 deletions assets/scripts/init.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import 'htmx.org';
import 'hyperscript.org';

import '@fortawesome/fontawesome-free/js/fontawesome'
import '@fortawesome/fontawesome-free/js/solid'
import '@fortawesome/fontawesome-free/js/regular'
import '@fortawesome/fontawesome-free/js/brands'
import Alpine from 'alpinejs'
import $ from 'jquery'

Expand All @@ -15,4 +11,26 @@ window._hyperscript.browserInit();
window.Alpine = Alpine

window.jQuery = $;
window.$ = $;
window.$ = $;

document.addEventListener("DOMContentLoaded", function () {
const drawer = document.getElementById("service_list_drawer");
var togglers = document.querySelectorAll("#service_list_togglers");

drawer.addEventListener("change", function () {
if (drawer.checked) {
document.getElementById("service_list_toggler").checked = true;
for (let i = 0; i < togglers.length; i++) {
togglers[i].checked = true
}
document.getElementById("logo_single_service_list_toggler").checked = true;
} else {
document.getElementById("service_list_toggler").checked = false;
for (let i = 0; i < togglers.length; i++) {
togglers[i].checked = false
}
document.getElementById("logo_single_service_list_toggler").checked = false;
}
;
});
});
29 changes: 29 additions & 0 deletions assets/scripts/receipt_downloads.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Downloads a file from the specified URL.
*
* @param {string} downloadUrl - The URL of the file to be downloaded.
*/

/*#__NO_RENAME__*/
window.download_file = function Download_file(downloadUrl) {
var xhr = new XMLHttpRequest();
xhr.open('GET', downloadUrl, true);
xhr.onload = function () {
if (this.status === 200) {
var response = JSON.parse(this.responseText);

// Use the download_link and filename from the JSON response
var downloadLink = response.download_link;
var filename = response.filename;

// Trigger the download using a link element
var a = document.createElement('a');
a.href = downloadLink;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
};
xhr.send();
}
16 changes: 0 additions & 16 deletions frontend/static/js/bundle.js.LICENSE.txt

This file was deleted.

27 changes: 0 additions & 27 deletions frontend/static/js/receipt_download.js

This file was deleted.

21 changes: 11 additions & 10 deletions frontend/templates/base/_head.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{% load static %}
{% load render_bundle from webpack_loader %}
{% load tz_detect %}
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Expand Down Expand Up @@ -29,7 +31,7 @@
<!-- AlpineJS -->
<script defer
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script>
{# <script src="{% static 'js/init-alpine.js' %}"></script>#}
{# <script src="{% static 'js/c/init-alpine.js' %}"></script>#}
<!-- SimpleMDE -->
{# <script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>#}
{#
Expand All @@ -46,18 +48,17 @@
<script src="https://unpkg.com/htmx.org/dist/ext/response-targets.js"></script>
<script src="https://unpkg.com/[email protected]"></script>
{% else %}
<script src="{% static "js/bundle.js" %}"></script>
{# <script defer type="text/javascript" src="{% static "js/c/init.js" %}"></script>#}
{# <script defer type="text/javascript" src="{% static "js/c/htmx.js" %}"></script>#}
{# <script defer type="text/javascript" src="{% static "js/c/font_awesome.js" %}"></script>#}
{# {% render_bundle 'all' 'js' %}#}
{% render_bundle 'init' 'js' %}
{% render_bundle 'htmx' 'js' %}
{% render_bundle 'font_awesome' 'js' %}
<!-- Tailwind & DaisyUI -->
<link rel="stylesheet" href="{% static 'src/output.css' %}">
{% endif %}
<script src="{% static 'js/receipt_download.js' %}"></script>
<script>
// https://htmx.org/docs/#config
htmx.config.globalViewTransitions = true
htmx.config.useTemplateFragments = true // for swapping of table items
Alpine.start()
</script>
{% render_bundle 'receipt_downloads' 'js' %}
{{ analytics|safe }}
{% load tz_detect %}
{% tz_detect %}
</head>
5 changes: 0 additions & 5 deletions frontend/templates/base/auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,5 @@ <h2 class="text-2xl font-semibold mb-2 text-center">
</div>
</div>
</div>
<script>
document.body.addEventListener('htmx:configRequest', (event) => {
event.detail.headers['X-CSRFToken'] = '{{ csrf_token }}';
})
</script>
</body>
</html>
50 changes: 0 additions & 50 deletions frontend/templates/base/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,56 +33,6 @@
</ul>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", function () {
const drawer = document.getElementById("service_list_drawer");
var togglers = document.querySelectorAll("#service_list_togglers");

drawer.addEventListener("change", function () {
if (drawer.checked) {
document.getElementById("service_list_toggler").checked = true;
for (let i = 0; i < togglers.length; i++) {
togglers[i].checked = true
}
document.getElementById("logo_single_service_list_toggler").checked = true;
} else {
document.getElementById("service_list_toggler").checked = false;
for (let i = 0; i < togglers.length; i++) {
togglers[i].checked = false
}
document.getElementById("logo_single_service_list_toggler").checked = false;
}
;
});
});
</script>
<script>
function htmx_resend(event) {
let eventType;
if (event.detail.requestConfig.triggeringEvent) {
eventType = event.detail.requestConfig.triggeringEvent.type
} else {
eventType = "retry"
}

let timeout;

if (event.detail.error.startsWith("Response Status Error Code 429")) {
timeout = 4000;
} else {
timeout = 2000;
}

setTimeout(function () {
console.log("Sending HTMX retry event")
htmx.trigger(event.detail.elt, eventType);
}, timeout);
}

document.body.addEventListener("htmx:sendError", htmx_resend);
document.body.addEventListener("htmx:responseError", htmx_resend);
document.body.addEventListener("htmx:loadError", htmx_resend);
</script>
<input type="checkbox" id="logout_modal" class="modal-toggle" />
<div class="modal modal-responsive">
<div class="modal-box">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<button onclick="modal_invoices_from_destination.showModal();"
id="from_destination"
class="input_card text-left"
hx-trigger="click once"
hx-trigger="click"
hx-swap="beforeend"
hx-target="#modal_container"
hx-get="{% url 'api:base:modal retrieve with context' modal_name='invoices_from_destination' context_type='edit_invoice_from' context_value=invoice_object.id %}">
Expand Down
9 changes: 2 additions & 7 deletions frontend/templates/pages/receipts/_search_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h2 class="menu-title">Amount</h2>
</button>
<button type="button"
class="btn btn-outline btn-primary btn-sm"
onclick="Download_file('{% url 'api:receipts:generate_download_link' receipt_id=row.id %}')">
onclick="download_file('{% url 'api:receipts:generate_download_link' receipt_id=row.id %}')">
Download
</button>
<button class="btn btn-outline btn-error btn-sm"
Expand Down Expand Up @@ -110,7 +110,7 @@ <h2 class="text-xl">
<div class="flex gap-3">
<button type="button"
class="btn btn-primary"
onclick="Download_file('{% url 'api:receipts:generate_download_link' receipt_id=row.id %}')">
onclick="download_file('{% url 'api:receipts:generate_download_link' receipt_id=row.id %}')">
Download
</button>
<button class="btn" onclick="modal_receipt_{{ row.id }}.close();">Cancel</button>
Expand Down Expand Up @@ -145,9 +145,4 @@ <h2 class="text-xl">
name="amount_100+"
value="{% if '100' in selected_filters %}true{% endif %}">
</div>
<script>
document.body.addEventListener('htmx:configRequest', (event) => {
event.detail.headers['X-CSRFToken'] = '{{ csrf_token }}';
})
</script>
{% component "messages_list" %}
3 changes: 2 additions & 1 deletion infrastructure/backend/scripts/tests/views.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/sh

python3 manage.py test --parallel
python3 manage.py collectstatic --no-input
python3 manage.py test --parallel
Loading

0 comments on commit 0128465

Please sign in to comment.