From 3bacf32fc22a929631b92b04c742152ef25b9c19 Mon Sep 17 00:00:00 2001 From: Emanuele Paolini Date: Mon, 25 Dec 2023 12:46:37 +0100 Subject: [PATCH] =?UTF-8?q?avanzamento=20*=20riscritti=20end-point=20per?= =?UTF-8?q?=20la=20ricerca=20delle=20persone=20e=20dei=20grant=20*=20si=20?= =?UTF-8?q?pu=C3=B2=20scegliere=20la=20persona=20*=20si=20possono=20inseri?= =?UTF-8?q?re=20i=20dati=20della=20visita?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controllers/processes/visits.js | 34 +++++++++++++++++++++++-- server/models/Visit.js | 1 + src/components/ModelInput.js | 35 +++++++++++--------------- src/processes/AddVisit.js | 19 +++++++++++--- 4 files changed, 63 insertions(+), 26 deletions(-) diff --git a/server/controllers/processes/visits.js b/server/controllers/processes/visits.js index ae813ccc..e63ec245 100644 --- a/server/controllers/processes/visits.js +++ b/server/controllers/processes/visits.js @@ -189,8 +189,38 @@ router.put('/add/institution', async (req, res) => { }) */ router.get('/add/grant/search', async (req, res) => { - const controller = new GrantController() - await controller.search(req, res) + const $regex = new RegExp(escapeRegExp(req.query.q), 'i') + const data = await Grant.aggregate([ + { $lookup: { + from: 'people', + localField: 'pi', + foreignField: '_id', + as: 'pi', + pipeline: [ + { $project: { + _id: 1, + firstName: 1, + lastName: 1, + }}, + ] + }},/* + { $match: { + startDate: { $lte: "$$NOW" }, + endDate: { $gte: "$$NOW" }, + }},*/ + { $match: { $or: [ + { title: { $regex }}, + { code: { $regex }}, + { 'pi.lastName': { $regex }}, + ]}}, + { $project: { + _id: 1, + name: 1, + identifier: 1, + pi: 1, + }}, + ]) + res.json({ data }) }) module.exports = router \ No newline at end of file diff --git a/server/models/Visit.js b/server/models/Visit.js index a257662c..e2f94625 100644 --- a/server/models/Visit.js +++ b/server/models/Visit.js @@ -14,6 +14,7 @@ const visitSchema = new Schema({ affiliations: [{ type: ObjectId, label: 'affiliazioni al tempo della visita', ref: 'Institution' }], startDate, endDate, + publish: { type: Boolean, label: 'pubblica', default: false }, referencePeople: [{ type: ObjectId, label: 'referenti', ref: 'Person' }], grants: [{type: ObjectId, label: 'grants', ref: 'Grant'}], SSD, diff --git a/src/components/ModelInput.js b/src/components/ModelInput.js index 8ed6bbd9..fa6ee870 100644 --- a/src/components/ModelInput.js +++ b/src/components/ModelInput.js @@ -19,12 +19,11 @@ import { ConferenceRoomInput, SeminarCategoryInput } from './Input' +import { DatetimeInput } from './DatetimeInput' +import { usePrefix } from '../processes/PrefixProvider' -import { - DatetimeInput -} from './DatetimeInput' - -export function ModelFieldInput({ schema, value, setValue, api_prefix }) { +export function ModelFieldInput({ schema, value, setValue }) { + const api_prefix = usePrefix() function element(Element, opts = {}) { const {options, multiple} = opts return } if (!schema) return

no schema provided

- if (api_prefix === undefined) { - api_prefix = "/api/v0" - } - if (schema.type === 'array') { if (schema.enum) return element(MultipleSelectInput, {options: schema.enum}) if (!schema.items['x-ref']) return element(ListInput) - if (schema.items['x-ref'] === 'Person') return element(PersonInput, {multiple:true, api_prefix: api_prefix}) - if (schema.items['x-ref'] === 'Grant') return element(GrantInput, {multiple:true, api_prefix: api_prefix}) - if (schema.items['x-ref'] === 'Institution') return element(InstitutionInput, {multiple:true, api_prefix: api_prefix}) + if (schema.items['x-ref'] === 'Person') return element(PersonInput, {multiple:true}) + if (schema.items['x-ref'] === 'Grant') return element(GrantInput, {multiple:true}) + if (schema.items['x-ref'] === 'Institution') return element(InstitutionInput, {multiple:true}) return

x-ref to {schema.items['x-ref']} not yet implemented in array

} else { const xref = schema['x-ref'] - if (xref === 'Person') return element(PersonInput, {api_prefix: api_prefix}) - if (xref === 'Room') return element(RoomInput, {api_prefix: api_prefix}) - if (xref === 'ConferenceRoom') return element(ConferenceRoomInput, {api_prefix: api_prefix}) - if (xref === 'SeminarCategory') return element(SeminarCategoryInput, {api_prefix: api_prefix}) - if (xref === 'Institution') return element(InstitutionInput, {api_prefix: api_prefix}) - if (xref === 'User') return element(StringInput, {api_prefix: api_prefix}) + if (xref === 'Person') return element(PersonInput) + if (xref === 'Room') return element(RoomInput) + if (xref === 'ConferenceRoom') return element(ConferenceRoomInput) + if (xref === 'SeminarCategory') return element(SeminarCategoryInput) + if (xref === 'Institution') return element(InstitutionInput) + if (xref === 'User') return element(StringInput) if (xref) return

x-ref to {xref} not yet implemented

if (schema.format === 'date-time') { if (schema.widget === 'datetime') return element(DatetimeInput) // use formatted text input "YYYY-MM-DD HH:mm" @@ -81,7 +75,7 @@ export function ModelFieldInput({ schema, value, setValue, api_prefix }) { } } -export function ModelInput({ field, modified, schema, value, setValue, api_prefix}) { +export function ModelInput({ field, modified, schema, value, setValue}) { const label = schema?.items?.label || schema?.label || field const help = schema?.help @@ -90,7 +84,6 @@ export function ModelInput({ field, modified, schema, value, setValue, api_prefi schema={schema} value={value} setValue={setValue} - api_prefix={api_prefix} /> } diff --git a/src/processes/AddVisit.js b/src/processes/AddVisit.js index e50ee14d..afe8cf21 100644 --- a/src/processes/AddVisit.js +++ b/src/processes/AddVisit.js @@ -1,5 +1,5 @@ import { Button, Card, Form } from 'react-bootstrap' -import { useEffect, useState } from 'react' +import { useState } from 'react' import { useParams, useNavigate } from 'react-router-dom' import api from '../api' import axios from 'axios' @@ -9,6 +9,7 @@ import { Converter } from 'showdown' import SelectPersonBlock from './SelectPersonBlock' import { GrantInput, InputRow, DateInput } from '../components/Input' import { PrefixProvider } from './PrefixProvider' +import { myDateFormat } from '../Engine' export default function AddVisit() { const [data, setData] = useState({ @@ -29,7 +30,19 @@ export default function AddVisit() { : } - { data.person && setDetailsDone(true)}> } + { data.person && !detailsDone && setDetailsDone(true)}> } + { data.person && detailsDone && + +
+
Dettagli della visita
+
setDetailsDone(false)}>Modifica
+
+
+ + Date: {myDateFormat(data.startDate)} - {myDateFormat(data.endDate)}
+ Grants: {data.grants.map(grant => grant.identifier).join(", ")}
+
+
} } @@ -55,7 +68,7 @@ function VisitDetailsBlock({data, setData, onCompleted}) { function check() { - return data.startDate && data.endDate + return data.startDate && data.endDate && data.startDate <= data.endDate } }