@intellegens/cornerstone-client 0.0.9999-alpha-21 → 0.0.9999-alpha-22

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.
@@ -51,6 +51,7 @@ export declare class CollectionViewAdapter<TKey, TDto extends IIdentifiable<TKey
51
51
  private _readClient;
52
52
  private _isLoading;
53
53
  private _pageData;
54
+ private _selectedItems;
54
55
  private _defaultOptions;
55
56
  private _initialOptions;
56
57
  private _currentOptions;
@@ -157,4 +158,37 @@ export declare class CollectionViewAdapter<TKey, TDto extends IIdentifiable<TKey
157
158
  * @returns The computed total item count
158
159
  */
159
160
  private _calculateTotal;
161
+ /**
162
+ * Selects or deselects an item based on its ID.
163
+ * @param item - The item to select or deselect.
164
+ */
165
+ toggleItemSelected(item: TDto): void;
166
+ clearSelectedItems(): void;
167
+ selectItems(item: TDto): void;
168
+ deselectItem(item: TDto): void;
169
+ /**
170
+ * Returns the currently selected items
171
+ */
172
+ get selectedItems(): TDto[];
173
+ /**
174
+ * Checks if an item is currently selected
175
+ * @param item - The item to check
176
+ */
177
+ isItemSelected(item: TDto): boolean;
178
+ /**
179
+ * Selects all items on the current page
180
+ */
181
+ selectAllItemsOnCurrentPage(): void;
182
+ /**
183
+ * Deselects all items on the current page
184
+ */
185
+ deselectAllItemsOnCurrentPage(): void;
186
+ /**
187
+ * Checks if all items on the current page are selected
188
+ */
189
+ areAllItemsOnCurrentPageSelected(): boolean;
190
+ /**
191
+ * Checks if some (but not all) items on the current page are selected
192
+ */
193
+ areSomeItemsOnCurrentPageSelected(): boolean;
160
194
  }
