From 2d1e1e9532b766c0817656922e4b2d0c0367c19b Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Mon, 23 Oct 2023 14:53:32 +0200 Subject: [PATCH 1/3] Modify return payload of planner endpoint. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previous: [ { sequence: …}, { sequence: …}, … ] Current: { remarks: "…", sequences: [ { sequence: …}, { sequence: …}, … ] } --- lib/www/server/api/middleware/plan/list/json.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/www/server/api/middleware/plan/list/json.js b/lib/www/server/api/middleware/plan/list/json.js index 2fb5674..e5ee08b 100644 --- a/lib/www/server/api/middleware/plan/list/json.js +++ b/lib/www/server/api/middleware/plan/list/json.js @@ -1,9 +1,14 @@ -const { plan } = require('../../../../lib/db'); +const { plan, info } = require('../../../../lib/db'); const json = async function (req, res, next) { try { - const response = await plan.list(req.params.project, req.query); + const sequences = await plan.list(req.params.project, req.query) ?? []; + const remarks = await info.get(req.params.project, "plan/remarks", req.query, req.user.role) ?? null; + const response = { + remarks, + sequences + }; res.status(200).send(response); next(); } catch (err) { From 5065d624437bf0f4e34f5cbee61f6e0142676002 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Mon, 23 Oct 2023 14:57:27 +0200 Subject: [PATCH 2/3] Update planner endpoint documentation --- lib/www/server/spec/openapi.yaml | 52 ++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/lib/www/server/spec/openapi.yaml b/lib/www/server/spec/openapi.yaml index 52b968e..1f07811 100644 --- a/lib/www/server/spec/openapi.yaml +++ b/lib/www/server/spec/openapi.yaml @@ -1232,9 +1232,55 @@ paths: content: application/json: schema: - type: array - items: - $ref: "#/components/schemas/PlannedSequence" + type: object + properties: + remarks: + type: string + description: Planner remarks + sequences: + type: array + items: + $ref: "#/components/schemas/PlannedSequence" + text/csv: + schema: + type: string + format: csv + description: | + Returns a CSV response containing one row for each planned sequence, with the following columns: + + * `sequence`: Sequence number + * `line`: Line number + * `fsp`: First shotpoint + * `lsp`: Last shotpoint + * `ts0`: Estimated timestamp of the first shotpoint + * `ts1`: Estimated timestamp of the last shotpoint + * `name`: Line name + * `remarks`: Arbitrary comments + * `num_points`: Number of shotpoints + * `duration`: Estimated duration in seconds + * `length`: Line length in metres + * `azimuth`: Line azimuth + * `lon0`: Longitude of the first shotpoint + * `lat0`: Latitude of the first shotpoint + * `lon1` Longitude of the last shotpoint + * `lat1`: Latitude of the last shotpoint + example: | + "sequence","line","fsp","lsp","ts0","ts1","name","remarks","num_points","duration","length","azimuth","lon0","lat0","lon1","lat1" + 81,5162,2422,1158,"2023-10-22T11:09:24.912Z","2023-10-22T12:56:03.395Z","2051621081S00000","",633,6398,15799.988472147348,26.4703415983101,2.474872,59.086695,2.596266,59.214146 + 82,5178,2444,1146,"2023-10-22T12:56:03.000Z","2023-10-22T14:45:33.607Z","2051781082S00000","",650,6570,16225.02094944685,26.470137885560813,2.469632,59.085264,2.594277,59.216147 + text/html: + schema: + type: string + format: html + description: | + An HTML representation of the plan. + application/pdf: + schema: + type: string + contentMediaType: application/pdf + description: | + A PDF representation of the plan. + post: description: Add a new sequence to the plan. From 851369a0b4c5390dffef0b1fff31f6507b079dad Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Mon, 23 Oct 2023 14:58:41 +0200 Subject: [PATCH 3/3] Invalidate planner endpoint cache when setting remarks --- lib/www/server/api/middleware/etag/watch.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/www/server/api/middleware/etag/watch.js b/lib/www/server/api/middleware/etag/watch.js index 26fac46..09914f7 100644 --- a/lib/www/server/api/middleware/etag/watch.js +++ b/lib/www/server/api/middleware/etag/watch.js @@ -43,15 +43,26 @@ const rels = [ matches: [ ], callback (url, data) { if (data.payload?.table == "info") { + const pid = data.payload?.pid; + const key = (data.payload?.new ?? data.payload?.old)?.key; + const rx = /^\/project\/([^\/]+)\/info\/([^\/?]+)[\/?]?/; const match = url.match(rx); if (match) { - if (match[1] == data.payload.pid) { + if (match[1] == pid) { if (match[2] == data.payload?.old?.key || match[2] == data.payload?.new?.key) { return true; } } } + + if (key == "plan") { + const rx = /^\/project\/([^\/]+)\/plan[\/?]?/; + const match = url.match(rx); + if (match) { + return match[1] == pid; + } + } } return false; }