dbm 1.1.3 → 1.1.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/dbm.js CHANGED
@@ -57,6 +57,31 @@ export let objectPath = function(aObject, aPath) {
57
57
  return currentObject;
58
58
  }
59
59
 
60
+ export let setAtObjectPath = function(aObject, aPath, aValue) {
61
+ aPath += "";
62
+ if(aPath.length === 0) {
63
+ return 0;
64
+ }
65
+
66
+ let baseObject = aObject;
67
+ let propertyName = aPath;
68
+
69
+ let paths = aPath.split(".");
70
+ if(paths.length > 1) {
71
+ propertyName = paths.pop();
72
+
73
+ baseObject = objectPath(baseObject, paths.join("."));
74
+ }
75
+
76
+ if(baseObject) {
77
+ let partAsInt = parseInt(propertyName, 10);
78
+ if(partAsInt.toString() === propertyName) {
79
+ propertyName = partAsInt;
80
+ }
81
+ baseObject[propertyName] = aValue;
82
+ }
83
+ }
84
+
60
85
  export * as utils from "./utils/index.js";
61
86
  export * as core from "./core/index.js";
62
87
  export * as loading from "./loading/index.js";
@@ -1,2 +1,3 @@
1
1
  export * as select from "./select/index.js";
2
- export * as edit from "./edit/index.js";
2
+ export * as edit from "./edit/index.js";
3
+ export * as transform from "./transform/index.js";
@@ -0,0 +1,51 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class PartOfObject extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+
7
+ this.item.requireProperty("object", null);
8
+ this.item.requireProperty("path", null);
9
+ this.item.requireProperty("value", null);
10
+
11
+ this._lastUpdatedValue = null;
12
+
13
+ let objectUpdatedCommand = Dbm.commands.callFunction(this._objectUpdated.bind(this));
14
+ Dbm.flow.addUpdateCommand(this.item.properties.object, objectUpdatedCommand);
15
+ Dbm.flow.addUpdateCommand(this.item.properties.path, objectUpdatedCommand);
16
+
17
+ Dbm.flow.addUpdateCommand(this.item.properties.value, Dbm.commands.callFunction(this._valueUpdated.bind(this)));
18
+ }
19
+
20
+ _objectUpdated() {
21
+ console.log("_objectUpdated");
22
+
23
+ if(this.item.path !== null) {
24
+ let stringValue = JSON.stringify(Dbm.objectPath(this.item.object, this.item.path));
25
+
26
+ if(stringValue !== this._lastUpdatedValue) {
27
+ this._lastUpdatedValue = stringValue;
28
+ let newValue = JSON.parse(stringValue);
29
+ this.item.value = newValue;
30
+ }
31
+ }
32
+ }
33
+
34
+ _valueUpdated() {
35
+ console.log("_valueUpdated");
36
+
37
+ if(this.item.path !== null) {
38
+ let stringValue = JSON.stringify(this.item.value);
39
+
40
+ if(stringValue !== this._lastUpdatedValue) {
41
+ this._lastUpdatedValue = stringValue;
42
+ let object = JSON.parse(JSON.stringify(this.item.object));
43
+ Dbm.setAtObjectPath(object, this.item.path, JSON.parse(stringValue));
44
+
45
+ this.item.properties.object.getMostUpstreamProperty().value = object;
46
+ }
47
+
48
+ }
49
+
50
+ }
51
+ }
@@ -0,0 +1 @@
1
+ export {default as PartOfObject} from "./PartOfObject.js";
@@ -93,4 +93,12 @@ export const fullSetup = function() {
93
93
  currentDecoder.item.setValue("encodingType", name);
94
94
  currentDecoder.item.register(decodePrefix + name);
95
95
  }
