dbm 1.1.10 → 1.1.12

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.
Files changed (66) hide show
  1. package/core/source/SourceBaseObject.js +8 -0
  2. package/dbm.js +2 -1
  3. package/ecommerce/Cart.js +79 -0
  4. package/ecommerce/CartLineItem.js +44 -0
  5. package/ecommerce/LocalStorageCartLoader.js +74 -0
  6. package/ecommerce/index.js +16 -0
  7. package/flow/controllers/transform/SingleArrayValues.js +125 -0
  8. package/flow/controllers/transform/index.js +2 -1
  9. package/graphapi/webclient/GraphApi.js +2 -2
  10. package/graphapi/webclient/admin/ImageUploader.js +81 -0
  11. package/graphapi/webclient/admin/ItemEditor.js +62 -0
  12. package/graphapi/webclient/admin/SaveFunctions.js +34 -0
  13. package/graphapi/webclient/admin/index.js +2 -0
  14. package/graphapi/webclient/decode/Relations.js +77 -0
  15. package/graphapi/webclient/decode/index.js +24 -0
  16. package/package.json +1 -1
  17. package/react/BaseObject.js +1 -1
  18. package/react/admin/EditPage.js +25 -1
  19. package/react/admin/SelectedImage.js +48 -0
  20. package/react/admin/editor/fields/SelectObjectsField.js +80 -0
  21. package/react/admin/editor/fields/SelectionField.js +55 -0
  22. package/react/admin/editor/fields/index.js +3 -1
  23. package/react/admin/editorsgroup/EditField.js +26 -0
  24. package/react/admin/editorsgroup/EditItem.js +43 -0
  25. package/react/admin/editorsgroup/index.js +2 -0
  26. package/react/admin/index.js +4 -1
  27. package/react/admin/objects/EditObject.js +50 -0
  28. package/react/admin/objects/InjectObjectTypeEditor.js +30 -0
  29. package/react/admin/objects/ObjectList.js +92 -0
  30. package/react/admin/objects/ObjectListRow.js +35 -0
  31. package/react/admin/objects/RunObjectCommands.js +55 -0
  32. package/react/admin/objects/index.js +7 -0
  33. package/react/admin/objects/itemeditors/Content.js +48 -0
  34. package/react/admin/objects/itemeditors/Link.js +46 -0
  35. package/react/admin/objects/itemeditors/Name.js +46 -0
  36. package/react/admin/objects/itemeditors/Title.js +46 -0
  37. package/react/admin/objects/itemeditors/Visibility.js +44 -0
  38. package/react/admin/objects/itemeditors/index.js +5 -0
  39. package/react/admin/website/EditLocalBusiness.js +87 -86
  40. package/react/admin/website/EditWebsite.js +71 -16
  41. package/react/area/HasData.js +23 -4
  42. package/react/area/List.js +7 -2
  43. package/react/area/index.js +14 -1
  44. package/react/blocks/admin/index.js +1 -0
  45. package/react/blocks/admin/objects/Edit.js +42 -0
  46. package/react/blocks/admin/objects/List.js +17 -0
  47. package/react/blocks/admin/objects/RunObjectCommands.js +32 -0
  48. package/react/blocks/admin/objects/index.js +3 -0
  49. package/react/blocks/content/ContentBlock.js +46 -0
  50. package/react/blocks/content/index.js +2 -1
  51. package/react/blocks/faq/AskAQuestion.js +144 -0
  52. package/react/blocks/faq/index.js +1 -0
  53. package/react/blocks/index.js +125 -0
  54. package/react/context/AddItemByIdToContext.js +24 -0
  55. package/react/context/index.js +2 -1
  56. package/react/form/EditArray.js +43 -0
  57. package/react/form/GraphApiImage.js +92 -0
  58. package/react/form/GraphApiObjectSelection.js +1 -1
  59. package/react/form/GraphApiSelectOrCreateObject.js +71 -0
  60. package/react/form/TextArea.js +31 -0
  61. package/react/form/index.js +5 -1
  62. package/site/SiteNavigation.js +6 -5
  63. package/updater/PropertyUpdater.js +10 -0
  64. package/utils/ArrayFunctions.js +24 -2
  65. package/utils/CompareFunctions.js +45 -0
  66. package/utils/index.js +2 -1
