From 27add0f8a406b98e4060a7081a58c84dc359519f Mon Sep 17 00:00:00 2001 From: Emma Hegarty Date: Thu, 23 May 2024 16:12:14 +0200 Subject: [PATCH] wip: save job properties to AppRouteData --- .../components/optimization/optimization.js | 47 ++++++++++++------- src/models/place.js | 6 +++ 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/fragments/forms/map-form/components/optimization/optimization.js b/src/fragments/forms/map-form/components/optimization/optimization.js index b1b3b43ed..2245612ff 100644 --- a/src/fragments/forms/map-form/components/optimization/optimization.js +++ b/src/fragments/forms/map-form/components/optimization/optimization.js @@ -8,6 +8,7 @@ import AppMode from '@/support/app-modes/app-mode' import MapViewData from '@/models/map-view-data' import constants from '@/resources/constants' import appConfig from '@/config/app-config' +import Place from '@/models/place' import Job from '@/models/job' import Vehicle from '@/models/vehicle' import Skill from '@/models/skill' @@ -345,19 +346,35 @@ export default { * url synchronized with the current map status */ updateAppRoute () { - let localCoords = this.jobs.map(j => j.coordinates) - const appRouteData = this.$store.getters.appRouteData - let urlCoords = appRouteData.places.map(urlJ => urlJ.coordinates) - if (JSON.stringify(localCoords) !== JSON.stringify(urlCoords) || JSON.stringify(this.vehiclesJSON) !== JSON.stringify(appRouteData.options.vehicles)) { - const jobs = this.jobs - const vehicles = this.vehiclesJSON - this.$store.commit('mode', constants.modes.optimization) - const appMode = new AppMode(this.$store.getters.mode) - const route = appMode.getRoute(jobs, {vehicles: vehicles}) - if (Object.keys(route.params).length > 1) {// params contains data and placeName? props - this.$router.push(route) + this.$store.commit('mode', constants.modes.optimization) + const appMode = new AppMode(this.$store.getters.mode) + let jobLocations = [] + let jobProps = [] + for (const job of this.jobs) { + jobLocations.push(Place.fromJob(job)) + jobProps.push(this.getPropsFromJob(job)) + } + const route = appMode.getRoute(jobLocations, {vehicles: this.vehiclesJSON, jobProps: jobProps}) + if (Object.keys(route.params).length > 1) {// params contains data and placeName? props + this.$router.push(route) + } + }, + getPropsFromJob (job) { + let jobProps = {id: job.id} + if (job.skills.length) { + let skillIds = [] + for (const skill of job.skills) { + skillIds.push(skill.id) + } + skillIds.sort() + jobProps.skills = skillIds + } + for (const prop of ['service', 'priority', 'delivery', 'pickup', 'time_windows']) { + if (job[prop].length) { + jobProps[prop] = job[prop] } } + return jobProps }, /** * Request and draw a route based on the value of multiples places input @@ -439,9 +456,9 @@ export default { // object reference because it is a prop const defaultJobs = this.jobs const defaultVehicles = this.vehicles - this.jobs = this.$store.getters.appRouteData.jobs + const jobProps = this.$store.getters.appRouteData.options.jobProps const urlVehicles = this.$store.getters.appRouteData.options.vehicles - let places = this.$store.getters.appRouteData.places + const places = this.$store.getters.appRouteData.places let storedJobs = localStorage.getItem('jobs') let storedVehicles = localStorage.getItem('vehicles') // prioritise data from url, then data from local storage @@ -463,9 +480,7 @@ export default { const jobs = [] if (places.length > 0) { for (const [i, place] of places.entries()) { - const job = Job.fromPlace(place) - job.setId(i + 1) - jobs.push(job) + jobs.push(new Job(place.lng, place.lat, place.placeName, jobProps[i])) } } else if (this.jobs === undefined && storedJobs) { for (const job of JSON.parse(storedJobs)) { diff --git a/src/models/place.js b/src/models/place.js index 5d4ba48d2..3f1e6f47a 100644 --- a/src/models/place.js +++ b/src/models/place.js @@ -221,6 +221,12 @@ class Place { }) } + static fromJob(job) { + return new Place(job.location[0], job.location[1], '', { + placeId: job.id + }) + } + /** * Get place models that are filled * @returns {Array} of filled places