Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:Unipisa/dm-manager into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
aziis98 committed Nov 7, 2023
2 parents 427188b + 03c7d7e commit 4d87394
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 22 deletions.
40 changes: 40 additions & 0 deletions server/controllers/processes/AddSeminar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const express = require('express')
const Person = require('../../models/Person')
const router = express.Router()

const EventSeminar = require('../../models/EventSeminar')

router.get('/searchPerson', async (req, res) => {
const lastName = req.query.lastName

if (lastName) {
const people = await Person.aggregate([
{ $match: { lastName: {$regex: lastName, $options: 'i'} } },
{ $lookup: {
from: 'institutions',
localField: 'affiliations',
foreignField: '_id',
as: 'affiliations'
}}
])
res.json(JSON.stringify(people))
}
else {
res.json(JSON.stringify([]))
}

})

router.put('/save', async (req, res) => {
const seminar = EventSeminar(req.body)
console.log(seminar)
try {
await seminar.save()
res.send({ result: "OK" })
}
catch (error) {
res.status(400).send({ error: error.message })
}
})

module.exports = router
8 changes: 4 additions & 4 deletions server/processes.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Custom processes to insert data from end-users.
const express = require('express')

const router = express.Router()

router.get('/', function (req, res) {
res.send('ok')
})
const addSeminarRouter = require('./controllers/processes/AddSeminar')
router.use('/seminars/add', addSeminarRouter)



module.exports = router
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function Internal() {
<Routes>
<Route path="/" element={<Home />} />
<Route path="/profile" element={<Profile />} />
<Route path="/process/seminar/add" element={<AddSeminar/>}></Route>
<Route path="/process/seminars/add" element={<AddSeminar/>}></Route>
{ Object.values(Models).map(x => x.routers()) }
<Route path="/map" element={<Map />} />
<Route path="*" element={<NotFound />} />
Expand Down
95 changes: 78 additions & 17 deletions src/processes/AddSeminar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Card, Form } from 'react-bootstrap'
import { ModelInput } from '../components/ModelInput'
import { useState } from 'react'
import { useEngine } from '../Engine'
import axios from 'axios'

