ModerationApp.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2015 - present Instructure, Inc.
  3. *
  4. * This file is part of Canvas.
  5. *
  6. * Canvas is free software: you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License as published by the Free
  8. * Software Foundation, version 3 of the License.
  9. *
  10. * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. import _ from 'underscore'
  19. import React from 'react'
  20. import PropTypes from 'prop-types'
  21. import I18n from 'i18n!moderated_grading'
  22. import ModeratedStudentList from './ModeratedStudentList'
  23. import Header from './ModerationHeader'
  24. import FlashMessageHolder from './FlashMessageHolder'
  25. import Actions from './actions/ModerationActions'
  26. import ModeratedColumnHeader from './ModeratedColumnHeader'
  27. export default React.createClass({
  28. displayName: 'ModerationApp',
  29. propTypes: {
  30. store: PropTypes.object.isRequired,
  31. permissions: PropTypes.shape({
  32. viewGrades: PropTypes.bool.isRequired,
  33. editGrades: PropTypes.bool.isRequired
  34. }).isRequired
  35. },
  36. getInitialState () {
  37. return this.props.store.getState();
  38. },
  39. componentDidMount () {
  40. this.props.store.subscribe(this.handleChange);
  41. this.props.store.dispatch(Actions.apiGetStudents());
  42. },
  43. handleChange () {
  44. this.setState(this.props.store.getState());
  45. },
  46. handleCheckbox (student, event) {
  47. if (event.target.checked) {
  48. this.props.store.dispatch(Actions.selectStudent(student.id));
  49. } else {
  50. this.props.store.dispatch(Actions.unselectStudent(student.id));
  51. }
  52. },
  53. isModerationSet (students) {
  54. return !!(_.find(students, (student) => {
  55. return student.in_moderation_set;
  56. }));
  57. },
  58. handleSelectAll (event) {
  59. if (event.target.checked) {
  60. var allStudents = this.props.store.getState().students;
  61. this.props.store.dispatch(Actions.selectAllStudents(allStudents));
  62. } else {
  63. this.props.store.dispatch(Actions.unselectAllStudents());
  64. }
  65. },
  66. render () {
  67. return (
  68. <div className="ModerationApp">
  69. <FlashMessageHolder {...this.state.flashMessage} />
  70. <h1 className="screenreader-only">{I18n.t('Moderate %{assignment_name}', {assignment_name: this.state.assignment.title})}</h1>
  71. <Header
  72. onPublishClick={
  73. () => {
  74. this.props.store.dispatch(Actions.publishStarted());
  75. this.props.store.dispatch(Actions.publishGrades())
  76. }
  77. }
  78. onReviewClick={
  79. () => {
  80. this.props.store.dispatch(Actions.moderationStarted());
  81. this.props.store.dispatch(Actions.addStudentToModerationSet());
  82. }
  83. }
  84. published={this.state.assignment.published}
  85. selectedStudentCount={this.state.studentList.selectedCount}
  86. inflightAction={this.state.inflightAction}
  87. permissions={this.props.permissions}
  88. />
  89. <table width="100%" className="grade-moderation-table">
  90. <caption className="screenreader-only">{I18n.t('Clicking on the column headers will sort the rows by that column.')}</caption>
  91. <ModeratedColumnHeader
  92. includeModerationSetHeaders={this.isModerationSet(this.state.studentList.students)}
  93. sortDirection={this.state.studentList.sort.direction}
  94. markColumn={this.state.studentList.sort.column}
  95. store={this.props.store}
  96. handleSortMark1={() => this.props.store.dispatch(Actions.sortMark1Column())}
  97. handleSortMark2={() => this.props.store.dispatch(Actions.sortMark2Column())}
  98. handleSortMark3={() => this.props.store.dispatch(Actions.sortMark3Column())}
  99. handleSelectAll={this.handleSelectAll}
  100. permissions={this.props.permissions}
  101. />
  102. <ModeratedStudentList
  103. includeModerationSetColumns={this.isModerationSet(this.state.studentList.students)}
  104. handleCheckbox={this.handleCheckbox}
  105. onSelectProvisionalGrade={
  106. provisionalGradeId => this.props.store.dispatch(Actions.selectProvisionalGrade(provisionalGradeId))
  107. }
  108. studentList={this.state.studentList}
  109. assignment={this.state.assignment}
  110. urls={this.state.urls}
  111. />
  112. </table>
  113. </div>
  114. );
  115. }
  116. });