From 42966b50c5892312fdf42e9759027e92aaebb937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20=C3=9Cstere?= Date: Fri, 8 Nov 2024 11:56:54 +0000 Subject: [PATCH 1/3] user section changes --- .../javascripts/countly.common.components.js | 18 ++++++++++++++++-- .../public/templates/sections/users.html | 7 +++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/plugins/populator/frontend/public/javascripts/countly.common.components.js b/plugins/populator/frontend/public/javascripts/countly.common.components.js index 56d7b0b2105..30d69efaf0d 100644 --- a/plugins/populator/frontend/public/javascripts/countly.common.components.js +++ b/plugins/populator/frontend/public/javascripts/countly.common.components.js @@ -328,7 +328,7 @@ data: function() { return { users: [], - conditionPropertyValues: [] + conditionPropertyValues: [], }; }, created() { @@ -373,11 +373,13 @@ onAddUserProperty: function() { this.users.push({ "key": "", - "values": [{key: "", probability: 0}], + "values": [{key: "", probability: 100}], + "isProbabilitiesEqual": true, }); }, onAddAnotherValue: function(index) { this.users[index].values.push({key: "", probability: 0}); + this.calculatePropertyProbabilities(index); }, checkRemoveValue: function(key, value) { let usedProperties = []; @@ -435,6 +437,7 @@ } try { this.users[index].values.splice(valueIndex, 1); + this.calculatePropertyProbabilities(index); } catch (error) { CountlyHelpers.notify({ @@ -481,6 +484,17 @@ if (item) { this.conditionPropertyValues = item.values.map(valueItem => valueItem.key || null); } + }, + calculatePropertyProbabilities: function(index) { + if (this.users[index].isProbabilitiesEqual) { + var valueCount = Object.keys(this.users[index].values).length, + equalProbability = 100 / valueCount; + const updatedValues = this.users[index].values.map(item => ({ + ...item, + probability: equalProbability // Set the new probability value + })); + this.users[index].values = updatedValues; + } } }, template: CV.T("/populator/templates/sections/users.html") diff --git a/plugins/populator/frontend/public/templates/sections/users.html b/plugins/populator/frontend/public/templates/sections/users.html index b7f804f89e8..2d6605ebe3f 100644 --- a/plugins/populator/frontend/public/templates/sections/users.html +++ b/plugins/populator/frontend/public/templates/sections/users.html @@ -25,14 +25,17 @@
- {{i18n('populator-template.probability')}} + + + {{i18n('populator-template.probability')}} +
- + From c30f8c30d05ba70325ad45fbf636f82aa4cc8b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20=C3=9Cstere?= Date: Fri, 8 Nov 2024 13:29:05 +0000 Subject: [PATCH 2/3] changes for user property conditions --- .../javascripts/countly.common.components.js | 17 ++++++++++++++++- .../public/templates/sections/users.html | 7 +++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/plugins/populator/frontend/public/javascripts/countly.common.components.js b/plugins/populator/frontend/public/javascripts/countly.common.components.js index 30d69efaf0d..c2822b43909 100644 --- a/plugins/populator/frontend/public/javascripts/countly.common.components.js +++ b/plugins/populator/frontend/public/javascripts/countly.common.components.js @@ -221,7 +221,8 @@ selectedKey: this.selectedProperty, selectedValue: this.selectedValue, conditionType: this.conditionType, - values: [{key: "", probability: 0}] + values: [{key: "", probability: 100}], + "isProbabilitiesEqual": true, }); this.$emit('input', conditions); } @@ -454,9 +455,11 @@ try { if (this.users[index].conditions[conditionIndex].values.length === 1) { this.users[index].conditions.splice(conditionIndex, 1); + this.calculateConditionProbabilities(index, conditionIndex); } else { this.users[index].conditions[conditionIndex].values.splice(valueIndex, 1); + this.calculateConditionProbabilities(index, conditionIndex); } } catch (error) { @@ -470,6 +473,7 @@ onAddAnotherConditionValue: function(index, conditionIndex) { try { this.users[index].conditions[conditionIndex].values.push({key: "", probability: 0}); + this.calculateConditionProbabilities(index, conditionIndex); } catch (error) { CountlyHelpers.notify({ @@ -495,6 +499,17 @@ })); this.users[index].values = updatedValues; } + }, + calculateConditionProbabilities: function(index, conditionIndex) { + if (this.users[index].conditions[conditionIndex].isProbabilitiesEqual) { + var valueCount = Object.keys(this.users[index].conditions[conditionIndex].values).length, + equalProbability = 100 / valueCount; + const updatedValues = this.users[index].conditions[conditionIndex].values.map(item => ({ + ...item, + probability: equalProbability // Set the new probability value + })); + this.users[index].conditions[conditionIndex].values = updatedValues; + } } }, template: CV.T("/populator/templates/sections/users.html") diff --git a/plugins/populator/frontend/public/templates/sections/users.html b/plugins/populator/frontend/public/templates/sections/users.html index 2d6605ebe3f..bd1d14f766d 100644 --- a/plugins/populator/frontend/public/templates/sections/users.html +++ b/plugins/populator/frontend/public/templates/sections/users.html @@ -69,14 +69,17 @@
- {{i18n('populator-template.probability')}} + + + {{i18n('populator-template.probability')}} +
- + From acbf23676e4c6c48fb841cae35ff554e4594b105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20=C3=9Cstere?= Date: Mon, 11 Nov 2024 07:39:29 +0000 Subject: [PATCH 3/3] events and event conditions --- .../javascripts/countly.common.components.js | 31 ++++++++++++++++++- .../public/templates/sections/events.html | 14 ++++++--- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/plugins/populator/frontend/public/javascripts/countly.common.components.js b/plugins/populator/frontend/public/javascripts/countly.common.components.js index c2822b43909..7fa5d05963a 100644 --- a/plugins/populator/frontend/public/javascripts/countly.common.components.js +++ b/plugins/populator/frontend/public/javascripts/countly.common.components.js @@ -571,7 +571,8 @@ onAddEventSegmentation: function(index) { this.events[index].segmentations.push({ "key": "", - "values": [{key: "", probability: 0}], + "values": [{key: "", probability: 100}], + "isProbabilitiesEqual": true, }); }, checkRemoveValue: function(key, value, index) { @@ -628,6 +629,7 @@ return; } this.events[index].segmentations[segmentIndex].values.splice(valueIndex, 1); + this.calculateSegmentProbabilities(index, segmentIndex); } catch (error) { CountlyHelpers.notify({ @@ -640,6 +642,7 @@ onAddAnotherValue: function(index, segmentIndex) { try { this.events[index].segmentations[segmentIndex].values.push({key: "", probability: 0}); + this.calculateSegmentProbabilities(index, segmentIndex); } catch (error) { CountlyHelpers.notify({ @@ -651,6 +654,7 @@ }, onAddAnotherConditionValue: function(index, segmentIndex, conditionIndex) { this.events[index].segmentations[segmentIndex].conditions[conditionIndex].values.push({key: "", probability: 0}); + this.calculateConditionProbabilities(index, segmentIndex, conditionIndex); }, onRemoveConditionValue: function(index, segmentIndex, valueIndex, conditionIndex) { try { @@ -659,6 +663,7 @@ } else { this.events[index].segmentations[segmentIndex].conditions[conditionIndex].values.splice(valueIndex, 1); + this.calculateConditionProbabilities(index, segmentIndex, conditionIndex); } } catch (error) { @@ -677,6 +682,30 @@ if (item) { this.conditionPropertyValues = item.values.map(valueItem => valueItem.key || null); } + }, + calculateSegmentProbabilities: function(index, segmentIndex) { + if (this.events[index].segmentations[segmentIndex].isProbabilitiesEqual) { + var valueCount = Object.keys(this.events[index].segmentations[segmentIndex].values).length, + equalProbability = 100 / valueCount; + const updatedValues = this.events[index].segmentations[segmentIndex].values.map(item => ({ + ...item, + probability: equalProbability // Set the new probability value + })); + this.events[index].segmentations[segmentIndex].values = updatedValues; + this.events[index].segmentations[segmentIndex].probabilitySum = equalProbability * valueCount; + } + }, + calculateConditionProbabilities: function(index, segmentIndex, conditionIndex) { + if (this.events[index].segmentations[segmentIndex].conditions[conditionIndex].isProbabilitiesEqual) { + var valueCount = Object.keys(this.events[index].segmentations[segmentIndex].conditions[conditionIndex].values).length, + equalProbability = 100 / valueCount; + const updatedValues = this.events[index].segmentations[segmentIndex].conditions[conditionIndex].values.map(item => ({ + ...item, + probability: equalProbability // Set the new probability value + })); + this.events[index].segmentations[segmentIndex].conditions[conditionIndex].values = updatedValues; + this.events[index].segmentations[segmentIndex].conditions[conditionIndex].probabilitySum = equalProbability * valueCount; + } } }, created() { diff --git a/plugins/populator/frontend/public/templates/sections/events.html b/plugins/populator/frontend/public/templates/sections/events.html index dccc723ecc8..23b39689a5b 100644 --- a/plugins/populator/frontend/public/templates/sections/events.html +++ b/plugins/populator/frontend/public/templates/sections/events.html @@ -67,14 +67,17 @@
- {{i18n('populator-template.probability')}} + + + {{i18n('populator-template.probability')}} +
- + @@ -109,14 +112,17 @@
- {{i18n('populator-template.probability')}} + + + {{i18n('populator-template.probability')}} +
- +