Skip to content
Snippets Groups Projects
Commit 24f9df75 authored by S.Listl's avatar S.Listl
Browse files

Attribute translation

parent ac3614a1
No related branches found
No related tags found
No related merge requests found
......@@ -97,6 +97,14 @@
<name>AttributeCount_param</name>
<expose v="false" />
</entityParameter>
<entityParameter>
<name>ObjectType_param</name>
<expose v="false" />
</entityParameter>
<entityParameter>
<name>GetGroups_param</name>
<expose v="false" />
</entityParameter>
</children>
</entityProvider>
<entityParameter>
......@@ -255,7 +263,7 @@
<entityParameter>
<name>GetGroups_param</name>
<valueProcess>%aditoprj%/entity/Attribute_entity/entityfields/attributegroups/children/getgroups_param/valueProcess.js</valueProcess>
<expose v="true" />
<expose v="false" />
</entityParameter>
<entityParameter>
<name>AttrParentId_param</name>
......@@ -265,6 +273,10 @@
<name>AttributeCount_param</name>
<expose v="false" />
</entityParameter>
<entityParameter>
<name>ObjectType_param</name>
<expose v="false" />
</entityParameter>
</children>
</entityProvider>
<entityConsumer>
......
......@@ -13,6 +13,7 @@ var getGroups = vars.exists("$param.GetGroups_param") && vars.get("$param.GetGro
var objectType = vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param");
var parentType = vars.exists("$param.AttrParentType_param") && vars.get("$param.AttrParentType_param");
var fetchUsages = true;
var translateName = false;
var uidTableAlias = "UIDROW";
var sqlSelect = "select UIDROW.AB_ATTRIBUTEID, UIDROW.ATTRIBUTE_PARENT_ID, UIDROW.ATTRIBUTE_ACTIVE, UIDROW.DROPDOWNDEFINITION, UIDROW.SORTING, UIDROW.ATTRIBUTE_TYPE, "
......@@ -70,7 +71,8 @@ else if (objectType) //if there's an objectType, it comes from the AttributeRel
else // do not return anything, if parameter is there but an empty array
condition.and("1=2");
fetchUsages = false;
fetchUsages = false;
translateName = true;
}
//when there are filters selected, add them to the conditon
......@@ -101,11 +103,11 @@ if (fetchUsages) //this query is only necessary in Attribute, not in AttributeRe
var attributes = db.table(condition.buildSql(sqlSelect, "1=1", sqlOrder));
var nameCache = {};
result.object(_buildAttributeTable(attributes, usages));
result.object(_buildAttributeTable(attributes, usages, translateName));
//sorts the records in a way that a tree can be built and adds values
function _buildAttributeTable (pAttributes, pUsages)
function _buildAttributeTable (pAttributes, pUsages, pTranslate)
{
var rows = {};
var allIds = {};
......@@ -142,9 +144,13 @@ function _buildAttributeTable (pAttributes, pUsages)
return translate.text(usage);
}).join(", ");
}
var fullName = displaySimpleName
? rowData[8]
: _getFullName(rowData[8], rowData[9], rowData[10], rowData[11], rowData[12]);
var fullName;
if (displaySimpleName)
fullName = pTranslate
? translate.text(rowData[8])
: rowData[8];
else
fullName = _getFullName(rowData[8], rowData[9], rowData[10], rowData[11], rowData[12], pTranslate);
rowData.splice(10, 3, fullName);
sortedArray[rows[i].index] = rowData;
}
......@@ -156,16 +162,23 @@ function _buildAttributeTable (pAttributes, pUsages)
* builds the full attribute name from the pre-loaded parent names and adds all parent names
* if required
*/
function _getFullName (pAttributeName, pParent1Name, pParent2Name, pParent3Name, pParent4Id)
function _getFullName (pAttributeName, pParent1Name, pParent2Name, pParent3Name, pParent4Id, pTranslate)
{
var parent4FullName;
if (pParent4Id && pParent4Id in nameCache)
parent4FullName = nameCache[pParent4Id];
else
{
parent4FullName = pParent4Id ? AttributeUtil.getFullAttributeName(pParent4Id) : null;
parent4FullName = pParent4Id ? AttributeUtil.getFullAttributeName(pParent4Id, false, pTranslate) : null;
nameCache[pParent4Id] = parent4FullName;
}
if (pTranslate)
{
pAttributeName = translate.text(pAttributeName);
pParent1Name = translate.text(pParent1Name);
pParent2Name = translate.text(pParent2Name);
pParent3Name = translate.text(pParent3Name);
}
pAttributeName = ArrayUtils.joinNonEmptyFields([parent4FullName, pParent3Name, pParent2Name, pParent1Name, pAttributeName], " / ");
return pAttributeName;
......
import("system.result");
import("system.vars");
import("system.tools");
var userTitle = vars.exists("$param.UserTitle_param") && vars.get("$param.UserTitle_param");
var role = vars.get("$field.ROLE");
if (userTitle && tools.existUsers(userTitle))
{
var user = tools.getUser(userTitle);
var roles = tools.getRoles(userTitle);
var roleObj = {};
roles = [role].concat(roles)
.filter(function (role)
{
var exists = role in roleObj;
roleObj[role] = true;
return !exists;
});
user[tools.ROLES] = roles;
tools.updateUser(user);
import("system.result");
import("system.vars");
import("system.tools");
var userTitle = vars.exists("$param.UserTitle_param") && vars.get("$param.UserTitle_param");
var role = vars.get("$field.ROLE");
if (userTitle && tools.existUsers(userTitle))
{
var user = tools.getUser(userTitle);
var roles = tools.getRoles(userTitle);
var roleObj = {};
roles = [role].concat(roles)
.filter(function (role)
{
var exists = role in this;
this[role] = true;
return !exists;
}, roleObj);
user[tools.ROLES] = roles;
tools.updateUser(user);
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<neonView xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.1">
<name>EmployeeRoleFilter_view</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<layout>
<boxLayout>
<name>layout</name>
</boxLayout>
</layout>
<children>
<tableViewTemplate>
<name>Table</name>
<autoNewRow v="true" />
<entityField>#ENTITY</entityField>
<columns>
<neonTableColumn>
<name>ab1c8d39-fc29-42e8-8b8e-3557d544b272</name>
<entityField>ROLE</entityField>
</neonTableColumn>
</columns>
</tableViewTemplate>
</children>
</neonView>
<?xml version="1.0" encoding="UTF-8"?>
<neonView xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.1">
<name>EmployeeRoleFilter_view</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<layout>
<boxLayout>
<name>layout</name>
</boxLayout>
</layout>
<children>
<tableViewTemplate>
<name>Table</name>
<inlineEdit v="true" />
<autoNewRow v="true" />
<entityField>#ENTITY</entityField>
<columns>
<neonTableColumn>
<name>ab1c8d39-fc29-42e8-8b8e-3557d544b272</name>
<entityField>ROLE</entityField>
</neonTableColumn>
</columns>
</tableViewTemplate>
</children>
</neonView>
......@@ -78,18 +78,21 @@ AttributeUtil.getPossibleAttributes = function (pObjectType, pIncludeGroups, pFi
*
* @param {String} pAttributeId the id of the attribute
* @param {Boolean} [pSimpleName=false] Use only the name of the attribute and not the names of the parents.
* @param {Boolean} [pTranslate=true] translate the name
*
* @return {String} the name of the attribute
*/
AttributeUtil.getFullAttributeName = function (pAttributeId, pSimpleName)
AttributeUtil.getFullAttributeName = function (pAttributeId, pSimpleName, pTranslate)
{
if (pSimpleName == undefined)
if (pSimpleName === undefined)
pSimpleName = false;
if (pTranslate === undefined)
pTranslate = true;
if (!pAttributeId)
return "";
if (pSimpleName)
return AttributeUtil.getSimpleAttributeName(pAttributeId);
return AttributeUtil.getSimpleAttributeName(pAttributeId, pTranslate);
var attributeNames = [];
var attribute;
do {
......@@ -113,6 +116,13 @@ AttributeUtil.getFullAttributeName = function (pAttributeId, pSimpleName)
pAttributeId = "";
} while (pAttributeId);
if (pTranslate)
{
for (let i = 0; i < attributeNames.length; i++)
{
attributeNames[i] = translate.text(attributeNames[i]);
}
}
return attributeNames.reverse().join(" / ");
}
......@@ -120,16 +130,18 @@ AttributeUtil.getFullAttributeName = function (pAttributeId, pSimpleName)
* returns the name of an attribute
*
* @param {String} pAttributeId the id of the attribute
* @param {boolean} [pTranslate] if the name should be translated
*
* @return {String} the name of the attribute
*/
AttributeUtil.getSimpleAttributeName = function (pAttributeId)
AttributeUtil.getSimpleAttributeName = function (pAttributeId, pTranslate)
{
var attributeName = db.cell(SqlCondition.begin()
.andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", pAttributeId)
.buildSql("select ATTRIBUTE_NAME from AB_ATTRIBUTE")
);
if (pTranslate)
attributeName = translate.text(attributeName);
return attributeName;
}
......@@ -172,12 +184,9 @@ AttributeUtil.hasRelations = function (pAttributeId)
return db.cell(SqlCondition.begin()
.andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", pAttributeId)
.buildSql(
"select exists ("
+ "select AB_ATTRIBUTERELATIONID from AB_ATTRIBUTERELATION "
+ "where AB_ATTRIBUTE_ID = AB_ATTRIBUTEID"
+ ") from AB_ATTRIBUTE", "1=2"
"select count(*) = 0 from AB_ATTRIBUTERELATION", "1=2"
)
) == "true";
) != "true";
}
/**
......@@ -742,8 +751,8 @@ AttributeUsageUtil.insertChildrenUsages = function (pAttributeId, pObjectType)
var types = db.getColumnTypes(table, columns);
var sqlSelect = "select AB_ATTRIBUTEID, "
+ " exists (select AB_ATTRIBUTEUSAGEID from AB_ATTRIBUTEUSAGE where AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID and OBJECT_TYPE = '"
+ pObjectType + "') from AB_ATTRIBUTE";
+ " (select count(*) from AB_ATTRIBUTEUSAGE where AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID and OBJECT_TYPE = '"
+ pObjectType + "') = 0 from AB_ATTRIBUTE";
var inserts = [];
_addInserts(pAttributeId, pObjectType);
......@@ -758,7 +767,7 @@ AttributeUsageUtil.insertChildrenUsages = function (pAttributeId, pObjectType)
attributes.forEach(function (row)
{
if (row[1] != "true")
if (row[1] == "true")
{
let values = [util.getNewUUID(), row[0], pObjectType];
inserts.push([table, columns, types, values]);
......@@ -784,8 +793,8 @@ AttributeUsageUtil.updateChildrenUsages = function (pAttributeId, pOldObjectType
var table = "AB_ATTRIBUTEUSAGE";
var sqlSelect = "select AB_ATTRIBUTEID, AB_ATTRIBUTEUSAGEID, "
+ " exists (select AB_ATTRIBUTEUSAGEID from AB_ATTRIBUTEUSAGE where AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID and OBJECT_TYPE = '"
+ pNewObjectType + "')"
+ " (select count(*) from AB_ATTRIBUTEUSAGE where AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID and OBJECT_TYPE = '"
+ pNewObjectType + "') = 0"
+ " from AB_ATTRIBUTE left join AB_ATTRIBUTEUSAGE on AB_ATTRIBUTEID = AB_ATTRIBUTE_ID and OBJECT_TYPE = '" + pOldObjectType + "'";
var updateCond = SqlCondition.begin();
......@@ -810,7 +819,7 @@ AttributeUsageUtil.updateChildrenUsages = function (pAttributeId, pOldObjectType
attributes.forEach(function (row)
{
if (row[1] && row[2] == "true")
if (row[1] && row[2] != "true")
deleteCond.orPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTEUSAGEID", row[1]);
else if (row[1])
updateCond.orPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTEUSAGEID", row[1]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment