Skip to content

Commit

Permalink
[5.1] MSPB-295,MSPB-296: Copy diagnostic data for a call instead of p…
Browse files Browse the repository at this point in the history
…roducing an html email link (#461) (#469)
  • Loading branch information
oscbco authored Nov 21, 2022
1 parent fe76ea5 commit f257025
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 20 deletions.
20 changes: 19 additions & 1 deletion i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
},

Expand Down
137 changes: 119 additions & 18 deletions submodules/callLogs/callLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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');
Expand All @@ -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')
Expand All @@ -230,6 +324,10 @@ define(function(require) {
submodule: 'callLogs'
})));
});
} else {
// Handle copy diagnostic data button
var otherLegs = $this.data('otherLegs');
self.callLogsTriggerCopy(target, otherLegs);
}
}
});
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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) && {
Expand Down
2 changes: 1 addition & 1 deletion submodules/callLogs/views/cdrsList.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</div>
<div class="grid-cell actions">
<div class="sub-cell single-cell">
{{#if ../showReport}}<a class="monster-link" target="_blank" href="{{this.mailtoLink}}"><i data-placement="top" data-toggle="tooltip" data-placement="top" data-original-title="{{ @root.i18n.callLogs.actions.report }}" class="fa fa-lg fa-fire-extinguisher"></i></a>{{/if}}
{{#if ../showReport}}<i data-placement="top" data-toggle="tooltip" data-placement="top" data-original-title="{{ @root.i18n.callLogs.actions.report }}" class="fa fa-lg fa-clone copy-diag-data" data-id="{{this.id}}" data-diag-data="{{this.diagData}}"></i>{{/if}}
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions submodules/callLogs/views/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,7 @@
<div class="loader-message">{{i18n.callLogs.loaderMessage}}</div>
<div class="loading-message"><i class="fa fa-spinner fa-lg"></i><span>{{i18n.callLogs.loadingMessage}}</span></div>
</div>

<!-- DOM element to which clipboard click events can be anchored without interfeering with the toggle main-leg logic -->
<div class="copy-diag-data-target"></div>
</div>

0 comments on commit f257025

Please sign in to comment.