Skip to content

Commit

Permalink
Merge pull request #53 from maingockien01/calendar
Browse files Browse the repository at this point in the history
Calendar added
  • Loading branch information
ntt2402vn authored Feb 28, 2024
2 parents 2a28995 + 04d41e2 commit c7f49d3
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 39 deletions.
44 changes: 24 additions & 20 deletions apps/SQL queries/section.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,33 @@
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

INSERT INTO `section` (`sid`, `sectionName`, `time`, `professor`, `courseCid`, `termTid`, `locationLid`) VALUES
(1, 'A02', '8:00 PM', 'Robert', 1, 1, 2);
(1, 'A02', 'M20:00-21:00,W20:00-21:00,F20:00-21:00', 'Robert', 1, 1, 2);
INSERT INTO `section` (`sid`, `sectionName`, `time`, `professor`, `courseCid`, `termTid`, `locationLid`) VALUES
(2, 'B01', '10:00 AM', 'Jennifer', 2, 2, 5);
(2, 'B01', 'M10:00-11:00,W10:00-11:00,F10:00-11:00', 'Jennifer', 2, 2, 5);
INSERT INTO `section` (`sid`, `sectionName`, `time`, `professor`, `courseCid`, `termTid`, `locationLid`) VALUES
(3, 'C03', '1:00 PM', 'Michael', 3, 3, 7);
(3, 'C03', 'M13:00-14:00,W13:00-14:00,F13:00-14:00', 'Michael', 3, 3, 7);
INSERT INTO `section` (`sid`, `sectionName`, `time`, `professor`, `courseCid`, `termTid`, `locationLid`) VALUES
(4, 'D01', '9:00 AM', 'Emily', 4, 4, 9),
(5, 'E02', '2:00 PM', 'David', 5, 5, 11),
(6, 'F01', '11:00 AM', 'Jessica', 6, 6, 13),
(7, 'G03', '3:00 PM', 'Christopher', 7, 7, 15),
(8, 'H01', '10:00 AM', 'Sarah', 8, 8, 17),
(9, 'I02', '12:00 PM', 'Daniel', 9, 9, 19),
(10, 'J01', '11:00 AM', 'Karen', 10, 10, 20),
(11, 'K03', '2:00 PM', 'Andrew', 11, 1, 3),
(12, 'L01', '9:00 AM', 'Michelle', 12, 2, 6),
(13, 'M02', '11:00 AM', 'William', 13, 3, 8),
(14, 'N01', '10:00 AM', 'Elizabeth', 14, 4, 10),
(15, 'O03', '3:00 PM', 'John', 15, 5, 12),
(16, 'P01', '1:00 PM', 'Amanda', 16, 6, 14),
(17, 'Q02', '12:00 PM', 'Kevin', 17, 7, 16),
(18, 'R01', '10:00 AM', 'Rachel', 18, 8, 18),
(19, 'S03', '2:00 PM', 'Thomas', 19, 9, 2),
(20, 'T01', '11:00 AM', 'Laura', 20, 10, 4);
(4, 'D01', 'M09:00-10:00,W09:00-10:00,F09:00-10:00', 'Emily', 4, 4, 9),
(5, 'E02', 'M14:00-15:00,W14:00-15:00,F14:00-15:00', 'David', 5, 5, 11),
(6, 'F01', 'M11:00-12:00,W11:00-12:00,F11:00-12:00', 'Jessica', 6, 6, 13),
(7, 'G03', 'M15:00-16:00,W15:00-16:00,F15:00-16:00', 'Christopher', 7, 7, 15),
(8, 'H01', 'M10:00-11:00,W10:00-11:00,F10:00-11:00', 'Sarah', 8, 8, 17),
(9, 'I02', 'M12:00-13:00,W12:00-13:00,F12:00-13:00', 'Daniel', 9, 9, 19),
(10, 'J01', 'M11:00-12:00,W11:00-12:00,F11:00-12:00', 'Karen', 10, 10, 20),
(11, 'K03', 'M14:00-15:00,W14:00-15:00,F14:00-15:00', 'Andrew', 11, 1, 3),
(12, 'L01', 'M09:00-10:00,W09:00-10:00,F09:00-10:00', 'Michelle', 12, 2, 6),
(13, 'M02', 'M11:00-12:00,W11:00-12:00,F11:00-12:00', 'William', 13, 3, 8),
(14, 'N01', 'M10:00-11:00,W10:00-11:00,F10:00-11:00', 'Elizabeth', 14, 4, 10),
(15, 'O03', 'M15:00-16:00,W15:00-16:00,F15:00-16:00', 'John', 15, 5, 12),
(16, 'P01', 'M13:00-14:00,W13:00-14:00,F13:00-14:00', 'Amanda', 16, 6, 14),
(17, 'Q02', 'M12:00-13:00,W12:00-13:00,F12:00-13:00', 'Kevin', 17, 7, 16),
(18, 'R01', 'R10:00-11:00,F10:00-11:00', 'Rachel', 18, 8, 18),
(19, 'S03', 'R14:00-15:00,F14:00-15:00', 'Thomas', 19, 9, 2),
(20, 'T01', 'R11:00-12:00,F11:00-12:00', 'Laura', 20, 10, 4);





