From 776a7f518a431132ae34813d35cd255b33d8572f Mon Sep 17 00:00:00 2001 From: Jean-Roch Maitre Date: Thu, 28 Jul 2016 15:18:33 -0700 Subject: [PATCH] UI-2233: first step of migration of fax logs to fax app --- app.js | 169 +++++++++++++++++++++++++++++++++++++++++ i18n/en-US.json | 21 ++++- style/app.css | 21 +++++ views/logs-detail.html | 30 ++++++++ views/logs-layout.html | 5 ++ 5 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 views/logs-detail.html create mode 100644 views/logs-layout.html diff --git a/app.js b/app.js index 86a4c54..82bd72e 100644 --- a/app.js +++ b/app.js @@ -59,6 +59,10 @@ define(function(require){ { text: self.i18n.active().fax.menuTitles.outbound, callback: self.renderOutbound + }, + { + text: self.i18n.active().fax.menuTitles.logs, + callback: self.renderLogs } ] } @@ -407,6 +411,171 @@ define(function(require){ return self.apiUrl + 'accounts/' + self.accountId + '/faxes/'+ type +'/' + mediaId + '/attachment?auth_token=' + self.authToken; }, + renderLogs: function(pArgs) { + var self = this, + args = pArgs || {}, + parent = args.container || $('#fax_app_container .app-content-wrapper'), + template = $(monster.template(self, 'logs-layout')); + + self.logsInitTable(template, function() { + self.logsBindEvents(template); + + parent + .fadeOut(function() { + $(this) + .empty() + .append(template) + .fadeIn(); + }); + }); + }, + + logsBindEvents: function(template) { + var self = this; + + template.on('click','.detail-link', function() { + var logId = $(this).data('id'); + + self.logsRenderDetailPopup(logId); + }); + }, + + logsRenderDetailPopup: function(logId) { + var self = this; + + self.logsGetDetails(logId, function(details) { + var detailTemplate = $(monster.template(self, 'logs-detail', details)); + + detailTemplate.find('#close').on('click', function() { + popup.dialog('close').remove(); + }); + + var popup = monster.ui.dialog(detailTemplate, { + title: self.i18n.active().fax.logs.detailDialog.popupTitle, + position: ['center', 20] + }); + }); + }, + + logsFormatDataTable: function(logs) { + var self = this, + formattedArray = []; + + $.each(logs, function() { + formattedArray.push([this.hasOwnProperty('error'), this.from || '-', this.to || '-', monster.util.toFriendlyDate(this.created), this.id, this.id, this.created]); + }); + + return formattedArray; + }, + + logsFormatDetailData: function(details) { + var self = this, + formattedData = { + metadata: {}, + errors: [] + }, + formattedKey = ''; + + _.each(details, function(value, key) { + if(key === 'errors') { + formattedData.errors = value; + } + else { + formattedKey = self.i18n.active().fax.logs.detailDialog.apiKeys.hasOwnProperty(key) ? self.i18n.active().fax.logs.detailDialog.apiKeys[key] : key.replace(/_/g, ' '); + formattedData.metadata[key] = { + friendlyKey: formattedKey, + value: value + } + } + }); + + return formattedData; + }, + + logsInitTable: function(template, callback) { + var self = this, + hasError, + iconClass, + columns = [ + { + 'sTitle': self.i18n.active().fax.logs.tableTitles.status, + 'fnRender': function(obj) { + hasError = obj.aData[0]; + iconClass = hasError ? 'thumbs-down monster-red' : 'thumbs-up monster-green'; + + return ''; + } + }, + { + 'sTitle': self.i18n.active().fax.logs.tableTitles.from + }, + { + 'sTitle': self.i18n.active().fax.logs.tableTitles.to + }, + { + 'sTitle': self.i18n.active().fax.logs.tableTitles.date + }, + { + 'sTitle': self.i18n.active().fax.logs.tableTitles.details, + 'fnRender': function(obj) { + return ''; + } + }, + { + 'sTitle': 'ID', + bVisible: false + }, + { + 'sTitle': 'Timestamp', + bVisible: false + } + ]; + + self.logsGetData(function(logs) { + monster.ui.table.create('logs', template.find('#smtp_logs_grid'), columns, logs, { + sDom: '<"table-custom-actions">frtlip', + aaSorting: [[3, 'desc']] + }); + + $.fn.dataTableExt.afnFiltering.pop(); + + callback && callback(); + }); + }, + + logsGetData: function(callback) { + var self = this; + + self.callApi({ + resource: 'faxes.getLogs', + data: { + accountId: self.accountId + }, + success: function(data) { + var formattedData = self.logsFormatDataTable(data.data); + + callback && callback(formattedData); + } + }); + }, + + logsGetDetails: function(id, callback) { + var self = this; + + self.callApi({ + resource: 'faxes.getLogDetails', + data: { + accountId: self.accountId, + logId: id + }, + success: function(data) { + var formattedData = self.logsFormatDetailData(data.data); + + callback && callback(formattedData); + } + }); + }, + getInboundFaxes: function(fromDate, toDate, callback) { var self = this; diff --git a/i18n/en-US.json b/i18n/en-US.json index 5926c47..010a057 100644 --- a/i18n/en-US.json +++ b/i18n/en-US.json @@ -3,7 +3,8 @@ "title": "Fax Portal", "menuTitles": { "inbound": "Inbound faxes", - "outbound": "Outbound faxes" + "outbound": "Outbound faxes", + "logs": "Logs" }, "table": { "columns": { @@ -66,6 +67,24 @@ "confirmButtonText": "Re-send Faxes", "title": "Are you sure?", "success": "You successfully tried to re-send the selected faxes!" + }, + + + "logs": { + "tableTitles": { + "from": "From", + "to": "To", + "date": "Date", + "details": "Details", + "status": "Status" + }, + "detailDialog": { + "popupTitle": "Technical Details", + "metadataTitle": "Metadata", + "errorTitle": "Error(s)", + "apiKeys": { + } + } } } } \ No newline at end of file diff --git a/style/app.css b/style/app.css index 6a0bbf2..31f617a 100644 --- a/style/app.css +++ b/style/app.css @@ -175,4 +175,25 @@ #faxbox_cdr_details_dialog { width: 750px; margin: 15px; +} + +/* Faxes log */ +#smtp_logs_container .table .detail-link { + margin: 0px; +} + +#smtp_logs_grid { + clear: right; +} + +#smtp_logs_detail_dialog { + width: 700px; + padding: 15px; +} + +#smtp_logs_detail_dialog tr, +#smtp_logs_detail_dialog td { + line-height: 15px; + padding: 2px; + white-space: normal; } \ No newline at end of file diff --git a/views/logs-detail.html b/views/logs-detail.html new file mode 100644 index 0000000..bb53c75 --- /dev/null +++ b/views/logs-detail.html @@ -0,0 +1,30 @@ +
+

{{ i18n.fax.logs.detailDialog.metadataTitle }}

+ + + + {{#each metadata}} + + + + + {{/each}} + +
{{ this.friendlyKey }}{{ this.value }}
+ +

{{ i18n.fax.logs.detailDialog.errorTitle }}

+ + + + {{#each errors}} + + + + {{/each}} + +
{{this}}
+ +
+ +
+
diff --git a/views/logs-layout.html b/views/logs-layout.html new file mode 100644 index 0000000..f37dc3a --- /dev/null +++ b/views/logs-layout.html @@ -0,0 +1,5 @@ +
+
+
+
+