Commit Graph

67 Commits

Author SHA1 Message Date
jordi fita mas a0f9c10193 Add management of surroundings’ highlights (points of interest)
Customer does not want the new “masonry-like” design of the surroundings
page, and wants the same style they already had: a regular list with
text and photo, alternating the photo’s side.

And, of course, they want to be able to add and edit them themselves. It
is like another carousel, but with an additional rich-text description.

The photos that we had in that page are no longer of use.
2024-01-16 01:26:35 +01:00
jordi fita mas 0ed6c1b121 Added note about dogs to the campsite type page
The pets icon is just the same as the notpet but without the diagonal
bar.

The price is hardcoded in the query for now, as there is no field
in the campsite type.
2024-01-15 02:07:32 +01:00
jordi fita mas 0beb0bb315 Add VAT and tourist tax information
Since i need the number of decimals to format the price in the template,
i added them to the company, and used them in the call to price_parse().
2024-01-15 01:45:58 +01:00
jordi fita mas 76456aa9b2 Add check-in and check-out time information to campsite type’s page 2024-01-15 01:02:50 +01:00
jordi fita mas dabd197f02 Add additional information field to campsite types
This is actually just to have a fourth column in order to “balance”
lists for types that have a long descriptions.
2024-01-15 00:28:34 +01:00
jordi fita mas 79df1736f2 Add tourist tax to company
Not used anywhere yet, but i will need it when computing the booking’s
total.
2024-01-14 02:09:17 +01:00
jordi fita mas 976b2bcbcf Add position to services to be able to manually sort by admins 2024-01-13 01:15:24 +01:00
jordi fita mas b6cd2f7693 Use I18nInput instead of L10nInput to translate carousels 2024-01-12 19:33:44 +01:00
jordi fita mas f28664acce Replace use of L10NInput with I18nInput for campsite 2024-01-10 21:52:49 +01:00
jordi fita mas 3f46ea3a9a Add “Menu” next to the trigram symbol (“hamburger”) 2024-01-10 19:41:57 +01:00
jordi fita mas cdf32a0234 Updated translations 2023-12-22 03:32:40 +01:00
jordi fita mas 03c20fec88 Add management of legal texts 2023-12-22 02:23:18 +01:00
jordi fita mas ff6e9497b5 Replace contact page with location
Customer does not want a contact page, but a page where they can write
the direction on how to reach the campground, with a Google map embed
instead of using Leaflet, because Google Maps shows the reviews right
in the map.

That means i had to replace the GPS locations with XML fields for the
customer to write.  In all four languages.

This time i tried a translation approach inspired by PrestaShop: instead
of opening a new page for each language, i have all languages in the
same page and use AlpineJS to show just a single language.  It is far
easier to write the translations, even though you do not have the source
text visible, specially in this section that there is no place for me
to put the language links.
2023-12-21 21:17:04 +01:00
jordi fita mas c9a6df658f Add position to campsite type features 2023-12-21 17:33:01 +01:00
jordi fita mas 678b5cc523 Add user-defined order to campsite types, options, seasons and carousels
I use Sortable, exactly like HTMx’s sorting example does[0].  Had to
export the slug or ID of some entries to be able to add it in the hidden
input.

For forms that use ID instead of slug, had to use an input name other
than “id” because otherwise the swap would fail due to bug #1496[1].  It
is apparently fixed in a recent version of HTMx, but i did not want to
update for fear of behaviour changes.

[0]: https://htmx.org/examples/sortable/
[1]: https://github.com/bigskysoftware/htmx/issues/1496
2023-12-20 19:52:14 +01:00
jordi fita mas 66a7ae3d27 Fix typo in Accommodation, and fix its translations 2023-12-13 23:45:36 +01:00
jordi fita mas cfd5d5675c Remove “Party Details” from booking form, and stylize it a bit 2023-12-12 23:16:04 +01:00
jordi fita mas 0cbf973cbb Add the payment form to admin
Had to change setup_redsys because admins can not read the current
encrypt key, thus it is not possible to `set encrypt_key =
coalesce(…, encrypt_key)`.

Not that it did much sense, anyway, as i was already inside the branch
of the if when encrpty_key is null.

However, it seems that this also affects in the `on conflict` update. I
assume this is because `excluded` is some kind of row of the relation
and has the same restrictions.
2023-10-27 16:08:13 +02:00
jordi fita mas 62b54961f4 Implement Redsys request signature in PostgreSQL
Every company need to have its own merchant code and encryption key,
thus it is not possible to use environment variables to keep that data,
and i have to store it in the database.

