@sapui5/sap.ui.vbm 1.129.0 → 1.131.0

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.
@@ -0,0 +1,130 @@
1
+ sap.ui.define([
2
+ "sap/ui/base/Object",
3
+ "./VectorUtils"
4
+ ], function (BaseObject, VectorUtils) {
5
+ 'use strict';
6
+
7
+ /**
8
+ * Constructor for a new PayloadGenerator.
9
+ *
10
+ * @class
11
+ * Provides a class for creating Payloads from events.
12
+ *
13
+ * @private
14
+ * @author SAP SE
15
+ * @version 1.131.0
16
+ * @alias sap.ui.vbm.vector.PayloadGenerator
17
+ */
18
+ const PayloadGenerator = BaseObject.extend("sap.ui.vbm.vector.PayloadGenerator", /** @lends sap.ui.vbm.vector.PayloadGenerator.prototype */ {
19
+ constructor: function (adapter) {
20
+ BaseObject.call(this);
21
+ this._adapter = adapter;
22
+ }
23
+ });
24
+
25
+ this.keysObjects = {};
26
+ this.mergeArray = [];
27
+
28
+ // Method to check if the key exists in the array for a given name
29
+ PayloadGenerator.keyExists = function (name, key, mergeArray) {
30
+ const nameObject = mergeArray.find(item => item.name === name);
31
+ if (nameObject) {
32
+ return nameObject.E.some(entry => entry.K === key);
33
+ }
34
+ return false;
35
+ };
36
+
37
+ // Method to insert unique key-value pairs and update "VB:s" flags
38
+ PayloadGenerator.insertUniqueKey = function (name, key, mergeArray) {
39
+ // Update all existing entries' "VB:s" flag to false
40
+ mergeArray.forEach(item => {
41
+ if (item.name === name) {
42
+ item.E.forEach(entry => {
43
+ entry["VB:s"] = "false"; // Set all existing ones to false
44
+ });
45
+ }
46
+ });
47
+
48
+ let nameObject = mergeArray.find(item => item.name === name);
49
+
50
+ // If the name (Spot or Link) doesn't exist, create it
51
+ if (!nameObject) {
52
+ nameObject = {
53
+ name: name,
54
+ E: []
55
+ };
56
+ mergeArray.push(nameObject);
57
+ }
58
+
59
+ // Check if the key already exists under the given name
60
+ const existingEntry = nameObject.E.find(entry => entry.K === key);
61
+
62
+ if (!existingEntry) {
63
+ // Push the new key-value pair with "VB:s" set to true for the clicked spot
64
+ nameObject.E.push({
65
+ K: key,
66
+ "VB:s": "true"
67
+ });
68
+ } else {
69
+ // If it exists, update its "VB:s" to true for the clicked spot
70
+ existingEntry["VB:s"] = "true";
71
+ }
72
+ };
73
+
74
+ PayloadGenerator.objectClick = (objectType, event, object, clickCoordinates) => {
75
+ //Format the coordinates
76
+ const formattedCoordinates = VectorUtils.formatCoordinates(clickCoordinates);
77
+
78
+ // Initialize objects for this specific call
79
+ const keysObjects = {};
80
+ const mergeArray = this.mergeArray; // This array persists across multiple clicks
81
+
82
+ keysObjects["K"] = object.properties.Key;
83
+
84
+ // Insert only if the key is unique for "objectType"
85
+ PayloadGenerator.insertUniqueKey(objectType, keysObjects["K"], mergeArray);
86
+
87
+ var payload = {
88
+ version: "2.0",
89
+ "xmlns:VB": "VB",
90
+ Action: {
91
+ name: event,
92
+ object: objectType,
93
+ id: object.id.toString(),
94
+ instance: object.properties.Key,
95
+ Params: {
96
+ Param: [
97
+ {
98
+ name: "x",
99
+ "#": object.properties.x
100
+ },
101
+ {
102
+ name: "y",
103
+ "#": object.properties.y
104
+ }
105
+ ]
106
+ },
107
+ AddActionProperties: {
108
+ AddActionProperty: [
109
+ {
110
+ name: "pos",
111
+ "#": formattedCoordinates
112
+ }
113
+ ]
114
+ }
115
+ },
116
+ Data: {
117
+ Merge: {
118
+ N: mergeArray
119
+ }
120
+ }
121
+ };
122
+
123
+ // Fire the submit event with the generated payload
124
+ this._adapter.fireSubmit({
125
+ data: JSON.stringify(payload)
126
+ });
127
+ };
128
+
129
+ return PayloadGenerator;
130
+ });