dbm 1.4.4 → 1.4.5

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/css/admin.css CHANGED
@@ -56,6 +56,7 @@
56
56
  height: 120px;
57
57
  }
58
58
 
59
+ .admin-save-all-position,
59
60
  .dbm-admin .save-all-position {
60
61
  position: fixed;
61
62
  bottom: 10px;
package/css/utils.css CHANGED
@@ -156,6 +156,10 @@
156
156
  display: block;
157
157
  }
158
158
 
159
+ .display-inline-block {
160
+ display: inline-block;
161
+ }
162
+
159
163
  .display-none {
160
164
  display: none;
161
165
  }
package/dbm.js CHANGED
@@ -93,6 +93,10 @@ export const getGraphApi = function() {
93
93
  return getRepositoryItem("graphApi").controller;
94
94
  }
95
95
 
96
+ export const getCachedGraphApi = function() {
97
+ return getRepositoryItem("cachedGraphApi").controller;
98
+ }
99
+
96
100
  export * as utils from "./utils/index.js";
97
101
  export * as core from "./core/index.js";
98
102
  export * as loading from "./loading/index.js";
package/ecommerce/Cart.js CHANGED
@@ -16,7 +16,7 @@ export default class Cart extends Dbm.core.BaseObject {
16
16
  //METODO: integrate local storage
17
17
  }
18
18
 
19
- addProduct(aProduct, aQuantity = 1) {
19
+ addProduct(aProduct, aQuantity = 1, aMeta = null) {
20
20
  //console.log("addProduct");
21
21
  //console.log(aQuantity);
22
22
 
@@ -25,8 +25,14 @@ export default class Cart extends Dbm.core.BaseObject {
25
25
  let index = Dbm.utils.ArrayFunctions.getItemIndexByIfExists(lineItems, "product", aProduct);
26
26
 
27
27
  if(index !== -1) {
28
- lineItem = lineItems[index];
29
- lineItem.controller.increaseQuantity(aQuantity);
28
+ lineItem = lineItems[index].controller;
29
+ lineItem.increaseQuantity(aQuantity);
30
+ //METODO: support items with different meta
31
+ if(aMeta) {
32
+ for(let objectName in aMeta) {
33
+ lineItem.setMeta(objectName, aMeta[objectName]);
34
+ }
35
+ }
30
36
  }
31
37
  else {
32
38
  let id = "lineItem" + Dbm.getInstance().getNextId();
@@ -36,6 +42,12 @@ export default class Cart extends Dbm.core.BaseObject {
36
42
  lineItem.setQuantity(aQuantity);
37
43
  lineItem.setCart(this.item);
38
44
 
45
+ if(aMeta) {
46
+ for(let objectName in aMeta) {
47
+ lineItem.setMeta(objectName, aMeta[objectName]);
48
+ }
49
+ }
50
+
39
51
  Dbm.flow.addUpdateCommand(lineItem.item.properties.quantity, this._changeCommand);
40
52
 
41
53
  let newLineItems = [].concat(lineItems);
@@ -7,6 +7,7 @@ export default class CartLineItem extends Dbm.core.BaseObject {
7
7
  this.item.setValue("cart", null);
8
8
  this.item.setValue("product", null);
9
9
  this.item.setValue("quantity", 0);
10
+ this.item.setValue("meta", {});
10
11
  }
11
12
 
12
13
  setCart(aItem) {
@@ -30,6 +31,12 @@ export default class CartLineItem extends Dbm.core.BaseObject {
30
31
  return this;
31
32
  }
32
33
 
34
+ setMeta(aKey, aValue) {
35
+ this.item.meta[aKey] = aValue;
36
+
37
+ return this;
38
+ }
39
+
33
40
  increaseQuantity(aQuantity) {
34
41
  this.item.quantity += aQuantity;
35
42
 
@@ -33,7 +33,7 @@ export default class LocalStorageCartLoader extends Dbm.core.BaseObject {
33
33
  for(let i = 0; i < currentArrayLength; i++) {
34
34
  let currentData = currentArray[i];
35
35
 
36
- this.item.cart.controller.addProduct(repository.getItem(currentData["product"]), currentData["quantity"]);
36
+ this.item.cart.controller.addProduct(repository.getItem(currentData["product"]), currentData["quantity"], currentData["meta"]);
37
37
  }
38
38
  }
39
39
  }
@@ -58,7 +58,7 @@ export default class LocalStorageCartLoader extends Dbm.core.BaseObject {
58
58
  for(let i = 0; i < currentArrayLength; i++) {
59
59
  let currentData = currentArray[i];
60
60
 
61
- let encodedData = {"product": currentData.product.id, "quantity": currentData.quantity};
61
+ let encodedData = {"product": currentData.product.id, "quantity": currentData.quantity, "meta": currentData.meta};
62
62
  encodedLineItems.push(encodedData);
63
63
  }
64
64
 
@@ -15,7 +15,7 @@ export default class InArray extends Dbm.core.BaseObject {
15
15
 
16
16
  getSelectionForValue(aValue) {
17
17
  let selections = this.item.selections;
18
- let currentSelection = Dbm.utils.ArrayFunctions.getItemBy(selections, "value", aValue);
18
+ let currentSelection = Dbm.utils.ArrayFunctions.getItemByIfExists(selections, "value", aValue);
19
19
 
20
20
  if(!currentSelection) {
21
21
  let selections = [].concat(this.item.selections);
@@ -4,6 +4,8 @@ export default class SingleSelection extends Dbm.core.BaseObject {
4
4
  _construct() {
5
5
  super._construct();
6
6
 
7
+ this._valueMap = new Map();
8
+
7
9
  let valueUpdatedCommand = Dbm.commands.callFunction(this._valueUpdated.bind(this));
8
10
 
9
11
  this._selectionChangedBound = this._selectionChanged.bind(this);
@@ -15,13 +17,22 @@ export default class SingleSelection extends Dbm.core.BaseObject {
15
17
  }
16
18
 
17
19
  addSelectionValue(aValue) {
20
+ //console.log("addSelectionValue");
21
+ //console.log(aValue);
22
+
23
+ if(this._valueMap.has(aValue)) {
24
+ return this._valueMap.get(aValue);
25
+ }
26
+
18
27
  let selections = [].concat(this.item.selections);
19
28
 
20
29
  let property = new Dbm.flow.FlowProperty();
21
30
  property.setValue(false);
22
31
  Dbm.flow.addUpdateCommand(property, Dbm.commands.callFunction(this._selectionChangedBound, [property, aValue]));
32
+ this._valueMap.set(aValue, property);
23
33
 
24
34
  selections.push({"value": aValue, "property": property});
35
+
25
36
  this.item.selections = selections;
26
37
 
27
38
  return property;
@@ -0,0 +1,69 @@
1
+ import Dbm from "../index.js";
2
+
3
+ export default class LoadingSequence extends Dbm.core.BaseObject {
4
+
5
+ _construct() {
6
+
7
+ super._construct();
8
+
9
+ this.item.setValue("waitingLoaders", []);
10
+ this.item.setValue("loaders", []);
11
+ this.item.setValue("currentLoader", null);
12
+
13
+ this.item.setValue("status", Dbm.loading.LoadingStatus.NOT_STARTED);
14
+ }
15
+
16
+ get completed() {
17
+ let status = this.item.status;
18
+ return (status === Dbm.loading.LoadingStatus.LOADED || status === Dbm.loading.LoadingStatus.ERROR);
19
+ }
20
+
21
+ addLoader(aLoader) {
22
+ this.item.addToArray("waitingLoaders", aLoader);
23
+ this.item.addToArray("loaders", aLoader);
24
+
25
+ if(this.item.status === Dbm.loading.LoadingStatus.LOADED) {
26
+ this._loadNextLoader();
27
+ }
28
+
29
+ return this;
30
+ }
31
+
32
+ load() {
33
+ console.log("load");
34
+
35
+ if(this.item.status !== Dbm.loading.LoadingStatus.NOT_STARTED) {
36
+ return this;
37
+ }
38
+
39
+ this._loadNextLoader();
40
+
41
+ return this;
42
+ }
43
+
44
+ _loadNextLoader() {
45
+ console.log("_loadNextLoader");
46
+
47
+ if(this.item.waitingLoaders.length > 0) {
48
+ let nextLoader = this.item.waitingLoaders[0];
49
+ this.item.removeFromArray("waitingLoaders", nextLoader);
50
+ this.item.currentLoader = nextLoader;
51
+
52
+ this.item.status = Dbm.loading.LoadingStatus.LOADING;
53
+
54
+ Dbm.flow.runWhenMatched(nextLoader.item.properties.status, Dbm.loading.LoadingStatus.LOADED, Dbm.commands.callFunction(this._loaderLoaded.bind(this), [nextLoader]));
55
+ nextLoader.load();
56
+
57
+ }
58
+ else {
59
+ this.item.status = Dbm.loading.LoadingStatus.LOADED;
60
+ }
61
+ }
62
+
63
+ _loaderLoaded(aLoader) {
64
+ if(this.item.currentLoader === aLoader) {
65
+ this.item.currentLoader = null;
66
+ this._loadNextLoader();
67
+ }
68
+ }
69
+ }
@@ -0,0 +1,51 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export default class DataLoader extends Dbm.core.BaseObject {
4
+
5
+ _construct() {
6
+
7
+ super._construct();
8
+
9
+ this.item.setValue("request", null);
10
+
11
+ this.item.setValue("type", null);
12
+ this.item.setValue("body", {});
13
+
14
+ this.item.setValue("status", Dbm.loading.LoadingStatus.NOT_STARTED);
15
+
16
+ this.item.setValue("data", null);
17
+ }
18
+
19
+ get completed() {
20
+ let status = this.item.status;
21
+ return (status === Dbm.loading.LoadingStatus.LOADED || status === Dbm.loading.LoadingStatus.ERROR);
22
+ }
23
+
24
+ setType(aType) {
25
+ this.item.type = aType;
26
+
27
+ return this;
28
+ }
29
+
30
+ setBody(aBody) {
31
+ this.item.body = aBody;
32
+
33
+ return this;
34
+ }
35
+
36
+ load() {
37
+
38
+ if(this.item.status !== Dbm.loading.LoadingStatus.NOT_STARTED) {
39
+ return this;
40
+ }
41
+
42
+ let request = Dbm.getCachedGraphApi().requestData(this.item.type, this.item.body);
43
+
44
+ this.item.request = request;
45
+
46
+ this.item.properties.data.connectInput(request.properties.data);
47
+ this.item.properties.status.connectInput(request.properties.status);
48
+
49
+ return this;
50
+ }
51
+ }
@@ -0,0 +1,63 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export default class RangeLoader extends Dbm.core.BaseObject {
4
+
5
+ _construct() {
6
+
7
+ super._construct();
8
+
9
+ this.item.setValue("request", null);
10
+
11
+ this.item.setValue("selects", []);
12
+ this.item.setValue("encodes", ["id"]);
13
+
14
+ this.item.setValue("status", Dbm.loading.LoadingStatus.NOT_STARTED);
15
+
16
+ this.item.setValue("items", []);
17
+ }
18
+
19
+ get completed() {
20
+ let status = this.item.status;
21
+ return (status === Dbm.loading.LoadingStatus.LOADED || status === Dbm.loading.LoadingStatus.ERROR);
22
+ }
23
+
24
+ addSelect(aSelect) {
25
+ this.item.addToArray("selects", aSelect);
26
+
27
+ return this;
28
+ }
29
+
30
+ includePrivate() {
31
+ this.addSelect({"type": "includePrivate"});
32
+
33
+ return this;
34
+ }
35
+
36
+ includedraft() {
37
+ this.addSelect({"type": "includeDraft"});
38
+
39
+ return this;
40
+ }
41
+
42
+ addEncode(aEncode) {
43
+ this.item.addToArray("encodes", aEncode);
44
+
45
+ return this;
46
+ }
47
+
48
+ load() {
49
+
50
+ if(this.item.status !== Dbm.loading.LoadingStatus.NOT_STARTED) {
51
+ return this;
52
+ }
53
+
54
+ let request = Dbm.getCachedGraphApi().requestRange(this.item.selects, this.item.encodes);
55
+
56
+ this.item.request = request;
57
+
58
+ this.item.properties.items.connectInput(request.items);
59
+ this.item.properties.status.connectInput(request.status);
60
+
61
+ return this;
62
+ }
63
+ }
@@ -0,0 +1,12 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export {default as RangeLoader} from "./RangeLoader.js";
4
+ export {default as DataLoader} from "./DataLoader.js";
5
+
6
+ export const createDataLoader = function(aType, aBody = {}) {
7
+ let newLoader = new Dbm.loading.graphapi.DataLoader();
8
+ newLoader.setType(aType);
9
+ newLoader.setBody(aBody);
10
+
11
+ return newLoader;
12
+ }
package/loading/index.js CHANGED
@@ -1,10 +1,14 @@
1
1
  import Dbm from "../index.js";
2
+
2
3
  export {default as ScriptLoader} from "./ScriptLoader.js";
3
4
  export {default as JsonLoader} from "./JsonLoader.js";
4
5
  export {default as ImageLoader} from "./ImageLoader.js";
6
+ export {default as LoadingSequence} from "./LoadingSequence.js";
7
+
5
8
  export * as LoadingStatus from "./LoadingStatus.js";
6
9
 
7
10
  export * as node from "./node/index.js";
11
+ export * as graphapi from "./graphapi/index.js";
8
12
 
9
13
  export const loadScript = function(aUrl) {
10
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbm",
3
- "version": "1.4.4",
3
+ "version": "1.4.5",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "exports": {
package/react/AddProps.js CHANGED
@@ -10,7 +10,6 @@ export default class AddProps extends Dbm.react.BaseObject {
10
10
  }
11
11
 
12
12
  _getMainElementProps() {
13
- //console.log("wprr/manipulation/ManipulationBaseObject::_getMainElementProps");
14
13
  let returnObject = {};
15
14
 
16
15
  for(let objectName in this.props) {
@@ -33,6 +32,7 @@ export default class AddProps extends Dbm.react.BaseObject {
33
32
  }
34
33
 
35
34
  _performClone(aChild, aProps) {
35
+ //console.log("_cloneChildrenAndAddProps");
36
36
 
37
37
  if(aChild instanceof Array) {
38
38
  let returnArray = [];
@@ -46,20 +46,8 @@ export default class AddProps extends Dbm.react.BaseObject {
46
46
 
47
47
  return returnArray;
48
48
  }
49
-
50
- let newProps = aProps;
51
- if(aChild && aChild.props && aChild.props.className) {
52
- newProps = {};
53
- for(let objectName in aProps) {
54
- newProps[objectName] = aProps[objectName];
55
- }
56
- if(aProps.className) {
57
- newProps.className = aProps.className + " " + aChild.props.className;
58
- }
59
- else {
60
- newProps.className = aChild.props.className;
61
- }
62
- }
49
+
50
+ let newProps = this._copyProps(aChild.props);
63
51
 
64
52
  let callArray = [aChild, newProps];
65
53
 
@@ -80,21 +68,21 @@ export default class AddProps extends Dbm.react.BaseObject {
80
68
  }
81
69
 
82
70
  _cloneChildrenAndAddProps(aChildren) {
83
- //console.log("wprr/manipulation/ManipulationBaseObject::_cloneChildrenAndAddProps");
71
+ //console.log("_cloneChildrenAndAddProps");
84
72
 
85
73
  let children = aChildren;
86
74
 
87
75
  if(children.length === 0) {
88
76
  return null;
89
77
  }
90
- else if(children.length === 1) {
91
- return this._performClone(children[0], this.props);
92
- }
93
-
94
- let returnArray = new Array();
95
78
 
96
79
  let mainElementProps = this.props;
97
80
 
81
+ if(children.length === 1) {
82
+ return this._performClone(children[0], mainElementProps);
83
+ }
84
+
85
+ let returnArray = new Array();
98
86
  let currentArray = children;
99
87
  let currentArrayLength = currentArray.length;
100
88
  for(let i = 0; i < currentArrayLength; i++) {
@@ -106,16 +94,16 @@ export default class AddProps extends Dbm.react.BaseObject {
106
94
  }
107
95
  }
108
96
 
109
- let callArray = [Fragment, {}].concat(returnArray);
97
+ let callArray = [React.Fragment, {}].concat(returnArray);
110
98
  return React.createElement.apply(React, callArray);
111
99
  }
112
100
 
113
101
  _renderClonedElement() {
114
- return this._cloneChildrenAndAddProps(this.getPropValue("children"));
102
+ let children = Dbm.utils.ArrayFunctions.singleOrArray(this.getPropValue("children"));
103
+ return this._cloneChildrenAndAddProps(children);
115
104
  }
116
105
 
117
106
  _createClonedElement() {
118
- //console.log("wprr/manipulation/ManipulationBaseObject::_createClonedElement");
119
107
 
120
108
  this._clonedElement = this._renderClonedElement();
121
109
  }
@@ -32,12 +32,13 @@ export default class ObjectList extends Dbm.react.BaseObject {
32
32
  }
33
33
 
34
34
  _loaded(aRequest) {
35
- console.log("_loaded");
35
+ //console.log("_loaded");
36
36
 
37
37
  let currentArray = [].concat(aRequest.items);
38
38
 
39
39
  let nameField = this.getPropValueWithDefault("nameField", "name");
40
- Dbm.utils.ArrayFunctions.sortOnField(currentArray, nameField);
40
+
41
+ Dbm.utils.ArrayFunctions.naturalSortOnField(currentArray, nameField);
41
42
 
42
43
  this.item.items = currentArray;
43
44
  }
@@ -5,7 +5,7 @@ export default class SingleRelation extends Dbm.react.BaseObject {
5
5
  _construct() {
6
6
  super._construct();
7
7
 
8
- let graphApi = Dbm.getInstance().repository.getItem("graphApi").controller;
8
+ let graphApi = Dbm.getGraphApi();
9
9
 
10
10
  let id = this.context.item.id;
11
11
 
@@ -13,12 +13,23 @@ export default class SingleRelation extends Dbm.react.BaseObject {
13
13
  this.item.requireProperty("loaded", false);
14
14
 
15
15
  {
16
- let request = graphApi.requestRange(
17
- [
16
+ let selects = [
18
17
  {"type": "includePrivate"},
19
18
  {"type": "includeDraft"},
20
19
  {"type": "idSelection", "ids": [id]},
21
- ],
20
+ ];
21
+
22
+ if(this.getPropValue("anyStatus")) {
23
+ selects = [
24
+ {"type": "includeAnyStatus"},
25
+ {"type": "idSelection", "ids": [id]},
26
+ ];
27
+ }
28
+
29
+ console.log(selects);
30
+
31
+ let request = graphApi.requestRange(
32
+ selects,
22
33
  ["admin_fields", "relations"]
23
34
  );
24
35
  allLoaded.addCheck(request.properties.status);
@@ -32,6 +43,7 @@ export default class SingleRelation extends Dbm.react.BaseObject {
32
43
  let id = this.context.item.id;
33
44
 
34
45
  let label = this.getPropValue("label");
46
+ let labelElement = label ? React.createElement(Dbm.react.form.LabelledArea, {label: label}) : null;
35
47
  let direction = this.getPropValue("direction");
36
48
  let relationType = this.getPropValue("relationType");
37
49
  let objectType = this.getPropValue("objectType");
@@ -41,9 +53,9 @@ export default class SingleRelation extends Dbm.react.BaseObject {
41
53
  return React.createElement("div", {},
42
54
 
43
55
  React.createElement(Dbm.react.area.HasData, {check: this.item.properties.loaded},
44
- React.createElement(Dbm.react.form.LabelledArea, {label: label}),
56
+ labelElement,
45
57
  React.createElement(Dbm.react.admin.editorsgroup.EditRelation, {"direction": direction, "relationType": relationType, "objectType": objectType},
46
- React.createElement(Dbm.react.form.GraphApiObjectSelection, {value: Dbm.react.source.contextVariable("valueEditor.editValue.value"), "objectType": objectType, "encoding": encoding, nameField: nameField, className: "standard-field standard-field-padding full-width"})
58
+ React.createElement(Dbm.react.form.GraphApiObjectSelection, {value: Dbm.react.source.contextVariable("valueEditor.editValue.value"), "objectType": objectType, "encoding": encoding, nameField: nameField, anyStatus: this.getPropValue("anyStatus"), className: "standard-field standard-field-padding full-width"})
47
59
  )
48
60
  )
49
61
 
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import Dbm from "../../../../index.js";
3
3
 
4
- export default class ObjectList extends Dbm.react.BaseObject {
4
+ export default class List extends Dbm.react.BaseObject {
5
5
  _construct() {
6
6
  super._construct();
7
7
  }
@@ -0,0 +1,103 @@
1
+ import React from "react";
2
+ import Dbm from "../../index.js";
3
+
4
+ export default class GraphApiObjectOptions extends Dbm.react.BaseObject {
5
+ _construct() {
6
+ super._construct();
7
+
8
+ let valueProp = this.getDynamicProp("value", "");
9
+ this.item.requireProperty("items", []);
10
+ this.item.requireProperty("options", []);
11
+
12
+ this._singelSelection = new Dbm.flow.controllers.select.SingleSelection();
13
+ this._singelSelection.item.properties.value.connectInput(valueProp);
14
+
15
+ let objectType = this.getPropValue("objectType");
16
+ let encodings = Dbm.utils.ArrayFunctions.arrayOrSeparatedString(this.getPropValueWithDefault("encoding", "name,identifier"), ",", true);
17
+
18
+ {
19
+ let request = Dbm.getCachedGraphApi().requestRange(
20
+ [
21
+ {"type": "byObjectType", "objectType": objectType},
22
+ {"type": "includeDraft"},
23
+ {"type": "includePrivate"}
24
+ ],
25
+ encodings
26
+ );
27
+
28
+ Dbm.flow.runWhenMatched(request.properties.status, Dbm.loading.LoadingStatus.LOADED, Dbm.commands.callFunction(this._itemsLoaded.bind(this), [request]));
29
+ }
30
+ }
31
+
32
+
33
+
34
+ _itemsLoaded(aRequest) {
35
+
36
+ let nameField = this.getPropValueWithDefault("nameField", "name");
37
+ let identifierField = this.getPropValueWithDefault("identifierField", "identifier");
38
+ let options = this.getPropValue("options");
39
+
40
+ let currentArray = [].concat(aRequest.items);
41
+ if(options) {
42
+ currentArray = Dbm.utils.ArrayFunctions.filterByField(aRequest.items, identifierField, options, "inArray");
43
+
44
+ let sortFunction = function(aA, aB) {
45
+
46
+ let sortIndexA = options.indexOf(aA);
47
+ if(sortIndexA === -1) {
48
+ sortIndexA = order.length;
49
+ }
50
+
51
+ let sortIndexB = options.indexOf(aB);
52
+ if(sortIndexB === -1) {
53
+ sortIndexB = order.length;
54
+ }
55
+
56
+ return sortIndexA-sortIndexB;
57
+ }
58
+
59
+ Dbm.utils.ArrayFunctions.sortOnField(currentArray, identifierField, sortFunction);
60
+ }
61
+ else {
62
+ Dbm.utils.ArrayFunctions.naturalSortOnField(currentArray, nameField);
63
+ }
64
+
65
+ this.item.items = currentArray;
66
+
67
+ let rows = new Array();
68
+
69
+ let children = this.getPropValue("children");
70
+ if(!children) {
71
+ children = React.createElement("span", {},
72
+ React.createElement(Dbm.react.form.Checkbox, {"checked": Dbm.react.source.contextVariable("selected")}),
73
+ Dbm.react.text.text(Dbm.react.source.item(nameField))
74
+ );
75
+ }
76
+
77
+ let currentArrayLength = currentArray.length;
78
+ for(let i = 0; i < currentArrayLength; i++) {
79
+ let currentItem = currentArray[i];
80
+ let currentRow = new Dbm.repository.Item();
81
+ currentRow.setId("_dbmInternal/row" + currentItem.id);
82
+
83
+ let property = this._singelSelection.addSelectionValue(currentItem.id);
84
+
85
+ currentRow.setValue("item", currentItem);
86
+ currentRow.setValue("element", React.createElement(Dbm.react.context.AddContextVariables, {"values": {"item": currentItem, "selected": property}}, children));
87
+ rows.push(currentRow);
88
+ }
89
+ this.item.options = rows;
90
+ }
91
+
92
+ _renderMainElement() {
93
+
94
+ let value = this.getDynamicProp("value");
95
+
96
+ return this._createMainElement("div", {},
97
+ React.createElement(Dbm.react.area.List, {items: this.item.properties.options, as: "option"},
98
+ React.createElement(Dbm.react.area.InsertElement, {"element": Dbm.react.source.contextVariable("option.element")})
99
+ )
100
+ );
101
+ }
102
+ }
103
+
@@ -9,24 +9,27 @@ export default class GraphApiObjectSelection extends Dbm.react.BaseObject {
9
9
  this.item.requireProperty("items", []);
10
10
 
11
11
  let objectType = this.getPropValue("objectType");
12
- let encoding = this.getPropValue("encoding");
13
- if(!encoding) {
14
- encoding = "name";
15
- }
12
+ let encodings = Dbm.utils.ArrayFunctions.arrayOrSeparatedString(this.getPropValueWithDefault("encoding", "name"), ",", true);
16
13
 
17
- let graphApi = Dbm.getInstance().repository.getItem("graphApi").controller;
18
14
  {
19
- let request = graphApi.requestRange(
20
- [
15
+ let selects = [
21
16
  {"type": "byObjectType", "objectType": objectType},
22
17
  {"type": "includeDraft"},
23
18
  {"type": "includePrivate"}
24
- ],
25
- [encoding]
19
+ ];
20
+ if(this.getPropValue("anyStatus")) {
21
+ selects = [
22
+ {"type": "byObjectType", "objectType": objectType},
23
+ {"type": "includeAnyStatus"}
24
+ ];
25
+ }
26
+
27
+ let request = Dbm.getCachedGraphApi().requestRange(
28
+ selects,
29
+ encodings
26
30
  );
27
31
 
28
-
29
- Dbm.flow.addUpdateCommandWhenMatched(request.properties.status, Dbm.loading.LoadingStatus.LOADED, Dbm.commands.callFunction(this._itemsLoaded.bind(this), [request]));
32
+ Dbm.flow.runWhenMatched(request.properties.status, Dbm.loading.LoadingStatus.LOADED, Dbm.commands.callFunction(this._itemsLoaded.bind(this), [request]));
30
33
  }
31
34
  }
32
35
 
@@ -41,7 +44,7 @@ export default class GraphApiObjectSelection extends Dbm.react.BaseObject {
41
44
  }
42
45
 
43
46
  let currentArray = [].concat(aRequest.items);
44
- Dbm.utils.ArrayFunctions.sortOnField(currentArray, nameField);
47
+ Dbm.utils.ArrayFunctions.naturalSortOnField(currentArray, nameField);
45
48
 
46
49
  let currentArrayLength = currentArray.length;
47
50
  for(let i = 0; i < currentArrayLength; i++) {
@@ -11,4 +11,5 @@ export {default as TextArea} from "./TextArea.js";
11
11
  export {default as EditObjectProperty} from "./EditObjectProperty.js";
12
12
  export {default as Form} from "./Form.js";
13
13
  export {default as Option} from "./Option.js";
14
- export {default as Dropdown} from "./Dropdown.js";
14
+ export {default as Dropdown} from "./Dropdown.js";
15
+ export {default as GraphApiObjectOptions} from "./GraphApiObjectOptions.js";
package/react/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export {default as BaseObject} from "./BaseObject.js";
2
2
  export {default as RefToProperty} from "./RefToProperty.js";
3
+ export {default as AddProps} from "./AddProps.js";
3
4
 
4
5
  export * as ChildFunctions from "./ChildFunctions.js";
5
6
 
@@ -16,7 +16,7 @@ export default class LoginForm extends Dbm.react.BaseObject {
16
16
  let loader = new Dbm.loading.JsonLoader();
17
17
  loader.setupJsonPost("/api/user/login", {"username": this.item.username, "password": this.item.password});
18
18
 
19
- Dbm.flow.addUpdateCommand(loader.item.properties.status, Dbm.commands.callFunction(this._loaderStatusChanged.bind(this), [loader]));
19
+ Dbm.flow.runWhenMatched(loader.item.properties.status, Dbm.loading.LoadingStatus.LOADED, Dbm.commands.callFunction(this._loaderStatusChanged.bind(this), [loader]));
20
20
 
21
21
  loader.load();
22
22
  }
@@ -25,15 +25,13 @@ export default class LoginForm extends Dbm.react.BaseObject {
25
25
  console.log("_loaderStatusChanged");
26
26
  console.log(aLoader, aLoader.item.status);
27
27
 
28
- if(aLoader.item.status === Dbm.loading.LoadingStatus.LOADED) {
29
- if(aLoader.item.data.success) {
30
-
31
- let item = Dbm.getGraphApi().signIn(aLoader.item.data.data.wsToken);
32
- Dbm.flow.addUpdateCommand(item.properties.status, Dbm.commands.callFunction(this._graphApiRequestStatusChanges.bind(this), [item, aLoader]));
33
- }
34
- else {
35
- alert("Unable to log in: " + aLoader.item.data.message);
36
- }
28
+ if(aLoader.item.data.success) {
29
+
30
+ let item = Dbm.getGraphApi().signIn(aLoader.item.data.data.wsToken);
31
+ Dbm.flow.runWhenMatched(item.properties.status, Dbm.loading.LoadingStatus.LOADED, Dbm.commands.callFunction(this._graphApiRequestStatusChanges.bind(this), [item, aLoader]));
32
+ }
33
+ else {
34
+ alert("Unable to log in: " + aLoader.item.data.message);
37
35
  }
38
36
  }
39
37
 
@@ -86,6 +86,20 @@ export default class Item extends Dbm.core.LifeCycleObject {
86
86
  return this;
87
87
  }
88
88
 
89
+ addUniqueToArray(aName, aValue) {
90
+ let currentArray = this[aName];
91
+ if(currentArray) {
92
+ let index = currentArray.indexOf(aValue);
93
+ if(index !== -1) {
94
+ return this;
95
+ }
96
+ }
97
+
98
+ this.addToArray(aName, aValue);
99
+
100
+ return this;
101
+ }
102
+
89
103
  removeFromArray(aName, aValue) {
90
104
  let currentArray = this[aName];
91
105
  if(currentArray) {
@@ -266,19 +266,21 @@ export const getUnselectedItems = function(aSelectedItems, aAllItems) {
266
266
  return returnItems;
267
267
  }
268
268
 
269
+ const defaultCompareFunction = function (aA, aB) {
270
+ if(aA < aB) {
271
+ return -1;
272
+ }
273
+ else if(aA > aB) {
274
+ return 1;
275
+ }
276
+
277
+ return 0;
278
+ }
279
+
269
280
  export const sortOnField = function(aArray, aField, aCompareFunction = null) {
270
281
  let compareFunction = aCompareFunction;
271
282
  if(!compareFunction) {
272
- compareFunction = function(aA, aB) {
273
- if(aA < aB) {
274
- return -1;
275
- }
276
- else if(aA > aB) {
277
- return 1;
278
- }
279
-
280
- return 0;
281
- }
283
+ compareFunction = defaultCompareFunction;
282
284
  }
283
285
 
284
286
  let sortFunction = function(aA, aB) {
@@ -311,6 +313,27 @@ export const sortOnNumericField = function(aArray, aField) {
311
313
  return sortOnField(aArray, aField, compareFunction);
312
314
  }
313
315
 
316
+ export const naturalSortOnField = function(aArray, aField, aLanguageCode = null) {
317
+
318
+ if(!aLanguageCode) {
319
+ aLanguageCode = Dbm.getRepositoryItem("site").currentLanguageCode;
320
+ }
321
+
322
+ let compareObject = new Intl.Collator(aLanguageCode, { numeric: true, sensitivity: 'base' });
323
+
324
+ let compareFunction = function(aA, aB) {
325
+ if(!aA && !aB) return 0;
326
+ if(!aA) return 1;
327
+ if(!aB) return -1;
328
+
329
+ let result = compareObject.compare(aA, aB);
330
+
331
+ return result;
332
+ }
333
+
334
+ return sortOnField(aArray, aField, compareFunction)
335
+ }
336
+
314
337
  export const getItemIndexByIfExists = function(aArray, aField, aIdentifier) {
315
338
 
316
339
  if(!Array.isArray(aArray)) {