From bb024d22568a941ab9c1974e9ea8dd9ba7ad035c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=B1nar=20Gen=C3=A7?= Date: Tue, 10 Jan 2023 13:51:55 +0300 Subject: [PATCH] [SER-338] Column titles are not user friendly Implemented custom export function for hooks plugin --- .../public/javascripts/countly.models.js | 62 +++++++++++++++++++ .../public/javascripts/countly.views.js | 17 +++++ .../public/localization/hooks.properties | 2 +- .../frontend/public/templates/vue-table.html | 3 +- 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/plugins/hooks/frontend/public/javascripts/countly.models.js b/plugins/hooks/frontend/public/javascripts/countly.models.js index 3e9f0ea6922..fcdcde095ae 100644 --- a/plugins/hooks/frontend/public/javascripts/countly.models.js +++ b/plugins/hooks/frontend/public/javascripts/countly.models.js @@ -136,6 +136,64 @@ return triggerEffectDom; }; + hooksPlugin.generateTriggerActionsTreeForExport = function(row) { + var triggerNames = { + "APIEndPointTrigger": jQuery.i18n.map["hooks.trigger-api-endpoint-uri"], + "IncomingDataTrigger": jQuery.i18n.map["hooks.IncomingData"], + "InternalEventTrigger": jQuery.i18n.map["hooks.internal-event-selector-title"], + "ScheduledTrigger": jQuery.i18n.map["hooks.ScheduledTrigger"], + }; + var triggerText = triggerNames[row.trigger.type]; + var triggerDesc = ''; + try { + if (row.trigger.type === "IncomingDataTrigger") { + var event = row.trigger.configuration.event; + var parts = event[0].split("***"); + triggerDesc = ' ' + parts[1] + ' '; + } + + if (row.trigger.type === "APIEndPointTrigger") { + var path = row.trigger.configuration.path; + triggerDesc = ' ' + path + ' '; + } + + if (row.trigger.type === "InternalEventTrigger") { + var eventType = row.trigger.configuration.eventType; + triggerDesc = ' ' + eventType + ' '; + } + } + catch (e) { + //silent catch + } + + var effectNames = { + "EmailEffect": jQuery.i18n.map["hooks.EmailEffect"], + "HTTPEffect": jQuery.i18n.map["hooks.HTTPEffect"], + "CustomCodeEffect": jQuery.i18n.map["hooks.CustomCodeEffect"], + }; + var effectList = ""; + var arrow = ' -> '; + row.effects.forEach(function(effect) { + effectList += arrow + (effectNames[effect.type] && effectNames[effect.type].toUpperCase()) + ' '; + if (effect.type === "EmailEffect") { + effectList += ' ' + effect.configuration.address + ' '; + } + if (effect.type === "HTTPEffect") { + effectList += ' ' + effect.configuration.url + ' '; + } + if (effect.type === "CustomCodeEffect") { + effectList += ' ' + effect.configuration.code + ' '; + } + }); + + var triggerEffectDom = triggerText.toUpperCase() + ' '; + triggerEffectDom += triggerDesc; + triggerEffectDom += ' '; + triggerEffectDom += effectList; + triggerEffectDom += ' '; + return triggerEffectDom; + }; + hooksPlugin.getVuexModule = function() { var getEmptyState = function() { return { @@ -200,6 +258,7 @@ success: function(data) { if (data.hooksList && data.hooksList.length === 1) { var record = data.hooksList[0]; + record.triggerEfectDomForExport = hooksPlugin.generateTriggerActionsTreeForExport(record); record.triggerEffectDom = hooksPlugin.generateTriggerActionsTreeDom(record); record._canUpdate = countlyAuth.validateUpdate(FEATURE_NAME, countlyGlobal.member, record.apps[0]), record._canDelete = countlyAuth.validateDelete(FEATURE_NAME, countlyGlobal.member, record.apps[0]), @@ -329,6 +388,8 @@ var triggerEffectDom = hooksPlugin.generateTriggerActionsTreeDom(row); + var triggerEffectDomForExport = hooksPlugin.generateTriggerActionsTreeForExport(row); + tableData.push({ _id: hookList[i]._id, name: hookList[i].name || '', @@ -345,6 +406,7 @@ created_at: hookList[i].created_at || 0, created_at_string: moment(hookList[i].created_at).fromNow(), triggerEffectColumn: triggerEffectDom || "", + triggerEffectForExport: triggerEffectDomForExport || "", _canUpdate: countlyAuth.validateUpdate(FEATURE_NAME, countlyGlobal.member, hookList[i].apps[0]), _canDelete: countlyAuth.validateDelete(FEATURE_NAME, countlyGlobal.member, hookList[i].apps[0]), }); diff --git a/plugins/hooks/frontend/public/javascripts/countly.views.js b/plugins/hooks/frontend/public/javascripts/countly.views.js index 07a8d752ab2..1a358488870 100644 --- a/plugins/hooks/frontend/public/javascripts/countly.views.js +++ b/plugins/hooks/frontend/public/javascripts/countly.views.js @@ -109,6 +109,23 @@ onRowClick: function(params) { app.navigate("/manage/hooks/" + params._id, true); }, + formatExportFunction: function() { + var tableData = this.tableRows; + var table = []; + for (var i = 0; i < tableData.length; i++) { + var item = {}; + item[CV.i18n('hooks.hook-name').toUpperCase()] = tableData[i].name; + item[CV.i18n('hooks.description').toUpperCase()] = tableData[i].description; + item[CV.i18n('hooks.trigger-and-actions').toUpperCase()] = tableData[i].triggerEffectForExport; + item[CV.i18n('hooks.trigger-count').toUpperCase()] = tableData[i].triggerCount; + item[CV.i18n('hooks.trigger-last-time').toUpperCase()] = tableData[i].lastTriggerTimestampString === "-" ? "" : tableData[i].lastTriggerTimestampString; + item[CV.i18n('hooks.create-by').toUpperCase()] = tableData[i].createdByUser; + + table.push(item); + } + return table; + + }, } }); diff --git a/plugins/hooks/frontend/public/localization/hooks.properties b/plugins/hooks/frontend/public/localization/hooks.properties index d0319084100..6d997369251 100644 --- a/plugins/hooks/frontend/public/localization/hooks.properties +++ b/plugins/hooks/frontend/public/localization/hooks.properties @@ -49,7 +49,7 @@ hooks.trigger-instruction = TIPS hooks.trigger-copy-url = Copy URL hooks.test-hook=Test hook hooks.ScheduledTrigger = Scheduled Trigger - +hooks.trigger-and-actions = Trigger -> Actions #efffects hooks.CustomCodeEffect = Custom Code diff --git a/plugins/hooks/frontend/public/templates/vue-table.html b/plugins/hooks/frontend/public/templates/vue-table.html index 14132a924eb..59886c7a72c 100644 --- a/plugins/hooks/frontend/public/templates/vue-table.html +++ b/plugins/hooks/frontend/public/templates/vue-table.html @@ -5,6 +5,7 @@ class="cly-vue-hook-table is-clickable" :tracked-fields="localTableTrackedFields" :rows="tableRows" :resizable="false" + :exportFormat="formatExportFunction" :available-dynamic-cols="tableDynamicCols" > - +