Skip to content

Commit

Permalink
feat:c2corg#3936 selecting starting and ending waypoints for a route
Browse files Browse the repository at this point in the history
- Starting points and ending points can be selected using a document input
  - They are stored in route specific field because the generic data structure isn't made to have specific information in a route-waypoint association
  - The entire waypoint object is stored in order to use it easily
  - Ending waypoints are always available in order to avoid back and forth with activity type
  - Only access waypoints are displayed
      - Fhe filter is done after the research
      - Possible improvement: add a filter on the api call
- All waypoints (start, end and intermediate) are still stored in document's waypoints attribute
  - In order to avoid any data/api breaking changes
- Allow waypoint suppression directly from associationInputRow
  • Loading branch information
Nayor committed May 6, 2024
1 parent 58c88cf commit 3d9325a
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 16 deletions.
10 changes: 8 additions & 2 deletions src/components/generics/inputs/InputDocument.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{{ $gettext(type + 's') | uppercaseFirstLetter }}
</div>
<div
v-for="document of promise.data[type + 's'].documents"
v-for="document of promise.data[type + 's'].documents.filter(optionsFilter)"
:key="document.document_id"
@mousedown="toggle(document)"
class="dropdown-item dropdown-item-option columns is-gapless has-cursor-pointer"
Expand Down Expand Up @@ -134,6 +134,10 @@ export default {
type: Boolean,
default: false,
},
optionsFilter: {
type: Function,
default: (doc) => doc,
},
},
data() {
Expand Down Expand Up @@ -162,7 +166,9 @@ export default {
documentTypesWithResults() {
const result = this.promise.data;
return this.documentTypes_.filter((type) => result[type + 's'] && result[type + 's'].documents.length !== 0);
return this.documentTypes_.filter(
(type) => result[type + 's'] && result[type + 's'].documents.filter(this.optionsFilter).length !== 0
);
},
letterTypes() {
Expand Down
5 changes: 5 additions & 0 deletions src/js/associations-rights-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ export default {
return child.author.user_id === this.$user.id;
}

// technical limitation, a route should at least have one waypoint
if (child.type === 'w' && (parent.type !== 'r' || parent.associations.waypoints?.length > 1)) {
return true;
}

return false;
},
},
Expand Down
2 changes: 2 additions & 0 deletions src/js/constants/documentsProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@
]
}
},
{ "id": "ending_waypoints" },
{
"id": "engagement_rating",
"properties": {
Expand Down Expand Up @@ -501,6 +502,7 @@
}
},
{ "id": "route_types", "properties": { "url": "rtyp" } },
{ "id": "starting_waypoints" },
{ "id": "ski_exposition", "properties": { "url": "sexpo", "activities": ["skitouring"] } },
{ "id": "ski_rating", "properties": { "url": "trat", "activities": ["skitouring"] } },
{ "id": "slackline_height", "properties": { "activities": ["slacklining"] } },
Expand Down
2 changes: 2 additions & 0 deletions src/translations/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@
"quality_types": "buit"
},
"empty comment": "comentari buit",
"ending waypoints": "punts d'arribada",
"en": {
"langs": "anglès"
},
Expand Down Expand Up @@ -1612,6 +1613,7 @@
"stone_ice_fall": {
"event_types": "caiguda de pedra/glaç/serac"
},
"starting waypoints": "punts de partida",
"stories": {
"article_categories": "narracions"
},
Expand Down
2 changes: 2 additions & 0 deletions src/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@
"quality_types": "leer"
},
"empty comment": "leerer Kommentar",
"ending waypoints": "ankunftsorte",
"en": {
"langs": "englisch"
},
Expand Down Expand Up @@ -1906,6 +1907,7 @@
"stories": {
"article_categories": "Geschichten"
},
"starting waypoints": "startpunkte",
"strava": "Strava",
"strong text": "fetter Text",
"summary": "Überblick",
Expand Down
2 changes: 2 additions & 0 deletions src/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@
"quality_types": "vacío"
},
"empty comment": "comentario vacío",
"ending waypoints": "puntos de llegada",
"en": {
"langs": "inglés"
},
Expand Down Expand Up @@ -1460,6 +1461,7 @@
"stories": {
"article_categories": "historias"
},
"starting waypoints": "puntos de salida",
"strava": "Strava",
"summary": "Resumen",
"summit": {
Expand Down
2 changes: 2 additions & 0 deletions src/translations/eu.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@
"empty": {
"quality_types": "hutsa"
},
"ending waypoints": "iristeko puntuak",
"en": {
"langs": "ingelesa"
},
Expand Down Expand Up @@ -874,6 +875,7 @@
"stories": {
"article_categories": "kontakizuna"
},
"starting waypoints": "abia puntuak",
"strava": "Strava",
"summary": "laburpena",
"summit": {
Expand Down
4 changes: 3 additions & 1 deletion src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
"Extent": "Couverture",
"FAQ?": "FAQ ?",
"Fauna protection areas": "Faune",
"Fauna protection site:": "Site de protection de la faune :",
"Fauna protection site:": "Site de protection de la faune :",
"Feel free to edit it.": "Éditez-le.",
"Filter on map extent": "Limiter la recherche à la carte visible",
"Filter results": "Filtrer",
Expand Down Expand Up @@ -1032,6 +1032,7 @@
"quality_types": "vide"
},
"empty comment": "commentaire vide",
"ending waypoints": "points d'arrivée",
"en": {
"langs": "anglais"
},
Expand Down Expand Up @@ -1717,6 +1718,7 @@
"stone_ice_fall": {
"event_types": "chute de pierre/glace/serac"
},
"starting waypoints": "points de départ",
"stories": {
"article_categories": "récits"
},
Expand Down
5 changes: 5 additions & 0 deletions src/translations/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,11 @@
"quality_types": "üres"
},
"empty comment": "üres megjegyzés",
"ending waypoints": "érkezési pontok",
"engagement_rating": "elkötelezettség_besorolás",
"en": {
"langs": "angol"
},
"environment": {
"book_types": "környezet"
},
Expand Down Expand Up @@ -1582,6 +1586,7 @@
"stories": {
"article_categories": "történetek"
},
"starting waypoints": "indulási pontok",
"strava": "Strava",
"strong text": "hangsúlyos szöveg",
"summary": "összefoglaló",
Expand Down
2 changes: 2 additions & 0 deletions src/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,7 @@
"quality_types": "vuoto"
},
"empty comment": "commento vuoto",
"ending waypoints": "punti di arrivo",
"en": {
"langs": "inglese"
},
Expand Down Expand Up @@ -1775,6 +1776,7 @@
"stories": {
"article_categories": "racconti"
},
"starting waypoints": "punti di partenza",
"strava": "Strava",
"strong text": "testo in grassetto ",
"summary": "Riassunto",
Expand Down
2 changes: 2 additions & 0 deletions src/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@
"quality_types": "пустой"
},
"empty comment": "пустой комментарий",
"ending waypoints": "пункты прибытия",
"en": {
"langs": "английский"
},
Expand Down Expand Up @@ -1079,6 +1080,7 @@
"stories": {
"article_categories": "рассказы"
},
"starting waypoints": "пункты отправления",
"strava": "Strava",
"suunto": "Suunto",
"tags": {
Expand Down
2 changes: 2 additions & 0 deletions src/translations/sl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,7 @@
"quality_types": "prazno"
},
"empty comment": "prazni komentar",
"ending waypoints": "točke prihoda",
"en": {
"langs": "angleščina"
},
Expand Down Expand Up @@ -1826,6 +1827,7 @@
"stories": {
"article_categories": "zgodbe"
},
"starting waypoints": "točke odhoda",
"strava": "Strava",
"strong text": "krepko besedilo",
"summary": "Povzetek",
Expand Down
2 changes: 2 additions & 0 deletions src/translations/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,7 @@
"quality_types": "空白"
},
"empty comment": "空白评论",
"ending waypoints": "到达点",
"en": {
"langs": "English"
},
Expand Down Expand Up @@ -1833,6 +1834,7 @@
"stories": {
"article_categories": "故事"
},
"starting waypoints": "起点",
"strava": "Strava",
"strong text": "加粗字体",
"summary": "总结",
Expand Down
51 changes: 50 additions & 1 deletion src/views/wiki/edition/RouteEditionView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,27 @@

