Skip to content

Commit

Permalink
SAS-664: merge from tfat-1594
Browse files Browse the repository at this point in the history
  • Loading branch information
tswarmerdam-mx committed Aug 19, 2024
2 parents 1b264da + 537e8a9 commit c44d40b
Show file tree
Hide file tree
Showing 14 changed files with 806 additions and 775 deletions.
Binary file modified AI Bot Starter App.mpr
Binary file not shown.
208 changes: 104 additions & 104 deletions javascriptsource/feedbackmodule/actions/GetStorageItemObject.js
Original file line number Diff line number Diff line change
@@ -1,104 +1,104 @@
// 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 AsyncStorage from '@react-native-community/async-storage';

// BEGIN EXTRA CODE
// END EXTRA CODE

/**
* What does this JavaScript action do?
*
* Get locally stored JSON object stored in clients internet browser. Identified by a unique key. Can be accessed by the GetStorageItemObject action. Please note that users can clear the device storage.
* @param {string} key - This field is required.
* @param {string} entity - This field is required.
* @returns {Promise.<MxObject>}
*/
export async function GetStorageItemObject(key, entity) {
// BEGIN USER CODE
if (!key) {
return Promise.reject(new Error("Input parameter 'Key' is required"));
}
if (!entity) {
return Promise.reject(new Error("Input parameter 'Entity' is required"));
}
return getItem(key).then(result => {
if (result === null) {
return Promise.reject(new Error(`Storage item '${key}' does not exist`));
}
const value = JSON.parse(result);
return getOrCreateMxObject(entity, value).then(newObject => {
const newValue = serializeMxObject(newObject);
return setItem(key, JSON.stringify(newValue)).then(() => newObject);
});
});
function getItem(key) {
if (navigator && navigator.product === "ReactNative") {
return AsyncStorage.getItem(key);
}
if (window) {
const value = window.localStorage.getItem(key);
return Promise.resolve(value);
}
return Promise.reject(new Error("No storage API available"));
}
function setItem(key, value) {
if (navigator && navigator.product === "ReactNative") {
return AsyncStorage.setItem(key, value);
}
if (window) {
window.localStorage.setItem(key, value);
return Promise.resolve();
}
return Promise.reject(new Error("No storage API available"));
}
function getOrCreateMxObject(entity, value) {
return getMxObject(value.guid).then(existingObject => {
if (existingObject) {
return existingObject;
}
else {
return createMxObject(entity, value);
}
});
}
function getMxObject(guid) {
return new Promise((resolve, reject) => {
mx.data.get({
guid,
callback: mxObject => resolve(mxObject),
error: error => reject(error)
});
});
}
function createMxObject(entity, value) {
return new Promise((resolve, reject) => {
mx.data.create({
entity,
callback: mxObject => {
Object.keys(value)
.filter(attribute => attribute !== "guid")
.forEach(attributeName => {
const attributeValue = value[attributeName];
mxObject.set(attributeName, attributeValue);
});
resolve(mxObject);
},
error: () => reject(new Error(`Could not create '${entity}' object`))
});
});
}
function serializeMxObject(object) {
return object.getAttributes().reduce((accumulator, attributeName) => {
accumulator[attributeName] = object.get(attributeName);
return accumulator;
}, { guid: object.getGuid() });
}
// END USER CODE
}
// 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 AsyncStorage from '@react-native-community/async-storage';

// BEGIN EXTRA CODE
// END EXTRA CODE

/**
* What does this JavaScript action do?
*
* Get locally stored JSON object stored in clients internet browser. Identified by a unique key. Can be accessed by the GetStorageItemObject action. Please note that users can clear the device storage.
* @param {string} key - This field is required.
* @param {string} entity - This field is required.
* @returns {Promise.<MxObject>}
*/
export async function GetStorageItemObject(key, entity) {
// BEGIN USER CODE
if (!key) {
return Promise.reject(new Error("Input parameter 'Key' is required"));
}
if (!entity) {
return Promise.reject(new Error("Input parameter 'Entity' is required"));
}
return getItem(key).then(result => {
if (result === null) {
return Promise.reject(new Error(`Storage item '${key}' does not exist`));
}
const value = JSON.parse(result);
return getOrCreateMxObject(entity, value).then(newObject => {
const newValue = serializeMxObject(newObject);
return setItem(key, JSON.stringify(newValue)).then(() => newObject);
});
});
function getItem(key) {
if (navigator && navigator.product === "ReactNative") {
return AsyncStorage.getItem(key);
}
if (window) {
const value = window.localStorage.getItem(key);
return Promise.resolve(value);
}
return Promise.reject(new Error("No storage API available"));
}
function setItem(key, value) {
if (navigator && navigator.product === "ReactNative") {
return AsyncStorage.setItem(key, value);
}
if (window) {
window.localStorage.setItem(key, value);
return Promise.resolve();
}
return Promise.reject(new Error("No storage API available"));
}
function getOrCreateMxObject(entity, value) {
return getMxObject(value.guid).then(existingObject => {
if (existingObject) {
return existingObject;
}
else {
return createMxObject(entity, value);
}
});
}
function getMxObject(guid) {
return new Promise((resolve, reject) => {
mx.data.get({
guid,
callback: mxObject => resolve(mxObject),
error: error => reject(error)
});
});
}
function createMxObject(entity, value) {
return new Promise((resolve, reject) => {
mx.data.create({
entity,
callback: mxObject => {
Object.keys(value)
.filter(attribute => attribute !== "guid")
.forEach(attributeName => {
const attributeValue = value[attributeName];
mxObject.set(attributeName, attributeValue);
});
resolve(mxObject);
},
error: () => reject(new Error(`Could not create '${entity}' object`))
});
});
}
function serializeMxObject(object) {
return object.getAttributes().reduce((accumulator, attributeName) => {
accumulator[attributeName] = object.get(attributeName);
return accumulator;
}, { guid: object.getGuid() });
}
// END USER CODE
}
144 changes: 72 additions & 72 deletions javascriptsource/feedbackmodule/actions/JS_PopulateFeedbackMetadata.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
// 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";

// BEGIN EXTRA CODE
const handleUserRoles = async () => {
if(!mx) return undefined;
try {
return await mx.session.getUserRoleNames();
} catch (error){
console.error("Error getting user role names", error);
return undefined;
}
};
const handlePagePath = async () => {
if(!mx) return undefined;
try {
const mendixVersion = mx.version
const mendixMajorVersion = mendixVersion.split('.')[0];
switch(mendixMajorVersion) {
case '9':
case '10':
return mx.ui.getContentForm().path.toString();
default:
return undefined;
};
} catch {
console.error("Error getting page path", 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("Error setting meta data", error);
}
// END USER CODE
}
// 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";

// BEGIN EXTRA CODE
const handleUserRoles = async () => {
if(!mx) return undefined;
try {
return await mx.session.getUserRoleNames();
} catch (error){
console.error("Error getting user role names", error);
return undefined;
}
};
const handlePagePath = async () => {
if(!mx) return undefined;
try {
const mendixVersion = mx.version
const mendixMajorVersion = mendixVersion.split('.')[0];
switch(mendixMajorVersion) {
case '9':
case '10':
return mx.ui.getContentForm().path.toString();
default:
return undefined;
};
} catch {
console.error("Error getting page path", 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("Error setting meta data", error);
}
// END USER CODE
}
Loading

0 comments on commit c44d40b

Please sign in to comment.