Skip to content
Snippets Groups Projects
Commit 0adece9c authored by David Büchler's avatar David Büchler
Browse files

Beim Updaten von Kampagnenteilnehmern werden nun die gleichen Nachrichten...

Beim Updaten von Kampagnenteilnehmern werden nun die gleichen Nachrichten angezeigt, wie beim Hinzufügen.
Die let condition im onInsert wenn if(isUpdate == "true") prüft nun sowohl auf die ContactId als auch die ParticipantId. Dies kommt daher, dass an allen Stellen die ContactId genutzt wird, bis auf im FilterView der Teilnehmer. Hier wird immer die TeilnehmerId selektiert
Update Action im CampaignParticipant entity wurde um Filter-Condition Funktionalität erweitert
parent 682f2701
No related branches found
No related tags found
No related merge requests found
......@@ -127,6 +127,10 @@
<name>dataSourceTableName_param</name>
<expose v="true" />
</entityParameter>
<entityField>
<name>isOperationValid</name>
<valueProcess>%aditoprj%/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js</valueProcess>
</entityField>
</entityFields>
<recordContainers>
<jDitoRecordContainer>
......
import("Campaign_lib");
import("system.logging");
import("system.result");
import("system.translate");
import("system.vars");
//logging.log("campaignParticipantsRowIds_param -> " + vars.get("$param.campaignParticipantsRowIds_param"));
//logging.log("campaignParticipantsRowIds_param -> " + JSON.parse(vars.getString("$param.campaignParticipantsRowIds_param")).length);
//logging.log("campaignParticipantsRowIds_param -> " + vars.getString("$param.campaignParticipantsRowIds_param"));
//logging.log("campaignParticipantsCondition_param -> " + vars.getString("$param.campaignParticipantsCondition_param"));
var campaignParticipantsAmount = 0;
var informationText = translate.text("participants will be added to the selected campaign step");
var targetTable = vars.get("$param.dataSourceTableName_param");
var selectionRowIds = JSON.parse(vars.getString("$param.campaignParticipantsRowIds_param"));
var selectedCampaignId = vars.get("$field.CAMPAIGN_ID");
var selectedCampaignStepId = vars.get("$field.CAMPAIGNSTEP_ID");
var participantCondition = "";
var resultString = "";
//logging.log("selectedCampaignId -> " + selectedCampaignId);
if(selectedCampaignId == '')
result.string(resultString);
else
{
/*
* First determines how many of the selected are already in the campaign
* If there are no valid participants at all or too many in respect of the
* selected steps max number of participants, nothing will be added.
* A message describing this situation will be written.
*
* If none of those criteria match, all participants are good to be added.
*/
var countParticipantsAlreadyInCampaign = 0;
var countParticipantsToAdd = 0;
var countValidParticipantsToAdd = 0;
//if theres a selection, we have to use it, otherwise use the condition
if(selectionRowIds != null && selectionRowIds.length > 0)
{
countParticipantsToAdd = selectionRowIds.length;
logging.log("selectedCampaignId -> " + selectedCampaignId);
countParticipantsAlreadyInCampaign = CampaignUtils.GetParticipantsAlreadyInStepCountByRowId(selectedCampaignId, selectionRowIds);
}
else
{
logging.log("campaignParticipantsCondition_param -> " + vars.getString("$param.campaignParticipantsCondition_param"));
participantCondition = JSON.parse(vars.getString("$param.campaignParticipantsCondition_param")).condition;
countParticipantsToAdd = CampaignUtils.GetContactCountByCondition(participantCondition);
countParticipantsAlreadyInCampaign = CampaignUtils.GetParticipantsAlreadyInStepCountByCondition(selectedCampaignId, targetTable, participantCondition);
}
countValidParticipantsToAdd = countParticipantsToAdd - countParticipantsAlreadyInCampaign;
logging.log("countParticipantsToAdd -> " + countParticipantsToAdd);
logging.log("countParticipantsAlreadyInCampaign -> " + countParticipantsAlreadyInCampaign);
logging.log("countValidParticipantsToAdd -> " + countValidParticipantsToAdd);
if(countValidParticipantsToAdd <= 0)
{
resultString = "Alle selektierten Teilnehmer befinden sich bereits in der Stufe";
}
else if(hasStepEnoughSlots(countValidParticipantsToAdd))
{
resultString = countValidParticipantsToAdd + "/" + countParticipantsToAdd + " " + informationText;
}
else
{
resultString = "Nicht genug Teilnehmerplätze für "
+ countValidParticipantsToAdd + "/" + countParticipantsToAdd
+ " Teilnehmern vorhanden";
}
result.string(resultString);
}
function hasStepEnoughSlots(pCountToAdd)
{
// logging.log(" selectedCampaignStepId-> " + selectedCampaignStepId);
let currentParticipants = CampaignUtils.getParticipantCountForStep(selectedCampaignStepId)
let maxParticipants = CampaignUtils.getMaxParticipantCountForStep(selectedCampaignStepId)
// logging.log(" currentParticipants + pCountToAdd-> " + (parseInt(currentParticipants) + parseInt(pCountToAdd)));
// logging.log(" maxParticipants-> " + maxParticipants);
// logging.log(" (currentParticipants + pCountToAdd) <= maxParticipants-> " + ((currentParticipants + pCountToAdd) <= maxParticipants));
return (parseInt(currentParticipants) + parseInt(pCountToAdd)) <= maxParticipants;
}
\ No newline at end of file
import("Campaign_lib");
import("system.logging");
import("system.result");
import("system.translate");
import("system.vars");
import("system.neon");
//logging.log("campaignParticipantsRowIds_param -> " + vars.get("$param.campaignParticipantsRowIds_param"));
//logging.log("campaignParticipantsRowIds_param -> " + JSON.parse(vars.getString("$param.campaignParticipantsRowIds_param")).length);
//logging.log("campaignParticipantsRowIds_param -> " + vars.getString("$param.campaignParticipantsRowIds_param"));
//logging.log("campaignParticipantsCondition_param -> " + vars.getString("$param.campaignParticipantsCondition_param"));
var campaignParticipantsAmount = 0;
var informationText = translate.text("participants will be added to the selected campaign step");
var targetTable = vars.get("$param.dataSourceTableName_param");
var selectionRowIds = JSON.parse(vars.getString("$param.campaignParticipantsRowIds_param"));
var selectedCampaignId = vars.get("$field.CAMPAIGN_ID");
var selectedCampaignStepId = vars.get("$field.CAMPAIGNSTEP_ID");
var isUpdate = vars.get("$field.isUpdate");
var participantCondition = "";
var messageString = "";
var resultValue = "false";
//logging.log("selectedCampaignId -> " + selectedCampaignId);
if(selectedCampaignId != '')
{
/*
* First determines how many of the selected are already in the campaign
* If there are no valid participants at all or too many in respect of the
* selected steps max number of participants, nothing will be added.
* A message describing this situation will be written.
*
* If none of those criteria match, all participants are good to be added.
*/
var countParticipantsAlreadyInCampaign = 0;
var countParticipantsToAdd = 0;
var countValidParticipantsToAdd = 0;
var whereCondition = "";
var rowIdsComparisonField = "";
//if theres a selection, we have to use it, otherwise use the condition
if(selectionRowIds != null && selectionRowIds.length > 0)
{
countParticipantsToAdd = selectionRowIds.length;
/*
* The field against which will be checked, if the selection is already contained in the campaignStep
* depends on wether isUpdate is true or not.
* If true, the selected IDs are CampaignParticipantIds, otherwise contactIds.
* This happens because on true the action is called in the participants filterview to move participants
* between steps, on false new participants are in the process of being added to a step.
*/
if(isUpdate == "true")
{
rowIdsComparisonField = "CAMPAIGNPARTICIPANT.CAMPAIGNPARTICIPANTID";
whereCondition = "CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID = '" + selectedCampaignStepId + "'";
}
else
{
rowIdsComparisonField = "CAMPAIGNPARTICIPANT.CONTACT_ID";
whereCondition = "CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + selectedCampaignId + "'";
}
countParticipantsAlreadyInCampaign = CampaignUtils.GetParticipantsAlreadyAddedCountByRowId(whereCondition, rowIdsComparisonField, selectionRowIds);
}
else
{
participantCondition = JSON.parse(vars.getString("$param.campaignParticipantsCondition_param")).condition;
countParticipantsToAdd = CampaignUtils.GetContactCountByCondition(participantCondition);
if(isUpdate == "true")
whereCondition = "CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID = '" + selectedCampaignStepId + "'";
else
whereCondition = "CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + selectedCampaignId + "'";
countParticipantsAlreadyInCampaign = CampaignUtils.GetParticipantsAlreadyAddedCountByCondition(whereCondition, participantCondition);
//CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "'"
}
countValidParticipantsToAdd = countParticipantsToAdd - countParticipantsAlreadyInCampaign;
logging.log("countParticipantsToAdd -> " + countParticipantsToAdd);
logging.log("countParticipantsAlreadyInCampaign -> " + countParticipantsAlreadyInCampaign);
logging.log("countValidParticipantsToAdd -> " + countValidParticipantsToAdd);
if(countValidParticipantsToAdd <= 0)
{
messageString = "Alle selektierten Teilnehmer befinden sich bereits in der Stufe";
}
else if(hasStepEnoughSlots(countValidParticipantsToAdd))
{
messageString = countValidParticipantsToAdd + "/" + countParticipantsToAdd + " " + informationText;
resultValue = "true";
}
else
{
messageString = "Nicht genug Teilnehmerplätze für "
+ countValidParticipantsToAdd + "/" + countParticipantsToAdd
+ " Teilnehmern vorhanden";
}
neon.setFieldValue("$field.campaignParticipantMessage", messageString);
result.string(resultValue);
}
function hasStepEnoughSlots(pCountToAdd)
{
// logging.log(" selectedCampaignStepId-> " + selectedCampaignStepId);
let currentParticipants = CampaignUtils.getParticipantCountForStep(selectedCampaignStepId)
let maxParticipants = CampaignUtils.getMaxParticipantCountForStep(selectedCampaignStepId)
// logging.log(" currentParticipants + pCountToAdd-> " + (parseInt(currentParticipants) + parseInt(pCountToAdd)));
// logging.log(" maxParticipants-> " + maxParticipants);
// logging.log(" (currentParticipants + pCountToAdd) <= maxParticipants-> " + ((currentParticipants + pCountToAdd) <= maxParticipants));
return (parseInt(currentParticipants) + parseInt(pCountToAdd)) <= maxParticipants;
}
\ No newline at end of file
......@@ -19,8 +19,10 @@ var colNamesCampaignParticipantLog = CampaignUtils.getParticipantLogInsertColumn
if(participantRowIds != null && participantRowIds.length > 0)
{
let contactIdsToHandle = participantRowIds;
if(isUpdate == "false")
contactIdsToHandle = CampaignUtils.GetContactIdsNotInCampaignByRowIds(campaignId, participantRowIds);
logging.log("contactIdsToHandle by rowIds -> " + contactIdsToHandle);
_handleRowIds(contactIdsToHandle);
}
......@@ -30,6 +32,8 @@ else
_handleCondition(campaignId, conditionSourceTableName, participantCondition);
}
function _handleCondition(pCampaignId, pTargetTableName, pCondition)
{
let contactIdsToHandle = [];
......@@ -39,7 +43,7 @@ function _handleCondition(pCampaignId, pTargetTableName, pCondition)
* Because they already are participants, no restrictions apply to the affected IDs.
*
* Otherwise the participants ought to be inserted. The only restriction right now is, hat the participants to be inserted
* musn't already be in this specific campaign. Therefore all IDs hat are defined by the condition and not in the campaign are selected.
* can't already be in this specific campaign. Therefore all IDs hat are defined by the condition and not in the campaign are selected.
*/
if(isUpdate == "true")
{
......@@ -78,13 +82,14 @@ function _handleRowIds(pParticipantRowIds)
for (participant in pParticipantRowIds)
{
let campaignParticipantLogId = util.getNewUUID();
if(isUpdate == "true")
{
let updatedValues = [newCampaignStepId,
vars.get("$sys.user"),
vars.get("$sys.date")];
let condition = "CAMPAIGNPARTICIPANTID = '" + pParticipantRowIds[participant] + "'";
let condition = "CONTACT_ID = '" + pParticipantRowIds[participant] + "' OR CAMPAIGNPARTICIPANTID = '" + pParticipantRowIds[participant] + "'";
let valsCampaignParticipantLog = new Array(pParticipantRowIds[participant], campaignId, newCampaignStepId, campaignParticipantLogId, vars.get("$sys.user"), vars.get("$sys.date"));
statementArray.push(["CAMPAIGNPARTICIPANT", cols, null, updatedValues, condition]);
......@@ -107,9 +112,12 @@ function _handleRowIds(pParticipantRowIds)
statementArray.push(["CAMPAIGNPARTICIPANT", cols, null, valsCampaignParticipant]);
}
}
logging.log("statementArray -> " + statementArray);
if(isUpdate == "true")
db.updates(statementArray)
{
logging.log("vor db.updates??? -> ");
db.updates(statementArray)
}
else
db.inserts(statementArray);
......
import("system.logging");
import("system.vars");
import("system.neon");
import("Campaign_lib");
var sysSelection = vars.getString("$sys.selection");
var sysSelection = vars.get("$sys.selection");
var campaignId = vars.get("$field.CAMPAIGN_ID");
var campaignStepId = vars.get("$field.CAMPAIGNSTEP_ID")
if(sysSelection.length > 0) //selektierte IDs als Array
{
CampaignUtils.openSetCampaignStepView(vars.getString("$sys.selection"), vars.get("$field.CAMPAIGN_ID"), vars.get("$field.CAMPAIGNSTEP_ID"));
CampaignUtils.openSetCampaignStepViewByRowIds(vars.getString("$sys.selection"), campaignId, campaignStepId);
}
else
{
let sysFilter = vars.get("$sys.filter");//todo change name
logging.log("sysFilter -> " + sysFilter);
CampaignUtils.openSetCampaignStepViewByCondition(JSON.stringify(sysFilter), campaignId, campaignStepId);
}
\ No newline at end of file
......@@ -158,7 +158,7 @@ CampaignUtils.getParticipantLogInsertColumnNames = function()
/**
* todo
*/
CampaignUtils.openSetCampaignStepView = function(pParticipantIds, pCampaignId, pCampaignStepId)
CampaignUtils.openSetCampaignStepViewByRowIds = function(pParticipantIds, pCampaignId, pCampaignStepId)
{
var params = {};
params["campaignParticipantsRowIds_param"] = pParticipantIds;
......@@ -166,8 +166,20 @@ CampaignUtils.openSetCampaignStepView = function(pParticipantIds, pCampaignId, p
params["currentCampaignStepId_param"] = pCampaignStepId;
params["isUpdate_param"] = true;
neon.openContext("CampaignAddParticipants", "CampaignAddParticipantsEdit_view", null, neon.OPERATINGSTATE_NEW, params);
}
/**
* todo
*/
CampaignUtils.openSetCampaignStepViewByCondition = function(pCondition, pCampaignId, pCampaignStepId)
{
var params = {};
params["campaignParticipantsCondition_param"] = pCondition;
params["currentCampaignId_param"] = pCampaignId;
params["currentCampaignStepId_param"] = pCampaignStepId;
params["isUpdate_param"] = true;
neon.openContext("CampaignAddParticipants", "CampaignAddParticipantsEdit_view", null, neon.OPERATINGSTATE_NEW, params);
}
......@@ -310,60 +322,30 @@ CampaignUtils.checkforCommRestrictions = function()
.buildSql("select MEDIUM from CAMPAIGNSTEP join COMMRESTRICTION on MEDIUM = STEPMEDIUM", "1=2"));
}
//CampaignUtils.GetContactIdsNotInStepByRowIds = function(pCampaignId, pParticipantRowIds)
//{
// //SELECT CAMPAIGNPARTICIPANTID FROM CAMPAIGNPARTICIPANT
// //WHERE CAMPAIGNPARTICIPANT.CONTACT_ID
// //IN ('4cc98357-25f3-462b-898c-440f9faf4b97','d5a2dc64-e503-4aed-a0c6-d54f49b8db87','45635aca-7971-43df-a683-c80c86cb58cc','1a67eaa7-21da-4a18-97ab-755ac5cb74f7')
//
// let rowIdsAsRay = _CampaignUtils._convertToSqlValuesList(pParticipantRowIds);
//
// let query = "SELECT CAMPAIGNPARTICIPANTID FROM CAMPAIGNPARTICIPANT"
// + " where CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "' AND"
// + " CAMPAIGNPARTICIPANT.CONTACT_ID NOT IN " + rowIdsAsRay;
//
// return db.array(db.COLUMN, query)
//}
CampaignUtils.GetParticipantsAlreadyInStepCountByRowId = function(pCampaignId, pParticipantRowIds)
CampaignUtils.GetParticipantsAlreadyAddedCountByRowId = function(pWhereCondition, pRowIdsComparisonField, pParticipantRowIds)
{
let rowIdsAsRay = _CampaignUtils._convertToSqlValuesList(pParticipantRowIds);
let query = "SELECT COUNT(*) FROM CAMPAIGNPARTICIPANT"
+ " where CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "' AND"
+ " CAMPAIGNPARTICIPANT.CONTACT_ID IN " + rowIdsAsRay;
+ " where " + pWhereCondition + " AND"
+ " " + pRowIdsComparisonField + " IN " + rowIdsAsRay;
logging.log("GetParticipantsAlreadyInStepCountByRowId query -> " + query);
return db.cell(query)
}
CampaignUtils.GetParticipantsAlreadyInStepCountByCondition = function(pCampaignId, pTargetTableName, pCondition)
CampaignUtils.GetParticipantsAlreadyAddedCountByCondition = function(pWhereCondition, pCondition)
{
let targetIdField = "CONTACT.CONTACTID";
var joinCondition = "";
if(pTargetTableName == "PERSON")
{
joinCondition = "PERSONID = PERSON_ID";
}
else
{
joinCondition = "ORGANISATIONID = ORGANISATION_ID";
}
//select PERSON.*
//from CONTACT
//join PERSON on PERSONID = PERSON_ID
//where CONTACT.CONTACTID in ('d5a2dc64-e503-4aed-a0c6-d54f49b8db87','45635aca-7971-43df-a683-c80c86cb58cc','1a67eaa7-21da-4a18-97ab-755ac5cb74f7')
let query = "select count(*) from CAMPAIGNPARTICIPANT"
+ " where CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "' AND"
+ " CAMPAIGNPARTICIPANT.CONTACT_ID in"
+ " (" + _CampaignUtils._selectFromContactWithJoin(targetIdField, pTargetTableName, joinCondition, pCondition)
+ ")";
let query = "select count(*) from PERSON"
+ " join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID)"
+ " join ORGANISATION on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID)"
+ " left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)"
+ " left join CAMPAIGNPARTICIPANT on CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID"
+ " where " + pWhereCondition
+ " and " + pCondition;
logging.log("query -> " + query);
logging.log("GetParticipantsAlreadyAddedCountByCondition query -> " + query);
return db.cell(query)
}
......@@ -397,13 +379,13 @@ CampaignUtils.GetContactIdsNotInCampaignByCondition = function(pCampaignId, pCon
CampaignUtils.GetContactIdsInCampaignByCondition = function(pCampaignId, pCondition)
{
let query = "select CONTACT.CONTACTID, person.FIRSTNAME from PERSON"
let query = "select CONTACT.CONTACTID from PERSON"
+ " join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID)"
+ " join ORGANISATION on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID)"
+ " left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)"
+ " left join CAMPAIGNPARTICIPANT on CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID"
+ " where " + pCondition
+ " and CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "')";
+ " and CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "'";
return db.array(db.COLUMN, query);
}
......@@ -413,7 +395,8 @@ CampaignUtils.GetContactCountByCondition = function(pCondition)
let query = "select count(*) from PERSON"
+ " join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID)"
+ " join ORGANISATION on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID)"
+ " left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)";
+ " left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)"
+ " left join CAMPAIGNPARTICIPANT on CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID";
if(pCondition != "")
query += " where " + pCondition;
......
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