IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
6.6KB

  1. import { h, Component } from 'preact';
  2. import WBBrowseDialogProjectList from 'wb-browse-dialog-project-list';
  3. import WBBrowseDialogCollectionList from 'wb-browse-dialog-collection-list';
  4. import WBBrowseDialogCollectionContent from 'wb-browse-dialog-collection-content';
  5. import WBBrowseDialogUserList from 'wb-browse-dialog-user-list';
  6. import linkState from 'linkstate';
  7. import { Router } from 'preact-router';
  8. import { createHashHistory } from 'history';
  9. //
  10. // internal URLs look like this
  11. //
  12. // /browse-dialog/browse/( owner-uuid )/( project-page )/( text-search )
  13. // /browse-dialog/users//( users-page )/( text-search )
  14. // /browse-dialog/shared-with-me//( project-page )/( collection-page )/( text-search )
  15. // /browse-dialog/content/( collection-uuid )//( content-page )/( text-search )
  16. //
  17. // general pattern therefore:
  18. // /browse-dialog/( mode )/( uuid )/( top-page )/( bottom-page )/( text-search )
  19. //
  20. // props:
  21. // selectMany: Boolean
  22. // selectWhat: [ 'file', 'directory' ]
  23. //
  24. // state:
  25. // selected: Array of UUID
  26. // textSearch: string
  27. // textSearchInput: string
  28. //
  29. class WBBrowseDialog extends Component {
  30. constructor(...args) {
  31. super(...args);
  32. this.state.history = [];
  33. this.state.selected = {};
  34. this.state.selectedOrder = [];
  35. const { currentUser } = this.props.app.state;
  36. this.state.currentUrl = '/browse-dialog/browse/' + currentUser.uuid;
  37. this.state.uuid = currentUser.uuid;
  38. this.state.mode = 'browse';
  39. this.state.topPage = 0;
  40. this.state.bottomPage = 0;
  41. }
  42. navigateBack() {
  43. if (this.state.history.length === 0)
  44. return;
  45. const url = this.state.history.pop();
  46. this.navigate(url, false);
  47. }
  48. navigate(url, useHistory=true) {
  49. if (typeof(url) === 'object') {
  50. url = ['', 'browse-dialog',
  51. 'mode' in url ? url.mode : this.state.mode,
  52. 'uuid' in url ? url.uuid : this.state.uuid,
  53. 'topPage' in url ? url.topPage : this.state.topPage,
  54. 'bottomPage' in url ? url.bottomPage : this.state.bottomPage,
  55. 'textSearch' in url ? url.textSearch : this.state.textSearch
  56. ].join('/');
  57. }
  58. url = url.substr(url.indexOf('/browse-dialog/'));
  59. if (useHistory)
  60. this.state.history.push(this.state.currentUrl);
  61. let [ _1, _2, mode, uuid, topPage, bottomPage, textSearch ] = url.split('/');
  62. topPage = parseInt(topPage, 10) || 0;
  63. bottomPage = parseInt(bottomPage, 10) || 0;
  64. this.setState({
  65. 'currentUrl': url,
  66. mode, uuid, topPage, bottomPage, textSearch
  67. });
  68. }
  69. select(uuid) {
  70. let { selected, selectedOrder } = this.state;
  71. if (uuid in selected) {
  72. const n = selectedOrder.indexOf(uuid);
  73. selectedOrder = selected.splice(n, n + 1);
  74. }
  75. selected[uuid] = true;
  76. selectedOrder.push(uuid);
  77. this.setState({
  78. selected, selectedOrder
  79. });
  80. }
  81. deselect(uuid) {
  82. let { selected, selectedOrder } = this.state;
  83. if (!(uuid in selected))
  84. return;
  85. const n = selectedOrder.indexOf(uuid);
  86. selectedOrder = selected.splice(n, n + 1);
  87. delete selected[uuid];
  88. this.setState({
  89. selected, selectedOrder
  90. });
  91. }
  92. resetSelection() {
  93. this.setState({
  94. 'selected': {},
  95. 'selectedOrder': []
  96. });
  97. }
  98. render({ app, id, selectMany, selectWhat }, { history, currentUrl, mode, uuid, topPage, bottomPage, textSearch }) {
  99. return (
  100. <div class="modal" id={ id } tabindex="-1" role="dialog">
  101. <div class="modal-dialog modal-lg" role="document">
  102. <div class="modal-content">
  103. <div class="modal-header">
  104. { false ? <h5 class="modal-title">Browse</h5> : null }
  105. <div>{ currentUrl }</div>
  106. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  107. <span aria-hidden="true">&times;</span>
  108. </button>
  109. </div>
  110. <div class="modal-body">
  111. <div class="mb-3">
  112. <a href="#" class={ 'btn btn-outline-secondary mr-2' +
  113. (history.length === 0 ? ' disabled': '') }
  114. onclick={ e => { e.preventDefault();
  115. this.navigateBack(); } }>Back</a>
  116. <a href="#" class="btn btn-outline-primary mr-2"
  117. onclick={ e => { e.preventDefault();
  118. this.navigate('/browse-dialog/browse/' + app.state.currentUser.uuid); } }>Home</a>
  119. <a href="#" class="btn btn-outline-primary mr-2">All Projects</a>
  120. <a href="#" class="btn btn-outline-primary mr-2">All Users</a>
  121. <a href="#" class="btn btn-outline-primary mr-2">Shared with Me</a>
  122. </div>
  123. <div class="input-group mb-3">
  124. <input type="text" class="form-control" placeholder="Search"
  125. aria-label="Search" value={ textSearch }
  126. onChange={ linkState(this, 'textSearch') } />
  127. <div class="input-group-append">
  128. <button class="btn btn-outline-primary" type="button">Search</button>
  129. </div>
  130. </div>
  131. { (mode === 'browse' || mode === 'shared-with-me') ? (
  132. <div>
  133. <h5>Projects</h5>
  134. <WBBrowseDialogProjectList app={ app }
  135. navigate={ url => this.navigate(url) }
  136. mode={ mode } ownerUuid={ uuid }
  137. page={ topPage } textSearch={ textSearch } />
  138. </div>
  139. ) : null }
  140. { (mode === 'users') ? (
  141. <WBBrowseDialogUserList app={ app } parent={ this } />
  142. ) : null }
  143. { (mode === 'content') ? (
  144. <div>
  145. <h5>Content</h5>
  146. <WBBrowseDialogCollectionContent app={ app } parent={ this }
  147. selectMany={ selectMany } selectWhat={ selectWhat }/>
  148. </div>
  149. ) : (mode === 'browse' || mode === 'shared-with-me') ? (
  150. <div>
  151. <h5>Collections</h5>
  152. <WBBrowseDialogCollectionList app={ app } parent={ this }
  153. selectMany={ selectMany } selectWhat={ selectWhat } />
  154. </div>
  155. ) : null }
  156. </div>
  157. <div class="modal-footer">
  158. <button type="button" class="btn btn-primary">Accept</button>
  159. <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
  160. </div>
  161. </div>
  162. </div>
  163. </div>
  164. );
  165. }
  166. }
  167. export default WBBrowseDialog;