96
+
97
+ {
98
+ let name = "visibility";
99
+ let currentDecoder = new Dbm.graphapi.webclient.decode.DecodeBaseObject();
100
+ currentDecoder.item.setValue("copyFields", ["visibility"]);
101
+ currentDecoder.item.setValue("encodingType", name);
102
+ currentDecoder.item.register(decodePrefix + name);
103
+ }
96
104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbm",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {},
@@ -2,4 +2,5 @@ export {default as CreatePage} from "./CreatePage.js";
2
2
  export {default as EditPage} from "./EditPage.js";
3
3
  export {default as SelectImageFromLibrary} from "./SelectImageFromLibrary.js";
4
4
 
5
- export * as editor from "./editor/index.js";
5
+ export * as editor from "./editor/index.js";
6
+ export * as pages from "./pages/index.js";
@@ -0,0 +1,66 @@
1
+ import React from "react";
2
+ import Dbm from "../../../index.js";
3
+
4
+ export default class PageList extends Dbm.react.BaseObject {
5
+ _construct() {
6
+ super._construct();
7
+
8
+ let graphApi = Dbm.getInstance().repository.getItem("graphApi").controller;
9
+
10
+ this.item.requireProperty("items", []);
11
+
12
+ let request = graphApi.requestRange(
13
+ [
14
+ {"type": "includePrivate"},
15
+ {"type": "includeDraft"},
16
+ {"type": "byObjectType", "objectType": "page"},
17
+ ],
18
+ ["urlRequest"]
19
+ );
20
+ Dbm.flow.addUpdateCommandWhenMatched(request.properties.status, Dbm.loading.LoadingStatus.LOADED, Dbm.commands.callFunction(this._loaded.bind(this), [request]));
21
+
22
+ }
23
+
24
+ _loaded(aRequest) {
25
+ console.log("_loaded");
26
+ console.log(aRequest);
27
+
28
+ let items = [...aRequest.items];
29
+ let field = "url";
30
+ items.sort(function(aA, aB) {
31
+
32
+ let aValue = Dbm.objectPath(aA, field);
33
+ let bValue = Dbm.objectPath(aB, field);
34
+
35
+ if(aValue < bValue) {
36
+ return -1;
37
+ }
38
+ else if(aValue < bValue) {
39
+ return 1;
40
+ }
41
+ else {
42
+ return 0;
43
+ }
44
+ });
45
+
46
+ console.log(items);
47
+
48
+ this.item.setValue("items", items);
49
+ }
50
+
51
+ _renderMainElement() {
52
+
53
+ return React.createElement("div", {"className": "centered-site"},
54
+ React.createElement(Dbm.react.area.List, {"items": this.item.properties.items},
55
+ React.createElement("div", {},
56
+ React.createElement(Dbm.react.text.Link, {"href": Dbm.react.source.contextVariable("item.url")},
57
+ Dbm.react.text.text(Dbm.react.source.contextVariable("item.url")),
58
+ " - ",
59
+ Dbm.react.text.text(Dbm.react.source.contextVariable("item.title")),
60
+ )
61
+ )
62
+ )
63
+ );
64
+ }
65
+ }
66
+
@@ -0,0 +1 @@
1
+ export {default as PageList} from "./PageList.js";
@@ -100,4 +100,5 @@ export let getDefaultEditorModule = function() {
100
100
  export let registerAllBlocks = function() {
101
101
  registerBlock("cookie/settings", "Cookie settings", createElement(Dbm.react.cookies.CookieSettings));
102
102
  registerBlock("login/loginForm", "Login form", createElement(Dbm.react.login.LoginForm));
103
+ registerBlock("admin/pageList", "Admin / Page list", createElement(Dbm.react.admin.pages.PageList), createElement(Dbm.react.admin.pages.PageList));
103
104
  }
@@ -0,0 +1,37 @@
1
+ import Dbm from "../../index.js";
2
+ import React from "react";
3
+
4
+ export default class ContainedScaledImage extends Dbm.react.BaseObject {
5
+ _construct() {
6
+ super._construct();
7
+ }
8
+
9
+ _removedUsedProps(aProps) {
10
+ delete aProps["image"];
11
+ delete aProps["targetWidth"];
12
+ delete aProps["targetHeight"];
13
+ }
14
+
15
+ _renderMainElement() {
16
+
17
+ let image = this.getPropValue("image");
18
+ let width = this.getPropValue("targetWidth");
19
+ let height = this.getPropValue("targetHeight");
20
+ let url = Dbm.utils.UrlFunctions.createContainScaledImageUrl(image, width, height);
21
+
22
+ let newProps = this._copyProps({src: url});
23
+
24
+ let altText = Dbm.objectPath(image, "altText");
25
+ if(altText) {
26
+ newProps["alt"] = altText;
27
+ }
28
+
29
+ let elementType = this.getPropValue("elementType");
30
+ if(elementType) {
31
+ newProps["elementType"] = elementType;
32
+ }
33
+
34
+ return React.createElement(Dbm.react.image.Image, newProps, this.getPropValue("children"));
35
+
36
+ }
37
+ }
@@ -1,4 +1,5 @@
1
1
  export {default as Image} from "./Image.js";
2
2
  export {default as WidthScaledImage} from "./WidthScaledImage.js";
3
3
  export {default as CoverScaledImage} from "./CoverScaledImage.js";
4
+ export {default as ContainScaledImage} from "./ContainScaledImage.js";
4
5
  export {default as LocalImage} from "./LocalImage.js";
@@ -172,7 +172,7 @@ export default class SiteNavigation extends Dbm.core.BaseObject {
172
172
  }
173
173
  }
