-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathCourseSelect.js
More file actions
152 lines (140 loc) · 4.72 KB
/
CourseSelect.js
File metadata and controls
152 lines (140 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import React, { Component } from "react";
import {
ButtonBase,
Card,
CardContent,
IconButton,
Icon,
Modal,
Tooltip
} from "@material-ui/core";
import { withStyles } from "@material-ui/core/styles";
import "../../css/CourseSelect.css";
/**
* FUNC to position modal in the middle of the screen
*/
function getModalStyle() {
const top = 50;
const left = 50;
return {
top: `${top}%`,
left: `${left}%`,
transform: `translate(-${top}%, -${left}%)`,
maxWidth: "90%"
};
}
/**
* CSS for modal
*
* @param {*} theme Will use default theme if not provided
*/
const modelStyles = theme => ({
paper: {
position: "absolute",
width: theme.spacing(100),
maxWidth: "90%",
backgroundColor: theme.palette.background.paper,
boxShadow: theme.shadows[5],
padding: theme.spacing(4),
},
button: {
margin: theme.spacing(1),
}
});
/**
* React component for creating modal listing courses
*/
class CourseSelectModal extends Component {
/**
* Helper function to create card for a course modal.
* @param {object} course Object with course info
* @returns {HTMLElement} Card element of course
*/
helper = (course) => {
if (course) {
let id = course._id;
let shortname = course.shortname;
let name = course.name;
let description = course.description;
let link = "/course/" + shortname;
return (
<div key={id} id={id} title={name}
className="course-listing col-xs-12 col-md-6">
<Card raised="true">
<CardContent>
<a
tabIndex="0"
rel="noopener noreferrer"
role="button"
href={link}>
<h4>{name}</h4>
<p>{description}</p>
</a>
</CardContent>
</Card>
<br></br>
</div >
);
} else {
return null;
}
}
/**
* Render all of the elements
* @returns {HTMLElement} Course modal with the list of course cards
*/
render() {
const { classes } = this.props;
const courses = [].concat(this.props.courses);
const style = {
default: {
margin: 1,
marginTop: 8,
color: "#fff",
}
};
return (
<div>
{
!this.props.hideTooltip ?
<Tooltip title="Courses" placement="bottom-start">
<IconButton
onClick={this.props.handleCoursesToggle}
id="select-course"
size="small"
style={style.default}
className="header-btn d-none d-sm-block">
<Icon className="material-icons">school</Icon>
</IconButton >
</Tooltip>
: null
}
<Modal
aria-labelledby="simple-modal-title"
aria-describedby="simple-modal-description"
open={this.props.coursesOpen}
onClose={this.props.handleCoursesToggle} >
<div style={getModalStyle()} className={classes.paper}>
<ButtonBase
style={{ position: "absolute", right: 15, top: 15 }}
onClick={this.props.handleCoursesToggle} >
<Icon className="material-icons">clear</Icon>
</ButtonBase >
<h3 className="col-12 p-0 mb-3 border-bottom">Available Courses</h3>
<div className="row" id="courses">
{ // Sort the courses in alphabetical order
courses.sort(function (a, b) {
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
}).map(course => {
return this.helper(course);
})
}
</div>
</div>
</Modal >
</div >
);
}
}
const CourseSelect = withStyles(modelStyles)(CourseSelectModal);
export default CourseSelect;