@girder/core 5.0.0-beta.1 → 5.0.0
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.
- package/dist-lib/Girder_Favicon.png +0 -0
- package/dist-lib/Girder_Mark.png +0 -0
- package/dist-lib/girder-core.css +2 -0
- package/dist-lib/girder-core.js +60421 -0
- package/dist-lib/girder-core.js.map +1 -0
- package/dist-lib/girder-core.umd.cjs +1484 -0
- package/dist-lib/girder-core.umd.cjs.map +1 -0
- package/dist-lib/index.d.ts +1 -0
- package/dist-lib/src/auth.js +112 -0
- package/dist-lib/src/collections/ApiKeyCollection.js +9 -0
- package/dist-lib/src/collections/AssetstoreCollection.js +10 -0
- package/dist-lib/src/collections/Collection.js +295 -0
- package/dist-lib/src/collections/CollectionCollection.js +9 -0
- package/dist-lib/src/collections/FileCollection.js +11 -0
- package/dist-lib/src/collections/FolderCollection.js +11 -0
- package/dist-lib/src/collections/GroupCollection.js +9 -0
- package/dist-lib/src/collections/ItemCollection.js +11 -0
- package/dist-lib/src/collections/UserCollection.js +24 -0
- package/dist-lib/src/collections/index.js +21 -0
- package/dist-lib/src/constants.js +32 -0
- package/dist-lib/src/dialog.js +128 -0
- package/dist-lib/src/events.js +6 -0
- package/dist-lib/src/index.ts +80 -0
- package/dist-lib/src/main.ts +61 -0
- package/dist-lib/src/misc.js +260 -0
- package/dist-lib/src/models/AccessControlledModel.js +76 -0
- package/dist-lib/src/models/ApiKeyModel.js +31 -0
- package/dist-lib/src/models/AssetstoreModel.js +43 -0
- package/dist-lib/src/models/CollectionCreationPolicyModel.js +20 -0
- package/dist-lib/src/models/CollectionModel.js +12 -0
- package/dist-lib/src/models/FileModel.js +310 -0
- package/dist-lib/src/models/FolderModel.js +33 -0
- package/dist-lib/src/models/GroupModel.js +197 -0
- package/dist-lib/src/models/ItemModel.js +72 -0
- package/dist-lib/src/models/MetadataMixin.js +88 -0
- package/dist-lib/src/models/Model.js +187 -0
- package/dist-lib/src/models/UserModel.js +189 -0
- package/dist-lib/src/models/index.js +25 -0
- package/dist-lib/src/pluginUtils.js +11 -0
- package/dist-lib/src/rest.js +221 -0
- package/dist-lib/src/router.js +58 -0
- package/dist-lib/src/routes.js +229 -0
- package/dist-lib/src/stylesheets/apidocs/apidocs.styl +50 -0
- package/dist-lib/src/stylesheets/body/adminConsole.styl +21 -0
- package/dist-lib/src/stylesheets/body/assetstores.styl +46 -0
- package/dist-lib/src/stylesheets/body/collectionList.styl +39 -0
- package/dist-lib/src/stylesheets/body/collectionPage.styl +6 -0
- package/dist-lib/src/stylesheets/body/frontPage.styl +48 -0
- package/dist-lib/src/stylesheets/body/groupList.styl +43 -0
- package/dist-lib/src/stylesheets/body/groupPage.styl +116 -0
- package/dist-lib/src/stylesheets/body/itemPage.styl +81 -0
- package/dist-lib/src/stylesheets/body/plugins.styl +61 -0
- package/dist-lib/src/stylesheets/body/searchResultsList.styl +51 -0
- package/dist-lib/src/stylesheets/body/systemConfig.styl +56 -0
- package/dist-lib/src/stylesheets/body/userAccount.styl +57 -0
- package/dist-lib/src/stylesheets/body/userList.styl +79 -0
- package/dist-lib/src/stylesheets/body/userPage.styl +6 -0
- package/dist-lib/src/stylesheets/layout/footer.styl +19 -0
- package/dist-lib/src/stylesheets/layout/global.styl +154 -0
- package/dist-lib/src/stylesheets/layout/globalNav.styl +89 -0
- package/dist-lib/src/stylesheets/layout/header.styl +29 -0
- package/dist-lib/src/stylesheets/layout/headerUser.styl +33 -0
- package/dist-lib/src/stylesheets/layout/layout.styl +75 -0
- package/dist-lib/src/stylesheets/layout/layoutVars.styl +9 -0
- package/dist-lib/src/stylesheets/layout/loading.styl +37 -0
- package/dist-lib/src/stylesheets/layout/progressArea.styl +17 -0
- package/dist-lib/src/stylesheets/widgets/accessWidget.styl +106 -0
- package/dist-lib/src/stylesheets/widgets/browserWidget.styl +9 -0
- package/dist-lib/src/stylesheets/widgets/hierarchyWidget.styl +188 -0
- package/dist-lib/src/stylesheets/widgets/markdownWidget.styl +92 -0
- package/dist-lib/src/stylesheets/widgets/metadataWidget.styl +92 -0
- package/dist-lib/src/stylesheets/widgets/searchFieldWidget.styl +70 -0
- package/dist-lib/src/stylesheets/widgets/taskProgress.styl +41 -0
- package/dist-lib/src/stylesheets/widgets/timelineWidget.styl +41 -0
- package/dist-lib/src/stylesheets/widgets/uploadWidget.styl +43 -0
- package/dist-lib/src/stylesheets/widgets/userOtpManagementWidget.styl +159 -0
- package/dist-lib/src/templates/body/adminConsole.pug +13 -0
- package/dist-lib/src/templates/body/assetstores.pug +83 -0
- package/dist-lib/src/templates/body/collectionList.pug +40 -0
- package/dist-lib/src/templates/body/collectionPage.pug +36 -0
- package/dist-lib/src/templates/body/filesystemImport.pug +41 -0
- package/dist-lib/src/templates/body/frontPage.pug +83 -0
- package/dist-lib/src/templates/body/groupList.pug +30 -0
- package/dist-lib/src/templates/body/groupPage.pug +116 -0
- package/dist-lib/src/templates/body/itemPage.pug +61 -0
- package/dist-lib/src/templates/body/plugins.pug +20 -0
- package/dist-lib/src/templates/body/s3Import.pug +35 -0
- package/dist-lib/src/templates/body/searchResults.pug +15 -0
- package/dist-lib/src/templates/body/searchResultsType.pug +13 -0
- package/dist-lib/src/templates/body/systemConfiguration.pug +215 -0
- package/dist-lib/src/templates/body/userAccount.pug +83 -0
- package/dist-lib/src/templates/body/userList.pug +43 -0
- package/dist-lib/src/templates/body/userPage.pug +40 -0
- package/dist-lib/src/templates/layout/alert.pug +5 -0
- package/dist-lib/src/templates/layout/layout.pug +12 -0
- package/dist-lib/src/templates/layout/layoutFooter.pug +11 -0
- package/dist-lib/src/templates/layout/layoutGlobalNav.pug +7 -0
- package/dist-lib/src/templates/layout/layoutHeader.pug +8 -0
- package/dist-lib/src/templates/layout/layoutHeaderUser.pug +26 -0
- package/dist-lib/src/templates/layout/layoutProgressArea.pug +1 -0
- package/dist-lib/src/templates/layout/loginDialog.pug +30 -0
- package/dist-lib/src/templates/layout/registerDialog.pug +35 -0
- package/dist-lib/src/templates/layout/resetPasswordDialog.pug +25 -0
- package/dist-lib/src/templates/widgets/accessEditor.pug +23 -0
- package/dist-lib/src/templates/widgets/accessEditorMixins.pug +57 -0
- package/dist-lib/src/templates/widgets/accessEditorNonModal.pug +11 -0
- package/dist-lib/src/templates/widgets/accessEntry.pug +32 -0
- package/dist-lib/src/templates/widgets/apiKeyList.pug +50 -0
- package/dist-lib/src/templates/widgets/browserWidget.pug +32 -0
- package/dist-lib/src/templates/widgets/checkedActionsMenu.pug +46 -0
- package/dist-lib/src/templates/widgets/collectionInfoDialog.pug +37 -0
- package/dist-lib/src/templates/widgets/confirmDialog.pug +14 -0
- package/dist-lib/src/templates/widgets/dateTimeRangeWidget.pug +20 -0
- package/dist-lib/src/templates/widgets/dateTimeWidget.pug +8 -0
- package/dist-lib/src/templates/widgets/editApiKeyWidget.pug +43 -0
- package/dist-lib/src/templates/widgets/editAssetstoreWidget.pug +70 -0
- package/dist-lib/src/templates/widgets/editCollectionWidget.pug +27 -0
- package/dist-lib/src/templates/widgets/editFileWidget.pug +21 -0
- package/dist-lib/src/templates/widgets/editFolderWidget.pug +27 -0
- package/dist-lib/src/templates/widgets/editGroupWidget.pug +54 -0
- package/dist-lib/src/templates/widgets/editItemWidget.pug +27 -0
- package/dist-lib/src/templates/widgets/fileInfoDialog.pug +33 -0
- package/dist-lib/src/templates/widgets/fileList.pug +33 -0
- package/dist-lib/src/templates/widgets/folderInfoDialog.pug +42 -0
- package/dist-lib/src/templates/widgets/folderList.pug +21 -0
- package/dist-lib/src/templates/widgets/groupAdminList.pug +33 -0
- package/dist-lib/src/templates/widgets/groupInviteDialog.pug +76 -0
- package/dist-lib/src/templates/widgets/groupInviteList.pug +14 -0
- package/dist-lib/src/templates/widgets/groupMemberList.pug +39 -0
- package/dist-lib/src/templates/widgets/groupModList.pug +23 -0
- package/dist-lib/src/templates/widgets/hierarchyBreadcrumb.pug +37 -0
- package/dist-lib/src/templates/widgets/hierarchyPaginated.pug +19 -0
- package/dist-lib/src/templates/widgets/hierarchyWidget.pug +96 -0
- package/dist-lib/src/templates/widgets/itemBreadcrumb.pug +16 -0
- package/dist-lib/src/templates/widgets/itemList.pug +27 -0
- package/dist-lib/src/templates/widgets/jsonMetadatumEditWidget.pug +13 -0
- package/dist-lib/src/templates/widgets/jsonMetadatumView.pug +6 -0
- package/dist-lib/src/templates/widgets/loadingAnimation.pug +4 -0
- package/dist-lib/src/templates/widgets/markdownWidget.pug +34 -0
- package/dist-lib/src/templates/widgets/metadataWidget.pug +16 -0
- package/dist-lib/src/templates/widgets/metadatumEditWidget.pug +15 -0
- package/dist-lib/src/templates/widgets/metadatumView.pug +5 -0
- package/dist-lib/src/templates/widgets/newAssetstore.pug +87 -0
- package/dist-lib/src/templates/widgets/paginateWidget.pug +7 -0
- package/dist-lib/src/templates/widgets/pluginConfigBreadcrumb.pug +13 -0
- package/dist-lib/src/templates/widgets/rootSelectorWidget.pug +13 -0
- package/dist-lib/src/templates/widgets/searchField.pug +10 -0
- package/dist-lib/src/templates/widgets/searchHelp.pug +12 -0
- package/dist-lib/src/templates/widgets/searchModeSelect.pug +9 -0
- package/dist-lib/src/templates/widgets/searchResults.pug +14 -0
- package/dist-lib/src/templates/widgets/sortCollectionWidget.pug +14 -0
- package/dist-lib/src/templates/widgets/taskProgress.pug +16 -0
- package/dist-lib/src/templates/widgets/timeline.pug +15 -0
- package/dist-lib/src/templates/widgets/uploadWidget.pug +15 -0
- package/dist-lib/src/templates/widgets/uploadWidgetMixins.pug +31 -0
- package/dist-lib/src/templates/widgets/uploadWidgetNonModal.pug +10 -0
- package/dist-lib/src/templates/widgets/userOtpBegin.pug +4 -0
- package/dist-lib/src/templates/widgets/userOtpDisable.pug +6 -0
- package/dist-lib/src/templates/widgets/userOtpEnable.pug +44 -0
- package/dist-lib/src/utilities/EventStream.js +119 -0
- package/dist-lib/src/utilities/PluginUtils.js +36 -0
- package/dist-lib/src/utilities/S3UploadHandler.js +263 -0
- package/dist-lib/src/utilities/index.js +9 -0
- package/dist-lib/src/utilities/jquery/girderEnable.js +19 -0
- package/dist-lib/src/utilities/jquery/girderModal.js +48 -0
- package/dist-lib/src/version.js +6 -0
- package/dist-lib/src/views/App.js +359 -0
- package/dist-lib/src/views/View.js +79 -0
- package/dist-lib/src/views/body/AdminView.js +29 -0
- package/dist-lib/src/views/body/AssetstoresView.js +233 -0
- package/dist-lib/src/views/body/CollectionView.js +188 -0
- package/dist-lib/src/views/body/CollectionsView.js +120 -0
- package/dist-lib/src/views/body/FilesystemImportView.js +83 -0
- package/dist-lib/src/views/body/FolderView.js +54 -0
- package/dist-lib/src/views/body/FrontPageView.js +47 -0
- package/dist-lib/src/views/body/GroupView.js +336 -0
- package/dist-lib/src/views/body/GroupsView.js +106 -0
- package/dist-lib/src/views/body/ItemView.js +177 -0
- package/dist-lib/src/views/body/PluginsView.js +73 -0
- package/dist-lib/src/views/body/S3ImportView.js +80 -0
- package/dist-lib/src/views/body/SearchResultsView.js +162 -0
- package/dist-lib/src/views/body/SystemConfigurationView.js +177 -0
- package/dist-lib/src/views/body/UserAccountView.js +179 -0
- package/dist-lib/src/views/body/UserView.js +165 -0
- package/dist-lib/src/views/body/UsersView.js +124 -0
- package/dist-lib/src/views/body/index.js +38 -0
- package/dist-lib/src/views/index.js +13 -0
- package/dist-lib/src/views/layout/FooterView.js +29 -0
- package/dist-lib/src/views/layout/GlobalNavView.js +103 -0
- package/dist-lib/src/views/layout/HeaderUserView.js +45 -0
- package/dist-lib/src/views/layout/HeaderView.js +83 -0
- package/dist-lib/src/views/layout/LoginView.js +100 -0
- package/dist-lib/src/views/layout/ProgressListView.js +70 -0
- package/dist-lib/src/views/layout/RegisterView.js +101 -0
- package/dist-lib/src/views/layout/ResetPasswordView.js +70 -0
- package/dist-lib/src/views/layout/index.js +19 -0
- package/dist-lib/src/views/widgets/AccessWidget.js +427 -0
- package/dist-lib/src/views/widgets/ApiKeyListWidget.js +140 -0
- package/dist-lib/src/views/widgets/BrowserWidget.js +317 -0
- package/dist-lib/src/views/widgets/CheckedMenuWidget.js +68 -0
- package/dist-lib/src/views/widgets/CollectionInfoWidget.js +40 -0
- package/dist-lib/src/views/widgets/DateTimeRangeWidget.js +180 -0
- package/dist-lib/src/views/widgets/DateTimeWidget.js +110 -0
- package/dist-lib/src/views/widgets/EditApiKeyWidget.js +124 -0
- package/dist-lib/src/views/widgets/EditAssetstoreWidget.js +136 -0
- package/dist-lib/src/views/widgets/EditCollectionWidget.js +93 -0
- package/dist-lib/src/views/widgets/EditFileWidget.js +56 -0
- package/dist-lib/src/views/widgets/EditFolderWidget.js +116 -0
- package/dist-lib/src/views/widgets/EditGroupWidget.js +125 -0
- package/dist-lib/src/views/widgets/EditItemWidget.js +110 -0
- package/dist-lib/src/views/widgets/FileInfoWidget.js +26 -0
- package/dist-lib/src/views/widgets/FileListWidget.js +151 -0
- package/dist-lib/src/views/widgets/FolderInfoWidget.js +39 -0
- package/dist-lib/src/views/widgets/FolderListWidget.js +106 -0
- package/dist-lib/src/views/widgets/GroupAdminsWidget.js +88 -0
- package/dist-lib/src/views/widgets/GroupInvitesWidget.js +56 -0
- package/dist-lib/src/views/widgets/GroupMembersWidget.js +185 -0
- package/dist-lib/src/views/widgets/GroupModsWidget.js +77 -0
- package/dist-lib/src/views/widgets/HierarchyWidget.js +1097 -0
- package/dist-lib/src/views/widgets/ItemBreadcrumbWidget.js +38 -0
- package/dist-lib/src/views/widgets/ItemListWidget.js +345 -0
- package/dist-lib/src/views/widgets/LoadingAnimation.js +17 -0
- package/dist-lib/src/views/widgets/MarkdownWidget.js +217 -0
- package/dist-lib/src/views/widgets/MetadataWidget.js +508 -0
- package/dist-lib/src/views/widgets/NewAssetstoreWidget.js +72 -0
- package/dist-lib/src/views/widgets/PaginateWidget.js +37 -0
- package/dist-lib/src/views/widgets/PluginConfigBreadcrumbWidget.js +33 -0
- package/dist-lib/src/views/widgets/RootSelectorWidget.js +192 -0
- package/dist-lib/src/views/widgets/SearchFieldWidget.js +365 -0
- package/dist-lib/src/views/widgets/SearchPaginateWidget.js +149 -0
- package/dist-lib/src/views/widgets/SortCollectionWidget.js +53 -0
- package/dist-lib/src/views/widgets/TaskProgressWidget.js +91 -0
- package/dist-lib/src/views/widgets/TimelineWidget.js +155 -0
- package/dist-lib/src/views/widgets/UploadWidget.js +340 -0
- package/dist-lib/src/views/widgets/UserOtpManagementWidget.js +105 -0
- package/dist-lib/src/views/widgets/index.js +81 -0
- package/dist-lib/src/vite-env.d.ts +5 -0
- package/package.json +17 -15
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import _ from 'underscore';
|
|
2
|
+
|
|
3
|
+
import UserModel from '@girder/core/models/UserModel';
|
|
4
|
+
import events from '@girder/core/events';
|
|
5
|
+
import { restRequest } from '@girder/core/rest';
|
|
6
|
+
|
|
7
|
+
// TODO: this might need some fixing/testing, as it seems that
|
|
8
|
+
// girder.corsAuth could be an override. See login doc below.
|
|
9
|
+
var corsAuth = false;
|
|
10
|
+
var currentUser = null;
|
|
11
|
+
var currentToken = window.localStorage.getItem('girderToken');
|
|
12
|
+
|
|
13
|
+
function getCurrentUser() {
|
|
14
|
+
return currentUser;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function setCurrentUser(user) {
|
|
18
|
+
currentUser = user;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getCurrentToken() {
|
|
22
|
+
return currentToken;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function setCurrentToken(token) {
|
|
26
|
+
currentToken = token;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function fetchCurrentUser() {
|
|
30
|
+
return restRequest({
|
|
31
|
+
method: 'GET',
|
|
32
|
+
url: '/user/me'
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Encode password using TextEncoder to support unicode
|
|
38
|
+
*/
|
|
39
|
+
function basicAuthEncode(username, password) {
|
|
40
|
+
const encoder = new TextEncoder();
|
|
41
|
+
const data = encoder.encode(username + ':' + password);
|
|
42
|
+
return 'Basic ' + btoa(String.fromCharCode(...data));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Log in to the server. If successful, sets the value of currentUser
|
|
47
|
+
* and currentToken and triggers the "g:login" and "g:login.success".
|
|
48
|
+
* On failure, triggers the "g:login.error" event.
|
|
49
|
+
*
|
|
50
|
+
* @param username The username or email to login as.
|
|
51
|
+
* @param password The password to use.
|
|
52
|
+
* @param otpToken An optional one-time password to include with the login.
|
|
53
|
+
*/
|
|
54
|
+
function login(username, password, otpToken = null) {
|
|
55
|
+
var auth = basicAuthEncode(username, password);
|
|
56
|
+
|
|
57
|
+
const headers = {
|
|
58
|
+
Authorization: auth
|
|
59
|
+
};
|
|
60
|
+
if (_.isString(otpToken)) {
|
|
61
|
+
// Use _.isString to send header with empty string
|
|
62
|
+
headers['Girder-OTP'] = otpToken;
|
|
63
|
+
}
|
|
64
|
+
return restRequest({
|
|
65
|
+
method: 'GET',
|
|
66
|
+
url: '/user/authentication',
|
|
67
|
+
headers: headers,
|
|
68
|
+
error: null
|
|
69
|
+
}).then(function (response) {
|
|
70
|
+
response.user.token = response.authToken;
|
|
71
|
+
|
|
72
|
+
setCurrentUser(new UserModel(response.user));
|
|
73
|
+
setCurrentToken(response.user.token.token);
|
|
74
|
+
|
|
75
|
+
window.localStorage.setItem('girderToken', response.user.token.token);
|
|
76
|
+
|
|
77
|
+
events.trigger('g:login.success', response.user);
|
|
78
|
+
events.trigger('g:login', response);
|
|
79
|
+
|
|
80
|
+
return response.user;
|
|
81
|
+
}).fail(function (jqxhr) {
|
|
82
|
+
events.trigger('g:login.error', jqxhr.status, jqxhr);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function logout() {
|
|
87
|
+
return restRequest({
|
|
88
|
+
method: 'DELETE',
|
|
89
|
+
url: '/user/authentication'
|
|
90
|
+
}).done(function () {
|
|
91
|
+
setCurrentUser(null);
|
|
92
|
+
setCurrentToken(null);
|
|
93
|
+
|
|
94
|
+
window.localStorage.removeItem('girderToken');
|
|
95
|
+
|
|
96
|
+
events.trigger('g:login', null);
|
|
97
|
+
events.trigger('g:logout.success');
|
|
98
|
+
}).fail(function (jqxhr) {
|
|
99
|
+
events.trigger('g:logout.error', jqxhr.status, jqxhr);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export {
|
|
104
|
+
corsAuth,
|
|
105
|
+
getCurrentUser,
|
|
106
|
+
setCurrentUser,
|
|
107
|
+
getCurrentToken,
|
|
108
|
+
setCurrentToken,
|
|
109
|
+
fetchCurrentUser,
|
|
110
|
+
login,
|
|
111
|
+
logout
|
|
112
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import AssetstoreModel from '@girder/core/models/AssetstoreModel';
|
|
2
|
+
import Collection from '@girder/core/collections/Collection';
|
|
3
|
+
|
|
4
|
+
var AssetstoreCollection = Collection.extend({
|
|
5
|
+
resourceName: 'assetstore',
|
|
6
|
+
model: AssetstoreModel,
|
|
7
|
+
pageLimit: 1000
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export default AssetstoreCollection;
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import _ from 'underscore';
|
|
2
|
+
import Backbone from 'backbone';
|
|
3
|
+
|
|
4
|
+
import { localeComparator } from '@girder/core/misc';
|
|
5
|
+
import Model from '@girder/core/models/Model';
|
|
6
|
+
import { restRequest } from '@girder/core/rest';
|
|
7
|
+
import { SORT_ASC } from '@girder/core/constants';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* All collections should descend from this collection base class, which
|
|
11
|
+
* provides nice utilities for pagination and sorting.
|
|
12
|
+
*/
|
|
13
|
+
var Collection = Backbone.Collection.extend({
|
|
14
|
+
model: Model,
|
|
15
|
+
resourceName: null,
|
|
16
|
+
|
|
17
|
+
sortField: 'name',
|
|
18
|
+
sortDir: SORT_ASC,
|
|
19
|
+
comparator: localeComparator,
|
|
20
|
+
|
|
21
|
+
// Number of records to fetch per page
|
|
22
|
+
pageLimit: 25,
|
|
23
|
+
offset: 0,
|
|
24
|
+
|
|
25
|
+
// Alternative fetch URL
|
|
26
|
+
altUrl: null,
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Append mode can be used to append pages to the collection rather than
|
|
30
|
+
* simply replacing its contents when a new page is fetched. For the sake
|
|
31
|
+
* of least surprise, this property should not be changed in the definition
|
|
32
|
+
* of collections, but after they are instantiated.
|
|
33
|
+
*/
|
|
34
|
+
append: false,
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Client-side filtering: set to a function that takes an instance of this
|
|
38
|
+
* collection's model and returns true for each instance that should be
|
|
39
|
+
* included in this collection. For the sake of least surprise, this
|
|
40
|
+
* property should not be changed in the definition of collections, but
|
|
41
|
+
* after they are instantiated.
|
|
42
|
+
*/
|
|
43
|
+
filterFunc: null,
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* If filtering and not appending, this stack is used to record the offsets
|
|
47
|
+
* at which prior pages had been fetched.
|
|
48
|
+
*/
|
|
49
|
+
pageOffsetStack: null,
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Number of items in the collection returned by 'girder-total-count' header
|
|
53
|
+
*/
|
|
54
|
+
_totalCount: 0,
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns a boolean of whether or not this collection has previous pages,
|
|
58
|
+
* i.e. if the offset of the current page start is > 0
|
|
59
|
+
*/
|
|
60
|
+
hasPreviousPage: function () {
|
|
61
|
+
if (this.filterFunc) {
|
|
62
|
+
if (this.append) { return false; }
|
|
63
|
+
this.pageOffsetStack = this.pageOffsetStack || [];
|
|
64
|
+
return (this.pageOffsetStack.length > 1);
|
|
65
|
+
}
|
|
66
|
+
return this.offset - this.length > 0;
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* After you have called fetch() on a collection, this method will tell
|
|
71
|
+
* you whether there are more pages remaining to be fetched, or if you
|
|
72
|
+
* have hit the end.
|
|
73
|
+
*/
|
|
74
|
+
hasNextPage: function () {
|
|
75
|
+
return this._hasMorePages;
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* This value is populated whenever the list length exceeds the pageLimit.
|
|
79
|
+
* It is used to determine how many pages are needed based on the page limit
|
|
80
|
+
* it is retrieved from the response header 'girder-total-count'
|
|
81
|
+
* @returns {number} total number of items retrieved
|
|
82
|
+
*/
|
|
83
|
+
getTotalCount: function () {
|
|
84
|
+
return this._totalCount || 0;
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Fetch the previous page of this collection, emitting g:changed when done.
|
|
88
|
+
*/
|
|
89
|
+
fetchPreviousPage: function (params) {
|
|
90
|
+
if (this.filterFunc) {
|
|
91
|
+
if (this.append) {
|
|
92
|
+
this.offset = 0;
|
|
93
|
+
} else {
|
|
94
|
+
this.pageOffsetStack = this.pageOffsetStack || [];
|
|
95
|
+
if (this.pageOffsetStack.length) {
|
|
96
|
+
this.pageOffsetStack.pop();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
this.offset = (
|
|
100
|
+
this.pageOffsetStack.length ? this.pageOffsetStack.pop() : 0
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
this.offset = Math.max(
|
|
105
|
+
0,
|
|
106
|
+
this.offset - this.length - this.pageLimit);
|
|
107
|
+
}
|
|
108
|
+
return this.fetch(_.extend({}, this.params, params || {}));
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Fetch the next page of this collection, emitting g:changed when done.
|
|
113
|
+
*/
|
|
114
|
+
fetchNextPage: function (params) {
|
|
115
|
+
return this.fetch(_.extend({}, this.params, params || {}));
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @returns {number} the 0-indexed page number of the current page. Add 1 to this
|
|
120
|
+
* result when displaying it to the user.
|
|
121
|
+
*
|
|
122
|
+
* If this collection hasn't been fully initialized (i.e.: before any pages
|
|
123
|
+
* have been fetched), pageNum() may return a page number < 0 to signal that
|
|
124
|
+
* there is no "current page".
|
|
125
|
+
*/
|
|
126
|
+
pageNum: function () {
|
|
127
|
+
if (this.filterFunc) {
|
|
128
|
+
if (this.append) { return 0; }
|
|
129
|
+
this.pageOffsetStack = this.pageOffsetStack || [];
|
|
130
|
+
return this.pageOffsetStack.length - 1;
|
|
131
|
+
}
|
|
132
|
+
return Math.ceil((this.offset - this.length) / this.pageLimit);
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Sets a specific pagenumber for loading by calculating the offset
|
|
137
|
+
* @param {Number} pageNumber The 0 indexed page that should be loaded based on the pageLimit size
|
|
138
|
+
* @param {Object} params Additional parameters to pass to the fetch call
|
|
139
|
+
* @returns {Promise} a fetch promise to retrieve more data
|
|
140
|
+
*/
|
|
141
|
+
fetchPage: function (pageNumber, params) {
|
|
142
|
+
// Make sure the page Number is within range, pageNumber is indexed at 0
|
|
143
|
+
if (!this.append && pageNumber * this.pageLimit < this._totalCount && pageNumber >= 0) {
|
|
144
|
+
this.offset = pageNumber * this.pageLimit;
|
|
145
|
+
return this.fetch(_.extend({}, this.params, params || {}));
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Fetches the next page of this collection, replacing the existing models
|
|
151
|
+
* of this collection with the requested page. If the next page contains
|
|
152
|
+
* any records (i.e. it was not already on the last page), this will
|
|
153
|
+
* trigger g:changed.
|
|
154
|
+
* @param params Any additional parameters to be passed with the request.
|
|
155
|
+
* @param reset Set this to true to re-fetch the current page.
|
|
156
|
+
*/
|
|
157
|
+
fetch: function (params, reset) {
|
|
158
|
+
if (this.altUrl === null && this.resourceName === null) {
|
|
159
|
+
throw new Error('An altUrl or resourceName must be set on the Collection.');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (this.filterFunc && !this.append) {
|
|
163
|
+
this.pageOffsetStack = this.pageOffsetStack || [];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (reset) {
|
|
167
|
+
if (this.filterFunc && !this.append) {
|
|
168
|
+
this.pageOffsetStack = [];
|
|
169
|
+
}
|
|
170
|
+
this.offset = 0;
|
|
171
|
+
} else {
|
|
172
|
+
this.params = params || {};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (this.filterFunc && !this.append) {
|
|
176
|
+
this.pageOffsetStack.push(this.offset);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
var limit = this.pageLimit > 0 ? this.pageLimit + 1 : 0;
|
|
180
|
+
|
|
181
|
+
var finalList = []; /* will be built up in pieces */
|
|
182
|
+
|
|
183
|
+
function fetchListFragment() {
|
|
184
|
+
var xhr = restRequest({
|
|
185
|
+
url: this.altUrl || this.resourceName,
|
|
186
|
+
data: _.extend({
|
|
187
|
+
limit: limit,
|
|
188
|
+
offset: this.offset,
|
|
189
|
+
sort: this.sortField,
|
|
190
|
+
sortdir: this.sortDir
|
|
191
|
+
}, this.params)
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
var result = xhr.then((list) => {
|
|
195
|
+
if (this.pageLimit > 0 && list.length > this.pageLimit) {
|
|
196
|
+
// This means we have more pages to display still. Pop off
|
|
197
|
+
// the extra that we fetched.
|
|
198
|
+
list.pop();
|
|
199
|
+
this._totalCount = xhr.getResponseHeader('girder-total-count');
|
|
200
|
+
this._hasMorePages = true;
|
|
201
|
+
} else {
|
|
202
|
+
this._hasMorePages = false;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
var offsetDelta = list.length;
|
|
206
|
+
|
|
207
|
+
/*
|
|
208
|
+
* If filtering, decorate the list with their pre-filtered
|
|
209
|
+
* indexes. The index will be needed when adjusting the offset.
|
|
210
|
+
*/
|
|
211
|
+
if (this.filterFunc) {
|
|
212
|
+
var filter = this.filterFunc;
|
|
213
|
+
list = (
|
|
214
|
+
list
|
|
215
|
+
.map(function (x, index) { return [index, x]; })
|
|
216
|
+
.filter(function (tuple) {
|
|
217
|
+
return filter(tuple[1]);
|
|
218
|
+
})
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
var numUsed = list.length;
|
|
223
|
+
var wantMorePages = (
|
|
224
|
+
(this.pageLimit === 0) ||
|
|
225
|
+
(finalList.length + numUsed < this.pageLimit)
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
/* page is complete */
|
|
229
|
+
if (!wantMorePages && this.pageLimit > 0) {
|
|
230
|
+
/*
|
|
231
|
+
* If we fetched more data than we needed to complete the
|
|
232
|
+
* page, then newNumUsed will be < numUsed ...
|
|
233
|
+
*/
|
|
234
|
+
var newNumUsed = this.pageLimit - finalList.length;
|
|
235
|
+
if (numUsed > newNumUsed) {
|
|
236
|
+
/*
|
|
237
|
+
* ...therefore, entries are being left out at the end,
|
|
238
|
+
* so they necessarily remain to be fetched.
|
|
239
|
+
*/
|
|
240
|
+
this._hasMorePages = true;
|
|
241
|
+
numUsed = newNumUsed;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/*
|
|
245
|
+
* correct the offset: it must be advanced beyond the
|
|
246
|
+
* last element that got used.
|
|
247
|
+
*/
|
|
248
|
+
if (this.filterFunc) {
|
|
249
|
+
/*
|
|
250
|
+
* If filtering, consult the index for the last element
|
|
251
|
+
* to be featured on this page.
|
|
252
|
+
*/
|
|
253
|
+
offsetDelta = list[numUsed - 1][0] + 1;
|
|
254
|
+
} else {
|
|
255
|
+
/*
|
|
256
|
+
* Otherwise, the first numUsed elements will be
|
|
257
|
+
* unconditionally featured.
|
|
258
|
+
*/
|
|
259
|
+
offsetDelta = numUsed;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
list = list.slice(0, numUsed);
|
|
264
|
+
/* If filtering, undecorate the list. */
|
|
265
|
+
if (this.filterFunc) {
|
|
266
|
+
list = list.map(function (tuple) { return tuple[1]; });
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
finalList = finalList.concat(list);
|
|
270
|
+
this.offset += offsetDelta;
|
|
271
|
+
|
|
272
|
+
if (wantMorePages && this._hasMorePages) {
|
|
273
|
+
return fetchListFragment.apply(this);
|
|
274
|
+
} else {
|
|
275
|
+
if (finalList.length > 0 || reset) {
|
|
276
|
+
if (this.append && !reset) {
|
|
277
|
+
this.add(finalList);
|
|
278
|
+
} else {
|
|
279
|
+
this.reset(finalList);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
this.trigger('g:changed');
|
|
284
|
+
}
|
|
285
|
+
return undefined;
|
|
286
|
+
});
|
|
287
|
+
xhr.girder = { fetch: true };
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return fetchListFragment.apply(this);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
export default Collection;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Collection from '@girder/core/collections/Collection';
|
|
2
|
+
import CollectionModel from '@girder/core/models/CollectionModel';
|
|
3
|
+
|
|
4
|
+
var CollectionCollection = Collection.extend({
|
|
5
|
+
resourceName: 'collection',
|
|
6
|
+
model: CollectionModel
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export default CollectionCollection;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Collection from '@girder/core/collections/Collection';
|
|
2
|
+
import FileModel from '@girder/core/models/FileModel';
|
|
3
|
+
|
|
4
|
+
var FileCollection = Collection.extend({
|
|
5
|
+
resourceName: 'file',
|
|
6
|
+
model: FileModel,
|
|
7
|
+
|
|
8
|
+
pageLimit: 100
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export default FileCollection;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Collection from '@girder/core/collections/Collection';
|
|
2
|
+
import FolderModel from '@girder/core/models/FolderModel';
|
|
3
|
+
|
|
4
|
+
var FolderCollection = Collection.extend({
|
|
5
|
+
resourceName: 'folder',
|
|
6
|
+
model: FolderModel,
|
|
7
|
+
|
|
8
|
+
pageLimit: 100
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export default FolderCollection;
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
@@ -0,0 +1,24 @@
|
|
|
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;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
S3: 2
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
var Layout = {
|
|
22
|
+
DEFAULT: 'default',
|
|
23
|
+
EMPTY: 'empty'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
SORT_ASC, SORT_DESC,
|
|
28
|
+
MONTHS,
|
|
29
|
+
AccessType,
|
|
30
|
+
AssetstoreType,
|
|
31
|
+
Layout
|
|
32
|
+
};
|