I do not want to give SELECT permission on the encryption key to guest,
because i am going to fuck it up sooner or later, and everyone would be
able to read that secret; i know it would.  Therefore, i need a security
definer function that takes the data to encrypt, use the key to encrypt
it, and returns the result; nobody else should have access to that key,
not even admins!

By the way, i found out that every merchant receives the same key, thus
it is not a problem to keep it in the repository.

Since i need that SQL function to encrypt the data, i thought that i may
go the whole nine yards and sign the request in PostgreSQL too, after
all the data to sign comes from there, and it has JSON functions to
create and base64-code an object.

Fortunately, pg_crypto has all the functions that i need, but i can no
longer keep that extension inside the auth schema, because it is used
from others, and the public schema, like every other extensions, seems
more appropriate.

Instead of having the list of currency and language codes that Redsys
uses as constants in the code, i moved that as field to the currency
and language relations, so i can simply pass the lang_tag to the
function and it can transform that tag to the correct code; the currency
is from the company’s relation, since it is the only currency used in
the whole application (for now).

As a consequence, i had to grant execute to currency and the parse_price
functions to guest, too.

To generate the test data used in the unit tests, i used a third-party
PHP implementation[0], but i only got from that the resulting base64-coded
JSON object and signature, using the same that as in the unit test, and
did not use any code from there.

PostgreSQL formats the JSON as text differently than most
implementations i have seen: it adds spaces between the key name and
the colons, and space between the value and the separating comma.  The
first implementation used replace() to format the JSON as exactly as
the PHP implementation, so that the result matches, and then tried to do
generate the form by hand using the output from PostgreSQL without the
replace(), to verify that Redsys would still accept my input.  Finally,
i adjusted the unit test to whatever pg_prove said it was getting from
the function.

I still have the form’s action hard-codded to the test environment, but
the idea is that administrators should be able to switch from test to
live themselves.  That means that i need that info in the redsys
relation as well.  I think this is one of the few use cases for SQL’s
types, because it is unlikely to change anytime soon, and i do not need
the actual labels.

Unfortunately, i could not use enumerations for the request’s
transaction type because i can not attach an arbitrary number to the
enum’s values.  Having a relation is overkill, because i would need
a constant in Go to refer to its primary key anyway, thus i kept the
same constant i had before for that.  Language and currency constant
went out, as this is in the corresponding relations.

In setup_redsys i must have a separate update if the encrypt_key is null
because PostgreSQL checks constraints before key conflict, and i do
not want to give a default value to the key if the row is not there yet.
The problem is that i want to use null to mean “keep the same password”,
because it is what i intend to do with the user-facing form: leave the
input empty to keep the same password.

As now Go needs to pass composite types back and forth with PostgreSQL,
i need to register these types, and i have to do it every time because
the only moment i have access to the non-pooled connection is in the
AfterConnect function, but at that point i have no idea whether the
user is going to request a payment.  I do not know how much the
performance degrades because of this.

[0]: https://github.com/ssheduardo/sermepa/blob/master/src/Sermepa/Tpv/Tpv.php
2023-10-27 01:52:04 +02:00
jordi fita mas 302ce29e4a Add the first draft of the booking and payment forms
The form is based on the one in the current website, but in a single
page instead of split into many pages; possibly each <fieldset> should
be in a separate page/view.  The idea is for Oriol to check the design
and decide how it would be presented to the user, so i needed something
to show him first.

I hardcoded the **test** data for the customer’s Redsys account.  Is
this bad? I hope not, but i am not really, really sure.

The data sent to Redsys is just a placeholder because there are booking
details that i do not know, like what i have to do with the “teenagers”
field or the area preferences, thus i can not yet have a booking
relation.  Nevertheless, had to generate a random order number up to
12-chars in length or Redsys would refuse the payment, claiming that
the order is duplicated.

The Redsys package is based on the PHP code provided by Redsys
themselves, plus some hints at the implementations from various Go
packages that did not know why they were so complicated.

Had to grant select on table country to guest in order to show the
select with the country options.

I have changed the “Postal code” input in taxDetails for “Postcode”
because this is the spell that it is used in the current web, i did not
see a reason to change it—it is an accepted form—, and i did not want to
have inconsistencies between forms.
2023-10-19 21:37:34 +02:00
jordi fita mas 27af39b296 Add the Catalonia’s Tourism Registry number to company
It is required to be displayed on the website of tourism companies of
Catalonia.
2023-10-14 21:59:36 +02:00
jordi fita mas 9b240cf8c2 Add the booking form to type, and style page according to design 2023-10-13 21:59:45 +02:00
jordi fita mas d1b43e5062 Show “Starting from” price with campsite types that have options
In the old website, the prices where show with all the options, but in
the new design only a single price is show, that in the case of
campsites with options is the price per night of the “base” plus the
minimum options selected.
2023-10-13 20:44:24 +02:00
jordi fita mas 2e10966ad7 Add the list of features for campsite type 2023-10-13 20:30:31 +02:00
jordi fita mas 7fc87b5cb5 Add the info and facilities fields to campsite type
I wish CKEditor would have support for <dl>, but it is unlikely that
they will add any time soon[0], specially when in 2018 they already
“forgotten”[1] that this was requested back in 2007[2].

Therefore, in the demo i did it more or less like in the original
design, with “extra” <h4>, although i added them under a <h3>, to avoid
“gaps” in the outline.

[0]: https://github.com/ckeditor/ckeditor5/issues/775
[1]: https://github.com/ckeditor/ckeditor5/issues/775#issuecomment-358591747
[2]: https://dev.ckeditor.com/ticket/1333
2023-10-13 18:09:28 +02:00
jordi fita mas ebf47b5d75 Add the “spiel” for campsite types
This is the text that introduces the carousel; it is not a spiel, but
this is what i call it.

It turns out that this text needs to have paragraphs and headings, much
like home’s slider, rather than the one in services page, thus no need
to change its font size or to align all items in the carousel in the
middle.
2023-10-12 18:47:08 +02:00
jordi fita mas 471ed9e870 Add the carousel for campsite types
I can not reuse the carousel package because these carousels need the
campsite site’s slug as a first parameters: i can not have a relation
per campsite type, as i do in home and services pages, because the
campsite types are added by administration types; even if i had a
single relation for slides of home and services pages, these would go
in a different relation due to the foreign key to campsite type.

What i could reuse, however, is the Slide and SlideEntry types from
that package, although i had to export carousel.Translation to be usable
from the types package.  I should change that to use locale.Translation,
but this was the easier option, or i would need to change the queries
and templates for carousel package too.

Besides that, they work exactly like the slides in home and services
pages.
2023-10-12 17:43:23 +02:00
jordi fita mas caab52a274 Add the campground page
For now, this page only shows the map, that i had to create a new
“files” template function to include it as an extra template file.
2023-10-06 22:14:11 +02:00
jordi fita mas ae29726fa2 Add the footer site map
I created a common template to show the company address in the footer
and the contact page, and then i realized Go did not like to output my
phone URL in the anchor without having the tel: schema in the template.
I then removed that variable and now the URL is created with tel: and
the phone number with its spaces removed.
2023-10-06 22:02:59 +02:00
jordi fita mas b73c70c347 Change “singular lodges” menu item to just “campsites” 2023-10-06 18:58:24 +02:00
jordi fita mas 9293a341ef Add campsite type options, mainly for plots 2023-10-06 13:26:01 +02:00
jordi fita mas 5f38ab8fd3 Add internationalization and localization to seasons 2023-10-03 21:14:37 +02:00
jordi fita mas ef6a8f5aee Add the campsite type cost per season 2023-10-01 21:14:39 +02:00
jordi fita mas 680d51e704 Add max campers and dogs allowed fields to campsite types 2023-09-29 20:17:39 +02:00
jordi fita mas ea2fe8848b Add the season_calendar relation and table on the admin section
This calendar is supposed to be edited by admin users, but do not yet
have the complete JavaScript code to do so, thus for now i have made it
read-only.
2023-09-27 02:23:09 +02:00
jordi fita mas 067ca7a3ee Add function and HTTP handler to delete services 2023-09-26 17:29:49 +02:00
jordi fita mas 650d3bff7b Add a confirmation message for delete actions, except for session
I do not like confirmation messages: they question user’s actions, and
in general it is better to offer an undo option afterward. However, undo
is harder to implement, and currently i do not have time to do this.

The delete for the session is different because the only repercussion
would be to log in again; the user is not in danger of losing any data
whatsoever.
2023-09-26 17:00:22 +02:00
jordi fita mas d4cabce7f5 Add the new service form 2023-09-26 16:51:35 +02:00
jordi fita mas 44526b1efb Add the edit form for services
This one has an input to select the icon.  It makes no sense to choose
an icon only by name, thus a <select> is not appropriate, and had to
use a hidden input with a row of button to choose the icon from.  This
works now only because there are very few icons; we’ll need to choose
a different approach when there are many more icons.

