Skip to content

Commit

Permalink
add grants home widget
Browse files Browse the repository at this point in the history
  • Loading branch information
c2d13p committed Dec 5, 2024
1 parent 213ecf2 commit c0225f0
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dm-manager",
"version": "1.10.1",
"version": "1.10.2",
"private": true,
"dependencies": {
"@babel/core": "^7.16.0",
Expand Down
4 changes: 2 additions & 2 deletions widgets/src/components/CourseList.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ export function CourseList({ from, to }) {
<>
<p>The list of Ph.D. courses that will be taught during the academic year {fromYear}-{toYear} is below:</p>
<div style={{ height: '5px' }} aria-hidden="true" className="wp-block-spacer"></div>
<h4 class="wp-block-heading">Fall/Winter Term</h4>
<h4 className="wp-block-heading">Fall/Winter Term</h4>
{renderCourses(fallCourses)}
<div style={{ height: '20px' }} aria-hidden="true" className="wp-block-spacer"></div>
<h4 class="wp-block-heading">Winter/Spring Term</h4>
<h4 className="wp-block-heading">Winter/Spring Term</h4>
{renderCourses(springCourses)}
</>
);
Expand Down
2 changes: 1 addition & 1 deletion widgets/src/components/Grant.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function Grant({ grant_id }) {
{data.budgetAmount && <>Budget: {data.budgetAmount} <br /></>}
{data.webSite && <>Website: <a href={data.webSite}>{data.webSite}</a></>}
</p>
<p class='mb-3'>
<p className='mb-3'>
{data.pi && data.pi.firstName && <><KeyPerson person={data.pi} title="Principal Investigator"></KeyPerson> <br /></>}
{data.localCoordinator && data.localCoordinator.firstName && (data.localCoordinator._id !== data.pi._id) && <KeyPerson person={data.localCoordinator} title="Local Coordinator"></KeyPerson>}
</p>
Expand Down
1 change: 0 additions & 1 deletion widgets/src/components/HomeEventList.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export function HomeEventList({}) {
const conf = await axios.get(getManageURL("public/conferences"), { params: { _limit: numberOfEntries, _sort: "startDate", from: now} })
if (conf.data) {
for (const e of conf.data.data) {
console.log(`Conference: ${e._id}`,e)
events[e._id] = {...e, type: 'conference'}
}
}
Expand Down
79 changes: 79 additions & 0 deletions widgets/src/components/HomeGrantList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React, { useState } from 'react';
import { Button } from 'react-bootstrap';
import { useQuery } from 'react-query';
import axios from 'axios';
import { Loading } from './Loading';
import {
formatDateInterval,
getManageURL,
getDMURL,
formatDate,
formatTime,
truncateTextByWords
} from '../utils';
import './styles.css';

export function HomeGrantList({}) {
const [numberOfEntries, setNumberOfEntries] = useState(6);

const { isLoading, error, data } = useQuery([ 'homegrants', numberOfEntries ], async () => {
const now = new Date()
now.setHours(0, 0, 0, 0)

const grants = await axios.get(getManageURL("public/grants"), { params: { _limit: numberOfEntries, _sort: "-budgetAmount", from: now} })
if (grants.data) {
return grants.data.data
}
})

if (isLoading || error) {
return <Loading widget="Lista dei grant" error={error}></Loading>
}

const all_grant_list = data.slice(0, numberOfEntries).map((x) => (
<GrantBox grant={x} key={x._id}></GrantBox>
));

const showButton = numberOfEntries <= all_grant_list.length;

return (
<div className="">
<div className="row">{all_grant_list}</div>
{showButton && (
<div className="d-flex flex-row justify-content-center">
<Button className="load-button" onClick={() => setNumberOfEntries(numberOfEntries + 3)}>
{'Load more'}
</Button>
</div>
)}
</div>
);
}

function GrantBox({ grant }) {
console.log(grant)
const date = grant.endDate
? formatDateInterval(grant.startDate, grant.endDate, 'en-US')
: `${formatDate(grant.startDatetime)} - ${formatTime(grant.startDatetime)}`;

const link = getDMURL(`en/research/grant-details/?grant_id=${grant._id}`);

var title = grant.name

return <div className="col-6 col-md-6 col-lg-4 event-box">
<h2 className="title_style">
<a href={link} className="title_style">
{truncateTextByWords(title, 20)}
</a>
<small className="text-muted"> ({grant.projectType})</small>
</h2>
{ grant.pi && grant.pi.firstName &&
<div className="subtitle_style fas fa-user"> Principal Investigator: {grant.pi.firstName} {grant.pi.lastName} </div>
}
{ grant.localCoordinator && grant.localCoordinator.firstName && (grant.localCoordinator._id !== grant.pi._id) &&
<div className="subtitle_style fas fa-user"> Local Coordinator: {grant.localCoordinator.firstName} {grant.localCoordinator.lastName} </div>
}
<div className="subtitle_style far fa-calendar"> {date}</div>
<div className="subtitle_style fas fa-coins"> {grant.budgetAmount}</div>
</div>
}
9 changes: 9 additions & 0 deletions widgets/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
data-target="#homeeventlist-tab" type="button" role="tab" aria-controls="homeeventlist"
aria-selected="false">HomeEventList</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#homegrantlist" id="homegrantlist-label" data-toggle="tab"
data-target="#homegrantlist-tab" type="button" role="tab" aria-controls="homegrantlist"
aria-selected="false">HomeGrantList</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#persondetails" id="persondetails-label" data-toggle="tab"
data-target="#persondetails-tab" type="button" role="tab" aria-controls="persondetails"
Expand Down Expand Up @@ -103,6 +108,7 @@
<div class="tab-pane fade p-3" id="conferencelist-tab"><div id="conferencelist"></div></div>
<div class="tab-pane fade p-3" id="conference-tab"><div id="conference"></div></div>
<div class="tab-pane fade p-3" id="homeeventlist-tab"><div id="homeeventlist"></div></div>
<div class="tab-pane fade p-3" id="homegrantlist-tab"><div id="homegrantlist"></div></div>
<div class="tab-pane fade p-3" id="persondetails-tab"><div id="persondetails"></div></div>
<div class="tab-pane fade p-3" id="courselist-tab"><div id="courselist"></div></div>
<div class="tab-pane fade p-3" id="grant-tab"><div id="grant"></div></div>
Expand Down Expand Up @@ -146,6 +152,9 @@
dmwidgets.loadComponent(document.getElementById('homeeventlist'), "HomeEventList", {
_limit: 10,
})
dmwidgets.loadComponent(document.getElementById('homegrantlist'), "HomeGrantList", {
_limit: 10,
})
dmwidgets.loadComponent(document.getElementById('persondetails'), "PersonDetails", {
person_id: '66471d4ef38d44852c3310e9',
})
Expand Down
4 changes: 4 additions & 0 deletions widgets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Conference } from './components/Conference'
import { ConferenceList } from './components/ConferenceList';
import { QueryClient, QueryClientProvider } from 'react-query'
import { HomeEventList } from './components/HomeEventList';
import { HomeGrantList } from './components/HomeGrantList';
import { PersonDetails } from './components/PersonDetails';
import { CourseList } from './components/CourseList';
import { Grant } from './components/Grant';
Expand Down Expand Up @@ -47,6 +48,9 @@ dmwidgets.loadComponent = (target, name, props = {}) => {
case 'HomeEventList':
element = <HomeEventList></HomeEventList>
break;
case 'HomeGrantList':
element = <HomeGrantList></HomeGrantList>
break;
case 'PersonDetails':
element = <PersonDetails {...props}></PersonDetails>
break;
Expand Down

0 comments on commit c0225f0

Please sign in to comment.