Skip to content

Commit

Permalink
Split jinja files (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
berrydenhartog authored Jul 3, 2024
2 parents a239a2e + a74327a commit a857a7d
Show file tree
Hide file tree
Showing 19 changed files with 319 additions and 120 deletions.
2 changes: 1 addition & 1 deletion tad/api/routes/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ async def default_layout(
"tasks_service": tasks_service,
"statuses_service": status_service,
}
return templates.TemplateResponse(request=request, name="default_layout.jinja", context=context)
return templates.TemplateResponse(request=request, name="index.html.jinja", context=context)
4 changes: 2 additions & 2 deletions tad/api/routes/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ async def move_task(
moved_task.next_sibling_id,
)
# todo(Robbert) add error handling for input error or task error handling
return templates.TemplateResponse(request=request, name="task.jinja", context={"task": task})
return templates.TemplateResponse(request=request, name="task.html.jinja", context={"task": task})
except Exception:
return templates.TemplateResponse(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, request=request, name="error.jinja"
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, request=request, name="error.html.jinja"
)
14 changes: 7 additions & 7 deletions tad/locale/base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-06-24 10:53+0200\n"
"POT-Creation-Date: 2024-07-03 11:56+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -17,14 +17,14 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.15.0\n"

#: tad/site/templates/default_layout.jinja:19
msgid "Transparency of Algorithmic Decision making (TAD)"
msgstr ""

#: tad/site/templates/default_layout.jinja:49
#: tad/site/templates/default_header.html.jinja:6
msgid "Transparency of Algorithmic Decision making"
msgstr ""

#: tad/site/templates/default_layout.jinja:55
#: tad/site/templates/default_header.html.jinja:12
msgid "Language"
msgstr ""

#: tad/site/templates/layouts/base.html.jinja:10
msgid "Transparency of Algorithmic Decision making (TAD)"
msgstr ""
Binary file modified tad/locale/en_US/LC_MESSAGES/messages.mo
Binary file not shown.
25 changes: 17 additions & 8 deletions tad/locale/en_US/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-06-24 10:53+0200\n"
"PO-Revision-Date: 2024-06-24 09:48+0200\n"
"POT-Creation-Date: 2024-07-03 11:56+0200\n"
"PO-Revision-Date: 2024-07-02 11:20+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en_US\n"
"Language-Team: en_US <[email protected]>\n"
Expand All @@ -18,14 +18,23 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.15.0\n"

#: tad/site/templates/default_layout.jinja:19
msgid "Transparency of Algorithmic Decision making (TAD)"
msgstr ""

#: tad/site/templates/default_layout.jinja:49
#: tad/site/templates/default_header.html.jinja:6
msgid "Transparency of Algorithmic Decision making"
msgstr ""

#: tad/site/templates/default_layout.jinja:55
#: tad/site/templates/default_header.html.jinja:12
msgid "Language"
msgstr ""

#: tad/site/templates/layouts/base.html.jinja:10
msgid "Transparency of Algorithmic Decision making (TAD)"
msgstr ""

#~ msgid "Transparency of Algorithmic Decision making (TAD)"
#~ msgstr ""

#~ msgid "Transparency of Algorithmic Decision making"
#~ msgstr ""

#~ msgid "Language"
#~ msgstr ""
Binary file modified tad/locale/nl_FY/LC_MESSAGES/messages.mo
Binary file not shown.
29 changes: 19 additions & 10 deletions tad/locale/nl_FY/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-06-24 10:53+0200\n"
"PO-Revision-Date: 2024-06-24 09:48+0200\n"
"POT-Creation-Date: 2024-07-03 11:56+0200\n"
"PO-Revision-Date: 2024-07-02 11:05+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: nl_FY\n"
"Language-Team: nl_FY <[email protected]>\n"
Expand All @@ -18,14 +18,23 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.15.0\n"

#: tad/site/templates/default_layout.jinja:19
msgid "Transparency of Algorithmic Decision making (TAD)"
msgstr "Transparânsje fan algoritmyske beslútfoarming (TAD)"

#: tad/site/templates/default_layout.jinja:49
#: tad/site/templates/default_header.html.jinja:6
msgid "Transparency of Algorithmic Decision making"
msgstr "Transparânsje fan algoritmyske beslútfoarming"
msgstr ""

#: tad/site/templates/default_layout.jinja:55
#: tad/site/templates/default_header.html.jinja:12
msgid "Language"
msgstr "Taal"
msgstr ""

#: tad/site/templates/layouts/base.html.jinja:10
msgid "Transparency of Algorithmic Decision making (TAD)"
msgstr ""

#~ msgid "Transparency of Algorithmic Decision making (TAD)"
#~ msgstr "Transparânsje fan algoritmyske beslútfoarming (TAD)"

#~ msgid "Transparency of Algorithmic Decision making"
#~ msgstr "Transparânsje fan algoritmyske beslútfoarming"

#~ msgid "Language"
#~ msgstr "Taal"
Binary file modified tad/locale/nl_NL/LC_MESSAGES/messages.mo
Binary file not shown.
29 changes: 19 additions & 10 deletions tad/locale/nl_NL/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-06-24 10:53+0200\n"
"PO-Revision-Date: 2024-06-24 09:48+0200\n"
"POT-Creation-Date: 2024-07-03 11:56+0200\n"
"PO-Revision-Date: 2024-07-02 11:20+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: nl_NL\n"
"Language-Team: nl_NL <[email protected]>\n"
Expand All @@ -18,14 +18,23 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.15.0\n"

#: tad/site/templates/default_layout.jinja:19
msgid "Transparency of Algorithmic Decision making (TAD)"
msgstr "Transparantie voor Algoritmische Besluitvorming (TAD)"

#: tad/site/templates/default_layout.jinja:49
#: tad/site/templates/default_header.html.jinja:6
msgid "Transparency of Algorithmic Decision making"
msgstr "Transparantie voor Algoritmische Besluitvorming"
msgstr ""

#: tad/site/templates/default_layout.jinja:55
#: tad/site/templates/default_header.html.jinja:12
msgid "Language"
msgstr "Taal"
msgstr ""

#: tad/site/templates/layouts/base.html.jinja:10
msgid "Transparency of Algorithmic Decision making (TAD)"
msgstr ""

#~ msgid "Transparency of Algorithmic Decision making (TAD)"
#~ msgstr "Transparantie voor Algoritmische Besluitvorming (TAD)"

#~ msgid "Transparency of Algorithmic Decision making"
#~ msgstr "Transparantie voor Algoritmische Besluitvorming"

#~ msgid "Language"
#~ msgstr "Taal"
12 changes: 12 additions & 0 deletions tad/site/static/vendor/htmx/js/json-enc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
htmx.defineExtension('json-enc', {
onEvent: function (name, evt) {
if (name === "htmx:configRequest") {
evt.detail.headers['Content-Type'] = "application/json";
}
},

encodeParameters : function(xhr, parameters, elt) {
xhr.overrideMimeType('text/json');
return (JSON.stringify(parameters));
}
});
130 changes: 130 additions & 0 deletions tad/site/static/vendor/htmx/js/response-targets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
(function(){

/** @type {import("../htmx").HtmxInternalApi} */
var api;

var attrPrefix = 'hx-target-';

// IE11 doesn't support string.startsWith
function startsWith(str, prefix) {
return str.substring(0, prefix.length) === prefix
}

/**
* @param {HTMLElement} elt
* @param {number} respCode
* @returns {HTMLElement | null}
*/
function getRespCodeTarget(elt, respCodeNumber) {
if (!elt || !respCodeNumber) return null;

var respCode = respCodeNumber.toString();

// '*' is the original syntax, as the obvious character for a wildcard.
// The 'x' alternative was added for maximum compatibility with HTML
// templating engines, due to ambiguity around which characters are
// supported in HTML attributes.
//
// Start with the most specific possible attribute and generalize from
// there.
var attrPossibilities = [
respCode,

respCode.substr(0, 2) + '*',
respCode.substr(0, 2) + 'x',

respCode.substr(0, 1) + '*',
respCode.substr(0, 1) + 'x',
respCode.substr(0, 1) + '**',
respCode.substr(0, 1) + 'xx',

'*',
'x',
'***',
'xxx',
];
if (startsWith(respCode, '4') || startsWith(respCode, '5')) {
attrPossibilities.push('error');
}

for (var i = 0; i < attrPossibilities.length; i++) {
var attr = attrPrefix + attrPossibilities[i];
var attrValue = api.getClosestAttributeValue(elt, attr);
if (attrValue) {
if (attrValue === "this") {
return api.findThisElement(elt, attr);
} else {
return api.querySelectorExt(elt, attrValue);
}
}
}

return null;
}

/** @param {Event} evt */
function handleErrorFlag(evt) {
if (evt.detail.isError) {
if (htmx.config.responseTargetUnsetsError) {
evt.detail.isError = false;
}
} else if (htmx.config.responseTargetSetsError) {
evt.detail.isError = true;
}
}

htmx.defineExtension('response-targets', {

/** @param {import("../htmx").HtmxInternalApi} apiRef */
init: function (apiRef) {
api = apiRef;

if (htmx.config.responseTargetUnsetsError === undefined) {
htmx.config.responseTargetUnsetsError = true;
}
if (htmx.config.responseTargetSetsError === undefined) {
htmx.config.responseTargetSetsError = false;
}
if (htmx.config.responseTargetPrefersExisting === undefined) {
htmx.config.responseTargetPrefersExisting = false;
}
if (htmx.config.responseTargetPrefersRetargetHeader === undefined) {
htmx.config.responseTargetPrefersRetargetHeader = true;
}
},

/**
* @param {string} name
* @param {Event} evt
*/
onEvent: function (name, evt) {
if (name === "htmx:beforeSwap" &&
evt.detail.xhr &&
evt.detail.xhr.status !== 200) {
if (evt.detail.target) {
if (htmx.config.responseTargetPrefersExisting) {
evt.detail.shouldSwap = true;
handleErrorFlag(evt);
return true;
}
if (htmx.config.responseTargetPrefersRetargetHeader &&
evt.detail.xhr.getAllResponseHeaders().match(/HX-Retarget:/i)) {
evt.detail.shouldSwap = true;
handleErrorFlag(evt);
return true;
}
}
if (!evt.detail.requestConfig) {
return true;
}
var target = getRespCodeTarget(evt.detail.requestConfig.elt, evt.detail.xhr.status);
if (target) {
handleErrorFlag(evt);
evt.detail.shouldSwap = true;
evt.detail.target = target;
}
return true;
}
}
});
})();
19 changes: 19 additions & 0 deletions tad/site/templates/default_header.html.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<header class="header">
<div class="container">
<div class="header_logo_container">
<img class="header_logo_image" src="/static/images/logo.svg"/>
<div class="header_subtitle_container">
<span>{% trans %}Transparency of Algorithmic Decision making{% endtrans %} ({{ version }})</span>
</div>
</div>
</div>
<nav class="header_nav">
<div style="color: white; float: right; margin-right: 50px; width: 10em; height: 100%; display: flex; align-items: center">
{% trans %}Language{% endtrans %}:&nbsp;
{% for available_translation in available_translations %}
<a {% if available_translation == language %}class="selected"{% endif %} id="langselect-{{ available_translation }}" style="color: white; text-decoration: none" href="javascript:setCookie('lang','{{ available_translation }}',9999); window.location.reload()">{{ available_translation }}</a>&nbsp;
{% endfor %}
</div>

</nav>
</header>
Loading

0 comments on commit a857a7d

Please sign in to comment.