Add position to services to be able to manually sort by admins

This commit is contained in:
jordi fita mas 2024-01-13 01:15:24 +01:00
parent 4e126237a0
commit 976b2bcbcf
16 changed files with 425 additions and 270 deletions

25
deploy/order_services.sql Normal file
View File

@ -0,0 +1,25 @@
-- Deploy camper:order_services to pg
-- requires: schema_camper
-- requires: roles
-- requires: service
-- requires: service__position
begin;
set search_path to camper, public;
create or replace function order_services(positions integer[]) returns void as
$$
update service
set position = cast(temp.position as integer)
from unnest(positions) with ordinality as temp(service_id, position)
where service.service_id = temp.service_id
;
$$
language sql
;
revoke execute on function order_services(integer[]) from public;
grant execute on function order_services(integer[]) to admin;
commit;

View File

@ -0,0 +1,10 @@
-- Deploy camper:service__position to pg
-- requires: service
begin;
alter table camper.service
add column position integer not null default 2147483647
;
commit;

View File

@ -145,3 +145,8 @@ func (tx *Tx) TranslateService(ctx context.Context, id int, langTag language.Tag
_, err := tx.Exec(ctx, "select translate_service($1, $2, $3, $4)", id, langTag, name, description)
return err
}
func (c *Conn) OrderServices(ctx context.Context, ids []int) error {
_, err := c.Exec(ctx, "select order_services($1)", ids)
return err
}

View File

