FEATURE: displays average for 2 columns tables which support average

FEATURE: displays average for 2 columns tables which support average

diff --git a/app/assets/javascripts/admin/components/admin-report-table.js.es6 b/app/assets/javascripts/admin/components/admin-report-table.js.es6
index 0b52599..bba15f0 100644
--- a/app/assets/javascripts/admin/components/admin-report-table.js.es6
+++ b/app/assets/javascripts/admin/components/admin-report-table.js.es6
@@ -31,6 +31,16 @@ export default Ember.Component.extend({
     return reportTotal && total && twoColumns;
   },
 
+  @computed("model.average", "totalsForSample.1.value", "twoColumns")
+  showAverage(reportAverage, totalValue, twoColumns) {
+    return reportAverage && totalValue && twoColumns;
+  },
+
+  @computed("totalsForSample.1.value", "model.data.length")
+  averageForSample(totals, count) {
+    return (totals / count).toFixed(0);
+  },
+
   @computed("model.data.length")
   showSortingUI(dataLength) {
     return dataLength >= 5;
diff --git a/app/assets/javascripts/admin/templates/components/admin-report-table.hbs b/app/assets/javascripts/admin/templates/components/admin-report-table.hbs
index 6011407..0fccf35 100644
--- a/app/assets/javascripts/admin/templates/components/admin-report-table.hbs
+++ b/app/assets/javascripts/admin/templates/components/admin-report-table.hbs
@@ -48,6 +48,18 @@
         <td class="admin-report-table-cell number y">{{number model.total}}</td>
       </tr>
     {{/if}}
+
+    {{#if showAverage}}
+      <tr class="total-row">
+        <td colspan="2">
+          {{i18n 'admin.dashboard.reports.average'}}
+        </td>
+      </tr>
+      <tr class="admin-report-table-row">
+        <td class="admin-report-table-cell date x">—</td>
+        <td class="admin-report-table-cell number y">{{number averageForSample}}</td>
+      </tr>
+    {{/if}}
   </tbody>
 </table>
 
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 030d754..65b7a27 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -3111,6 +3111,7 @@ en:
           groups: "All groups"
           disabled: "This report is disabled"
           totals_for_sample: "Totals for sample"
+          average_for_sample: "Average for sample"
           total: "All time total"
           no_data: "No data to display."
           trending_search:

GitHub sha: b79d02ff

Are we 100% sure count is always !== 0 ?

hmmm that’s a good point will check this thx

1 Like