dbm 1.1.6 → 1.1.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.
@@ -118,11 +118,8 @@ export default class MoveElement extends Dbm.core.BaseObject {
118
118
  let minY = this.item.minY;
119
119
  let maxY = this.item.maxY;
120
120
 
121
- this.item.xParameter = Math.max(minX, Math.min(x, maxX));
122
- this.item.yParameter = Math.max(minY, Math.min(y, maxY));
123
-
124
- console.log(this.item.xParameter);
125
- console.log(this.item.yParameter);
121
+ this.item.properties.xParameter.getMostUpstreamProperty().value = Math.max(minX, Math.min(x, maxX));
122
+ this.item.properties.yParameter.getMostUpstreamProperty().value = Math.max(minY, Math.min(y, maxY));
126
123
  }
127
124
 
128
125
  _callback_mouseUp(aEvent) {
@@ -146,7 +143,7 @@ export default class MoveElement extends Dbm.core.BaseObject {
146
143
  }
147
144
 
148
145
  _callback_mouseMove(aEvent) {
149
- console.log("_callback_mouseMove");
146
+ //console.log("_callback_mouseMove");
150
147
  //console.log(aEvent);
151
148
 
152
149
  if(aEvent.type === "touchmove") {
@@ -158,7 +155,7 @@ export default class MoveElement extends Dbm.core.BaseObject {
158
155
  }
159
156
 
160
157
  _callback_startDrag(aEvent) {
161
- console.log("_callback_startDrag");
158
+ //console.log("_callback_startDrag");
162
159
  //console.log(aEvent, aEvent.type);
163
160
 
164
161
  if(aEvent.type === "touchstart") {
package/flow/index.js CHANGED
@@ -67,8 +67,6 @@ export const animateValue = function(aValue, aTime = 0.5, aEasing = null) {
67
67
  returnObject._internal_addProperty("output", outputProperty);
68
68
 
69
69
  let updateCommand = Dbm.flow.addUpdateCommand(inputProperty, Dbm.commands.callFunction(function(aItem) {
70
- console.log("animate value");
71
-
72
70
  aItem.properties.output.animateValue(aItem.input, aItem.time, aItem.easing);
73
71
  }, [returnObject]));
74
72
 
@@ -0,0 +1,51 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class TransformStyle extends Dbm.flow.updatefunctions.basic.CombineString {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.stringCombiners = [];
9
+ this.input.delimeter = " ";
10
+ }
11
+
12
+ addSingleValueOperation(aOperation, aValue, aUnit = "") {
13
+ let newCombineString = new Dbm.flow.updatefunctions.basic.CombineString();
14
+ newCombineString.addParts(aOperation, "(", aValue, aUnit, ")");
15
+ this.stringCombiners.push(newCombineString);
16
+
17
+ this.addPart(newCombineString.output.properties.value);
18
+ }
19
+
20
+ addDoubleValueOperation(aOperation, aValue1, aUnit1 = "", aValue2, aUnit2 = "") {
21
+ let newCombineString = new Dbm.flow.updatefunctions.basic.CombineString();
22
+ newCombineString.addParts(aOperation, "(", aValue1, aUnit1, ", ", aValue2, aUnit2, ")");
23
+ this.stringCombiners.push(newCombineString);
24
+
25
+ this.addPart(newCombineString.output.properties.value);
26
+ }
27
+
28
+ translate(aValue1, aUnit1 = "px", aValue2, aUnit2 = "px") {
29
+ this.addDoubleValueOperation("translate", aValue1, aUnit1, aValue2, aUnit2);
30
+ }
31
+
32
+ translateX(aValue, aUnit = "px") {
33
+ this.addSingleValueOperation("translateX", aValue, aUnit);
34
+ }
35
+
36
+ translateY(aValue, aUnit = "px") {
37
+ this.addSingleValueOperation("translateY", aValue, aUnit);
38
+ }
39
+
40
+ uniformScale(aValue, aUnit = "") {
41
+ this.addDoubleValueOperation("scale", aValue, aUnit, aValue, aUnit);
42
+ }
43
+
44
+ rotate(aValue, aUnit = "deg") {
45
+ this.addSingleValueOperation("rotate", aValue, aUnit);
46
+ }
47
+
48
+ perspective(aValue, aUnit = "px") {
49
+ this.addSingleValueOperation("perspective", aValue, aUnit);
50
+ }
51
+ }
@@ -1,4 +1,5 @@
1
1
  export {default as ElementSize} from "./ElementSize.js";
2
2
  export {default as StyleObject} from "./StyleObject.js";
3
3
  export {default as HorizontalFlip} from "./HorizontalFlip.js";
4
- export {default as ElementPosition} from "./ElementPosition.js";
4
+ export {default as ElementPosition} from "./ElementPosition.js";
5
+ export {default as TransformStyle} from "./TransformStyle.js";
@@ -2,4 +2,5 @@ export * as logic from "./logic/index.js";
2
2
  export * as debug from "./debug/index.js";
3
3
  export * as react from "./react/index.js";
4
4
  export * as basic from "./basic/index.js";
5
- export * as dom from "./dom/index.js";
5
+ export * as dom from "./dom/index.js";
6
+ export * as thirdparty from "./thirdparty/index.js";
@@ -0,0 +1 @@
1
+ export * as threejs from "./threejs/index.js";
@@ -0,0 +1,48 @@
1
+ import Dbm from "../../../../index.js";
2
+
3
+ export default class UpdateObjectPosition extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("object", null);
9
+ this.input.register("x", 0);
10
+ this.input.register("y", 0);
11
+ this.input.register("z", 0);
12
+
13
+ this.input.register("rotationX", 0);
14
+ this.input.register("rotationY", 0);
15
+ this.input.register("rotationZ", 0);
16
+
17
+ this.input.register("scaleX", 1);
18
+ this.input.register("scaleY", 1);
19
+ this.input.register("scaleZ", 1);
20
+
21
+ this.output.register("dynamicUpdate", 0);
22
+ }
23
+
24
+ _update() {
25
+ //console.log("UpdateObjectPosition::_update");
26
+
27
+ let dynamicUpdate = this.output.dynamicUpdate;
28
+ dynamicUpdate++;
29
+
30
+ let object = this.input.object;
31
+
32
+ if(object) {
33
+ object.position.x = this.input.x;
34
+ object.position.y = this.input.y;
35
+ object.position.z = this.input.z;
36
+
37
+ object.rotation.x = this.input.rotationX;
38
+ object.rotation.y = this.input.rotationY;
39
+ object.rotation.z = this.input.rotationZ;
40
+
41
+ object.scale.x = this.input.scaleX;
42
+ object.scale.y = this.input.scaleY;
43
+ object.scale.z = this.input.scaleY;
44
+ }
45
+
46
+ this.output.dynamicUpdate = dynamicUpdate;
47
+ }
48
+ }
@@ -0,0 +1,26 @@
1
+ import Dbm from "../../../../index.js";
2
+
3
+ export {default as UpdateObjectPosition} from "./UpdateObjectPosition.js";
4
+
5
+ export const updateObjectPosition = function(aObject, aX = 0, aY = 0, aZ = 0, aRotationX = 0, aRotationY = 0, aRotationZ = 0, aScaleX = 1, aScaleY = 1, aScaleZ = 1) {
6
+ let newUpdateObjectPosition = new Dbm.flow.updatefunctions.thirdparty.threejs.UpdateObjectPosition();
7
+
8
+ let inputProperties = newUpdateObjectPosition.input.properties;
9
+ inputProperties.object.setOrConnect(aObject);
10
+
11
+ inputProperties.x.setOrConnect(aX);
12
+ inputProperties.y.setOrConnect(aY);
13
+ inputProperties.z.setOrConnect(aZ);
14
+
15
+ inputProperties.rotationX.setOrConnect(aRotationX);
16
+ inputProperties.rotationY.setOrConnect(aRotationY);
17
+ inputProperties.rotationZ.setOrConnect(aRotationZ);
18
+
19
+ inputProperties.scaleX.setOrConnect(aScaleX);
20
+ inputProperties.scaleY.setOrConnect(aScaleY);
21
+ inputProperties.scaleZ.setOrConnect(aScaleZ);
22
+
23
+ newUpdateObjectPosition.output.properties.dynamicUpdate.startUpdating();
24
+
25
+ return newUpdateObjectPosition;
26
+ }
@@ -6,6 +6,8 @@ export default class ApiConnection extends Dbm.core.BaseObject {
6
6
 
7
7
  this._url = null;
8
8
  this._setupItemResponseBound = this._setupItemResponse.bind(this);
9
+ this._setupItemsResponseBound = this._setupItemsResponse.bind(this);
10
+ this._setupDataResponseBound = this._setupDataResponse.bind(this);
9
11
  }
10
12
 
11
13
  setup(aUrl) {
@@ -26,7 +28,32 @@ export default class ApiConnection extends Dbm.core.BaseObject {
26
28
 
27
29
  requestRange(aSelect, aEncode) {
28
30
  let item = this._getRequestItem();
31
+
32
+ let selectArray = [];
33
+ let encodeString = aEncode.join(",");
34
+ let parametersArray = [];
35
+
36
+ {
37
+ let currentArray = aSelect;
38
+ let currentArrayLength = currentArray.length;
39
+ for(let i = 0; i < currentArrayLength; i++) {
40
+ let currentSelect = currentArray[i];
41
+ selectArray.push(currentSelect.type);
42
+
43
+ for(let objectName in currentSelect) {
44
+ if(objectName !== "type") {
45
+ parametersArray.push(objectName + "=" + encodeURIComponent(currentSelect[objectName]));
46
+ }
47
+ }
48
+ }
49
+ }
29
50
 
51
+ let fullUrl = this._url + "range/" + selectArray.join(",") + "/" + encodeString + "?" + parametersArray.join("&");
52
+ fetch(fullUrl).then((aRequest) => {
53
+ return aRequest.json();
54
+ }).then((aData) => {
55
+ this._setupItemsResponseBound(item, aData);
56
+ });
30
57
 
31
58
  return item;
32
59
  }
@@ -34,17 +61,41 @@ export default class ApiConnection extends Dbm.core.BaseObject {
34
61
  requestItem(aId, aEncode) {
35
62
  let item = this._getRequestItem();
36
63
 
64
+ let encodeString = aEncode.join(",");
65
+
66
+ let fullUrl = this._url + "item/" + aId + "/" + encodeString;
67
+ fetch(fullUrl).then((aRequest) => {
68
+ return aRequest.json();
69
+ }).then((aData) => {
70
+ this._setupItemResponseBound(item, aData);
71
+ });
37
72
 
38
73
  return item;
39
74
  }
40
75
 
41
76
  requestData(aFunctionName, aData) {
42
77
  let item = this._getRequestItem();
78
+
79
+ let parametersArray = [];
80
+
81
+ for(let objectName in aData) {
82
+ if(objectName !== "type") {
83
+ parametersArray.push(objectName + "=" + encodeURIComponent(aData[objectName]));
84
+ }
85
+ }
43
86
 
87
+ let fullUrl = this._url + "data/" + aFunctionName + "?" + parametersArray.join("&");
88
+ fetch(fullUrl).then((aRequest) => {
89
+ return aRequest.json();
90
+ }).then((aData) => {
91
+ this._setupDataResponseBound(item, aData);
92
+ });
44
93
 
45
94
  return item;
46
95
  }
47
96
 
97
+ //METODO: action
98
+
48
99
  createItem(aTypes, aVisibility = "draft", aChanges = [], aEncode = []) {
49
100
  let item = this._getRequestItem();
50
101
 
@@ -76,6 +127,22 @@ export default class ApiConnection extends Dbm.core.BaseObject {
76
127
  }
77
128
  }
78
129
  }
130
+
131
+ _setupItemsResponse(aRequestItem, aData) {
132
+ this._updateObjects(aData.objects);
133
+
134
+ let repository = Dbm.getInstance().repository;
135
+
136
+ let ids = aData.data.ids;
137
+ if(ids) {
138
+ aRequestItem.setValue("items", repository.getItems(ids));
139
+ }
140
+ else {
141
+ aRequestItem.setValue("items", []);
142
+ }
143
+
144
+ aRequestItem.status = 1;
145
+ }
79
146
 
80
147
  _setupItemResponse(aRequestItem, aData) {
81
148
  this._updateObjects(aData.objects);
@@ -93,6 +160,20 @@ export default class ApiConnection extends Dbm.core.BaseObject {
93
160
  aRequestItem.status = 1;
94
161
  }
95
162
 
163
+ _setupDataResponse(aRequestItem, aData) {
164
+ this._updateObjects(aData.objects);
165
+
166
+ let data = aData.data;
167
+ if(data) {
168
+ aRequestItem.setValue("data", data);
169
+ }
170
+ else {
171
+ aRequestItem.setValue("data", null);
172
+ }
173
+
174
+ aRequestItem.status = 1;
175
+ }
176
+
96
177
  requestUrl(aUrl) {
97
178
 
98
179
  let item = this._getRequestItem();
@@ -0,0 +1,107 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export default class CachedRequests extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+
7
+ this._ranges = {};
8
+ this._items = {};
9
+ this._data = {};
10
+ }
11
+
12
+ _getRangeIdentifier(aSelect, aEncode) {
13
+ let selects = [];
14
+ let paramters = [];
15
+
16
+ {
17
+ let currentArray = aSelect;
18
+ let currentArrayLength = currentArray.length;
19
+ for(let i = 0; i < currentArrayLength; i++) {
20
+ let currentSelect = currentArray[i];
21
+ selects.push(currentSelect.type);
22
+
23
+ for(let objectName in currentSelect) {
24
+ if(objectName !== "type") {
25
+ paramters.push(objectName + "=" + encodeURIComponent(currentSelect[objectName]));
26
+ }
27
+ }
28
+ }
29
+ }
30
+
31
+ selects.sort();
32
+ paramters.sort();
33
+
34
+ let returnString = selects.join(",") + "/" + this._getEncodeIdentifier(aEncode) + "?" + paramters.join("&");
35
+
36
+ return returnString;
37
+ }
38
+
39
+ _getEncodeIdentifier(aEncode) {
40
+ let encodes = [].concat(aEncode).sort();
41
+ return encodes.join(",");
42
+ }
43
+
44
+ requestRange(aSelect, aEncode) {
45
+ console.log("requestRange");
46
+
47
+ let id = this._getRangeIdentifier(aSelect, aEncode);
48
+ console.log(id);
49
+
50
+ if(this._ranges[id]) {
51
+ return this._ranges[id];
52
+ }
53
+
54
+ let graphApi = Dbm.getInstance().repository.getItem("graphApi").controller;
55
+ let request = graphApi.requestRange(aSelect, aEncode);
56
+
57
+ this._ranges[id] = request;
58
+ return request;
59
+ }
60
+
61
+ requestItem(aId, aEncode) {
62
+ console.log("requestItem");
63
+
64
+ let id = aId + "/" + this._getEncodeIdentifier(aEncode);
65
+ console.log(id);
66
+
67
+ if(this._items[id]) {
68
+ return this._items[id];
69
+ }
70
+
71
+ let graphApi = Dbm.getInstance().repository.getItem("graphApi").controller;
72
+ let request = graphApi.requestItem(aId, aEncode);
73
+
74
+ this._items[id] = request;
75
+ return request;
76
+ }
77
+
78
+ requestData(aFunctionName, aData) {
79
+ let paramters = [];
80
+ for(let objectName in aData) {
81
+ if(objectName !== "type") {
82
+ paramters.push(objectName + "=" + encodeURIComponent(aData[objectName]));
83
+ }
84
+ }
85
+
86
+ paramters.sort();
87
+
88
+ let id = aFunctionName + "?" + paramters.join("&");
89
+ console.log(">>>>>>>>>", id);
90
+
91
+ if(this._data[id]) {
92
+ return this._data[id];
93
+ }
94
+
95
+ let graphApi = Dbm.getInstance().repository.getItem("graphApi").controller;
96
+ let request = graphApi.requestData(aFunctionName, aData);
97
+
98
+ this._data[id] = request;
99
+ return request;
100
+ }
101
+
102
+ requestUrl(aUrl) {
103
+ //console.log("requestUrl");
104
+ //console.log(aUrl);
105
+
106
+ }
107
+ }
@@ -21,15 +21,31 @@ export default class GraphApi extends Dbm.core.BaseObject {
21
21
  }
22
22
 
23
23
  requestRange(aSelect, aEncode) {
24
- return this._websocketConnection.requestRange(aSelect, aEncode);
24
+ console.log("requestRange");
25
+
26
+ if(this._websocketConnection && this._websocketConnection.item.status === 1) {
27
+ return this._websocketConnection.requestRange(aSelect, aEncode);
28
+ }
29
+
30
+ return this._apiConnection.requestRange(aSelect, aEncode);
25
31
  }
26
32
 
27
33
  requestItem(aId, aEncode) {
28
- return this._websocketConnection.requestItem(aId, aEncode);
34
+ console.log("requestItem");
35
+
36
+ if(this._websocketConnection && this._websocketConnection.item.status === 1) {
37
+ return this._websocketConnection.requestItem(aId, aEncode);
38
+ }
39
+
40
+ return this._apiConnection.requestItem(aId, aEncode);
29
41
  }
30
42
 
31
43
  requestData(aFunctionName, aData) {
32
- return this._websocketConnection.requestData(aFunctionName, aData);
44
+ if(this._websocketConnection && this._websocketConnection.item.status === 1) {
45
+ return this._websocketConnection.requestData(aFunctionName, aData);
46
+ }
47
+
48
+ return this._apiConnection.requestData(aFunctionName, aData);
33
49
  }
34
50
 
35
51
  performAction(aFunctionName, aData) {
@@ -6,6 +6,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
6
6
 
7
7
  this._url = null;
8
8
  this._webSocket = null;
9
+ this._reconnectIfDisconnected = false;
9
10
 
10
11
  this._intervalId = -1;
11
12
  this._callback_onOpenBound = this._callback_onOpen.bind(this);
@@ -28,8 +29,16 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
28
29
 
29
30
  _connect() {
30
31
  if(this.item.status === 0) {
31
- this._webSocket = new WebSocket(this._url);
32
- this.item.setValue("status", 2);
32
+ this.item.setValue("status", 2);
33
+ try{
34
+ this._webSocket = new WebSocket(this._url);
35
+ }
36
+ catch(theError) {
37
+ this._webSocket = null;;
38
+ this.item.setValue("status", 0);
39
+ return;
40
+ }
41
+
33
42
 
34
43
  this._webSocket.onopen = this._callback_onOpenBound;
35
44
  this._webSocket.onmessage = this._callback_onMessageBound;
@@ -65,6 +74,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
65
74
  requestRange(aSelect, aEncode) {
66
75
  let item = this._getRequestItem();
67
76
  item.setValue("requestData", {"type": "range", "select": aSelect, "encode": aEncode, "requestId": item.id});
77
+ item.requireProperty("items", []);
68
78
  this._runRequest(item);
69
79
 
70
80
  return item;
@@ -127,6 +137,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
127
137
  if(this._intervalId === -1) {
128
138
  this._intervalId = setInterval(this._callback_sendHeartbeatBound, 20*1000);
129
139
  }
140
+ this._reconnectIfDisconnected = true;
130
141
  }
131
142
 
132
143
  _callback_onClose(aEvent) {
@@ -148,13 +159,19 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
148
159
  }
149
160
 
150
161
  this.item.setValue("status", 0);
151
- this._connect();;
162
+
163
+ if(this._reconnectIfDisconnected) {
164
+ this._connect();
165
+ }
152
166
  }
153
167
 
154
168
  _callback_onError(aEvent) {
155
- console.log("_callback_onError");
156
- console.log(aEvent);
169
+ //console.log("_callback_onError");
170
+ //console.log(aEvent);
157
171
 
172
+ if(this._reconnectIfDisconnected) {
173
+ console.log(aEvent);;
174
+ }
158
175
  //MENOTE: do nothing
159
176
  }
160
177
 
@@ -41,7 +41,12 @@ export default class DecodeBaseObject extends Dbm.core.BaseObject {
41
41
  for(let i = 0; i < currentArrayLength; i++) {
42
42
  let currentField = currentArray[i];
43
43
  let currentIds = aData[currentField];
44
- aItem.setValue(currentField, Dbm.getInstance().repository.getItems(currentIds));
44
+ if(currentIds) {
45
+ aItem.setValue(currentField, Dbm.getInstance().repository.getItems(currentIds));
46
+ }
47
+ else {
48
+ aItem.setValue(currentField, []);
49
+ }
45
50
  }
46
51
  }
47
52
  }
@@ -63,6 +63,14 @@ export const fullSetup = function() {
63
63
  currentDecoder.item.register(decodePrefix + name);
64
64
  }
65
65
 
66
+ {
67
+ let name = "pageRepresentation";
68
+ let currentDecoder = new Dbm.graphapi.webclient.decode.DecodeBaseObject();
69
+ currentDecoder.item.setValue("copyLink", ["representing"]);
70
+ currentDecoder.item.setValue("encodingType", name);
71
+ currentDecoder.item.register(decodePrefix + name);
72
+ }
73
+
66
74
  {
67
75
  let name = "navigationName";
68
76
  let currentDecoder = new Dbm.graphapi.webclient.decode.DecodeBaseObject();
@@ -101,4 +109,12 @@ export const fullSetup = function() {
101
109
  currentDecoder.item.setValue("encodingType", name);
102
110
  currentDecoder.item.register(decodePrefix + name);
103
111
  }
112
+
113
+ {
114
+ let name = "representingPage";
115
+ let currentDecoder = new Dbm.graphapi.webclient.decode.DecodeBaseObject();
116
+ currentDecoder.item.setValue("copyLink", ["representingPage"]);
117
+ currentDecoder.item.setValue("encodingType", name);
118
+ currentDecoder.item.register(decodePrefix + name);
119
+ }
104
120
  }
@@ -5,6 +5,7 @@ export {default as WebSocketRequest} from "./WebSocketRequest.js";
5
5
  export {default as GraphApi} from "./GraphApi.js";
6
6
  export {default as ApiConnection} from "./ApiConnection.js";
7
7
  export {default as ApiRequest} from "./ApiRequest.js";
8
+ export {default as CachedRequests} from "./CachedRequests.js";
8
9
 
9
10
  export * as decode from "./decode/index.js";
10
11
  export * as admin from "./admin/index.js";
@@ -20,4 +21,7 @@ export const setup = function(aWsPath, aApiPath) {
20
21
  graphApi.setWebsocketConnection(webSocketConnection);
21
22
  graphApi.setApiConnection(apiConnection);
22
23
  graphApi.item.register("graphApi");
24
+
25
+ let cachedRequests = new Dbm.graphapi.webclient.CachedRequests();
26
+ cachedRequests.item.register("cachedGraphApi");
23
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbm",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {},
@@ -98,6 +98,16 @@ export default class BaseObject extends Component {
98
98
  return currentProp;
99
99
  }
100
100
 
101
+ getPropValueWithDefault(aName, aDefaultValue) {
102
+ let value = this.getPropValue(aName);
103
+
104
+ if(!value) {
105
+ value = aDefaultValue;
106
+ }
107
+
108
+ return value;
109
+ }
110
+
101
111
  createRef(aName) {
102
112
  let refToProperty = this.item["ref/" + aName];
103
113
 
@@ -22,6 +22,8 @@ export default class EditPage extends Dbm.react.BaseObject {
22
22
  let descriptionEditor = itemEditor.addFieldEditor("meta/description", page["meta/description"], "meta/description");
23
23
  let descriptionLength = Dbm.flow.updatefunctions.basic.length(descriptionEditor.item.editValue.value);
24
24
  this.item.requireProperty("descriptionLength", 0).connectInput(descriptionLength.output.properties.length);
25
+
26
+ this.item.requireProperty("importText", "");
25
27
  }
26
28
 
27
29
  _save() {
@@ -37,11 +39,64 @@ export default class EditPage extends Dbm.react.BaseObject {
37
39
  itemSaveData.setField("lastModified", (new Date()).toISOString());
38
40
  itemSaveData.createChange("clearCache", {});
39
41
 
40
- console.log(editorGroup, saveData);
41
-
42
42
  saveData.save();
43
43
  }
44
44
 
45
+ _export() {
46
+ let editorGroup = this.item.editorGroup;
47
+
48
+ let page = this.context.page;
49
+ let id = page.id;
50
+ let itemEditor = editorGroup.getItemEditor(id);
51
+ let url = itemEditor.addFieldEditor("url").item.editValue.value.value;
52
+ let content = itemEditor.addFieldEditor("content").item.editValue.value.value;
53
+
54
+ let blob = new Blob([JSON.stringify(content, null, 2)], { type: 'application/json' });
55
+ let downloadUrl = URL.createObjectURL(blob);
56
+
57
+ let fileName = id + Dbm.utils.StringFunctions.createNiceFilePath(url) + ".json";
58
+ let a = document.createElement('a');
59
+ a.href = downloadUrl;
60
+ a.download = fileName;
61
+ document.body.appendChild(a);
62
+ a.click();
63
+
64
+ document.body.removeChild(a);
65
+ URL.revokeObjectURL(downloadUrl);
66
+ }
67
+
68
+ _import() {
69
+
70
+ let editorGroup = this.item.editorGroup;
71
+
72
+ let page = this.context.page;
73
+ let id = page.id;
74
+ let itemEditor = editorGroup.getItemEditor(id);
75
+
76
+
77
+ let data = JSON.parse(this.item.importText);
78
+ console.log(data);
79
+
80
+ let newContent = {...itemEditor.addFieldEditor("content").item.editValue.value.value};
81
+ if(!newContent) {
82
+ newContent = {};
83
+ }
84
+ if(!newContent.blocks) {
85
+ newContent.blocks = [];
86
+ }
87
+
88
+ let currentArray = data.blocks;
89
+ let currentArrayLength = currentArray.length;
90
+ for(let i = 0; i < currentArrayLength; i++) {
91
+ let currentBlock = currentArray[i];
92
+ delete currentBlock["id"];
93
+ newContent.blocks.push(currentBlock);
94
+ }
95
+
96
+ itemEditor.addFieldEditor("content").item.editValue.value.value = newContent;
97
+ this.item.editor.contentUpdatedExternally();
98
+ }
99
+
45
100
  _generateSeoSummary() {
46
101
 
47
102
  let page = this.context.page;
@@ -122,7 +177,15 @@ export default class EditPage extends Dbm.react.BaseObject {
122
177
  "Content"
123
178
  ),
124
179
  React.createElement("div", {},
125
- React.createElement(Dbm.react.admin.editor.Editor, {"value": itemEditor.getEditor("content").item.editValue.value}),
180
+ React.createElement(Dbm.react.admin.editor.Editor, {"value": itemEditor.getEditor("content").item.editValue.value, "ref": this.createRef("editor")}),
181
+ ),
182
+ React.createElement("div", {className: "spacing small"}),
183
+ React.createElement("div", {"className": "standard-button standard-button-padding", "onClick": () => {this._export()}},
184
+ "Export"
185
+ ),
186
+ React.createElement(Dbm.react.form.FormField, {value: this.item.properties.importText}),
187
+ React.createElement("div", {"className": "standard-button standard-button-padding", "onClick": () => {this._import()}},
188
+ "Import"
126
189
  )
127
190
  ),
128
191
  React.createElement("div", {className: "spacing standard"}),
@@ -153,6 +153,14 @@ export default class Editor extends Dbm.react.BaseObject {
153
153
  }
154
154
  }
155
155
 
156
+ contentUpdatedExternally() {
157
+
158
+ let data = this.getDynamicProp("value").value;
159
+ this.item.editor.render(data);
160
+
161
+ return this;
162
+ }
163
+
156
164
  /*
157
165
  _save() {
158
166
  this.item.editor.save().then((aOutputData) => {
@@ -0,0 +1,57 @@
1
+ import React from "react";
2
+ import Dbm from "../../../../index.js";
3
+
4
+ export default class SelectObjectField extends Dbm.react.BaseObject {
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this._valueChangedBound = this._valueChanged.bind(this);
9
+ this._objectChangedBound = this._objectChanged.bind(this);
10
+
11
+ Dbm.flow.addUpdateCommand(this.item.requireProperty("value", this._getObjectData()), Dbm.commands.callFunction(this._valueChangedBound));
12
+
13
+ let editorData = Dbm.objectPath(this.context, "moduleData.editorData");
14
+ Dbm.flow.addUpdateCommand(editorData.properties.data, Dbm.commands.callFunction(this._objectChangedBound));
15
+ }
16
+
17
+ _getObjectData() {
18
+ let fieldName = this.getPropValue("name");
19
+
20
+ let editorData = Dbm.objectPath(this.context, "moduleData.editorData");
21
+
22
+ console.log(">>>>>", editorData);
23
+
24
+ let returnData = editorData.data[fieldName];
25
+ if(!returnData) {
26
+ returnData = 0;
27
+ }
28
+
29
+ return returnData;
30
+ }
31
+
32
+
33
+ _valueChanged() {
34
+ //console.log("_valueChanged");
35
+
36
+ let fieldName = this.getPropValue("name");
37
+ let newValue = this.item.value;
38
+ let editorData = Dbm.objectPath(this.context, "moduleData.editorData");
39
+
40
+ let newData = {...editorData.data};
41
+ newData[fieldName] = newValue;
42
+
43
+ editorData.data = newData;
44
+
45
+ this.context.moduleData.editorData.editorBlock.dataUpdated();
46
+ }
47
+
48
+ _objectChanged() {
49
+ //console.log("_objectChanged");
50
+
51
+ this.item.value = this._getObjectData();
52
+ }
53
+
54
+ _renderMainElement() {
55
+ return this._createMainElement(Dbm.react.form.GraphApiObjectSelection, {value: this.item.properties.value, objectType: this.getPropValue("objectType"), className: "standard-field standard-field-padding full-width"});
56
+ }
57
+ }
@@ -1,4 +1,5 @@
1
1
  export {default as TextField} from "./TextField.js";
2
2
  export {default as RichTextField} from "./RichTextField.js";
3
3
  export {default as ImageField} from "./ImageField.js";
4
- export {default as CheckboxField} from "./CheckboxField.js";
4
+ export {default as CheckboxField} from "./CheckboxField.js";
5
+ export {default as SelectObjectField} from "./SelectObjectField.js";
@@ -27,6 +27,10 @@ export default class List extends Dbm.react.BaseObject {
27
27
  let mainChildren = slots.main;
28
28
 
29
29
  let currentArray = items;
30
+ if(!currentArray || isNaN(currentArray.length)) {
31
+ console.error("Items is not an array", this);
32
+ return null;
33
+ }
30
34
  let currentArrayLength = currentArray.length;
31
35
  let newChildren = [];
32
36
  for(let i = 0; i < currentArrayLength; i++) {
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+ import Dbm from "../../index.js";
3
+
4
+ export default class AddItemToContext extends Dbm.react.BaseObject {
5
+ _construct() {
6
+ super._construct();
7
+ }
8
+
9
+ render() {
10
+
11
+ let item = this.getPropValue("item");
12
+ let id = Dbm.objectPath(item, "id");
13
+
14
+ let as = this.getPropValue("as");
15
+ if(!as) {
16
+ as = "item";
17
+ }
18
+
19
+ let values = {};
20
+ values[as] = item;
21
+
22
+ return React.createElement(Dbm.react.context.AddContextVariables, {"values": values, "key": id}, this.props.children);
23
+ }
24
+ }
@@ -1,2 +1,3 @@
1
1
  export {default as Context} from "./Context.js";
2
- export {default as AddContextVariables} from "./AddContextVariables.js";
2
+ export {default as AddContextVariables} from "./AddContextVariables.js";
3
+ export {default as AddItemToContext} from "./AddItemToContext.js";
@@ -6,7 +6,24 @@ export default class CookieBar extends Dbm.react.BaseObject {
6
6
  _construct() {
7
7
  super._construct();
8
8
 
9
- this.getDynamicProp("open", false);
9
+ let openProperty = this.getDynamicProp("open", false);
10
+ this.item.requireProperty("envelope", 0);
11
+
12
+ let stateToEnvelope = Dbm.flow.updatefunctions.logic.switchValue(openProperty).setDefaultValue(100).addCase(true, 0);
13
+ let inDomCase = Dbm.flow.updatefunctions.logic.switchValue(this.item.properties.envelope).setDefaultValue(true).addCase(100, false);
14
+
15
+ this.item.requireProperty("inDom", false).connectInput(inDomCase.output.properties.value);
16
+
17
+ let animation = new Dbm.flow.animateValue(stateToEnvelope.output.properties.value);
18
+
19
+ this.item.properties.envelope.connectInput(animation.properties.output);
20
+
21
+ let transform = new Dbm.flow.updatefunctions.dom.TransformStyle();
22
+ transform.translateY(animation.properties.output, "%");
23
+
24
+ let style = new Dbm.flow.updatefunctions.dom.StyleObject();
25
+ style.addProperty("transform", transform.output.properties.value);
26
+ this.item.requireProperty("style", null).connectInput(style.output.properties.style);
10
27
 
11
28
  let shouldShow = Cookies.get("cookie/hideCookieBar") !== "1";
12
29
 
@@ -108,10 +125,25 @@ export default class CookieBar extends Dbm.react.BaseObject {
108
125
  this.item.properties.element.connectInput(layoutSwitch.output.properties.value);
109
126
  }
110
127
 
128
+ _getDomain() {
129
+
130
+ let parts = document.location.hostname.split('.');
131
+
132
+ let length = parts.length;
133
+ if (length === 1) {
134
+ return parts[0];
135
+ }
136
+ else if(parts[length-2] === "co" && parts[length-1] === "uk") {
137
+ return '.' + parts.slice(-3).join('.');
138
+ }
139
+
140
+ return '.' + parts.slice(-2).join('.');
141
+ }
142
+
111
143
  _acceptAll() {
112
144
  console.log("_acceptAll");
113
145
 
114
- let options = {"expires": 365};
146
+ let options = {"expires": 365, "domain": this._getDomain()};
115
147
 
116
148
  Cookies.set("cookie/allowPreferences", "1", options);
117
149
  Cookies.set("cookie/allowStatistics", "1", options);
@@ -120,7 +152,7 @@ export default class CookieBar extends Dbm.react.BaseObject {
120
152
 
121
153
  let consentTime = (new Date()).toISOString();
122
154
 
123
- Cookies.set("cookie/consentTime", consentTime);
155
+ Cookies.set("cookie/consentTime", consentTime, options);
124
156
 
125
157
  Dbm.getInstance().repository.getItem("trackingController").allowStatistics = true;
126
158
  Dbm.getInstance().repository.getItem("trackingController").allowMarketing = true;
@@ -130,7 +162,7 @@ export default class CookieBar extends Dbm.react.BaseObject {
130
162
 
131
163
  _rejectAll() {
132
164
 
133
- let options = {"expires": 365};
165
+ let options = {"expires": 365, "domain": this._getDomain()};
134
166
 
135
167
  Cookies.set("cookie/allowPreferences", "0", options);
136
168
  Cookies.set("cookie/allowStatistics", "0", options);
@@ -139,7 +171,7 @@ export default class CookieBar extends Dbm.react.BaseObject {
139
171
 
140
172
  let consentTime = (new Date()).toISOString();
141
173
 
142
- Cookies.set("cookie/consentTime", consentTime);
174
+ Cookies.set("cookie/consentTime", consentTime, options);
143
175
 
144
176
  Dbm.getInstance().repository.getItem("trackingController").allowStatistics = false;
145
177
  Dbm.getInstance().repository.getItem("trackingController").allowMarketing = false;
@@ -149,10 +181,16 @@ export default class CookieBar extends Dbm.react.BaseObject {
149
181
 
150
182
  _renderMainElement() {
151
183
 
152
- return this._createMainElement("div", {className: "cookie-bar-position", ref: this.createRef("widthElement")},
153
- React.createElement(Dbm.react.area.OpenCloseExpandableArea, {open: this.getDynamicProp("open")},
154
- React.createElement(Dbm.react.area.InsertElement, {element: this.item.properties.element})
155
- )
184
+ return this._createMainElement("div", {className: "cookie-bar-position no-pointer-events", ref: this.createRef("widthElement")},
185
+ React.createElement(Dbm.react.area.HasData, {"check": this.item.properties.inDom},
186
+ React.createElement("div", {className: "overflow-hidden"},
187
+ React.createElement(Dbm.react.BaseObject, {style: this.item.properties.style},
188
+ React.createElement("div", {className: "all-pointer-events"},
189
+ React.createElement(Dbm.react.area.InsertElement, {element: this.item.properties.element})
190
+ )
191
+ )
192
+ )
193
+ )
156
194
  );
157
195
  }
158
196
  }
@@ -59,11 +59,26 @@ export default class CookieSettings extends Dbm.react.BaseObject {
59
59
  return currentItem;
60
60
  }
61
61
 
62
+ _getDomain() {
63
+
64
+ let parts = document.location.hostname.split('.');
65
+
66
+ let length = parts.length;
67
+ if (length === 1) {
68
+ return parts[0];
69
+ }
70
+ else if(parts[length-2] === "co" && parts[length-1] === "uk") {
71
+ return '.' + parts.slice(-3).join('.');
72
+ }
73
+
74
+ return '.' + parts.slice(-2).join('.');
75
+ }
76
+
62
77
  _save() {
63
78
  console.log("_save");
64
79
 
65
80
  let settings = this.item.settings;
66
- let options = {"expires": 365};
81
+ let options = {"expires": 365, "domain": this._getDomain()};
67
82
 
68
83
  let currentArray = settings;
69
84
  let currentArrayLength = currentArray.length;
@@ -85,8 +100,8 @@ export default class CookieSettings extends Dbm.react.BaseObject {
85
100
 
86
101
  let consentTime = (new Date()).toISOString();
87
102
 
88
- Cookies.set("cookie/consentTime", consentTime)
89
- this.item.setValue("consentTime", consentTime, options);
103
+ Cookies.set("cookie/consentTime", consentTime, options);
104
+ this.item.setValue("consentTime", consentTime);
90
105
  }
91
106
 
92
107
  _renderMainElement() {
@@ -0,0 +1,53 @@
1
+ import React from "react";
2
+ import Dbm from "../../index.js";
3
+
4
+ export default class GraphApiObjectSelection extends Dbm.react.form.Selection {
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.getDynamicProp("value", "");
9
+ this.item.requireProperty("items", []);
10
+
11
+ let objectType = this.getPropValue("objectType")
12
+
13
+ let graphApi = Dbm.getInstance().repository.getItem("graphApi").controller;
14
+ {
15
+ let request = graphApi.requestRange(
16
+ [
17
+ {"type": "byObjectType", "objectType": objectType},
18
+ {"type": "includeDraft"},
19
+ {"type": "includePrivate"}
20
+ ],
21
+ ["name"]
22
+ );
23
+
24
+
25
+ Dbm.flow.addUpdateCommandWhenMatched(request.properties.status, Dbm.loading.LoadingStatus.LOADED, Dbm.commands.callFunction(this._itemsLoaded.bind(this), [request]));
26
+ }
27
+ }
28
+
29
+ _itemsLoaded(aRequest) {
30
+ let options = [];
31
+
32
+ options.push(React.createElement("option", {key: 0, value: 0}, "None"));
33
+
34
+ let currentArray = [].concat(aRequest.items);
35
+ Dbm.utils.ArrayFunctions.sortOnField(currentArray, "name");
36
+
37
+ let currentArrayLength = currentArray.length;
38
+ for(let i = 0; i < currentArrayLength; i++) {
39
+ let currentItem = currentArray[i];
40
+ options.push(React.createElement("option", {key: currentItem["id"], value: currentItem["id"]}, currentItem["name"] + " (id: " + currentItem["id"] + ")"));
41
+ }
42
+
43
+ this.item.items = options;
44
+ }
45
+
46
+ _renderMainElement() {
47
+
48
+ let value = this.getDynamicProp("value");
49
+
50
+ return this._createMainElement(Dbm.react.form.Selection, {"value": value}, this.item.properties.items);
51
+ }
52
+ }
53
+
@@ -0,0 +1,29 @@
1
+ import React from "react";
2
+ import Dbm from "../../index.js";
3
+
4
+ export default class Selection extends Dbm.react.BaseObject {
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.getDynamicProp("value", "");
9
+
10
+ this._callback_changeBound = this._callback_change.bind(this);
11
+ }
12
+
13
+ _callback_change(aEvent) {
14
+ //console.log("_callback_change");
15
+ //console.log(aEvent);
16
+
17
+ let value = aEvent.target.value;
18
+
19
+ this.getDynamicProp("value").getMostUpstreamProperty().setValue(value);
20
+ }
21
+
22
+ _renderMainElement() {
23
+
24
+ let value = this.getDynamicProp("value").value;
25
+
26
+ return this._createMainElement("select", {"value": value, onChange: this._callback_changeBound}, this.getPropValue("children"));
27
+ }
28
+ }
29
+
@@ -1,4 +1,6 @@
1
1
  export {default as Checkbox} from "./Checkbox.js";
2
2
  export {default as FormField} from "./FormField.js";
3
3
  export {default as LabelledArea} from "./LabelledArea.js";
4
- export {default as FileDropArea} from "./FileDropArea.js";
4
+ export {default as FileDropArea} from "./FileDropArea.js";
5
+ export {default as Selection} from "./Selection.js";
6
+ export {default as GraphApiObjectSelection} from "./GraphApiObjectSelection.js";
@@ -3,6 +3,9 @@ import Dbm from "../index.js";
3
3
  export default class DataLayerTracker extends Dbm.core.BaseObject {
4
4
  _construct() {
5
5
  super._construct();
6
+
7
+ this._statisticsTracking = false;
8
+ this._marketingTracking = false;
6
9
  }
7
10
 
8
11
  addToDataLayer(aData) {
@@ -35,6 +38,7 @@ export default class DataLayerTracker extends Dbm.core.BaseObject {
35
38
 
36
39
  startStatisticsTracking() {
37
40
 
41
+ this._statisticsTracking = true;
38
42
  this._gtag("consent", "update", {
39
43
  "analytics_storage": "granted"
40
44
  });
@@ -46,6 +50,7 @@ export default class DataLayerTracker extends Dbm.core.BaseObject {
46
50
 
47
51
  startMarketingTracking() {
48
52
 
53
+ this._marketingTracking = true;
49
54
  this._gtag("consent", "update", {
50
55
  "ad_storage": "granted",
51
56
  "ad_user_data": "granted",
@@ -66,8 +71,15 @@ export default class DataLayerTracker extends Dbm.core.BaseObject {
66
71
  console.log("trackEvent");
67
72
  console.log(aEventName, aData);
68
73
 
69
- this.addToDataLayer({"event": "trackEvent", "value": {"name": aEventName, "data": aData}});
70
- this._gtag("event", aEventName, aData);
74
+ if(this._statisticsTracking) {
75
+ this.addToDataLayer({"event": "trackEvent", "value": {"name": aEventName, "data": aData}});
76
+ this._gtag("event", aEventName, aData);
77
+ }
78
+
79
+ if(this._marketingTracking) {
80
+ this.addToDataLayer({"event": "trackMarketingEvent", "value": {"name": aEventName, "data": aData}});
81
+ this._gtag("event", "Marketing / " + aEventName, aData);
82
+ }
71
83
  }
72
84
 
73
85
  trackCurrentPage() {
@@ -117,6 +117,17 @@ export const arrayOrSeparatedString = function(aData, aSeparator = ",", aTrim =
117
117
  return [];
118
118
  }
119
119
 
120
+ export const numericArrayOrSeparatedString = function(aData, aSeparator = ",", aTrim = 3) {
121
+ let returnArray = new Array();
122
+ let currentArray = arrayOrSeparatedString(aData, aSeparator, aTrim);
123
+ let currentarrayLength = currentArray.length;
124
+ for(let i = 0; i < currentarrayLength; i++) {
125
+ returnArray.push(parseFloat(currentArray[i]));
126
+ }
127
+
128
+ return returnArray;
129
+ }
130
+
120
131
  export const filterByField = function(aArray, aField, aValue) {
121
132
  let returnArray = [];
122
133
 
@@ -144,4 +155,117 @@ export const mapField = function(aArray, aField) {
144
155
  }
145
156
 
146
157
  return returnArray;
158
+ }
159
+
160
+ export const group = function(aArray, aField) {
161
+
162
+ let groups = new Map();
163
+
164
+ let currentArray = aArray;
165
+ let currentArrayLength = currentArray.length;
166
+ for(let i = 0; i < currentArrayLength; i++) {
167
+ let currentObject = aArray[i];
168
+ let groupValue = Dbm.objectPath(aArray[i], aField);
169
+
170
+ if(!groups.has(groupValue)) {
171
+ groups.set(groupValue, []);
172
+ }
173
+
174
+ groups.get(groupValue).push(currentObject);
175
+ }
176
+
177
+ let returnArray = [];
178
+
179
+ for (const value of groups.entries()) {
180
+ returnArray.push({"key": value[0], "value": value[1]});
181
+ }
182
+
183
+ return returnArray;
184
+ }
185
+
186
+ export const makeFlat = function(aArray) {
187
+ let returnArray = [];
188
+
189
+ let currentArray = aArray;
190
+ let currentArrayLength = currentArray.length;
191
+ for(let i = 0; i < currentArrayLength; i++) {
192
+ returnArray = returnArray.concat(currentArray[i]);
193
+ }
194
+
195
+ return returnArray;
196
+ }
197
+
198
+ export const getUnselectedItems = function(aSelectedItems, aAllItems) {
199
+ let returnItems = new Array();
200
+
201
+ let currentArray = aAllItems;
202
+ let currentArrayLength = currentArray.length;
203
+ for(let i = 0; i < currentArrayLength; i++) {
204
+ let currentItem = currentArray[i];
205
+ if(aSelectedItems.indexOf(currentItem) === -1) {
206
+ returnItems.push(currentItem);
207
+ }
208
+ }
209
+
210
+ return returnItems;
211
+ }
212
+
213
+ export const sortOnField = function(aArray, aField) {
214
+ let sortFunction = function(aA, aB) {
215
+ let aValue = Dbm.objectPath(aA, aField);
216
+ let bValue = Dbm.objectPath(aB, aField);
217
+
218
+ if(aValue < bValue) {
219
+ return -1;
220
+ }
221
+ else if(aValue > bValue) {
222
+ return 1;
223
+ }
224
+
225
+ return 0;
226
+ }
227
+
228
+ aArray.sort(sortFunction);
229
+
230
+ return aArray;
231
+ }
232
+
233
+ export const sortOnNumericField = function(aArray, aField) {
234
+ let sortFunction = function(aA, aB) {
235
+ let aValue = 1*Dbm.objectPath(aA, aField);
236
+ let bValue = 1*Dbm.objectPath(aB, aField);
237
+
238
+ if(aValue < bValue) {
239
+ return -1;
240
+ }
241
+ else if(aValue > bValue) {
242
+ return 1;
243
+ }
244
+
245
+ return 0;
246
+ }
247
+
248
+ aArray.sort(sortFunction);
249
+
250
+ return aArray;
251
+ }
252
+
253
+ export const getItemIndexByIfExists = function(aArray, aField, aIdentifier) {
254
+
255
+ if(!Array.isArray(aArray)) {
256
+ console.warn("No array provided", aArray);
257
+ return -1;
258
+ }
259
+
260
+ let currentArray = aArray;
261
+ let currentArrayLength = currentArray.length;
262
+ for(let i = 0; i < currentArrayLength; i++) {
263
+ let currentItem = currentArray[i];
264
+ let currentValue = Dbm.objectPath(currentItem, aField);
265
+ if(currentValue == aIdentifier) {
266
+ return i;
267
+ }
268
+ }
269
+
270
+ return -1;
147
271
  }