@girder/core 3.2.8 → 5.0.0-a7

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,9 +0,0 @@
1
- import Collection from '@girder/core/collections/Collection';
2
- import GroupModel from '@girder/core/models/GroupModel';
3
-
4
- var GroupCollection = Collection.extend({
5
- resourceName: 'group',
6
- model: GroupModel
7
- });
8
-
9
- export default GroupCollection;
@@ -1,11 +0,0 @@
1
- import Collection from '@girder/core/collections/Collection';
2
- import ItemModel from '@girder/core/models/ItemModel';
3
-
4
- var ItemCollection = Collection.extend({
5
- resourceName: 'item',
6
- model: ItemModel,
7
-
8
- pageLimit: 100
9
- });
10
-
11
- export default ItemCollection;
@@ -1,24 +0,0 @@
1
- import Collection from '@girder/core/collections/Collection';
2
- import UserModel from '@girder/core/models/UserModel';
3
- import { restRequest } from '@girder/core/rest';
4
-
5
- var UserCollection = Collection.extend({
6
- resourceName: 'user',
7
- model: UserModel,
8
-
9
- // Override default sort field
10
- sortField: 'lastName',
11
- secondarySortField: 'firstName'
12
- }, {
13
- getTotalCount: function () {
14
- return restRequest({
15
- url: 'user/details',
16
- method: 'GET'
17
- })
18
- .then((resp) => {
19
- return resp.nUsers;
20
- });
21
- }
22
- });
23
-
24
- export default UserCollection;
@@ -1,21 +0,0 @@
1
- import ApiKeyCollection from './ApiKeyCollection';
2
- import AssetstoreCollection from './AssetstoreCollection';
3
- import Collection from './Collection';
4
- import CollectionCollection from './CollectionCollection';
5
- import FileCollection from './FileCollection';
6
- import FolderCollection from './FolderCollection';
7
- import GroupCollection from './GroupCollection';
8
- import ItemCollection from './ItemCollection';
9
- import UserCollection from './UserCollection';
10
-
11
- export {
12
- ApiKeyCollection,
13
- AssetstoreCollection,
14
- Collection,
15
- CollectionCollection,
16
- FileCollection,
17
- FolderCollection,
18
- GroupCollection,
19
- ItemCollection,
20
- UserCollection
21
- };
package/constants.js DELETED
@@ -1,33 +0,0 @@
1
- var SORT_ASC = 1;
2
- var SORT_DESC = -1;
3
-
4
- var MONTHS = [
5
- 'January', 'February', 'March', 'April', 'May', 'June', 'July',
6
- 'August', 'September', 'October', 'November', 'December'
7
- ];
8
-
9
- var AccessType = {
10
- NONE: -1,
11
- READ: 0,
12
- WRITE: 1,
13
- ADMIN: 2
14
- };
15
-
16
- var AssetstoreType = {
17
- FILESYSTEM: 0,
18
- GRIDFS: 1,
19
- S3: 2
20
- };
21
-
22
- var Layout = {
23
- DEFAULT: 'default',
24
- EMPTY: 'empty'
25
- };
26
-
27
- export {
28
- SORT_ASC, SORT_DESC,
29
- MONTHS,
30
- AccessType,
31
- AssetstoreType,
32
- Layout
33
- };
package/dialog.js DELETED
@@ -1,128 +0,0 @@
1
- import $ from 'jquery';
2
- import _ from 'underscore';
3
- import Backbone from 'backbone';
4
-
5
- import router from '@girder/core/router';
6
- import { parseQueryString, splitRoute } from '@girder/core/misc';
7
-
8
- import ConfirmDialogTemplate from '@girder/core/templates/widgets/confirmDialog.pug';
9
-
10
- import '@girder/core/utilities/jquery/girderModal';
11
-
12
- function handleClose(name, options, nameId) {
13
- if (!router.enabled()) {
14
- return;
15
- }
16
- var curRoute = Backbone.history.fragment,
17
- routeParts = splitRoute(curRoute),
18
- queryString = parseQueryString(routeParts.name),
19
- dialogName = queryString.dialog,
20
- dialogId = queryString.dialogid;
21
- delete queryString.dialog;
22
- delete queryString.dialogid;
23
- var unparsedQueryString = $.param(queryString);
24
- if (unparsedQueryString.length > 0) {
25
- unparsedQueryString = '?' + unparsedQueryString;
26
- }
27
- if (dialogName === name && dialogId === nameId) {
28
- router.navigate(routeParts.base + unparsedQueryString, options);
29
- }
30
- }
31
-
32
- function handleOpen(name, options, nameId) {
33
- if (!router.enabled()) {
34
- return;
35
- }
36
- var curRoute = Backbone.history.fragment,
37
- routeParts = splitRoute(curRoute),
38
- queryString = parseQueryString(routeParts.name),
39
- dialogName = queryString.dialog,
40
- dialogId = queryString.dialogid;
41
-
42
- if (dialogName !== name || nameId !== dialogId) {
43
- queryString.dialog = name;
44
- if (nameId) {
45
- queryString.dialogid = nameId;
46
- }
47
- var unparsedQueryString = $.param(queryString);
48
- if (unparsedQueryString.length > 0) {
49
- unparsedQueryString = '?' + unparsedQueryString;
50
- }
51
- router.navigate(routeParts.base + unparsedQueryString, options);
52
- }
53
- }
54
-
55
- /**
56
- * Prompt the user to confirm an action.
57
- * @param {Object} [params] Parameters controlling this function's behavior.
58
- * @param {String} [params.text] The text to prompt the user with.
59
- * @param {String} [params.yesText] The text for the confirm button.
60
- * @param {String} [params.yesClass] Class string to apply to the confirm button.
61
- * @param {String} [params.noText] The text for the no/cancel button.
62
- * @param {Boolean} [params.escapedHtml] If you want to render the text as HTML rather than
63
- * plain text, set this to true to acknowledge that you have escaped any
64
- * user-created data within the text to prevent XSS exploits.
65
- * @param {Boolean} [params.msgConfirmation] If you want to add a new security before
66
- * perform an action. This will ask to enter a specific string "params.yesText params.name"
67
- * @param {String} [params.additionalText] Additional text to display before the confirmation
68
- * input.
69
- * @param {String} [params.name] The name to enter in order to confirm an action.
70
- * @param {Function} [params.confirmCallback]Callback function when the user confirms the action.
71
- */
72
- function confirm(params) {
73
- params = _.extend({
74
- text: 'Are you sure?',
75
- yesText: 'Yes',
76
- yesClass: 'btn-danger',
77
- noText: 'Cancel',
78
- escapedHtml: false,
79
- msgConfirmation: false,
80
- additionalText: '',
81
- name: ''
82
- }, params);
83
- $('#g-dialog-container').html(ConfirmDialogTemplate({
84
- params: params
85
- })).girderModal(false).one('hidden.bs.modal', function () {
86
- $('#g-confirm-button').off('click');
87
- });
88
-
89
- const el = $('#g-dialog-container').find('.modal-body>p:first-child');
90
- if (params.escapedHtml) {
91
- el.html(params.text);
92
- } else {
93
- el.text(params.text);
94
- }
95
- if (params.msgConfirmation) {
96
- if (params.escapedHtml) {
97
- $('.g-additional-text').html(params.additionalText);
98
- } else {
99
- $('.g-additional-text').text(params.additionalText);
100
- }
101
- }
102
-
103
- $('#g-confirm-button').off('click').on('click', function () {
104
- if (params.msgConfirmation) {
105
- const key = `${params.yesText.toUpperCase()} ${params.name}`;
106
- const msg = $('#g-confirm-text').val();
107
- if (msg.toUpperCase() === key.toUpperCase()) {
108
- $('#g-dialog-container').modal('hide');
109
- params.confirmCallback();
110
- } else if (msg.toUpperCase() === '') {
111
- $('.g-msg-error').html(`Error: You need to enter <b>'${key}'</b>.`);
112
- $('.g-msg-error').css('color', 'red');
113
- } else {
114
- $('.g-msg-error').html(`Error: <b>'${msg}'</b> isn't <b>'${key}'</b>`);
115
- $('.g-msg-error').css('color', 'red');
116
- }
117
- } else {
118
- $('#g-dialog-container').modal('hide');
119
- params.confirmCallback();
120
- }
121
- });
122
- }
123
-
124
- export {
125
- confirm,
126
- handleClose,
127
- handleOpen
128
- };
package/events.js DELETED
@@ -1,6 +0,0 @@
1
- import _ from 'underscore';
2
- import Backbone from 'backbone';
3
-
4
- var girderEvents = _.clone(Backbone.Events);
5
-
6
- export default girderEvents;
package/index.js DELETED
@@ -1,31 +0,0 @@
1
- import * as auth from './auth';
2
- import * as collections from './collections';
3
- import * as constants from './constants';
4
- import * as dialog from './dialog';
5
- import * as misc from './misc';
6
- import * as models from './models';
7
- import * as rest from './rest';
8
- import * as utilities from './utilities';
9
- import * as views from './views';
10
- import events from './events';
11
- import router from './router';
12
- import version from './version';
13
-
14
- // This will be modified dynamically when plugins are loaded.
15
- var plugins = {};
16
-
17
- export {
18
- auth,
19
- collections,
20
- constants,
21
- dialog,
22
- events,
23
- misc,
24
- models,
25
- plugins,
26
- rest,
27
- router,
28
- utilities,
29
- version,
30
- views
31
- };
package/main.js DELETED
@@ -1,21 +0,0 @@
1
- import $ from 'jquery';
2
- import _ from 'underscore';
3
- import Backbone from 'backbone';
4
- import moment from 'moment';
5
- import * as girder from '@girder/core';
6
-
7
- window.girder = girder;
8
-
9
- // Some cross-browser globals
10
- if (!window.console) {
11
- window.console = {
12
- log: $.noop,
13
- error: $.noop
14
- };
15
- }
16
-
17
- // For testing and convenience, available now because of testUtils.js reliance on $
18
- window.$ = $;
19
- window._ = _;
20
- window.moment = moment;
21
- window.Backbone = Backbone;
package/misc.js DELETED
@@ -1,260 +0,0 @@
1
- import $ from 'jquery';
2
- import _ from 'underscore';
3
-
4
- import { MONTHS } from '@girder/core/constants';
5
-
6
- import { Remarkable } from 'remarkable';
7
-
8
- import { linkify } from 'remarkable/linkify';
9
-
10
- /**
11
- * This file contains utility functions for general use in the application
12
- */
13
- var DATE_MONTH = 0;
14
- var DATE_DAY = 1;
15
- var DATE_MINUTE = 2;
16
- var DATE_SECOND = 3;
17
-
18
- /**
19
- * Format a date string to the given resolution.
20
- * @param datestr The date string to format.
21
- * @param resolution The resolution, defaults to 'day'. Minimum is month.
22
- */
23
- function formatDate(datestr, resolution) {
24
- datestr = datestr.replace(' ', 'T'); // Cross-browser accepted date format
25
- var date = new Date(datestr);
26
- var output = MONTHS[date.getMonth()];
27
-
28
- resolution = resolution || DATE_MONTH;
29
-
30
- if (resolution >= DATE_DAY) {
31
- output += ' ' + date.getDate() + ',';
32
- }
33
-
34
- output += ' ' + date.getFullYear();
35
-
36
- if (resolution >= DATE_MINUTE) {
37
- output += ' at ' + date.getHours() + ':' +
38
- ('0' + date.getMinutes()).slice(-2);
39
- }
40
- if (resolution >= DATE_SECOND) {
41
- output += ':' + ('0' + date.getSeconds()).slice(-2);
42
- }
43
-
44
- return output;
45
- }
46
-
47
- /**
48
- * Format a size in bytes into a human-readable string with metric unit
49
- * prefixes.
50
- */
51
- function formatSize(sizeBytes) {
52
- if (sizeBytes < 1024) {
53
- return sizeBytes + ' B';
54
- }
55
- var i, sizeVal = sizeBytes, precision = 1;
56
- for (i = 0; sizeVal >= 1024; i += 1) {
57
- sizeVal /= 1024;
58
- }
59
- // If we are just reporting a low number, no need for decimal places.
60
- if (sizeVal < 10) {
61
- precision = 3;
62
- } else if (sizeVal < 100) {
63
- precision = 2;
64
- }
65
- return sizeVal.toFixed(precision) + ' ' +
66
- ['B', 'kB', 'MB', 'GB', 'TB'][Math.min(i, 4)];
67
- }
68
-
69
- /**
70
- * Like formatSize, but more generic. Returns a human-readable format
71
- * of an integer using metric prefixes. The caller is expected to append any
72
- * unit string if necessary.
73
- *
74
- * @param {integer} n The number to format.
75
- * @param {Object} [opts={}] Formatting options. These include:
76
- * - {integer} [maxLen] Max number of digits in the output.
77
- * - {integer} [base=1000] Base for the prefixes (usually 1000 or 1024).
78
- * - {string} [sep=''] Separator between numeric value and metric prefix.
79
- */
80
- function formatCount(n, opts) {
81
- n = n || 0;
82
- opts = opts || {};
83
-
84
- var i = 0,
85
- base = opts.base || 1000,
86
- sep = opts.sep || '',
87
- maxLen = opts.maxLen || 3,
88
- precision = maxLen - 1;
89
-
90
- for (; n > base; i += 1) {
91
- n /= base;
92
- }
93
-
94
- if (!i) {
95
- precision = 0;
96
- } else if (n > 100) {
97
- precision -= 2;
98
- } else if (n > 10) {
99
- precision -= 1;
100
- }
101
-
102
- return n.toFixed(Math.max(0, precision)) + sep +
103
- ['', 'k', 'M', 'G', 'T'][Math.min(i, 4)];
104
- }
105
-
106
- /**
107
- * This comparator can be used by collections that wish to support locale-based
108
- * sorting. The locale specifies how upper and lower case are compared.
109
- */
110
- function localeComparator(model1, model2) {
111
- var a1 = model1.get(this.sortField),
112
- a2 = model2.get(this.sortField);
113
-
114
- if (a1 !== undefined && a1.localeCompare) {
115
- var result = a1.localeCompare(a2) * this.sortDir;
116
- if (result || !this.secondarySortField) {
117
- return result;
118
- }
119
- a1 = model1.get(this.secondarySortField);
120
- a2 = model2.get(this.secondarySortField);
121
- return a1.localeCompare(a2) * this.sortDir;
122
- }
123
-
124
- return a1 > a2 ? this.sortDir : (a1 < a2 ? -this.sortDir : 0);
125
- }
126
-
127
- /**
128
- * This comparator can be passed to the sort function on javascript arrays.
129
- */
130
- function localeSort(a1, a2) {
131
- if (a1 !== undefined && a1.localeCompare) {
132
- return a1.localeCompare(a2);
133
- }
134
- return a1 > a2 ? 1 : (a1 < a2 ? -1 : 0);
135
- }
136
-
137
- /**
138
- * Return the model class name given its collection name.
139
- * @param name Collection name, e.g. 'user'
140
- */
141
- function getModelClassByName(name) {
142
- var className = name.charAt(0).toUpperCase();
143
- return className + name.substr(1) + 'Model';
144
- }
145
-
146
- function parseQueryString(queryString) {
147
- var params = {};
148
- if (queryString) {
149
- _.each(queryString.replace(/\+/g, ' ').split(/&/g), function (el) {
150
- var aux = el.split('='), val;
151
- if (aux.length > 1) {
152
- val = decodeURIComponent(el.substr(aux[0].length + 1));
153
- }
154
- params[decodeURIComponent(aux[0])] = val;
155
- });
156
- }
157
- return params;
158
- }
159
-
160
- /**
161
- * Create a set of flags that can be OR'd (|) together to define a set of
162
- * options.
163
- *
164
- * @param {Array} options An array of strings defining the option names.
165
- * @param {string} allOption If you want an option that enables all options,
166
- * pass its name as this parameter.
167
- * @return {Object} An object mapping the names of options to values.
168
- */
169
- function defineFlags(options, allOption) {
170
- var i = 0,
171
- obj = {};
172
-
173
- if (allOption) {
174
- obj[allOption] = 1;
175
- }
176
- _.each(options, function (opt) {
177
- obj[opt] = 1 << i;
178
-
179
- if (allOption) {
180
- obj[allOption] |= obj[opt];
181
- }
182
-
183
- i += 1;
184
- });
185
-
186
- return obj;
187
- }
188
-
189
- /**
190
- * Transform markdown into HTML and render it into the given element. If no
191
- * element is provided, simply returns the HTML.
192
- *
193
- * @param val The markdown text input.
194
- * @param el The element to render the output HTML into, or falsy to simply
195
- * return the HTML value.
196
- */
197
- var renderMarkdown = (function () {
198
- var md = new Remarkable().use(linkify);
199
- return function (val, el) {
200
- if (el) {
201
- $(el).html(md.render(val));
202
- } else {
203
- return md.render(val);
204
- }
205
- };
206
- }());
207
-
208
- /**
209
- * Capitalize the first character of a string.
210
- */
211
- function capitalize(str) {
212
- return str.charAt(0).toUpperCase() + str.substring(1);
213
- }
214
-
215
- function splitRoute(route) {
216
- if (!route) {
217
- return { base: '', name: '' };
218
- }
219
- var firstIndex = route.indexOf('?'),
220
- lastIndex = route.lastIndexOf('?'),
221
- dialogName,
222
- baseRoute;
223
-
224
- if (firstIndex === -1) {
225
- baseRoute = route;
226
- } else {
227
- baseRoute = route.slice(0, firstIndex);
228
- }
229
-
230
- if (lastIndex === -1) {
231
- dialogName = '';
232
- } else {
233
- dialogName = route.slice(lastIndex + 1);
234
- }
235
-
236
- return { name: dialogName, base: baseRoute };
237
- }
238
-
239
- function _whenAll(promises) {
240
- return $.when(...promises).then((...results) => results);
241
- }
242
-
243
- export {
244
- DATE_MONTH,
245
- DATE_DAY,
246
- DATE_MINUTE,
247
- DATE_SECOND,
248
- formatDate,
249
- formatSize,
250
- formatCount,
251
- localeComparator,
252
- localeSort,
253
- getModelClassByName,
254
- parseQueryString,
255
- defineFlags,
256
- renderMarkdown,
257
- capitalize,
258
- splitRoute,
259
- _whenAll
260
- };
@@ -1,76 +0,0 @@
1
- import $ from 'jquery';
2
- import _ from 'underscore';
3
-
4
- import Model from '@girder/core/models/Model';
5
- import { restRequest } from '@girder/core/rest';
6
-
7
- /**
8
- * Models corresponding to AccessControlledModels on the server should extend
9
- * from this object. It provides utilities for managing and storing the
10
- * access control list on
11
- */
12
- var AccessControlledModel = Model.extend({
13
- /**
14
- * Saves the access control list on this model to the server. Saves the
15
- * state of whatever this model's "access" parameter is set to, which
16
- * should be an object of the form:
17
- * {groups: [{id: <groupId>, level: <accessLevel>}, ...],
18
- * users: [{id: <userId>, level: <accessLevel>}, ...]}
19
- * The "public" attribute of this model should also be set as a boolean.
20
- * When done, triggers the 'g:accessListSaved' event on the model.
21
- */
22
- updateAccess: function (params) {
23
- if (this.altUrl === null && this.resourceName === null) {
24
- throw new Error('An altUrl or resourceName must be set on the Model.');
25
- }
26
-
27
- return restRequest({
28
- url: `${this.altUrl || this.resourceName}/${this.id}/access`,
29
- method: 'PUT',
30
- data: _.extend({
31
- access: JSON.stringify(this.get('access')),
32
- public: this.get('public'),
33
- publicFlags: JSON.stringify(this.get('publicFlags') || [])
34
- }, params || {})
35
- }).done(() => {
36
- this.trigger('g:accessListSaved');
37
- }).fail((err) => {
38
- this.trigger('g:error', err);
39
- });
40
- },
41
-
42
- /**
43
- * Fetches the access control list from the server, and sets it as the
44
- * access property.
45
- * @param force By default, this only fetches access if it hasn't already
46
- * been set on the model. If you want to force a refresh
47
- * anyway, set this param to true.
48
- */
49
- fetchAccess: function (force) {
50
- if (this.altUrl === null && this.resourceName === null) {
51
- throw new Error('An altUrl or resourceName must be set on the Model.');
52
- }
53
-
54
- if (!this.get('access') || force) {
55
- return restRequest({
56
- url: `${this.altUrl || this.resourceName}/${this.id}/access`,
57
- method: 'GET'
58
- }).done((resp) => {
59
- if (resp.access) {
60
- this.set(resp);
61
- } else {
62
- this.set('access', resp);
63
- }
64
- this.trigger('g:accessFetched');
65
- return resp;
66
- }).fail((err) => {
67
- this.trigger('g:error', err);
68
- });
69
- } else {
70
- this.trigger('g:accessFetched');
71
- return $.Deferred().resolve(this.get('access')).promise();
72
- }
73
- }
74
- });
75
-
76
- export default AccessControlledModel;
@@ -1,31 +0,0 @@
1
- import AccessControlledModel from '@girder/core/models/AccessControlledModel';
2
- import { restRequest } from '@girder/core/rest';
3
-
4
- var ApiKeyModel = AccessControlledModel.extend({
5
- resourceName: 'api_key',
6
-
7
- setActive: function (active) {
8
- return restRequest({
9
- url: `api_key/${this.id}`,
10
- method: 'PUT',
11
- data: {
12
- active: active
13
- }
14
- }).done(() => {
15
- this.set({ active: active });
16
- this.trigger('g:setActive');
17
- });
18
- },
19
-
20
- save: function () {
21
- // Scope needs to be sent to the server as JSON
22
- var scope = this.get('scope');
23
- this.set('scope', JSON.stringify(scope), { silent: true }); // eslint-disable-line backbone/no-silent
24
- var promise = AccessControlledModel.prototype.save.call(this, arguments);
25
- // Restore scope to its original state
26
- this.set('scope', scope, { silent: true }); // eslint-disable-line backbone/no-silent
27
- return promise;
28
- }
29
- });
30
-
31
- export default ApiKeyModel;