Skip to content

Commit c393308

Browse files
committed
fix: parsing of JSON file into mapViewData
references #420 and commit 6f75c63
1 parent 100007c commit c393308

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/fragments/forms/map-form/components/download/download.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export default {
237237
return csvData
238238
},
239239
parseMapView (mapViewData) {
240-
let localMapViewData = mapViewData
240+
let localMapViewData = mapViewData.clone()
241241

242242
if (mapViewData.mode === constants.modes.optimization) {
243243
let jsonJobs = []

src/support/map-data-services/file-data-extractors/file-extractors/json-file-importer.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import MapViewData from '@/models/map-view-data'
22
import constants from '@/resources/constants'
33
import Place from '@/models/place'
4+
import Job from '@/models/job'
5+
import Vehicle from '@/models/vehicle'
46
import store from '@/store/store'
57
import lodash from 'lodash'
68
/**
@@ -22,9 +24,9 @@ class JsonImporter {
2224
return new Promise((resolve, reject) => {
2325
let mapViewData = new MapViewData()
2426
const parsingResult = context.parseFileContentToMapViewData()
27+
2528
if (parsingResult) {
26-
mapViewData = parsingResult
27-
mapViewData = context.setMode(mapViewData)
29+
mapViewData = context.setMode(parsingResult)
2830

2931
// Make sure that the mode defined
3032
// in the imported file/object is valid
@@ -93,6 +95,10 @@ class JsonImporter {
9395
} else {
9496
if (key === 'places') {
9597
mapViewData.places = this.parsePlaces(content)
98+
} else if (key === 'jobs') {
99+
mapViewData.jobs = this.parseJobs(content)
100+
} else if (key === 'vehicles') {
101+
mapViewData.vehicles = this.parseVehicles(content)
96102
} else if (content[key]) {
97103
mapViewData[key] = content[key]
98104
}
@@ -118,6 +124,22 @@ class JsonImporter {
118124
return places
119125
}
120126

127+
parseJobs = (content) => {
128+
const jobs = []
129+
for (const job of content.jobs) {
130+
jobs.push(Job.fromObject(job))
131+
}
132+
return jobs
133+
}
134+
135+
parseVehicles = (content) => {
136+
const vehicles = []
137+
for (const v of content.vehicles) {
138+
vehicles.push(Vehicle.fromObject(v))
139+
}
140+
return vehicles
141+
}
142+
121143
/**
122144
* Adjust summary data
123145
*/

0 commit comments

Comments
 (0)