@everymatrix/user-action-controller 1.27.10 → 1.28.4
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/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{player-legislation-wrapper_3.cjs.entry.js → player-user-consents_2.cjs.entry.js} +112 -70
- package/dist/cjs/user-action-controller.cjs.js +1 -1
- package/dist/collection/collection-manifest.json +0 -6
- package/dist/collection/components/user-action-controller/user-action-controller.js +89 -60
- package/dist/collection/utils/locale.utils.js +60 -0
- package/dist/components/user-action-controller.js +120 -48
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{player-legislation-wrapper_3.entry.js → player-user-consents_2.entry.js} +114 -71
- package/dist/esm/user-action-controller.js +1 -1
- package/dist/types/Users/adrian.pripon/Documents/Work/widgets-stencil/packages/user-action-controller/.stencil/packages/user-action-controller/stencil.config.d.ts +2 -0
- package/dist/types/components/user-action-controller/user-action-controller.d.ts +13 -10
- package/dist/types/components.d.ts +16 -8
- package/dist/types/utils/locale.utils.d.ts +2 -0
- package/dist/user-action-controller/p-711fa494.entry.js +1 -0
- package/dist/user-action-controller/user-action-controller.esm.js +1 -1
- package/package.json +1 -1
- package/dist/components/player-legislation-wrapper.js +0 -6
- package/dist/components/player-legislation-wrapper2.js +0 -54
- package/dist/types/Users/dragos.bodea/Documents/everymatrix-prjs/emfe-widgets/widgets-stencil/packages/user-action-controller/.stencil/packages/user-action-controller/stencil.config.d.ts +0 -2
- package/dist/user-action-controller/p-073a0fe2.entry.js +0 -1
|
@@ -1,7 +1,67 @@
|
|
|
1
1
|
import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
|
|
2
|
-
import { d as defineCustomElement$3 } from './player-legislation-wrapper2.js';
|
|
3
2
|
import { d as defineCustomElement$2 } from './player-user-consents2.js';
|
|
4
3
|
|
|
4
|
+
const DEFAULT_LANGUAGE = 'en';
|
|
5
|
+
const SUPPORTED_LANGUAGES = ['ro', 'en', 'cz', 'de', 'hr'];
|
|
6
|
+
const TRANSLATIONS = {
|
|
7
|
+
en: {
|
|
8
|
+
termsandconditions: 'Terms and Conditions',
|
|
9
|
+
sms: 'SMS marketing',
|
|
10
|
+
emailmarketing: 'Email marketing'
|
|
11
|
+
},
|
|
12
|
+
ro: {
|
|
13
|
+
termsandconditions: 'Terms and Conditions',
|
|
14
|
+
sms: 'SMS marketing',
|
|
15
|
+
emailmarketing: 'Email marketing'
|
|
16
|
+
},
|
|
17
|
+
hr: {
|
|
18
|
+
termsandconditions: 'Terms and Conditions',
|
|
19
|
+
sms: 'SMS marketing',
|
|
20
|
+
emailmarketing: 'Email marketing'
|
|
21
|
+
},
|
|
22
|
+
fr: {
|
|
23
|
+
termsandconditions: 'Terms and Conditions',
|
|
24
|
+
sms: 'SMS marketing',
|
|
25
|
+
emailmarketing: 'Email marketing'
|
|
26
|
+
},
|
|
27
|
+
cs: {
|
|
28
|
+
termsandconditions: 'Terms and Conditions',
|
|
29
|
+
sms: 'SMS marketing',
|
|
30
|
+
emailmarketing: 'Email marketing'
|
|
31
|
+
},
|
|
32
|
+
de: {
|
|
33
|
+
termsandconditions: 'Terms and Conditions',
|
|
34
|
+
sms: 'SMS marketing',
|
|
35
|
+
emailmarketing: 'Email marketing'
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
const getTranslations = (url) => {
|
|
39
|
+
// fetch url, get the data, replace the TRANSLATIONS content
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
fetch(url)
|
|
42
|
+
.then((res) => res.json())
|
|
43
|
+
.then((data) => {
|
|
44
|
+
Object.keys(data).forEach((item) => {
|
|
45
|
+
for (let key in data[item]) {
|
|
46
|
+
TRANSLATIONS[item][key] = data[item][key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
resolve(true);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
const translate = (key, customLang, values) => {
|
|
54
|
+
const lang = customLang;
|
|
55
|
+
let translation = TRANSLATIONS[lang !== undefined && SUPPORTED_LANGUAGES.includes(lang) ? lang : DEFAULT_LANGUAGE][key];
|
|
56
|
+
if (values !== undefined) {
|
|
57
|
+
for (const [key, value] of Object.entries(values.values)) {
|
|
58
|
+
const regex = new RegExp(`{${key}}`, 'g');
|
|
59
|
+
translation = translation.replace(regex, value);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return translation;
|
|
63
|
+
};
|
|
64
|
+
|
|
5
65
|
const userActionControllerCss = ":host{display:block}.QueryReferenceContainer{height:100%;width:100%}.UserConsentNotice{font-size:1.2rem;font-weight:200;text-align:center}.CloseButton{width:25px;height:25px;align-self:flex-end}.UserActionController{font-family:Arial, Helvetica, sans-serif;font-weight:100;height:100%;width:100%;padding:1rem 1.5rem 2rem;background-color:#fff;display:flex;flex-direction:column;justify-content:space-between;border-radius:5%}.ConsentSubmitButton{font-size:1rem;padding:0.4rem 1.4rem;background:#fff;border:2px solid #000;color:#000;border-radius:5px;align-self:flex-end}.ConsentSubmitButton:disabled{border:2px solid #ccc;color:#ccc}@media screen and (max-width: 320px){.QueryReferenceContainer{font-size:0.8rem;color:blue}}.spinner{animation:rotate 2s linear infinite;z-index:2;position:absolute;top:50%;left:50%;margin:-25px 0 0 -25px;width:50px;height:50px}.spinner .path{stroke:var(--emfe-w-login-color-primary, var(--emfe-w-color-primary, #D0046C));stroke-linecap:round;animation:dash 1.5s ease-in-out infinite}@keyframes rotate{100%{transform:rotate(360deg)}}@keyframes dash{0%{stroke-dasharray:1, 150;stroke-dashoffset:0}50%{stroke-dasharray:90, 150;stroke-dashoffset:-35}100%{stroke-dasharray:90, 150;stroke-dashoffset:-124}}";
|
|
6
66
|
|
|
7
67
|
const UserActionController$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
@@ -10,13 +70,17 @@ const UserActionController$1 = /*@__PURE__*/ proxyCustomElement(class extends HT
|
|
|
10
70
|
this.__registerHost();
|
|
11
71
|
this.__attachShadow();
|
|
12
72
|
/**
|
|
13
|
-
*
|
|
73
|
+
* Language
|
|
14
74
|
*/
|
|
15
|
-
this.
|
|
75
|
+
this.lang = 'en';
|
|
16
76
|
/**
|
|
17
77
|
* Select GM version
|
|
18
78
|
*/
|
|
19
79
|
this.gmVersion = '';
|
|
80
|
+
/**
|
|
81
|
+
* Translation url
|
|
82
|
+
*/
|
|
83
|
+
this.translationUrl = '';
|
|
20
84
|
/**
|
|
21
85
|
* Client custom styling via inline style
|
|
22
86
|
*/
|
|
@@ -30,17 +94,19 @@ const UserActionController$1 = /*@__PURE__*/ proxyCustomElement(class extends HT
|
|
|
30
94
|
*/
|
|
31
95
|
this.queryFired = false;
|
|
32
96
|
this.readyActionsCount = 0;
|
|
97
|
+
this.activeUserActions = [];
|
|
98
|
+
this.userActionsValidated = true;
|
|
33
99
|
this.receivedQueryResponses = 0;
|
|
34
100
|
this.limitStylingAppends = false;
|
|
35
101
|
this.isLoading = true;
|
|
102
|
+
this.mandatoryActionsChecked = 0;
|
|
103
|
+
//for now this variable is hardcoded bcs we have only terms and conditions mandatory and we dont receive with these new functionality the mandatory actions
|
|
36
104
|
this.mandatoryActions = ['termsandconditions'];
|
|
37
|
-
this.requiredActionsCount = 0;
|
|
38
|
-
this.expectedQueryResponses = 0;
|
|
39
105
|
this.userActions = [];
|
|
40
106
|
this.consentTitles = {
|
|
41
|
-
termsandconditions:
|
|
42
|
-
sms:
|
|
43
|
-
emailmarketing:
|
|
107
|
+
termsandconditions: translate('termsandconditions', this.lang),
|
|
108
|
+
sms: translate('sms', this.lang),
|
|
109
|
+
emailmarketing: translate('emailmarketing', this.lang)
|
|
44
110
|
};
|
|
45
111
|
this.setClientStyling = () => {
|
|
46
112
|
let sheet = document.createElement('style');
|
|
@@ -62,44 +128,45 @@ const UserActionController$1 = /*@__PURE__*/ proxyCustomElement(class extends HT
|
|
|
62
128
|
});
|
|
63
129
|
};
|
|
64
130
|
}
|
|
131
|
+
handleNewTranslations() {
|
|
132
|
+
getTranslations(this.translationUrl);
|
|
133
|
+
}
|
|
65
134
|
handleQueryResponse() {
|
|
66
|
-
if (this.receivedQueryResponses === this.
|
|
135
|
+
if (this.receivedQueryResponses === this.activeUserActions.length) {
|
|
67
136
|
this.updateUserConsents();
|
|
68
137
|
}
|
|
69
138
|
}
|
|
70
|
-
hasToSetConsentsHandler(_) {
|
|
71
|
-
this.hasToSetConsents = true;
|
|
72
|
-
}
|
|
73
139
|
userLegislationConsentHandler(event) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
else
|
|
79
|
-
this.readyActionsCount--;
|
|
140
|
+
const actionType = event.detail.type;
|
|
141
|
+
const actionTypeChecked = event.detail.value;
|
|
142
|
+
if (this.mandatoryActions.includes(actionType) && this.queryFired === false) {
|
|
143
|
+
actionTypeChecked === true ? this.mandatoryActionsChecked++ : this.mandatoryActionsChecked--;
|
|
80
144
|
}
|
|
81
145
|
// Register final user choices only if we're ready to update
|
|
82
146
|
if (this.queryFired) {
|
|
83
|
-
this.userActions.push({ tagCode:
|
|
147
|
+
this.userActions.push({ tagCode: actionType, status: actionTypeChecked ? 'Accepted' : 'Denied' });
|
|
84
148
|
this.receivedQueryResponses++;
|
|
85
149
|
}
|
|
86
150
|
}
|
|
87
|
-
|
|
88
|
-
const url = new URL(`${this.endpoint}/v1/player/
|
|
151
|
+
determineUserActions() {
|
|
152
|
+
const url = new URL(`${this.endpoint}/v1/player/${this.userId}/consent`);
|
|
153
|
+
const headers = new Headers();
|
|
154
|
+
headers.append('X-SessionId', this.userSession);
|
|
89
155
|
let requestOptions;
|
|
90
156
|
requestOptions = {
|
|
91
157
|
method: 'GET',
|
|
92
|
-
headers
|
|
93
|
-
'X-SessionId': `${this.userSession}`,
|
|
94
|
-
},
|
|
158
|
+
headers
|
|
95
159
|
};
|
|
96
160
|
if (url && requestOptions) {
|
|
97
161
|
return fetch(url.href, requestOptions)
|
|
98
162
|
.then(res => res.json())
|
|
99
163
|
.then(data => {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
164
|
+
const actionItems = data.items;
|
|
165
|
+
actionItems.forEach(element => {
|
|
166
|
+
if (element.status === 'Expired') {
|
|
167
|
+
this.activeUserActions.push(element.tagCode);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
103
170
|
this.isLoading = false;
|
|
104
171
|
})
|
|
105
172
|
.catch(error => {
|
|
@@ -169,14 +236,17 @@ const UserActionController$1 = /*@__PURE__*/ proxyCustomElement(class extends HT
|
|
|
169
236
|
handleApplyClick() {
|
|
170
237
|
this.queryFired = true;
|
|
171
238
|
}
|
|
172
|
-
componentWillLoad() {
|
|
239
|
+
async componentWillLoad() {
|
|
173
240
|
if (this.gmVersion === 'gmcore') {
|
|
174
|
-
return this.
|
|
241
|
+
return this.determineUserActions();
|
|
175
242
|
}
|
|
176
243
|
else {
|
|
177
|
-
this.activeUserActions = 'termsandconditions';
|
|
244
|
+
this.activeUserActions = ['termsandconditions'];
|
|
178
245
|
this.isLoading = false;
|
|
179
246
|
}
|
|
247
|
+
if (this.translationUrl.length > 2) {
|
|
248
|
+
await getTranslations(this.translationUrl);
|
|
249
|
+
}
|
|
180
250
|
}
|
|
181
251
|
componentDidRender() {
|
|
182
252
|
// start custom styling area
|
|
@@ -190,16 +260,20 @@ const UserActionController$1 = /*@__PURE__*/ proxyCustomElement(class extends HT
|
|
|
190
260
|
// end custom styling area
|
|
191
261
|
}
|
|
192
262
|
render() {
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
263
|
+
const isMandatoryPresent = this.mandatoryActions.every(action => this.activeUserActions.includes(action));
|
|
264
|
+
if (isMandatoryPresent) {
|
|
265
|
+
this.userActionsValidated = !(this.mandatoryActionsChecked === this.mandatoryActions.length);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
this.userActionsValidated = false;
|
|
269
|
+
}
|
|
270
|
+
return (h("div", { class: "QueryReferenceContainer", ref: el => this.stylingContainer = el }, this.isLoading ? (h("slot", { name: 'spinner' })
|
|
271
|
+
&&
|
|
272
|
+
h("svg", { class: "spinner", viewBox: "0 0 50 50" }, h("circle", { class: "path", cx: "25", cy: "25", r: "20", fill: "none", "stroke-width": "5" }))) : (h("div", { class: "UserActionController" }, h("h2", { class: "UserConsentNotice" }, this.userNoticeText), h("div", { class: "PlayerLegislationWrapper" }, this.activeUserActions.map(action => (h("slot", { name: action }, h("player-user-consents", { slot: action, consentType: action, consentTitle: this.consentTitles[action], queried: this.queryFired, mandatory: this.mandatoryActions.includes(action), "client-styling": this.clientStyling }))))), this.includeSubmitButton &&
|
|
273
|
+
h("button", { class: "ConsentSubmitButton", disabled: this.userActionsValidated, onClick: () => this.handleApplyClick() }, this.submitButtonText)))));
|
|
201
274
|
}
|
|
202
275
|
static get watchers() { return {
|
|
276
|
+
"translationUrl": ["handleNewTranslations"],
|
|
203
277
|
"receivedQueryResponses": ["handleQueryResponse"]
|
|
204
278
|
}; }
|
|
205
279
|
static get style() { return userActionControllerCss; }
|
|
@@ -207,36 +281,34 @@ const UserActionController$1 = /*@__PURE__*/ proxyCustomElement(class extends HT
|
|
|
207
281
|
"endpoint": [513],
|
|
208
282
|
"userSession": [513, "user-session"],
|
|
209
283
|
"userId": [513, "user-id"],
|
|
284
|
+
"lang": [1537],
|
|
210
285
|
"includeSubmitButton": [516, "include-submit-button"],
|
|
211
286
|
"submitButtonText": [513, "submit-button-text"],
|
|
212
287
|
"userNoticeText": [513, "user-notice-text"],
|
|
213
|
-
"activeUserActions": [513, "active-user-actions"],
|
|
214
288
|
"gmVersion": [1, "gm-version"],
|
|
289
|
+
"translationUrl": [513, "translation-url"],
|
|
215
290
|
"clientStyling": [1537, "client-styling"],
|
|
216
291
|
"clientStylingUrl": [513, "client-styling-url"],
|
|
217
292
|
"queryFired": [32],
|
|
218
293
|
"readyActionsCount": [32],
|
|
294
|
+
"activeUserActions": [32],
|
|
295
|
+
"userActionsValidated": [32],
|
|
219
296
|
"receivedQueryResponses": [32],
|
|
220
297
|
"limitStylingAppends": [32],
|
|
221
|
-
"
|
|
222
|
-
"
|
|
223
|
-
}, [[0, "
|
|
298
|
+
"isLoading": [32],
|
|
299
|
+
"mandatoryActionsChecked": [32]
|
|
300
|
+
}, [[0, "userLegislationConsent", "userLegislationConsentHandler"]]]);
|
|
224
301
|
function defineCustomElement$1() {
|
|
225
302
|
if (typeof customElements === "undefined") {
|
|
226
303
|
return;
|
|
227
304
|
}
|
|
228
|
-
const components = ["user-action-controller", "player-
|
|
305
|
+
const components = ["user-action-controller", "player-user-consents"];
|
|
229
306
|
components.forEach(tagName => { switch (tagName) {
|
|
230
307
|
case "user-action-controller":
|
|
231
308
|
if (!customElements.get(tagName)) {
|
|
232
309
|
customElements.define(tagName, UserActionController$1);
|
|
233
310
|
}
|
|
234
311
|
break;
|
|
235
|
-
case "player-legislation-wrapper":
|
|
236
|
-
if (!customElements.get(tagName)) {
|
|
237
|
-
defineCustomElement$3();
|
|
238
|
-
}
|
|
239
|
-
break;
|
|
240
312
|
case "player-user-consents":
|
|
241
313
|
if (!customElements.get(tagName)) {
|
|
242
314
|
defineCustomElement$2();
|
package/dist/esm/loader.js
CHANGED
|
@@ -10,7 +10,7 @@ const patchEsm = () => {
|
|
|
10
10
|
const defineCustomElements = (win, options) => {
|
|
11
11
|
if (typeof window === 'undefined') return Promise.resolve();
|
|
12
12
|
return patchEsm().then(() => {
|
|
13
|
-
return bootstrapLazy([["player-
|
|
13
|
+
return bootstrapLazy([["player-user-consents_2",[[1,"user-action-controller",{"endpoint":[513],"userSession":[513,"user-session"],"userId":[513,"user-id"],"lang":[1537],"includeSubmitButton":[516,"include-submit-button"],"submitButtonText":[513,"submit-button-text"],"userNoticeText":[513,"user-notice-text"],"gmVersion":[1,"gm-version"],"translationUrl":[513,"translation-url"],"clientStyling":[1537,"client-styling"],"clientStylingUrl":[513,"client-styling-url"],"queryFired":[32],"readyActionsCount":[32],"activeUserActions":[32],"userActionsValidated":[32],"receivedQueryResponses":[32],"limitStylingAppends":[32],"isLoading":[32],"mandatoryActionsChecked":[32]},[[0,"userLegislationConsent","userLegislationConsentHandler"]]],[1,"player-user-consents",{"queried":[516],"consentType":[513,"consent-type"],"mandatory":[516],"consentTitle":[513,"consent-title"],"tcLink":[513,"tc-link"],"privacyLink":[513,"privacy-link"],"clientStyling":[1,"client-styling"],"textContent":[32],"limitStylingAppends":[32]}]]]], options);
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
16
|
|
|
@@ -1,36 +1,4 @@
|
|
|
1
|
-
import { r as registerInstance,
|
|
2
|
-
|
|
3
|
-
const playerLegislationWrapperCss = ":host{display:block}";
|
|
4
|
-
|
|
5
|
-
const PlayerLegislationWrapper = class {
|
|
6
|
-
constructor(hostRef) {
|
|
7
|
-
registerInstance(this, hostRef);
|
|
8
|
-
/**
|
|
9
|
-
* Client custom styling via inline style
|
|
10
|
-
*/
|
|
11
|
-
this.clientStyling = '';
|
|
12
|
-
this.limitStylingAppends = false;
|
|
13
|
-
this.setClientStyling = () => {
|
|
14
|
-
let sheet = document.createElement('style');
|
|
15
|
-
sheet.innerHTML = this.clientStyling;
|
|
16
|
-
this.stylingContainer.prepend(sheet);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
componentDidRender() {
|
|
20
|
-
// start custom styling area
|
|
21
|
-
if (!this.limitStylingAppends && this.stylingContainer) {
|
|
22
|
-
if (this.clientStyling)
|
|
23
|
-
this.setClientStyling();
|
|
24
|
-
this.limitStylingAppends = true;
|
|
25
|
-
}
|
|
26
|
-
// end custom styling area
|
|
27
|
-
}
|
|
28
|
-
render() {
|
|
29
|
-
const activeUAList = this.activeUserActions.replace(/ /g, '').split(',');
|
|
30
|
-
return (h("div", { class: "PlayerLegislationWrapper", ref: el => this.stylingContainer = el }, activeUAList.map(action => (h("slot", { name: action })))));
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
PlayerLegislationWrapper.style = playerLegislationWrapperCss;
|
|
1
|
+
import { r as registerInstance, c as createEvent, h } from './index-71f14530.js';
|
|
34
2
|
|
|
35
3
|
const playerUserConsentsCss = ":host{display:block}.ConsentTitle{margin-bottom:0.2rem;font-weight:600}.userConsent:hover{border-bottom:1px solid #000;cursor:pointer}.MandatoryItem{color:#f00;font-size:1.2rem}";
|
|
36
4
|
|
|
@@ -118,19 +86,84 @@ const PlayerUserConsents = class {
|
|
|
118
86
|
};
|
|
119
87
|
PlayerUserConsents.style = playerUserConsentsCss;
|
|
120
88
|
|
|
89
|
+
const DEFAULT_LANGUAGE = 'en';
|
|
90
|
+
const SUPPORTED_LANGUAGES = ['ro', 'en', 'cz', 'de', 'hr'];
|
|
91
|
+
const TRANSLATIONS = {
|
|
92
|
+
en: {
|
|
93
|
+
termsandconditions: 'Terms and Conditions',
|
|
94
|
+
sms: 'SMS marketing',
|
|
95
|
+
emailmarketing: 'Email marketing'
|
|
96
|
+
},
|
|
97
|
+
ro: {
|
|
98
|
+
termsandconditions: 'Terms and Conditions',
|
|
99
|
+
sms: 'SMS marketing',
|
|
100
|
+
emailmarketing: 'Email marketing'
|
|
101
|
+
},
|
|
102
|
+
hr: {
|
|
103
|
+
termsandconditions: 'Terms and Conditions',
|
|
104
|
+
sms: 'SMS marketing',
|
|
105
|
+
emailmarketing: 'Email marketing'
|
|
106
|
+
},
|
|
107
|
+
fr: {
|
|
108
|
+
termsandconditions: 'Terms and Conditions',
|
|
109
|
+
sms: 'SMS marketing',
|
|
110
|
+
emailmarketing: 'Email marketing'
|
|
111
|
+
},
|
|
112
|
+
cs: {
|
|
113
|
+
termsandconditions: 'Terms and Conditions',
|
|
114
|
+
sms: 'SMS marketing',
|
|
115
|
+
emailmarketing: 'Email marketing'
|
|
116
|
+
},
|
|
117
|
+
de: {
|
|
118
|
+
termsandconditions: 'Terms and Conditions',
|
|
119
|
+
sms: 'SMS marketing',
|
|
120
|
+
emailmarketing: 'Email marketing'
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
const getTranslations = (url) => {
|
|
124
|
+
// fetch url, get the data, replace the TRANSLATIONS content
|
|
125
|
+
return new Promise((resolve) => {
|
|
126
|
+
fetch(url)
|
|
127
|
+
.then((res) => res.json())
|
|
128
|
+
.then((data) => {
|
|
129
|
+
Object.keys(data).forEach((item) => {
|
|
130
|
+
for (let key in data[item]) {
|
|
131
|
+
TRANSLATIONS[item][key] = data[item][key];
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
resolve(true);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
const translate = (key, customLang, values) => {
|
|
139
|
+
const lang = customLang;
|
|
140
|
+
let translation = TRANSLATIONS[lang !== undefined && SUPPORTED_LANGUAGES.includes(lang) ? lang : DEFAULT_LANGUAGE][key];
|
|
141
|
+
if (values !== undefined) {
|
|
142
|
+
for (const [key, value] of Object.entries(values.values)) {
|
|
143
|
+
const regex = new RegExp(`{${key}}`, 'g');
|
|
144
|
+
translation = translation.replace(regex, value);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return translation;
|
|
148
|
+
};
|
|
149
|
+
|
|
121
150
|
const userActionControllerCss = ":host{display:block}.QueryReferenceContainer{height:100%;width:100%}.UserConsentNotice{font-size:1.2rem;font-weight:200;text-align:center}.CloseButton{width:25px;height:25px;align-self:flex-end}.UserActionController{font-family:Arial, Helvetica, sans-serif;font-weight:100;height:100%;width:100%;padding:1rem 1.5rem 2rem;background-color:#fff;display:flex;flex-direction:column;justify-content:space-between;border-radius:5%}.ConsentSubmitButton{font-size:1rem;padding:0.4rem 1.4rem;background:#fff;border:2px solid #000;color:#000;border-radius:5px;align-self:flex-end}.ConsentSubmitButton:disabled{border:2px solid #ccc;color:#ccc}@media screen and (max-width: 320px){.QueryReferenceContainer{font-size:0.8rem;color:blue}}.spinner{animation:rotate 2s linear infinite;z-index:2;position:absolute;top:50%;left:50%;margin:-25px 0 0 -25px;width:50px;height:50px}.spinner .path{stroke:var(--emfe-w-login-color-primary, var(--emfe-w-color-primary, #D0046C));stroke-linecap:round;animation:dash 1.5s ease-in-out infinite}@keyframes rotate{100%{transform:rotate(360deg)}}@keyframes dash{0%{stroke-dasharray:1, 150;stroke-dashoffset:0}50%{stroke-dasharray:90, 150;stroke-dashoffset:-35}100%{stroke-dasharray:90, 150;stroke-dashoffset:-124}}";
|
|
122
151
|
|
|
123
152
|
const UserActionController = class {
|
|
124
153
|
constructor(hostRef) {
|
|
125
154
|
registerInstance(this, hostRef);
|
|
126
155
|
/**
|
|
127
|
-
*
|
|
156
|
+
* Language
|
|
128
157
|
*/
|
|
129
|
-
this.
|
|
158
|
+
this.lang = 'en';
|
|
130
159
|
/**
|
|
131
160
|
* Select GM version
|
|
132
161
|
*/
|
|
133
162
|
this.gmVersion = '';
|
|
163
|
+
/**
|
|
164
|
+
* Translation url
|
|
165
|
+
*/
|
|
166
|
+
this.translationUrl = '';
|
|
134
167
|
/**
|
|
135
168
|
* Client custom styling via inline style
|
|
136
169
|
*/
|
|
@@ -144,17 +177,19 @@ const UserActionController = class {
|
|
|
144
177
|
*/
|
|
145
178
|
this.queryFired = false;
|
|
146
179
|
this.readyActionsCount = 0;
|
|
180
|
+
this.activeUserActions = [];
|
|
181
|
+
this.userActionsValidated = true;
|
|
147
182
|
this.receivedQueryResponses = 0;
|
|
148
183
|
this.limitStylingAppends = false;
|
|
149
184
|
this.isLoading = true;
|
|
185
|
+
this.mandatoryActionsChecked = 0;
|
|
186
|
+
//for now this variable is hardcoded bcs we have only terms and conditions mandatory and we dont receive with these new functionality the mandatory actions
|
|
150
187
|
this.mandatoryActions = ['termsandconditions'];
|
|
151
|
-
this.requiredActionsCount = 0;
|
|
152
|
-
this.expectedQueryResponses = 0;
|
|
153
188
|
this.userActions = [];
|
|
154
189
|
this.consentTitles = {
|
|
155
|
-
termsandconditions:
|
|
156
|
-
sms:
|
|
157
|
-
emailmarketing:
|
|
190
|
+
termsandconditions: translate('termsandconditions', this.lang),
|
|
191
|
+
sms: translate('sms', this.lang),
|
|
192
|
+
emailmarketing: translate('emailmarketing', this.lang)
|
|
158
193
|
};
|
|
159
194
|
this.setClientStyling = () => {
|
|
160
195
|
let sheet = document.createElement('style');
|
|
@@ -176,44 +211,45 @@ const UserActionController = class {
|
|
|
176
211
|
});
|
|
177
212
|
};
|
|
178
213
|
}
|
|
214
|
+
handleNewTranslations() {
|
|
215
|
+
getTranslations(this.translationUrl);
|
|
216
|
+
}
|
|
179
217
|
handleQueryResponse() {
|
|
180
|
-
if (this.receivedQueryResponses === this.
|
|
218
|
+
if (this.receivedQueryResponses === this.activeUserActions.length) {
|
|
181
219
|
this.updateUserConsents();
|
|
182
220
|
}
|
|
183
221
|
}
|
|
184
|
-
hasToSetConsentsHandler(_) {
|
|
185
|
-
this.hasToSetConsents = true;
|
|
186
|
-
}
|
|
187
222
|
userLegislationConsentHandler(event) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
else
|
|
193
|
-
this.readyActionsCount--;
|
|
223
|
+
const actionType = event.detail.type;
|
|
224
|
+
const actionTypeChecked = event.detail.value;
|
|
225
|
+
if (this.mandatoryActions.includes(actionType) && this.queryFired === false) {
|
|
226
|
+
actionTypeChecked === true ? this.mandatoryActionsChecked++ : this.mandatoryActionsChecked--;
|
|
194
227
|
}
|
|
195
228
|
// Register final user choices only if we're ready to update
|
|
196
229
|
if (this.queryFired) {
|
|
197
|
-
this.userActions.push({ tagCode:
|
|
230
|
+
this.userActions.push({ tagCode: actionType, status: actionTypeChecked ? 'Accepted' : 'Denied' });
|
|
198
231
|
this.receivedQueryResponses++;
|
|
199
232
|
}
|
|
200
233
|
}
|
|
201
|
-
|
|
202
|
-
const url = new URL(`${this.endpoint}/v1/player/
|
|
234
|
+
determineUserActions() {
|
|
235
|
+
const url = new URL(`${this.endpoint}/v1/player/${this.userId}/consent`);
|
|
236
|
+
const headers = new Headers();
|
|
237
|
+
headers.append('X-SessionId', this.userSession);
|
|
203
238
|
let requestOptions;
|
|
204
239
|
requestOptions = {
|
|
205
240
|
method: 'GET',
|
|
206
|
-
headers
|
|
207
|
-
'X-SessionId': `${this.userSession}`,
|
|
208
|
-
},
|
|
241
|
+
headers
|
|
209
242
|
};
|
|
210
243
|
if (url && requestOptions) {
|
|
211
244
|
return fetch(url.href, requestOptions)
|
|
212
245
|
.then(res => res.json())
|
|
213
246
|
.then(data => {
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
247
|
+
const actionItems = data.items;
|
|
248
|
+
actionItems.forEach(element => {
|
|
249
|
+
if (element.status === 'Expired') {
|
|
250
|
+
this.activeUserActions.push(element.tagCode);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
217
253
|
this.isLoading = false;
|
|
218
254
|
})
|
|
219
255
|
.catch(error => {
|
|
@@ -283,14 +319,17 @@ const UserActionController = class {
|
|
|
283
319
|
handleApplyClick() {
|
|
284
320
|
this.queryFired = true;
|
|
285
321
|
}
|
|
286
|
-
componentWillLoad() {
|
|
322
|
+
async componentWillLoad() {
|
|
287
323
|
if (this.gmVersion === 'gmcore') {
|
|
288
|
-
return this.
|
|
324
|
+
return this.determineUserActions();
|
|
289
325
|
}
|
|
290
326
|
else {
|
|
291
|
-
this.activeUserActions = 'termsandconditions';
|
|
327
|
+
this.activeUserActions = ['termsandconditions'];
|
|
292
328
|
this.isLoading = false;
|
|
293
329
|
}
|
|
330
|
+
if (this.translationUrl.length > 2) {
|
|
331
|
+
await getTranslations(this.translationUrl);
|
|
332
|
+
}
|
|
294
333
|
}
|
|
295
334
|
componentDidRender() {
|
|
296
335
|
// start custom styling area
|
|
@@ -304,19 +343,23 @@ const UserActionController = class {
|
|
|
304
343
|
// end custom styling area
|
|
305
344
|
}
|
|
306
345
|
render() {
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
346
|
+
const isMandatoryPresent = this.mandatoryActions.every(action => this.activeUserActions.includes(action));
|
|
347
|
+
if (isMandatoryPresent) {
|
|
348
|
+
this.userActionsValidated = !(this.mandatoryActionsChecked === this.mandatoryActions.length);
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
this.userActionsValidated = false;
|
|
352
|
+
}
|
|
353
|
+
return (h("div", { class: "QueryReferenceContainer", ref: el => this.stylingContainer = el }, this.isLoading ? (h("slot", { name: 'spinner' })
|
|
354
|
+
&&
|
|
355
|
+
h("svg", { class: "spinner", viewBox: "0 0 50 50" }, h("circle", { class: "path", cx: "25", cy: "25", r: "20", fill: "none", "stroke-width": "5" }))) : (h("div", { class: "UserActionController" }, h("h2", { class: "UserConsentNotice" }, this.userNoticeText), h("div", { class: "PlayerLegislationWrapper" }, this.activeUserActions.map(action => (h("slot", { name: action }, h("player-user-consents", { slot: action, consentType: action, consentTitle: this.consentTitles[action], queried: this.queryFired, mandatory: this.mandatoryActions.includes(action), "client-styling": this.clientStyling }))))), this.includeSubmitButton &&
|
|
356
|
+
h("button", { class: "ConsentSubmitButton", disabled: this.userActionsValidated, onClick: () => this.handleApplyClick() }, this.submitButtonText)))));
|
|
315
357
|
}
|
|
316
358
|
static get watchers() { return {
|
|
359
|
+
"translationUrl": ["handleNewTranslations"],
|
|
317
360
|
"receivedQueryResponses": ["handleQueryResponse"]
|
|
318
361
|
}; }
|
|
319
362
|
};
|
|
320
363
|
UserActionController.style = userActionControllerCss;
|
|
321
364
|
|
|
322
|
-
export {
|
|
365
|
+
export { PlayerUserConsents as player_user_consents, UserActionController as user_action_controller };
|
|
@@ -13,5 +13,5 @@ const patchBrowser = () => {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
patchBrowser().then(options => {
|
|
16
|
-
return bootstrapLazy([["player-
|
|
16
|
+
return bootstrapLazy([["player-user-consents_2",[[1,"user-action-controller",{"endpoint":[513],"userSession":[513,"user-session"],"userId":[513,"user-id"],"lang":[1537],"includeSubmitButton":[516,"include-submit-button"],"submitButtonText":[513,"submit-button-text"],"userNoticeText":[513,"user-notice-text"],"gmVersion":[1,"gm-version"],"translationUrl":[513,"translation-url"],"clientStyling":[1537,"client-styling"],"clientStylingUrl":[513,"client-styling-url"],"queryFired":[32],"readyActionsCount":[32],"activeUserActions":[32],"userActionsValidated":[32],"receivedQueryResponses":[32],"limitStylingAppends":[32],"isLoading":[32],"mandatoryActionsChecked":[32]},[[0,"userLegislationConsent","userLegislationConsentHandler"]]],[1,"player-user-consents",{"queried":[516],"consentType":[513,"consent-type"],"mandatory":[516],"consentTitle":[513,"consent-title"],"tcLink":[513,"tc-link"],"privacyLink":[513,"privacy-link"],"clientStyling":[1,"client-styling"],"textContent":[32],"limitStylingAppends":[32]}]]]], options);
|
|
17
17
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import '@everymatrix/player-legislation-wrapper';
|
|
2
1
|
import '@everymatrix/player-user-consents';
|
|
3
2
|
interface LegislationConsentEvent {
|
|
4
3
|
type: string;
|
|
@@ -17,6 +16,10 @@ export declare class UserActionController {
|
|
|
17
16
|
* user id required for the update call
|
|
18
17
|
*/
|
|
19
18
|
userId: string;
|
|
19
|
+
/**
|
|
20
|
+
* Language
|
|
21
|
+
*/
|
|
22
|
+
lang: string;
|
|
20
23
|
/**
|
|
21
24
|
* whether or not to include the submit button (in case we want to compose a different )
|
|
22
25
|
*/
|
|
@@ -29,14 +32,14 @@ export declare class UserActionController {
|
|
|
29
32
|
* the title of the action group
|
|
30
33
|
*/
|
|
31
34
|
userNoticeText: string;
|
|
32
|
-
/**
|
|
33
|
-
* which user action widgets are included
|
|
34
|
-
*/
|
|
35
|
-
activeUserActions: string;
|
|
36
35
|
/**
|
|
37
36
|
* Select GM version
|
|
38
37
|
*/
|
|
39
38
|
gmVersion: string;
|
|
39
|
+
/**
|
|
40
|
+
* Translation url
|
|
41
|
+
*/
|
|
42
|
+
translationUrl: string;
|
|
40
43
|
/**
|
|
41
44
|
* Client custom styling via inline style
|
|
42
45
|
*/
|
|
@@ -45,25 +48,25 @@ export declare class UserActionController {
|
|
|
45
48
|
* Client custom styling via url
|
|
46
49
|
*/
|
|
47
50
|
clientStylingUrl: string;
|
|
51
|
+
handleNewTranslations(): void;
|
|
48
52
|
handleQueryResponse(): void;
|
|
49
|
-
hasToSetConsentsHandler(_: CustomEvent): void;
|
|
50
53
|
userLegislationConsentHandler(event: CustomEvent<LegislationConsentEvent>): void;
|
|
51
54
|
/**
|
|
52
55
|
* Which actions are required in order to activate the "Apply" button. Other actions are considered optional.
|
|
53
56
|
*/
|
|
54
57
|
queryFired: boolean;
|
|
55
58
|
readyActionsCount: number;
|
|
59
|
+
activeUserActions: Array<string>;
|
|
60
|
+
userActionsValidated: boolean;
|
|
56
61
|
receivedQueryResponses: number;
|
|
57
62
|
private limitStylingAppends;
|
|
58
|
-
hasToSetConsents: boolean;
|
|
59
63
|
private isLoading;
|
|
64
|
+
private mandatoryActionsChecked;
|
|
60
65
|
private mandatoryActions;
|
|
61
|
-
private requiredActionsCount;
|
|
62
|
-
private expectedQueryResponses;
|
|
63
66
|
private userActions;
|
|
64
67
|
private stylingContainer;
|
|
65
68
|
private consentTitles;
|
|
66
|
-
|
|
69
|
+
determineUserActions(): Promise<void>;
|
|
67
70
|
updateUserConsents(): void;
|
|
68
71
|
handleApplyClick(): void;
|
|
69
72
|
componentWillLoad(): Promise<void>;
|