Newer
Older
import DegreeCourseItem from "./DegreeCourseItem";
import DeleteDegreeCourseModal from './DeleteDegreeCourseModal'
import EditDegreeCourse from './EditDegreeCourse'
import CreateNewDegreeCourse from './CreateNewDegreeCourse'
import addIcon from '../../icons/addIcon.png'
import Button from "react-bootstrap/esm/Button";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import * as degreeCourseManagementActions from '../../actions/DegreeCourseManagementActions'
const mapStateToProps = state => {
return {
showDeleteDegreeCourseModal: state.DegreeCourseReducer.showDeleteDegreeCourseModal,
degreeCourseList: state.DegreeCourseReducer.degreeCourseList
};
}
const DISPLAY = {
LIST: "list",
EDIT: "edit",
CREATE: "create"
}
class DegreeCourseManagement extends Component {
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
constructor(props) {
super(props);
this.state = {
displayingPage: DISPLAY.LIST,
editingDegreeCourse: null
}
this.MapAllDegreeCourses = this.MapAllDegreeCourses.bind(this);
this.handleShowDeleteModal = this.handleShowDeleteModal.bind(this);
this.handleClose = this.handleClose.bind(this);
this.handleSwitchToList = this.handleSwitchToList.bind(this);
this.handleShowCreatePage = this.handleShowCreatePage.bind(this);
}
handleShowDeleteModal(e, dialogModalData) {
e.preventDefault();
const { showDeleteDegreeCourseModalAction } = this.props
showDeleteDegreeCourseModalAction(dialogModalData)
}
handleShowEditPage(e, degreeCourse) {
e.preventDefault();
this.setState({ editingDegreeCourse: degreeCourse })
this.setState({ displayingPage: DISPLAY.EDIT })
}
handleShowCreatePage(e) {
e.preventDefault();
this.setState({ displayingPage: DISPLAY.CREATE })
}
handleSwitchToList() {
this.setState({ displayingPage: DISPLAY.LIST })
}
handleClose() {
const { hideDeleteDegreeCourseModalAction } = this.props;
hideDeleteDegreeCourseModalAction();
}
MapAllDegreeCourses() {
const allDegreeCourses = this.props.degreeCourseList
if (allDegreeCourses) {
var showDeleteDegreeCourseModal = this.props.showDeleteDegreeCourseModal
if (showDeleteDegreeCourseModal === undefined) {
showDeleteDegreeCourseModal = false
}
console.log("deleteModal:" + showDeleteDegreeCourseModal)
var degreeCourses = allDegreeCourses.map(degreeCourse => {
return (
<DegreeCourseItem key={degreeCourse.id} degreeCourse={degreeCourse} handleShowDeleteModal={this.handleShowDeleteModal} handleShowEditPage={this.handleShowEditPage}/>
)
})
console.log(degreeCourses)
return degreeCourses
}
}
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
var workspace
switch (this.state.displayingPage) {
case DISPLAY.LIST:
workspace =
(
<div id="DegreeCourseManagementPageListComponent">
<Button id="DegreeCourseManagementPageCreateDegreeCourseButton" onClick={this.handleShowCreatePage}>
<img alt="Add-DegreeCourse-Button" src={addIcon} style={{ width: '2rem' }}></img>
</Button>
{this.MapAllDegreeCourses()}
<DeleteDegreeCourseModal />
</div>)
break
case DISPLAY.CREATE:
workspace = <CreateNewDegreeCourse id="DegreeCourseManagementPageCreateComponent" goBack={this.handleSwitchToList} />
break
case DISPLAY.EDIT:
workspace = <EditDegreeCourse id="DegreeCourseManagementPageEditComponent" goBack={this.handleSwitchToList} editDegreeCourse={this.state.editingDegreeCourse} />
break
default:
workspace = <Button onClick={this.handleShowCreatePage}>
<img alt="Add-DegreeCourse-Button" src={addIcon} style={{ width: '2rem' }}></img>
</Button>
(<div id="DegreeCourseManagementPageListComponent">
<Button id="DegreeCourseManagementPageCreateDegreeCourseButton" onClick={this.handleShowCreatePage}>
<img alt="Add-DegreeCourse-Button" src={addIcon} style={{ width: '2rem' }}></img>
</Button>
{this.MapAllDegreeCourses()}
<DeleteDegreeCourseModal />
</div>)
}
<div id="DegreeCourseManagementPage" style={{ height: '50vw', backgroundColor: '#2b3648', padding: '2rem' }}>
{workspace}
const mapDispatchToProps = dispatch => bindActionCreators({
showDeleteDegreeCourseModalAction: degreeCourseManagementActions.getShowDeleteDegreeCourseModalAction,
hideDeleteDegreeCourseModalAction: degreeCourseManagementActions.getHideDeleteDegreeCourseModalAction
}, dispatch)
const ConnectedDegreeCourseManagement = connect(mapStateToProps, mapDispatchToProps)(DegreeCourseManagement)
export default ConnectedDegreeCourseManagement