diff --git a/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/contentProcess.js b/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/contentProcess.js index 9f1541d2f9b4b072bcdb0a64bdf3c8c84baf1d7a..53985b5cc50a47402b9df28330a3f2623c768f39 100644 --- a/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/contentProcess.js +++ b/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/contentProcess.js @@ -1,3 +1,4 @@ +import("system.logging"); import("JditoFilter_lib"); import("system.util"); import("system.db"); @@ -26,34 +27,47 @@ if (isMariaDB) columnName = "\`NAME\`"; } -var stepsRows = stepCondition.select("CAMPAIGNSTEPID, CAMPAIGNSTEP."+ columnName + ", CAMPAIGNSTEP.PREDECESSORSTEP_ID," +stepCondition.select("CAMPAIGNSTEPID, CAMPAIGNSTEP."+ columnName + ", CAMPAIGNSTEP.PREDECESSORSTEP_ID," + " CAMPAIGNSTEP.DESCRIPTION, CAMPAIGNSTEP.DATE_START, CAMPAIGNSTEP.DATE_END, CAMPAIGNID, CAMPAIGN."+ columnName +", CAMPAIGN.STATUS") .from("CAMPAIGN") - .join("CAMPAIGNSTEP", "CAMPAIGN.CAMPAIGNID = CAMPAIGNSTEP.CAMPAIGN_ID") - .orderBy("SORTING") - .table(); + .join("CAMPAIGNSTEP", "CAMPAIGN.CAMPAIGNID = CAMPAIGNSTEP.CAMPAIGN_ID"); + +if (vars.exists("$local.idvalues") && vars.get("$local.idvalues")) + stepCondition.and("CAMPAIGNSTEP.CAMPAIGNSTEPID", vars.get("$local.idvalues"), SqlBuilder.IN()); -stepsRows = stepsRows.map(function ([stepId, stepName, predecessorId, desc, stepStartDate, stepEndDate, campaignId, campaignName, campaignStatus]) +var stepsRows = stepCondition.orderBy("SORTING").table(); + +//this can happen when not a CampaignStep, but a Campaign node was selected +if(stepsRows.length == 0 && vars.get("$local.idvalues") && newSelect("count(*)").from("CAMPAIGN").where("CAMPAIGN.CAMPAIGNID", vars.get("$local.idvalues")).cell() > 0) { - if (!campaignRows[campaignId]) - { - let startDate = CampaignUtils.getCampaignStartDate(campaignId); - let endDate = CampaignUtils.getCampaignEndDate(campaignId); - campaignRows[campaignId] = [campaignId, campaignName, null, null, startDate, endDate, campaignId, TARGET_CONTEXT_ROOT_ELEMENT, campaignStatus]; - } - stepIds[stepId] = true; - - return [stepId, stepName, predecessorId || campaignId, desc, stepStartDate, stepEndDate, campaignId, TARGET_CONTEXT_ELEMENT, campaignStatus]; -}); + stepsRows = [[vars.get("$local.idvalues"), "", "", "", "", "", vars.get("$local.idvalues"), "", ""]] +} -//replace all predecessor ids that are not in the tree with the campaign id -stepsRows.forEach(function (row) +if(!vars.get("$local.idvalues")) { - if (!(stepIds[row[2]])) - row[2] = row[6]; -}); + stepsRows = stepsRows.map(function ([stepId, stepName, predecessorId, desc, stepStartDate, stepEndDate, campaignId, campaignName, campaignStatus]) + { + if (!campaignRows[campaignId]) + { + let startDate = CampaignUtils.getCampaignStartDate(campaignId); + let endDate = CampaignUtils.getCampaignEndDate(campaignId); + campaignRows[campaignId] = [campaignId, campaignName, null, null, startDate, endDate, campaignId, TARGET_CONTEXT_ROOT_ELEMENT, campaignStatus]; + } + stepIds[stepId] = true; + + return [stepId, stepName, predecessorId || campaignId, desc, stepStartDate, stepEndDate, campaignId, TARGET_CONTEXT_ELEMENT, campaignStatus]; + }); -//convert the object to an array -campaignRows = Object.keys(campaignRows).map(function (id) {return campaignRows[id];}); + //replace all predecessor ids that are not in the tree with the campaign id + stepsRows.forEach(function (row) + { + if (!(stepIds[row[2]])) + row[2] = row[6]; + }); -result.object(campaignRows.concat(stepsRows)) + //convert the object to an array + campaignRows = Object.keys(campaignRows).map(function (id) {return campaignRows[id];}); + + stepsRows = campaignRows.concat(stepsRows); +} +result.object(stepsRows);