From f2570259409f774a94ecf5b87de1a2b753e42540 Mon Sep 17 00:00:00 2001 From: Oscar Barrera Date: Mon, 21 Nov 2022 11:13:44 -0600 Subject: [PATCH] [5.1] MSPB-295,MSPB-296: Copy diagnostic data for a call instead of producing an html email link (#461) (#469) --- i18n/en-US.json | 20 +++- submodules/callLogs/callLogs.js | 137 ++++++++++++++++++++---- submodules/callLogs/views/cdrsList.html | 2 +- submodules/callLogs/views/layout.html | 3 + 4 files changed, 142 insertions(+), 20 deletions(-) diff --git a/i18n/en-US.json b/i18n/en-US.json index 6d880651..781b892e 100644 --- a/i18n/en-US.json +++ b/i18n/en-US.json @@ -1234,9 +1234,27 @@ "__version": "v4.0", "loading": "Loading additional information...", "actions": { - "report": "Report Call", + "report": "Copy details", "details": "Technical Details" }, + "diagnosticCallData": { + "accountId": "Account ID: {{variable}}", + "fromName": "From (Name): {{variable}}", + "fromNumber": "From (Number): {{variable}}", + "toName": "To (Name): {{variable}}", + "toNumber": "To (Number): {{variable}}", + "date": "Date: {{variable}}", + "duration": "Duration: {{variable}}", + "hangUpCause": "Hangup Cause: {{variable}}", + "callId": "Call ID: {{variable}}", + "otherLegCallId": "Other Leg Call ID: {{variable}}", + "otherLegs": "Other Legs: {{variable}}", + "handlingServer": "Handling Server: {{variable}}", + "timestamp": "Timestamp: {{variable}}", + "base64Encoded": "Base64 Encoded: {{variable}}" + }, + "copyCallDiagInfo": "Diagnostic data copied to clipboard, please email this to your support representative for assistance", + "copyCallDiagError": "An error occurred while copying diagnostic data to clipboard", "downloadTooltip": "In \"Custom\" Mode, you'll need to click on \"Filter\" before clicking on download." }, diff --git a/submodules/callLogs/callLogs.js b/submodules/callLogs/callLogs.js index ac224382..231a5463 100644 --- a/submodules/callLogs/callLogs.js +++ b/submodules/callLogs/callLogs.js @@ -41,6 +41,88 @@ define(function(require) { }); }, + callLogsGenerateCallData: function(target, otherLegs, callback) { + var self = this; + + monster.waterfall([ + function addOtherLegsToCall(next) { + try { + var $this = $(target), + call = $this.data('diag-data'); + call.other_legs = otherLegs; + + next(null, call); + } catch (e) { + next(e); + } + }, + function encodeCallToBase64(call, next) { + try { + var base64EncodedCall = btoa(JSON.stringify(call)); + + next(null, call, base64EncodedCall); + } catch (e) { + next(e); + } + }, + function formatCallData(call, base64EncodedCall, next) { + var diagnosticData = _.chain([ + { i18nKey: 'accountId', prop: 'account_id' }, + { i18nKey: 'fromName', prop: 'from_name' }, + { i18nKey: 'fromNumber', prop: 'from_number' }, + { i18nKey: 'toName', prop: 'to_name' }, + { i18nKey: 'toNumber', prop: 'to_number' }, + { i18nKey: 'date', prop: 'date' }, + { i18nKey: 'duration', prop: 'duration' }, + { i18nKey: 'hangUpCause', prop: 'hangup_cause' }, + { i18nKey: 'callId', prop: 'call_id' }, + { i18nKey: 'otherLegCallId', value: call.other_leg_call_id }, + { i18nKey: 'otherLegs', value: '\n ' + _.join(otherLegs, '\n ') }, + { i18nKey: 'handlingServer', prop: 'handling_server' }, + { i18nKey: 'timestamp', prop: 'timestamp' }, + { i18nKey: 'base64Encoded', value: base64EncodedCall } + ]) + .map(function(data) { + var template = self.getTemplate({ + name: '!' + monster.util.tryI18n(self.i18n.active().callLogs.diagnosticCallData, data.i18nKey), + data: { + variable: _.find([ + data.value, + _.get(call, data.prop), + '' + ], _.isString) + }, + ignoreSpaces: true + }); + return template; + }).join('\n').value(); + + next(null, diagnosticData); + } + ], callback); + }, + + callLogsTriggerCopy: function(target, otherLegs) { + var self = this; + + if (!target.classList.contains('copy-diag-data')) { + return; + } + + self.callLogsGenerateCallData(target, otherLegs, function(err, callData) { + if (err) { + return monster.ui.toast({ + type: 'error', + message: self.i18n.active().callLogs.copyCallDiagError + }); + } + + var clipboardTarget = $('#call_logs_container .copy-diag-data-target'); + clipboardTarget.data('callData', callData); + clipboardTarget.trigger('click'); + }); + }, + callLogsRenderContent: function(parent, fromDate, toDate, type, callback) { var self = this, template, @@ -201,11 +283,16 @@ define(function(require) { var $this = $(this), rowGroup = $this.parents('.grid-row-group'), callId = $this.data('id'), - extraLegs = rowGroup.find('.extra-legs'); + extraLegs = rowGroup.find('.extra-legs'), + target = e.target; if (rowGroup.hasClass('open')) { rowGroup.removeClass('open'); extraLegs.slideUp(); + + // Handle copy diagnostic data button + var otherLegs = $this.data('otherLegs'); + self.callLogsTriggerCopy(target, otherLegs); } else { // Reset all slidedDown legs template.find('.grid-row-group').removeClass('open'); @@ -219,6 +306,13 @@ define(function(require) { self.callLogsGetLegs(callId, function(cdrs) { var formattedCdrs = self.callLogsFormatCdrs(cdrs); + // Make other legs available when querying but not copying + var otherLegs = cdrs.map(function(call) { return call.id; }); + + // Handle copy diagnostic data button + $this.data('otherLegs', otherLegs); + self.callLogsTriggerCopy(target, otherLegs); + rowGroup.find('.extra-legs') .empty() .addClass('data-loaded') @@ -230,6 +324,10 @@ define(function(require) { submodule: 'callLogs' }))); }); + } else { + // Handle copy diagnostic data button + var otherLegs = $this.data('otherLegs'); + self.callLogsTriggerCopy(target, otherLegs); } } }); @@ -293,6 +391,10 @@ define(function(require) { template.find('.call-logs-loader:not(.loading) .loader-message').on('click', function(e) { loadMoreCdrs(); }); + + monster.ui.clipboard(template.find('.copy-diag-data-target'), function(trigger) { + return $(trigger).data('callData'); + }, self.i18n.active().callLogs.copyCallDiagInfo); }, // Function built to return JS Dates for the fixed ranges. @@ -391,7 +493,21 @@ define(function(require) { .get('request', cdr.to) .thru(extractSipDestination) .value(), - device = _.get(self.appFlags.callLogs.devices, _.get(cdr, 'custom_channel_vars.authorizing_id')); + device = _.get(self.appFlags.callLogs.devices, _.get(cdr, 'custom_channel_vars.authorizing_id')), + base64DiagData = JSON.stringify({ + account_id: self.accountId, + from_name: (cdr.caller_id_name || ''), + from_number: fromNumber, + to_name: (cdr.callee_id_name || ''), + to_number: toNumber, + date: shortDate, + duration: durationMin + ':' + durationSec, + hangup_cause: (cdr.hangup_cause || ''), + call_id: cdr.call_id, + other_leg_call_id: (cdr.other_leg_call_id || ''), + handling_server: (cdr.media_server || ''), + timestamp: (cdr.timestamp || '') + }); return _.merge({ id: cdr.id, @@ -412,22 +528,7 @@ define(function(require) { // Only display help if it's in the i18n. hangupHelp: _.get(hangupI18n, [cdr.hangup_cause, isOutboundCall ? 'outbound' : 'inbound'], ''), isOutboundCall: isOutboundCall, - mailtoLink: 'mailto:' + monster.config.whitelabel.callReportEmail - + '?subject=Call Report: ' + cdr.call_id - + '&body=Please describe the details of the issue:%0D%0A%0D%0A' - + '%0D%0A____________________________________________________________%0D%0A' - + '%0D%0AAccount ID: ' + self.accountId - + '%0D%0AFrom (Name): ' + (cdr.caller_id_name || '') - + '%0D%0AFrom (Number): ' + fromNumber - + '%0D%0ATo (Name): ' + (cdr.callee_id_name || '') - + '%0D%0ATo (Number): ' + toNumber - + '%0D%0ADate: ' + shortDate - + '%0D%0ADuration: ' + durationMin + ':' + durationSec - + '%0D%0AHangup Cause: ' + (cdr.hangup_cause || '') - + '%0D%0ACall ID: ' + cdr.call_id - + '%0D%0AOther Leg Call ID: ' + (cdr.other_leg_call_id || '') - + '%0D%0AHandling Server: ' + (cdr.media_server || '') - + '%0D%0ATimestamp: ' + (cdr.timestamp || '') + diagData: base64DiagData }, _.has(cdr, 'channel_created_time') && { channelCreatedTime: cdr.channel_created_time }, !_.isUndefined(device) && { diff --git a/submodules/callLogs/views/cdrsList.html b/submodules/callLogs/views/cdrsList.html index c06273f6..6a2c866b 100644 --- a/submodules/callLogs/views/cdrsList.html +++ b/submodules/callLogs/views/cdrsList.html @@ -42,7 +42,7 @@
- {{#if ../showReport}}{{/if}} + {{#if ../showReport}}{{/if}}
diff --git a/submodules/callLogs/views/layout.html b/submodules/callLogs/views/layout.html index c85b8081..bbbf0b2f 100644 --- a/submodules/callLogs/views/layout.html +++ b/submodules/callLogs/views/layout.html @@ -93,4 +93,7 @@
{{i18n.callLogs.loaderMessage}}
{{i18n.callLogs.loadingMessage}}
+ + +