-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass.js
127 lines (121 loc) · 3.95 KB
/
Class.js
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
import React from "react";
import { DragSource } from "react-dnd";
import { Button, Col, Card, Modal, Popover } from "antd";
import { MovableTypes } from "./MovableTypes";
import { InfoCircleOutlined } from "@ant-design/icons";
import _ from "lodash";
import 'antd/dist/antd.css';
import courses_dictionary from "./data/courses_dictionary.json"
const spec = {
beginDrag(props, monitor, component) {
props.onDrag(props.name);
return component.props;
}
}
const collect = (connect, monitor) => {
return {
connectDragSource: connect.dragSource()
}
}
export const Class = DragSource(MovableTypes.CLASS, spec, collect) (class extends React.Component {
constructor(props){
super(props);
let hours = {};
_.forEach(courses_dictionary[this.props.name]["Hours"], (value, key) => {
hours[key] = parseFloat(value);
});
this.hours = (Object.keys(hours).map(c => (
c + ": " + hours[c]
))).toString().replace(/,/g, " | ");
this.state = {
modalState: false,
popState: false
}
}
render(){
const {connectDragSource} = this.props;
let cardStyle = {
width: 200,
backgroundColor: "#B4A76C"
};
let prereqStyle = {
color: "#000000",
fontWeight: "normal",
};
if(this.props.notsatisfied == true) {
cardStyle["backgroundColor"] = '#CA4949';
prereqStyle["color"] = "#CA4949";
prereqStyle["fontWeight"] = "bold";
}
return (connectDragSource(
<div>
<Popover content={
<div>
{courses_dictionary[this.props.name]["Course Title"]}
</div>
}>
<Col>
<Card onClick={()=>{this.showModal()}} onContextMenu={()=>{console.log(this.props.name)}} bordered={false} hoverable style={cardStyle} >
<h2>
<b>
<center>
{this.props.name}
</center>
</b>
</h2>
</Card>
</Col>
</Popover>
<Modal
visible={this.state.modalState}
onOk={() => { this.hideModal() }}
onCancel={() => { this.hideModal() }}
footer={[
<div style={{
whiteSpace: "pre-wrap"
}}>
{this.hours}
</div>
]}
>
<h2>
<b>
<center>
<a href={courses_dictionary[this.props.name]["url"]} target="_blank">
{this.props.name}: {courses_dictionary[this.props.name]["Course Title"]}
</a>
</center>
</b>
</h2>
<div>
{courses_dictionary[this.props.name]["Description"]}
<br /><br />
<div style={prereqStyle}>
Prerequisites: {courses_dictionary[this.props.name]["Prerequisites"].toUpperCase()}
</div>
</div>
</Modal>
</div>
));
}
showPop(){
this.setState({
popState: true
});
}
hidePop(){
this.setState({
popState: false
});
}
showModal(){
this.setState({
modalState: true
});
}
hideModal(){
this.setState({
modalState: false
});
}
});