@ -58,6 +58,13 @@ func (h *AdminHandler) Handler(user *auth.User, company *auth.Company, conn *dat
default:
httplib.MethodNotAllowed(w, r, http.MethodGet)
}
case "order":
switch r.Method {
case http.MethodPost:
orderServices(w, r, user, company, conn)
default:
httplib.MethodNotAllowed(w, r, http.MethodPost)
}
case "slides":
h.carousel.Handler(user, company, conn).ServeHTTP(w, r)
default:
@ -95,6 +102,33 @@ func (h *AdminHandler) Handler(user *auth.User, company *auth.Company, conn *dat
})
}
func orderServices(w http.ResponseWriter, r *http.Request, user *auth.User, company *auth.Company, conn *database.Conn) {
if err := r.ParseForm(); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if err := user.VerifyCSRFToken(r); err != nil {
http.Error(w, err.Error(), http.StatusForbidden)
return
}
input := r.PostForm["service_id"]
if len(input) > 0 {
var ids []int
for _, s := range input {
if id, err := strconv.Atoi(s); err == nil {
ids = append(ids, id)
} else {
http.Error(w, err.Error(), http.StatusUnprocessableEntity)
return
}
}
if err := conn.OrderServices(r.Context(), ids); err != nil {
panic(err)
}
}
serveServicesIndex(w, r, user, company, conn)
}
func serveServicesIndex(w http.ResponseWriter, r *http.Request, user *auth.User, company *auth.Company, conn *database.Conn) {
slides, err := carousel.CollectSlideEntries(r.Context(), company, conn, carouselName)
if err != nil {
@ -118,6 +152,7 @@ func (page *servicesIndex) MustRender(w http.ResponseWriter, r *http.Request, us
}
type serviceEntry struct {
ID int
URL string
Icon string
Name string
@ -125,12 +160,14 @@ type serviceEntry struct {
func collectServiceEntries(ctx context.Context, company *auth.Company, conn *database.Conn) ([]*serviceEntry, error) {
rows, err := conn.Query(ctx, `
select '/admin/services/' || service_id
select service_id
, '/admin/services/' || service_id
, icon_name
, service.name
, name
from service
where service.company_id = $1
order by service.name
where company_id = $1
order by position
, name
`, company.ID)
if err != nil {
return nil, err
@ -140,7 +177,7 @@ func collectServiceEntries(ctx context.Context, company *auth.Company, conn *dat
var services []*serviceEntry
for rows.Next() {
entry := &serviceEntry{}
if err = rows.Scan(&entry.URL, &entry.Icon, &entry.Name); err != nil {
if err = rows.Scan(&entry.ID, &entry.URL, &entry.Icon, &entry.Name); err != nil {
return nil, err
}
services = append(services, entry)

View File

@ -74,6 +74,8 @@ func mustCollectServices(ctx context.Context, company *auth.Company, conn *datab
from service
left join service_i18n as i18n on service.service_id = i18n.service_id and lang_tag = $1
where service.company_id = $2
order by position
, l10_name
`, loc.Language, company.ID)
if err != nil {
panic(err)

149
po/ca.po
View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: camper\n"
"Report-Msgid-Bugs-To: jordi@tandem.blog\n"
"POT-Creation-Date: 2024-01-12 19:19+0100\n"
"POT-Creation-Date: 2024-01-13 01:12+0100\n"
"PO-Revision-Date: 2023-07-22 23:45+0200\n"
"Last-Translator: jordi fita mas <jordi@tandem.blog>\n"
"Language-Team: Catalan <ca@dodds.net>\n"
@ -125,7 +125,7 @@ msgid "Book"
msgstr "Reserva"
#: web/templates/public/campsite/type.gohtml:62
#: web/templates/admin/season/index.gohtml:59
#: web/templates/admin/season/index.gohtml:51
msgctxt "title"
msgid "Calendar"
msgstr "Calendari"
@ -422,9 +422,7 @@ msgstr "Àlies"
#: web/templates/admin/campsite/option/form.gohtml:34
#: web/templates/admin/campsite/type/form.gohtml:46
#: web/templates/admin/season/form.gohtml:46
#: web/templates/admin/season/l10n.gohtml:20
#: web/templates/admin/services/form.gohtml:52
#: web/templates/admin/services/l10n.gohtml:20
#: web/templates/admin/profile.gohtml:26
msgctxt "input"
msgid "Name"
@ -442,8 +440,8 @@ msgstr "Contingut"
#: web/templates/admin/campsite/form.gohtml:70
#: web/templates/admin/campsite/option/form.gohtml:83
#: web/templates/admin/campsite/type/form.gohtml:158
#: web/templates/admin/season/form.gohtml:64
#: web/templates/admin/services/form.gohtml:69
#: web/templates/admin/season/form.gohtml:69
#: web/templates/admin/services/form.gohtml:80
#: web/templates/admin/media/form.gohtml:35
msgctxt "action"
msgid "Update"
@ -456,8 +454,8 @@ msgstr "Actualitza"
#: web/templates/admin/campsite/form.gohtml:72
#: web/templates/admin/campsite/option/form.gohtml:85
#: web/templates/admin/campsite/type/form.gohtml:160
#: web/templates/admin/season/form.gohtml:66
#: web/templates/admin/services/form.gohtml:71
#: web/templates/admin/season/form.gohtml:71
#: web/templates/admin/services/form.gohtml:82
msgctxt "action"
msgid "Add"
msgstr "Afegeix"
@ -606,7 +604,7 @@ msgstr "Llegenda"
#: web/templates/admin/campsite/carousel/index.gohtml:27
#: web/templates/admin/services/index.gohtml:27
#: web/templates/admin/services/index.gohtml:64
#: web/templates/admin/services/index.gohtml:72
#: web/templates/admin/home/index.gohtml:27
msgctxt "header"
msgid "Actions"
@ -620,7 +618,7 @@ msgstr "Esteu segur de voler esborrar aquesta diapositiva?"
#: web/templates/admin/campsite/carousel/index.gohtml:45
#: web/templates/admin/services/index.gohtml:44
#: web/templates/admin/services/index.gohtml:83
#: web/templates/admin/services/index.gohtml:88
#: web/templates/admin/home/index.gohtml:44
msgctxt "action"
msgid "Delete"
@ -724,13 +722,13 @@ msgstr "Tipus"
#: web/templates/admin/campsite/index.gohtml:28
#: web/templates/admin/campsite/type/index.gohtml:49
#: web/templates/admin/season/index.gohtml:49
#: web/templates/admin/season/index.gohtml:41
msgid "Yes"
msgstr "Sí"
#: web/templates/admin/campsite/index.gohtml:28
#: web/templates/admin/campsite/type/index.gohtml:49
#: web/templates/admin/season/index.gohtml:49
#: web/templates/admin/season/index.gohtml:41
msgid "No"
msgstr "No"
@ -787,8 +785,7 @@ msgid "Facilities"
msgstr "Equipaments"
#: web/templates/admin/campsite/type/form.gohtml:143
#: web/templates/admin/services/form.gohtml:60
#: web/templates/admin/services/l10n.gohtml:32
#: web/templates/admin/services/form.gohtml:65
msgctxt "input"
msgid "Description"
msgstr "Descripció"
@ -852,12 +849,12 @@ msgid "New Season"
msgstr "Nova temporada"
#: web/templates/admin/season/form.gohtml:37
#: web/templates/admin/season/index.gohtml:28
#: web/templates/admin/season/index.gohtml:27
msgctxt "season"
msgid "Active"
msgstr "Activa"
#: web/templates/admin/season/form.gohtml:54
#: web/templates/admin/season/form.gohtml:59
msgctxt "input"
msgid "Color"
msgstr "Color"
@ -879,41 +876,10 @@ msgctxt "header"
msgid "Color"
msgstr "Color"
#: web/templates/admin/season/index.gohtml:27
#: web/templates/admin/services/index.gohtml:63
msgctxt "header"
msgid "Translations"
msgstr "Traduccions"
#: web/templates/admin/season/index.gohtml:56
#: web/templates/admin/season/index.gohtml:48
msgid "No seasons added yet."
msgstr "No sha afegit cap temporada encara."
#: web/templates/admin/season/l10n.gohtml:7
#: web/templates/admin/season/l10n.gohtml:14
msgctxt "title"
msgid "Translate Season to %s"
msgstr "Traducció de la temporada a %s"
#: web/templates/admin/season/l10n.gohtml:21
#: web/templates/admin/services/l10n.gohtml:21
#: web/templates/admin/services/l10n.gohtml:33
msgid "Source:"
msgstr "Origen:"
#: web/templates/admin/season/l10n.gohtml:23
#: web/templates/admin/services/l10n.gohtml:23
#: web/templates/admin/services/l10n.gohtml:36
msgctxt "input"
msgid "Translation:"
msgstr "Traducció:"
#: web/templates/admin/season/l10n.gohtml:32
#: web/templates/admin/services/l10n.gohtml:45
msgctxt "action"
msgid "Translate"
msgstr "Tradueix"
#: web/templates/admin/season/calendar.gohtml:49
#: web/templates/admin/media/picker.gohtml:61
msgctxt "action"
@ -1006,25 +972,24 @@ msgctxt "action"
msgid "Add service"
msgstr "Afegeix servei"
#: web/templates/admin/services/index.gohtml:62
#: web/templates/admin/services/index.gohtml:70
msgctxt "header"
msgid "Order"
msgstr "Ordre"
#: web/templates/admin/services/index.gohtml:71
msgctxt "header"
msgid "Service"
msgstr "Servei"
#: web/templates/admin/services/index.gohtml:68
#: web/templates/admin/services/index.gohtml:76
msgid "Are you sure you wish to delete this service?"
msgstr "Esteu segur de voler esborrar aquest servei?"
#: web/templates/admin/services/index.gohtml:91
#: web/templates/admin/services/index.gohtml:97
msgid "No services added yet."
msgstr "No sha afegit cap servei encara."
#: web/templates/admin/services/l10n.gohtml:7
#: web/templates/admin/services/l10n.gohtml:14
msgctxt "title"
msgid "Translate Service to %s"
msgstr "Traducció del servei a %s"
#: web/templates/admin/profile.gohtml:6 web/templates/admin/profile.gohtml:12
#: web/templates/admin/layout.gohtml:32
msgctxt "title"
@ -1210,14 +1175,13 @@ msgctxt "title"
msgid "Upload Media"
msgstr "Pujada de mèdia"
#: pkg/legal/admin.go:255 pkg/app/user.go:249 pkg/campsite/types/option.go:344
#: pkg/legal/admin.go:258 pkg/app/user.go:249 pkg/campsite/types/option.go:344
#: pkg/campsite/types/feature.go:259 pkg/campsite/types/admin.go:453
#: pkg/season/l10n.go:69 pkg/season/admin.go:405 pkg/services/l10n.go:73
#: pkg/services/admin.go:266
#: pkg/season/admin.go:415 pkg/services/admin.go:319
msgid "Name can not be empty."
msgstr "No podeu deixar el nom en blanc."
#: pkg/legal/admin.go:256 pkg/campsite/types/option.go:345
#: pkg/legal/admin.go:259 pkg/campsite/types/option.go:345
#: pkg/campsite/types/feature.go:260 pkg/campsite/types/admin.go:454
msgid "Name must have at least one letter."
msgstr "El nom ha de tenir com a mínim una lletra."
@ -1315,7 +1279,7 @@ msgstr "El preu per nit ha de ser un número decimal."
msgid "Price per night must be zero or greater."
msgstr "El preu per nit ha de ser com a mínim zero."
#: pkg/campsite/types/feature.go:258 pkg/services/admin.go:265
#: pkg/campsite/types/feature.go:258 pkg/services/admin.go:318
msgid "Selected icon is not valid."
msgstr "La icona escollida no és vàlida."
@ -1369,92 +1333,92 @@ msgstr "El tipus dallotjament escollit no és vàlid."
msgid "Label can not be empty."
msgstr "No podeu deixar letiqueta en blanc."
#: pkg/season/admin.go:222
#: pkg/season/admin.go:186
msgctxt "month"
msgid "January"
msgstr "gener"
#: pkg/season/admin.go:223
#: pkg/season/admin.go:187
msgctxt "month"
msgid "February"
msgstr "febrer"
#: pkg/season/admin.go:224
#: pkg/season/admin.go:188
msgctxt "month"
msgid "March"
msgstr "març"
#: pkg/season/admin.go:225
#: pkg/season/admin.go:189
msgctxt "month"
msgid "April"
msgstr "abril"
#: pkg/season/admin.go:226
#: pkg/season/admin.go:190
msgctxt "month"
msgid "May"
msgstr "maig"
#: pkg/season/admin.go:227
#: pkg/season/admin.go:191
msgctxt "month"
msgid "June"
msgstr "juny"
#: pkg/season/admin.go:228
#: pkg/season/admin.go:192
msgctxt "month"
msgid "July"
msgstr "juliol"
#: pkg/season/admin.go:229
#: pkg/season/admin.go:193
msgctxt "month"
msgid "August"
msgstr "agost"
#: pkg/season/admin.go:230
#: pkg/season/admin.go:194
msgctxt "month"
msgid "September"
msgstr "setembre"
#: pkg/season/admin.go:231
#: pkg/season/admin.go:195
msgctxt "month"
msgid "October"
msgstr "octubre"
#: pkg/season/admin.go:232
#: pkg/season/admin.go:196
msgctxt "month"
msgid "November"
msgstr "novembre"
#: pkg/season/admin.go:233
#: pkg/season/admin.go:197
msgctxt "month"
msgid "December"
msgstr "desembre"
#: pkg/season/admin.go:406
#: pkg/season/admin.go:416
msgid "Color can not be empty."
msgstr "No podeu deixar el color en blanc."
#: pkg/season/admin.go:407
#: pkg/season/admin.go:417
msgid "This color is not valid. It must be like #123abc."
msgstr "Aquest color no és vàlid. Hauria de ser similar a #123abc."
#: pkg/season/admin.go:507
#: pkg/season/admin.go:517
msgctxt "action"
msgid "Unset"
msgstr "Desassigna"
#: pkg/season/admin.go:538
#: pkg/season/admin.go:548
msgid "Start date can not be empty."
msgstr "No podeu deixar la data dinici en blanc."
#: pkg/season/admin.go:539
#: pkg/season/admin.go:549
msgid "Start date must be a valid date."
msgstr "La data dinici ha de ser una data vàlida."
#: pkg/season/admin.go:541
#: pkg/season/admin.go:551
msgid "End date can not be empty."
msgstr "No podeu deixar la data de fi en blanc."
#: pkg/season/admin.go:542
#: pkg/season/admin.go:552
msgid "End date must be a valid date."
msgstr "La data de fi ha de ser una data vàlida."
@ -1638,6 +1602,29 @@ msgstr "El valor de %s ha de ser com a mínim %d."
msgid "%s must be at most %d."
msgstr "El valor de %s ha de ser com a màxim %d."
#~ msgctxt "header"
#~ msgid "Translations"
#~ msgstr "Traduccions"
#~ msgctxt "title"
#~ msgid "Translate Season to %s"
#~ msgstr "Traducció de la temporada a %s"
#~ msgid "Source:"
#~ msgstr "Origen:"
#~ msgctxt "input"
#~ msgid "Translation:"
#~ msgstr "Traducció:"
#~ msgctxt "action"
#~ msgid "Translate"
#~ msgstr "Tradueix"
#~ msgctxt "title"
#~ msgid "Translate Service to %s"
#~ msgstr "Traducció del servei a %s"
#~ msgctxt "title"
#~ msgid "Translate Carousel Slide to %s"
#~ msgstr "Traducció de la diapositiva del carrusel a %s"

149
po/es.po
View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: camper\n"
"Report-Msgid-Bugs-To: jordi@tandem.blog\n"
"POT-Creation-Date: 2024-01-12 19:19+0100\n"
"POT-Creation-Date: 2024-01-13 01:12+0100\n"
"PO-Revision-Date: 2023-07-22 23:46+0200\n"
"Last-Translator: jordi fita mas <jordi@tandem.blog>\n"
"Language-Team: Spanish <es@tp.org.es>\n"
@ -125,7 +125,7 @@ msgid "Book"
msgstr "Reservar"
#: web/templates/public/campsite/type.gohtml:62
#: web/templates/admin/season/index.gohtml:59
#: web/templates/admin/season/index.gohtml:51
msgctxt "title"
msgid "Calendar"
msgstr "Calendario"
@ -422,9 +422,7 @@ msgstr "Álias"
#: web/templates/admin/campsite/option/form.gohtml:34
#: web/templates/admin/campsite/type/form.gohtml:46
#: web/templates/admin/season/form.gohtml:46
#: web/templates/admin/season/l10n.gohtml:20
#: web/templates/admin/services/form.gohtml:52
#: web/templates/admin/services/l10n.gohtml:20
#: web/templates/admin/profile.gohtml:26
msgctxt "input"
msgid "Name"
@ -442,8 +440,8 @@ msgstr "Contenido"
#: web/templates/admin/campsite/form.gohtml:70
#: web/templates/admin/campsite/option/form.gohtml:83
#: web/templates/admin/campsite/type/form.gohtml:158
#: web/templates/admin/season/form.gohtml:64
#: web/templates/admin/services/form.gohtml:69
#: web/templates/admin/season/form.gohtml:69
#: web/templates/admin/services/form.gohtml:80
#: web/templates/admin/media/form.gohtml:35
msgctxt "action"
msgid "Update"
@ -456,8 +454,8 @@ msgstr "Actualizar"
#: web/templates/admin/campsite/form.gohtml:72
#: web/templates/admin/campsite/option/form.gohtml:85
#: web/templates/admin/campsite/type/form.gohtml:160
#: web/templates/admin/season/form.gohtml:66
#: web/templates/admin/services/form.gohtml:71
#: web/templates/admin/season/form.gohtml:71
#: web/templates/admin/services/form.gohtml:82
msgctxt "action"
msgid "Add"
msgstr "Añadir"
@ -606,7 +604,7 @@ msgstr "Leyenda"
#: web/templates/admin/campsite/carousel/index.gohtml:27
#: web/templates/admin/services/index.gohtml:27
#: web/templates/admin/services/index.gohtml:64
#: web/templates/admin/services/index.gohtml:72
#: web/templates/admin/home/index.gohtml:27
msgctxt "header"
msgid "Actions"
@ -620,7 +618,7 @@ msgstr "¿Estáis seguro de querer borrar esta diapositiva?"
#: web/templates/admin/campsite/carousel/index.gohtml:45
#: web/templates/admin/services/index.gohtml:44
#: web/templates/admin/services/index.gohtml:83
#: web/templates/admin/services/index.gohtml:88
#: web/templates/admin/home/index.gohtml:44
msgctxt "action"
msgid "Delete"
@ -724,13 +722,13 @@ msgstr "Tipo"
#: web/templates/admin/campsite/index.gohtml:28
#: web/templates/admin/campsite/type/index.gohtml:49
#: web/templates/admin/season/index.gohtml:49
#: web/templates/admin/season/index.gohtml:41
msgid "Yes"
msgstr "Sí"
#: web/templates/admin/campsite/index.gohtml:28
#: web/templates/admin/campsite/type/index.gohtml:49
#: web/templates/admin/season/index.gohtml:49
#: web/templates/admin/season/index.gohtml:41
msgid "No"
msgstr "No"
@ -787,8 +785,7 @@ msgid "Facilities"
msgstr "Equipamento"
#: web/templates/admin/campsite/type/form.gohtml:143
#: web/templates/admin/services/form.gohtml:60
#: web/templates/admin/services/l10n.gohtml:32
#: web/templates/admin/services/form.gohtml:65
msgctxt "input"
msgid "Description"
msgstr "Descripción"
@ -852,12 +849,12 @@ msgid "New Season"
msgstr "Nueva temporada"
#: web/templates/admin/season/form.gohtml:37
#: web/templates/admin/season/index.gohtml:28
#: web/templates/admin/season/index.gohtml:27
msgctxt "season"
msgid "Active"
msgstr "Activa"
#: web/templates/admin/season/form.gohtml:54
#: web/templates/admin/season/form.gohtml:59
msgctxt "input"
msgid "Color"
msgstr "Color"
@ -879,41 +876,10 @@ msgctxt "header"
msgid "Color"
msgstr "Color"
#: web/templates/admin/season/index.gohtml:27
#: web/templates/admin/services/index.gohtml:63
msgctxt "header"
msgid "Translations"
msgstr "Traducciones"
#: web/templates/admin/season/index.gohtml:56
#: web/templates/admin/season/index.gohtml:48
msgid "No seasons added yet."
msgstr "No se ha añadido ninguna temporada todavía."
#: web/templates/admin/season/l10n.gohtml:7
#: web/templates/admin/season/l10n.gohtml:14
msgctxt "title"
msgid "Translate Season to %s"
msgstr "Traducción de la temporada a %s"
#: web/templates/admin/season/l10n.gohtml:21
#: web/templates/admin/services/l10n.gohtml:21
#: web/templates/admin/services/l10n.gohtml:33
msgid "Source:"
msgstr "Origen:"
#: web/templates/admin/season/l10n.gohtml:23
#: web/templates/admin/services/l10n.gohtml:23
#: web/templates/admin/services/l10n.gohtml:36
msgctxt "input"
msgid "Translation:"
msgstr "Traducción"
#: web/templates/admin/season/l10n.gohtml:32
#: web/templates/admin/services/l10n.gohtml:45
msgctxt "action"
msgid "Translate"
msgstr "Traducir"
#: web/templates/admin/season/calendar.gohtml:49
#: web/templates/admin/media/picker.gohtml:61
msgctxt "action"
@ -1006,25 +972,24 @@ msgctxt "action"
msgid "Add service"
msgstr "Añadir servicio"
#: web/templates/admin/services/index.gohtml:62
#: web/templates/admin/services/index.gohtml:70
msgctxt "header"
msgid "Order"
msgstr "Orden"
#: web/templates/admin/services/index.gohtml:71
msgctxt "header"
msgid "Service"
msgstr "Servicio"
#: web/templates/admin/services/index.gohtml:68
#: web/templates/admin/services/index.gohtml:76
msgid "Are you sure you wish to delete this service?"
msgstr "¿Estáis seguro de querer borrar este servicio?"
#: web/templates/admin/services/index.gohtml:91
#: web/templates/admin/services/index.gohtml:97
msgid "No services added yet."
msgstr "No se ha añadido ningún servicio todavía."
#: web/templates/admin/services/l10n.gohtml:7
#: web/templates/admin/services/l10n.gohtml:14
msgctxt "title"
msgid "Translate Service to %s"
msgstr "Traducción del servicio a %s"
#: web/templates/admin/profile.gohtml:6 web/templates/admin/profile.gohtml:12
#: web/templates/admin/layout.gohtml:32
msgctxt "title"
@ -1210,14 +1175,13 @@ msgctxt "title"
msgid "Upload Media"
msgstr "Subida de medio"
#: pkg/legal/admin.go:255 pkg/app/user.go:249 pkg/campsite/types/option.go:344
#: pkg/legal/admin.go:258 pkg/app/user.go:249 pkg/campsite/types/option.go:344
#: pkg/campsite/types/feature.go:259 pkg/campsite/types/admin.go:453
#: pkg/season/l10n.go:69 pkg/season/admin.go:405 pkg/services/l10n.go:73
#: pkg/services/admin.go:266
#: pkg/season/admin.go:415 pkg/services/admin.go:319
msgid "Name can not be empty."
msgstr "No podéis dejar el nombre en blanco."
#: pkg/legal/admin.go:256 pkg/campsite/types/option.go:345
#: pkg/legal/admin.go:259 pkg/campsite/types/option.go:345
#: pkg/campsite/types/feature.go:260 pkg/campsite/types/admin.go:454
msgid "Name must have at least one letter."
msgstr "El nombre tiene que tener como mínimo una letra."
@ -1315,7 +1279,7 @@ msgstr "El precio por noche tien que ser un número decimal."
msgid "Price per night must be zero or greater."
msgstr "El precio por noche tiene que ser como mínimo cero."
#: pkg/campsite/types/feature.go:258 pkg/services/admin.go:265
#: pkg/campsite/types/feature.go:258 pkg/services/admin.go:318
msgid "Selected icon is not valid."
msgstr "El icono escogido no es válido."
@ -1369,92 +1333,92 @@ msgstr "El tipo de alojamiento escogido no es válido."
msgid "Label can not be empty."
msgstr "No podéis dejar la etiqueta en blanco."
#: pkg/season/admin.go:222
#: pkg/season/admin.go:186
msgctxt "month"
msgid "January"
msgstr "enero"
#: pkg/season/admin.go:223
#: pkg/season/admin.go:187
msgctxt "month"
msgid "February"
msgstr "febrero"
#: pkg/season/admin.go:224
#: pkg/season/admin.go:188
msgctxt "month"
msgid "March"
msgstr "marzo"
#: pkg/season/admin.go:225
#: pkg/season/admin.go:189
msgctxt "month"
msgid "April"
msgstr "abril"
#: pkg/season/admin.go:226
#: pkg/season/admin.go:190
msgctxt "month"
msgid "May"
msgstr "mayo"
#: pkg/season/admin.go:227
#: pkg/season/admin.go:191
msgctxt "month"
msgid "June"
msgstr "junio"
#: pkg/season/admin.go:228
#: pkg/season/admin.go:192
msgctxt "month"
msgid "July"
msgstr "julio"
#: pkg/season/admin.go:229
#: pkg/season/admin.go:193
msgctxt "month"
msgid "August"
msgstr "agosto"
#: pkg/season/admin.go:230
#: pkg/season/admin.go:194
msgctxt "month"
msgid "September"
msgstr "septiembre"
#: pkg/season/admin.go:231
#: pkg/season/admin.go:195
msgctxt "month"
msgid "October"
msgstr "octubre"
#: pkg/season/admin.go:232
#: pkg/season/admin.go:196
msgctxt "month"
msgid "November"
msgstr "noviembre"
#: pkg/season/admin.go:233
#: pkg/season/admin.go:197
msgctxt "month"
msgid "December"
msgstr "diciembre"
#: pkg/season/admin.go:406
#: pkg/season/admin.go:416
msgid "Color can not be empty."
msgstr "No podéis dejar el color en blanco."
#: pkg/season/admin.go:407
#: pkg/season/admin.go:417
msgid "This color is not valid. It must be like #123abc."
msgstr "Este color no es válido. Tiene que ser parecido a #123abc."
#: pkg/season/admin.go:507
#: pkg/season/admin.go:517
msgctxt "action"
msgid "Unset"
msgstr "Desasignar"
#: pkg/season/admin.go:538
#: pkg/season/admin.go:548
msgid "Start date can not be empty."
msgstr "No podéis dejar la fecha de inicio en blanco."
#: pkg/season/admin.go:539
#: pkg/season/admin.go:549
msgid "Start date must be a valid date."
msgstr "La fecha de inicio tiene que ser una fecha válida."
#: pkg/season/admin.go:541
#: pkg/season/admin.go:551
msgid "End date can not be empty."
msgstr "No podéis dejar la fecha final en blanco."
#: pkg/season/admin.go:542
#: pkg/season/admin.go:552
msgid "End date must be a valid date."
msgstr "La fecha final tiene que ser una fecha válida."
@ -1638,6 +1602,29 @@ msgstr "%s tiene que ser como mínimo %d."
msgid "%s must be at most %d."
msgstr "%s tiene que ser como máximo %d"
#~ msgctxt "header"
#~ msgid "Translations"
#~ msgstr "Traducciones"
#~ msgctxt "title"
#~ msgid "Translate Season to %s"
#~ msgstr "Traducción de la temporada a %s"
#~ msgid "Source:"
#~ msgstr "Origen:"
#~ msgctxt "input"
#~ msgid "Translation:"
#~ msgstr "Traducción"
#~ msgctxt "action"
#~ msgid "Translate"
#~ msgstr "Traducir"
#~ msgctxt "title"
#~ msgid "Translate Service to %s"
#~ msgstr "Traducción del servicio a %s"
#~ msgctxt "title"
#~ msgid "Translate Carousel Slide to %s"
#~ msgstr "Traducción de la diapositiva de carrusel a %s"

149
po/fr.po
View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: camper\n"
"Report-Msgid-Bugs-To: jordi@tandem.blog\n"
"POT-Creation-Date: 2024-01-12 19:19+0100\n"
"POT-Creation-Date: 2024-01-13 01:12+0100\n"
"PO-Revision-Date: 2023-12-20 10:13+0100\n"
"Last-Translator: Oriol Carbonell <info@oriolcarbonell.cat>\n"
"Language-Team: French <traduc@traduc.org>\n"
@ -126,7 +126,7 @@ msgid "Book"
msgstr "Réserver"
#: web/templates/public/campsite/type.gohtml:62
#: web/templates/admin/season/index.gohtml:59
#: web/templates/admin/season/index.gohtml:51
msgctxt "title"
msgid "Calendar"
msgstr "Calendrier"
@ -423,9 +423,7 @@ msgstr "Slug"
#: web/templates/admin/campsite/option/form.gohtml:34
#: web/templates/admin/campsite/type/form.gohtml:46
#: web/templates/admin/season/form.gohtml:46
#: web/templates/admin/season/l10n.gohtml:20
#: web/templates/admin/services/form.gohtml:52
#: web/templates/admin/services/l10n.gohtml:20
#: web/templates/admin/profile.gohtml:26
msgctxt "input"
msgid "Name"
@ -443,8 +441,8 @@ msgstr "Contenu"
#: web/templates/admin/campsite/form.gohtml:70
#: web/templates/admin/campsite/option/form.gohtml:83
#: web/templates/admin/campsite/type/form.gohtml:158
#: web/templates/admin/season/form.gohtml:64
#: web/templates/admin/services/form.gohtml:69
#: web/templates/admin/season/form.gohtml:69
#: web/templates/admin/services/form.gohtml:80
#: web/templates/admin/media/form.gohtml:35
msgctxt "action"
msgid "Update"
@ -457,8 +455,8 @@ msgstr "Mettre à jour"
#: web/templates/admin/campsite/form.gohtml:72
#: web/templates/admin/campsite/option/form.gohtml:85
#: web/templates/admin/campsite/type/form.gohtml:160
#: web/templates/admin/season/form.gohtml:66
#: web/templates/admin/services/form.gohtml:71
#: web/templates/admin/season/form.gohtml:71
#: web/templates/admin/services/form.gohtml:82
msgctxt "action"
msgid "Add"
msgstr "Ajouter"
@ -607,7 +605,7 @@ msgstr "Légende"
#: web/templates/admin/campsite/carousel/index.gohtml:27
#: web/templates/admin/services/index.gohtml:27
#: web/templates/admin/services/index.gohtml:64
#: web/templates/admin/services/index.gohtml:72
#: web/templates/admin/home/index.gohtml:27
msgctxt "header"
msgid "Actions"
@ -621,7 +619,7 @@ msgstr "Êtes-vous sûr de vouloir supprimer cette diapositive ?"
#: web/templates/admin/campsite/carousel/index.gohtml:45
#: web/templates/admin/services/index.gohtml:44
#: web/templates/admin/services/index.gohtml:83
#: web/templates/admin/services/index.gohtml:88
#: web/templates/admin/home/index.gohtml:44
msgctxt "action"
msgid "Delete"
@ -725,13 +723,13 @@ msgstr "Type"
#: web/templates/admin/campsite/index.gohtml:28
#: web/templates/admin/campsite/type/index.gohtml:49
#: web/templates/admin/season/index.gohtml:49
#: web/templates/admin/season/index.gohtml:41
msgid "Yes"
msgstr "Oui"
#: web/templates/admin/campsite/index.gohtml:28
#: web/templates/admin/campsite/type/index.gohtml:49
#: web/templates/admin/season/index.gohtml:49
#: web/templates/admin/season/index.gohtml:41
msgid "No"
msgstr "Non"
@ -788,8 +786,7 @@ msgid "Facilities"
msgstr "Installations"
#: web/templates/admin/campsite/type/form.gohtml:143
#: web/templates/admin/services/form.gohtml:60
#: web/templates/admin/services/l10n.gohtml:32
#: web/templates/admin/services/form.gohtml:65
msgctxt "input"
msgid "Description"
msgstr "Description"
@ -853,12 +850,12 @@ msgid "New Season"
msgstr "Nouvelle saison"
#: web/templates/admin/season/form.gohtml:37
#: web/templates/admin/season/index.gohtml:28
#: web/templates/admin/season/index.gohtml:27
msgctxt "season"
msgid "Active"
msgstr "Actif"
#: web/templates/admin/season/form.gohtml:54
#: web/templates/admin/season/form.gohtml:59
msgctxt "input"
msgid "Color"
msgstr "Couleur"
@ -880,41 +877,10 @@ msgctxt "header"
msgid "Color"
msgstr "Couleur"
#: web/templates/admin/season/index.gohtml:27
#: web/templates/admin/services/index.gohtml:63
msgctxt "header"
msgid "Translations"
msgstr "Traductions"
#: web/templates/admin/season/index.gohtml:56
#: web/templates/admin/season/index.gohtml:48
msgid "No seasons added yet."
msgstr "Aucune saison na encore été ajoutée."
#: web/templates/admin/season/l10n.gohtml:7
#: web/templates/admin/season/l10n.gohtml:14
msgctxt "title"
msgid "Translate Season to %s"
msgstr "Traduire Season en %s"
#: web/templates/admin/season/l10n.gohtml:21
#: web/templates/admin/services/l10n.gohtml:21
#: web/templates/admin/services/l10n.gohtml:33
msgid "Source:"
msgstr "Source :"
#: web/templates/admin/season/l10n.gohtml:23
#: web/templates/admin/services/l10n.gohtml:23
#: web/templates/admin/services/l10n.gohtml:36
msgctxt "input"
msgid "Translation:"
msgstr "Traduction :"
#: web/templates/admin/season/l10n.gohtml:32
#: web/templates/admin/services/l10n.gohtml:45
msgctxt "action"
msgid "Translate"
msgstr "Traduire"
#: web/templates/admin/season/calendar.gohtml:49
#: web/templates/admin/media/picker.gohtml:61
msgctxt "action"
@ -1007,25 +973,24 @@ msgctxt "action"
msgid "Add service"
msgstr "Ajouter un service"
#: web/templates/admin/services/index.gohtml:62
#: web/templates/admin/services/index.gohtml:70
msgctxt "header"
msgid "Order"
msgstr "Ordre"
#: web/templates/admin/services/index.gohtml:71
msgctxt "header"
msgid "Service"
msgstr "Service"
#: web/templates/admin/services/index.gohtml:68
#: web/templates/admin/services/index.gohtml:76
msgid "Are you sure you wish to delete this service?"
msgstr "Êtes-vous sûr de vouloir supprimer ce service ?"
#: web/templates/admin/services/index.gohtml:91
#: web/templates/admin/services/index.gohtml:97
msgid "No services added yet."
msgstr "Aucun service na encore été ajouté."
#: web/templates/admin/services/l10n.gohtml:7
#: web/templates/admin/services/l10n.gohtml:14
msgctxt "title"
msgid "Translate Service to %s"
msgstr "Traduire le service en %s"
#: web/templates/admin/profile.gohtml:6 web/templates/admin/profile.gohtml:12
#: web/templates/admin/layout.gohtml:32
msgctxt "title"
@ -1211,14 +1176,13 @@ msgctxt "title"
msgid "Upload Media"
msgstr "Envoyer un fichier"
#: pkg/legal/admin.go:255 pkg/app/user.go:249 pkg/campsite/types/option.go:344
#: pkg/legal/admin.go:258 pkg/app/user.go:249 pkg/campsite/types/option.go:344
#: pkg/campsite/types/feature.go:259 pkg/campsite/types/admin.go:453
#: pkg/season/l10n.go:69 pkg/season/admin.go:405 pkg/services/l10n.go:73
#: pkg/services/admin.go:266
#: pkg/season/admin.go:415 pkg/services/admin.go:319
msgid "Name can not be empty."
msgstr "Le nom ne peut pas être laissé vide."
#: pkg/legal/admin.go:256 pkg/campsite/types/option.go:345
#: pkg/legal/admin.go:259 pkg/campsite/types/option.go:345
#: pkg/campsite/types/feature.go:260 pkg/campsite/types/admin.go:454
msgid "Name must have at least one letter."
msgstr "Le nom doit comporter au moins une lettre."
@ -1316,7 +1280,7 @@ msgstr "Le prix par nuit doit être un nombre décimal."
msgid "Price per night must be zero or greater."
msgstr "Le prix par nuit doit être égal ou supérieur."
#: pkg/campsite/types/feature.go:258 pkg/services/admin.go:265
#: pkg/campsite/types/feature.go:258 pkg/services/admin.go:318
msgid "Selected icon is not valid."
msgstr "Licône sélectionnée nest pas valide."
@ -1370,92 +1334,92 @@ msgstr "Le type demplacement sélectionné nest pas valide."
msgid "Label can not be empty."
msgstr "L'étiquette ne peut pas être vide."
#: pkg/season/admin.go:222
#: pkg/season/admin.go:186
msgctxt "month"
msgid "January"
msgstr "Janvier"
#: pkg/season/admin.go:223
#: pkg/season/admin.go:187
msgctxt "month"
msgid "February"
msgstr "Février"
#: pkg/season/admin.go:224
#: pkg/season/admin.go:188
msgctxt "month"
msgid "March"
msgstr "Mars"
#: pkg/season/admin.go:225
#: pkg/season/admin.go:189
msgctxt "month"
msgid "April"
msgstr "Avril"
#: pkg/season/admin.go:226
#: pkg/season/admin.go:190
msgctxt "month"
msgid "May"
msgstr "Mai"
#: pkg/season/admin.go:227
#: pkg/season/admin.go:191
msgctxt "month"
msgid "June"
msgstr "Juin"
#: pkg/season/admin.go:228
#: pkg/season/admin.go:192
msgctxt "month"
msgid "July"
msgstr "Juillet"
#: pkg/season/admin.go:229
#: pkg/season/admin.go:193
msgctxt "month"
msgid "August"
msgstr "Août"
#: pkg/season/admin.go:230
#: pkg/season/admin.go:194
msgctxt "month"
msgid "September"
msgstr "Septembre"
#: pkg/season/admin.go:231
#: pkg/season/admin.go:195
msgctxt "month"
msgid "October"
msgstr "Octobre"
#: pkg/season/admin.go:232
#: pkg/season/admin.go:196
msgctxt "month"
msgid "November"
msgstr "Novembre"
#: pkg/season/admin.go:233
#: pkg/season/admin.go:197
msgctxt "month"
msgid "December"
msgstr "Décembre"
#: pkg/season/admin.go:406
#: pkg/season/admin.go:416
msgid "Color can not be empty."
msgstr "La couleur ne peut pas être vide."
#: pkg/season/admin.go:407
#: pkg/season/admin.go:417
msgid "This color is not valid. It must be like #123abc."
msgstr "Cette couleur nest pas valide. Il doit être comme #123abc."
#: pkg/season/admin.go:507
#: pkg/season/admin.go:517
msgctxt "action"
msgid "Unset"
msgstr "Unset"
#: pkg/season/admin.go:538
#: pkg/season/admin.go:548
msgid "Start date can not be empty."
msgstr "La date de début ne peut pas être vide."
#: pkg/season/admin.go:539
#: pkg/season/admin.go:549
msgid "Start date must be a valid date."
msgstr "La date de début doit être une date valide."
#: pkg/season/admin.go:541
#: pkg/season/admin.go:551
msgid "End date can not be empty."
msgstr "La date de fin ne peut pas être vide."
#: pkg/season/admin.go:542
#: pkg/season/admin.go:552
msgid "End date must be a valid date."
msgstr "La date de fin doit être une date valide."
@ -1639,6 +1603,29 @@ msgstr "%s doit être %d ou plus."
msgid "%s must be at most %d."
msgstr "%s doit être tout au plus %d."
#~ msgctxt "header"
#~ msgid "Translations"
#~ msgstr "Traductions"
#~ msgctxt "title"
#~ msgid "Translate Season to %s"
#~ msgstr "Traduire Season en %s"
#~ msgid "Source:"
#~ msgstr "Source :"
#~ msgctxt "input"
#~ msgid "Translation:"
#~ msgstr "Traduction :"
#~ msgctxt "action"
#~ msgid "Translate"
#~ msgstr "Traduire"
#~ msgctxt "title"
#~ msgid "Translate Service to %s"
#~ msgstr "Traduire le service en %s"
#~ msgctxt "title"
#~ msgid "Translate Carousel Slide to %s"
#~ msgstr "Traduire la diapositive Carousel en %s"

View File

@ -0,0 +1,7 @@
-- Revert camper:order_services from pg
begin;
drop function if exists camper.order_services(integer[]);
commit;

View File

@ -0,0 +1,9 @@
-- Revert camper:service__position from pg
begin;
alter table camper.service
drop column if exists position
;
commit;

View File

@ -133,3 +133,5 @@ legal_text_i18n [roles schema_camper legal_text language] 2023-12-21T23:51:09Z j
translate_legal_text [roles schema_camper legal_text_i18n] 2023-12-22T00:10:05Z jordi fita mas <jordi@tandem.blog> # Add function to translate legal texts
@v0 2024-01-12T18:16:37Z jordi fita mas <jordi@tandem.blog> # Version 0
add_services_carousel_slide [add_services_carousel_slide@v0] 2024-01-12T18:17:33Z jordi fita mas <jordi@tandem.blog> # Change add_services_carousel_slides return type from void to integer
service__position [service] 2024-01-12T23:47:29Z jordi fita mas <jordi@tandem.blog> # Add position column to service
order_services [schema_camper roles service service__position] 2024-01-12T23:52:24Z jordi fita mas <jordi@tandem.blog> # Add function to order services

60
test/order_services.sql Normal file
View File

@ -0,0 +1,60 @@
-- Test order_services
set client_min_messages to warning;
create extension if not exists pgtap;
reset client_min_messages;
begin;
select plan(11);
set search_path to camper, public;
select has_function('camper', 'order_services', array['integer[]']);
select function_lang_is('camper', 'order_services', array['integer[]'], 'sql');
select function_returns('camper', 'order_services', array['integer[]'], 'void');
select isnt_definer('camper', 'order_services', array['integer[]']);
select volatility_is('camper', 'order_services', array['integer[]'], 'volatile');
select function_privs_are('camper', 'order_services', array ['integer[]'], 'guest', array[]::text[]);
select function_privs_are('camper', 'order_services', array ['integer[]'], 'employee', array[]::text[]);
select function_privs_are('camper', 'order_services', array ['integer[]'], 'admin', array['EXECUTE']);
select function_privs_are('camper', 'order_services', array ['integer[]'], 'authenticator', array[]::text[]);
set client_min_messages to warning;
truncate service cascade;
truncate company cascade;
reset client_min_messages;
insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, rtc_number, country_code, currency_code, default_lang_tag)
values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', '', 'ES', 'EUR', 'ca')
;
insert into service (service_id, company_id, icon_name, name, description)
values (4, 1, 'baby', '1', '<p>a</p>')
, (5, 1, 'nopet', '2', '<p>b</p>')
, (6, 1, 'castle', '3', '<p>c</p>')
, (7, 1, 'area', '4', '<p>d</p>')
, (8, 1, 'campfire', '5', '<p>e</p>')
;
select lives_ok(
$$ select order_services('{6,8,7,4,5}') $$,
'Should be able to sort services using their ID'
);
select bag_eq(
$$ select service_id, position from service $$,
$$ values (6, 1)
, (8, 2)
, (7, 3)
, (4, 4)
, (5, 5)
$$,
'Should have sorted all services.'
);
select *
from finish();
rollback;

View File

@ -5,7 +5,7 @@ reset client_min_messages;
begin;
select plan(45);
select plan(50);
set search_path to camper, public;
@ -46,6 +46,12 @@ select col_type_is('service', 'description', 'xml');
select col_not_null('service', 'description');
select col_hasnt_default('service', 'description');
select has_column('service', 'position');
select col_type_is('service', 'position', 'integer');
select col_not_null('service', 'position');
select col_has_default('service', 'position');
select col_default_is('service', 'position', '2147483647');
set client_min_messages to warning;
truncate service cascade;

View File

@ -0,0 +1,7 @@
-- Verify camper:order_services on pg
begin;
select has_function_privilege('camper.order_services(integer[])', 'execute');
rollback;

View File

@ -0,0 +1,10 @@
-- Verify camper:service__position on pg
begin;
select position
from camper.service
where false
;
rollback;

View File

@ -56,29 +56,43 @@
<h2>{{( pgettext "Services" "title" )}}</h2>
<a href="/admin/services/new">{{( pgettext "Add service" "action" )}}</a>
{{ if .Services -}}
<table class="services">
<thead>
<tr>
<th scope="col">{{( pgettext "Service" "header" )}}</th>
<th scope="col">{{( pgettext "Actions" "header" )}}</th>
</tr>
</thead>
<tbody>
{{ $confirm := ( gettext "Are you sure you wish to delete this service?" )}}
{{ range .Services -}}
<form id="service-index"
class="sortable"
data-hx-post="/admin/services/order"
data-hx-trigger="end"
data-hx-select="#service-index"
data-hx-swap="outerHTML"
>
{{ CSRFInput }}
<table class="services">
<thead>
<tr>
<td class="icon_{{ .Icon }}"><a href="{{ .URL }}">{{ .Name }}</a></td>
<td>
<form data-hx-delete="{{ .URL }}"
data-hx-confirm="{{ $confirm }}"
data-hx-headers='{ {{ CSRFHeader }} }'>
<button type="submit">{{( pgettext "Delete" "action" )}}</button>
</form>
</td>
<th scope="col" class="sr-only">{{( pgettext "Order" "header" )}}</th>
<th scope="col">{{( pgettext "Service" "header" )}}</th>
<th scope="col">{{( pgettext "Actions" "header" )}}</th>
</tr>
{{- end }}
</tbody>
</table>
</thead>
<tbody>
{{ $confirm := ( gettext "Are you sure you wish to delete this service?" )}}
{{ range .Services -}}
<tr>
<td>
<input type="hidden" name="service_id" value="{{ .ID }}">
<span class="handle"></span>
</td>
<td class="icon_{{ .Icon }}"><a href="{{ .URL }}">{{ .Name }}</a></td>
<td>
<form data-hx-delete="{{ .URL }}"
data-hx-confirm="{{ $confirm }}"
data-hx-headers='{ {{ CSRFHeader }} }'>
<button type="submit">{{( pgettext "Delete" "action" )}}</button>
</form>
</td>
</tr>
{{- end }}
</tbody>
</table>
</form>
{{ else -}}
<p>{{( gettext "No services added yet." )}}</p>
{{- end }}