From 8c50cc97c91f04ba3fee33d00fed15388e9d78b9 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 14 Jan 2017 15:15:26 -0300 Subject: [PATCH] Max Red - Create stats state, and display correct values in the toggle list [skip ci] --- .../dashboard/admin-panel-stats-chart.js | 6 +- .../panel/dashboard/admin-panel-stats.js | 61 +++++++++++++++++-- client/src/data/languages/en.js | 1 + 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/client/src/app/admin/panel/dashboard/admin-panel-stats-chart.js b/client/src/app/admin/panel/dashboard/admin-panel-stats-chart.js index b5582017..d62cc729 100644 --- a/client/src/app/admin/panel/dashboard/admin-panel-stats-chart.js +++ b/client/src/app/admin/panel/dashboard/admin-panel-stats-chart.js @@ -29,10 +29,10 @@ class StatsChart extends React.Component { let labels = this.getLabels(); let color = { - 'CREATE_TICKET': 'rgba(150, 20, 20, 0.8)', - 'CLOSE': 'rgba(20, 150, 20, 0.8)', + 'CLOSE': 'rgba(150, 20, 20, 0.8)', + 'CREATE_TICKET': 'rgba(20, 150, 20, 0.8)', 'SIGNUP': 'rgba(20, 20, 150, 0.8)', - 'COMMENT': 'rgba(150, 150, 20, 0.8)' + 'COMMENT': 'rgba(20, 200, 200, 0.8)' }; let datasets = []; diff --git a/client/src/app/admin/panel/dashboard/admin-panel-stats.js b/client/src/app/admin/panel/dashboard/admin-panel-stats.js index a7ae93dc..5b24047a 100644 --- a/client/src/app/admin/panel/dashboard/admin-panel-stats.js +++ b/client/src/app/admin/panel/dashboard/admin-panel-stats.js @@ -1,6 +1,7 @@ import React from 'react'; import i18n from 'lib-app/i18n'; +import API from 'lib-app/api-call'; import Header from 'core-components/header'; import DropDown from 'core-components/drop-down'; @@ -10,6 +11,19 @@ import StatsChart from 'app/admin/panel/dashboard/admin-panel-stats-chart'; class AdminPanelStats extends React.Component { + state = { + stats: { + 'CLOSE': 0, + 'CREATE_TICKET': 0, + 'SIGNUP': 0, + 'COMMENT': 0 + } + }; + + componentDidMount() { + this.retrieve(); + } + render() { return (
@@ -22,19 +36,36 @@ class AdminPanelStats extends React.Component { } getToggleListProps() { + console.log('LALA: ' + this.state.stats); return { items: [ { - content:
+ content: +
+ {this.state.stats['CREATE_TICKET']} +
{i18n('CHART_CREATE_TICKET')}
+
}, { - content:
+ content: +
+ {this.state.stats['CLOSE']} +
{i18n('CHART_CLOSE')}
+
}, { - content:
+ content: +
+ {this.state.stats['SIGNUP']} +
{i18n('CHART_SIGNUP')}
+
}, { - content:
+ content: +
+ {this.state.stats['COMMENT']} +
{i18n('CHART_COMMENT')}
+
} ] }; @@ -68,7 +99,7 @@ class AdminPanelStats extends React.Component { display: 7, strokes: [ { - name: 'CREATE_TICKET', + name: 'COMMENT', show: true, values: [ { @@ -172,6 +203,26 @@ class AdminPanelStats extends React.Component { ] } } + + retrieve() { + API.call({ + path: '/system/get-stats', + data: {} + }).then(this.onRetrieveSuccess.bind(this)); + } + + onRetrieveSuccess(result) { + let newState = { + 'CLOSE': 0, + 'CREATE_TICKET': 0, + 'SIGNUP': 0, + 'COMMENT': 0 + }; + for (let i = 0; i < result.data.length; i++) { + newState[result.data[i].type] += result.data[i].value * 1; + } + this.setState({stats: newState}); + } } export default AdminPanelStats; \ No newline at end of file diff --git a/client/src/data/languages/en.js b/client/src/data/languages/en.js index ceda9f35..cb576806 100644 --- a/client/src/data/languages/en.js +++ b/client/src/data/languages/en.js @@ -154,6 +154,7 @@ export default { 'VERIFY_FAILED': 'Could not verify', 'TICKET_ACTIVITY': 'Ticket Activity', + 'CHART_CREATE_TICKET': 'Tickets created', 'CHART_CLOSE': 'Tickets closed', 'CHART_SIGNUP': 'Signups',