Skip to content

Commit

Permalink
When main waypoint is missing, take the first associated waypoint #759
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeauchesne committed Aug 21, 2019
1 parent 7b0f25f commit 7bb3069
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/views/wiki/edition/RouteEditionView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,30 @@
export default {
mixins: [ documentEditionViewMixin ],
watch: {
'document.associations.waypoints': 'onWaypointsAssociation'
},
methods: {
afterLoad() {
// on creation from a waypoint, set this waypoint as main
if (this.mode === 'add' && this.$route.query.w) {
this.document.main_waypoint_id = parseInt(this.$route.query.w);
}
},
onWaypointsAssociation() {
const waypoints = this.document.associations.waypoints;
// clean main waypoint if it is missing from associated waypoints
if (waypoints.findIndex(doc => doc.document_id === this.document.main_waypoint_id) === -1) {
this.document.main_waypoint_id = null;
}
// if main waypoint is null, and some waypoints are associated, take the first
if (this.document.main_waypoint_id === null && waypoints.length !== 0) {
this.document.main_waypoint_id = waypoints[0].document_id;
}
}
}
};
Expand Down

0 comments on commit 7bb3069

Please sign in to comment.