174
174
 
175
- history.pushState({}, "Page", aUrl);
175
+ history.pushState({}, "", aUrl);
176
176
  this.item.url = aUrl;
177
177
 
178
178
  this._addUrlToPath(aUrl);
@@ -201,9 +201,13 @@ export default class SiteNavigation extends Dbm.core.BaseObject {
201
201
  }
202
202
  }
203
203
 
204
+ updateQueryString(aUrl) {
205
+ history.replaceState({}, "", aUrl);
206
+ }
207
+
204
208
  setUrlFromLocation() {
205
209
  let url = document.location.href;
206
- this.item.url = url
210
+ this.item.url = url;
207
211
 
208
212
  this._addUrlToPath(url);
209
213
 
@@ -6,6 +6,7 @@ export default class Controller extends Dbm.core.BaseObject {
6
6
  super._construct();
7
7
 
8
8
  this.item.setValue("trackers", []);
9
+ this.item.setValue("currency", "EUR");
9
10
 
10
11
  Dbm.flow.addDirectUpdateCommand(this.item.requireProperty("active", false), Dbm.commands.callFunction(this._updateActiveStatus.bind(this)));
11
12
 
@@ -154,4 +155,84 @@ export default class Controller extends Dbm.core.BaseObject {
154
155
  }
155
156
  }
156
157
  }
