Skip to content
21 changes: 8 additions & 13 deletions app/Database/Tables.hs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ data Time =
Time { weekDay :: Double,
startHour :: Double,
endHour :: Double,
firstRoom :: Maybe Location,
secondRoom :: Maybe Location
firstRoom :: Maybe Building,
secondRoom :: Maybe Building
} deriving (Show, Generic)

data Location =
Expand Down Expand Up @@ -323,8 +323,8 @@ convertTimeVals _ _ _ = (5.0, 25.0, 25.0)
-- | Convert Times into Time
buildTime :: Times -> SqlPersistM Time
buildTime t = do
room1 <- buildLocation (timesFirstRoom t)
room2 <- buildLocation (timesSecondRoom t)
room1 <- getBuilding (timesFirstRoom t)
room2 <- getBuilding (timesSecondRoom t)
return $ Time (timesWeekDay t)
(timesStartHour t)
(timesEndHour t)
Expand All @@ -340,8 +340,9 @@ buildTimes meetingKey t =
(firstRoom' t)
(secondRoom' t)

buildLocation :: Maybe T.Text -> SqlPersistM (Maybe Location)
buildLocation rm = do
-- | Given a building code, get the persistent Building associated with it
getBuilding :: Maybe T.Text -> SqlPersistM (Maybe Building)
getBuilding rm = do
case rm of
Nothing -> return Nothing
Just r -> do
Expand All @@ -350,10 +351,4 @@ buildLocation rm = do
Nothing -> return Nothing
Just entBuilding -> do
let building = entityVal entBuilding
return $ Just $ Location (T.take 2 r) -- Remove room number
(buildingName building)
(buildingCode building)
(buildingAddress building)
(buildingPostalCode building)
(buildingLat building)
(buildingLng building)
return $ Just building
116 changes: 54 additions & 62 deletions js/components/common/__tests__/GetTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ describe("getTable", () => {
{
endHour: 17,
firstRoom: {
address: "80 St. George Street",
bCode: "LM",
bName: "Lash Miller Chemical Laboratories",
lat: 43.66160185,
lng: -79.39841172598216,
postalCode: "M5S 3H6",
room: "LM 158",
buildingAddress: "80 St. George Street",
buildingCode: "LM",
buildingName: "Lash Miller Chemical Laboratories",
buildingLat: 43.66160185,
buildingLng: -79.39841172598216,
buildingPostalCode: "M5S 3H6",
},
secondRoom: null,
startHour: 15,
Expand All @@ -51,7 +50,7 @@ describe("getTable", () => {
availability: "31 of 69 available",
waitList: "0 students",
time: ["Tuesday 15 - 17"],
room: ["LM 158 "],
room: ["LM "],
},
]
expect(actual).toEqual(expected)
Expand All @@ -76,13 +75,12 @@ describe("getTable", () => {
{
endHour: 17,
firstRoom: {
address: "15 King's College Circle",
bCode: "UC",
bName: "University College",
lat: 43.66287995,
lng: -79.395181775127,
postalCode: "M5S 3H7",
room: "UC 179",
buildingAddress: "15 King's College Circle",
buildingCode: "UC",
buildingName: "University College",
buildingLat: 43.66287995,
buildingLng: -79.395181775127,
buildingPostalCode: "M5S 3H7",
},
secondRoom: null,
startHour: 16,
Expand All @@ -91,13 +89,12 @@ describe("getTable", () => {
{
endHour: 17,
firstRoom: {
address: "80 St. George Street",
bCode: "LM",
bName: "Lash Miller Chemical Laboratories",
lat: 43.66160185,
lng: -79.39841172598216,
postalCode: "M5S 3H6",
room: "LM 158",
buildingAddress: "80 St. George Street",
buildingCode: "LM",
buildingName: "Lash Miller Chemical Laboratories",
buildingLat: 43.66160185,
buildingLng: -79.39841172598216,
buildingPostalCode: "M5S 3H6",
},
secondRoom: null,
startHour: 15,
Expand All @@ -116,7 +113,7 @@ describe("getTable", () => {
availability: "31 of 69 available",
waitList: "0 students",
time: ["Tuesday 15 - 17", "Thursday 16 - 17"],
room: ["LM 158 ", "UC 179 "],
room: ["LM ", "UC "],
},
]

Expand All @@ -142,22 +139,20 @@ describe("getTable", () => {
{
endHour: 17,
firstRoom: {
address: "80 St. George Street",
bCode: "LM",
bName: "Lash Miller Chemical Laboratories",
lat: 43.66160185,
lng: -79.39841172598216,
postalCode: "M5S 3H6",
room: "LM 158",
buildingAddress: "80 St. George Street",
buildingCode: "LM",
buildingName: "Lash Miller Chemical Laboratories",
buildingLat: 43.66160185,
buildingLng: -79.39841172598216,
buildingPostalCode: "M5S 3H6",
},
secondRoom: {
address: "80 St. George Street",
bCode: "LM",
bName: "Lash Miller Chemical Laboratories",
lat: 43.66160185,
lng: -79.39841172598216,
postalCode: "M5S 3H6",
room: "UC 179",
buildingAddress: "15 King's College Circle",
buildingCode: "UC",
buildingName: "University College",
buildingLat: 43.66287995,
buildingLng: -79.395181775127,
buildingPostalCode: "M5S 3H7",
},
startHour: 15,
weekDay: 1,
Expand All @@ -175,7 +170,7 @@ describe("getTable", () => {
availability: "31 of 69 available",
waitList: "0 students",
time: ["Tuesday 15 - 17"],
room: ["LM 158, UC 179"],
room: ["LM, UC"],
},
]
expect(actual).toEqual(expected)
Expand All @@ -200,13 +195,12 @@ describe("getTable", () => {
{
endHour: 17,
firstRoom: {
address: "80 St. George Street",
bCode: "LM",
bName: "Lash Miller Chemical Laboratories",
lat: 43.66160185,
lng: -79.39841172598216,
postalCode: "M5S 3H6",
room: "LM 158",
buildingAddress: "80 St. George Street",
buildingCode: "LM",
buildingName: "Lash Miller Chemical Laboratories",
buildingLat: 43.66160185,
buildingLng: -79.39841172598216,
buildingPostalCode: "M5S 3H6",
},
secondRoom: null,
startHour: 15,
Expand All @@ -229,13 +223,12 @@ describe("getTable", () => {
{
endHour: 17,
firstRoom: {
address: "80 St. George Street",
bCode: "LM",
bName: "Lash Miller Chemical Laboratories",
lat: 43.66160185,
lng: -79.39841172598216,
postalCode: "M5S 3H6",
room: "LM 158",
buildingAddress: "80 St. George Street",
buildingCode: "LM",
buildingName: "Lash Miller Chemical Laboratories",
buildingLat: 43.66160185,
buildingLng: -79.39841172598216,
buildingPostalCode: "M5S 3H6",
},
secondRoom: null,
startHour: 15,
Expand All @@ -254,15 +247,15 @@ describe("getTable", () => {
availability: "31 of 69 available",
waitList: "0 students",
time: ["Tuesday 15 - 17"],
room: ["LM 158 "],
room: ["LM "],
},
{
activity: "LEC2001",
instructor: "A. Jacobson",
availability: "0 of 1 available",
waitList: "0 students",
time: ["Tuesday 15 - 17"],
room: ["LM 158 "],
room: ["LM "],
},
]
expect(actual).toEqual(expected)
Expand Down Expand Up @@ -308,13 +301,12 @@ describe("getTable", () => {
{
endHour: 17,
firstRoom: {
address: "80 St. George Street",
bCode: "LM",
bName: "Lash Miller Chemical Laboratories",
lat: 43.66160185,
lng: -79.39841172598216,
postalCode: "M5S 3H6",
room: "LM 158",
buildingAddress: "80 St. George Street",
buildingCode: "LM",
buildingName: "Lash Miller Chemical Laboratories",
buildingLat: 43.66160185,
buildingLng: -79.39841172598216,
buildingPostalCode: "M5S 3H6",
},
secondRoom: null,
startHour: 15,
Expand All @@ -333,7 +325,7 @@ describe("getTable", () => {
availability: "31 of 69 available",
waitList: "0 students",
time: ["Tuesday 15 - 17"],
room: ["LM 158 "],
room: ["LM "],
},
{
activity: "TUT0301",
Expand Down
30 changes: 14 additions & 16 deletions js/components/common/react_modal.js.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ class CourseModal extends React.Component {
if (occurrence.firstRoom === null || occurrence.firstRoom === undefined) {
firstRoom = " "
} else {
firstRoom = occurrence.firstRoom.room
firstRoom = occurrence.firstRoom.buildingCode
}

let secondRoom = ""
if (occurrence.secondRoom === null || occurrence.secondRoom === undefined) {
secondRoom = " "
} else {
secondRoom = occurrence.secondRoom.room
secondRoom = occurrence.secondRoom.buildingCode
}

if ((firstRoom != " ") & (secondRoom != " ")) {
Expand Down Expand Up @@ -483,7 +483,7 @@ class MapModal extends React.Component {
// their course codes
groupLecturesByBuilding(lecsByBuilding, lecture, roomNum) {
const foundBuilding = lecsByBuilding.find(
b => b.buildingName === lecture[roomNum].bName
b => b.buildingName === lecture[roomNum].buildingName
)

const timeframeData = {
Expand All @@ -503,12 +503,12 @@ class MapModal extends React.Component {
// if the building is not in the lecsByBuilding yet, add it into the array
if (!foundBuilding) {
lecsByBuilding.push({
buildingName: lecture[roomNum].bName,
buildingCode: lecture[roomNum].bCode,
address: lecture[roomNum].address,
lat: lecture[roomNum].lat,
lng: lecture[roomNum].lng,
postalCode: lecture[roomNum].postalCode,
buildingName: lecture[roomNum].buildingName,
buildingCode: lecture[roomNum].buildingCode,
address: lecture[roomNum].buildingAddress,
lat: lecture[roomNum].buildingLat,
lng: lecture[roomNum].buildingLng,
postalCode: lecture[roomNum].buildingPostalCode,
days: [dayData],
})
}
Expand Down Expand Up @@ -700,14 +700,12 @@ class DayBox extends React.Component {

getRoomStr(lec, room, roomNum) {
return (
"Room" +
"Location" +
(lec.fstRoom && lec.secRoom ? " " + roomNum : "") +
": " +
room.room +
", " +
room.bName +
room.buildingName +
" (" +
room.bCode +
room.buildingCode +
")"
)
}
Expand Down Expand Up @@ -875,8 +873,8 @@ class CampusMap extends React.Component {
let colouredMarker
const buildingInd = this.props.selectedLecTimeframes.findIndex(
lec =>
(lec.fstRoom && lec.fstRoom.bCode === building.buildingCode) ||
(lec.secRoom && lec.secRoom.bCode === building.buildingCode)
(lec.fstRoom && lec.fstRoom.buildingCode === building.buildingCode) ||
(lec.secRoom && lec.secRoom.buildingCode === building.buildingCode)
)

colouredMarker = buildingInd == -1 ? blueMarker : redMarker
Expand Down