@@ -24,6 +24,14 @@ export default class SourceBaseObject extends Dbm.core.BaseObject {
24
24
 
25
25
  if(this._log) {
26
26
  console.log("Source>>>>>", baseObject, path);
27
+ let currentPath = "";
28
+ let currentArray = path.split(".");
29
+ let currentArrayLength = currentArray.length;
30
+ for(let i = 0; i < currentArrayLength; i++) {
31
+ currentPath += currentArray[i];
32
+ console.log(currentPath, Dbm.objectPath(baseObject, currentPath));
33
+ currentPath += ".";
34
+ }
27
35
  }
28
36
 
29
37
  if(!path) {
package/dbm.js CHANGED
@@ -93,4 +93,5 @@ export * as flow from "./flow/index.js";
93
93
  export * as updater from "./updater/index.js";
94
94
  export * as startup from "./startup/index.js";
95
95
  export * as site from "./site/index.js";
96
- export * as tracking from "./tracking/index.js";
96
+ export * as tracking from "./tracking/index.js";
97
+ export * as ecommerce from "./ecommerce/index.js";
@@ -0,0 +1,79 @@
1
+ import Dbm from "../index.js";
2
+
3
+ export default class Cart extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+
7
+ this._changeCommand = Dbm.commands.callFunction(this._changed.bind(this));
8
+
9
+ this.item.setValue("lineItems", []);
10
+ Dbm.flow.addUpdateCommand(this.item.properties.lineItems, this._changeCommand);
11
+ this.item.setValue("numberOfItems", 0);
12
+ this.item.setValue("numberOfLines", 0);
13
+
14
+ this.item.setValue("changeCount", 0);
15
+
16
+ //METODO: integrate local storage
17
+ }
18
+
19
+ addProduct(aProduct, aQuantity = 1) {
20
+ //console.log("addProduct");
21
+ //console.log(aQuantity);
22
+
23
+ let lineItems = this.item.lineItems;
24
+ let lineItem;
25
+ let index = Dbm.utils.ArrayFunctions.getItemIndexByIfExists(lineItems, "product", aProduct);
26
+
27
+ if(index !== -1) {
28
+ lineItem = lineItems[index];
29
+ lineItem.controller.increaseQuantity(aQuantity);
30
+ }
31
+ else {
32
+ let id = "lineItem" + Dbm.getInstance().getNextId();
33
+ lineItem = new Dbm.ecommerce.CartLineItem();
34
+ lineItem.item.setId(id);
35
+ lineItem.setProduct(aProduct);
36
+ lineItem.setQuantity(aQuantity);
37
+ lineItem.setCart(this.item);
38
+
39
+ Dbm.flow.addUpdateCommand(lineItem.item.properties.quantity, this._changeCommand);
40
+
41
+ let newLineItems = [].concat(lineItems);
42
+ newLineItems.push(lineItem.item);
43
+ this.item.lineItems = newLineItems;
44
+ }
45
+
46
+ return lineItem;
47
+ }
48
+
49
+ removeLineItem(aItem) {
50
+ let lineItems = [].concat(this.item.lineItems);
51
+
52
+ let index = lineItems.indexOf(aItem);
53
+ if(index >= 0) {
54
+ lineItems.splice(index, 1);
55
+ this.item.lineItems = lineItems;
56
+ }
57
+ }
58
+
59
+ _changed() {
60
+ //console.log("_changed");
61
+
62
+ let lineItems = this.item.lineItems;
63
+
64
+ this.item.numberOfLines = lineItems.length;
65
+
66
+ let itemsCount = 0;
67
+ let currentArray = lineItems;
68
+ let currentArrayLength = currentArray.length;
69
+ for(let i = 0; i < currentArrayLength; i++) {
70
+ let currentItem = currentArray[i];
71
+ itemsCount += currentItem.quantity;
72
+ }
73
+
74
+ this.item.numberOfItems = itemsCount;
75
+ this.item.changeCount++;
76
+
77
+ //METODO: calculate totals
78
+ }
79
+ }
@@ -0,0 +1,44 @@
1
+ import Dbm from "../index.js";
2
+
3
+ export default class CartLineItem extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+
7
+ this.item.setValue("cart", null);
8
+ this.item.setValue("product", null);
9
+ this.item.setValue("quantity", 0);
10
+ }
11
+
12
+ setCart(aItem) {
13
+ this.item.cart = aItem;
14
+
15
+ return this;
16
+ }
17
+
18
+ setProduct(aProduct) {
19
+ this.item.product = aProduct;
20
+
21
+ return this;
22
+ }
23
+
24
+ setQuantity(aQuantity) {
25
+ console.log("setQuantity");
26
+ console.log(aQuantity);
27
+
28
+ this.item.quantity = aQuantity;
29
+
30
+ return this;
31
+ }
32
+
33
+ increaseQuantity(aQuantity) {
34
+ this.item.quantity += aQuantity;
35
+
36
+ return this;
37
+ }
38
+
39
+ remove() {
40
+ this.item.cart.controller.removeLineItem(this.item);
41
+
42
+ return this;
43
+ }
44
+ }
@@ -0,0 +1,74 @@
1
+ import Dbm from "../index.js";
2
+
3
+ export default class LocalStorageCartLoader extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+
7
+ this._changeCommand = Dbm.commands.callFunction(this._changed.bind(this));
8
+
9
+ this._isLoading = false;
10
+ this.item.requireProperty("storageKey", "cart");
11
+ this.item.requireProperty("cart", null);
12
+ }
13
+
14
+ setCart(aCart) {
15
+ this.item.cart = aCart;
16
+ Dbm.flow.addUpdateCommand(aCart.properties.changeCount, this._changeCommand);
17
+
18
+ return this;
19
+ }
20
+
21
+ load() {
22
+ //console.log("load");
23
+
24
+ let repository = Dbm.getInstance().repository;
25
+
26
+ this._isLoading = true;
27
+ try {
28
+ let cartDataString = localStorage.getItem(this.item.storageKey);
29
+ if(cartDataString) {
30
+ let cartData = JSON.parse(cartDataString);
31
+ console.log(cartData);
32
+ let currentArray = cartData.lineItems;
33
+ let currentArrayLength = currentArray.length;
34
+ for(let i = 0; i < currentArrayLength; i++) {
35
+ let currentData = currentArray[i];
36
+
37
+ console.log(">>>>>>>>", currentData["quantity"]);
38
+ this.item.cart.controller.addProduct(repository.getItem(currentData["product"]), currentData["quantity"]);
39
+ }
40
+ }
41
+ }
42
+ catch(theError) {
43
+ console.error(theError);
44
+ }
45
+
46
+ this._isLoading = false;
47
+ }
48
+
49
+ _changed() {
50
+ //console.log("_changed");
51
+
52
+ if(this._isLoading) {
53
+ return;
54
+ }
55
+
56
+ let encodedLineItems = [];
57
+
58
+ let currentArray = this.item.cart.lineItems;
59
+ let currentArrayLength = currentArray.length;
60
+ for(let i = 0; i < currentArrayLength; i++) {
61
+ let currentData = currentArray[i];
62
+
63
+ let encodedData = {"product": currentData.product.id, "quantity": currentData.quantity};
64
+ encodedLineItems.push(encodedData);
65
+ }
66
+
67
+ try {
68
+ let cartDataString = localStorage.setItem(this.item.storageKey, JSON.stringify({"lineItems": encodedLineItems}));
69
+ }
70
+ catch(theError) {
71
+ console.error(theError);
72
+ }
73
+ }
74
+ }
@@ -0,0 +1,16 @@
1
+ import Dbm from "../index.js";
2
+
3
+ export {default as Cart} from "./Cart.js";
4
+ export {default as CartLineItem} from "./CartLineItem.js";
5
+ export {default as LocalStorageCartLoader} from "./LocalStorageCartLoader.js";
6
+
7
+ export const setup = function() {
8
+
9
+ let cart = new Dbm.ecommerce.Cart();
10
+ cart.item.register("cart");
11
+
12
+ let localStorageLoader = new Dbm.ecommerce.LocalStorageCartLoader();
13
+ localStorageLoader.setCart(cart.item);
14
+ localStorageLoader.load();
15
+
16
+ }
@@ -0,0 +1,125 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class SingleArrayValues extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+
7
+ this.item.requireProperty("array", []);
8
+ this.item.requireProperty("items", []);
9
+
10
+ let arrayUpdatedCommand = Dbm.commands.callFunction(this._arrayUpdated.bind(this));
11
+ Dbm.flow.addUpdateCommand(this.item.properties.array, arrayUpdatedCommand);
12
+
13
+ this._valueUpdatedCommand = Dbm.commands.callFunction(this._valueUpdated.bind(this));
14
+
15
+ }
16
+
17
+ _createItem(aInitialValue = null) {
18
+ let newItem = new Dbm.repository.Item();
19
+ newItem.setId("_dbmInternal/" + Dbm.getInstance().getNextId());
20
+ Dbm.flow.addUpdateCommand(newItem.requireProperty("value", aInitialValue), this._valueUpdatedCommand);
21
+
22
+ return newItem;
23
+ }
24
+
25
+ push(aValue = null) {
26
+ let item = this._createItem(aValue);
27
+
28
+ let dataArray = [].concat(this.item.array);
29
+ let itemsArray = [].concat(this.item.items);
30
+
31
+ itemsArray.push(item);
32
+ dataArray.push(aValue);
33
+
34
+ this.item.items = itemsArray;
35
+ this.item.properties.array.getMostUpstreamProperty().value = dataArray;
36
+ }
37
+
38
+ removeItem(aItem) {
39
+ //console.log("removeItem");
40
+ //console.log(aItem);
41
+
42
+ let dataArray = [].concat(this.item.array);
43
+ let itemsArray = [].concat(this.item.items);
44
+
45
+ let index = itemsArray.indexOf(aItem);
46
+ if(index >= 0) {
47
+ itemsArray.splice(index, 1);
48
+ dataArray.splice(index, 1);
49
+
50
+ this.item.items = itemsArray;
51
+ this.item.properties.array.getMostUpstreamProperty().value = dataArray;
52
+ }
53
+ }
54
+
55
+ _movePosition(aFromIndex, aToIndex) {
56
+ //METODO
57
+ }
58
+
59
+ moveItem(aItem, aPosition) {
60
+ let index = this.item.items.indexOf(aItem);
61
+ if(index >= 0) {
62
+ this._movePosition(index, aPosition);
63
+ }
64
+ }
65
+
66
+ moveUpItem(aItem, aPosition) {
67
+
68
+ let index = this.item.items.indexOf(aItem);
69
+ if(index >= 0) {
70
+ if(index > 0) {
71
+ this._movePosition(index, index-1);
72
+ }
73
+ }
74
+ }
75
+
76
+ moveDownItem(aItem, aPosition) {
77
+ let index = this.item.items.indexOf(aItem);
78
+ if(index >= 0) {
79
+ if(index < this.item.items.length-1) {
80
+ this._movePosition(index, index+1);
81
+ }
82
+ }
83
+ }
84
+
85
+ _arrayUpdated() {
86
+ console.log("_arrayUpdated");
87
+
88
+ let dataArray = this.item.array;
89
+ let itemsArray = this.item.items;
90
+
91
+ let dataLength = dataArray.length;
92
+ let itemsLength = itemsArray.length;
93
+ let itemChange = dataLength-itemsLength;
94
+ if(itemChange !== 0) {
95
+ itemsArray = [].concat(itemsArray);
96
+ if(itemChange < 0) {
97
+ itemsArray.splice(itemsArray.length, Math.abs(itemChange));
98
+ }
99
+ else if(itemChange > 0) {
100
+ for(let i = 0; i < itemChange; i++) {
101
+ itemsArray.push(this._createItem(dataArray[itemsLength+i]));
102
+ }
103
+ }
104
+ }
105
+
106
+ let currentArray = dataArray;
107
+ let currentArrayLength = currentArray.length;
108
+ for(let i = 0; i < currentArrayLength; i++) {
109
+ itemsArray[i].value = currentArray[i];
110
+ }
111
+
112
+ if(itemChange !== 0) {
113
+ this.item.items = itemsArray;
114
+ }
115
+
116
+ }
117
+
118
+ _valueUpdated() {
119
+ console.log("_valueUpdated");
120
+
121
+ let values = Dbm.utils.ArrayFunctions.mapField(this.item.items, "value");
122
+ console.log(values);
123
+ this.item.properties.array.getMostUpstreamProperty().value = values;
124
+ }
125
+ }
@@ -1 +1,2 @@
1
- export {default as PartOfObject} from "./PartOfObject.js";
1
+ export {default as PartOfObject} from "./PartOfObject.js";
2
+ export {default as SingleArrayValues} from "./SingleArrayValues.js";
@@ -21,7 +21,7 @@ export default class GraphApi extends Dbm.core.BaseObject {
21
21
  }
