alchemymvc 1.4.0-alpha.7 → 1.4.0-alpha.8
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/lib/app/helper_model/model.js +5 -0
- package/lib/app/model/system_setting_model.js +10 -2
- package/lib/core/alchemy.js +19 -4
- package/lib/core/base.js +4 -4
- package/lib/core/setting.js +107 -2
- package/package.json +1 -1
|
@@ -680,6 +680,11 @@ Model.setMethod(function getAliasModel(alias) {
|
|
|
680
680
|
config = this.schema.associations[alias];
|
|
681
681
|
}
|
|
682
682
|
|
|
683
|
+
// @TODO: associated fields with an alias name inside a nested schema
|
|
684
|
+
// somehow breaks! Should be looked in to?
|
|
685
|
+
// Workaround: set `recursive: 0` on the root schema field
|
|
686
|
+
// console.log('Alias:', alias, 'config:', config, this.schema);
|
|
687
|
+
|
|
683
688
|
if (config) {
|
|
684
689
|
result = this.getModel(config.modelName);
|
|
685
690
|
} else {
|
|
@@ -144,11 +144,19 @@ SystemSetting.setDocumentMethod(function applySetting(do_actions = true) {
|
|
|
144
144
|
|
|
145
145
|
if (!existing_value) {
|
|
146
146
|
existing_value = setting.generateValue();
|
|
147
|
+
alchemy.system_settings.forceValueInstanceAtPath(this.setting_id, existing_value);
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
let result;
|
|
151
|
+
|
|
149
152
|
if (do_actions) {
|
|
150
|
-
|
|
153
|
+
result = existing_value.setValue(this.configuration.value);
|
|
151
154
|
} else {
|
|
152
|
-
|
|
155
|
+
result = existing_value.setValueSilently(this.configuration.value);
|
|
153
156
|
}
|
|
157
|
+
|
|
158
|
+
// And now force the settings to update!
|
|
159
|
+
alchemy.refreshSettingsObject();
|
|
160
|
+
|
|
161
|
+
return result;
|
|
154
162
|
});
|
package/lib/core/alchemy.js
CHANGED
|
@@ -17,7 +17,7 @@ let shared_objects = {},
|
|
|
17
17
|
*
|
|
18
18
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
19
19
|
* @since 0.0.1
|
|
20
|
-
* @version 1.
|
|
20
|
+
* @version 1.4.0
|
|
21
21
|
*/
|
|
22
22
|
global.Alchemy = Function.inherits('Alchemy.Base', function Alchemy() {
|
|
23
23
|
|
|
@@ -147,7 +147,6 @@ global.Alchemy = Function.inherits('Alchemy.Base', function Alchemy() {
|
|
|
147
147
|
this.text_body = this.use('body');
|
|
148
148
|
this.formidable = this.use('formidable');
|
|
149
149
|
this.body_parser = this.use('body-parser');
|
|
150
|
-
this.url_form_body = this.body_parser.urlencoded({extended: true});
|
|
151
150
|
});
|
|
152
151
|
|
|
153
152
|
/**
|
|
@@ -581,10 +580,21 @@ Alchemy.setMethod(function setSetting(path, value) {
|
|
|
581
580
|
this.system_settings.setPathSilently(path, value);
|
|
582
581
|
|
|
583
582
|
if (this.started) {
|
|
584
|
-
this.
|
|
583
|
+
this.refreshSettingsObject();
|
|
585
584
|
}
|
|
586
585
|
});
|
|
587
586
|
|
|
587
|
+
/**
|
|
588
|
+
* Refresh the settings object
|
|
589
|
+
*
|
|
590
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
591
|
+
* @since 1.4.0
|
|
592
|
+
* @version 1.4.0
|
|
593
|
+
*/
|
|
594
|
+
Alchemy.setMethod(function refreshSettingsObject() {
|
|
595
|
+
this.settings = this.system_settings.toObject();
|
|
596
|
+
});
|
|
597
|
+
|
|
588
598
|
/**
|
|
589
599
|
* Get a setting value
|
|
590
600
|
*
|
|
@@ -1879,7 +1889,12 @@ Alchemy.setMethod(function parseRequestBody(req, res, callback) {
|
|
|
1879
1889
|
// Regular form-encoded data
|
|
1880
1890
|
if (content_type && content_type.indexOf('form-urlencoded') > -1) {
|
|
1881
1891
|
|
|
1882
|
-
|
|
1892
|
+
let url_form_body = this.body_parser.urlencoded({
|
|
1893
|
+
limit: request_body_size_limit,
|
|
1894
|
+
extended: true,
|
|
1895
|
+
});
|
|
1896
|
+
|
|
1897
|
+
url_form_body(req, res, function parsedBody(err) {
|
|
1883
1898
|
|
|
1884
1899
|
if (err) {
|
|
1885
1900
|
|
package/lib/core/base.js
CHANGED
|
@@ -564,7 +564,7 @@ Base.setMethod(function attachConduit(conduit) {
|
|
|
564
564
|
*
|
|
565
565
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
566
566
|
* @since 0.3.0
|
|
567
|
-
* @version 1.
|
|
567
|
+
* @version 1.4.0
|
|
568
568
|
*
|
|
569
569
|
* @param {string} name The name of the model to get
|
|
570
570
|
* @param {boolean} init Initialize the class [true]
|
|
@@ -597,9 +597,9 @@ Base.setMethod(function getModel(name, init, options) {
|
|
|
597
597
|
|
|
598
598
|
if (options.cache !== false) {
|
|
599
599
|
if (!this._modelInstances) {
|
|
600
|
-
this._modelInstances =
|
|
600
|
+
this._modelInstances = new Map();
|
|
601
601
|
} else {
|
|
602
|
-
instance = this._modelInstances
|
|
602
|
+
instance = this._modelInstances.get(name);
|
|
603
603
|
}
|
|
604
604
|
}
|
|
605
605
|
|
|
@@ -622,7 +622,7 @@ Base.setMethod(function getModel(name, init, options) {
|
|
|
622
622
|
}
|
|
623
623
|
|
|
624
624
|
if (options.cache !== false) {
|
|
625
|
-
this._modelInstances
|
|
625
|
+
this._modelInstances.set(name, instance);
|
|
626
626
|
}
|
|
627
627
|
|
|
628
628
|
return instance;
|
package/lib/core/setting.js
CHANGED
|
@@ -452,6 +452,9 @@ const Group = Function.inherits('Alchemy.Setting.Base', function Group(name, con
|
|
|
452
452
|
|
|
453
453
|
// All the children
|
|
454
454
|
this.children = new Map();
|
|
455
|
+
|
|
456
|
+
// Weak references to existing values
|
|
457
|
+
this.weak_values = new Blast.Classes.WeakValueSet();
|
|
455
458
|
});
|
|
456
459
|
|
|
457
460
|
/**
|
|
@@ -583,6 +586,14 @@ Group.setMethod(function createGroup(name) {
|
|
|
583
586
|
let group = new Group(name, this);
|
|
584
587
|
this.children.set(name, group);
|
|
585
588
|
|
|
589
|
+
if (this.weak_values.size) {
|
|
590
|
+
let group_value = group.generateValue();
|
|
591
|
+
|
|
592
|
+
for (let existing of this.weak_values) {
|
|
593
|
+
this.setDefaultValue(existing, {[name]: group_value});
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
586
597
|
return group;
|
|
587
598
|
});
|
|
588
599
|
|
|
@@ -633,6 +644,8 @@ Group.setMethod(function generateValue() {
|
|
|
633
644
|
|
|
634
645
|
this.setDefaultValue(result, object);
|
|
635
646
|
|
|
647
|
+
this.weak_values.add(result);
|
|
648
|
+
|
|
636
649
|
return result;
|
|
637
650
|
});
|
|
638
651
|
|
|
@@ -1344,6 +1357,38 @@ GroupValue.setMethod(function _setPath(silent, path, raw_value) {
|
|
|
1344
1357
|
return this.getPath(path);
|
|
1345
1358
|
});
|
|
1346
1359
|
|
|
1360
|
+
/**
|
|
1361
|
+
* Force a value at the given path
|
|
1362
|
+
*
|
|
1363
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1364
|
+
* @since 1.4.0
|
|
1365
|
+
* @version 1.4.0
|
|
1366
|
+
*
|
|
1367
|
+
* @param {string|Array} path
|
|
1368
|
+
* @param {Value}
|
|
1369
|
+
*/
|
|
1370
|
+
GroupValue.setMethod(function forceValueInstanceAtPath(path, value) {
|
|
1371
|
+
|
|
1372
|
+
if (typeof path == 'string') {
|
|
1373
|
+
path = path.split('.');
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
if (this.definition.group == null && path[0] == this.definition.name) {
|
|
1377
|
+
path.shift();
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
let last = path.pop();
|
|
1381
|
+
|
|
1382
|
+
let current = this;
|
|
1383
|
+
|
|
1384
|
+
while (path.length && current) {
|
|
1385
|
+
let next = path.shift();
|
|
1386
|
+
current = current.get(next);
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
current[VALUE][last] = value;
|
|
1390
|
+
});
|
|
1391
|
+
|
|
1347
1392
|
/**
|
|
1348
1393
|
* Convert to a datasource array
|
|
1349
1394
|
*
|
|
@@ -1584,6 +1629,20 @@ Value.setMethod(function getPath(path) {
|
|
|
1584
1629
|
return current;
|
|
1585
1630
|
});
|
|
1586
1631
|
|
|
1632
|
+
/**
|
|
1633
|
+
* Force a value at the given path
|
|
1634
|
+
*
|
|
1635
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1636
|
+
* @since 1.4.0
|
|
1637
|
+
* @version 1.4.0
|
|
1638
|
+
*
|
|
1639
|
+
* @param {string|Array} path
|
|
1640
|
+
* @param {Value}
|
|
1641
|
+
*/
|
|
1642
|
+
Value.setMethod(function forceValueInstanceAtPath(path, value) {
|
|
1643
|
+
throw new Error('Unable to perform on a simple Value instance');
|
|
1644
|
+
});
|
|
1645
|
+
|
|
1587
1646
|
if (Blast.isBrowser) {
|
|
1588
1647
|
return;
|
|
1589
1648
|
}
|
|
@@ -1675,15 +1734,61 @@ const MagicGroupValue = Function.inherits('Magic', 'Alchemy.Setting', function M
|
|
|
1675
1734
|
*/
|
|
1676
1735
|
MagicGroupValue.setMethod(function __get(key) {
|
|
1677
1736
|
|
|
1678
|
-
let result = this[
|
|
1737
|
+
let result = this[key];
|
|
1738
|
+
|
|
1739
|
+
if (result != null) {
|
|
1740
|
+
return result;
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
result = this[VALUE].get(key);
|
|
1744
|
+
|
|
1745
|
+
if (result == null) {
|
|
1746
|
+
return this[VALUE][key];
|
|
1747
|
+
}
|
|
1679
1748
|
|
|
1680
1749
|
if (!result) {
|
|
1681
|
-
return;
|
|
1750
|
+
return result;
|
|
1682
1751
|
}
|
|
1683
1752
|
|
|
1684
1753
|
if (result.is_group) {
|
|
1685
1754
|
return result.toProxyObject();
|
|
1686
1755
|
}
|
|
1687
1756
|
|
|
1757
|
+
if (!result.get) {
|
|
1758
|
+
return result;
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1688
1761
|
return result.get();
|
|
1762
|
+
});
|
|
1763
|
+
|
|
1764
|
+
/**
|
|
1765
|
+
* The magic getter
|
|
1766
|
+
*
|
|
1767
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1768
|
+
* @since 1.4.0
|
|
1769
|
+
* @version 1.4.0
|
|
1770
|
+
*
|
|
1771
|
+
* @param {string} key
|
|
1772
|
+
*/
|
|
1773
|
+
MagicGroupValue.setMethod(function __ownKeys() {
|
|
1774
|
+
return Object.keys(this[VALUE].toObject())
|
|
1775
|
+
});
|
|
1776
|
+
|
|
1777
|
+
/**
|
|
1778
|
+
* The magic getter
|
|
1779
|
+
*
|
|
1780
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1781
|
+
* @since 1.4.0
|
|
1782
|
+
* @version 1.4.0
|
|
1783
|
+
*
|
|
1784
|
+
* @param {string} key
|
|
1785
|
+
*/
|
|
1786
|
+
MagicGroupValue.setMethod(function __describe(key) {
|
|
1787
|
+
let result = Object.getOwnPropertyDescriptor(this[VALUE], key);
|
|
1788
|
+
|
|
1789
|
+
if (result == null) {
|
|
1790
|
+
result = Object.getOwnPropertyDescriptor(this, key);
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
return result;
|
|
1689
1794
|
});
|