export default function AddSeminar() {
const [person, setPerson] = useState(null)
Expand All @@ -11,28 +11,26 @@ export default function AddSeminar() {
const [room, setRoom] = useState(null)
const [category, setCategory] = useState(null)
const [seminarAdded, setSeminarAdded] = useState(false)

const engine = useEngine()
const putSeminar = engine.usePut('event-seminar')
const [abstract, setAbstract] = useState("")

const onCompleted = async () => {
// Insert the seminar in the database
const s = {
title: title,
startDatetime: date,
duration: duration,
conferenceRoom: room,
speaker: person,
category: category
conferenceRoom: room._id,
speaker: person._id,
category: category._id,
abstract: abstract
}

console.log(s)

if (await putSeminar(s)) {
try {
await axios.put('/api/v0/process/seminars/add/save', s)
setSeminarAdded(true)
}
else {
console.log("error")
catch (error) {
console.log(error)
}
}

Expand All @@ -52,12 +50,13 @@ export default function AddSeminar() {
duration={duration} setDuration={setDuration}
room={room} setRoom={setRoom}
category={category} setCategory={setCategory}
abstract={abstract} setAbstract={setAbstract}
onCompleted={onCompleted}
></SeminarDetailsBlock>
</div>;
}

function SeminarDetailsBlock({ speaker, onCompleted, disabled, room, setRoom, date, setDate, title, setTitle, duration, setDuration, category, setCategory }) {
function SeminarDetailsBlock({ speaker, onCompleted, disabled, room, setRoom, date, setDate, title, setTitle, duration, setDuration, category, setCategory, abstract, setAbstract }) {
const confirm_enabled = (title !== "") && (date !== null) && (duration > 0) && (room !== null) && (category !== null)

if (disabled) {
Expand All @@ -83,6 +82,9 @@ function SeminarDetailsBlock({ speaker, onCompleted, disabled, room, setRoom, da
<Form.Group className="my-3">
<ModelInput field="Aula" schema={{ "x-ref": "ConferenceRoom" }} value={room} setValue={setRoom}></ModelInput>
</Form.Group>
<Form.Group className="my-3">
<ModelInput field="Abstract" schema={{ type: "string", widget: "text" }} value={abstract} setValue={setAbstract}></ModelInput>
</Form.Group>
</Form>
<div className="d-flex flex-row justify-content-end">
<Button className="text-end" onClick={onCompleted} disabled={! confirm_enabled}>Conferma</Button>
Expand All @@ -92,6 +94,28 @@ function SeminarDetailsBlock({ speaker, onCompleted, disabled, room, setRoom, da
}

function SelectPersonBlock({ onCompleted, disabled, person, setPerson }) {
const [surname, setSurname] = useState("")
const [matchedSpeakers, setMatchedSpeakers] = useState([])

const onSpeakerSelected = x => {
setPerson(x)
}

const searchSpeakers = async x => {
// Fetch the list of speakers with the given surname
const surname = x.target.value
if (surname.length < 2) {
setMatchedSpeakers([])
}
else {
const res = await axios.get('/api/v0/process/seminars/add/searchPerson', {
params: { lastName: surname }
})
setMatchedSpeakers(JSON.parse(res.data))
}
setSurname(surname)
}

if (disabled) {
return <Card className="shadow mb-3">
<Card.Header>Selezione speaker: <strong>{person?.firstName} {person?.lastName}</strong></Card.Header>
Expand All @@ -102,16 +126,53 @@ function SelectPersonBlock({ onCompleted, disabled, person, setPerson }) {
<Card className="shadow mb-3">
<Card.Header>Selezione speaker</Card.Header>
<Card.Body>
<Form>
<Form className="mb-3">
<Form.Group>
<ModelInput field="Speaker" schema={{'x-ref': 'Person'}} value={person} setValue={setPerson}></ModelInput>
<Form.Label>Inserire il cognome per attivare il completamento:</Form.Label>
<Form.Control type="input" value={surname} onChange={searchSpeakers}></Form.Control>
</Form.Group>
<MatchedSpeakersBlock speakers={matchedSpeakers} onSpeakerSelected={onSpeakerSelected}></MatchedSpeakersBlock>
</Form>
<div className="d-flex flex-row justify-content-end">
<Button className="text-end" onClick={() => onCompleted(person)} disabled={person != null}>Conferma</Button>
</div>
</Card.Body>
</Card>

</Card>
</div>
}

function MatchedSpeakersBlock({speakers, onSpeakerSelected}) {
const onChooseSpeakerClicked = x => {
onSpeakerSelected(x)
}

if (speakers.length === 0) {
return <div className="my-3">
<em>Se la persona cercata non è presente in anagrafica, scrivere a <a href="mailto:[email protected]">[email protected]</a> per richiederne l'inserimento, fornendo nome, affiliazione, indirizzo e-mail.
</em>
</div>
}
else {
const speakersBlock = Array.from(speakers).map(x => {
console.log(x.firstName + " " + x.lastName)
return <div className="p-3 col-6"><Card className="p-0 m-0">
<Card.Header>{x.firstName} {x.lastName}</Card.Header>
<Card.Body>
<a href="mailto:{x.email}">{x.email}</a><br></br>
<em>{x.affiliations.map(x => x.name)}</em>
<div className="flex-row d-flex justify-content-end">
<Button className="btn btn-primary" onClick={() => onChooseSpeakerClicked(x)}>Scegli</Button>
</div>
</Card.Body>
</Card></div>
})

console.log(speakersBlock)

return <div className="my-3">
<div className="row">
{speakersBlock}
</div>
</div>
}
}

0 comments on commit 4d87394

Please sign in to comment.