@rentman/rm-core 1.0.0 → 1.0.2

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 (126) hide show
  1. package/dist/definitions/classes/ApiFormatter.d.ts +36 -0
  2. package/dist/definitions/classes/BatchStatus.d.ts +16 -0
  3. package/dist/definitions/classes/ChangesCompiler.d.ts +34 -0
  4. package/dist/definitions/classes/ChangesProcessor.d.ts +46 -0
  5. package/dist/definitions/classes/CollectionCache.d.ts +39 -0
  6. package/dist/definitions/classes/CollectionEntryService.d.ts +15 -0
  7. package/dist/definitions/classes/CollectionHandler.d.ts +79 -0
  8. package/dist/definitions/classes/CollectionResourceService.d.ts +5 -0
  9. package/dist/definitions/classes/ColumnCache.d.ts +18 -0
  10. package/dist/definitions/classes/ColumnExpansion.d.ts +16 -0
  11. package/dist/definitions/classes/ColumnHandler.d.ts +19 -0
  12. package/dist/definitions/classes/ColumnSet.d.ts +54 -0
  13. package/dist/definitions/classes/ColumnUtil.d.ts +80 -0
  14. package/dist/definitions/classes/CreateRequest.d.ts +28 -0
  15. package/dist/definitions/classes/ItemAdministrator.d.ts +114 -0
  16. package/dist/definitions/classes/ItemCache.d.ts +22 -0
  17. package/dist/definitions/classes/ItemEntryService.d.ts +50 -0
  18. package/dist/definitions/classes/ItemHandler.d.ts +70 -0
  19. package/dist/definitions/classes/ItemRequestService.d.ts +31 -0
  20. package/dist/definitions/classes/ItemResourceService.d.ts +8 -0
  21. package/dist/definitions/classes/KeyService.d.ts +28 -0
  22. package/dist/definitions/classes/LockService.d.ts +25 -0
  23. package/dist/definitions/classes/ModuleChangesCompiler.d.ts +18 -0
  24. package/dist/definitions/classes/PromiseService.d.ts +10 -0
  25. package/dist/definitions/classes/QueryMatcher.d.ts +14 -0
  26. package/dist/definitions/classes/QueryParser.d.ts +16 -0
  27. package/dist/definitions/classes/QueryService.d.ts +19 -0
  28. package/dist/definitions/classes/RequestColumnExpansion.d.ts +9 -0
  29. package/dist/definitions/classes/ResourceCache.d.ts +78 -0
  30. package/dist/definitions/classes/Util.d.ts +25 -0
  31. package/dist/definitions/constants.d.ts +10 -0
  32. package/dist/definitions/factories/BatchStatusFactory.d.ts +8 -0
  33. package/dist/definitions/factories/ChangesCompilerFactory.d.ts +9 -0
  34. package/dist/definitions/factories/ChangesProcessorFactory.d.ts +31 -0
  35. package/{src/factories/CollectionCacheFactory.ts → dist/definitions/factories/CollectionCacheFactory.d.ts} +3 -11
  36. package/dist/definitions/factories/CollectionEntryFactory.d.ts +19 -0
  37. package/dist/definitions/factories/CollectionResourceFactory.d.ts +18 -0
  38. package/dist/definitions/factories/ColumnExpansionFactory.d.ts +11 -0
  39. package/dist/definitions/factories/ColumnSetFactory.d.ts +9 -0
  40. package/dist/definitions/factories/CreateRequestFactory.d.ts +13 -0
  41. package/dist/definitions/factories/ItemCacheFactory.d.ts +9 -0
  42. package/dist/definitions/factories/ItemEntryFactory.d.ts +6 -0
  43. package/dist/definitions/factories/ItemResourceFactory.d.ts +12 -0
  44. package/{src/factories/ModuleChangesCompilerFactory.ts → dist/definitions/factories/ModuleChangesCompilerFactory.d.ts} +3 -14
  45. package/dist/definitions/factories/QueryMatcherFactory.d.ts +7 -0
  46. package/dist/definitions/factories/QueryParserFactory.d.ts +5 -0
  47. package/{src/factories/RequestColumnExpansionFactory.ts → dist/definitions/factories/RequestColumnExpansionFactory.d.ts} +3 -11
  48. package/dist/definitions/factories/ResourceCacheFactory.d.ts +33 -0
  49. package/dist/definitions/index.d.ts +121 -0
  50. package/dist/definitions/interfaces/ApiRequestServiceInterface.d.ts +10 -0
  51. package/dist/definitions/interfaces/AuthInterface.d.ts +4 -0
  52. package/{src/interfaces/ErrorHandlerInterface.ts → dist/definitions/interfaces/ErrorHandlerInterface.d.ts} +2 -2
  53. package/dist/definitions/interfaces/ResourceCacheInterface.d.ts +6 -0
  54. package/dist/definitions/models/CollectionEditResource.d.ts +23 -0
  55. package/dist/definitions/models/CollectionEntry.d.ts +61 -0
  56. package/dist/definitions/models/CollectionResource.d.ts +29 -0
  57. package/{src/models/CollectionViewResource.ts → dist/definitions/models/CollectionViewResource.d.ts} +6 -13
  58. package/dist/definitions/models/EditResource.d.ts +7 -0
  59. package/dist/definitions/models/ItemEntry.d.ts +18 -0
  60. package/dist/definitions/models/ItemResource.d.ts +14 -0
  61. package/dist/definitions/models/ViewResource.d.ts +7 -0
  62. package/dist/rm-core.js +29 -0
  63. package/dist/rm-core.js.map +1 -0
  64. package/package.json +5 -1
  65. package/.editorconfig +0 -23
  66. package/src/classes/ApiFormatter.ts +0 -338
  67. package/src/classes/BatchStatus.ts +0 -86
  68. package/src/classes/ChangesCompiler.ts +0 -161
  69. package/src/classes/ChangesProcessor.ts +0 -475
  70. package/src/classes/CollectionCache.ts +0 -234
  71. package/src/classes/CollectionEntryService.ts +0 -83
  72. package/src/classes/CollectionHandler.ts +0 -619
  73. package/src/classes/CollectionResourceService.ts +0 -38
  74. package/src/classes/ColumnCache.ts +0 -114
  75. package/src/classes/ColumnExpansion.ts +0 -74
  76. package/src/classes/ColumnHandler.ts +0 -90
  77. package/src/classes/ColumnSet.ts +0 -181
  78. package/src/classes/ColumnUtil.ts +0 -589
  79. package/src/classes/CreateRequest.ts +0 -158
  80. package/src/classes/ItemAdministrator.ts +0 -571
  81. package/src/classes/ItemCache.ts +0 -158
  82. package/src/classes/ItemEntryService.ts +0 -488
  83. package/src/classes/ItemHandler.ts +0 -592
  84. package/src/classes/ItemRequestService.ts +0 -229
  85. package/src/classes/ItemResourceService.ts +0 -36
  86. package/src/classes/KeyService.ts +0 -76
  87. package/src/classes/LockService.ts +0 -184
  88. package/src/classes/ModuleChangesCompiler.ts +0 -123
  89. package/src/classes/PromiseService.ts +0 -19
  90. package/src/classes/QueryMatcher.ts +0 -135
  91. package/src/classes/QueryParser.ts +0 -209
  92. package/src/classes/QueryService.ts +0 -35
  93. package/src/classes/RequestColumnExpansion.ts +0 -31
  94. package/src/classes/ResourceCache.ts +0 -289
  95. package/src/classes/Util.ts +0 -422
  96. package/src/constants.ts +0 -11
  97. package/src/factories/BatchStatusFactory.ts +0 -18
  98. package/src/factories/ChangesCompilerFactory.ts +0 -20
  99. package/src/factories/ChangesProcessorFactory.ts +0 -53
  100. package/src/factories/CollectionEntryFactory.ts +0 -35
  101. package/src/factories/CollectionResourceFactory.ts +0 -36
  102. package/src/factories/ColumnExpansionFactory.ts +0 -25
  103. package/src/factories/ColumnSetFactory.ts +0 -24
  104. package/src/factories/CreateRequestFactory.ts +0 -28
  105. package/src/factories/ItemCacheFactory.ts +0 -18
  106. package/src/factories/ItemEntryFactory.ts +0 -18
  107. package/src/factories/ItemResourceFactory.ts +0 -28
  108. package/src/factories/QueryMatcherFactory.ts +0 -20
  109. package/src/factories/QueryParserFactory.ts +0 -10
  110. package/src/factories/ResourceCacheFactory.ts +0 -55
  111. package/src/index.ts +0 -188
  112. package/src/interfaces/ApiRequestServiceInterface.ts +0 -17
  113. package/src/interfaces/AuthInterface.ts +0 -5
  114. package/src/interfaces/ResourceCacheInterface.ts +0 -9
  115. package/src/models/CollectionEditResource.ts +0 -139
  116. package/src/models/CollectionEntry.ts +0 -448
  117. package/src/models/CollectionResource.ts +0 -223
  118. package/src/models/EditResource.ts +0 -15
  119. package/src/models/ItemEntry.ts +0 -24
  120. package/src/models/ItemResource.ts +0 -35
  121. package/src/models/ViewResource.ts +0 -14
  122. package/tsconfig.json +0 -12
  123. package/tslint.json +0 -63
  124. package/webpack.common.js +0 -35
  125. package/webpack.dev.js +0 -10
  126. package/webpack.prod.js +0 -17
@@ -1,448 +0,0 @@
1
- import CollectionEntryService from "../classes/CollectionEntryService";
2
- import ItemEntryService from "../classes/ItemEntryService";
3
- import ItemRequestService from "../classes/ItemRequestService";
4
- import KeyService from "../classes/KeyService";
5
- import PromiseService from "../classes/PromiseService";
6
- import QueryService from "../classes/QueryService";
7
-
8
- import { inArray } from "../classes/Util";
9
- import ErrorHandlerInterface from '../interfaces/ErrorHandlerInterface';
10
- import CollectionResource from "./CollectionResource";
11
- import ItemEntry from "./ItemEntry";
12
-
13
- let currentId = 0;
14
-
15
- export default class CollectionEntry {
16
- id: number = currentId++;
17
- query: any;
18
- columns: any;
19
-
20
- parent: null | { itemType: string, itemId: string } = null;
21
-
22
- initial: ItemEntry[] = [];
23
- items: ItemEntry[] = [];
24
-
25
- resources: CollectionResource[] = [];
26
- deferred: any;
27
- promise: any;
28
- reloadQueued: boolean;
29
-
30
- constructor (
31
- private errorHandler: ErrorHandlerInterface,
32
- private collectionEntryService: CollectionEntryService,
33
- private itemRequestService: ItemRequestService,
34
- private itemEntryService: ItemEntryService,
35
- private keyService: KeyService,
36
- private queryService: QueryService,
37
- private promiseService: PromiseService,
38
- public itemType: string,
39
- public options: any
40
- ) {
41
- this.deferred = this.promiseService.defer();
42
-
43
- this.itemType = itemType;
44
- this.options = options;
45
- this.query = collectionEntryService.createQuery(options);
46
- }
47
-
48
- isDeferred () {
49
- return this.promise !== undefined;
50
- }
51
-
52
- resolve (itemEntryResource) {
53
- const deferred = this.deferred;
54
-
55
- this.columns = itemEntryResource.columns;
56
- this.initial = itemEntryResource.items;
57
- this.items = itemEntryResource.items.slice();
58
-
59
- delete this.deferred;
60
- delete this.promise;
61
-
62
- deferred.resolve(this);
63
-
64
- return this;
65
- }
66
-
67
- isLocal () {
68
- const parent = this.parent;
69
-
70
- if (parent === null)
71
- return false;
72
-
73
- return this.keyService.isLocalId(parent.itemId);
74
- }
75
-
76
- matchParent (itemType, itemId) {
77
- const parent = this.parent;
78
-
79
- if (parent === null)
80
- return false;
81
-
82
- // == to compare itemIds
83
- return parent.itemType === itemType && parent.itemId == itemId;
84
- }
85
-
86
- forEach (callback) {
87
- const modified = this.items;
88
-
89
- for (const mod of modified)
90
- callback(mod);
91
- }
92
-
93
- getItemById (itemId) {
94
- const modified = this.items;
95
-
96
- for (const mod of modified) {
97
- if (mod.itemId === itemId)
98
- return mod;
99
- }
100
- }
101
-
102
- getIdArray (accumulator = {}) {
103
- return this.collectionEntryService.getIdArray(this.items, accumulator);
104
- }
105
-
106
- addItems (itemEntries, resultResource, updateInitial = false, enableCallback = true) {
107
- // local entry might be added multiple times (extend?)
108
- if (itemEntries.length === 0)
109
- return [];
110
-
111
- const collectionResources = this.resources;
112
- const parent = this.parent;
113
- const parentColumn = this.columns.link;
114
-
115
- if (updateInitial) {
116
- const initial = this.initial;
117
- const entriesAddedToInitial = [];
118
-
119
- for (const itemEntry of itemEntries) {
120
- // when saving, items that might already be in modified are added to initial
121
- if (initial.indexOf(itemEntry) === -1) {
122
- initial.push(itemEntry);
123
- entriesAddedToInitial.push(itemEntry);
124
- }
125
- }
126
-
127
- if (entriesAddedToInitial.length > 0) {
128
- for (const collectionResource of collectionResources)
129
- collectionResource.options.onAddInitial(entriesAddedToInitial, this);
130
- }
131
- }
132
-
133
- const modified = this.items;
134
- const entriesAddedToModified = [];
135
-
136
- for (const itemEntry of itemEntries) {
137
- if (modified.indexOf(itemEntry) === -1) {
138
- if (parent !== null) {
139
- itemEntry.parent = parent;
140
-
141
- if (parentColumn !== null && itemEntry.modified !== undefined)
142
- itemEntry.modified[parentColumn.id] = parent.itemId;
143
- }
144
-
145
- modified.push(itemEntry);
146
- entriesAddedToModified.push(itemEntry);
147
- }
148
- }
149
-
150
- if (entriesAddedToModified.length > 0) {
151
- let result;
152
-
153
- for (const collectionResource of collectionResources) {
154
- const addedResources = collectionResource.addItemResources(entriesAddedToModified);
155
-
156
- if (collectionResource === resultResource) {
157
- result = addedResources;
158
-
159
- if (enableCallback)
160
- collectionResource.callOnAdd(addedResources);
161
- } else
162
- collectionResource.callOnAdd(addedResources);
163
- }
164
-
165
- return result;
166
- } else
167
- return resultResource === null ? null : [];
168
- }
169
-
170
- removeItems (idArray, resultResource, updateInitial, enableCallback?) {
171
- if (idArray.length === 0)
172
- return [];
173
-
174
- return this.handleRemovedItems(itemEntry => {
175
- return inArray(itemEntry.itemId, idArray);
176
- },
177
- resultResource,
178
- updateInitial,
179
- enableCallback
180
- );
181
- }
182
-
183
- clear (resultResource, updateInitial, enableCallback?) {
184
- return this.handleRemovedItems(
185
- () => {
186
- return false;
187
- },
188
- resultResource,
189
- updateInitial,
190
- enableCallback
191
- );
192
- }
193
-
194
- handleRemovedItems (filterFunction, resultResource, updateInitial, enableCallback) {
195
- if (enableCallback === undefined)
196
- enableCallback = true;
197
-
198
- const collectionResources = this.resources;
199
- const removedFromModified = this.collectionEntryService.filterArray(this.items, filterFunction);
200
- const removedFromInitial = updateInitial ? this.collectionEntryService.filterArray(this.initial, filterFunction) : [];
201
-
202
- if (removedFromInitial.length > 0) {
203
- for (const collectionResource of collectionResources)
204
- collectionResource.options.onRemoveInitial(removedFromInitial, this);
205
- }
206
-
207
- if (removedFromModified.length === 0)
208
- return resultResource === null ? null : [];
209
-
210
- let result;
211
-
212
- for (const removedFromMod of removedFromModified)
213
- this.itemEntryService.deactivateResources(removedFromMod);
214
-
215
- for (const collectionResource of collectionResources) {
216
- const removedResources = collectionResource.removeItemResources(removedFromModified);
217
-
218
- if (collectionResource === resultResource) {
219
- result = removedResources;
220
-
221
- if (enableCallback)
222
- collectionResource.callOnRemove(removedResources);
223
- } else
224
- collectionResource.callOnRemove(removedResources);
225
- }
226
-
227
- return result;
228
- }
229
-
230
- expand (newColumns) {
231
- const itemType = this.itemType;
232
-
233
- if (newColumns.length === 0)
234
- return this.promiseService.when(this);
235
-
236
- this.promise = this.itemRequestService.requestItems(this, undefined, newColumns).then(response => {
237
- const responseItems = response.items[itemType];
238
- const columnExpansion = this.itemRequestService.processExpansion(newColumns, response, itemType, this.items);
239
-
240
- this.handleRemovedItems.call(
241
- this, itemEntry => {
242
- return responseItems[itemEntry.itemId] !== undefined || this.itemEntryService.isLocal(itemEntry);
243
- },
244
- null,
245
- true,
246
- true
247
- );
248
-
249
- this.updateColumns(columnExpansion);
250
-
251
- delete this.promise;
252
- return this;
253
- },
254
- this.errorHandler.reject
255
- );
256
-
257
- return this.promise;
258
- }
259
-
260
- extendQuery (callback) {
261
- const options = this.options;
262
-
263
- if (callback === undefined)
264
- return this.query;
265
-
266
- options.queryParams = callback(options.queryParams);
267
-
268
- return this.query = this.collectionEntryService.createQuery(options);
269
- }
270
-
271
- extend (queryCallback, collectionResource, enableCallback?, updateInitial?) {
272
- const extendedQuery = this.extendQuery(queryCallback).object;
273
- const fullQuery = this.queryService.addAndCondition(
274
- extendedQuery,
275
- this.queryService.createNotIn(this.getIdArray())
276
- );
277
-
278
- // todo: also do the limit check in batchExtend
279
- const promise = this.itemRequestService.requestItems(
280
- this,
281
- // When there's a limit we want to fetch all items because we will do sorting and splicing of the excess items
282
- this.options.limit !== null ?
283
- extendedQuery :
284
- fullQuery
285
- ).then(response => {
286
- // removeAbsentItems(response); TODO: we can only do this when we request *all* the items
287
- return this.itemRequestService.processResponse(
288
- response,
289
- response.links[this.itemType],
290
- this.parent,
291
- this.columns
292
- );
293
- },
294
- this.errorHandler.reject
295
- ).then(itemEntries => {
296
- delete this.promise;
297
-
298
- return this.addItems(itemEntries, collectionResource, updateInitial, enableCallback);
299
- },
300
- this.errorHandler.reject
301
- );
302
-
303
- this.promise = promise.then(
304
- () => {
305
- return this;
306
- },
307
- this.errorHandler.reject
308
- );
309
-
310
- return promise;
311
- }
312
-
313
- queueReload () {
314
- this.reloadQueued = true;
315
- this.deferred = this.promiseService.defer();
316
- this.promise = this.deferred.promise;
317
- }
318
-
319
- updateColumns (columnExpansion) {
320
- const columnInfo = columnExpansion(this.columns, false);
321
-
322
- this.options.columns = columnInfo.request;
323
- this.columns = columnInfo;
324
- }
325
-
326
- getAddedItems (returnItemIds = false) {
327
- const initial = this.initial;
328
- const modified = this.items;
329
- const result = [];
330
-
331
- for (const itemEntry of modified) {
332
- if (initial.indexOf(itemEntry) === -1)
333
- result.push(returnItemIds ? itemEntry.itemId : itemEntry);
334
- }
335
-
336
- return result;
337
- }
338
-
339
- getRemovedItems (returnItemIds = false) {
340
- const initial = this.initial;
341
- const modified = this.items;
342
- const result = [];
343
-
344
- for (const itemEntry of initial) {
345
- if (modified.indexOf(itemEntry) === -1)
346
- result.push(returnItemIds ? itemEntry.itemId : itemEntry);
347
- }
348
-
349
- return result;
350
- }
351
-
352
- getUpdatedItems () {
353
- const modified = this.items;
354
- const result = [];
355
-
356
- for (const itemEntry of modified) {
357
- if (!this.itemEntryService.isLocal(itemEntry) && this.itemEntryService.hasChanges(itemEntry))
358
- result.push(itemEntry);
359
- }
360
-
361
- return result;
362
- }
363
-
364
- hasAddedItems () {
365
- return this.items.length > this.initial.length;
366
- }
367
-
368
- hasRemovedItems () {
369
- return this.initial.length > this.items.length;
370
- }
371
-
372
- hasUpdatedItems () {
373
- const modified = this.items;
374
-
375
- for (const mod of modified) {
376
- if (this.itemEntryService.hasChanges(mod))
377
- return true;
378
- }
379
-
380
- return false;
381
- }
382
-
383
- getCurrentResource () {
384
- const resources = this.resources;
385
-
386
- return resources[resources.length - 1];
387
- }
388
-
389
- clearResources (isSubtabChange = false) {
390
- const itemEntries = this.items; // TODO: initial
391
- const currentResources = this.resources;
392
- const newResources = [];
393
-
394
- // we'll add the item resources back in later
395
- for (const itemEntry of itemEntries)
396
- this.itemEntryService.clearResources(itemEntry);
397
-
398
- for (const collectionResource of currentResources) {
399
- if (collectionResource.options[isSubtabChange ? 'clearOnSubTabChange' : 'clearOnTabChange'])
400
- continue;
401
-
402
- newResources.push(collectionResource);
403
-
404
- const itemResources = collectionResource.items;
405
-
406
- for (const itemResource of itemResources) {
407
- itemResource.entry.resources.push(itemResource); // resources should be empty by now :-)
408
- }
409
- }
410
-
411
- this.resources = newResources;
412
- }
413
-
414
- // this doesn't revert updates
415
- revertChanges () {
416
- const resources = this.resources;
417
- const removedItems = this.getRemovedItems();
418
- const addedItems = this.getAddedItems(true);
419
-
420
- for (const resource of resources) {
421
- resource.addItemResources(removedItems);
422
- resource.removeItemResources(addedItems);
423
- }
424
-
425
- this.items = this.initial.slice();
426
- }
427
-
428
- onItemsCreated (conversionMap) {
429
- const resources = this.resources;
430
-
431
- for (const resource of resources) {
432
- resource.rebuildMap();
433
- resource.options.onItemsCreated(conversionMap);
434
- }
435
- }
436
-
437
- getUpdatedItemColumns (conversionMap) {
438
- const itemColumns = this.columns.item;
439
- const result = {};
440
-
441
- for (const column of itemColumns) {
442
- if (conversionMap[column.apiColumn.itemType] !== undefined)
443
- result[column.id] = column;
444
- }
445
-
446
- return result;
447
- }
448
- }
@@ -1,223 +0,0 @@
1
- import { filterArray } from "../classes/Util";
2
- import ItemResourceFactory from "../factories/ItemResourceFactory";
3
- import CollectionEntry from './CollectionEntry';
4
- import ItemEntry from "./ItemEntry";
5
- import ItemResource from "./ItemResource";
6
-
7
- export default class CollectionResource {
8
- columns;
9
- items: ItemResource[];
10
- itemIdMap: {};
11
-
12
- constructor (
13
- private itemResourceFactory: ItemResourceFactory,
14
- public entry: CollectionEntry,
15
- public options
16
- ) {
17
- this.columns = entry.columns.response;
18
- this.itemIdMap = {};
19
- this.items = [];
20
-
21
- entry.resources.push(this);
22
-
23
- this.addItemResources(entry.items);
24
- }
25
-
26
- getItemById (itemId) {
27
- return this.itemIdMap[itemId];
28
- }
29
-
30
- rebuildMap () {
31
- const itemResources = this.items;
32
- const itemIdMap = {};
33
-
34
- for (const itemResource of itemResources) {
35
- itemIdMap[itemResource.entry.itemId] = itemResource;
36
- }
37
-
38
- this.itemIdMap = itemIdMap;
39
- }
40
-
41
- addItemResources (itemEntries: ItemEntry[]) { // should be fast
42
- if (itemEntries.length === 0)
43
- return [];
44
-
45
- const result = [];
46
- const options = this.options;
47
- const items = this.items;
48
- const itemIdMap = this.itemIdMap;
49
- const constructor = this.itemResourceFactory.getConstructor(
50
- {
51
- edit: options.editItems,
52
- onChange: options.onChange,
53
- onDeactivate: options.onDeactivateItem
54
- }
55
- );
56
-
57
- for (const itemEntry of itemEntries) {
58
- const itemId = itemEntry.itemId;
59
-
60
- let itemResource;
61
-
62
- if (itemIdMap[itemId] === undefined) {
63
- itemResource = constructor(itemEntry);
64
- items.push(itemResource);
65
- itemIdMap[itemId] = itemResource;
66
- } else
67
- itemResource = itemIdMap[itemId];
68
-
69
- result.push(itemResource);
70
- }
71
-
72
- return result;
73
- }
74
-
75
- removeItemResources (itemEntries) {
76
- const result = [];
77
-
78
- filterArray(
79
- this.items,
80
- itemResource => {
81
- for (const itemEntry of itemEntries) {
82
- if (itemResource.entry === itemEntry) {
83
- result.push(itemResource);
84
- delete this.itemIdMap[itemEntry.itemId];
85
-
86
- return false;
87
- }
88
- }
89
-
90
- return true;
91
- }
92
- );
93
-
94
- return result;
95
- }
96
-
97
- callOnAdd (itemResources: ItemResource[]) {
98
- this.options.onAdd(itemResources, this);
99
- }
100
-
101
- callOnRemove (itemResources: ItemResource[]) {
102
- this.options.onRemove(itemResources, this);
103
- }
104
-
105
- forEach (callback) {
106
- const itemResources = this.items;
107
-
108
- for (const itemResource of itemResources)
109
- callback(itemResource);
110
- }
111
-
112
- filter (callback) {
113
- const itemResources = this.items;
114
- const result = [];
115
-
116
- for (const itemResource of itemResources) {
117
- if (callback(itemResource))
118
- result.push(itemResource);
119
- }
120
-
121
- return result;
122
- }
123
-
124
- first (callback) {
125
- const itemResources = this.items;
126
-
127
- for (const itemResource of itemResources) {
128
- if (callback(itemResource))
129
- return itemResource;
130
- }
131
-
132
- return null;
133
- }
134
-
135
- some (callback) {
136
- return this.first(callback) !== null;
137
- }
138
-
139
- groupBy (argument) {
140
- const itemsResources = this.items;
141
- const result = {};
142
-
143
- if (typeof argument === 'string') {
144
- for (const itemResource of itemsResources) {
145
- const value = itemResource.fields[argument];
146
-
147
- if (result[value] === undefined)
148
- result[value] = [];
149
-
150
- result[value].push(itemResource);
151
- }
152
- }
153
-
154
- if (typeof argument === 'function') {
155
- for (const itemResource of itemsResources) {
156
- const value = argument(itemResource);
157
-
158
- if (value === null)
159
- continue;
160
-
161
- if (result[value] === undefined)
162
- result[value] = [];
163
-
164
- result[value].push(itemResource);
165
- }
166
- }
167
-
168
- return result;
169
- }
170
-
171
- map (argument) {
172
- const itemResources = this.items;
173
- const length = itemResources.length;
174
- const result = new Array(length);
175
-
176
- if (typeof argument === 'string') {
177
- for (let i = 0; i < length; i++)
178
- result[i] = itemResources[i].fields[argument];
179
- }
180
-
181
- if (typeof argument === 'function') {
182
- for (let i = 0; i < length; i++)
183
- result[i] = argument(itemResources[i]);
184
- }
185
-
186
- return result;
187
- }
188
-
189
- reduce (callback, value) {
190
- const itemResources = this.items;
191
-
192
- for (const itemResource of itemResources)
193
- value = callback(itemResource, value);
194
-
195
- return value;
196
- }
197
-
198
- extend (queryCallback, returnAllItems, enableCallbacks) {
199
- if (enableCallbacks === undefined)
200
- enableCallbacks = true;
201
-
202
- return this.entry.extend(queryCallback, this, enableCallbacks)
203
- .then(itemResources => {
204
- return returnAllItems ? this.items : itemResources;
205
- });
206
- }
207
-
208
- deactivate () {
209
- this.options.onDeactivateCollection(this);
210
- }
211
-
212
- clearResource () {
213
- const collectionResources = this.entry.resources;
214
- const itemResources = this.items;
215
- const index = collectionResources.indexOf(this);
216
-
217
- if (index !== -1)
218
- collectionResources.splice(index, 1);
219
-
220
- for (const itemResource of itemResources)
221
- itemResource.clearResource();
222
- }
223
- }
@@ -1,15 +0,0 @@
1
- import ItemEntryService from "../classes/ItemEntryService";
2
- import ItemEntry from "./ItemEntry";
3
- import ItemResource from "./ItemResource";
4
-
5
- export class EditResource extends ItemResource {
6
- fields;
7
-
8
- constructor (itemEntryService: ItemEntryService, entry: ItemEntry, options) {
9
- super(itemEntryService, entry, options);
10
-
11
- itemEntryService.setModified(entry);
12
-
13
- this.fields = entry.modified;
14
- }
15
- }
@@ -1,24 +0,0 @@
1
- import ItemResource from "./ItemResource";
2
-
3
- let currentId = 0;
4
-
5
- export default class ItemEntry {
6
- entryId: number;
7
-
8
- modified;
9
- parent: null | { itemType: string, itemId: string } = null;
10
-
11
- deferRequest = false;
12
- deferred;
13
-
14
- constructor (
15
- public itemType: string,
16
- public itemId: number,
17
- public columns?,
18
- public initial = {},
19
- public derived = {},
20
- public resources: ItemResource[] = []
21
- ) {
22
- this.entryId = ++currentId;
23
- }
24
- }