/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
Expand Down
3 changes: 2 additions & 1 deletion apps/backend/src/entities/section.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export class Section {

@Column()
sectionName: string;


// Start time of the section
@Column()
time: string;

Expand Down
101 changes: 85 additions & 16 deletions apps/frontend/src/Screens/Calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,97 @@
import React, { useState } from "react";
import React, { useEffect, useRef, useState } from "react";
import Container from '@mui/material/Container';
// eslint-disable-next-line
// @ts-ignore
import { DayPilotCalendar } from "@daypilot/daypilot-lite-react";
import Timetable from 'react-timetable-events';
import { getCurrentUserID } from "../Utils/getCurrentUserID";
import { SectionDTO } from '@team8/types/dtos/section/section.dto'

interface Class {
id: number,
name: string,
startTime: Date,
endTime: Date
}
const dayMappings: {
[key: string]: string;
} = {
M: "monday",
T: "tuesday",
W: "wednesday",
R: "thursday",
F: "friday"
};

let weeklySchedule: {
[K: string]:
any
} = {
monday: [],
tuesday: [],
wednesday: [],
thursday: [],
friday: []
}

const Calendar = () => {
const [config, setConfig] = useState({
viewType: "WorkWeek",
headerDateFormat: "dddd",
businessBeginsHour: 8,
businessEndsHour: 17,
timeRangeSelectedHandling: "Disabled",
eventMoveHandling: "Disabled",
eventResizeHandling: "Disabled",
eventClickHandling: "Disabled",
});
const [courses, setCourses] = useState<any>(null);
const [timetable, setTimetable] = useState({
monday: [], // "M"
tuesday: [],
wednesday: [],
thursday: [],
friday: [],
})

useEffect(() => {
let uid = getCurrentUserID();
fetch('/rest-api/term/searchCurrent')
.then((res) => res.json())
.then((tid) => {
return fetch(`/rest-api/user/searchActive?uid=1&tid=${tid}`);
})
.then((res) => res.json())
.then((res) => {
for (let i = 0; i < res.length; i++) {
console.log(res[i])
const events = res[i].time.split(',');
let day = [];
for(const e of events){
let dayAbbr = e.charAt(0);
let dayName = dayMappings[dayAbbr];
let [st, et] = e.substring(1).split('-');

// Construct the date strings
let startDateStr = `2020-12-12T${st}:00`;
let endDateStr = `2020-12-12T${et}:00`;
// Create the date objects
let startTime = new Date(startDateStr);
let endTime = new Date(endDateStr);

return(
setTimetable(weeklySchedule[dayName].push({
id: 1,
name: res[i].courseName + ' [' + res[i].location +']',
startTime: startTime,
endTime: endTime
}))
}
}
})
.catch((error) => {
console.error('Error fetching data:', error);
});
}, []);

return(
<Container maxWidth = "lg">
<h2>
Weekly Schedule
</h2>
<DayPilotCalendar {...config} />
<Timetable
events={ weeklySchedule }
style={{ height: '500px'}}
/>
</Container>
);

}

export default Calendar;
16 changes: 16 additions & 0 deletions apps/frontend/src/Utils/getCurrentUserID.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export function getCurrentUserID() {
let uidHeader = "uid=";
let cookie = decodeURIComponent(document.cookie);
let cookieItems = cookie.split(';');

for(let i = 0; i < cookieItems.length; i++){
let currItem = cookieItems[i];
while(currItem.charAt(0) == ' '){
currItem = currItem.substring(1);
}
if(currItem.indexOf(uidHeader) == 0){
return currItem.substring(uidHeader.length, currItem.length);
}
}
return "";
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"typescript": "^5.1.3"
},
"dependencies": {
"@daypilot/daypilot-lite-react": "^3.20.1"
"@daypilot/daypilot-lite-react": "^3.20.1",
"react-timetable-events": "^2.0.0"
}
}
17 changes: 16 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@
resolved "https://registry.yarnpkg.com/@babel/regjsgen/-/regjsgen-0.8.0.tgz#f0ba69b075e1f05fb2825b7fad991e7adbb18310"
integrity sha512-x/rqGMdzj+fWZvCOYForTghzbtqPDZ5gPwaoNGHdgDfF2QA/XZbCBp4Moo5scrkAMPhB7z26XM/AaHuIJdgauA==

"@babel/runtime@^7.12.5", "@babel/runtime@^7.18.3", "@babel/runtime@^7.23.2", "@babel/runtime@^7.23.9", "@babel/runtime@^7.5.5", "@babel/runtime@^7.8.4", "@babel/runtime@^7.8.7":
"@babel/runtime@^7.12.5", "@babel/runtime@^7.18.3", "@babel/runtime@^7.21.0", "@babel/runtime@^7.23.2", "@babel/runtime@^7.23.9", "@babel/runtime@^7.5.5", "@babel/runtime@^7.8.4", "@babel/runtime@^7.8.7":
version "7.23.9"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.23.9.tgz#47791a15e4603bb5f905bc0753801cf21d6345f7"
integrity sha512-0CX6F+BI2s9dkUqr08KFrAIZgNFj75rdBU/DjCyYLIaV/quFjkk6T+EJ2LkZHyZTbEV4L5p97mNkUsHl2wLFAw==
Expand Down Expand Up @@ -4105,6 +4105,13 @@ data-urls@^3.0.2:
whatwg-mimetype "^3.0.0"
whatwg-url "^11.0.0"

date-fns@^2.28.0:
version "2.30.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.30.0.tgz#f367e644839ff57894ec6ac480de40cae4b0f4d0"
integrity sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==
dependencies:
"@babel/runtime" "^7.21.0"

dayjs@^1.11.9:
version "1.11.10"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.10.tgz#68acea85317a6e164457d6d6947564029a6a16a0"
Expand Down Expand Up @@ -7276,6 +7283,14 @@ react-test-renderer@^18.2.0:
react-shallow-renderer "^16.15.0"
scheduler "^0.23.0"

react-timetable-events@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/react-timetable-events/-/react-timetable-events-2.0.0.tgz#2648397171865aee8561e86fd50300669d7af6cf"
integrity sha512-fiMHxor1kILwn1sB4y1zAzy++CSPokDZijkZFMk2q/D6AtUtJwK879LNlkyufEqXDRrYfllyx2tF7SHhWqmCbg==
dependencies:
date-fns "^2.28.0"
lodash "^4.17.21"

react-transition-group@^4.4.5:
version "4.4.5"
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-4.4.5.tgz#e53d4e3f3344da8521489fbef8f2581d42becdd1"
Expand Down

0 comments on commit c7f49d3

Please sign in to comment.