@@ -8,6 +8,7 @@ import AppMode from '@/support/app-modes/app-mode'
88import MapViewData from '@/models/map-view-data'
99import constants from '@/resources/constants'
1010import appConfig from '@/config/app-config'
11+ import Place from '@/models/place'
1112import Job from '@/models/job'
1213import Vehicle from '@/models/vehicle'
1314import Skill from '@/models/skill'
@@ -345,19 +346,35 @@ export default {
345346 * url synchronized with the current map status
346347 */
347348 updateAppRoute ( ) {
348- let localCoords = this . jobs . map ( j => j . coordinates )
349- const appRouteData = this . $store . getters . appRouteData
350- let urlCoords = appRouteData . places . map ( urlJ => urlJ . coordinates )
351- if ( JSON . stringify ( localCoords ) !== JSON . stringify ( urlCoords ) || JSON . stringify ( this . vehiclesJSON ) !== JSON . stringify ( appRouteData . options . vehicles ) ) {
352- const jobs = this . jobs
353- const vehicles = this . vehiclesJSON
354- this . $store . commit ( 'mode' , constants . modes . optimization )
355- const appMode = new AppMode ( this . $store . getters . mode )
356- const route = appMode . getRoute ( jobs , { vehicles : vehicles } )
357- if ( Object . keys ( route . params ) . length > 1 ) { // params contains data and placeName? props
358- this . $router . push ( route )
349+ this . $store . commit ( 'mode' , constants . modes . optimization )
350+ const appMode = new AppMode ( this . $store . getters . mode )
351+ let jobLocations = [ ]
352+ let jobProps = [ ]
353+ for ( const job of this . jobs ) {
354+ jobLocations . push ( Place . fromJob ( job ) )
355+ jobProps . push ( this . getPropsFromJob ( job ) )
356+ }
357+ const route = appMode . getRoute ( jobLocations , { vehicles : this . vehiclesJSON , jobProps : jobProps } )
358+ if ( Object . keys ( route . params ) . length > 1 ) { // params contains data and placeName? props
359+ this . $router . push ( route )
360+ }
361+ } ,
362+ getPropsFromJob ( job ) {
363+ let jobProps = { id : job . id }
364+ if ( job . skills . length ) {
365+ let skillIds = [ ]
366+ for ( const skill of job . skills ) {
367+ skillIds . push ( skill . id )
368+ }
369+ skillIds . sort ( )
370+ jobProps . skills = skillIds
371+ }
372+ for ( const prop of [ 'service' , 'priority' , 'delivery' , 'pickup' , 'time_windows' ] ) {
373+ if ( job [ prop ] . length ) {
374+ jobProps [ prop ] = job [ prop ]
359375 }
360376 }
377+ return jobProps
361378 } ,
362379 /**
363380 * Request and draw a route based on the value of multiples places input
@@ -439,9 +456,9 @@ export default {
439456 // object reference because it is a prop
440457 const defaultJobs = this . jobs
441458 const defaultVehicles = this . vehicles
442- this . jobs = this . $store . getters . appRouteData . jobs
459+ const jobProps = this . $store . getters . appRouteData . options . jobProps
443460 const urlVehicles = this . $store . getters . appRouteData . options . vehicles
444- let places = this . $store . getters . appRouteData . places
461+ const places = this . $store . getters . appRouteData . places
445462 let storedJobs = localStorage . getItem ( 'jobs' )
446463 let storedVehicles = localStorage . getItem ( 'vehicles' )
447464 // prioritise data from url, then data from local storage
@@ -463,9 +480,7 @@ export default {
463480 const jobs = [ ]
464481 if ( places . length > 0 ) {
465482 for ( const [ i , place ] of places . entries ( ) ) {
466- const job = Job . fromPlace ( place )
467- job . setId ( i + 1 )
468- jobs . push ( job )
483+ jobs . push ( new Job ( place . lng , place . lat , place . placeName , jobProps [ i ] ) )
469484 }
470485 } else if ( this . jobs === undefined && storedJobs ) {
471486 for ( const job of JSON . parse ( storedJobs ) ) {
0 commit comments