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
paolini committed Oct 27, 2023
2 parents e81c0f2 + 3b7a9f7 commit 87df175
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 7 deletions.
3 changes: 3 additions & 0 deletions server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const visitsQuery = require('./controllers/public/visits')
const seminarsQuery = require('./controllers/public/seminars')
const seminarQuery = require('./controllers/public/seminar')
const coursesQuery = require('./controllers/public/courses')
const processes = require('./processes.js')

const router = express.Router()

Expand Down Expand Up @@ -82,5 +83,7 @@ router.get('/public/courses', async (req, res) => {
res.send(await coursesQuery(req))
})

router.use('/process', processes)

module.exports = router
module.exports.ModelSchemas = ModelSchemas
23 changes: 17 additions & 6 deletions server/controllers/public/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@ const EventPhdCourse = require('../../models/EventPhdCourse')

async function coursesQuery(req) {
const pipeline = [
{$unwind: '$lessons'},
{$lookup: {
from: 'conferencerooms',
localField: 'lessons.conferenceRoom',
as: 'lessons.conferenceRoom',
foreignField: '_id'
}},
{ $project: {
_id: 1,
speaker: 1,
lecturer: 1,
lecturers: 1,
title: 1,
lessons: 1,
}},
]

// console.log(JSON.stringify({pipeline}))
lessons: {
date: 1,
duration: 1,
conferenceRoom: {
name: 1
}
}
}}
];

const courses = await EventPhdCourse.aggregate(pipeline)

Expand Down
10 changes: 10 additions & 0 deletions server/processes.js
Original file line number Diff line number Diff line change
@@ -0,0 +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')
})

module.exports = router
2 changes: 1 addition & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if (config.OAUTH2_CLIENT_ID) {
function setup_routes(app) {
app.use(cors(
{
origin: config.CORS_ORIGIN.split(","),
origin: config.CORS_ORIGIN,
optionsSuccessStatus: 200,
credentials: true // Needed for the client to handle session
}))
Expand Down
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Models from './models/Models'
import { Container } from 'react-bootstrap'
import {QueryClient, QueryClientProvider } from 'react-query'
import FormFillPage from './pages/FormFillPage'
import AddSeminar from './processes/AddSeminar';


console.log("dm-manager (app starting)")
Expand Down Expand Up @@ -55,6 +56,7 @@ function Internal() {
<Routes>
<Route path="/" element={<Home />} />
<Route path="/profile" element={<Profile />} />
<Route path="/process/seminar/add" element={<AddSeminar/>}></Route>
{ Object.values(Models).map(x => x.routers()) }
<Route path="/map" element={<Map />} />
<Route path="*" element={<NotFound />} />
Expand Down
83 changes: 83 additions & 0 deletions src/processes/AddSeminar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { Button, Card, Form } from 'react-bootstrap'
import { ModelInput } from '../components/ModelInput'
import { useState } from 'react'

export default function AddSeminar() {
const [speaker, setSpeaker] = useState(null)
const [speakerBlockDisabled, setSpeakerBlockDisabled] = useState(false)
const [seminarDetailsBlockDisabled, setSeminarDetailsBlockDisabled] = useState(true)

const onSpeakerSelected = x => {
setSpeaker(x)
setSpeakerBlockDisabled(true)
setSeminarDetailsBlockDisabled(false)
}

const speakerBlock = <div className={speakerBlockDisabled ? "d-none" : "d-block"}>
<SelectPersonBlock onCompleted={onSpeakerSelected}></SelectPersonBlock>
</div>;

const seminarDetails = <div className={seminarDetailsBlockDisabled ? "d-none" : "d-block"}>
<SeminarDetailsBlock speaker={speaker}></SeminarDetailsBlock>
</div>

return <div>
<h1 className="text-primary pb-4">Nuovo Seminario</h1>
{speakerBlock}
{seminarDetails}
</div>;
}

function SeminarDetailsBlock({ speaker, onCompleted }) {
const [confirm] = useState(false)

return <Card className="shadow">
<Card.Header>Dettagli del seminario [speaker: <strong>{speaker?.firstName} {speaker?.lastName}</strong>]</Card.Header>
<Card.Body>
<Form>
<Form.Group className="my-3">
<ModelInput field="Titolo" schema={{ type: "string" }}></ModelInput>
</Form.Group>
<Form.Group className="my-3">
<ModelInput field="Data e ora" schema={{ format: "date-time", widget: "datetime" }}></ModelInput>
</Form.Group>
<Form.Group className="my-3">
<ModelInput field="Durata (in minuti)" schema={{ type: "number" }}></ModelInput>
</Form.Group>
<Form.Group className="my-3">
<ModelInput field="Aula" schema={{ "x-ref": "ConferenceRoom" }}></ModelInput>
</Form.Group>
</Form>
<div className="d-flex flex-row justify-content-end">
<Button className="text-end" onClick={() => onCompleted()} disabled={! confirm}>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)
}

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

</div>
}

0 comments on commit 87df175

Please sign in to comment.