From 99aa12bd3f645b664f88826e1dde5b1cb555ebcc Mon Sep 17 00:00:00 2001 From: Johannes Hoermann <j.hoermann@adito.de> Date: Fri, 26 Apr 2019 10:49:37 +0200 Subject: [PATCH] targetConsumer in all Object_entity-Providers --- .../target_id/linkedContextProcess.js | 2 +- entity/Object_entity/Object_entity.aod | 1 + .../allobjects/targetConsumerProcess.js | 27 ++---------------- .../filteredobjects/targetConsumerProcess.js | 10 +++++++ process/Context_lib/process.js | 28 +++++++++++++++++++ 5 files changed, 43 insertions(+), 25 deletions(-) create mode 100644 entity/Object_entity/entityfields/filteredobjects/targetConsumerProcess.js diff --git a/entity/ObjectTree_entity/entityfields/target_id/linkedContextProcess.js b/entity/ObjectTree_entity/entityfields/target_id/linkedContextProcess.js index 1309ba4e92..215d53285d 100644 --- a/entity/ObjectTree_entity/entityfields/target_id/linkedContextProcess.js +++ b/entity/ObjectTree_entity/entityfields/target_id/linkedContextProcess.js @@ -5,4 +5,4 @@ import("Context_lib"); if (vars.get("$field.TARGET_CONTEXT")) { result.string(ContextUtils.getContextName(vars.get("$field.TARGET_CONTEXT"))); -} +} \ No newline at end of file diff --git a/entity/Object_entity/Object_entity.aod b/entity/Object_entity/Object_entity.aod index 99ed958580..a1759bc528 100644 --- a/entity/Object_entity/Object_entity.aod +++ b/entity/Object_entity/Object_entity.aod @@ -133,6 +133,7 @@ <entityProvider> <name>FilteredObjects</name> <fieldType>DEPENDENCY_IN</fieldType> + <targetConsumerProcess>%aditoprj%/entity/Object_entity/entityfields/filteredobjects/targetConsumerProcess.js</targetConsumerProcess> <dependencies> <entityDependency> <name>e644a709-cc8f-425e-bef2-9c51eea9bbe9</name> diff --git a/entity/Object_entity/entityfields/allobjects/targetConsumerProcess.js b/entity/Object_entity/entityfields/allobjects/targetConsumerProcess.js index 1a9d1e2e9d..8ba22ed45d 100644 --- a/entity/Object_entity/entityfields/allobjects/targetConsumerProcess.js +++ b/entity/Object_entity/entityfields/allobjects/targetConsumerProcess.js @@ -4,28 +4,7 @@ import("Context_lib"); if (vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param")) { - switch(vars.get("$param.ObjectType_param")) - { - case ContextUtils.getContextName("Organisation"): - result.string("Organisations"); - break; - case ContextUtils.getContextName("Person"): - result.string("Persons"); - break; - case ContextUtils.getContextName("Offer"): - result.string("Offers"); - break; - case ContextUtils.getContextName("Order"): - result.string("Orders"); - break; - case ContextUtils.getContextName("Product"): - result.string("Products"); - break; - case ContextUtils.getContextName("Contract"): - result.string("Contracts"); - break; - case ContextUtils.getContextName("Salesproject"): - result.string("Salesprojects"); - break; - } + var consumer = ContextUtils.getContextConsumer(vars.get("$param.ObjectType_param")); + if (consumer) + result.string(consumer); } \ No newline at end of file diff --git a/entity/Object_entity/entityfields/filteredobjects/targetConsumerProcess.js b/entity/Object_entity/entityfields/filteredobjects/targetConsumerProcess.js new file mode 100644 index 0000000000..8ba22ed45d --- /dev/null +++ b/entity/Object_entity/entityfields/filteredobjects/targetConsumerProcess.js @@ -0,0 +1,10 @@ +import("system.vars"); +import("system.result"); +import("Context_lib"); + +if (vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param")) +{ + var consumer = ContextUtils.getContextConsumer(vars.get("$param.ObjectType_param")); + if (consumer) + result.string(consumer); +} \ No newline at end of file diff --git a/process/Context_lib/process.js b/process/Context_lib/process.js index 0890b12f0f..238aa4b1ac 100644 --- a/process/Context_lib/process.js +++ b/process/Context_lib/process.js @@ -54,6 +54,34 @@ ContextUtils.getContextName = function(pContextId) return pContextId; } +/** + * Returns the Name of the correct Consumer or null + * + * @param {String} pContextId the id of a context + * @return {String|null} Name of the correct Consumer + */ +ContextUtils.getContextConsumer = function(pContextId) +{ + // TODO: is there a better solution without a swiutch case? maybe metadata of context / entity + switch(pContextId) + { + case ContextUtils.getContextName("Organisation"): + return "Organisations"; + case ContextUtils.getContextName("Person"): + return "Persons"; + case ContextUtils.getContextName("Offer"): + return "Offers"; + case ContextUtils.getContextName("Order"): + return "Orders"; + case ContextUtils.getContextName("Product"): + return "Products"; + case ContextUtils.getContextName("Contract"): + return "Contracts"; + case ContextUtils.getContextName("Salesproject"): + return "Salesprojects"; + } +} + /** * * @param {Boolean} [pFilter=false] filter only for contexts which have a mapping in ContextUtils.getSelectMap -- GitLab