Skip to content

Commit

Permalink
wip: save job properties to AppRouteData
Browse files Browse the repository at this point in the history
  • Loading branch information
blackbirdem committed May 23, 2024
1 parent 499b324 commit 27add0f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)) {
Expand Down
6 changes: 6 additions & 0 deletions src/models/place.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 27add0f

Please sign in to comment.