-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Further work on the react components.
- Loading branch information
Showing
7 changed files
with
210 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const ObjectId = require('mongoose').Types.ObjectId | ||
const EventConference = require('../../models/EventConference') | ||
|
||
const maxDate = new Date(8640000000000000); | ||
|
||
async function conferencesQuery(req) { | ||
const from = req.query.from ? new Date(req.query.from) : new Date() | ||
const to = req.query.to ? new Date(req.query.to) : maxDate | ||
|
||
var match = { | ||
startDate: { | ||
$gte: from, | ||
$lt: to, | ||
}, | ||
} | ||
|
||
if (req.query.grant) { | ||
match["grant"] = ObjectId(req.query.grant) | ||
} | ||
|
||
const pipeline = [ | ||
{ $match: match }, | ||
{ $lookup: { | ||
from: 'conferencerooms', | ||
foreignField: '_id', | ||
localField: 'conferenceRoom', | ||
as: 'conferenceRoom' | ||
}}, | ||
{ $unwind: '$conferenceRoom' }, | ||
{ $lookup: { | ||
from: 'grants', | ||
foreignField: '_id', | ||
localField: 'grant', | ||
as: 'grant' | ||
}}, | ||
{ $project: { | ||
_id: 1, | ||
title: 1, | ||
startDate: 1, | ||
endDate: 1, | ||
SSD: 1, | ||
url: 1, | ||
conferenceRoom: 1, | ||
notes: 1 | ||
}} | ||
] | ||
|
||
const conferences = await EventConference.aggregate(pipeline) | ||
|
||
return { | ||
data: conferences | ||
} | ||
} | ||
|
||
module.exports = conferencesQuery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react' | ||
import axios from 'axios' | ||
import { truncateText, getManageURL, getDMURL } from '../utils' | ||
import { ConferenceTitle } from './Conference' | ||
import { Loading } from './Loading' | ||
|
||
import Markdown from 'react-markdown' | ||
import rehypeKatex from 'rehype-katex' | ||
import remarkMath from 'remark-math' | ||
import { useQuery } from 'react-query' | ||
|
||
export function ConferenceList({ from, to, grant }) { | ||
const filter = { from, to, grant } | ||
|
||
const { isLoading, error, data } = useQuery([ 'conferences' ], async () => { | ||
const res = await axios.get(getManageURL("public/conferences"), { params: filter }) | ||
if (res.data) { | ||
const ee = res.data.data | ||
ee.sort((a,b) => new Date(a.startDatetime) - new Date(b.startDatetime)) | ||
return ee | ||
} | ||
}) | ||
|
||
if (isLoading || error) { | ||
return <Loading widget="Lista delle conferenze" error={error}></Loading> | ||
} | ||
|
||
var events_block = [] | ||
for (var i = 0; i < data.length; i++) { | ||
const e = data[i] | ||
const link = getDMURL("conferenza?id=" + e._id) | ||
|
||
events_block.push( | ||
<div key={e._id}> | ||
<ConferenceTitle conference={e} href={link}></ConferenceTitle> | ||
<Markdown remarkPlugins={[remarkMath]} rehypePlugins={[rehypeKatex]}>{truncateText(e.notes, 200)}</Markdown> | ||
<hr className="my-4"></hr> | ||
</div> | ||
) | ||
} | ||
|
||
return <> | ||
{events_block} | ||
</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,83 @@ | ||
import React from 'react' | ||
import { useEffect, useState } from 'react' | ||
import axios from 'axios' | ||
import { formatPersonName, formatDate, formatTime, truncateText, getManageURL } from '../utils' | ||
import { MathJax, MathJaxContext } from 'better-react-mathjax' | ||
|
||
export function EventList({ filter }) { | ||
const [events, setEvents] = useState(null) | ||
|
||
useEffect(() => { | ||
const loader = async () => { | ||
if (events === null) { | ||
const res = await axios.get(getManageURL("public/seminars", filter)) | ||
if (res.data) { | ||
const ee = res.data.data | ||
ee.sort((a,b) => new Date(a.startDatetime) - new Date(b.startDatetime)) | ||
setEvents(ee) | ||
} | ||
} | ||
import { truncateText, getManageURL, getDMURL } from '../utils' | ||
import { ConferenceTitle } from './Conference' | ||
import { SeminarTitle } from './Seminar' | ||
import { Loading } from './Loading' | ||
|
||
import Markdown from 'react-markdown' | ||
import rehypeKatex from 'rehype-katex' | ||
import remarkMath from 'remark-math' | ||
import { useQuery } from 'react-query' | ||
|
||
export function EventList({ from, to, grant }) { | ||
const filter = { from, to, grant } | ||
|
||
const { isLoading, error, data } = useQuery([ 'events' ], async () => { | ||
var events = [] | ||
|
||
const conf = await axios.get(getManageURL("public/conferences"), { params: filter }) | ||
if (conf.data) { | ||
const ec = conf.data.data | ||
const ec_label = ec.map(x => { | ||
return {...x, type: 'conference'} | ||
}) | ||
events.push(...ec_label) | ||
} | ||
|
||
const sem = await axios.get(getManageURL("public/seminars"), { params: filter }) | ||
if (sem.data) { | ||
const es = sem.data.data | ||
const es_label = es.map(x => { | ||
return {...x, type: 'seminar'} | ||
}) | ||
events.push(...es_label) | ||
} | ||
loader() | ||
|
||
events.sort((a, b) => { | ||
const dateA = a.startDatetime ? a.startDatetime : a.startDate | ||
const dateB = b.startDatetime ? b.startDatetime : b.startDate | ||
return new Date(dateA) - new Date(dateB) | ||
}) | ||
|
||
return events | ||
}) | ||
|
||
if (events === null) { | ||
return <> | ||
Loading events ... | ||
</> | ||
if (isLoading || error) { | ||
return <Loading widget="Lista degli eventi" error={error}></Loading> | ||
} | ||
|
||
var events_block = [] | ||
for (var i = 0; i < events.length; i++) { | ||
const e = events[i] | ||
events_block.push( | ||
<div key={e._id}> | ||
<h4><MathJax>{e.title}</MathJax>, {formatPersonName(e.speaker)}</h4> | ||
<p> | ||
{formatDate(e.startDatetime)} — {e.conferenceRoom?.name} | ||
</p> | ||
<p> | ||
<MathJax>{truncateText(e.abstract, 200)}</MathJax> | ||
</p> | ||
</div> | ||
) | ||
for (var i = 0; i < data.length; i++) { | ||
const e = data[i] | ||
|
||
if (e.type == 'seminar') { | ||
const e = data[i] | ||
const link = getDMURL("seminario?id=" + e._id) | ||
|
||
events_block.push( | ||
<div key={e._id}> | ||
<SeminarTitle seminar={e} href={link}></SeminarTitle> | ||
<Markdown remarkPlugins={[remarkMath]} rehypePlugins={[rehypeKatex]}>{truncateText(e.abstract, 200)}</Markdown> | ||
<hr className="my-4"></hr> | ||
</div> | ||
) | ||
} | ||
else { | ||
const link = getDMURL("conferenza?id=" + e._id) | ||
events_block.push( | ||
<div key={e._id}> | ||
<ConferenceTitle conference={e} href={link}></ConferenceTitle> | ||
<Markdown remarkPlugins={[remarkMath]} rehypePlugins={[rehypeKatex]}>{truncateText(e.notes, 200)}</Markdown> | ||
<hr className="my-4"></hr> | ||
</div> | ||
) | ||
} | ||
|
||
|
||
} | ||
|
||
return <MathJaxContext> | ||
return <> | ||
{events_block} | ||
</MathJaxContext> | ||
</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters