From 7173e31510492ddf3f915e008fa68f4e03ad1e17 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 18 Feb 2015 19:00:49 -0800 Subject: [PATCH] crmMailingAB - Hyperlinks for stats. Get stats in a batch. --- js/angular-crmMailing/services.js | 65 +++++++++++++++++++++++++++++++ js/angular-crmMailingAB.js | 22 ++++++----- partials/crmMailingAB/report.html | 43 +++++++------------- 3 files changed, 91 insertions(+), 39 deletions(-) diff --git a/js/angular-crmMailing/services.js b/js/angular-crmMailing/services.js index 1ee3c89378..96dc1b6e83 100644 --- a/js/angular-crmMailing/services.js +++ b/js/angular-crmMailing/services.js @@ -427,4 +427,69 @@ }; }); + angular.module('crmMailing').factory('crmMailingStats', function (crmApi, crmLegacy) { + var statTypes = [ + // {name: 'Recipients', title: ts('Intended Recipients'), searchFilter: '', eventsFilter: '&event=queue'}, + {name: 'Delivered', title: ts('Successful Deliveries'), searchFilter: '&mailing_delivery_status=Y', eventsFilter: '&event=delivered'}, + {name: 'Opened', title: ts('Tracked Opens'), searchFilter: '&mailing_open_status=Y', eventsFilter: '&event=opened'}, + {name: 'Unique Clicks', title: ts('Click-throughs'), searchFilter: '&mailing_click_status=Y', eventsFilter: '&event=click&distinct=1'}, + // {name: 'Forward', title: ts('Forwards'), searchFilter: '&mailing_forward=1', eventsFilter: '&event=forward'}, + // {name: 'Replies', title: ts('Replies'), searchFilter: '&mailing_reply_status=Y', eventsFilter: '&event=reply'}, + {name: 'Bounces', title: ts('Bounces'), searchFilter: '&mailing_delivery_status=N', eventsFilter: '&event=bounce'}, + {name: 'Unsubscribers', title: ts('Unsubscribes'), searchFilter: '&mailing_unsubscribe=1', eventsFilter: '&event=unsubscribe'} + // {name: 'OptOuts', title: ts('Opt-Outs'), searchFilter: '&mailing_optout=1', eventsFilter: '&event=optout'} + ]; + + return { + getStatTypes: function() { + return statTypes; + }, + + /** + * @param mailingIds object + * List of mailing IDs ({a: 123, b: 456}) + * @return Promise + * List of stats for each mailing + * ({a: ...object..., b: ...object...}) + */ + getStats: function(mailingIds) { + var params = {}; + angular.forEach(mailingIds, function(mailingId, name) { + params[name] = ['Mailing', 'stats', {mailing_id: mailingId}]; + }); + return crmApi(params).then(function(result) { + var stats = {}; + angular.forEach(mailingIds, function(mailingId, name) { + stats[name] = result[name].values[mailingId]; + }); + return stats; + }); + }, + + /** + * Determine the legacy URL for a report about a given mailing and stat. + * + * @param mailing object + * @param statType object (see statTypes above) + * @param view string ('search', 'event', 'report') + * @return string|null + */ + getUrl: function getUrl(mailing, statType, view) { + switch (view) { + case 'events': + return crmLegacy.url('civicrm/mailing/report/event', + 'reset=1&mid=' + mailing.id + statType.eventsFilter); + + case 'search': + return crmLegacy.url('civicrm/contact/search/advanced', + 'force=1&mailing_id=' + mailing.id + statType.searchFilter); + + // TODO: case 'report': + default: + return null; + } + } + }; + }); + })(angular, CRM.$, CRM._); diff --git a/js/angular-crmMailingAB.js b/js/angular-crmMailingAB.js index 4d30b29de2..89d49bdfe2 100644 --- a/js/angular-crmMailingAB.js +++ b/js/angular-crmMailingAB.js @@ -203,19 +203,21 @@ $scope.$on('$destroy', myAutosave.stop); }); - angular.module('crmMailingAB').controller('CrmMailingABReportCtrl', function ($scope, crmApi, crmMailingStats, crmLegacy) { + angular.module('crmMailingAB').controller('CrmMailingABReportCtrl', function ($scope, crmApi, crmMailingStats) { var ts = $scope.ts = CRM.ts(null); - $scope.stats = {}; - crmApi('Mailing', 'stats', {mailing_id: $scope.abtest.ab.mailing_id_a}).then(function(data){ - $scope.stats.a = data.values[$scope.abtest.ab.mailing_id_a]; - }); - crmApi('Mailing', 'stats', {mailing_id: $scope.abtest.ab.mailing_id_b}).then(function(data){ - $scope.stats.b = data.values[$scope.abtest.ab.mailing_id_b]; - }); - crmApi('Mailing', 'stats', {mailing_id: $scope.abtest.ab.mailing_id_c}).then(function(data){ - $scope.stats.c = data.values[$scope.abtest.ab.mailing_id_c]; + crmMailingStats.getStats({ + a: $scope.abtest.ab.mailing_id_a, + b: $scope.abtest.ab.mailing_id_b, + c: $scope.abtest.ab.mailing_id_c + }).then(function(stats) { + $scope.stats = stats; }); + + $scope.statTypes = crmMailingStats.getStatTypes(); + $scope.statUrl = function statUrl(mailing, statType, view) { + return crmMailingStats.getUrl(mailing, statType, view); + }; }); angular.module('crmMailingAB').controller('CrmMailingABWinnerDialogCtrl', function ($scope, $timeout, dialogService, crmMailingMgr, crmStatus) { diff --git a/partials/crmMailingAB/report.html b/partials/crmMailingAB/report.html index 4913630e07..89a0d8a38b 100644 --- a/partials/crmMailingAB/report.html +++ b/partials/crmMailingAB/report.html @@ -21,35 +21,20 @@ {{ts('View')}} {{ts('View')}} - - {{ts('Deliveries')}} - {{stats.a.Delivered}} - {{stats.b.Delivered}} - {{stats.c.Delivered}} - - - {{ts('Opens')}} - {{stats.a.Opened}} - {{stats.b.Opened}} - {{stats.c.Opened}} - - - {{ts('Unique Clicks')}} - {{stats.a['Unique Clicks']}} - {{stats.b['Unique Clicks']}} - {{stats.c['Unique Clicks']}} - - - {{ts('Bounces')}} - {{stats.a.Bounces}} - {{stats.b.Bounces}} - {{stats.c.Bounces}} - - - {{ts('Unsubscribes')}} - {{stats.a.Unsubscribers}} - {{stats.b.Unsubscribers}} - {{stats.c.Unsubscribers}} + + {{statType.title}} + + {{stats.a[statType.name] || ts('n/a')}} + + + + {{stats.b[statType.name] || ts('n/a')}} + + + + {{stats.a[statType.name] || ts('n/a')}} + + -- 2.25.1