diff --git a/app/controllers/api/v2/accounts/reports_controller.rb b/app/controllers/api/v2/accounts/reports_controller.rb index dedeb17bf..a9fc5d4b4 100644 --- a/app/controllers/api/v2/accounts/reports_controller.rb +++ b/app/controllers/api/v2/accounts/reports_controller.rb @@ -32,6 +32,11 @@ class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController generate_csv('teams_report', 'api/v2/accounts/reports/teams') end + def conversation_traffic + @report_data = generate_conversations_heatmap_report + generate_csv('conversation_traffic_reports', 'api/v2/accounts/reports/conversation_traffic') + end + def conversations return head :unprocessable_entity if params[:type].blank? diff --git a/app/helpers/api/v2/accounts/reports_helper.rb b/app/helpers/api/v2/accounts/reports_helper.rb index 0604eba2f..b15683afd 100644 --- a/app/helpers/api/v2/accounts/reports_helper.rb +++ b/app/helpers/api/v2/accounts/reports_helper.rb @@ -27,6 +27,27 @@ module Api::V2::Accounts::ReportsHelper end end + def generate_conversations_heatmap_report + report_params = { + type: :account, + group_by: 'hour', + since: params[:since], + until: params[:until], + metric: 'conversations_count', + business_hours: false + } + data = V2::ReportBuilder.new(Current.account, report_params).build + + # data format is { timestamp: 1231242342, value: 3} + # we need to convert it to { date: "2020-01-01", hour: 12, value: 3} + # + # the generated report is **always** in UTC timezone + data.map do |d| + date = Time.zone.at(d[:timestamp]).to_s + [date, d[:value]] + end + end + def generate_report(report_params) V2::ReportBuilder.new( Current.account, diff --git a/app/javascript/dashboard/api/reports.js b/app/javascript/dashboard/api/reports.js index 29fefeec8..dbd795f3c 100644 --- a/app/javascript/dashboard/api/reports.js +++ b/app/javascript/dashboard/api/reports.js @@ -59,6 +59,12 @@ class ReportsAPI extends ApiClient { }); } + getConversationTrafficCSV({ from: since, to: until }) { + return axios.get(`${this.url}/conversation_traffic`, { + params: { since, until }, + }); + } + getLabelReports({ from: since, to: until, businessHours }) { return axios.get(`${this.url}/labels`, { params: { since, until, business_hours: businessHours }, diff --git a/app/javascript/dashboard/routes/dashboard/settings/reports/LiveReports.vue b/app/javascript/dashboard/routes/dashboard/settings/reports/LiveReports.vue index 5de08717f..7acfc6251 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/reports/LiveReports.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/reports/LiveReports.vue @@ -40,6 +40,17 @@ +
-
{{ header }}
- - {{ $t('OVERVIEW_REPORTS.LIVE') }} - + +
+
{{ header }}
+ + {{ + $t('OVERVIEW_REPORTS.LIVE') + }} + +
+
+ +
+
@@ -42,37 +51,66 @@ export default {