@girder/core 3.2.7 → 5.0.0-a6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/README.md +61 -0
  2. package/package.json +79 -31
  3. package/assets/Girder_Mark.png +0 -0
  4. package/auth.js +0 -152
  5. package/collections/ApiKeyCollection.js +0 -9
  6. package/collections/AssetstoreCollection.js +0 -9
  7. package/collections/Collection.js +0 -295
  8. package/collections/CollectionCollection.js +0 -9
  9. package/collections/FileCollection.js +0 -11
  10. package/collections/FolderCollection.js +0 -11
  11. package/collections/GroupCollection.js +0 -9
  12. package/collections/ItemCollection.js +0 -11
  13. package/collections/UserCollection.js +0 -24
  14. package/collections/index.js +0 -21
  15. package/constants.js +0 -33
  16. package/dialog.js +0 -128
  17. package/events.js +0 -6
  18. package/index.js +0 -31
  19. package/main.js +0 -21
  20. package/misc.js +0 -260
  21. package/models/AccessControlledModel.js +0 -76
  22. package/models/ApiKeyModel.js +0 -31
  23. package/models/AssetstoreModel.js +0 -43
  24. package/models/CollectionCreationPolicyModel.js +0 -20
  25. package/models/CollectionModel.js +0 -12
  26. package/models/FileModel.js +0 -310
  27. package/models/FolderModel.js +0 -33
  28. package/models/GroupModel.js +0 -197
  29. package/models/ItemModel.js +0 -72
  30. package/models/MetadataMixin.js +0 -88
  31. package/models/Model.js +0 -187
  32. package/models/UserModel.js +0 -189
  33. package/models/index.js +0 -25
  34. package/pluginUtils.js +0 -11
  35. package/rest.js +0 -216
  36. package/router.js +0 -58
  37. package/routes.js +0 -231
  38. package/stylesheets/apidocs/apidocs.styl +0 -50
  39. package/stylesheets/body/adminConsole.styl +0 -21
  40. package/stylesheets/body/assetstores.styl +0 -46
  41. package/stylesheets/body/collectionList.styl +0 -39
  42. package/stylesheets/body/collectionPage.styl +0 -6
  43. package/stylesheets/body/frontPage.styl +0 -48
  44. package/stylesheets/body/groupList.styl +0 -43
  45. package/stylesheets/body/groupPage.styl +0 -116
  46. package/stylesheets/body/itemPage.styl +0 -81
  47. package/stylesheets/body/plugins.styl +0 -61
  48. package/stylesheets/body/searchResultsList.styl +0 -51
  49. package/stylesheets/body/systemConfig.styl +0 -56
  50. package/stylesheets/body/userAccount.styl +0 -57
  51. package/stylesheets/body/userList.styl +0 -79
  52. package/stylesheets/body/userPage.styl +0 -6
  53. package/stylesheets/layout/footer.styl +0 -19
  54. package/stylesheets/layout/global.styl +0 -154
  55. package/stylesheets/layout/globalNav.styl +0 -89
  56. package/stylesheets/layout/header.styl +0 -29
  57. package/stylesheets/layout/headerUser.styl +0 -33
  58. package/stylesheets/layout/layout.styl +0 -75
  59. package/stylesheets/layout/layoutVars.styl +0 -9
  60. package/stylesheets/layout/loading.styl +0 -37
  61. package/stylesheets/layout/progressArea.styl +0 -17
  62. package/stylesheets/widgets/accessWidget.styl +0 -106
  63. package/stylesheets/widgets/browserWidget.styl +0 -9
  64. package/stylesheets/widgets/hierarchyWidget.styl +0 -188
  65. package/stylesheets/widgets/markdownWidget.styl +0 -92
  66. package/stylesheets/widgets/metadataWidget.styl +0 -92
  67. package/stylesheets/widgets/searchFieldWidget.styl +0 -70
  68. package/stylesheets/widgets/taskProgress.styl +0 -41
  69. package/stylesheets/widgets/timelineWidget.styl +0 -41
  70. package/stylesheets/widgets/uploadWidget.styl +0 -43
  71. package/stylesheets/widgets/userOtpManagementWidget.styl +0 -159
  72. package/templates/body/adminConsole.pug +0 -13
  73. package/templates/body/assetstores.pug +0 -98
  74. package/templates/body/collectionList.pug +0 -40
  75. package/templates/body/collectionPage.pug +0 -36
  76. package/templates/body/filesystemImport.pug +0 -41
  77. package/templates/body/frontPage.pug +0 -83
  78. package/templates/body/groupList.pug +0 -30
  79. package/templates/body/groupPage.pug +0 -116
  80. package/templates/body/itemPage.pug +0 -61
  81. package/templates/body/plugins.pug +0 -20
  82. package/templates/body/s3Import.pug +0 -35
  83. package/templates/body/searchResults.pug +0 -15
  84. package/templates/body/searchResultsType.pug +0 -13
  85. package/templates/body/systemConfiguration.pug +0 -221
  86. package/templates/body/userAccount.pug +0 -83
  87. package/templates/body/userList.pug +0 -43
  88. package/templates/body/userPage.pug +0 -40
  89. package/templates/layout/alert.pug +0 -5
  90. package/templates/layout/layout.pug +0 -12
  91. package/templates/layout/layoutFooter.pug +0 -11
  92. package/templates/layout/layoutGlobalNav.pug +0 -7
  93. package/templates/layout/layoutHeader.pug +0 -8
  94. package/templates/layout/layoutHeaderUser.pug +0 -26
  95. package/templates/layout/layoutProgressArea.pug +0 -1
  96. package/templates/layout/loginDialog.pug +0 -30
  97. package/templates/layout/registerDialog.pug +0 -35
  98. package/templates/layout/resetPasswordDialog.pug +0 -25
  99. package/templates/widgets/accessEditor.pug +0 -23
  100. package/templates/widgets/accessEditorMixins.pug +0 -57
  101. package/templates/widgets/accessEditorNonModal.pug +0 -11
  102. package/templates/widgets/accessEntry.pug +0 -32
  103. package/templates/widgets/apiKeyList.pug +0 -50
  104. package/templates/widgets/browserWidget.pug +0 -32
  105. package/templates/widgets/checkedActionsMenu.pug +0 -46
  106. package/templates/widgets/collectionInfoDialog.pug +0 -37
  107. package/templates/widgets/confirmDialog.pug +0 -14
  108. package/templates/widgets/dateTimeRangeWidget.pug +0 -20
  109. package/templates/widgets/dateTimeWidget.pug +0 -8
  110. package/templates/widgets/editApiKeyWidget.pug +0 -43
  111. package/templates/widgets/editAssetstoreWidget.pug +0 -78
  112. package/templates/widgets/editCollectionWidget.pug +0 -27
  113. package/templates/widgets/editFileWidget.pug +0 -21
  114. package/templates/widgets/editFolderWidget.pug +0 -27
  115. package/templates/widgets/editGroupWidget.pug +0 -54
  116. package/templates/widgets/editItemWidget.pug +0 -27
  117. package/templates/widgets/fileInfoDialog.pug +0 -33
  118. package/templates/widgets/fileList.pug +0 -33
  119. package/templates/widgets/folderInfoDialog.pug +0 -42
  120. package/templates/widgets/folderList.pug +0 -21
  121. package/templates/widgets/groupAdminList.pug +0 -33
  122. package/templates/widgets/groupInviteDialog.pug +0 -76
  123. package/templates/widgets/groupInviteList.pug +0 -14
  124. package/templates/widgets/groupMemberList.pug +0 -39
  125. package/templates/widgets/groupModList.pug +0 -23
  126. package/templates/widgets/hierarchyBreadcrumb.pug +0 -37
  127. package/templates/widgets/hierarchyPaginated.pug +0 -19
  128. package/templates/widgets/hierarchyWidget.pug +0 -96
  129. package/templates/widgets/itemBreadcrumb.pug +0 -16
  130. package/templates/widgets/itemList.pug +0 -27
  131. package/templates/widgets/jsonMetadatumEditWidget.pug +0 -13
  132. package/templates/widgets/jsonMetadatumView.pug +0 -6
  133. package/templates/widgets/loadingAnimation.pug +0 -4
  134. package/templates/widgets/markdownWidget.pug +0 -34
  135. package/templates/widgets/metadataWidget.pug +0 -16
  136. package/templates/widgets/metadatumEditWidget.pug +0 -15
  137. package/templates/widgets/metadatumView.pug +0 -5
  138. package/templates/widgets/newAssetstore.pug +0 -118
  139. package/templates/widgets/paginateWidget.pug +0 -7
  140. package/templates/widgets/pluginConfigBreadcrumb.pug +0 -13
  141. package/templates/widgets/rootSelectorWidget.pug +0 -13
  142. package/templates/widgets/searchField.pug +0 -10
  143. package/templates/widgets/searchHelp.pug +0 -12
  144. package/templates/widgets/searchModeSelect.pug +0 -9
  145. package/templates/widgets/searchResults.pug +0 -14
  146. package/templates/widgets/sortCollectionWidget.pug +0 -14
  147. package/templates/widgets/taskProgress.pug +0 -16
  148. package/templates/widgets/timeline.pug +0 -15
  149. package/templates/widgets/uploadWidget.pug +0 -15
  150. package/templates/widgets/uploadWidgetMixins.pug +0 -31
  151. package/templates/widgets/uploadWidgetNonModal.pug +0 -10
  152. package/templates/widgets/userOtpBegin.pug +0 -4
  153. package/templates/widgets/userOtpDisable.pug +0 -6
  154. package/templates/widgets/userOtpEnable.pug +0 -44
  155. package/utilities/EventStream.js +0 -177
  156. package/utilities/PluginUtils.js +0 -36
  157. package/utilities/S3UploadHandler.js +0 -303
  158. package/utilities/index.js +0 -9
  159. package/utilities/jquery/girderEnable.js +0 -19
  160. package/utilities/jquery/girderModal.js +0 -48
  161. package/version.js +0 -10
  162. package/views/App.js +0 -359
  163. package/views/View.js +0 -78
  164. package/views/body/AdminView.js +0 -29
  165. package/views/body/AssetstoresView.js +0 -235
  166. package/views/body/CollectionView.js +0 -188
  167. package/views/body/CollectionsView.js +0 -120
  168. package/views/body/FilesystemImportView.js +0 -83
  169. package/views/body/FolderView.js +0 -54
  170. package/views/body/FrontPageView.js +0 -47
  171. package/views/body/GroupView.js +0 -336
  172. package/views/body/GroupsView.js +0 -106
  173. package/views/body/ItemView.js +0 -177
  174. package/views/body/PluginsView.js +0 -73
  175. package/views/body/S3ImportView.js +0 -80
  176. package/views/body/SearchResultsView.js +0 -162
  177. package/views/body/SystemConfigurationView.js +0 -196
  178. package/views/body/UserAccountView.js +0 -179
  179. package/views/body/UserView.js +0 -165
  180. package/views/body/UsersView.js +0 -124
  181. package/views/body/index.js +0 -37
  182. package/views/index.js +0 -13
  183. package/views/layout/FooterView.js +0 -29
  184. package/views/layout/GlobalNavView.js +0 -103
  185. package/views/layout/HeaderUserView.js +0 -45
  186. package/views/layout/HeaderView.js +0 -83
  187. package/views/layout/LoginView.js +0 -100
  188. package/views/layout/ProgressListView.js +0 -70
  189. package/views/layout/RegisterView.js +0 -101
  190. package/views/layout/ResetPasswordView.js +0 -70
  191. package/views/layout/index.js +0 -19
  192. package/views/widgets/AccessWidget.js +0 -427
  193. package/views/widgets/ApiKeyListWidget.js +0 -140
  194. package/views/widgets/BrowserWidget.js +0 -317
  195. package/views/widgets/CheckedMenuWidget.js +0 -68
  196. package/views/widgets/CollectionInfoWidget.js +0 -40
  197. package/views/widgets/DateTimeRangeWidget.js +0 -179
  198. package/views/widgets/DateTimeWidget.js +0 -109
  199. package/views/widgets/EditApiKeyWidget.js +0 -122
  200. package/views/widgets/EditAssetstoreWidget.js +0 -148
  201. package/views/widgets/EditCollectionWidget.js +0 -93
  202. package/views/widgets/EditFileWidget.js +0 -56
  203. package/views/widgets/EditFolderWidget.js +0 -116
  204. package/views/widgets/EditGroupWidget.js +0 -125
  205. package/views/widgets/EditItemWidget.js +0 -110
  206. package/views/widgets/FileInfoWidget.js +0 -26
  207. package/views/widgets/FileListWidget.js +0 -151
  208. package/views/widgets/FolderInfoWidget.js +0 -39
  209. package/views/widgets/FolderListWidget.js +0 -106
  210. package/views/widgets/GroupAdminsWidget.js +0 -88
  211. package/views/widgets/GroupInvitesWidget.js +0 -56
  212. package/views/widgets/GroupMembersWidget.js +0 -185
  213. package/views/widgets/GroupModsWidget.js +0 -77
  214. package/views/widgets/HierarchyWidget.js +0 -1097
  215. package/views/widgets/ItemBreadcrumbWidget.js +0 -38
  216. package/views/widgets/ItemListWidget.js +0 -345
  217. package/views/widgets/LoadingAnimation.js +0 -17
  218. package/views/widgets/MarkdownWidget.js +0 -217
  219. package/views/widgets/MetadataWidget.js +0 -504
  220. package/views/widgets/NewAssetstoreWidget.js +0 -81
  221. package/views/widgets/PaginateWidget.js +0 -37
  222. package/views/widgets/PluginConfigBreadcrumbWidget.js +0 -33
  223. package/views/widgets/RootSelectorWidget.js +0 -192
  224. package/views/widgets/SearchFieldWidget.js +0 -365
  225. package/views/widgets/SearchPaginateWidget.js +0 -149
  226. package/views/widgets/SortCollectionWidget.js +0 -53
  227. package/views/widgets/TaskProgressWidget.js +0 -91
  228. package/views/widgets/TimelineWidget.js +0 -155
  229. package/views/widgets/UploadWidget.js +0 -340
  230. package/views/widgets/UserOtpManagementWidget.js +0 -105
  231. package/views/widgets/index.js +0 -75
