Skip to content

Commit

Permalink
feat(endpoint-posts): event post fields
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Jan 14, 2024
1 parent d126e61 commit 9e4158f
Show file tree
Hide file tree
Showing 18 changed files with 445 additions and 21 deletions.
1 change: 1 addition & 0 deletions packages/endpoint-posts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class PostsEndpoint {
"reply",
"like",
"photo",
"event",
"rsvp",
"repost",
"video",
Expand Down
7 changes: 3 additions & 4 deletions packages/endpoint-posts/lib/controllers/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ export const formController = {
}
}

// Convert geo value to object
if (values.geo) {
values.location = getLocationProperty(values.geo);
delete values.geo;
// Derive location from location and/or geo values
if (values.location || values.geo) {
values.location = getLocationProperty(values);
}

// Delete empty values
Expand Down
8 changes: 3 additions & 5 deletions packages/endpoint-posts/lib/middleware/post-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from "node:path";
import { IndiekitError } from "@indiekit/error";
import { statusTypes } from "../status-types.js";
import {
getGeoValue,
getPostName,
getPostProperties,
getPostTypeName,
Expand Down Expand Up @@ -56,11 +57,8 @@ export const postData = {
throw IndiekitError.notFound(response.locals.__("NotFoundError.page"));
}

if (properties.location) {
properties.geo = [
properties.location.latitude,
properties.location.longitude,
].toString();
if (properties.location.geo) {
properties.geo = getGeoValue(properties.geo);
}

const postType = properties["post-type"];
Expand Down
7 changes: 6 additions & 1 deletion packages/endpoint-posts/lib/middleware/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ export const validate = [
.if(
(value, { req }) =>
req.body?.["post-type"] === "article" ||
req.body?.["post-type"] === "bookmark",
req.body?.["post-type"] === "bookmark" ||
req.body?.["post-type"] === "event",
)
.notEmpty()
.withMessage((value, { req, path }) => req.__(`posts.error.${path}.empty`)),
check("start")
.if((value, { req }) => req.body?.["post-type"] === "event")
.notEmpty()
.withMessage((value, { req, path }) => req.__(`posts.error.${path}.empty`)),
check("content")
.if(
(value, { req }) =>
Expand Down
52 changes: 47 additions & 5 deletions packages/endpoint-posts/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,65 @@ export const LAT_LONG_RE =
/^(?<latitude>(?:-?|\+?)?\d+(?:\.\d+)?),\s*(?<longitude>(?:-?|\+?)?\d+(?:\.\d+)?)$/;

/**
* Get location property
* Get geographic coordinates property
* @param {string} geo - Latitude and longitude, comma separated
* @returns {object} JF2 location property
* @returns {object} JF2 geo location property
*/
export const getLocationProperty = (geo) => {
export const getGeoProperty = (geo) => {
const { latitude, longitude } = geo.match(LAT_LONG_RE).groups;

return {
type: "geo",
latitude,
longitude,
name: formatcoords(geo).format({
decimalPlaces: 2,
}),
latitude: Number(latitude),
longitude: Number(longitude),
};
};

/**
* Get comma separated geographic coordinates
* @param {object} geo - JF2 geo location property
* @returns {string} Latitude and longitude, comma separated
*/
export const getGeoValue = (geo) => {
return [geo.latitude, geo.longitude].toString();
};

/**
* Get location property
* @param {object} values - Latitude and longitude, comma separated
* @returns {object} JF2 location property
*/
export const getLocationProperty = (values) => {
const { location, geo } = values;

// Determine Microformat type
if (location && location.name) {
location.type = "card";
} else if (location) {
location.type = "adr";
}

// Add (or use) any provided geo location properties
if (location && geo) {
location.geo = getGeoProperty(geo);
} else if (geo) {
return getGeoProperty(geo);
}

// Delete empty values
for (const key in location) {
const noValue = !location[key] || location[key] === "";
if (Object.prototype.hasOwnProperty.call(location, key) && noValue) {
delete location[key];
}
}

return location;
};

/**
* Get post status badges
* @param {object} post - Post
Expand Down
17 changes: 17 additions & 0 deletions packages/endpoint-posts/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"name": {
"empty": "Titel eingeben"
},
"start": {
"empty": "Geben Sie ein Startdatum ein"
},
"url": {
"empty": "Geben Sie eine Webadresse wie %s"
}
Expand All @@ -50,6 +53,12 @@
"label": "Inhalt"
},
"continue": "Fortsetzen",
"event": {
"all-day": "Ganztägig",
"end": "Endet",
"label": "Datum und Uhrzeit",
"start": "Beginnt"
},
"geo": {
"hint": "Breitengrad und Längengrad, zum Beispiel %s",
"label": "Koordinaten des Standorts"
Expand All @@ -60,6 +69,14 @@
"like-of": {
"label": "Wie von"
},
"location": {
"country-name": "Land",
"label": "Standort",
"locality": "Stadt oder Ort",
"name": "Veranstaltungsort",
"postal-code": "Postleitzahl",
"street-address": "Straße"
},
"media": {
"label": "Dateipfad oder URL"
},
Expand Down
17 changes: 17 additions & 0 deletions packages/endpoint-posts/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"name": {
"empty": "Enter a title"
},
"start": {
"empty": "Enter a start date"
},
"url": {
"empty": "Enter a web address like %s"
},
Expand Down Expand Up @@ -75,6 +78,12 @@
"content": {
"label": "Content"
},
"event": {
"label": "Date and time",
"start": "Starts",
"end": "Ends",
"all-day": "All-day"
},
"geo": {
"label": "Location coordinates",
"hint": "Latitude and longitude, for example %s"
Expand All @@ -85,6 +94,14 @@
"like-of": {
"label": "Like of"
},
"location": {
"label": "Location",
"name": "Venue",
"street-address": "Street address",
"locality": "City or town",
"country-name": "Country",
"postal-code": "Postal code"
},
"name": {
"label": "Title"
},
Expand Down
17 changes: 17 additions & 0 deletions packages/endpoint-posts/locales/es-419.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"name": {
"empty": "Ingresar un título"
},
"start": {
"empty": "Introduce una fecha de inicio"
},
"url": {
"empty": "Introducir una dirección web como %s"
}
Expand All @@ -50,6 +53,12 @@
"label": "Contenido"
},
"continue": "Continuar",
"event": {
"all-day": "Todo el día",
"end": "Termina",
"label": "Fecha y hora",
"start": "Comienza"
},
"geo": {
"hint": "Latitud y longitud, por ejemplo %s",
"label": "Coordenadas de ubicación"
Expand All @@ -60,6 +69,14 @@
"like-of": {
"label": "Como de"
},
"location": {
"country-name": "País",
"label": "Ubicación",
"locality": "Ciudad o pueblo",
"name": "Lugar de eventos",
"postal-code": "Código postal",
"street-address": "Dirección de la calle"
},
"media": {
"label": "Ruta o URL del archivo"
},
Expand Down
17 changes: 17 additions & 0 deletions packages/endpoint-posts/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"name": {
"empty": "Pon un título"
},
"start": {
"empty": "Introduce una fecha de inicio"
},
"url": {
"empty": "Introduce una dirección web como %s"
}
Expand All @@ -50,6 +53,12 @@
"label": "Contenido"
},
"continue": "Continuar",
"event": {
"all-day": "Todo el día",
"end": "Termina",
"label": "Fecha y hora",
"start": "Comienza"
},
"geo": {
"hint": "Latitud y longitud, por ejemplo %s",
"label": "Coordenadas de ubicación"
Expand All @@ -60,6 +69,14 @@
"like-of": {
"label": "Como de"
},
"location": {
"country-name": "País",
"label": "Ubicación",
"locality": "Ciudad o pueblo",
"name": "Campo",
"postal-code": "Código postal",
"street-address": "Dirección"
},
"media": {
"label": "Ruta o URL del archivo"
},
Expand Down
17 changes: 17 additions & 0 deletions packages/endpoint-posts/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"name": {
"empty": "Saisir un titre"
},
"start": {
"empty": "Entrez la date de début"
},
"url": {
"empty": "Saisir une adresse Web telle que %s"
}
Expand All @@ -50,6 +53,12 @@
"label": "Contenu"
},
"continue": "Continuer",
"event": {
"all-day": "Toute la journée",
"end": "Fin",
"label": "Date et heure",
"start": "Commence"
},
"geo": {
"hint": "Latitude et longitude, par exemple %s",
"label": "Coordonnées de localisation"
Expand All @@ -60,6 +69,14 @@
"like-of": {
"label": "J’aime"
},
"location": {
"country-name": "Pays",
"label": "Localisation",
"locality": "Ville",
"name": "Lieu",
"postal-code": "Code postal",
"street-address": "Adresse"
},
"media": {
"label": "Chemin du fichier ou URL"
},
Expand Down
17 changes: 17 additions & 0 deletions packages/endpoint-posts/locales/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"name": {
"empty": "Masukkan judul"
},
"start": {
"empty": "Masukkan tanggal mulai"
},
"url": {
"empty": "Masukkan alamat web misalnya %s"
}
Expand All @@ -50,6 +53,12 @@
"label": "Konten"
},
"continue": "Lanjutkan",
"event": {
"all-day": "Sepanjang hari",
"end": "Berakhir",
"label": "Tanggal dan waktu",
"start": "Mulai"
},
"geo": {
"hint": "Lintang dan bujur, misalnya %s",
"label": "Koordinat lokasi"
Expand All @@ -60,6 +69,14 @@
"like-of": {
"label": "Seperti"
},
"location": {
"country-name": "Negara",
"label": "Lokasi",
"locality": "Kota",
"name": "Tempat",
"postal-code": "Kode pos",
"street-address": "Alamat jalan"
},
"media": {
"label": "Jalur file atau URL"
},
Expand Down
17 changes: 17 additions & 0 deletions packages/endpoint-posts/locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"name": {
"empty": "Geef een titel in"
},
"start": {
"empty": "Voer een startdatum in"
},
"url": {
"empty": "Voer een webadres in zoals %s"
}
Expand All @@ -50,6 +53,12 @@
"label": "Inhoud"
},
"continue": "Doorgaan",
"event": {
"all-day": "Hele dag",
"end": "Eindigt",
"label": "Datum en tijd",
"start": "Begint"
},
"geo": {
"hint": "Lengte- en breedtegraad, bijvoorbeeld %s",
"label": "Locatiecoördinaten"
Expand All @@ -60,6 +69,14 @@
"like-of": {
"label": "Zoals van"
},
"location": {
"country-name": "Land",
"label": "Locatie",
"locality": "Stad",
"name": "Plaats",
"postal-code": "Postcode",
"street-address": "Adres"
},
"media": {
"label": "Bestandspad of URL"
},
Expand Down
Loading

0 comments on commit 9e4158f

Please sign in to comment.