@barchart/portfolio-api-common 1.2.78 → 1.2.82

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.
@@ -6,7 +6,7 @@ const array = require('@barchart/common-js/lang/array'),
6
6
  Decimal = require('@barchart/common-js/lang/Decimal'),
7
7
  DisposableStack = require('@barchart/common-js/collections/specialized/DisposableStack'),
8
8
  Event = require('@barchart/common-js/messaging/Event'),
9
- is = require('@barchart/common-js/lang/array'),
9
+ is = require('@barchart/common-js/lang/is'),
10
10
  Rate = require('@barchart/common-js/lang/Rate'),
11
11
  Tree = require('@barchart/common-js/collections/Tree');
12
12
 
@@ -371,21 +371,39 @@ module.exports = (() => {
371
371
  return array.unique(symbols);
372
372
  }
373
373
 
374
+ /**
375
+ * Causes a position to be flagged as locked (for editing).
376
+ *
377
+ * @public
378
+ * @param {Object} position
379
+ */
374
380
  setPositionLock(position) {
375
381
  if (position) {
376
382
  assert.argumentIsRequired(position, 'position', Object);
377
383
  assert.argumentIsRequired(position.position, 'position.position', String);
378
384
 
379
- const item = this._items.find((i) => i.position.position === position.position);
385
+ const item = this._items.find(i => i.position.position === position.position);
380
386
 
381
387
  if (item) {
382
- const locked = is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
383
-
384
- item.setPositionLock(locked);
388
+ item.setPositionLock(position);
385
389
  }
386
390
  }
387
391
  }
388
392
 
393
+ /**
394
+ * Returns all positions which are currently locked (for editing).
395
+ *
396
+ * @public
397
+ * @returns {Array.<Object>}
398
+ */
399
+ getLockedPositions() {
400
+ return this._items.filter((i) => {
401
+ return i.data.locked;
402
+ }).map((i) => {
403
+ return i.position;
404
+ });
405
+ }
406
+
389
407
  /**
390
408
  * Performs a batch update of both position quotes and forex quotes,
391
409
  * triggering updates to position(s) and data aggregation(s).
@@ -70,7 +70,7 @@ module.exports = (() => {
70
70
 
71
71
  this._data.newsExists = false;
72
72
  this._data.fundamental = { };
73
- this._data.locked = is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
73
+ this._data.locked = getIsLocked(position);
74
74
 
75
75
  calculateStaticData(this);
76
76
  calculatePriceData(this, null);
@@ -242,18 +242,20 @@ module.exports = (() => {
242
242
  }
243
243
 
244
244
  /**
245
- * Sets position lock status.
245
+ * Sets a position's lock status.
246
246
  *
247
247
  * @public
248
- * @param {Boolean} value
248
+ * @param {Object} position
249
249
  */
250
- setPositionLock(value) {
251
- assert.argumentIsRequired(value, 'value', Boolean);
250
+ setPositionLock(position) {
251
+ assert.argumentIsRequired(position, 'position');
252
252
 
253
253
  if (this.getIsDisposed()) {
254
254
  return;
255
255
  }
256
256
 
257
+ const value = getIsLocked(position);
258
+
257
259
  if (this._data.locked !== value) {
258
260
  this._lockChangedEvent.fire(this._data.locked = value);
259
261
  }
@@ -525,5 +527,11 @@ module.exports = (() => {
525
527
  return summary;
526
528
  }
527
529
 
530
+ function getIsLocked(position) {
531
+ assert.argumentIsRequired(position, 'position');
532
+
533
+ return is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
534
+ }
535
+
528
536
  return PositionItem;
529
537
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.78",
3
+ "version": "1.2.82",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -1385,7 +1385,7 @@ const array = require('@barchart/common-js/lang/array'),
1385
1385
  Decimal = require('@barchart/common-js/lang/Decimal'),
1386
1386
  DisposableStack = require('@barchart/common-js/collections/specialized/DisposableStack'),
1387
1387
  Event = require('@barchart/common-js/messaging/Event'),
1388
- is = require('@barchart/common-js/lang/array'),
1388
+ is = require('@barchart/common-js/lang/is'),
1389
1389
  Rate = require('@barchart/common-js/lang/Rate'),
1390
1390
  Tree = require('@barchart/common-js/collections/Tree');
1391
1391
 
@@ -1750,21 +1750,39 @@ module.exports = (() => {
1750
1750
  return array.unique(symbols);
1751
1751
  }
1752
1752
 
1753
+ /**
1754
+ * Causes a position to be flagged as locked (for editing).
1755
+ *
1756
+ * @public
1757
+ * @param {Object} position
1758
+ */
1753
1759
  setPositionLock(position) {
1754
1760
  if (position) {
1755
1761
  assert.argumentIsRequired(position, 'position', Object);
1756
1762
  assert.argumentIsRequired(position.position, 'position.position', String);
1757
1763
 
1758
- const item = this._items.find((i) => i.position.position === position.position);
1764
+ const item = this._items.find(i => i.position.position === position.position);
1759
1765
 
1760
1766
  if (item) {
1761
- const locked = is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
1762
-
1763
- item.setPositionLock(locked);
1767
+ item.setPositionLock(position);
1764
1768
  }
1765
1769
  }
1766
1770
  }
1767
1771
 
1772
+ /**
1773
+ * Returns all positions which are currently locked (for editing).
1774
+ *
1775
+ * @public
1776
+ * @returns {Array.<Object>}
1777
+ */
1778
+ getLockedPositions() {
1779
+ return this._items.filter((i) => {
1780
+ return i.data.locked;
1781
+ }).map((i) => {
1782
+ return i.position;
1783
+ });
1784
+ }
1785
+
1768
1786
  /**
1769
1787
  * Performs a batch update of both position quotes and forex quotes,
1770
1788
  * triggering updates to position(s) and data aggregation(s).
@@ -2336,7 +2354,7 @@ module.exports = (() => {
2336
2354
  return PositionContainer;
2337
2355
  })();
2338
2356
 
2339
- },{"./../data/PositionSummaryFrame":3,"./PositionGroup":7,"./PositionItem":8,"./definitions/PositionLevelDefinition":9,"./definitions/PositionLevelType":10,"./definitions/PositionTreeDefinition":11,"@barchart/common-js/collections/Tree":15,"@barchart/common-js/collections/sorting/ComparatorBuilder":16,"@barchart/common-js/collections/sorting/comparators":17,"@barchart/common-js/collections/specialized/DisposableStack":18,"@barchart/common-js/lang/Currency":20,"@barchart/common-js/lang/Decimal":22,"@barchart/common-js/lang/Rate":26,"@barchart/common-js/lang/array":28,"@barchart/common-js/lang/assert":29,"@barchart/common-js/messaging/Event":35}],7:[function(require,module,exports){
2357
+ },{"./../data/PositionSummaryFrame":3,"./PositionGroup":7,"./PositionItem":8,"./definitions/PositionLevelDefinition":9,"./definitions/PositionLevelType":10,"./definitions/PositionTreeDefinition":11,"@barchart/common-js/collections/Tree":15,"@barchart/common-js/collections/sorting/ComparatorBuilder":16,"@barchart/common-js/collections/sorting/comparators":17,"@barchart/common-js/collections/specialized/DisposableStack":18,"@barchart/common-js/lang/Currency":20,"@barchart/common-js/lang/Decimal":22,"@barchart/common-js/lang/Rate":26,"@barchart/common-js/lang/array":28,"@barchart/common-js/lang/assert":29,"@barchart/common-js/lang/is":33,"@barchart/common-js/messaging/Event":35}],7:[function(require,module,exports){
2340
2358
  const array = require('@barchart/common-js/lang/array'),
2341
2359
  assert = require('@barchart/common-js/lang/assert'),
2342
2360
  Currency = require('@barchart/common-js/lang/Currency'),
@@ -3278,7 +3296,7 @@ module.exports = (() => {
3278
3296
 
3279
3297
  this._data.newsExists = false;
3280
3298
  this._data.fundamental = { };
3281
- this._data.locked = is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
3299
+ this._data.locked = getIsLocked(position);
3282
3300
 
3283
3301
  calculateStaticData(this);
3284
3302
  calculatePriceData(this, null);
@@ -3450,18 +3468,20 @@ module.exports = (() => {
3450
3468
  }
3451
3469
 
3452
3470
  /**
3453
- * Sets position lock status.
3471
+ * Sets a position's lock status.
3454
3472
  *
3455
3473
  * @public
3456
- * @param {Boolean} value
3474
+ * @param {Object} position
3457
3475
  */
3458
- setPositionLock(value) {
3459
- assert.argumentIsRequired(value, 'value', Boolean);
3476
+ setPositionLock(position) {
3477
+ assert.argumentIsRequired(position, 'position');
3460
3478
 
3461
3479
  if (this.getIsDisposed()) {
3462
3480
  return;
3463
3481
  }
3464
3482
 
3483
+ const value = getIsLocked(position);
3484
+
3465
3485
  if (this._data.locked !== value) {
3466
3486
  this._lockChangedEvent.fire(this._data.locked = value);
3467
3487
  }
@@ -3733,6 +3753,12 @@ module.exports = (() => {
3733
3753
  return summary;
3734
3754
  }
3735
3755
 
3756
+ function getIsLocked(position) {
3757
+ assert.argumentIsRequired(position, 'position');
3758
+
3759
+ return is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
3760
+ }
3761
+
3736
3762
  return PositionItem;
3737
3763
  })();
3738
3764