From bfc4124b33c55bb98af871f1a5eb62efe774ceb2 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Tue, 1 Sep 2020 10:52:38 +0200 Subject: [PATCH] Save to real_time_inputs also when we're on a line --- lib/www/server/lib/db/navdata/save.js | 49 ++++++++++++--------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/lib/www/server/lib/db/navdata/save.js b/lib/www/server/lib/db/navdata/save.js index e36b3e8..53bbc58 100644 --- a/lib/www/server/lib/db/navdata/save.js +++ b/lib/www/server/lib/db/navdata/save.js @@ -10,7 +10,6 @@ async function getAllProjectConfigs () { return `SELECT '${r.schema}' AS schema, data FROM ${r.schema}.file_data WHERE (data->>'archived')::boolean IS NOT true AND data->>'id' IS NOT NULL`; }).join("\nUNION ALL "); - console.log(text); const res1 = await client.query(text); client.release(); return res1.rows.map(r => Object.assign(r.data, {schema: r.schema})); @@ -185,42 +184,38 @@ async function save (navData, opts = {}) { }); return obj; }).filter(c => !!c); - console.log("CANDIDATES", candidates); +// console.log("CANDIDATES", candidates); if (candidates.length == 0) { // This is probably a test line, so we treat it as offline console.log("No match"); - } else if (candidates.length == 1) { - // Only one candidate, associate with it - console.log("Save into schema", candidates[0].match.schema); } else { - // More than one candidate, go for the closest. If more than one active - // project with the same preplots, highest numbered schema. - console.log("Choose nearest"); -// - const destinationSchema = await getNearestPreplot(candidates); - if (destinationSchema) { - await saveOnline(candidates.filter(c => c.schema == destinationSchema)); + if (candidates.length == 1) { + // Only one candidate, associate with it +// console.log("Save into schema", candidates[0].match.schema); + await saveOnline(candidates); + navData.payload._schema = candidates[0].match.schema; } else { - console.log("Nowhere to save to"); + // More than one candidate, go for the closest. If more than one active + // project with the same preplots, highest numbered schema. +// console.log("Choose nearest"); + const destinationSchema = await getNearestPreplot(candidates); + if (destinationSchema) { + await saveOnline(candidates.filter(c => c.schema == destinationSchema)); + navData.payload._schema = destinationSchema; + } else { + console.log("Nowhere to save to"); + } } - } - } else { - console.log("Save offline"); - await saveOffline(navData); + navData.payload._sequence = candidates[0].sequence; + navData.payload._line = candidates[0].line; + navData.payload._point = candidates[0].point; + navData.payload._online = true; + } } -// const client = await setSurvey(projectId); -// -// const text = ` -// SELECT * -// FROM project_summary; -// `; -// -// const res = await client.query(text); -// client.release(); -// return res.rows[0]; + await saveOffline(navData); } module.exports = save;