SearchResults.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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!react_files'
  19. import _ from 'underscore'
  20. import React from 'react'
  21. import SearchResults from 'compiled/react_files/components/SearchResults'
  22. import NoResults from 'jsx/files/NoResults'
  23. import ColumnHeaders from 'jsx/files/ColumnHeaders'
  24. import Folder from 'compiled/models/Folder'
  25. import FolderChild from 'jsx/files/FolderChild'
  26. import LoadingIndicator from 'jsx/files/LoadingIndicator'
  27. import FilePreview from 'jsx/files/FilePreview'
  28. import page from 'page'
  29. import FocusStore from 'compiled/react_files/modules/FocusStore'
  30. SearchResults.displayErrors = function (errors) {
  31. var error_message= null
  32. if (errors != null) {
  33. error_message = errors.map(function (error) {
  34. return (
  35. <li>
  36. {error.message}
  37. </li>
  38. )
  39. })
  40. }
  41. return (
  42. <div>
  43. <p>
  44. {I18n.t({one: 'Your search encountered the following error:', other: 'Your search encountered the following errors:'}, {count: errors.length}) }
  45. </p>
  46. <ul>
  47. { error_message }
  48. </ul>
  49. </div>
  50. );
  51. }
  52. SearchResults.closeFilePreview = function (url) {
  53. page(url);
  54. FocusStore.setFocusToItem();
  55. }
  56. SearchResults.renderFilePreview = function () {
  57. if (this.props.query.preview != null && this.state.collection.length) {
  58. return (
  59. /*
  60. * Prepare and render the FilePreview if needed.
  61. * As long as ?preview is present in the url.
  62. */
  63. <FilePreview
  64. isOpen={true}
  65. params={this.props.params}
  66. query={this.props.query}
  67. collection={this.state.collection}
  68. usageRightsRequiredForContext={this.props.usageRightsRequiredForContext}
  69. splat={this.props.splat}
  70. closePreview={this.closeFilePreview}
  71. />
  72. )
  73. }
  74. }
  75. SearchResults.render = function () {
  76. if (this.state.errors) {
  77. return (this.displayErrors(this.state.errors))
  78. } else if (this.state.collection.loadedAll && (this.state.collection.length == 0)) {
  79. return (<NoResults search_term={this.props.query.search_term } />)
  80. } else {
  81. return (
  82. <div role='grid'>
  83. <div ref='accessibilityMessage' className='SearchResults__accessbilityMessage col-xs' tabIndex='0'>
  84. {I18n.t("Warning: For improved accessibility in moving files, please use the Move To Dialog option found in the menu.")}
  85. </div>
  86. <ColumnHeaders
  87. to='search'
  88. query= {this.props.query}
  89. params={this.props.params}
  90. pathname={this.props.pathname}
  91. toggleAllSelected={this.props.toggleAllSelected}
  92. areAllItemsSelected={this.props.areAllItemsSelected}
  93. usageRightsRequiredForContext={this.props.usageRightsRequiredForContext}
  94. />
  95. {
  96. this.state.collection.models.sort(Folder.prototype.childrenSorter.bind(this.state.collection, this.props.query.sort, this.props.query.order)).map((child) => {
  97. return (
  98. <FolderChild
  99. key={child.cid}
  100. model={child}
  101. isSelected={_.indexOf(this.props.selectedItems, child) >=0}
  102. toggleSelected={this.props.toggleItemSelected.bind(null, child)}
  103. userCanManageFilesForContext={this.props.userCanManageFilesForContext}
  104. userCanRestrictFilesForContext={this.props.userCanRestrictFilesForContext}
  105. usageRightsRequiredForContext={this.props.usageRightsRequiredForContext}
  106. externalToolsForContext={this.props.externalToolsForContext}
  107. previewItem={this.props.previewItem.bind(null, child)}
  108. dndOptions={this.props.dndOptions}
  109. modalOptions={this.props.modalOptions}
  110. clearSelectedItems={this.props.clearSelectedItems}
  111. onMove={this.props.onMove}
  112. />
  113. )
  114. })
  115. }
  116. <LoadingIndicator isLoading={!this.state.collection.loadedAll} />
  117. { this.renderFilePreview() }
  118. </div>
  119. )
  120. }
  121. };
  122. export default React.createClass(SearchResults)