@@ -1,12 +0,0 @@
1
- p.g-search-help-text= modeHelp
2
- if mode === 'text'
3
- ul.g-search-examples-list
4
- li
5
- code cat dog
6
- | returns documents containing either "cat" or "dog".
7
- li
8
- code "cat" "dog"
9
- | returns documents containing both "cat" and "dog".
10
- li
11
- code "cat dog"
12
- | returns documents containing the phrase "cat dog".
@@ -1,9 +0,0 @@
1
- p Choose search mode:
2
-
3
- for mode in modes
4
- .radio
5
- label
6
- input.g-search-mode-radio(
7
- type="radio", name="search-mode", value=mode,
8
- checked=(mode === currentMode ? 'checked' : undefined))
9
- = getModeDescription(mode)
@@ -1,14 +0,0 @@
1
- each result in results
2
- li.g-search-result
3
- a.g-search-result-element(data-resource-id=result.id, data-resource-type=result.type, data-resource-icon=result.icon, tabindex="-1")
4
- i(class=`icon-${result.icon}`)
5
- | #{result.text}
6
- if results.length === 0
7
- li.g-no-search-results.disabled
8
- a(tabindex="-1")
9
- i.icon-block
10
- | No results found
11
- else
12
- li.g-search-result
13
- a.g-search-result-page-link(data-resource-type="resultPage")
14
- | ...
@@ -1,14 +0,0 @@
1
- .btn-group
2
- a.g-sort-order-button.g-up.btn.btn-sm(title="Sort order")
3
- i.icon-sort-name-up
4
- a.g-sort-order-button.g-down.btn.btn-sm(title="Sort order")
5
- i.icon-sort-name-down
6
- button.g-collection-sort-actions.btn.btn-sm.btn-default.dropdown-toggle(
7
- data-toggle="dropdown", title="Sort by Field")
8
- | Sort by
9
- i.icon-down-dir
10
- ul.g-collection-sort-menu.dropdown-menu(role="menu")
11
- each fieldName, field in fields
12
- li(role="presentation")
13
- a.g-collection-sort-link(role="menuitem", g-sort=field)
14
- = fieldName
@@ -1,16 +0,0 @@
1
- .g-task-progress-top
2
- .g-task-progress-bar.progress(class=progressClass)
3
- .progress-bar(class=barClass, style=`width: ${width};`)
4
- .progress-status
5
- .progress-percent
6
- = percentText
7
- .progress-left
8
- = timeLeftText
9
- .g-task-progress-title(title=progress.data.title)
10
- if progress.data.resource && progress.data.resource._id && progress.data.resourceName
11
- a(title=progress.data.title, href='#' + progress.data.resourceName + '/' + progress.data.resource._id)
12
- = progress.data.title
13
- else
14
- = progress.data.title
15
- .g-task-progress-bottom
16
- .g-task-progress-message= progress.data.message
@@ -1,15 +0,0 @@
1
- .g-timeline-widget-wrapper
2
- .g-timeline-container
3
- each segment in segments
4
- .g-timeline-segment(
5
- title=segment.tooltip, class=segment.class,
6
- style=`left: ${segment.left}; width: ${segment.width}; ${segment.color}`)
7
- each point in points
8
- .g-timeline-point(
9
- title=point.tooltip, class=point.class, style=`left: calc(${point.left} - 10px); ${point.color}`)
10
- if startLabel !== undefined || endLabel !== undefined
11
- .g-timeline-labels-container
12
- if startLabel !== undefined
13
- .g-timeline-start-label= startLabel
14
- if endLabel !== undefined
15
- .g-timeline-end-label= endLabel
@@ -1,15 +0,0 @@
1
- include uploadWidgetMixins
2
-
3
- .modal-dialog
4
- .modal-content
5
- form#g-upload-form.modal-form(role="form")
6
- .modal-header
7
- button.close(data-dismiss="modal", aria-hidden="true", type="button") ×
8
- h4.modal-title= title
9
- +g-upload-widget-subtitle
10
- .modal-body
11
- +g-upload-widget-browse-or-drop
12
- +g-upload-widget-progress
13
- .modal-footer
14
- a.btn.btn-small.btn-default(data-dismiss="modal") Close
15
- +g-upload-widget-start-button
@@ -1,31 +0,0 @@
1
- mixin g-upload-widget-subtitle
2
- if parent && parentType
3
- .g-dialog-subtitle
4
- if (parentType === 'folder')
5
- i.icon-folder-open
6
- else if (parentType === 'item')
7
- i.icon-doc-text-inv
8
- else if (parentType === 'file')
9
- i.icon-doc-inv
10
- = parent.name()
11
-
12
- mixin g-upload-widget-browse-or-drop
13
- .g-drop-zone
14
- i.icon-docs
15
- | #{browseText}
16
- .form-group.hide
17
- input#g-files(type="file", multiple=(multiFile ? 'multiple' : null))
18
-
19
- mixin g-upload-widget-progress
20
- .g-current-progress-message
21
- .g-progress-current.progress.progress-striped.hide
22
- .progress-bar.progress-bar-info(role="progressbar")
23
- .g-overall-progress-message= noneSelectedText
24
- .g-progress-overall.progress.progress-striped.hide
25
- .progress-bar.progress-bar-info(role="progressbar")
26
- .g-upload-error-message.g-validation-failed-message
27
-
28
- mixin g-upload-widget-start-button
29
- button.g-start-upload.btn.btn-small.btn-primary.disabled(type="submit", disabled)
30
- i.icon-upload
31
- | Start Upload
@@ -1,10 +0,0 @@
1
- include uploadWidgetMixins
2
-
3
- form#g-upload-form
4
- if title
5
- h4= title
6
- +g-upload-widget-subtitle
7
- +g-upload-widget-browse-or-drop
8
- +g-upload-widget-progress
9
- .g-nonmodal-upload-buttons-container
10
- +g-upload-widget-start-button
@@ -1,4 +0,0 @@
1
- h2 Enable Two-factor authentication
2
-
3
- button#g-user-otp-initialize-enable.btn.btn-primary(type="submit")
4
- | Begin
@@ -1,6 +0,0 @@
1
- h2.g-user-otp-heading-enable Two-factor authentication is currently enabled
2
-
3
- h3.g-user-otp-heading-disable Disable Two-factor authentication
4
-
5
- button#g-user-otp-disable.btn.btn-primary(type="submit")
6
- | Disable
@@ -1,44 +0,0 @@
1
- h2 Enable Two-factor authentication
2
-
3
- ol.g-account-otp-steps
4
- li.g-account-otp-step
5
- h3 Install an authenticator app on your mobile device.
6
- div.
7
- There are many compatible apps, including, but not limited to
8
- #[a(href='https://support.google.com/accounts/answer/1066447?hl=en', target='_blank', rel='noopener') Google Authenticator],
9
- #[a(href='https://guide.duo.com/third-party-accounts', target='_blank', rel='noopener') Duo Mobile], and
10
- #[a(href='https://freeotp.github.io/', target='_blank', rel='noopener') FreeOTP].
11
- li.g-account-otp-step
12
- h3 Enter your key into the authenticator app
13
- .g-account-otp-scan-qr
14
- h4 Scan with your mobile device's camera:
15
- canvas#g-user-otp-qr
16
- .g-account-otp-enter-manual
17
- h4 Advanced Users:
18
- span You may enter your information manually, instead:
19
- table
20
- tr
21
- th Service
22
- td
23
- code= totpInfo.issuer
24
- tr
25
- th Account
26
- td
27
- code= totpInfo.account
28
- tr
29
- th Key
30
- td
31
- // Split into 4-character chunks for human readability
32
- code= totpInfo.key.match(/.{1,4}/g).join('-')
33
- tr
34
- th Type
35
- td
36
- span #[code Time-based] / #[code TOTP]
37
- li.g-account-otp-step
38
- h3 Enter the authentication code from your app
39
- input#g-user-otp-token(type='text', minlength=6, maxlength=6, placeholder='Your 6-digit code')
40
- div
41
- span#g-account-otp-error.g-validation-failed-message
42
- .g-user-otp-footer
43
- a#g-user-otp-cancel-enable.btn.btn-default Cancel
44
- button#g-user-otp-finalize-enable.btn.btn-primary.btn-success(type="submit") Enable Two-Factor
@@ -1,177 +0,0 @@
1
- import $ from 'jquery';
2
- import _ from 'underscore';
3
- import Backbone from 'backbone';
4
-
5
- import { getApiRoot, restRequest } from '@girder/core/rest';
6
-
7
- /**
8
- * The EventStream type wraps window.EventSource to listen to the unified
9
- * per-user event channel endpoint using the SSE protocol. When events are
10
- * received on the SSE channel, this triggers a Backbone event of the form
11
- * 'g:event.<type>' where <type> is the value of the event type field.
12
- * Listeners can bind to specific event types on the channel.
13
- */
14
- function EventStream(settings) {
15
- const defaults = {
16
- timeout: null,
17
- streamPath: '/notification/stream'
18
- };
19
-
20
- // User-provided settings from initialization
21
- this.settings = _.extend(defaults, settings);
22
- // Possible states are 'closed', 'stopped', 'started'
23
- this._state = 'closed';
24
- // Whether this is started (if so, holds the EventSource instance)
25
- this._eventSource = null;
26
-
27
- // Create context bindings only once, so they can be referenced when unbinding events
28
- this._onVisibilityStateChange = _.bind(this._onVisibilityStateChange, this);
29
- this._onMessage = _.bind(this._onMessage, this);
30
- this._onError = _.bind(this._onError, this);
31
-
32
- return _.extend(this, Backbone.Events);
33
- }
34
-
35
- EventStream.prototype._onVisibilityStateChange = function () {
36
- if (document.visibilityState === 'visible' && this._state === 'stopped') {
37
- this._start();
38
- } else if (document.visibilityState === 'hidden' && this._state === 'started') {
39
- this._stop();
40
- }
41
- };
42
-
43
- EventStream.prototype._onMessage = function (e) {
44
- let obj;
45
- try {
46
- obj = window.JSON.parse(e.data);
47
- } catch (err) {
48
- console.error('Invalid JSON from SSE stream: ' + e.data + ',' + err);
49
- this.trigger('g:error', e);
50
- return;
51
- }
52
- EventStream.setLastTimestamp(obj._girderTime);
53
- this.trigger('g:event.' + obj.type, obj);
54
- };
55
-
56
- EventStream.prototype._onError = function () {
57
- // The EventSource.onerror API does not provide the HTTP status code of the error, so send an Ajax HEAD request to
58
- // capture the status code.
59
- restRequest({
60
- url: this.settings.streamPath,
61
- method: 'HEAD',
62
- error: null
63
- })
64
- .fail((jqXHR) => {
65
- if (jqXHR.status === 503) {
66
- // Notification stream is disabled, so close this EventStream
67
- this.trigger('g:eventStream.disable', jqXHR);
68
- this.close();
69
- }
70
- });
71
- // In all other cases (HEAD doesn't fail, or fails with a non-503 code), assume this is a temporary outage and allow
72
- // the EventStream to continue attempting to auto-connect
73
- };
74
-
75
- EventStream.prototype.open = function () {
76
- if (!window.EventSource) {
77
- console.error('EventSource is not supported on this platform.');
78
- this.trigger('g:eventStream.disable');
79
- return;
80
- }
81
- if (this._state !== 'closed') {
82
- console.warn('EventStream should be closed.');
83
- return;
84
- }
85
-
86
- this._state = 'stopped';
87
- this._start();
88
-
89
- document.addEventListener('visibilitychange', this._onVisibilityStateChange);
90
- };
91
-
92
- EventStream.prototype._start = function () {
93
- if (this._state !== 'stopped') {
94
- console.warn('EventStream should be stopped');
95
- return;
96
- }
97
-
98
- const params = {};
99
-
100
- if (this.settings.timeout) {
101
- params.timeout = this.settings.timeout;
102
- }
103
-
104
- // Set the "since" argument to filter out notifications that have already been sent to this client.
105
- const timestamp = EventStream.getLastTimestamp();
106
- if (_.isNumber(timestamp)) {
107
- params.since = timestamp;
108
- }
109
-
110
- const url = getApiRoot() + this.settings.streamPath + '?' + $.param(params);
111
-
112
- this._eventSource = new window.EventSource(url);
113
- this._eventSource.onmessage = this._onMessage;
114
- this._eventSource.onerror = this._onError;
115
-
116
- this._state = 'started';
117
- this.trigger('g:eventStream.start');
118
- };
119
-
120
- EventStream.prototype._stop = function () {
121
- if (this._state !== 'started') {
122
- console.warn('EventStream should be started');
123
- return;
124
- }
125
-
126
- this._eventSource.close();
127
- this._eventSource = null;
128
-
129
- this._state = 'stopped';
130
- this.trigger('g:eventStream.stop');
131
- };
132
-
133
- EventStream.prototype.close = function () {
134
- if (this._state === 'closed') {
135
- console.warn('EventStream should not be closed');
136
- return;
137
- }
138
-
139
- document.removeEventListener('visibilitychange', this._onVisibilityStateChange);
140
-
141
- if (this._state === 'started') {
142
- this._stop();
143
- }
144
-
145
- this._state = 'closed';
146
- this.trigger('g:eventStream.close');
147
- };
148
-
149
- // Static methods
150
- EventStream._lastTimestamp = null;
151
- EventStream.setLastTimestamp = function (timestamp) {
152
- try {
153
- window.localStorage.setItem('sseTimestamp', timestamp);
154
- } catch (e) {
155
- // Ignore any errors raised by localStorage
156
- }
157
- EventStream._lastTimestamp = timestamp;
158
- };
159
- EventStream.getLastTimestamp = function () {
160
- let timestamp;
161
- try {
162
- timestamp = parseInt(window.localStorage.getItem('sseTimestamp'), 10);
163
- } catch (e) {
164
- // Ignore any errors raised by localStorage
165
- }
166
- if (!_.isNaN(timestamp)) {
167
- // An int was parsed
168
- return timestamp;
169
- } else {
170
- // Value could not be gotten from localStorage, so return from fallback (which is also the default of null)f
171
- return EventStream._lastTimestamp;
172
- }
173
- };
174
-
175
- const eventStream = new EventStream();
176
-
177
- export default eventStream;
@@ -1,36 +0,0 @@
1
- import _ from 'underscore';
2
-
3
- /**
4
- * Wrap the prototype method of a given object.
5
- *
6
- * @param obj The object whose prototype to extend, e.g. MyView
7
- * @param funcName The name of the function to wrap, e.g. "render"
8
- * @param wrapper The wrapper function, which should be a function taking the
9
- * underlying wrapped function as its first argument. The wrapped function
10
- * should be called with .call(this[, arguments]) inside of the wrapper in
11
- * order to preserve "this" semantics.
12
- */
13
- function wrap(obj, funcName, wrapper) {
14
- obj.prototype[funcName] = _.wrap(obj.prototype[funcName], wrapper);
15
- }
16
-
17
- var _pluginConfigRoutes = {};
18
-
19
- /**
20
- * Expose a plugin configuration page via the admin plugins page.
21
- * @param pluginName The canonical plugin name, i.e. its directory name
22
- * @param route The route to trigger that will render the plugin config.
23
- */
24
- function exposePluginConfig(pluginName, route) {
25
- _pluginConfigRoutes[pluginName] = route;
26
- }
27
-
28
- function getPluginConfigRoute(pluginName) {
29
- return _pluginConfigRoutes[pluginName];
30
- }
31
-
32
- export {
33
- exposePluginConfig,
34
- getPluginConfigRoute,
35
- wrap
36
- };