Skip to content

Commit

Permalink
avanzamento
Browse files Browse the repository at this point in the history
* riscritti end-point per la ricerca delle persone e dei grant
* si può scegliere la persona
* si possono inserire i dati della visita
  • Loading branch information
paolini committed Dec 25, 2023
1 parent 49c77a3 commit 3bacf32
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 26 deletions.
34 changes: 32 additions & 2 deletions server/controllers/processes/visits.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions server/models/Visit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
35 changes: 14 additions & 21 deletions src/components/ModelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,38 @@ 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 <Element
value={value}
setValue={setValue}
options={options}
multiple={multiple}
api_prefix={api_prefix}
/>
}

if (!schema) return <p>no schema provided</p>

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 <p>x-ref to {schema.items['x-ref']} not yet implemented in array</p>
} 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 <p>x-ref to {xref} not yet implemented</p>
if (schema.format === 'date-time') {
if (schema.widget === 'datetime') return element(DatetimeInput) // use formatted text input "YYYY-MM-DD HH:mm"
Expand All @@ -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

Expand All @@ -90,7 +84,6 @@ export function ModelInput({ field, modified, schema, value, setValue, api_prefi
schema={schema}
value={value}
setValue={setValue}
api_prefix={api_prefix}
/>
</InputRow>
}
Expand Down
19 changes: 16 additions & 3 deletions src/processes/AddVisit.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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({
Expand All @@ -29,7 +30,19 @@ export default function AddVisit() {
</Card>
: <SelectPersonBlock title="Selezione speaker" label="Seaker" person={data.person} setPerson={setter(setData, 'person')}/>
}
{ data.person && <VisitDetailsBlock data={data} setData={setData} onCompleted={() => setDetailsDone(true)}></VisitDetailsBlock> }
{ data.person && !detailsDone && <VisitDetailsBlock data={data} setData={setData} onCompleted={() => setDetailsDone(true)}></VisitDetailsBlock> }
{ data.person && detailsDone && <Card className="shadow mb-3">
<Card.Header>
<div className="d-flex d-row justify-content-between">
<div>Dettagli della visita</div>
<div className="btn btn-warning btn-sm" onClick={() => setDetailsDone(false)}>Modifica</div>
</div>
</Card.Header>
<Card.Body>
<strong>Date:</strong> {myDateFormat(data.startDate)} - {myDateFormat(data.endDate)}<br />
<strong>Grants:</strong> {data.grants.map(grant => grant.identifier).join(", ")}<br />
</Card.Body>
</Card> }
</PrefixProvider>
}

Expand All @@ -55,7 +68,7 @@ function VisitDetailsBlock({data, setData, onCompleted}) {
</Card>

function check() {
return data.startDate && data.endDate
return data.startDate && data.endDate && data.startDate <= data.endDate
}
}

Expand Down

0 comments on commit 3bacf32

Please sign in to comment.