@@ -12,6 +12,7 @@ export class CollectionViewAdapter {
12
12
  _readClient;
13
13
  _isLoading = false;
14
14
  _pageData = [];
15
+ _selectedItems = [];
15
16
  _defaultOptions = {
16
17
  pagination: {
17
18
  useTotalItemCount: false,
@@ -299,4 +300,76 @@ export class CollectionViewAdapter {
299
300
  }
300
301
  return previousTotal;
301
302
  }
303
+ /**
304
+ * Selects or deselects an item based on its ID.
305
+ * @param item - The item to select or deselect.
306
+ */
307
+ toggleItemSelected(item) {
308
+ // if item with the same id is not already selected, add it
309
+ // if item with the same id is already selected, remove it
310
+ if (this._selectedItems.find(x => x.id === item.id)) {
311
+ this._selectedItems = this._selectedItems.filter(x => x.id !== item.id);
312
+ }
313
+ else {
314
+ this._selectedItems.push(item);
315
+ }
316
+ }
317
+ clearSelectedItems() {
318
+ this._selectedItems = [];
319
+ }
320
+ selectItems(item) {
321
+ if (!this._selectedItems.find(x => x.id === item.id)) {
322
+ this._selectedItems.push(item);
323
+ }
324
+ }
325
+ deselectItem(item) {
326
+ this._selectedItems = this._selectedItems.filter(x => x.id !== item.id);
327
+ }
328
+ /**
329
+ * Returns the currently selected items
330
+ */
331
+ get selectedItems() {
332
+ return this._selectedItems;
333
+ }
334
+ /**
335
+ * Checks if an item is currently selected
336
+ * @param item - The item to check
337
+ */
338
+ isItemSelected(item) {
339
+ return this._selectedItems.some(x => x.id === item.id);
340
+ }
341
+ /**
342
+ * Selects all items on the current page
343
+ */
344
+ selectAllItemsOnCurrentPage() {
345
+ for (const item of this._pageData) {
346
+ if (!this.isItemSelected(item)) {
347
+ this._selectedItems.push(item);
348
+ }
349
+ }
350
+ }
351
+ /**
352
+ * Deselects all items on the current page
353
+ */
354
+ deselectAllItemsOnCurrentPage() {
355
+ const pageItemIds = this._pageData.map(item => item.id);
356
+ this._selectedItems = this._selectedItems.filter(item => !pageItemIds.includes(item.id));
357
+ }
358
+ /**
359
+ * Checks if all items on the current page are selected
360
+ */
361
+ areAllItemsOnCurrentPageSelected() {
362
+ if (this._pageData.length === 0)
363
+ return false;
364
+ return this._pageData.every(item => this.isItemSelected(item));
365
+ }
366
+ /**
367
+ * Checks if some (but not all) items on the current page are selected
368
+ */
369
+ areSomeItemsOnCurrentPageSelected() {
370
+ if (this._pageData.length === 0)
371
+ return false;
372
+ const selectedCount = this._pageData.filter(item => this.isItemSelected(item)).length;
373
+ return selectedCount > 0 && selectedCount < this._pageData.length;
374
+ }
302
375
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intellegens/cornerstone-client",
3
- "version": "0.0.9999-alpha-21",
3
+ "version": "0.0.9999-alpha-22",
4
4
  "private": false,
5
5
  "publishable": true,
6
6
  "main": "./dist/index.js",
@@ -56,6 +56,7 @@ export class CollectionViewAdapter<TKey, TDto extends IIdentifiable<TKey>, TDeta
56
56
 
57
57
  private _isLoading = false;
58
58
  private _pageData: TDto[] = [];
59
+ private _selectedItems: TDto[] = [];
59
60
 
60
61
  private _defaultOptions: CollectionViewAdapterOptions<TDto> = {
61
62
  pagination: {
@@ -387,4 +388,83 @@ export class CollectionViewAdapter<TKey, TDto extends IIdentifiable<TKey>, TDeta
387
388
  }
388
389
  return previousTotal;
389
390
  }
391
+
392
+ /**
393
+ * Selects or deselects an item based on its ID.
394
+ * @param item - The item to select or deselect.
395
+ */
396
+ public toggleItemSelected(item: TDto) {
397
+ // if item with the same id is not already selected, add it
398
+ // if item with the same id is already selected, remove it
399
+ if (this._selectedItems.find(x => x.id === item.id)) {
400
+ this._selectedItems = this._selectedItems.filter(x => x.id !== item.id);
401
+ } else {
402
+ this._selectedItems.push(item);
403
+ }
404
+ }
405
+
406
+ public clearSelectedItems() {
407
+ this._selectedItems = [];
408
+ }
409
+
410
+ public selectItems(item: TDto) {
411
+ if (!this._selectedItems.find(x => x.id === item.id)) {
412
+ this._selectedItems.push(item);
413
+ }
414
+ }
415
+
416
+ public deselectItem(item: TDto) {
417
+ this._selectedItems = this._selectedItems.filter(x => x.id !== item.id);
418
+ }
419
+
420
+ /**
421
+ * Returns the currently selected items
422
+ */
423
+ public get selectedItems(): TDto[] {
424
+ return this._selectedItems;
425
+ }
426
+
427
+ /**
428
+ * Checks if an item is currently selected
429
+ * @param item - The item to check
430
+ */
431
+ public isItemSelected(item: TDto): boolean {
432
+ return this._selectedItems.some(x => x.id === item.id);
433
+ }
434
+
435
+ /**
436
+ * Selects all items on the current page
437
+ */
438
+ public selectAllItemsOnCurrentPage() {
439
+ for (const item of this._pageData) {
440
+ if (!this.isItemSelected(item)) {
441
+ this._selectedItems.push(item);
442
+ }
443
+ }
444
+ }
445
+
446
+ /**
447
+ * Deselects all items on the current page
448
+ */
449
+ public deselectAllItemsOnCurrentPage() {
450
+ const pageItemIds = this._pageData.map(item => item.id);
451
+ this._selectedItems = this._selectedItems.filter(item => !pageItemIds.includes(item.id));
452
+ }
453
+
454
+ /**
455
+ * Checks if all items on the current page are selected
456
+ */
457
+ public areAllItemsOnCurrentPageSelected(): boolean {
458
+ if (this._pageData.length === 0) return false;
459
+ return this._pageData.every(item => this.isItemSelected(item));
460
+ }
461
+
462
+ /**
463
+ * Checks if some (but not all) items on the current page are selected
464
+ */
465
+ public areSomeItemsOnCurrentPageSelected(): boolean {
466
+ if (this._pageData.length === 0) return false;
467
+ const selectedCount = this._pageData.filter(item => this.isItemSelected(item)).length;
468
+ return selectedCount > 0 && selectedCount < this._pageData.length;
469
+ }
390
470
  }