From f1b4d1a53101471354d0974b9af678df8c04e7df Mon Sep 17 00:00:00 2001 From: Stefano Ricci Date: Wed, 27 Sep 2023 16:11:02 +0200 Subject: [PATCH 1/8] fixing now() function timezone offset --- core/record/_record/recordNodesUpdater.js | 16 +++++++++---- package.json | 2 +- server/modules/record/api/recordApi.js | 4 ++-- .../_recordManager/nodeCreationManager.js | 3 ++- .../_recordManager/nodeUpdateManager.js | 6 ++++- .../_recordManager/recordUpdateManager.js | 23 +++++++++++++++---- .../modules/record/service/recordService.js | 10 ++++++-- .../update/thread/recordsUpdateThread.js | 6 +++-- webapp/store/ui/record/actions/checkIn.js | 3 +++ webapp/store/ui/record/actions/delete.js | 4 +++- webapp/store/ui/record/actions/update.js | 3 +++ yarn.lock | 22 ++++++++---------- 12 files changed, 72 insertions(+), 30 deletions(-) diff --git a/core/record/_record/recordNodesUpdater.js b/core/record/_record/recordNodesUpdater.js index dba4de557a..106c9c9162 100644 --- a/core/record/_record/recordNodesUpdater.js +++ b/core/record/_record/recordNodesUpdater.js @@ -209,7 +209,7 @@ const _getOrCreateEntityByKeys = return { entity: entityInserted, updateResult } } -const _afterNodesUpdate = async ({ survey, record, nodes, sideEffect = false }) => { +const _afterNodesUpdate = async ({ survey, record, nodes, timezoneOffset, sideEffect = false }) => { // output const updateResult = new RecordUpdateResult({ record, nodes }) @@ -218,6 +218,7 @@ const _afterNodesUpdate = async ({ survey, record, nodes, sideEffect = false }) survey, record, nodes, + timezoneOffset, sideEffect, }) @@ -240,7 +241,7 @@ const _afterNodesUpdate = async ({ survey, record, nodes, sideEffect = false }) } const updateAttributesWithValues = - ({ survey, entityDefUuid, valuesByDefUuid, insertMissingNodes = false, sideEffect = false }) => + ({ survey, entityDefUuid, valuesByDefUuid, timezoneOffset, insertMissingNodes = false, sideEffect = false }) => async (record) => { const updateResult = new RecordUpdateResult({ record }) @@ -253,6 +254,7 @@ const updateAttributesWithValues = survey, record: nodeUpdateResult.record, nodes: nodeUpdateResult.nodes, + timezoneOffset, sideEffect, }) updateResult.merge(dependentsUpdateResult) @@ -399,7 +401,7 @@ const _mergeEntities = ({ survey, recordSource, recordTarget, entitySource, enti } const replaceUpdatedNodes = - ({ survey, recordSource, sideEffect = false }) => + ({ survey, recordSource, timezoneOffset, sideEffect = false }) => async (recordTarget) => { const rootSource = RecordReader.getRootNode(recordSource) const rootTarget = RecordReader.getRootNode(recordTarget) @@ -415,7 +417,13 @@ const replaceUpdatedNodes = entityTarget: rootTarget, sideEffect, }) - return _afterNodesUpdate({ survey, record: updateResult.record, nodes: updateResult.nodes, sideEffect }) + return _afterNodesUpdate({ + survey, + record: updateResult.record, + nodes: updateResult.nodes, + timezoneOffset, + sideEffect, + }) } export const RecordNodesUpdater = { diff --git a/package.json b/package.json index b37cb57bdb..fc4bb296fa 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,7 @@ "@mui/material": "^5.14.10", "@mui/x-data-grid": "^6.14.0", "@mui/x-date-pickers": "^6.14.0", - "@openforis/arena-core": "^0.0.166", + "@openforis/arena-core": "../arena-core", "@openforis/arena-server": "^0.1.29", "@sendgrid/mail": "^7.7.0", "@shopify/draggable": "^1.0.0-beta.8", diff --git a/server/modules/record/api/recordApi.js b/server/modules/record/api/recordApi.js index c5b0ea3505..a7ec867070 100644 --- a/server/modules/record/api/recordApi.js +++ b/server/modules/record/api/recordApi.js @@ -328,11 +328,11 @@ export const init = (app) => { // RECORD Check in / out app.post('/survey/:surveyId/record/:recordUuid/checkin', requireRecordViewPermission, async (req, res, next) => { try { - const { surveyId, recordUuid, draft } = Request.getParams(req) + const { surveyId, recordUuid, draft, timezoneOffset } = Request.getParams(req) const user = Request.getUser(req) const socketId = Request.getSocketId(req) - const record = await RecordService.checkIn({ socketId, user, surveyId, recordUuid, draft }) + const record = await RecordService.checkIn({ socketId, user, surveyId, recordUuid, draft, timezoneOffset }) res.json({ record }) } catch (error) { diff --git a/server/modules/record/manager/_recordManager/nodeCreationManager.js b/server/modules/record/manager/_recordManager/nodeCreationManager.js index a5aaf80acd..8b32532e61 100644 --- a/server/modules/record/manager/_recordManager/nodeCreationManager.js +++ b/server/modules/record/manager/_recordManager/nodeCreationManager.js @@ -58,7 +58,7 @@ export const insertNodesInBatch = async ({ user, surveyId, nodes, systemActivity } export const insertNode = async ( - { user, survey, record, node, system, persistNodes = true, createMultipleEntities = true }, + { user, survey, record, node, system, timezoneOffset, persistNodes = true, createMultipleEntities = true }, t ) => { const surveyId = Survey.getId(survey) @@ -85,6 +85,7 @@ export const insertNode = async ( record, parentNode: node, nodeDef, + timezoneOffset, createMultipleEntities, }) Object.assign(nodesCreated, descendantsCreateResult.nodes) diff --git a/server/modules/record/manager/_recordManager/nodeUpdateManager.js b/server/modules/record/manager/_recordManager/nodeUpdateManager.js index 9de6658437..7be29a7bef 100644 --- a/server/modules/record/manager/_recordManager/nodeUpdateManager.js +++ b/server/modules/record/manager/_recordManager/nodeUpdateManager.js @@ -141,11 +141,15 @@ const _reloadNodes = async ({ surveyId, record, nodes }, tx) => { return ObjectUtils.toUuidIndexedObj(nodesReloadedArray) } -export const updateNodesDependents = async ({ survey, record, nodes, persistNodes = true, sideEffect = false }, tx) => { +export const updateNodesDependents = async ( + { survey, record, nodes, timezoneOffset, persistNodes = true, sideEffect = false }, + tx +) => { const { record: recordUpdatedDependents, nodes: nodesUpdated } = Record.updateNodesDependents({ survey, record, nodes, + timezoneOffset, logger, sideEffect, }) diff --git a/server/modules/record/manager/_recordManager/recordUpdateManager.js b/server/modules/record/manager/_recordManager/recordUpdateManager.js index 254a487031..50c58401b2 100644 --- a/server/modules/record/manager/_recordManager/recordUpdateManager.js +++ b/server/modules/record/manager/_recordManager/recordUpdateManager.js @@ -38,7 +38,15 @@ import { NodeRdbManager } from './nodeRDBManager' // ==== CREATE export const initNewRecord = async ( - { user, survey, record, nodesUpdateListener = null, nodesValidationListener = null, createMultipleEntities = true }, + { + user, + survey, + record, + timezoneOffset, + nodesUpdateListener = null, + nodesValidationListener = null, + createMultipleEntities = true, + }, client = db ) => { const rootNodeDef = Survey.getNodeDefRoot(survey) @@ -51,6 +59,7 @@ export const initNewRecord = async ( survey, record, node: rootNode, + timezoneOffset, nodesUpdateListener, nodesValidationListener, system: true, @@ -170,6 +179,7 @@ export const persistNode = async ( survey, record, node, + timezoneOffset, nodesUpdateListener = null, nodesValidationListener = null, system = false, @@ -182,6 +192,7 @@ export const persistNode = async ( survey, record, node, + timezoneOffset, async (user, survey, record, node, t) => { const nodeUuid = Node.getUuid(node) @@ -226,6 +237,7 @@ const _updateNodeAndValidateRecordUniqueness = async ( survey, record, node, + timezoneOffset, nodesUpdateFn, nodesUpdateListener = null, nodesValidationListener = null, @@ -238,7 +250,7 @@ const _updateNodeAndValidateRecordUniqueness = async ( let recordUpdated = recordUpdated1 const { record: recordUpdated2, nodes: updatedNodesAndDependents } = await _onNodesUpdate( - { survey, record: recordUpdated, nodesUpdated, nodesUpdateListener, nodesValidationListener }, + { survey, record: recordUpdated, nodesUpdated, timezoneOffset, nodesUpdateListener, nodesValidationListener }, t ) recordUpdated = recordUpdated2 @@ -291,7 +303,10 @@ const _getDependentNodesToValidate = ({ survey, record, nodes }) => { return { ...nodes, ...ObjectUtils.toUuidIndexedObj(dependentNodesToValidate) } } -const _onNodesUpdate = async ({ survey, record, nodesUpdated, nodesUpdateListener, nodesValidationListener }, t) => { +const _onNodesUpdate = async ( + { survey, record, nodesUpdated, timezoneOffset, nodesUpdateListener, nodesValidationListener }, + t +) => { // 1. update record and notify if (nodesUpdateListener) { nodesUpdateListener(nodesUpdated) @@ -299,7 +314,7 @@ const _onNodesUpdate = async ({ survey, record, nodesUpdated, nodesUpdateListene // 2. update dependent nodes const { record: recordUpdatedDependentNodes, nodes: updatedDependentNodes } = - await NodeUpdateManager.updateNodesDependents({ survey, record, nodes: nodesUpdated }, t) + await NodeUpdateManager.updateNodesDependents({ survey, record, nodes: nodesUpdated, timezoneOffset }, t) if (nodesUpdateListener) { nodesUpdateListener(updatedDependentNodes) } diff --git a/server/modules/record/service/recordService.js b/server/modules/record/service/recordService.js index fdcd00b540..335aa38ef7 100644 --- a/server/modules/record/service/recordService.js +++ b/server/modules/record/service/recordService.js @@ -149,7 +149,7 @@ export const deleteRecordsPreview = async (olderThan24Hours = false) => { return count } -export const checkIn = async ({ socketId, user, surveyId, recordUuid, draft }) => { +export const checkIn = async ({ socketId, user, surveyId, recordUuid, draft, timezoneOffset }) => { const survey = await SurveyManager.fetchSurveyById({ surveyId, draft }) const surveyInfo = Survey.getSurveyInfo(survey) const record = await RecordManager.fetchRecordAndNodesByUuid({ surveyId, recordUuid, draft }) @@ -163,7 +163,13 @@ export const checkIn = async ({ socketId, user, surveyId, recordUuid, draft }) = const thread = RecordsUpdateThreadService.getOrCreatedThread({ surveyId, cycle, draft: preview }) // initialize record if empty if (Record.getNodesArray(record).length === 0) { - thread.postMessage({ type: RecordsUpdateThreadMessageTypes.recordInit, user, surveyId, recordUuid }) + thread.postMessage({ + type: RecordsUpdateThreadMessageTypes.recordInit, + user, + surveyId, + recordUuid, + timezoneOffset, + }) } } return record diff --git a/server/modules/record/service/update/thread/recordsUpdateThread.js b/server/modules/record/service/update/thread/recordsUpdateThread.js index a7f7702e3d..d652d3f02b 100644 --- a/server/modules/record/service/update/thread/recordsUpdateThread.js +++ b/server/modules/record/service/update/thread/recordsUpdateThread.js @@ -147,7 +147,7 @@ class RecordsUpdateThread extends Thread { async processRecordInitMsg(msg) { const { survey, surveyId } = this - const { recordUuid, user } = msg + const { recordUuid, user, timezoneOffset } = msg let record = await RecordManager.fetchRecordAndNodesByUuid({ surveyId, recordUuid }) @@ -155,6 +155,7 @@ class RecordsUpdateThread extends Thread { user, survey, record, + timezoneOffset, nodesUpdateListener: (updatedNodes) => this.handleNodesUpdated.bind(this)({ record, updatedNodes }), nodesValidationListener: (validations) => this.handleNodesValidationUpdated.bind(this)({ record, validations }), }) @@ -173,7 +174,7 @@ class RecordsUpdateThread extends Thread { async processRecordNodePersistMsg(msg) { const { survey } = this - const { node, user } = msg + const { node, user, timezoneOffset } = msg const recordUuid = Node.getRecordUuid(node) let record = await this.getOrFetchRecord({ recordUuid }) record = await RecordManager.persistNode({ @@ -181,6 +182,7 @@ class RecordsUpdateThread extends Thread { survey, record, node, + timezoneOffset, nodesUpdateListener: (updatedNodes) => this.handleNodesUpdated({ record, updatedNodes }), nodesValidationListener: (validations) => this.handleNodesValidationUpdated({ record, validations }), }) diff --git a/webapp/store/ui/record/actions/checkIn.js b/webapp/store/ui/record/actions/checkIn.js index 90fc7d7cc9..5f0b56d362 100644 --- a/webapp/store/ui/record/actions/checkIn.js +++ b/webapp/store/ui/record/actions/checkIn.js @@ -1,6 +1,8 @@ import * as R from 'ramda' import axios from 'axios' +import { Dates } from '@openforis/arena-core' + import * as Survey from '@core/survey/survey' import * as NodeDefLayout from '@core/survey/nodeDefLayout' import * as Record from '@core/record/record' @@ -21,6 +23,7 @@ export const checkInRecord = data: { record }, } = await axios.post(`/api/survey/${surveyId}/record/${recordUuid}/checkin`, { draft, + timezoneOffset: Dates.getTimezoneOffset(), }) if (!record) { diff --git a/webapp/store/ui/record/actions/delete.js b/webapp/store/ui/record/actions/delete.js index 3b25243200..defc9809eb 100644 --- a/webapp/store/ui/record/actions/delete.js +++ b/webapp/store/ui/record/actions/delete.js @@ -1,5 +1,7 @@ import axios from 'axios' +import { Dates } from '@openforis/arena-core' + import * as Record from '@core/record/record' import * as Node from '@core/record/node' @@ -23,7 +25,7 @@ export const removeNode = (nodeDef, node) => async (dispatch, getState) => { const nodeUuid = Node.getUuid(node) await axios.delete(`/api/survey/${surveyId}/record/${recordUuid}/node/${nodeUuid}`, { - data: { cycle, draft }, + data: { cycle, draft, timezoneOffset: Dates.getTimezoneOffset() }, }) } diff --git a/webapp/store/ui/record/actions/update.js b/webapp/store/ui/record/actions/update.js index 735e4eb41d..ba63a2c77d 100644 --- a/webapp/store/ui/record/actions/update.js +++ b/webapp/store/ui/record/actions/update.js @@ -1,5 +1,7 @@ import axios from 'axios' +import { Dates } from '@openforis/arena-core' + import * as A from '@core/arena' import * as Record from '@core/record/record' import * as Node from '@core/record/node' @@ -32,6 +34,7 @@ const _updateNodeDebounced = (node, file, delay) => { cycle, draft, node: JSON.stringify(node), + timezoneOffset: Dates.getTimezoneOffset(), ...(file ? { file } : {}), }) diff --git a/yarn.lock b/yarn.lock index c4793f51b4..4aebfebd00 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2513,13 +2513,11 @@ mkdirp "^1.0.4" rimraf "^3.0.2" -"@openforis/arena-core@^0.0.164": - version "0.0.164" - resolved "https://npm.pkg.github.com/download/@openforis/arena-core/0.0.164/7b8f863f75216eaa8185b89c2fbce4bc4a434cd3#7b8f863f75216eaa8185b89c2fbce4bc4a434cd3" - integrity sha512-q2GNymzZDPLYQdMQHqqiXVip+TUK2GezJg9fc3nUpd9P0XFgJA0ue6boBCeKm9LRZoTb2TMbuTQXk/OSNjq24g== +"@openforis/arena-core@../arena-core": + version "0.0.166" dependencies: "@jsep-plugin/regex" "^1.0.3" - bignumber.js "^9.1.1" + bignumber.js "^9.1.2" date-fns "^2.30.0" jsep "^1.3.8" lodash.differencewith "^4.5.0" @@ -2527,15 +2525,15 @@ lodash.isequal "^4.5.0" lodash.topairs "^4.3.0" proj4 "^2.9.0" - uuid "^9.0.0" + uuid "^9.0.1" -"@openforis/arena-core@^0.0.166": - version "0.0.166" - resolved "https://npm.pkg.github.com/download/@openforis/arena-core/0.0.166/6aaecc0092f34f4074e5b77a8dbee08ce2f987c9#6aaecc0092f34f4074e5b77a8dbee08ce2f987c9" - integrity sha512-Z1Lqbc16uwy1lpCxGwGn/jcC6hlljLG/bE3prwzPq9wNryHSz+vYOpmNXecqEr11EhoO34zxwoMcdAX9n0K1+Q== +"@openforis/arena-core@^0.0.164": + version "0.0.164" + resolved "https://npm.pkg.github.com/download/@openforis/arena-core/0.0.164/7b8f863f75216eaa8185b89c2fbce4bc4a434cd3#7b8f863f75216eaa8185b89c2fbce4bc4a434cd3" + integrity sha512-q2GNymzZDPLYQdMQHqqiXVip+TUK2GezJg9fc3nUpd9P0XFgJA0ue6boBCeKm9LRZoTb2TMbuTQXk/OSNjq24g== dependencies: "@jsep-plugin/regex" "^1.0.3" - bignumber.js "^9.1.2" + bignumber.js "^9.1.1" date-fns "^2.30.0" jsep "^1.3.8" lodash.differencewith "^4.5.0" @@ -2543,7 +2541,7 @@ lodash.isequal "^4.5.0" lodash.topairs "^4.3.0" proj4 "^2.9.0" - uuid "^9.0.1" + uuid "^9.0.0" "@openforis/arena-server@^0.1.29": version "0.1.29" From af4e5623d39701976642405052cd2f66ef7562a6 Mon Sep 17 00:00:00 2001 From: Stefano Ricci Date: Fri, 29 Sep 2023 09:42:22 +0200 Subject: [PATCH 2/8] use latest arena-core --- package.json | 2 +- yarn.lock | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index fc4bb296fa..8da24c2f6a 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,7 @@ "@mui/material": "^5.14.10", "@mui/x-data-grid": "^6.14.0", "@mui/x-date-pickers": "^6.14.0", - "@openforis/arena-core": "../arena-core", + "@openforis/arena-core": "^0.0.167", "@openforis/arena-server": "^0.1.29", "@sendgrid/mail": "^7.7.0", "@shopify/draggable": "^1.0.0-beta.8", diff --git a/yarn.lock b/yarn.lock index 4aebfebd00..13af9a060b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2513,11 +2513,13 @@ mkdirp "^1.0.4" rimraf "^3.0.2" -"@openforis/arena-core@../arena-core": - version "0.0.166" +"@openforis/arena-core@^0.0.164": + version "0.0.164" + resolved "https://npm.pkg.github.com/download/@openforis/arena-core/0.0.164/7b8f863f75216eaa8185b89c2fbce4bc4a434cd3#7b8f863f75216eaa8185b89c2fbce4bc4a434cd3" + integrity sha512-q2GNymzZDPLYQdMQHqqiXVip+TUK2GezJg9fc3nUpd9P0XFgJA0ue6boBCeKm9LRZoTb2TMbuTQXk/OSNjq24g== dependencies: "@jsep-plugin/regex" "^1.0.3" - bignumber.js "^9.1.2" + bignumber.js "^9.1.1" date-fns "^2.30.0" jsep "^1.3.8" lodash.differencewith "^4.5.0" @@ -2525,15 +2527,15 @@ lodash.isequal "^4.5.0" lodash.topairs "^4.3.0" proj4 "^2.9.0" - uuid "^9.0.1" + uuid "^9.0.0" -"@openforis/arena-core@^0.0.164": - version "0.0.164" - resolved "https://npm.pkg.github.com/download/@openforis/arena-core/0.0.164/7b8f863f75216eaa8185b89c2fbce4bc4a434cd3#7b8f863f75216eaa8185b89c2fbce4bc4a434cd3" - integrity sha512-q2GNymzZDPLYQdMQHqqiXVip+TUK2GezJg9fc3nUpd9P0XFgJA0ue6boBCeKm9LRZoTb2TMbuTQXk/OSNjq24g== +"@openforis/arena-core@^0.0.167": + version "0.0.167" + resolved "https://npm.pkg.github.com/download/@openforis/arena-core/0.0.167/d8ccf7aff8efd03c8d8778cdfc7db01cb112cbdd#d8ccf7aff8efd03c8d8778cdfc7db01cb112cbdd" + integrity sha512-ggPPFufKqX9fKcNo8k2c+XyV9a/ubK1SOYFfi4S+DzfdL3/XQpdSAXm4u0x/BSgcVx0MGU5t7hRQhwqRwWT9OQ== dependencies: "@jsep-plugin/regex" "^1.0.3" - bignumber.js "^9.1.1" + bignumber.js "^9.1.2" date-fns "^2.30.0" jsep "^1.3.8" lodash.differencewith "^4.5.0" @@ -2541,7 +2543,7 @@ lodash.isequal "^4.5.0" lodash.topairs "^4.3.0" proj4 "^2.9.0" - uuid "^9.0.0" + uuid "^9.0.1" "@openforis/arena-server@^0.1.29": version "0.1.29" From 93adf94cfafa59296fd25aaae3853f715e3a652f Mon Sep 17 00:00:00 2001 From: Stefano Ricci Date: Fri, 29 Sep 2023 09:42:30 +0200 Subject: [PATCH 3/8] layout adjustments --- webapp/components/form/DateTimeInput/DateInput.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/webapp/components/form/DateTimeInput/DateInput.scss b/webapp/components/form/DateTimeInput/DateInput.scss index 311b8b1e57..e86065edb4 100644 --- a/webapp/components/form/DateTimeInput/DateInput.scss +++ b/webapp/components/form/DateTimeInput/DateInput.scss @@ -5,4 +5,8 @@ width: 7rem; padding: 4px 6px; } + + .MuiIconButton-root { + padding: 0; + } } From e22737dd784901e108d19a08e923eebca96f87bc Mon Sep 17 00:00:00 2001 From: Stefano Ricci Date: Fri, 29 Sep 2023 16:26:06 +0200 Subject: [PATCH 4/8] fixed passing timezone offset parameter --- package.json | 2 +- server/modules/record/api/recordApi.js | 8 ++++---- .../manager/_recordManager/recordUpdateManager.js | 5 ++++- server/modules/record/service/recordService.js | 15 +++++++++++++-- yarn.lock | 8 ++++---- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 8da24c2f6a..5b6b980373 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,7 @@ "@mui/material": "^5.14.10", "@mui/x-data-grid": "^6.14.0", "@mui/x-date-pickers": "^6.14.0", - "@openforis/arena-core": "^0.0.167", + "@openforis/arena-core": "^0.0.169", "@openforis/arena-server": "^0.1.29", "@sendgrid/mail": "^7.7.0", "@shopify/draggable": "^1.0.0-beta.8", diff --git a/server/modules/record/api/recordApi.js b/server/modules/record/api/recordApi.js index a7ec867070..9640d76b5c 100644 --- a/server/modules/record/api/recordApi.js +++ b/server/modules/record/api/recordApi.js @@ -59,12 +59,12 @@ export const init = (app) => { app.post('/survey/:surveyId/record/:recordUuid/node', requireRecordEditPermission, async (req, res, next) => { try { const user = Request.getUser(req) - const { surveyId, cycle, draft } = Request.getParams(req) + const { surveyId, cycle, draft, timezoneOffset } = Request.getParams(req) const node = Request.getJsonParam(req, 'node') const file = Request.getFile(req) const socketId = Request.getSocketId(req) - await RecordService.persistNode({ socketId, user, surveyId, cycle, draft, node, file }) + await RecordService.persistNode({ socketId, user, surveyId, cycle, draft, node, file, timezoneOffset }) sendOk(res) } catch (error) { @@ -397,11 +397,11 @@ export const init = (app) => { }) app.delete('/survey/:surveyId/record/:recordUuid/node/:nodeUuid', requireRecordEditPermission, (req, res) => { - const { surveyId, cycle, draft, recordUuid, nodeUuid } = Request.getParams(req) + const { surveyId, cycle, draft, recordUuid, nodeUuid, timezoneOffset } = Request.getParams(req) const user = Request.getUser(req) const socketId = Request.getSocketId(req) - RecordService.deleteNode({ socketId, user, surveyId, cycle, draft, recordUuid, nodeUuid }) + RecordService.deleteNode({ socketId, user, surveyId, cycle, draft, recordUuid, nodeUuid, timezoneOffset }) sendOk(res) }) } diff --git a/server/modules/record/manager/_recordManager/recordUpdateManager.js b/server/modules/record/manager/_recordManager/recordUpdateManager.js index 50c58401b2..12accbe01a 100644 --- a/server/modules/record/manager/_recordManager/recordUpdateManager.js +++ b/server/modules/record/manager/_recordManager/recordUpdateManager.js @@ -201,7 +201,10 @@ export const persistNode = async ( if (existingNode) { return NodeUpdateManager.updateNode({ user, survey, record, node, system }, t) } - return NodeCreationManager.insertNode({ user, survey, record, node, system, createMultipleEntities }, t) + return NodeCreationManager.insertNode( + { user, survey, record, node, system, createMultipleEntities, timezoneOffset }, + t + ) }, nodesUpdateListener, nodesValidationListener, diff --git a/server/modules/record/service/recordService.js b/server/modules/record/service/recordService.js index 335aa38ef7..769c8f782b 100644 --- a/server/modules/record/service/recordService.js +++ b/server/modules/record/service/recordService.js @@ -310,7 +310,16 @@ const _sendNodeUpdateMessage = ({ socketId, user, surveyId, cycle, recordUuid, d export const { fetchNodeByUuid } = RecordManager -export const persistNode = async ({ socketId, user, surveyId, draft, cycle, node, file = null }) => { +export const persistNode = async ({ + socketId, + user, + surveyId, + draft, + cycle, + node, + file = null, + timezoneOffset = null, +}) => { const recordUuid = Node.getRecordUuid(node) if (file) { @@ -337,11 +346,12 @@ export const persistNode = async ({ socketId, user, surveyId, draft, cycle, node type: RecordsUpdateThreadMessageTypes.nodePersist, node, user, + timezoneOffset, }, }) } -export const deleteNode = ({ socketId, user, surveyId, cycle, draft, recordUuid, nodeUuid }) => +export const deleteNode = ({ socketId, user, surveyId, cycle, draft, recordUuid, nodeUuid, timezoneOffset }) => _sendNodeUpdateMessage({ socketId, user, @@ -354,6 +364,7 @@ export const deleteNode = ({ socketId, user, surveyId, cycle, draft, recordUuid, recordUuid, nodeUuid, user, + timezoneOffset, }, }) diff --git a/yarn.lock b/yarn.lock index 13af9a060b..f22589c7d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2529,10 +2529,10 @@ proj4 "^2.9.0" uuid "^9.0.0" -"@openforis/arena-core@^0.0.167": - version "0.0.167" - resolved "https://npm.pkg.github.com/download/@openforis/arena-core/0.0.167/d8ccf7aff8efd03c8d8778cdfc7db01cb112cbdd#d8ccf7aff8efd03c8d8778cdfc7db01cb112cbdd" - integrity sha512-ggPPFufKqX9fKcNo8k2c+XyV9a/ubK1SOYFfi4S+DzfdL3/XQpdSAXm4u0x/BSgcVx0MGU5t7hRQhwqRwWT9OQ== +"@openforis/arena-core@^0.0.169": + version "0.0.169" + resolved "https://npm.pkg.github.com/download/@openforis/arena-core/0.0.169/f3fcefbe0cac508bae6e0a7bb3bf10db49757490#f3fcefbe0cac508bae6e0a7bb3bf10db49757490" + integrity sha512-00MekgdM/ywIt21j9ml5BXG09AvWy/Qw7i75Qei25x58tCwMqSga+KpMS3+ZHOoP5mL45wfPOTCixMCUV4yvBw== dependencies: "@jsep-plugin/regex" "^1.0.3" bignumber.js "^9.1.2" From 7d6d532b855ea1f988e94bb4d58572f3eeaf9644 Mon Sep 17 00:00:00 2001 From: Stefano Ricci Date: Fri, 29 Sep 2023 18:23:20 +0200 Subject: [PATCH 5/8] fixing tests --- test/e2e/tests/surveyFormPreview.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/e2e/tests/surveyFormPreview.js b/test/e2e/tests/surveyFormPreview.js index 0552e05ded..75e52f9332 100644 --- a/test/e2e/tests/surveyFormPreview.js +++ b/test/e2e/tests/surveyFormPreview.js @@ -57,9 +57,14 @@ export default () => verifyAttribute(cluster_coordinate, { x: '', y: '', srs: '4326', srsLabel: 'WGS 1984 (EPSG:4326)' }) verifyAttribute(cluster_time, () => { // it is possible the default value was set one minute after the startTime was initialized in the test - const date = new Date(startTime) - date.setMinutes(date.getMinutes() + 1) - return `(${formatTime(startTime)})|(${formatTime(date)})` + const startTimePlus1Minute = new Date(startTime) + startTimePlus1Minute.setMinutes(startTimePlus1Minute.getMinutes() + 1) + const possibleDateValues = [new Date(startTime), startTimePlus1Minute] + const expectedPossibleValues = possibleDateValues.map((possibleDateValue) => { + possibleDateValue.setMinutes(possibleDateValue.getMinutes() - possibleDateValue.getTimezoneOffset()) + return formatTime(possibleDateValue) + }) + return `(${expectedPossibleValues.join('|')})` }) verifyAttribute(cluster_date, () => startTime) From 979a85cf4643c9292aabf21cafb4c8f5ab7703e4 Mon Sep 17 00:00:00 2001 From: Stefano Ricci Date: Fri, 29 Sep 2023 21:43:27 +0200 Subject: [PATCH 6/8] fixing tests --- test/e2e/tests/surveyFormPreview.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/tests/surveyFormPreview.js b/test/e2e/tests/surveyFormPreview.js index 75e52f9332..9d36d7e918 100644 --- a/test/e2e/tests/surveyFormPreview.js +++ b/test/e2e/tests/surveyFormPreview.js @@ -58,10 +58,10 @@ export default () => verifyAttribute(cluster_time, () => { // it is possible the default value was set one minute after the startTime was initialized in the test const startTimePlus1Minute = new Date(startTime) - startTimePlus1Minute.setMinutes(startTimePlus1Minute.getMinutes() + 1) + startTimePlus1Minute.setMinutes(startTime.getMinutes() + 1) const possibleDateValues = [new Date(startTime), startTimePlus1Minute] const expectedPossibleValues = possibleDateValues.map((possibleDateValue) => { - possibleDateValue.setMinutes(possibleDateValue.getMinutes() - possibleDateValue.getTimezoneOffset()) + possibleDateValue.setMinutes(possibleDateValue.getMinutes() + possibleDateValue.getTimezoneOffset()) return formatTime(possibleDateValue) }) return `(${expectedPossibleValues.join('|')})` From b1c5798460c73a84e1207e3de992e1be14a1b84f Mon Sep 17 00:00:00 2001 From: Stefano Ricci Date: Mon, 2 Oct 2023 12:39:54 +0200 Subject: [PATCH 7/8] fixing tests --- core/dateUtils.js | 11 ++++++++++- test/e2e/tests/surveyFormPreview.js | 10 ++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/core/dateUtils.js b/core/dateUtils.js index d37623e03e..7f789df27a 100644 --- a/core/dateUtils.js +++ b/core/dateUtils.js @@ -13,7 +13,16 @@ import { import { isBlank } from './stringUtils' -export { parseISO, subDays, addDays, differenceInDays, differenceInHours, subMonths, subYears } from 'date-fns' +export { + parseISO, + subDays, + addDays, + addMinutes, + differenceInDays, + differenceInHours, + subMonths, + subYears, +} from 'date-fns' export const formats = { dateDefault: 'dd/MM/yyyy', diff --git a/test/e2e/tests/surveyFormPreview.js b/test/e2e/tests/surveyFormPreview.js index 9d36d7e918..db42f7f27b 100644 --- a/test/e2e/tests/surveyFormPreview.js +++ b/test/e2e/tests/surveyFormPreview.js @@ -1,3 +1,4 @@ +import * as DateUtils from '../../../core/dateUtils' import { TestId, getSelector } from '../../../webapp/utils/testId' import { cluster, plot, tree } from '../mock/nodeDefs' import { gotoFormPage } from './_formDesigner' @@ -57,12 +58,13 @@ export default () => verifyAttribute(cluster_coordinate, { x: '', y: '', srs: '4326', srsLabel: 'WGS 1984 (EPSG:4326)' }) verifyAttribute(cluster_time, () => { // it is possible the default value was set one minute after the startTime was initialized in the test - const startTimePlus1Minute = new Date(startTime) - startTimePlus1Minute.setMinutes(startTime.getMinutes() + 1) + const startTimeDate = new Date(startTime) + const startTimePlus1Minute = DateUtils.addMinutes(startTimeDate, 1) const possibleDateValues = [new Date(startTime), startTimePlus1Minute] const expectedPossibleValues = possibleDateValues.map((possibleDateValue) => { - possibleDateValue.setMinutes(possibleDateValue.getMinutes() + possibleDateValue.getTimezoneOffset()) - return formatTime(possibleDateValue) + // const dateWithTimezoneOffset = DateUtils.addMinutes(possibleDateValue, possibleDateValue.getTimezoneOffset()) + const dateWithTimezoneOffset = possibleDateValue + return formatTime(dateWithTimezoneOffset) }) return `(${expectedPossibleValues.join('|')})` }) From 20cda1c05183c56d4f2ad0603350e116d1cf1071 Mon Sep 17 00:00:00 2001 From: Stefano Ricci Date: Mon, 2 Oct 2023 13:13:38 +0200 Subject: [PATCH 8/8] fixing tests --- test/e2e/tests/surveyFormPreview.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/tests/surveyFormPreview.js b/test/e2e/tests/surveyFormPreview.js index db42f7f27b..eab533ef3e 100644 --- a/test/e2e/tests/surveyFormPreview.js +++ b/test/e2e/tests/surveyFormPreview.js @@ -62,8 +62,8 @@ export default () => const startTimePlus1Minute = DateUtils.addMinutes(startTimeDate, 1) const possibleDateValues = [new Date(startTime), startTimePlus1Minute] const expectedPossibleValues = possibleDateValues.map((possibleDateValue) => { - // const dateWithTimezoneOffset = DateUtils.addMinutes(possibleDateValue, possibleDateValue.getTimezoneOffset()) - const dateWithTimezoneOffset = possibleDateValue + const timezoneOffsetDiff = startTimeDate.getTimezoneOffset() - -120 // browser timezone=Europe/Rome + const dateWithTimezoneOffset = DateUtils.addMinutes(possibleDateValue, timezoneOffsetDiff) return formatTime(dateWithTimezoneOffset) }) return `(${expectedPossibleValues.join('|')})`