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 d62cc729..3e6c582b 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 @@ -8,13 +8,13 @@ class StatsChart extends React.Component { static propTypes = { strokes: React.PropTypes.arrayOf(React.PropTypes.shape({ name: React.PropTypes.string, + show: React.PropTypes.bool, values: React.PropTypes.arrayOf(React.PropTypes.shape({ date: React.PropTypes.string, - show: React.PropTypes.bool, value: React.PropTypes.number })) })), - display: React.PropTypes.number + period: React.PropTypes.number }; render() { @@ -56,7 +56,7 @@ class StatsChart extends React.Component { datasets.push(dataset); } - + return { labels: labels, datasets: datasets @@ -67,7 +67,7 @@ class StatsChart extends React.Component { let months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; let labels = []; - for (let i = 0; i < this.props.display; i++) { + for (let i = 0; i < this.props.period; i++) { let firstList = this.props.strokes[0]; let idx = firstList.values[i].date.slice(4, 6) - 1; labels.push( firstList.values[i].date.slice(6, 8) + ' ' + months[idx]); @@ -77,9 +77,9 @@ class StatsChart extends React.Component { } hitRadius() { - if (this.props.display === 7) return 20; - if (this.props.display === 30) return 15; - if (this.props.display === 90) return 10; + if (this.props.period === 7) return 20; + if (this.props.period === 30) return 15; + if (this.props.period === 90) return 10; return 3; } 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 5b24047a..74843f6a 100644 --- a/client/src/app/admin/panel/dashboard/admin-panel-stats.js +++ b/client/src/app/admin/panel/dashboard/admin-panel-stats.js @@ -1,4 +1,5 @@ import React from 'react'; +import _ from 'lodash'; import i18n from 'lib-app/i18n'; import API from 'lib-app/api-call'; @@ -17,7 +18,30 @@ class AdminPanelStats extends React.Component { 'CREATE_TICKET': 0, 'SIGNUP': 0, 'COMMENT': 0 - } + }, + strokes: [ + { + name: 'CLOSE', + show: true, + values: [] + }, + { + name: 'CREATE_TICKET', + show: true, + values: [] + }, + { + name: 'SIGNUP', + show: true, + values: [] + }, + { + name: 'COMMENT', + show: true, + values: [] + } + ], + period: 0 }; componentDidMount() { @@ -36,7 +60,6 @@ class AdminPanelStats extends React.Component { } getToggleListProps() { - console.log('LALA: ' + this.state.stats); return { items: [ { @@ -95,9 +118,14 @@ class AdminPanelStats extends React.Component { } getStatsChartProps() { + + console.log('This is the shit'); + console.log(this.state.strokes); + return { - display: 7, - strokes: [ + period: this.state.period, + strokes: this.state.strokes + /*strokes: [ { name: 'COMMENT', show: true, @@ -200,7 +228,7 @@ class AdminPanelStats extends React.Component { } ] } - ] + ]*/ } } @@ -212,16 +240,54 @@ class AdminPanelStats extends React.Component { } onRetrieveSuccess(result) { + let newState = { 'CLOSE': 0, 'CREATE_TICKET': 0, 'SIGNUP': 0, 'COMMENT': 0 }; + + let ID = { + 'CLOSE': 0, + 'CREATE_TICKET': 1, + 'SIGNUP': 2, + 'COMMENT': 3 + }; + + let newStrokes = [ + { + name: 'CLOSE', + show: true, + values: [] + }, + { + name: 'CREATE_TICKET', + show: true, + values: [] + }, + { + name: 'SIGNUP', + show: true, + values: [] + }, + { + name: 'COMMENT', + show: true, + values: [] + } + ]; + for (let i = 0; i < result.data.length; i++) { newState[result.data[i].type] += result.data[i].value * 1; + + newStrokes[ ID[result.data[i].type] ].values.push({ + date: result.data[i].date, + value: result.data[i].value * 1 + }); } - this.setState({stats: newState}); + + this.setState({stats: newState, strokes: newStrokes, period: 7}); } } diff --git a/client/src/data/fixtures/system-fixtures.js b/client/src/data/fixtures/system-fixtures.js index 57db8e0a..76200c6c 100644 --- a/client/src/data/fixtures/system-fixtures.js +++ b/client/src/data/fixtures/system-fixtures.js @@ -246,55 +246,55 @@ module.exports = [ "date": "20170109", "type": "SIGNUP", "general": "1", - "value": "0" + "value": "7" }, { "date": "20170109", "type": "CLOSE", "general": "1", - "value": "0" + "value": "4" }, { "date": "20170109", "type": "CREATE_TICKET", "general": "1", - "value": "0" + "value": "9" }, { "date": "20170108", "type": "COMMENT", "general": "1", - "value": "0" + "value": "8" }, { "date": "20170108", "type": "SIGNUP", "general": "1", - "value": "0" + "value": "4" }, { "date": "20170108", "type": "CLOSE", "general": "1", - "value": "0" + "value": "5" }, { "date": "20170108", "type": "CREATE_TICKET", "general": "1", - "value": "0" + "value": "6" }, { "date": "20170107", "type": "COMMENT", "general": "1", - "value": "0" + "value": "4" }, { "date": "20170107", "type": "SIGNUP", "general": "1", - "value": "0" + "value": "1" }, { "date": "20170107", @@ -306,31 +306,31 @@ module.exports = [ "date": "20170107", "type": "CREATE_TICKET", "general": "1", - "value": "0" + "value": "2" }, { "date": "20170106", "type": "COMMENT", "general": "1", - "value": "0" + "value": "7" }, { "date": "20170106", "type": "SIGNUP", "general": "1", - "value": "0" + "value": "4" }, { "date": "20170106", "type": "CLOSE", "general": "1", - "value": "0" + "value": "5" }, { "date": "20170106", "type": "CREATE_TICKET", "general": "1", - "value": "0" + "value": "5" } ] };