@singularsystems/neo-core 1.0.0-alpha.2 → 1.0.0-alpha.4

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 (296) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/ApiClient/ApiClientBase.d.ts +5 -5
  3. package/dist/ApiClient/ApiClientBase.js +13 -13
  4. package/dist/ApiClient/ReadApiClient.d.ts +16 -16
  5. package/dist/ApiClient/ReadApiClient.js +24 -24
  6. package/dist/ApiClient/UpdateableApiClient.d.ts +28 -28
  7. package/dist/ApiClient/UpdateableApiClient.js +33 -33
  8. package/dist/AppServices/AppService.d.ts +46 -46
  9. package/dist/AppServices/AppService.js +25 -25
  10. package/dist/AppServices/Config/ConfigModel.d.ts +21 -20
  11. package/dist/AppServices/Config/ConfigModel.js +28 -17
  12. package/dist/AppServices/Config/ConfigService.d.ts +15 -15
  13. package/dist/AppServices/Config/ConfigService.js +49 -53
  14. package/dist/AppServices/Module.d.ts +11 -11
  15. package/dist/AppServices/Module.js +13 -13
  16. package/dist/AppServices/NeoContainer.d.ts +22 -22
  17. package/dist/AppServices/NeoContainer.js +42 -42
  18. package/dist/AppServices/NeoModule.d.ts +3 -3
  19. package/dist/AppServices/NeoModule.js +30 -30
  20. package/dist/AppServices/NeoTypes.d.ts +61 -61
  21. package/dist/AppServices/NeoTypes.js +42 -42
  22. package/dist/AppServices/ServiceIdentifier.d.ts +23 -23
  23. package/dist/AppServices/ServiceIdentifier.js +38 -39
  24. package/dist/AppServices/index.d.ts +7 -7
  25. package/dist/AppServices/index.js +7 -7
  26. package/dist/Components/AnimationHelper.d.ts +69 -69
  27. package/dist/Components/AnimationHelper.js +182 -182
  28. package/dist/Components/BootstrapHelpers.d.ts +8 -8
  29. package/dist/Components/BootstrapHelpers.js +30 -30
  30. package/dist/Components/BootstrapTypes.d.ts +35 -35
  31. package/dist/Components/BootstrapTypes.js +1 -1
  32. package/dist/Components/ButtonOptions.d.ts +63 -61
  33. package/dist/Components/ButtonOptions.js +1 -1
  34. package/dist/Components/ContextMenu/ContextMenu.d.ts +16 -16
  35. package/dist/Components/ContextMenu/ContextMenu.js +1 -1
  36. package/dist/Components/ContextMenu/MenuUtils.d.ts +16 -16
  37. package/dist/Components/ContextMenu/MenuUtils.js +34 -34
  38. package/dist/Components/DatePicker/DatePicker.d.ts +70 -69
  39. package/dist/Components/DatePicker/DatePicker.js +502 -487
  40. package/dist/Components/DatePicker/DatePickerOptions.d.ts +43 -34
  41. package/dist/Components/DatePicker/DatePickerOptions.js +33 -33
  42. package/dist/Components/ErrorHandler.d.ts +59 -55
  43. package/dist/Components/ErrorHandler.js +210 -138
  44. package/dist/Components/FileManager/BoundFileManager.d.ts +18 -18
  45. package/dist/Components/FileManager/BoundFileManager.js +60 -60
  46. package/dist/Components/FileManager/FileManager.d.ts +80 -78
  47. package/dist/Components/FileManager/FileManager.js +277 -257
  48. package/dist/Components/FileManager/FileUploadBatch.d.ts +37 -37
  49. package/dist/Components/FileManager/FileUploadBatch.js +83 -82
  50. package/dist/Components/FileManager/IFileManagerOptions.d.ts +42 -42
  51. package/dist/Components/FileManager/IFileManagerOptions.js +1 -1
  52. package/dist/Components/FormOptions.d.ts +34 -34
  53. package/dist/Components/FormOptions.js +1 -1
  54. package/dist/Components/ICollapsableOptions.d.ts +11 -11
  55. package/dist/Components/ICollapsableOptions.js +1 -1
  56. package/dist/Components/Modal/ModalHelper.d.ts +31 -31
  57. package/dist/Components/Modal/ModalHelper.js +174 -174
  58. package/dist/Components/Modal/ModalOptions.d.ts +61 -61
  59. package/dist/Components/Modal/ModalOptions.js +1 -1
  60. package/dist/Components/Modal/ModalStore.d.ts +32 -32
  61. package/dist/Components/Modal/ModalStore.js +82 -82
  62. package/dist/Components/Modal/ModalUtils.d.ts +61 -61
  63. package/dist/Components/Modal/ModalUtils.js +109 -109
  64. package/dist/Components/Notifications/INotificationHelper.d.ts +56 -56
  65. package/dist/Components/Notifications/INotificationHelper.js +1 -1
  66. package/dist/Components/Notifications/Notification.d.ts +32 -32
  67. package/dist/Components/Notifications/Notification.js +26 -27
  68. package/dist/Components/Notifications/NotificationHelper.d.ts +63 -63
  69. package/dist/Components/Notifications/NotificationHelper.js +111 -112
  70. package/dist/Components/Notifications/NotificationStore.d.ts +34 -34
  71. package/dist/Components/Notifications/NotificationStore.js +78 -79
  72. package/dist/Components/PositionHelper.d.ts +10 -10
  73. package/dist/Components/PositionHelper.js +43 -43
  74. package/dist/Components/TaskRunner/Decorators.d.ts +6 -6
  75. package/dist/Components/TaskRunner/Decorators.js +24 -24
  76. package/dist/Components/TaskRunner/ProgressState.d.ts +22 -22
  77. package/dist/Components/TaskRunner/ProgressState.js +71 -72
  78. package/dist/Components/TaskRunner/TaskRunner.d.ts +114 -114
  79. package/dist/Components/TaskRunner/TaskRunner.js +253 -244
  80. package/dist/Components/TooltipOptions.d.ts +8 -8
  81. package/dist/Components/TooltipOptions.js +1 -1
  82. package/dist/Components/index.d.ts +22 -22
  83. package/dist/Components/index.js +13 -13
  84. package/dist/ConnectionManager.d.ts +45 -45
  85. package/dist/ConnectionManager.js +60 -61
  86. package/dist/Data/ApiDataSource.d.ts +46 -46
  87. package/dist/Data/ApiDataSource.js +140 -144
  88. package/dist/Data/AsyncDataSource.d.ts +35 -35
  89. package/dist/Data/AsyncDataSource.js +79 -80
  90. package/dist/Data/CacheService.d.ts +40 -40
  91. package/dist/Data/CacheService.js +63 -64
  92. package/dist/Data/DataCacheEntry.d.ts +42 -42
  93. package/dist/Data/DataCacheEntry.js +80 -80
  94. package/dist/Data/DataView.d.ts +43 -43
  95. package/dist/Data/DataView.js +173 -172
  96. package/dist/Data/Deserialiser.d.ts +42 -42
  97. package/dist/Data/Deserialiser.js +255 -255
  98. package/dist/Data/Paging/PageManager.d.ts +167 -167
  99. package/dist/Data/Paging/PageManager.js +323 -323
  100. package/dist/Data/Paging/PageRequest.d.ts +24 -24
  101. package/dist/Data/Paging/PageRequest.js +38 -39
  102. package/dist/Data/Paging/PageResult.d.ts +10 -10
  103. package/dist/Data/Paging/PageResult.js +14 -14
  104. package/dist/Data/Serialiser.d.ts +41 -41
  105. package/dist/Data/Serialiser.js +201 -201
  106. package/dist/Data/SortOperation.d.ts +8 -8
  107. package/dist/Data/SortOperation.js +26 -26
  108. package/dist/Data/StaticDataSource.d.ts +9 -9
  109. package/dist/Data/StaticDataSource.js +27 -27
  110. package/dist/Data/WindowedDataView.d.ts +8 -8
  111. package/dist/Data/WindowedDataView.js +49 -50
  112. package/dist/Data/index.d.ts +15 -15
  113. package/dist/Data/index.js +15 -15
  114. package/dist/Dates/DateUtils.d.ts +47 -47
  115. package/dist/Dates/DateUtils.js +226 -226
  116. package/dist/Dates/TimeSpan.d.ts +24 -24
  117. package/dist/Dates/TimeSpan.js +46 -46
  118. package/dist/DebounceHelper.d.ts +44 -38
  119. package/dist/DebounceHelper.js +122 -95
  120. package/dist/Extensions.d.ts +82 -82
  121. package/dist/Extensions.js +182 -182
  122. package/dist/FileUtils.d.ts +6 -6
  123. package/dist/FileUtils.js +37 -37
  124. package/dist/Globals.d.ts +19 -19
  125. package/dist/Globals.js +41 -41
  126. package/dist/JsonSchema/ClassMetadata.d.ts +25 -25
  127. package/dist/JsonSchema/ClassMetadata.js +53 -53
  128. package/dist/JsonSchema/JsonData.d.ts +16 -16
  129. package/dist/JsonSchema/JsonData.js +97 -97
  130. package/dist/JsonSchema/JsonSchemaTypes.d.ts +37 -37
  131. package/dist/JsonSchema/JsonSchemaTypes.js +1 -1
  132. package/dist/JsonSchema/PropertyMetadata.d.ts +8 -8
  133. package/dist/JsonSchema/PropertyMetadata.js +8 -8
  134. package/dist/JsonSchema/TypeCache.d.ts +16 -16
  135. package/dist/JsonSchema/TypeCache.js +44 -44
  136. package/dist/JsonSchema/TypeMetadata.d.ts +45 -45
  137. package/dist/JsonSchema/TypeMetadata.js +170 -170
  138. package/dist/JsonSchema/index.d.ts +7 -7
  139. package/dist/JsonSchema/index.js +6 -6
  140. package/dist/Localisation/ILocalisationService.d.ts +11 -11
  141. package/dist/Localisation/ILocalisationService.js +1 -1
  142. package/dist/Localisation/LocalisationService.d.ts +4 -4
  143. package/dist/Localisation/LocalisationService.js +17 -17
  144. package/dist/Localisation/index.d.ts +1 -1
  145. package/dist/Localisation/index.js +1 -1
  146. package/dist/Misc.d.ts +6 -6
  147. package/dist/Misc.js +6 -6
  148. package/dist/Model/BaseModels/AuditValues.d.ts +12 -12
  149. package/dist/Model/BaseModels/AuditValues.js +46 -48
  150. package/dist/Model/BaseModels/CriteriaBase.d.ts +18 -16
  151. package/dist/Model/BaseModels/CriteriaBase.js +45 -34
  152. package/dist/Model/BaseModels/FileDescriptorBase.d.ts +12 -12
  153. package/dist/Model/BaseModels/FileDescriptorBase.js +22 -22
  154. package/dist/Model/BaseModels/ReasonedUserEvent.d.ts +5 -4
  155. package/dist/Model/BaseModels/ReasonedUserEvent.js +23 -19
  156. package/dist/Model/BaseModels/UserEvent.d.ts +9 -8
  157. package/dist/Model/BaseModels/UserEvent.js +36 -32
  158. package/dist/Model/BindableBase.d.ts +46 -40
  159. package/dist/Model/BindableBase.js +79 -76
  160. package/dist/Model/Decorators.d.ts +47 -44
  161. package/dist/Model/Decorators.js +182 -177
  162. package/dist/Model/EnumHelper.d.ts +54 -54
  163. package/dist/Model/EnumHelper.js +104 -100
  164. package/dist/Model/IAutoRunner.d.ts +5 -5
  165. package/dist/Model/IAutoRunner.js +1 -1
  166. package/dist/Model/IModelBase.d.ts +92 -79
  167. package/dist/Model/IModelBase.js +1 -1
  168. package/dist/Model/IModelCreatorBase.d.ts +9 -9
  169. package/dist/Model/IModelCreatorBase.js +1 -1
  170. package/dist/Model/List.d.ts +79 -77
  171. package/dist/Model/List.js +208 -198
  172. package/dist/Model/LookupBase.d.ts +13 -6
  173. package/dist/Model/LookupBase.js +19 -10
  174. package/dist/Model/Misc.d.ts +83 -81
  175. package/dist/Model/Misc.js +59 -59
  176. package/dist/Model/ModelBase.d.ts +88 -86
  177. package/dist/Model/ModelBase.js +182 -180
  178. package/dist/Model/ModelCreatorBase.d.ts +24 -23
  179. package/dist/Model/ModelCreatorBase.js +92 -92
  180. package/dist/Model/ModelFieldInfo.d.ts +29 -12
  181. package/dist/Model/ModelFieldInfo.js +35 -26
  182. package/dist/Model/ModelGraphTraverser.d.ts +35 -35
  183. package/dist/Model/ModelGraphTraverser.js +101 -99
  184. package/dist/Model/NeoModel.d.ts +6 -6
  185. package/dist/Model/NeoModel.js +13 -13
  186. package/dist/Model/NeoTypeInfo.d.ts +52 -41
  187. package/dist/Model/NeoTypeInfo.js +300 -250
  188. package/dist/Model/ObservableProperty.d.ts +8 -8
  189. package/dist/Model/ObservableProperty.js +41 -41
  190. package/dist/Model/ObservableValue.d.ts +9 -9
  191. package/dist/Model/ObservableValue.js +25 -26
  192. package/dist/Model/PropertyInfo.d.ts +83 -81
  193. package/dist/Model/PropertyInfo.js +138 -137
  194. package/dist/Model/PropertyInstance.d.ts +84 -48
  195. package/dist/Model/PropertyInstance.js +173 -113
  196. package/dist/Model/ValueObject.d.ts +3 -3
  197. package/dist/Model/ValueObject.js +10 -10
  198. package/dist/Model/index.d.ts +15 -14
  199. package/dist/Model/index.js +13 -12
  200. package/dist/NumberUtils.d.ts +63 -49
  201. package/dist/NumberUtils.js +247 -197
  202. package/dist/Routing/IMenuItemProvider.d.ts +9 -9
  203. package/dist/Routing/IMenuItemProvider.js +1 -1
  204. package/dist/Routing/IMenuRoute.d.ts +18 -18
  205. package/dist/Routing/IMenuRoute.js +1 -1
  206. package/dist/Routing/INavigationHelper.d.ts +7 -7
  207. package/dist/Routing/INavigationHelper.js +1 -1
  208. package/dist/Routing/IPageLeaveHandler.d.ts +23 -23
  209. package/dist/Routing/IPageLeaveHandler.js +7 -7
  210. package/dist/Routing/IRoute.d.ts +27 -27
  211. package/dist/Routing/IRoute.js +1 -1
  212. package/dist/Routing/IRouteSecurityService.d.ts +14 -14
  213. package/dist/Routing/IRouteSecurityService.js +1 -1
  214. package/dist/Routing/MenuItemProvider.d.ts +17 -17
  215. package/dist/Routing/MenuItemProvider.js +53 -54
  216. package/dist/Routing/RouteSecurityService.d.ts +18 -18
  217. package/dist/Routing/RouteSecurityService.js +35 -36
  218. package/dist/Routing/index.d.ts +7 -7
  219. package/dist/Routing/index.js +3 -3
  220. package/dist/Security/IAuthenticationService.d.ts +41 -36
  221. package/dist/Security/IAuthenticationService.js +1 -1
  222. package/dist/Security/IAuthorisationService.d.ts +11 -11
  223. package/dist/Security/IAuthorisationService.js +1 -1
  224. package/dist/Security/ILoginErrorHandler.d.ts +4 -4
  225. package/dist/Security/ILoginErrorHandler.js +1 -1
  226. package/dist/Security/ISecurityService.d.ts +10 -10
  227. package/dist/Security/ISecurityService.js +1 -1
  228. package/dist/Security/IUser.d.ts +10 -10
  229. package/dist/Security/IUser.js +1 -1
  230. package/dist/Security/IUserRole.d.ts +6 -6
  231. package/dist/Security/IUserRole.js +1 -1
  232. package/dist/Security/LoginErrorHandler.d.ts +15 -15
  233. package/dist/Security/LoginErrorHandler.js +97 -98
  234. package/dist/Security/Oidc/OidcAuthService.d.ts +67 -60
  235. package/dist/Security/Oidc/OidcAuthService.js +216 -189
  236. package/dist/Security/Oidc/OidcTypes.d.ts +46 -29
  237. package/dist/Security/Oidc/OidcTypes.js +1 -1
  238. package/dist/Security/Oidc/OidcUser.d.ts +9 -9
  239. package/dist/Security/Oidc/OidcUser.js +33 -33
  240. package/dist/Security/SecurityService.d.ts +12 -12
  241. package/dist/Security/SecurityService.js +33 -34
  242. package/dist/Security/SignInResult.d.ts +13 -13
  243. package/dist/Security/SignInResult.js +8 -8
  244. package/dist/Security/User.d.ts +12 -12
  245. package/dist/Security/User.js +24 -24
  246. package/dist/Security/index.d.ts +10 -10
  247. package/dist/Security/index.js +5 -5
  248. package/dist/Settings.d.ts +71 -57
  249. package/dist/Settings.js +100 -87
  250. package/dist/SignalR/HubBase.d.ts +70 -70
  251. package/dist/SignalR/HubBase.js +164 -164
  252. package/dist/SignalR/HubReceiver.d.ts +11 -11
  253. package/dist/SignalR/HubReceiver.js +25 -25
  254. package/dist/SignalR/HubSubscription.d.ts +12 -12
  255. package/dist/SignalR/HubSubscription.js +14 -14
  256. package/dist/SignalR/index.d.ts +3 -3
  257. package/dist/SignalR/index.js +1 -1
  258. package/dist/StringUtils.d.ts +7 -7
  259. package/dist/StringUtils.js +24 -24
  260. package/dist/Utils.d.ts +81 -80
  261. package/dist/Utils.js +220 -218
  262. package/dist/Validation/Decorators.d.ts +12 -12
  263. package/dist/Validation/Decorators.js +52 -52
  264. package/dist/Validation/DisplayHelper.d.ts +20 -19
  265. package/dist/Validation/DisplayHelper.js +104 -104
  266. package/dist/Validation/Misc.d.ts +10 -10
  267. package/dist/Validation/Misc.js +11 -11
  268. package/dist/Validation/ModelProxy.d.ts +20 -20
  269. package/dist/Validation/ModelProxy.js +46 -46
  270. package/dist/Validation/RuleContext.d.ts +86 -86
  271. package/dist/Validation/RuleContext.js +130 -130
  272. package/dist/Validation/Rules.d.ts +70 -70
  273. package/dist/Validation/Rules.js +177 -177
  274. package/dist/Validation/ValidationHelpers.d.ts +12 -12
  275. package/dist/Validation/ValidationHelpers.js +57 -57
  276. package/dist/Validation/ValidationRules.d.ts +18 -18
  277. package/dist/Validation/ValidationRules.js +34 -34
  278. package/dist/Validation/ValidationState.d.ts +42 -42
  279. package/dist/Validation/ValidationState.js +74 -74
  280. package/dist/Validation/Validators/IModelValidator.d.ts +28 -24
  281. package/dist/Validation/Validators/IModelValidator.js +1 -1
  282. package/dist/Validation/Validators/IPropertyValidator.d.ts +21 -21
  283. package/dist/Validation/Validators/IPropertyValidator.js +15 -15
  284. package/dist/Validation/Validators/ModelValidator.d.ts +46 -45
  285. package/dist/Validation/Validators/ModelValidator.js +143 -137
  286. package/dist/Validation/Validators/PropertyValidator.d.ts +21 -21
  287. package/dist/Validation/Validators/PropertyValidator.js +64 -67
  288. package/dist/Validation/Validators/RuleValidator.d.ts +19 -19
  289. package/dist/Validation/Validators/RuleValidator.js +51 -55
  290. package/dist/Validation/index.d.ts +9 -9
  291. package/dist/Validation/index.js +7 -7
  292. package/dist/Views/IViewBase.d.ts +5 -5
  293. package/dist/Views/IViewBase.js +1 -1
  294. package/dist/index.d.ts +37 -36
  295. package/dist/index.js +44 -43
  296. package/package.json +11 -10