Since now the icons have to be defined in CSS for both the public and
admin sections, i had to split it into a separate file that both sites
can use.  I considered the option to “include” that CSS with m4, like
i do for images in demo.sql, but it made everything too complicated
(e.g., having to call make for each change in the CSS), and decided to
load that CSS in a separate <link>.
2023-09-25 20:10:33 +02:00
jordi fita mas e3503187d3 Add campsite map in SVG
I intend to use the same SVG file for customers and employees, so i had
to change Oriol’s design to add a class to layers that are supposed to
be only for customers, like trees.  These are hidden in the admin area.

I understood that customers and employees have to click on a campsite to
select it, and then they can book or whatever they need to do to them.
Since customers and employees most certainly will need to have different
listeners on campsites, i decided to add the link with JavaScript.  To
do so, i need a custom XML attribute with the campsite’s identifier.

Since i have seen that all campsites have a label, i changed the
“identifier” to the unique combination (company_id, label).  The
company_id is there because different companies could have the same
label; i left the campsite_id primary key for foreign constraints.

In this case, as a test, i add an <a> element to the campsite with a
link to edit it; we’ll discuss with Oriol what exactly it needs to do.

However, the original design had the labels in a different layer, that
interfered with the link, as the numbers must be above the path and
the link must wrap the path in order to “inherit” its shape.  I had no
other recourse than to move the labels in the same layer as the paths’.
2023-09-24 03:17:13 +02:00
jordi fita mas 8c0dbf7806 Fix the label and prompt for the carousel media field 2023-09-22 02:17:56 +02:00
jordi fita mas 5a16fa44a6 Change media picker from <div> to <dialog> and make it modal
Have to call Dialog.showModal when HTMx loaded the dialog in the DOM,
so had to add a onLoad event listened that checks whether the loaded
element is actually a DIALOG.

Had to restrict the margin: 0 for all elements (*) to exclude dialog,
because the browser sets it to auto, and i did not want to set it again
just because i was too overzealous with my “reset”.

The rest of the CSS is just to have a sticky header and footer, and see
the cancel button, that works as a “close”, all the time.

Finally, i realized that if i add the dialog at the end of the fieldset
and let HTMx inherit its hx-target and hx-swap, i no longer need to set
them in the dialog, as HTMx will always replace the fieldset, and i can
have the dialog side by side the current content of the fieldset, that
it was very confusing seeing it disappear when trying to select a new
media.

The cancel button could now just remove the dialog instead of making the
POST, but in local it makes no difference; we’lls see what happens on
production.
2023-09-22 02:11:03 +02:00
jordi fita mas b5d40cc262 Add the upload form to the media picker
It makes easier to upload new images from the place where we need it,
instead of having to go to the media section each time.

It was a little messy, this one.

First of all, I realized that POSTint to /admin/media/picker to get the
new media field was wrong: i was not asking the server to “accept an
entity”, but only requesting a new HTML value, just like a GET to
/admin/media/upload requests the form to upload a new media, thus here
i should do the same, except i needed the query parameters to change the
field, which is fine—it is actually a different resource, thus a
different URL.

Then, i thought that i could not POST the upload to /admin/media,
because i returned a different HTML —the media field—, so i reused the
recently unused POST to /admin/media/picker to upload that file and
return the HTML for the field.  It was wrong, because i was not
requesting the server to put the file as a subordinate of
/admin/media/picker, only /admin/media, but i did not come up with any
other solution.

Since i had two different upload functions now, i created uploadForm’s
Handle method to refactorize the duplicated logic to a single place.
Unfortunately, i did not work as i expected because uploadForm’s and
mediaPicker’s MustRender methods are different, and mediaPicker has to
embed uploadForm to render the form in the picker.  That made me change
Handle’s output to a boolean and error in order for the HTTP handler
function know when to render the form with the error messages with the
proper MustRender handler.

However, I saw the opportunity of reusing that Handler method for
editMedia, that was doing mostly the same job, but had to call a
different Validate than uploadForm’s, because editMedia does not require
the uploaded file.  That’s when i realized that i could use an interface
and that this interface could be reused not only within media but
throughout the application, and added HandleMultipart in form.

Had to create a different interface for multipart forms because they
need different parameters in Parse that non-multipart form, when i add
that interface, hence had to also change Parse to ParseForm to account
for the difference in signature; not a big deal.

After all that, i realized that i **could** POST to /admin/media in both
cases, because i always return “an HTML entity”, it just happens that
for the media section it is empty with a redirect, and for the picker is
the field.  That made the whole Handle method a bit redundant, but i
left it nevertheless, as i find it slightly easier to read the
uploadMedia function now.
2023-09-22 01:40:22 +02:00
jordi fita mas 97cf117da3 Manage all media uploads in a single place
It made no sense to have a file upload in each form that needs a media,
because to reuse an existing media users would need to upload the exact
same file again; this is very unusual and unfriendly.