<map-input-row :document="document" geom-detail-editable ref="map" />

<associations-input-row :document="document" :field="fields.waypoints" />
<associations-input-row
:document="document"
:field="fields.waypoints"
:label="$gettext('starting waypoints')"
@add="document.starting_waypoints.push(arguments[0])"
:options-filter="filterAccessWaypoints"
:cards-filter="filterStartingWaypoints"
/>
<associations-input-row
:document="document"
:field="fields.waypoints"
:cards-filter="filterIntermediateWaypoints"
/>
<associations-input-row
:document="document"
:field="fields.waypoints"
:label="$gettext('ending waypoints')"
@add="document.ending_waypoints.push(arguments[0])"
:options-filter="filterAccessWaypoints"
:cards-filter="filterEndingWaypoints"
/>
<associations-input-row :document="document" :field="fields.routes" />
<associations-input-row :document="document" :field="fields.articles" />
<associations-input-row :document="document" :field="fields.books" />
Expand Down Expand Up @@ -209,6 +229,8 @@ export default {
if (this.mode === 'add' && this.$route.query.w) {
this.document.main_waypoint_id = parseInt(this.$route.query.w);
}
this.document.starting_waypoints = []; // TODO waiting for api upgrade, remove before merging
this.document.ending_waypoints = []; // TODO waiting for api upgrade, remove before merging
},
beforeSave() {
Expand Down Expand Up @@ -239,6 +261,14 @@ export default {
this.document.main_waypoint_id = null;
}
// clear removed waypoints
this.document.starting_waypoints = this.document.starting_waypoints.filter(
(waypoint) => waypoints.findIndex((doc) => doc.document_id === waypoint.document_id) !== -1
);
this.document.ending_waypoints = this.document.ending_waypoints.filter(
(waypoint) => waypoints.findIndex((doc) => doc.document_id === waypoint.document_id) !== -1
);
// on creation mode, if main waypoint is null, and some waypoints are associated, take the first
if (this.mode === 'add' && this.document.main_waypoint_id === null && waypoints.length !== 0) {
this.document.main_waypoint_id = waypoints[0].document_id;
Expand All @@ -258,6 +288,25 @@ export default {
this.fields.rock_free_rating.values = ratings.map((grade) => grade.toLowerCase());
}
},
filterAccessWaypoints(doc) {
return doc.waypoint_type && doc.waypoint_type === 'access';
},
filterStartingWaypoints(waypoint) {
return this.$documentUtils.isInArray(this.document.starting_waypoints, waypoint);
},
filterIntermediateWaypoints(waypoint) {
return (
!this.$documentUtils.isInArray(this.document.starting_waypoints, waypoint) &&
!this.$documentUtils.isInArray(this.document.ending_waypoints, waypoint)
);
},
filterEndingWaypoints(waypoint) {
return this.$documentUtils.isInArray(this.document.ending_waypoints, waypoint);
},
},
};
</script>
39 changes: 29 additions & 10 deletions src/views/wiki/edition/utils/AssociationsInputRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@
</label>
</div>
<div class="column is-narrow">
<form-input class="is-expanded" ref="input" :document="document" :field="field" />
<form-input
class="is-expanded"
ref="input"
:document="document"
:field="field"
@add="$emit('add', arguments[0])"
:options-filter="optionsFilter"
/>
</div>
</div>
<div class="columns is-multiline">
<div v-for="child in document.associations[field.name]" :key="child.document_id" class="column is-4">
<document-card
:document="child"
:show-delete-button="showDeleteButton(child)"
@delete="$documentUtils.removeAssociation(document, child)"
target="_blank"
/>
</div>
<template v-for="child in document.associations[field.name]">
<div v-if="cardsFilter(child)" :key="child.document_id" class="column is-4">
<document-card
:document="child"
:show-delete-button="showDeleteButton(child)"
@delete="$documentUtils.removeAssociation(document, child)"
target="_blank"
/>
</div>
</template>
</div>
</div>
</template>
Expand Down Expand Up @@ -47,6 +56,16 @@ export default {
type: String,
default: undefined, // default must be undefined. null means explicit no helper
},
cardsFilter: {
type: Function,
default: () => true,
},
optionsFilter: {
type: Function,
default: (doc) => doc,
},
},
computed: {
Expand All @@ -60,7 +79,7 @@ export default {
methods: {
showDeleteButton(document) {
return this.canRemove(this.document, document); // ! FIXME import mixin
return this.canRemove(this.document, document);
},
},
};
Expand Down
Loading

0 comments on commit 3d9325a

Please sign in to comment.