ThemeEditorModal.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 I18n from 'i18n!theme_editor'
  19. import React from 'react'
  20. import PropTypes from 'prop-types'
  21. import Modal from 'react-modal'
  22. import ProgressBar from 'jsx/shared/ProgressBar'
  23. Modal.setAppElement(document.body)
  24. const modalOverrides = {
  25. overlay : {
  26. backgroundColor: 'rgba(0,0,0,0.5)'
  27. },
  28. content : {
  29. position: 'static',
  30. top: '0',
  31. left: '0',
  32. right: 'auto',
  33. bottom: 'auto',
  34. borderRadius: '0',
  35. border: 'none',
  36. padding: '0'
  37. }
  38. };
  39. export default React.createClass({
  40. displayName: 'ThemeEditorModal',
  41. propTypes: {
  42. showProgressModal: PropTypes.bool,
  43. showSubAccountProgress: PropTypes.bool,
  44. progress: PropTypes.number,
  45. activeSubAccountProgresses: PropTypes.array,
  46. },
  47. modalOpen(){
  48. return this.props.showProgressModal ||
  49. this.props.showSubAccountProgress
  50. },
  51. modalContent(){
  52. if (this.props.showProgressModal) {
  53. return this.previewGenerationModalContent();
  54. } else if (this.props.showSubAccountProgress) {
  55. return this.subAccountModalContent();
  56. }
  57. },
  58. previewGenerationModalContent() {
  59. return (
  60. <div className="ReactModal__Layout">
  61. <header className="ReactModal__Header">
  62. <div className="ReactModal__Header-Title">
  63. <h3>{I18n.t('Generating preview...')}</h3>
  64. </div>
  65. </header>
  66. <div className="ReactModal__Body">
  67. <ProgressBar
  68. progress={this.props.progress}
  69. title={I18n.t('%{percent} complete', {
  70. percent: I18n.toPercentage(this.props.progress, {precision: 0})
  71. })}
  72. />
  73. </div>
  74. </div>
  75. )
  76. },
  77. subAccountModalContent(){
  78. return (
  79. <div className="ReactModal__Layout">
  80. <header className="ReactModal__Header">
  81. <div className="ReactModal__Header-Title">
  82. <h3>{I18n.t('Applying new styles to subaccounts')}</h3>
  83. </div>
  84. </header>
  85. <div className="ReactModal__Body">
  86. <p>
  87. {I18n.t('Changes will still apply if you leave this page.')}
  88. </p>
  89. <ul className="unstyled_list">
  90. {this.props.activeSubAccountProgresses.map(this.subAccountProgressBar)}
  91. </ul>
  92. </div>
  93. </div>
  94. );
  95. },
  96. subAccountProgressBar(progress){
  97. return (
  98. <li className="Theme-editor-progress-list-item">
  99. <div className="Theme-editor-progress-list-item__title">
  100. {I18n.t('%{account_name}', {account_name: this.messageToName(progress.message)} )}
  101. </div>
  102. <div className="Theme-editor-progress-list-item__bar">
  103. <ProgressBar
  104. progress={progress.completion}
  105. title={I18n.t('Progress for %{account_name}', {
  106. account_name: this.messageToName(progress.message)
  107. })
  108. }
  109. />
  110. </div>
  111. </li>
  112. );
  113. },
  114. messageToName(message){
  115. return message.indexOf("Syncing for") > -1 ?
  116. message.replace("Syncing for ", "") :
  117. I18n.t("Unknown Account")
  118. },
  119. render() {
  120. return (
  121. <Modal
  122. isOpen={this.modalOpen()}
  123. className={
  124. (this.props.showProgressModal ? 'ReactModal__Content--canvas ReactModal__Content--mini-modal' : 'ReactModal__Content--canvas')
  125. }
  126. style={modalOverrides}
  127. >
  128. {this.modalContent()}
  129. </Modal>
  130. );
  131. }
  132. })