2023-01-13 19:43:42 +00:00
|
|
|
<!doctype html>
|
2023-01-31 14:45:51 +00:00
|
|
|
<html lang="{{ currentLocale }}">
|
2023-01-13 19:43:42 +00:00
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
2023-01-31 12:07:17 +00:00
|
|
|
<title>{{ template "title" . }} — Numerus</title>
|
2023-01-17 21:28:47 +00:00
|
|
|
<link rel="stylesheet" type="text/css" media="screen" href="/static/numerus.css">
|
2023-04-29 14:20:13 +00:00
|
|
|
<script src="/static/htmx@1.9.2.min.js"></script>
|
Add custom elements polyfill
I use customized built-in components, extended from any HTML elements
(e.g., HTMLDivElement), for product search, multiselect, and tags input
fields. The idea is that people that without JavaScript could still use
the regular, non-customized, inputs.
It turns out, this does not work so well: the CSS assumes that
JavaScript is enabled, and web components supported by the browser. If
one of these fails, then the controls are unusable—the multiselect is
too short, and the tags field accepts invalid characters that the
backend does not validate until it fails with a database error.
We discovered this because Apple does not implement customized built-in
components[0], hence it does not use my JavaScript code and forms,
the expenses forms in particular, are almost useless.
The way to fix this is to replace the regular inputs with autonomous
web components, extended from HTMLElement, using JavaScript, because
it would only do so with JavaScript enabled, and the CSS style would
only apply to these components, not the regular input fields.
However, currently i do not have time to do the proper fix, and have
to use a polyfill for Safari to support customized built-in components.
Shame.
[0]: https://lists.w3.org/Archives/Public/public-webapps/2013OctDec/0801.html
2023-11-11 02:32:03 +00:00
|
|
|
<script type="module" src="/static/custom-elements@1.3.0.min.js"></script>
|
Reimplement the multiselect as a custom element
What i really set off on was to refactor the multiselect’s x-data
context to a separate JavaScript file.
I did not see the need at first, thinking that it would not matter
because it was used only in a template and i was not duplicating the
code in my files. However, i then realized that having the context
in the template means the visitor has to download it each and every time
it accesses a form with a multiselect, even if nothing changed, and,
worse, it would download it multiple times if there were many
multiselect controls.
It makes more sense to put all that into a file that the browser would
only download and parse once, if the proper caching is set.
Once i realized that, it was a shame that AlpineJS has no way to do
the same for the HTML structure[0], for the exact same reasons: not
wanting to download many times the same extra <template> and other
markup required to build the control for JavaScript users. And then i
remembered that this is supposed to be custom element’s main selling
point.
At first i tried to create a shadow DOW to replace the <select> with
the same <div> and <ul> that i used with Alpine, but it turns out that
<select> is not one of the allowed elements that can have a shadow root
attached[0].
Therefore, i changed the custom element to extend the <div> for the
<select> and <label> instead—the same element that had the x-init
context—, but i would have to define or include all the styles inside
the shadow DOM, and bring the lang attribute, for it to look like it
did before. Out with the shadow DOM, and modify the <div>’s contents
instead.
At this point the code was so far removed from the declarative way that
AlpineJS promotes that i did not see much value on using it, except for
its reactivity. But, given that this is such a small component, at the
end decided to write it all in plain JavaScript.
It is more code, at least looking only at the code i had to write, but
i love how i only have to add an is="numerus-multiselect" attribute to
HTML for it to work.
[0]: https://github.com/alpinejs/alpine/discussions/1205
[1]: https://developer.mozilla.org/en-US/docs/Web/API/Element/attachShadow
2023-03-17 13:55:12 +00:00
|
|
|
<script type="module" src="/static/numerus.js"></script>
|
2023-03-25 00:56:26 +00:00
|
|
|
<script defer src="/static/alpinejs@3.12.0.min.js"></script>
|
2023-01-13 19:43:42 +00:00
|
|
|
</head>
|
2023-07-14 08:25:39 +00:00
|
|
|
<body class="filters-visible">
|
2023-01-17 21:28:47 +00:00
|
|
|
<header>
|
|
|
|
<h1><img src="/static/numerus.svg" alt="Numerus" width="261" height="33"></h1>
|
2023-03-07 10:52:09 +00:00
|
|
|
<details id="profile-menu" class="menu">
|
2023-07-06 09:49:36 +00:00
|
|
|
<summary aria-label="{{( gettext "Profile menu" )}}">
|
2023-07-02 17:49:03 +00:00
|
|
|
<i class="ri-user-6-line ri-3x"></i>
|
2023-01-23 17:52:18 +00:00
|
|
|
</summary>
|
2023-03-20 12:09:52 +00:00
|
|
|
<ul role="menu" class="action-menu" data-hx-push-url="false" data-hx-swap="beforeend">
|
2023-01-22 21:30:15 +00:00
|
|
|
<li role="presentation">
|
2023-03-20 12:09:52 +00:00
|
|
|
<a role="menuitem" href="{{ companyURI "/profile" }}" data-hx-boost="true">
|
2023-07-02 17:49:03 +00:00
|
|
|
<i class="ri-user-6-line"></i>
|
Add the company relation and read-only form to edit
I do not have more time to update the update to the company today, but i
believe this is already a good amount of work for a commit.
The company is going to be used for row level security, as users will
only have access to the data from companies they are granted access, by
virtue of being in the company_user relation.
I did not know how add a row level security policy to the company_user
because i needed the to select on the same relation and this is not
allowed, because it would create an infinite loop.
Had to add the vat, pg_libphonenumber, and uri extensions in order to
validate VAT identification numbers, phone numbers, and URIs,
repectively. These libraries are not in Debian, but i created packages
for them all in https://dev.tandem.ws/tandem.
2023-01-24 20:46:07 +00:00
|
|
|
{{( pgettext "Account" "menu" )}}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li role="presentation">
|
2023-03-21 10:58:54 +00:00
|
|
|
<a role="menuitem" href="{{ companyURI "/tax-details" }}" data-hx-boost="true">
|
Add the company relation and read-only form to edit
I do not have more time to update the update to the company today, but i
believe this is already a good amount of work for a commit.
The company is going to be used for row level security, as users will
only have access to the data from companies they are granted access, by
virtue of being in the company_user relation.
I did not know how add a row level security policy to the company_user
because i needed the to select on the same relation and this is not
allowed, because it would create an infinite loop.
Had to add the vat, pg_libphonenumber, and uri extensions in order to
validate VAT identification numbers, phone numbers, and URIs,
repectively. These libraries are not in Debian, but i created packages
for them all in https://dev.tandem.ws/tandem.
2023-01-24 20:46:07 +00:00
|
|
|
<i class="ri-vip-diamond-line"></i>
|
|
|
|
{{( pgettext "Tax Details" "menu" )}}
|
2023-01-23 17:52:18 +00:00
|
|
|
</a>
|
2023-01-22 21:30:15 +00:00
|
|
|
</li>
|
2023-11-06 12:52:34 +00:00
|
|
|
<li role="presentation">
|
|
|
|
<a role="menuitem" href="{{ companyURI "/switch-company" }}" data-hx-boost="true">
|
|
|
|
<i class="ri-briefcase-line"></i>
|
|
|
|
{{( pgettext "Switch Company" "menu" )}}
|
|
|
|
</a>
|
|
|
|
</li>
|
2023-01-22 21:30:15 +00:00
|
|
|
<li role="presentation">
|
2023-01-23 17:52:18 +00:00
|
|
|
<form method="POST" action="/logout">
|
2023-02-02 10:39:34 +00:00
|
|
|
{{ csrfToken }}
|
2023-01-23 17:52:18 +00:00
|
|
|
<button type="submit" role="menuitem">
|
|
|
|
<i class="ri-logout-circle-line"></i>
|
|
|
|
{{( pgettext "Logout" "action" )}}
|
|
|
|
</button>
|
|
|
|
</form>
|
2023-01-22 21:30:15 +00:00
|
|
|
</li>
|
2023-01-17 21:28:47 +00:00
|
|
|
</ul>
|
2023-01-23 17:52:18 +00:00
|
|
|
</details>
|
2023-01-17 21:28:47 +00:00
|
|
|
</header>
|
2023-03-23 09:55:02 +00:00
|
|
|
<nav aria-label="{{( pgettext "Main" "title" )}}" data-hx-target="main" data-hx-boost="true">
|
2023-01-29 14:14:31 +00:00
|
|
|
<ul>
|
Add aria-current attribute to links in the top menu
This is mainly to be able to stylize them using CSS; the current style
i set i just a placeholder to check that it works as expected.
Most of these links needs to check for the URI’s prefix, because they
are links to a whole section, but the first link must check for the
exact match, otherwise it would match every other URI, as all of them
start with /company/{uuid}.
The server does not return the markup for the top navigation when usin
HTMx, though, hence i have to change the current class using JavaScript.
I am not sure if the correct value for aria-current is “page” when the
link is not for the actual page the user is currently in, like when is
in the new quote page, but it seems to be the most appropriate value
from the enumeration given in the specifications, except, perhaps, for
the “location” value, but i was unable to find any example of that value
anywhere.
Part of #89.
2023-11-13 13:42:27 +00:00
|
|
|
<li><a{{if requestURIMatches (companyURI "/") }} aria-current="page"{{ end }} href="{{ companyURI "/" }}">{{( pgettext "Dashboard" "nav" )}}</a></li>
|
|
|
|
<li><a{{if requestURIHasPrefix (companyURI "/quotes") }} aria-current="page"{{ end }} href="{{ companyURI "/quotes" }}">{{( pgettext "Quotations" "nav" )}}</a></li>
|
|
|
|
<li><a{{if requestURIHasPrefix (companyURI "/invoices") }} aria-current="page"{{ end }} href="{{ companyURI "/invoices" }}">{{( pgettext "Invoices" "nav" )}}</a></li>
|
|
|
|
<li><a{{if requestURIHasPrefix (companyURI "/expenses") }} aria-current="page"{{ end }} href="{{ companyURI "/expenses" }}">{{( pgettext "Expenses" "nav" )}}</a></li>
|
|
|
|
<li><a{{if requestURIHasPrefix (companyURI "/products") }} aria-current="page"{{ end }} href="{{ companyURI "/products" }}">{{( pgettext "Products" "nav" )}}</a></li>
|
|
|
|
<li><a{{if requestURIHasPrefix (companyURI "/contacts") }} aria-current="page"{{ end }} href="{{ companyURI "/contacts" }}">{{( pgettext "Contacts" "nav" )}}</a></li>
|
2023-01-29 14:14:31 +00:00
|
|
|
</ul>
|
|
|
|
</nav>
|
2023-01-17 21:28:47 +00:00
|
|
|
<main>
|
2023-03-20 12:09:52 +00:00
|
|
|
{{- template "breadcrumbs" . }}
|
2023-01-22 20:41:50 +00:00
|
|
|
{{- template "content" . }}
|
2023-01-17 21:28:47 +00:00
|
|
|
</main>
|
2023-01-13 19:43:42 +00:00
|
|
|
</body>
|
2023-03-25 00:56:26 +00:00
|
|
|
<div x-data="snackbar">
|
|
|
|
<div x-show="show"
|
|
|
|
@click="dismiss"
|
|
|
|
x-cloak
|
|
|
|
x-transition:enter="enter"
|
|
|
|
x-transition:enter-start="start"
|
|
|
|
x-transition:enter-end="end"
|
|
|
|
x-transition:leave="leave"
|
|
|
|
x-transition:leave-start="start"
|
|
|
|
x-transition:leave-end="end"
|
|
|
|
role="alert">
|
|
|
|
<p x-text="toast"></p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-01-13 19:43:42 +00:00
|
|
|
</html>
|