diff --git a/app/routes/projects--source-data.js b/app/routes/projects--source-data.js index 043570ff..9754b2a6 100644 --- a/app/routes/projects--source-data.js +++ b/app/routes/projects--source-data.js @@ -17,7 +17,7 @@ import { ProjectStatusError } from '../utils/errors'; import { parseFormData, getPropInsensitive } from '../utils/utils'; -import { getOSRMProfileDefaultSpeedSettings, renderProfileFile } from '../utils/osrm-profile'; +import { getOSRMProfileDefaultSpeedSettings, renderProfileFile, getOSRMProfileDefaultSpeedMeta } from '../utils/osrm-profile'; const profileValidationSchema = Object.keys(getOSRMProfileDefaultSpeedSettings()) .reduce((acc, setting) => { @@ -243,7 +243,10 @@ export default [ .where('name', 'profile') .first(); - return reply(sourceData.data.settings); + return reply({ + sections: getOSRMProfileDefaultSpeedMeta(), + settings: sourceData.data.settings + }); } catch (err) { console.log('err', err); return reply(Boom.badImplementation(err)); diff --git a/app/utils/osrm-profile.js b/app/utils/osrm-profile.js index 1752359e..cf972a0f 100644 --- a/app/utils/osrm-profile.js +++ b/app/utils/osrm-profile.js @@ -28,6 +28,24 @@ export function toLua (element) { } } +// How the profile edit works: +// Section are gorups of speeds that can be edited (ex: "Surface Speeds", +// "Tracktype Speeds", "Smoothness Speeds", etc) These are required by the api +// and defined on the server alongside the labels. +// A section can have the `multi` flag set, which means that two levels are +// allowed. + +export function getOSRMProfileDefaultSpeedMeta () { + return [ + { key: 'speed_profile', label: 'Speeds' }, + { key: 'surface_speeds', label: 'Surface Speeds' }, + { key: 'tracktype_speeds', label: 'Tracktype Speeds' }, + { key: 'smoothness_speeds', label: 'Smoothness Speeds' }, + { key: 'maxspeed_table_default', label: 'Maxspeed Default' }, + { key: 'maxspeed_table', label: 'Maxspeed' } + ]; +} + export function getOSRMProfileDefaultSpeedSettings () { return { speed_profile: { diff --git a/test/test-projects-source-data.js b/test/test-projects-source-data.js index ffb40c78..7c88a4b3 100644 --- a/test/test-projects-source-data.js +++ b/test/test-projects-source-data.js @@ -9,7 +9,7 @@ import db from '../app/db'; import { setupStructure as setupDdStructure } from '../app/db/structure'; import { setupStructure as setupStorageStructure } from '../app/s3/structure'; import { fixMeUp } from './utils/data'; -import { getOSRMProfileDefaultSpeedSettings, toLua } from '../app/utils/osrm-profile'; +import { getOSRMProfileDefaultSpeedSettings, toLua, getOSRMProfileDefaultSpeedMeta } from '../app/utils/osrm-profile'; var options = { connection: {port: 2000, host: '0.0.0.0'} @@ -509,7 +509,10 @@ describe('Projects source data', function () { }).then(res => { assert.equal(res.statusCode, 200, 'Status code is 200'); var result = res.result; - assert.deepEqual(result, getOSRMProfileDefaultSpeedSettings()); + assert.deepEqual(result, { + sections: getOSRMProfileDefaultSpeedMeta(), + settings: getOSRMProfileDefaultSpeedSettings() + }); }); }); });