158
+
159
+ _getValueFromItems(aItems) {
160
+ let value = 0;
161
+
162
+ let currentArray = aItems;
163
+ let currentArrayLength = currentArray.length;
164
+ for(let i = 0; i < currentArrayLength; i++) {
165
+ let currentItem = currentArray[i];
166
+
167
+ let quantity = currentItem.quantity ? currentItem.quantity : 1;
168
+ value += quantity*currentItem.price;
169
+ }
170
+
171
+ return value;
172
+ }
173
+
174
+ trackProductView(aProduct) {
175
+
176
+ let items = [aProduct];
177
+
178
+ let data = {
179
+ currency: this.item.currency,
180
+ value: this._getValueFromItems(items),
181
+ items: items
182
+ }
183
+
184
+ this.trackEvent("Product view", data);
185
+ }
186
+
187
+ trackAddedToCart(aProductOrProducts) {
188
+ let items = Dbm.utils.ArrayFunctions.singleOrArray(aProductOrProducts);
189
+
190
+ let data = {
191
+ currency: this.item.currency,
192
+ value: this._getValueFromItems(items),
193
+ items: items
194
+ }
195
+
196
+ this.trackEvent("Added to cart", data);
197
+
198
+ }
199
+
200
+ trackCheckoutStarted(aProductOrProducts) {
201
+ let items = Dbm.utils.ArrayFunctions.singleOrArray(aProductOrProducts);
202
+
203
+ let data = {
204
+ currency: this.item.currency,
205
+ value: this._getValueFromItems(items),
206
+ items: items
207
+ }
208
+
209
+ this.trackEvent("Checkout started", data);
210
+ }
211
+
212
+ trackPurchase(aTransactionId, aProductOrProducts) {
213
+ let items = Dbm.utils.ArrayFunctions.singleOrArray(aProductOrProducts);
214
+
215
+ let data = {
216
+ transaction_id: aTransactionId,
217
+ currency: this.item.currency,
218
+ value: this._getValueFromItems(items),
219
+ items: items
220
+ }
221
+
222
+ this.trackEvent("Purchase", data);
223
+ }
224
+
225
+ createProductItemData(aId, aName, aPrice, aQuantity = 1, aAddtionalData = {}) {
226
+
227
+ let returnObject = {
228
+ ...aAddtionalData,
229
+ id: aId,
230
+ item_id: aId,
231
+ item_name: aName,
232
+ price: aPrice,
233
+ quantity: aQuantity
234
+ }
235
+
236
+ return returnObject;
237
+ }
157
238
  }
@@ -1,7 +1,6 @@
1
1
  import Dbm from "../index.js";
2
- import Cookies from "js-cookie";
3
2
 
4
- export default class Controller extends Dbm.core.BaseObject {
3
+ export default class DataLayerTracker extends Dbm.core.BaseObject {
5
4
  _construct() {
6
5
  super._construct();
7
6
  }
@@ -68,6 +67,7 @@ export default class Controller extends Dbm.core.BaseObject {
68
67
  console.log(aEventName, aData);
69
68
 
70
69
  this.addToDataLayer({"event": "trackEvent", "value": {"name": aEventName, "data": aData}});
70
+ this._gtag("event", aEventName, aData);
71
71
  }
72
72
 
73
73
  trackCurrentPage() {
@@ -0,0 +1,112 @@
1
+ import Dbm from "../index.js";
2
+
3
+ export default class MetaPixelTracker extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+
7
+ this.item.requireProperty("pixelId")
8
+ }
9
+
10
+ _setupFunction() {
11
+
12
+ if(window.fbq) return;
13
+
14
+ let fbq = function() {
15
+ fbq.callMethod ? fbq.callMethod.apply(fbq, arguments) : fbq.queue.push(arguments);
16
+ }
17
+ window.fbq = fbq;
18
+
19
+ if(!window._fbq) {
20
+ window._fbq = fbq;
21
+ }
22
+
23
+ fbq.push = fbq;
24
+ fbq.loaded = true;
25
+ fbq.version = "2.0";
26
+ fbq.queue = [];
27
+ fbq.disablePushState = true;
28
+
29
+ return this;
30
+ }
31
+
32
+ startTracking() {
33
+
34
+ //MENOTE: do nothing
35
+
36
+ return this;
37
+ }
38
+
39
+ startStatisticsTracking() {
40
+
41
+ //MENOTE: do nothing
42
+
43
+ return this;
44
+ }
45
+
46
+ startMarketingTracking() {
47
+
48
+ this._setupFunction();
49
+ Dbm.loading.loadScript("https://connect.facebook.net/en_US/fbevents.js");
50
+
51
+ let pixelId = this.item.pixelId;
52
+
53
+ if(this.item.pixelId) {
54
+ window.fbq("init", this.item.pixelId);
55
+ window.fbq("track", "PageView");
56
+ }
57
+
58
+ return this;
59
+ }
60
+
61
+ stopTracking() {
62
+
63
+ return this;
64
+ }
65
+
66
+ _convertGooogleAnalyctisData(aData) {
67
+
68
+ let data = {
69
+ content_type: "product",
70
+ value: aData.value,
71
+ currency: aData.currency,
72
+ contents: aData.items,
73
+ num_items: aData.items.length,
74
+ content_ids: Dbm.utils.ArrayFunctions.mapField(aData.items, "id")
75
+ };
76
+
77
+ if(aData.items.length === 1) {
78
+ data["content_name"] = aData.items[0]["item_name"];
79
+ }
80
+
81
+ return data;
82
+ }
83
+
84
+ trackEvent(aEventName, aData) {
85
+ console.log("trackEvent");
86
+ console.log(aEventName, aData);
87
+
88
+ if(aEventName === "Purchase") {
89
+ window.fbq('track', 'Purchase', this._convertGooogleAnalyctisData(aData), {eventID: aData.transaction_id});
90
+ }
91
+ else if(aEventName === "Product view") {
92
+ window.fbq('track', 'ViewContent', this._convertGooogleAnalyctisData(aData));
93
+ }
94
+ else if(aEventName === "Added to cart") {
95
+ window.fbq('track', 'AddToCart', this._convertGooogleAnalyctisData(aData));
96
+ }
97
+ else if(aEventName === "Checkout started") {
98
+ window.fbq('track', 'InitiateCheckout', this._convertGooogleAnalyctisData(aData));
99
+ }
100
+ else {
101
+ window.fbq("trackCustom", aEventName, aData);
102
+ }
103
+ }
104
+
105
+ trackCurrentPage() {
106
+ window.fbq("track", "PageView");
107
+ }
108
+
109
+ trackPage(aUrl) {
110
+ window.fbq("track", "PageView");
111
+ }
112
+ }
package/tracking/index.js CHANGED
@@ -2,8 +2,9 @@ import Dbm from "../index.js";
2
2
 
3
3
  export {default as Controller} from "./Controller.js";
4
4
  export {default as DataLayerTracker} from "./DataLayerTracker.js";
5
+ export {default as MetaPixelTracker} from "./MetaPixelTracker.js";
5
6
 
6
- export let setup = function() {
7
+ export const setup = function() {
7
8
 
8
9
  let controller = new Dbm.tracking.Controller();
9
10
  controller.item.register("trackingController");
@@ -13,4 +14,14 @@ export let setup = function() {
13
14
 
14
15
  let dataLayerTracker = new Dbm.tracking.DataLayerTracker();
15
16
  controller.addTracker(dataLayerTracker.item);
17
+ }
18
+
19
+ export const addMetaPixel = function(aPixelId) {
20
+ let tracker = new Dbm.tracking.MetaPixelTracker();
21
+ tracker.item.pixelId = aPixelId;
22
+ Dbm.getInstance().repository.getItem("trackingController").controller.addTracker(tracker.item);
23
+ }
24
+
25
+ export const setCurrency = function(aCurrency) {
26
+ Dbm.getInstance().repository.getItem("trackingController").currency = aCurrency;
16
27
  }
@@ -130,5 +130,18 @@ export const filterByField = function(aArray, aField, aValue) {
130
130
  }
131
131
  }
132
132
 
133
+ return returnArray;
134
+ }
135
+
136
+ export const mapField = function(aArray, aField) {
137
+
138
+
139
+ let currentArray = aArray;
140
+ let currentArrayLength = currentArray.length;
141
+ let returnArray = new Array(currentArrayLength);
142
+ for(let i = 0; i < currentArrayLength; i++) {
143
+ returnArray[i] = Dbm.objectPath(aArray[i], aField);
144
+ }
145
+
133
146
  return returnArray;
134
147
  }