@@ -1,257 +1,277 @@
1
- import { __awaiter, __decorate, __extends, __generator, __metadata } from "tslib";
2
- import NeoModel from '../../Model/NeoModel';
3
- import { ModalUtils } from '../Modal/ModalUtils';
4
- import { Observable } from '../../Model/Decorators';
5
- import { Globals } from '../../Misc';
6
- import { NeoTypes } from '../../AppServices';
7
- import { ErrorDisplayType } from '../ErrorHandler';
8
- import { Settings } from '../../Settings';
9
- import { FileUploadBatch } from './FileUploadBatch';
10
- var fileInputSymbol = Symbol("FileInput");
11
- var FileManagerBase = /** @class */ (function () {
12
- function FileManagerBase(uploadEndpointOrOptions, options) {
13
- this.currentUploads = [];
14
- if (uploadEndpointOrOptions === undefined || typeof uploadEndpointOrOptions === "string") {
15
- this._uploadEndpoint = uploadEndpointOrOptions;
16
- this.options = options || {};
17
- }
18
- else {
19
- this.options = uploadEndpointOrOptions;
20
- }
21
- }
22
- Object.defineProperty(FileManagerBase.prototype, "isUploading", {
23
- get: function () {
24
- return this.currentUploads.length > 0;
25
- },
26
- enumerable: false,
27
- configurable: true
28
- });
29
- Object.defineProperty(FileManagerBase.prototype, "uploadPercent", {
30
- get: function () {
31
- var totalSize = 0;
32
- var totalProgress = 0;
33
- for (var _i = 0, _a = this.currentUploads; _i < _a.length; _i++) {
34
- var batch = _a[_i];
35
- totalSize += batch.totalSize;
36
- totalProgress += batch.totalSize * batch.uploadPercent;
37
- }
38
- return totalSize === 0 ? 1 : (totalProgress / totalSize);
39
- },
40
- enumerable: false,
41
- configurable: true
42
- });
43
- Object.defineProperty(FileManagerBase.prototype, "uploadEndpoint", {
44
- get: function () {
45
- return this._uploadEndpoint;
46
- },
47
- enumerable: false,
48
- configurable: true
49
- });
50
- /**
51
- * Shows a file dialog and then calls processFiles.
52
- * onFilesSelected will be called if you need to handle the event.
53
- */
54
- FileManagerBase.prototype.showFileDialog = function () {
55
- var fileInput = document.getElementById("neo-file-input");
56
- if (!fileInput) {
57
- // Its 2020, and this is still the only way to open a file select dialog programmatically.
58
- fileInput = document.createElement("input");
59
- fileInput.type = "file";
60
- fileInput.id = "neo-file-input";
61
- fileInput.style.display = "none";
62
- fileInput.addEventListener("change", function (e) {
63
- var fileManager = fileInput[fileInputSymbol];
64
- if (fileInput.files) {
65
- fileManager.processFiles(fileInput.files, { handleErrors: !fileManager.options.taskRunner }).finally(function () {
66
- fileInput.value = "";
67
- });
68
- }
69
- });
70
- document.body.appendChild(fileInput);
71
- }
72
- fileInput[fileInputSymbol] = this;
73
- this.setFileInputValues(fileInput);
74
- fileInput.click();
75
- };
76
- /** Checks if the file extensions are allowed. Shows a modal if not. */
77
- FileManagerBase.prototype.validateFiles = function (files) {
78
- var checkResult = this.checkFileExtensions(files);
79
- if (checkResult.allowed) {
80
- return true;
81
- }
82
- else {
83
- ModalUtils.showMessage("File Upload", "File extension: " + checkResult.extension + " is not allowed.");
84
- return false;
85
- }
86
- };
87
- /**
88
- * Checks if file extensions are allowed, then calls onFilesSelected, or uploadFiles
89
- */
90
- FileManagerBase.prototype.processFiles = function (files, options) {
91
- if (options === void 0) { options = {}; }
92
- return __awaiter(this, void 0, void 0, function () {
93
- return __generator(this, function (_a) {
94
- if (this.validateFiles(files)) {
95
- if (this.options.onFilesSelected) {
96
- this.options.onFilesSelected(files, this);
97
- }
98
- else if (this.uploadEndpoint) {
99
- if (!options.additionalData && this.options.additionalData) {
100
- if (typeof this.options.additionalData === "function") {
101
- options.additionalData = this.options.additionalData();
102
- }
103
- else {
104
- options.additionalData = this.options.additionalData;
105
- }
106
- }
107
- return [2 /*return*/, this.uploadFiles(files, options)];
108
- }
109
- else {
110
- throw Error("You must specify at least one of uploadEndpoint, or onFilesSelected.");
111
- }
112
- }
113
- return [2 /*return*/];
114
- });
115
- });
116
- };
117
- FileManagerBase.prototype.uploadFiles = function (files, options) {
118
- var _this = this;
119
- var _a;
120
- if (options === void 0) { options = {}; }
121
- if (!this.uploadEndpoint) {
122
- throw Error("uploadFiles() can only be called if an uploadEndpoint has been specified.");
123
- }
124
- if (!this.options.allowConcurrent && this.isUploading) {
125
- throw Error("A file upload is already in progress, please wait for the current operation to complete.");
126
- }
127
- var formData = new FormData();
128
- if (options.additionalData) {
129
- for (var key in options.additionalData) {
130
- formData.append(key, options.additionalData[key].toString());
131
- }
132
- }
133
- var uploadBatch;
134
- if (files instanceof FileUploadBatch) {
135
- uploadBatch = files;
136
- }
137
- else {
138
- uploadBatch = new FileUploadBatch(files);
139
- }
140
- this.currentUploads.push(uploadBatch);
141
- for (var i = 0; i < uploadBatch.files.length; i++) {
142
- formData.append("file" + i, uploadBatch.files[i]);
143
- }
144
- var config = {
145
- headers: {
146
- 'Content-Type': 'multipart/form-data'
147
- },
148
- onUploadProgress: function (progressEvent) {
149
- if (progressEvent.total > 0) {
150
- uploadBatch.uploadPercent = progressEvent.loaded / progressEvent.total;
151
- }
152
- if (_this.options.taskRunner) {
153
- // Default to 90% of progress because it seems to hit 100% a while before the axios promise resolves.
154
- _this.options.taskRunner.progressState.progress = _this.uploadPercent * (_this.options.percentOfTask || 0.9);
155
- }
156
- }
157
- };
158
- var uploadTask = new Promise(function (resolve, reject) {
159
- // Send data to server
160
- Globals.appService.get(NeoTypes.Axios).post(_this.uploadEndpoint, formData, config).then(function (response) {
161
- _this.afterUpload(response.data);
162
- if (_this.options.afterUpload) {
163
- _this.options.afterUpload(response.data);
164
- }
165
- resolve(response.data);
166
- }).catch(function (e) {
167
- if (options.handleErrors) {
168
- Globals.appService.get(NeoTypes.UI.ErrorHandler).showError(e, ErrorDisplayType.ShowModal);
169
- }
170
- uploadBatch.uploadError = e.toString();
171
- reject(e);
172
- }).finally(function () {
173
- uploadBatch.isComplete = true;
174
- _this.currentUploads.remove(uploadBatch);
175
- });
176
- });
177
- if (this.options.taskRunner) {
178
- this.options.taskRunner.waitFor(uploadTask, { loadingText: (_a = this.options.taskRunnerLoadingText) === null || _a === void 0 ? void 0 : _a.format(uploadBatch.toString()), autoProgress: false });
179
- }
180
- return uploadTask;
181
- };
182
- FileManagerBase.prototype.setFileInputValues = function (fileInput) {
183
- var props = this.getFileInputProps();
184
- for (var attribute in props) {
185
- fileInput[attribute] = props[attribute];
186
- }
187
- fileInput.value = "";
188
- };
189
- FileManagerBase.prototype.getFileInputProps = function () {
190
- var props = {};
191
- if (this.options.accept) {
192
- props.accept = this.options.accept;
193
- }
194
- else if (this.options.allowedExtensions) {
195
- props.accept = this.options.allowedExtensions.join();
196
- }
197
- else if (Settings.fileManager.allowedExtensions.length) {
198
- props.accept = Settings.fileManager.allowedExtensions.join();
199
- }
200
- else {
201
- props.accept = "";
202
- }
203
- return props;
204
- };
205
- FileManagerBase.prototype.afterUpload = function (response) {
206
- };
207
- /** Checks if the file extensions are allowed. */
208
- FileManagerBase.prototype.checkFileExtensions = function (files) {
209
- var _a;
210
- for (var _i = 0, _b = Array.from(files); _i < _b.length; _i++) {
211
- var file = _b[_i];
212
- var extension = void 0;
213
- if (file.name.indexOf(".") > 0) {
214
- extension = "." + ((_a = file.name.split('.').pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase());
215
- if (this.options.allowedExtensions) {
216
- if (this.options.allowedExtensions.indexOf(extension) < 0) {
217
- return { allowed: false, extension: extension };
218
- }
219
- }
220
- else {
221
- if (Settings.fileManager.allowedExtensions.length && Settings.fileManager.allowedExtensions.indexOf(extension) < 0) {
222
- return { allowed: false, extension: extension };
223
- }
224
- if (Settings.fileManager.disallowedFileExtensions.length && Settings.fileManager.disallowedFileExtensions.indexOf(extension) >= 0) {
225
- return { allowed: false, extension: extension };
226
- }
227
- }
228
- }
229
- else {
230
- return { allowed: false, extension: "(none)" };
231
- }
232
- }
233
- return { allowed: true, extension: "" };
234
- };
235
- __decorate([
236
- Observable(),
237
- __metadata("design:type", Array)
238
- ], FileManagerBase.prototype, "currentUploads", void 0);
239
- return FileManagerBase;
240
- }());
241
- export { FileManagerBase };
242
- var FileManager = /** @class */ (function (_super) {
243
- __extends(FileManager, _super);
244
- function FileManager() {
245
- return _super !== null && _super.apply(this, arguments) || this;
246
- }
247
- FileManager.prototype.getFileInputProps = function () {
248
- var props = _super.prototype.getFileInputProps.call(this);
249
- props.multiple = this.options.multiple === true;
250
- return props;
251
- };
252
- FileManager = __decorate([
253
- NeoModel
254
- ], FileManager);
255
- return FileManager;
256
- }(FileManagerBase));
257
- export default FileManager;
1
+ import { __awaiter, __decorate, __extends, __generator, __metadata } from "tslib";
2
+ import NeoModel from '../../Model/NeoModel';
3
+ import { ModalUtils } from '../Modal/ModalUtils';
4
+ import { Observable } from '../../Model/Decorators';
5
+ import { Globals } from '../../Misc';
6
+ import { NeoTypes } from '../../AppServices';
7
+ import { ErrorDisplayType } from '../ErrorHandler';
8
+ import { Settings } from '../../Settings';
9
+ import { FileUploadBatch } from './FileUploadBatch';
10
+ var fileInputSymbol = Symbol("FileInput");
11
+ export var FileManagerBase = /** @class */ (function () {
12
+ function FileManagerBase(uploadEndpointOrOptions, options) {
13
+ this.currentUploads = [];
14
+ if (uploadEndpointOrOptions === undefined || typeof uploadEndpointOrOptions === "string") {
15
+ this._uploadEndpoint = uploadEndpointOrOptions;
16
+ this.options = options || {};
17
+ }
18
+ else {
19
+ this.options = uploadEndpointOrOptions;
20
+ }
21
+ }
22
+ Object.defineProperty(FileManagerBase.prototype, "isUploading", {
23
+ get: function () {
24
+ return this.currentUploads.length > 0;
25
+ },
26
+ enumerable: false,
27
+ configurable: true
28
+ });
29
+ Object.defineProperty(FileManagerBase.prototype, "uploadPercent", {
30
+ get: function () {
31
+ var totalSize = 0;
32
+ var totalProgress = 0;
33
+ for (var _i = 0, _a = this.currentUploads; _i < _a.length; _i++) {
34
+ var batch = _a[_i];
35
+ totalSize += batch.totalSize;
36
+ totalProgress += batch.totalSize * batch.uploadPercent;
37
+ }
38
+ return totalSize === 0 ? 1 : (totalProgress / totalSize);
39
+ },
40
+ enumerable: false,
41
+ configurable: true
42
+ });
43
+ Object.defineProperty(FileManagerBase.prototype, "uploadEndpoint", {
44
+ get: function () {
45
+ return this._uploadEndpoint;
46
+ },
47
+ enumerable: false,
48
+ configurable: true
49
+ });
50
+ Object.defineProperty(FileManagerBase.prototype, "allowMultiple", {
51
+ get: function () {
52
+ return false;
53
+ },
54
+ enumerable: false,
55
+ configurable: true
56
+ });
57
+ /**
58
+ * Shows a file dialog and then calls processFiles.
59
+ * onFilesSelected will be called if you need to handle the event.
60
+ */
61
+ FileManagerBase.prototype.showFileDialog = function () {
62
+ var fileInput = document.getElementById("neo-file-input");
63
+ if (!fileInput) {
64
+ // Its 2020, and this is still the only way to open a file select dialog programmatically.
65
+ fileInput = document.createElement("input");
66
+ fileInput.type = "file";
67
+ fileInput.id = "neo-file-input";
68
+ fileInput.style.display = "none";
69
+ fileInput.addEventListener("change", function (e) {
70
+ // @ts-ignore
71
+ var fileManager = fileInput[fileInputSymbol];
72
+ if (fileInput.files) {
73
+ fileManager.processFiles(fileInput.files, { handleErrors: !fileManager.options.taskRunner }).finally(function () {
74
+ fileInput.value = "";
75
+ });
76
+ }
77
+ });
78
+ document.body.appendChild(fileInput);
79
+ }
80
+ // @ts-ignore
81
+ fileInput[fileInputSymbol] = this;
82
+ this.setFileInputValues(fileInput);
83
+ fileInput.click();
84
+ };
85
+ /** Checks if the file extensions are allowed. Shows a modal if not. */
86
+ FileManagerBase.prototype.validateFiles = function (files) {
87
+ var checkResult = this.checkFileExtensions(files);
88
+ if (checkResult.allowed) {
89
+ return true;
90
+ }
91
+ else {
92
+ ModalUtils.showMessage("File Upload", "File extension: " + checkResult.extension + " is not allowed.");
93
+ return false;
94
+ }
95
+ };
96
+ /**
97
+ * Checks if file extensions are allowed, then calls onFilesSelected, or uploadFiles
98
+ */
99
+ FileManagerBase.prototype.processFiles = function (files, options) {
100
+ if (options === void 0) { options = {}; }
101
+ return __awaiter(this, void 0, void 0, function () {
102
+ return __generator(this, function (_a) {
103
+ if (files.length > 1 && !this.allowMultiple) {
104
+ files = [Array.from(files)[0]];
105
+ }
106
+ if (this.validateFiles(files)) {
107
+ if (this.options.onFilesSelected) {
108
+ return [2 /*return*/, Promise.resolve(this.options.onFilesSelected(files, this))];
109
+ }
110
+ else if (this.uploadEndpoint) {
111
+ if (!options.additionalData && this.options.additionalData) {
112
+ if (typeof this.options.additionalData === "function") {
113
+ options.additionalData = this.options.additionalData();
114
+ }
115
+ else {
116
+ options.additionalData = this.options.additionalData;
117
+ }
118
+ }
119
+ return [2 /*return*/, this.uploadFiles(files, options)];
120
+ }
121
+ else {
122
+ throw Error("You must specify at least one of uploadEndpoint, or onFilesSelected.");
123
+ }
124
+ }
125
+ return [2 /*return*/];
126
+ });
127
+ });
128
+ };
129
+ FileManagerBase.prototype.uploadFiles = function (files, options) {
130
+ var _this = this;
131
+ var _a;
132
+ if (options === void 0) { options = {}; }
133
+ if (!this.uploadEndpoint) {
134
+ throw Error("uploadFiles() can only be called if an uploadEndpoint has been specified.");
135
+ }
136
+ if (!this.options.allowConcurrent && this.isUploading) {
137
+ throw Error("A file upload is already in progress, please wait for the current operation to complete.");
138
+ }
139
+ var formData = new FormData();
140
+ if (options.additionalData) {
141
+ for (var key in options.additionalData) {
142
+ formData.append(key, options.additionalData[key].toString());
143
+ }
144
+ }
145
+ var uploadBatch;
146
+ if (files instanceof FileUploadBatch) {
147
+ uploadBatch = files;
148
+ }
149
+ else {
150
+ uploadBatch = new FileUploadBatch(files);
151
+ }
152
+ this.currentUploads.push(uploadBatch);
153
+ for (var i = 0; i < uploadBatch.files.length; i++) {
154
+ formData.append("file" + i, uploadBatch.files[i]);
155
+ }
156
+ var config = {
157
+ headers: {
158
+ 'Content-Type': 'multipart/form-data'
159
+ },
160
+ onUploadProgress: function (progressEvent) {
161
+ if (progressEvent.total && progressEvent.total > 0) {
162
+ uploadBatch.uploadPercent = progressEvent.loaded / progressEvent.total;
163
+ }
164
+ if (_this.options.taskRunner) {
165
+ // Default to 90% of progress because it seems to hit 100% a while before the axios promise resolves.
166
+ _this.options.taskRunner.progressState.progress = _this.uploadPercent * (_this.options.percentOfTask || 0.9);
167
+ }
168
+ }
169
+ };
170
+ var uploadTask = new Promise(function (resolve, reject) {
171
+ // Send data to server
172
+ Globals.appService.get(NeoTypes.Axios).post(_this.uploadEndpoint, formData, config).then(function (response) {
173
+ _this.afterUpload(response.data);
174
+ if (_this.options.afterUpload) {
175
+ _this.options.afterUpload(response.data);
176
+ }
177
+ resolve(response.data);
178
+ }).catch(function (e) {
179
+ if (options.handleErrors) {
180
+ Globals.appService.get(NeoTypes.UI.ErrorHandler).showError(e, ErrorDisplayType.ShowModal);
181
+ }
182
+ uploadBatch.uploadError = e.toString();
183
+ reject(e);
184
+ }).finally(function () {
185
+ uploadBatch.isComplete = true;
186
+ _this.currentUploads.remove(uploadBatch);
187
+ });
188
+ });
189
+ if (this.options.taskRunner) {
190
+ this.options.taskRunner.waitFor(uploadTask, { loadingText: (_a = this.options.taskRunnerLoadingText) === null || _a === void 0 ? void 0 : _a.format(uploadBatch.toString()), autoProgress: false });
191
+ }
192
+ return uploadTask;
193
+ };
194
+ FileManagerBase.prototype.setFileInputValues = function (fileInput) {
195
+ var props = this.getFileInputProps();
196
+ for (var attribute in props) {
197
+ // @ts-ignore
198
+ fileInput[attribute] = props[attribute];
199
+ }
200
+ fileInput.value = "";
201
+ };
202
+ FileManagerBase.prototype.getFileInputProps = function () {
203
+ var props = {};
204
+ if (this.options.accept) {
205
+ props.accept = this.options.accept;
206
+ }
207
+ else if (this.options.allowedExtensions) {
208
+ props.accept = this.options.allowedExtensions.join();
209
+ }
210
+ else if (Settings.fileManager.allowedExtensions.length) {
211
+ props.accept = Settings.fileManager.allowedExtensions.join();
212
+ }
213
+ else {
214
+ props.accept = "";
215
+ }
216
+ return props;
217
+ };
218
+ FileManagerBase.prototype.afterUpload = function (response) {
219
+ };
220
+ /** Checks if the file extensions are allowed. */
221
+ FileManagerBase.prototype.checkFileExtensions = function (files) {
222
+ var _a;
223
+ for (var _i = 0, _b = Array.from(files); _i < _b.length; _i++) {
224
+ var file = _b[_i];
225
+ var extension = void 0;
226
+ if (file.name.indexOf(".") > 0) {
227
+ extension = "." + ((_a = file.name.split('.').pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase());
228
+ if (this.options.allowedExtensions) {
229
+ if (this.options.allowedExtensions.indexOf(extension) < 0) {
230
+ return { allowed: false, extension: extension };
231
+ }
232
+ }
233
+ else {
234
+ if (Settings.fileManager.allowedExtensions.length && Settings.fileManager.allowedExtensions.indexOf(extension) < 0) {
235
+ return { allowed: false, extension: extension };
236
+ }
237
+ if (Settings.fileManager.disallowedFileExtensions.length && Settings.fileManager.disallowedFileExtensions.indexOf(extension) >= 0) {
238
+ return { allowed: false, extension: extension };
239
+ }
240
+ }
241
+ }
242
+ else {
243
+ return { allowed: false, extension: "(none)" };
244
+ }
245
+ }
246
+ return { allowed: true, extension: "" };
247
+ };
248
+ __decorate([
249
+ Observable(),
250
+ __metadata("design:type", Array)
251
+ ], FileManagerBase.prototype, "currentUploads", void 0);
252
+ return FileManagerBase;
253
+ }());
254
+ var FileManager = /** @class */ (function (_super) {
255
+ __extends(FileManager, _super);
256
+ function FileManager() {
257
+ return _super !== null && _super.apply(this, arguments) || this;
258
+ }
259
+ FileManager.prototype.getFileInputProps = function () {
260
+ var props = _super.prototype.getFileInputProps.call(this);
261
+ props.multiple = this.options.multiple === true;
262
+ return props;
263
+ };
264
+ Object.defineProperty(FileManager.prototype, "allowMultiple", {
265
+ get: function () {
266
+ var _a;
267
+ return (_a = this.options.multiple) !== null && _a !== void 0 ? _a : false;
268
+ },
269
+ enumerable: false,
270
+ configurable: true
271
+ });
272
+ FileManager = __decorate([
273
+ NeoModel
274
+ ], FileManager);
275
+ return FileManager;
276
+ }(FileManagerBase));
277
+ export default FileManager;
@@ -1,37 +1,37 @@
1
- import { IFileDescriptor } from "./IFileManagerOptions";
2
- interface ICreateRecordsOptions<T> {
3
- /**
4
- * Property name of a property which returns a FileUploadBatch.
5
- */
6
- uploadBatchKey?: keyof T;
7
- /**
8
- * Property name of a property which returns a FileDescriptorId.
9
- */
10
- fileDescriptorIdKey?: keyof T;
11
- }
12
- export declare class FileUploadBatch {
13
- constructor(files: FileList | File[]);
14
- private recordIndex;
15
- private recordFileIdKey?;
16
- readonly files: File[];
17
- readonly key: string;
18
- uploadPercent: number;
19
- isComplete: boolean;
20
- uploadError: string | null;
21
- get totalSize(): number;
22
- /**
23
- * Create a record of T for each file in this batch.
24
- * @param recordType Record type to create.
25
- * @param fileDescriptorKey Property name of a property which returns a file descriptor.
26
- * @param fileDescriptorType File descriptor type of your project.
27
- * @param options Additional options.
28
- */
29
- createRecords<T>(recordType: new () => T, fileDescriptorKey: keyof T, fileDescriptorType: new () => IFileDescriptor, options?: ICreateRecordsOptions<T>): T[];
30
- /**
31
- * Set the file descriptor ids on the records created in createRecords().
32
- * @param files File info returned from the server.
33
- */
34
- processResponse(files: IFileDescriptor[]): void;
35
- toString(): string;
36
- }
37
- export {};
1
+ import { IFileDescriptor } from "./IFileManagerOptions";
2
+ interface ICreateRecordsOptions<T> {
3
+ /**
4
+ * Property name of a property which returns a FileUploadBatch.
5
+ */
6
+ uploadBatchKey?: keyof T;
7
+ /**
8
+ * Property name of a property which returns a FileDescriptorId.
9
+ */
10
+ fileDescriptorIdKey?: keyof T;
11
+ }
12
+ export declare class FileUploadBatch {
13
+ constructor(files: FileList | File[]);
14
+ private recordIndex;
15
+ private recordFileIdKey?;
16
+ readonly files: File[];
17
+ readonly key: string;
18
+ uploadPercent: number;
19
+ isComplete: boolean;
20
+ uploadError: string | null;
21
+ get totalSize(): number;
22
+ /**
23
+ * Create a record of T for each file in this batch.
24
+ * @param recordType Record type to create.
25
+ * @param fileDescriptorKey Property name of a property which returns a file descriptor.
26
+ * @param fileDescriptorType File descriptor type of your project.
27
+ * @param options Additional options.
28
+ */
29
+ createRecords<T>(recordType: new () => T, fileDescriptorKey: keyof T, fileDescriptorType: new () => IFileDescriptor, options?: ICreateRecordsOptions<T>): T[];
30
+ /**
31
+ * Set the file descriptor ids on the records created in createRecords().
32
+ * @param files File info returned from the server.
33
+ */
34
+ processResponse(files: IFileDescriptor[]): void;
35
+ toString(): string;
36
+ }
37
+ export {};