-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJS_PopulateFeedbackMetadata.js
More file actions
94 lines (87 loc) · 3.06 KB
/
JS_PopulateFeedbackMetadata.js
File metadata and controls
94 lines (87 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
import "mx-global";
import { Big } from "big.js";
import { getUserRoleNames } from "mx-api/session";
import { ui, session } from "mx-api";
// BEGIN EXTRA CODE
const handleUserRoles = async () => {
try {
let userRoles;
if (
typeof mx !== "undefined" &&
typeof mx.session === "object" &&
typeof mx.session.getUserRoleNames === "function"
) {
userRoles = mx.session.getUserRoleNames();
} else if (typeof getUserRoleNames !== "function" || getUserRoleNames === undefined) {
userRoles = getUserRoleNames();
} else {
console.error("Feedback module cannot access a valid user role retrieval function.");
return undefined;
}
if (!Array.isArray(userRoles) || userRoles.length === 0) {
console.error("User roles not available or empty.");
return undefined;
}
return userRoles[0];
} catch (error) {
console.error("Feedback module failed to get the user role name.", error);
return undefined;
}
};
const handlePagePath = async () => {
try {
if (
typeof mx !== "undefined" &&
typeof mx.ui.getContentForm === "function" &&
typeof mx.ui.getContentForm().path !== "undefined"
) {
return mx.ui.getContentForm().path;
} else {
return window.history.state.pageName;
}
} catch(error) {
console.error("Feedback module cannot get the Mendix App page name", error);
return undefined;
}
};
// END EXTRA CODE
/**
* What does this JavaScript action do?
*
* Returns meta data from the clients internet browser.
*
* This includes;
*
* ActiveUserRoles
* PageName
* EnvironmentURL
* Browser
* ScreenWidth
* ScreenHeight
* @param {MxObject} feedback
* @returns {Promise.<MxObject>}
*/
export async function JS_PopulateFeedbackMetadata(feedback) {
// BEGIN USER CODE
try {
const userRoles = await handleUserRoles();
const pagePath = await handlePagePath();
feedback.set("ActiveUserRoles", userRoles || "");
feedback.set("PageName", pagePath || "");
feedback.set("EnvironmentURL", window.location.href || "");
feedback.set("Browser", navigator.userAgent || "");
feedback.set("ScreenWidth", window.screen.width || "");
feedback.set("ScreenHeight", window.screen.height || "");
return feedback;
} catch (error) {
console.error("Feedback Module cannot correctly set meta data.", error);
};
// END USER CODE
}