22
22
 
23
23
  requestRange(aSelect, aEncode) {
24
- console.log("requestRange");
24
+ //console.log("requestRange");
25
25
 
26
26
  if(this._websocketConnection && this._websocketConnection.item.status === 1) {
27
27
  return this._websocketConnection.requestRange(aSelect, aEncode);
@@ -31,7 +31,7 @@ export default class GraphApi extends Dbm.core.BaseObject {
31
31
  }
32
32
 
33
33
  requestItem(aId, aEncode) {
34
- console.log("requestItem");
34
+ //console.log("requestItem");
35
35
 
36
36
  if(this._websocketConnection && this._websocketConnection.item.status === 1) {
37
37
  return this._websocketConnection.requestItem(aId, aEncode);
@@ -0,0 +1,81 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class ImageUploader extends Dbm.core.BaseObject {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.item.requireProperty("file", null);
9
+ this.item.requireProperty("status", 0);
10
+ this.item.requireProperty("item", null);
11
+
12
+ this._fileUploadedBound = this._fileUploaded.bind(this);
13
+ }
14
+
15
+ setFile(aFile) {
16
+ this.item.file = aFile;
17
+ return this;
18
+ }
19
+
20
+ uploadImage() {
21
+ console.log("uploadImage");
22
+ if(this.item.status !== 0) {
23
+ console.warn("Image is already uploading", this);
24
+ return this;
25
+ }
26
+
27
+ let file = this.item.file;
28
+ if(!file) {
29
+ console.warn("No file set", this);
30
+ return this;
31
+ }
32
+
33
+ this.item.status = 2;
34
+
35
+ let graphApi = Dbm.getInstance().repository.getItem("graphApi").controller;
36
+
37
+ let preSign = graphApi.requestData("fileUpload", {"fileName": file.name, "mimeType": file.type});
38
+
39
+ Dbm.flow.addDirectUpdateCommand(preSign.getProperty("status"), Dbm.commands.callFunction(this._statusChanged.bind(this), [preSign, file]));
40
+
41
+ return this;
42
+ }
43
+
44
+ _statusChanged(aPreSign, aFile) {
45
+ console.log("_statusChanged");
46
+ console.log(aPreSign, aFile);
47
+
48
+ let item = Dbm.getInstance().repository.getItem(aPreSign.data.id);
49
+ item.setValue("name", aPreSign.data.name);
50
+ item.setValue("url", aPreSign.data.publicUrl);
51
+ item.setValue("resizeUrl", aPreSign.data.publicResizeUrl);
52
+ item.setValue("identifier", aPreSign.data.identifier);
53
+ this.item.item = item;
54
+
55
+ if(aPreSign.status === 1) {
56
+ let url = aPreSign.data.url;
57
+ console.log(url, aPreSign.data);
58
+
59
+ let headers = {
60
+ 'Content-Type': aFile.type,
61
+ 'Cache-Control': 'no-cache',
62
+ };
63
+
64
+ let additionalHeaders = aPreSign.data.additionalHeaders;
65
+ for(let objectName in additionalHeaders) {
66
+ headers[objectName] = additionalHeaders[objectName];
67
+ }
68
+
69
+ fetch(url, {method: 'PUT', headers: new Headers(headers), body: aFile}).then(this._fileUploadedBound)
70
+
71
+ }
72
+ }
73
+
74
+ _fileUploaded() {
75
+ console.log("_fileUploaded");
76
+
77
+ this.item.status = 1;
78
+
79
+ console.log("Uploaded", this.item.item);
80
+ }
81
+ }
@@ -42,6 +42,68 @@ export default class ItemEditor extends Dbm.core.BaseObject {
42
42
  return this.addEditor(aField, aInitialValue, Dbm.graphapi.webclient.admin.SaveFunctions.setField, aUpdateEncoding);
43
43
  }
44
44
 
45
+ _addRelationEditor(aName, aType, aObjectType, aInitialValue, aSaveFunction, aUpdateEncoding = null) {
46
+ let valueEditor = this.item["editor_relation_" + aName];
47
+ if(!valueEditor) {
48
+ valueEditor = new Dbm.graphapi.webclient.admin.ValueEditor();
49
+ valueEditor.item.editValue.setInitialValue(aInitialValue);
50
+
51
+ valueEditor.item.setValue("itemEditor", this.item);
52
+ valueEditor.item.setValue("type", aType);
53
+ valueEditor.item.setValue("objectType", aObjectType);
54
+ valueEditor.item.setValue("updateEncoding", aUpdateEncoding);
55
+
56
+ this.item.anyChange.addCheck(valueEditor.item.properties.changed);
57
+ this.item.setValue("editor_relation_" + aName, valueEditor);
58
+ this.item.editors = [].concat(this.item.editors, valueEditor);
59
+
60
+ valueEditor.addSaveFunction(aSaveFunction);
61
+ }
62
+
63
+ return valueEditor;
64
+ }
65
+
66
+ addIncomingRelationEditor(aType, aObjectType, aInitialValue, aUpdateEncoding = null) {
67
+ let name = "in_" + aType + "_" + aObjectType;
68
+ return this._addRelationEditor(name, aType, aObjectType, aInitialValue, Dbm.graphapi.webclient.admin.SaveFunctions.incomingRelation, aUpdateEncoding);
69
+ }
70
+
71
+ addOutgoingRelationEditor(aType, aObjectType, aInitialValue, aUpdateEncoding = null) {
72
+ let name = "out_" + aType + "_" + aObjectType;
73
+ return this._addRelationEditor(name, aType, aObjectType, aInitialValue, Dbm.graphapi.webclient.admin.SaveFunctions.outgoingRelation, aUpdateEncoding);
74
+ }
75
+
76
+ _addMultipleRelationsEditor(aName, aType, aObjectType, aInitialValue, aSaveFunction, aUpdateEncoding = null) {
77
+ let valueEditor = this.item["editor_relation_" + aName];
78
+ if(!valueEditor) {
79
+ valueEditor = new Dbm.graphapi.webclient.admin.ValueEditor();
80
+ valueEditor.item.editValue.setInitialValue(aInitialValue);
81
+
82
+ valueEditor.item.setValue("itemEditor", this.item);
83
+ valueEditor.item.setValue("type", aType);
84
+ valueEditor.item.setValue("objectType", aObjectType);
85
+ valueEditor.item.setValue("updateEncoding", aUpdateEncoding);
86
+
87
+ this.item.anyChange.addCheck(valueEditor.item.properties.changed);
88
+ this.item.setValue("editor_multipleRelations_" + aName, valueEditor);
89
+ this.item.editors = [].concat(this.item.editors, valueEditor);
90
+
91
+ valueEditor.addSaveFunction(aSaveFunction);
92
+ }
93
+
94
+ return valueEditor;
95
+ }
96
+
97
+ addMultipleIncomingRelationsEditor(aType, aObjectType, aInitialValue, aUpdateEncoding = null) {
98
+ let name = "in_" + aType + "_" + aObjectType;
99
+ return this._addMultipleRelationsEditor(name, aType, aObjectType, aInitialValue, Dbm.graphapi.webclient.admin.SaveFunctions.multipleIncomingRelations, aUpdateEncoding);
100
+ }
101
+
102
+ addMultipleOutgoingRelationsEditor(aType, aObjectType, aInitialValue, aUpdateEncoding = null) {
103
+ let name = "out_" + aType + "_" + aObjectType;
104
+ return this._addMultipleRelationsEditor(name, aType, aObjectType, aInitialValue, Dbm.graphapi.webclient.admin.SaveFunctions.multipleOutgoingRelations, aUpdateEncoding);
105
+ }
106
+
45
107
  addCommandsToSaveData(aSaveData) {
46
108
 
47
109
  let editedItemId = Dbm.objectPath(this.item, "editedItem.id");
@@ -1,7 +1,41 @@
1
+ import Dbm from "../../../index.js";
2
+
1
3
  export const setField = function(aEditor, aItemSaveData) {
2
4
  aItemSaveData.setField(aEditor.item.name, aEditor.item.editValue.getValue());
3
5
  }
4
6
 
5
7
  export const setUrl = function(aEditor, aItemSaveData) {
6
8
  aItemSaveData.createChange("setUrl", {"value": aEditor.item.editValue.getValue()});
9
+ }
10
+
11
+ export const setIdentifier = function(aEditor, aItemSaveData) {
12
+ aItemSaveData.createChange("setIdentifier", {"value": aEditor.item.editValue.getValue()});
13
+ }
14
+
15
+ export const setVisibility = function(aEditor, aItemSaveData) {
16
+ aItemSaveData.createChange("setVisibility", {"value": aEditor.item.editValue.getValue()});
17
+ }
18
+
19
+ export const incomingRelation = function(aEditor, aItemSaveData) {
20
+ let id = aEditor.item.editValue.getValue();
21
+
22
+ aItemSaveData.createChange("replaceIncomingRelation", {"value": id, "type": aEditor.item.type, "objectType": aEditor.item.objectType});
23
+ }
24
+
25
+ export const outgoingRelation = function(aEditor, aItemSaveData) {
26
+ let id = aEditor.item.editValue.getValue();
27
+
28
+ aItemSaveData.createChange("replaceOutgoingRelation", {"value": id, "type": aEditor.item.type, "objectType": aEditor.item.objectType});
29
+ }
30
+
31
+ export const multipleIncomingRelations = function(aEditor, aItemSaveData) {
32
+ let ids = Dbm.utils.ArrayFunctions.removeValues(aEditor.item.editValue.getValue(), [0, null, undefined]);
33
+
34
+ aItemSaveData.createChange("replaceMultipleIncomingRelations", {"value": ids, "type": aEditor.item.type, "objectType": aEditor.item.objectType});
35
+ }
36
+
37
+ export const multipleOutgoingRelations = function(aEditor, aItemSaveData) {
38
+ let ids = Dbm.utils.ArrayFunctions.removeValues(aEditor.item.editValue.getValue(), [0, null, undefined]);
39
+
40
+ aItemSaveData.createChange("replaceMultipleOutgoingRelations", {"value": ids, "type": aEditor.item.type, "objectType": aEditor.item.objectType});
7
41
  }
@@ -5,4 +5,6 @@ export {default as EditorGroup} from "./EditorGroup.js";
5
5
  export {default as ItemEditor} from "./ItemEditor.js";
6
6
  export {default as ValueEditor} from "./ValueEditor.js";
7
7
 
8
+ export {default as ImageUploader} from "./ImageUploader.js";
9
+
8
10
  export * as SaveFunctions from "./SaveFunctions.js";
@@ -0,0 +1,77 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class Relations extends Dbm.graphapi.webclient.decode.DecodeBaseObject {
4
+ _construct() {
5
+ super._construct();
6
+ }
7
+
8
+ _isRelationValid(aStartTime, aEndTime) {
9
+ let now = (new Date()).toISOString().split("T").join(" ").substring(0, 19);
10
+
11
+ return ((aStartTime === null || aStartTime <= now) && (aEndTime === null || aEndTime > now));
12
+ }
13
+
14
+ updateItem(aItem, aData) {
15
+ super.updateItem(aItem, aData);
16
+
17
+ let relations = aData["relations"];
18
+ {
19
+ let currentRelations = relations["in"];
20
+ let currentRelationsItem = aItem["relations/in"];
21
+ if(!currentRelationsItem) {
22
+ currentRelationsItem = new Dbm.repository.Item();
23
+ aItem.setValue("relations/in", currentRelationsItem);
24
+ }
25
+
26
+ let currentArray = currentRelations;
27
+ let currentArrayLength = currentArray.length;
28
+ for(let i = 0; i < currentArrayLength; i++) {
29
+ let currentRelationData = currentArray[i];
30
+ let currentType = currentRelationData["type"];
31
+ let typeItem = currentRelationsItem[currentType];
32
+ if(!typeItem) {
33
+ typeItem = new Dbm.repository.Item();
34
+ typeItem.setValue("objects", []);
35
+ currentRelationsItem.setValue(currentType, typeItem);
36
+ }
37
+
38
+ if(this._isRelationValid(currentRelationData["startAt"], currentRelationData["endAt"])) {
39
+ let newArray = [].concat(typeItem["objects"]);
40
+ newArray.push(Dbm.getInstance().repository.getItem(currentRelationData["id"]));
41
+ typeItem["objects"] = newArray;
42
+ //METODO: set up relations
43
+ }
44
+
45
+ }
46
+ }
47
+
48
+ {
49
+ let currentRelations = relations["out"];
50
+ let currentRelationsItem = aItem["relations/out"];
51
+ if(!currentRelationsItem) {
52
+ currentRelationsItem = new Dbm.repository.Item();
53
+ aItem.setValue("relations/out", currentRelationsItem);
54
+ }
55
+
56
+ let currentArray = currentRelations;
57
+ let currentArrayLength = currentArray.length;
58
+ for(let i = 0; i < currentArrayLength; i++) {
59
+ let currentRelationData = currentArray[i];
60
+ let currentType = currentRelationData["type"];
61
+ let typeItem = currentRelationsItem[currentType];
62
+ if(!typeItem) {
63
+ typeItem = new Dbm.repository.Item();
64
+ typeItem.setValue("objects", []);
65
+ currentRelationsItem.setValue(currentType, typeItem);
66
+ }
67
+
68
+ if(this._isRelationValid(currentRelationData["startAt"], currentRelationData["endAt"])) {
69
+ let newArray = [].concat(typeItem["objects"]);
70
+ newArray.push(Dbm.getInstance().repository.getItem(currentRelationData["id"]));
71
+ typeItem["objects"] = newArray;
72
+ //METODO: set up relations
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }