Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Unipisa/dm-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
paolini committed Oct 28, 2023
2 parents edf7ad8 + 44394ae commit cd430c7
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 45 deletions.
5 changes: 3 additions & 2 deletions server/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async function findPerson2(people, fullName, affiliazione) {
console.log(`found ${fullName} as ${p[0].firstName}+${p[0].lastName}`)
return p[0]._id
} else {
return findPerson(people, fullName, '*** fixme ***')
return findPerson(people, fullName, '')
}
}
}
Expand Down Expand Up @@ -803,7 +803,8 @@ const migrations = {
}

for(const seminar of await seminars.find({}).toArray()) {
const abstract = seminar.oldAbstract || ''
const abstract = seminar.oldAbstract
if (!abstract) continue
const parsed = parseHTML(abstract)
await seminars.updateOne({ _id: seminar._id },
{ $set: { abstract: parsed } })
Expand Down
1 change: 1 addition & 0 deletions server/models/ConferenceRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const schema = new Schema({
})

const ConferenceRoom = model('ConferenceRoom', schema)
ConferenceRoom.relatedModels = []

/**
* Questa è giusto una collezione intermedia che include alcune delle stanze
Expand Down
12 changes: 9 additions & 3 deletions server/models/EventConference.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const {
notes,
} = require('./Model')

const Grant = require('./Grant')

const eventConferenceSchema = new Schema({
title: {type: String, label: 'Titolo'},
startDate,
Expand All @@ -31,7 +29,9 @@ const eventConferenceSchema = new Schema({
})

const EventConference = model('EventConference', eventConferenceSchema)
module.exports = EventConference

const Grant = require('./Grant')
Grant.relatedModels.push({
model: EventConference,
modelName: 'EventConference',
Expand All @@ -40,4 +40,10 @@ Grant.relatedModels.push({
multiple: true,
})

module.exports = EventConference
const ConferenceRoom = require('./ConferenceRoom')
ConferenceRoom.relatedModels.push({
model: EventConference,
modelName: 'EventConference',
url: 'event-conference',
field: 'conferenceRoom',
})
12 changes: 10 additions & 2 deletions server/models/EventSeminar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const eventSeminarSchema = new Schema({
duration: { type: Number, label: 'Durata (in minuti)', default: 60 },
category: { type: ObjectId, label: 'Ciclo di Seminari', ref: 'SeminarCategory', required: true },
grants: [{type: ObjectId, label: 'grants', ref: 'Grant'}],
abstract: { type: String, label: 'Abstract (non modificare!)', widget: 'text' },
abstract: { type: String, label: "Abstract (non modificare se c'è un abstract vecchio!)", widget: 'text' },
oldUrl: { type: String, label: 'URL vecchio', widget: 'url' },
oldAbstract: { type: String, label: 'Abstract vecchio', widget: 'text' },

Expand Down Expand Up @@ -44,4 +44,12 @@ Person.relatedModels.push({
url: 'event-seminar',
field: 'speaker',
multiple: false,
})
})

const ConferenceRoom = require('./ConferenceRoom')
ConferenceRoom.relatedModels.push({
model: EventSeminar,
modelName: 'EventSeminar',
url: 'event-seminar',
field: 'conferenceRoom',
})
6 changes: 6 additions & 0 deletions server/models/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ function field_from_model_info(info) {
can_filter: true,
related_field: true,
}
} else if (info.ref === 'ConferenceRoom') {
return {
can_sort: ['name'],
can_filter: true,
related_field: true,
}
} else {
switch(info.type) {
case Number: // fall through
Expand Down
2 changes: 0 additions & 2 deletions src/components/DatetimeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ export function DatetimeInput({ value, setValue }) {
: ''
)

console.log(date, time)

return (
<div className="row d-flex">
<div className="col-sm-8 pe-0">
Expand Down
2 changes: 1 addition & 1 deletion src/components/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function ListInput({ id, value, setValue, separator }) {
if (separator === undefined) separator = ','
return <input
id={ id }
value={ value.join(separator) || "" }
value={ value ? (value.join(separator) || "") : "" }
onChange={ (evt) => {
const val = evt.target.value
.split(separator)
Expand Down
104 changes: 69 additions & 35 deletions src/processes/AddSeminar.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,114 @@
import { Button, Card, Form } from 'react-bootstrap'
import { ModelInput } from '../components/ModelInput'
import { useState } from 'react'
import { useEngine } from '../Engine'

export default function AddSeminar() {
const [speaker, setSpeaker] = useState(null)
const [speakerBlockDisabled, setSpeakerBlockDisabled] = useState(false)
const [seminarDetailsBlockDisabled, setSeminarDetailsBlockDisabled] = useState(true)
const [person, setPerson] = useState(null)
const [title, setTitle] = useState("")
const [date, setDate] = useState(null)
const [duration, setDuration] = useState(60)
const [room, setRoom] = useState(null)
const [category, setCategory] = useState(null)
const [seminarAdded, setSeminarAdded] = useState(false)

const onSpeakerSelected = x => {
setSpeaker(x)
setSpeakerBlockDisabled(true)
setSeminarDetailsBlockDisabled(false)
}
const engine = useEngine()
const putSeminar = engine.usePut('event-seminar')

const speakerBlock = <div className={speakerBlockDisabled ? "d-none" : "d-block"}>
<SelectPersonBlock onCompleted={onSpeakerSelected}></SelectPersonBlock>
</div>;
const onCompleted = async () => {
// Insert the seminar in the database
const s = {
title: title,
startDatetime: date,
duration: duration,
conferenceRoom: room,
speaker: person,
category: category
}

const seminarDetails = <div className={seminarDetailsBlockDisabled ? "d-none" : "d-block"}>
<SeminarDetailsBlock speaker={speaker}></SeminarDetailsBlock>
</div>
console.log(s)

if (await putSeminar(s)) {
setSeminarAdded(true)
}
else {
console.log("error")
}
}

if (seminarAdded) {
return <div>
<p>Seminario inserito correttamente.</p>
<a href="/"><button className="btn btn-primary">Torna alla home</button></a>
</div>
}

return <div>
<h1 className="text-primary pb-4">Nuovo Seminario</h1>
{speakerBlock}
{seminarDetails}
<h1 className="text-primary pb-4">Inserimento nuovo seminario</h1>
<SelectPersonBlock person={person} setPerson={setPerson} disabled={person != null}></SelectPersonBlock>
<SeminarDetailsBlock disabled={person == null}
title={title} setTitle={setTitle}
date={date} setDate={setDate}
duration={duration} setDuration={setDuration}
room={room} setRoom={setRoom}
category={category} setCategory={setCategory}
onCompleted={onCompleted}
></SeminarDetailsBlock>
</div>;
}

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

if (disabled) {
return <></>
}

return <Card className="shadow">
<Card.Header>Dettagli del seminario [speaker: <strong>{speaker?.firstName} {speaker?.lastName}</strong>]</Card.Header>
<Card.Header>Dettagli del seminario</Card.Header>
<Card.Body>
<Form>
<Form.Group className="my-3">
<ModelInput field="Titolo" schema={{ type: "string" }}></ModelInput>
<ModelInput field="Titolo" schema={{ type: "string" }} value={title} setValue={setTitle}></ModelInput>
</Form.Group>
<Form.Group className="my-3">
<ModelInput field="Categoria" schema={{ "x-ref": "SeminarCategory" }} value={category} setValue={setCategory}></ModelInput>
</Form.Group>
<Form.Group className="my-3">
<ModelInput field="Data e ora" schema={{ format: "date-time", widget: "datetime" }}></ModelInput>
<ModelInput field="Data e ora" schema={{ format: "date-time", widget: "datetime" }} value={date} setValue={setDate}></ModelInput>
</Form.Group>
<Form.Group className="my-3">
<ModelInput field="Durata (in minuti)" schema={{ type: "number" }}></ModelInput>
<ModelInput field="Durata (in minuti)" schema={{ type: "number" }} value={duration} setValue={setDuration}></ModelInput>
</Form.Group>
<Form.Group className="my-3">
<ModelInput field="Aula" schema={{ "x-ref": "ConferenceRoom" }}></ModelInput>
<ModelInput field="Aula" schema={{ "x-ref": "ConferenceRoom" }} value={room} setValue={setRoom}></ModelInput>
</Form.Group>
</Form>
<div className="d-flex flex-row justify-content-end">
<Button className="text-end" onClick={() => onCompleted()} disabled={! confirm}>Conferma</Button>
<Button className="text-end" onClick={onCompleted} disabled={! confirm_enabled}>Conferma</Button>
</div>
</Card.Body>
</Card>;
}

function SelectPersonBlock({ onCompleted }) {
const [person, setPerson] = useState(null)
const [confirm, setConfirm] = useState(person !== null)

const onSpeakerSelected = x => {
setPerson(x)
setConfirm(x !== null)
function SelectPersonBlock({ onCompleted, disabled, person, setPerson }) {
if (disabled) {
return <Card className="shadow mb-3">
<Card.Header>Selezione speaker: <strong>{person?.firstName} {person?.lastName}</strong></Card.Header>
</Card>
}

return <div>
<Card className="shadow">
<Card className="shadow mb-3">
<Card.Header>Selezione speaker</Card.Header>
<Card.Body>
<Form>
<Form.Group>
<ModelInput field="Speaker" schema={{'x-ref': 'Person'}} value={person} setValue={onSpeakerSelected}></ModelInput>
<ModelInput field="Speaker" schema={{'x-ref': 'Person'}} value={person} setValue={setPerson}></ModelInput>
</Form.Group>
</Form>
<div className="d-flex flex-row justify-content-end">
<Button className="text-end" onClick={() => onCompleted(person)} disabled={! confirm}>Conferma</Button>
<Button className="text-end" onClick={() => onCompleted(person)} disabled={person != null}>Conferma</Button>
</div>
</Card.Body>
</Card>
Expand Down

0 comments on commit cd430c7

Please sign in to comment.