A better option is to have a “centralized” media section, where people
can upload files there, and then have a picker to select from there.
Ideally, there would be an upload option in the picker, but i did not
add it yet.

I’ve split the content from the media because i want users to have the
option to update a media, for instance when they need to upload a
reduced or cropped version of the same photo, without an edit they would
need to upload the file as a new media and then update all places where
the old version was used.  And i did not want to trouble people that
uploads the same photo twice: without the separate relation, doing so
would throw a constraint error.

I do not believe there is any security problem to have all companies
link their media to the same file, as they were already readable by
everyone and could upload the data from a different company to their
own; in other words, it is not worse than it was now.
2023-09-21 01:56:44 +02:00
jordi fita mas afe77f2296 Add the services page
This page is more or less similar to home, in terms of database: it
has a carousel and a list of items; in this case, the definition of
campsite services.

As i said early, when adding the home carousel, this carousel has its
own relation and set of functions to manage slides.  They are also
duplicated in Go code, but i think i will need to refactor it later to
a carousel package or something like that, because both relations have
the exact same fields and types, so it makes no sense to have twice the
same code.

I already did it with the CSS and JavaScript code, mostly because it was
easier to replace the `.surroundings div` selector with `.carousel`, and
because that way i can have a single template that loads and initializes
Slick.

There is no UI to create or edit service definitions, although there are
the SQL functions, because i have no more time now, and Oriol needs to
check that the style is correct for that page.
2023-09-17 03:42:16 +02:00
jordi fita mas 8b8dda7969 Add the surroundings static page
This page is “highly stylized”, with a masonry-like grid, that i did not
know how to generate automatically from data defined in PostgreSQL,
therefore with Oriol we agreed to have this one as a static page and
we will see what we can do if the customer asks to be able to change
it.

I was a bit undecided on whether the icons in the bottom part of the
page should be defined in the CSS or with style="" and CSS variables,
like i do for the campsite type in the home page.

At first i thought that it should use CSS variables, mostly for
coherence: if another section of the web does it for its background
image, why no this one.  The difference is that the home page is
dynamically created from the database, while this page is static and we
know what icons we need, thus it makes more sense to move it to the
stylesheet file, because then it will be downloaded by user agents that
actually want to use it (e.g., browsers, but not Braille terminals).
2023-09-17 00:11:39 +02:00
jordi fita mas d08fa31c81 Add translate_campsite_type SQL function
It makes sense that, if i have it for the home page sliders, i should
also have it for the campsite type, for consistence, at least.
2023-09-15 01:23:51 +02:00
jordi fita mas f746c82b46 Make home page’s carousel manageable via the database
I debated with myself whether to create the home_carousel relation or
rather if it would be better to have a single carousel relation for all
pages.  However, i thought that it would be actually harder to maintain
a single relation because i would need an additional column to tell one
carrousel from another, and what would that column be? An enum? A
foreign key to another relation? home_carousel carries no such issues.

I was starting to duplicate logic all over the packages, such as the
way to encode media paths or “localization” (l10n) input fields.
Therefore, i refactorized them.

In the case of media path, i added a function that accepts rows of
media, because always need the same columns from the row, and it was
yet another repetition if i needed to pass them all the time.  Plus,
these kind of functions can be called as `table.function`, that make
them look like columns from the table; if PostgreSQL implemented virtual
generated columns, i would have used that instead.

I am not sure whether that media_path function can be immutable. An
immutable function is “guaranteed to return the same results given the
same arguments forever”, which would be true if the inputs where the
hash and the original_filename columns, instead of the whole rows, but
i left it as static because i did not know whether PostgreSQL interprets
the “same row but with different values” as a different input.  That is,
whether PostgreSQL’s concept of row is the actual tuple or the space
that has a rowid, irrespective of contents; in the latter case, the
function can not be immutable.  Just to be in the safe side, i left it
stable.

The home page was starting to grow a bit too much inside the app
package, new that it has its own admin handler, and moved it all to a
separate package.
2023-09-15 01:05:38 +02:00
jordi fita mas f48936f800 Add internationalization and localization of campsite types
I am not happy with the localization interface for admins, but it is the
easier that i could think of (for me, i guess), with a separate for
each language.

I am not at all proud of the use of RecordArray, but i did not see the
need to create and register a type just to show the translation links.
I might change my mind when i need to add more and more translation
links, but only it the current interface remains, which i am not that
sure at the moment.
2023-09-12 20:20:23 +02:00
jordi fita mas e4053cd844 Change home’s texts to English and add Catalan and Spanish translations 2023-09-11 04:20:21 +02:00