2016-11-24 16:29:11 +01:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
import { h, render, Component } from 'preact';
|
|
|
|
import Pageviews from '../components/Pageviews.js';
|
|
|
|
import Realtime from '../components/Realtime.js';
|
2016-12-07 21:40:06 +01:00
|
|
|
import GraphWidget from '../components/GraphWidget.js';
|
2016-11-24 16:29:11 +01:00
|
|
|
import DatePicker from '../components/DatePicker.js';
|
|
|
|
import Table from '../components/Table.js';
|
2016-11-25 13:38:20 +01:00
|
|
|
import HeaderBar from '../components/HeaderBar.js';
|
2016-11-26 15:39:29 +01:00
|
|
|
import CountWidget from '../components/CountWidget.js';
|
2016-11-24 16:29:11 +01:00
|
|
|
|
2016-11-26 16:17:52 +01:00
|
|
|
function removeImgElement(e) {
|
|
|
|
e.target.parentNode.removeChild(e.target);
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatCountryLabel(p) {
|
|
|
|
const src = "/static/img/country-flags/"+ p.Label.toLowerCase() +".png"
|
|
|
|
|
|
|
|
return (
|
|
|
|
<td>
|
|
|
|
{p.Label}
|
|
|
|
<img height="12" src={src} class="pull-right" onError={removeImgElement} />
|
|
|
|
</td>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-11-24 16:29:11 +01:00
|
|
|
class Dashboard extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
this.state = {
|
2016-12-24 10:42:05 +02:00
|
|
|
period: parseInt(window.location.hash.substring(2)) || 7
|
2016-11-24 16:29:11 +01:00
|
|
|
}
|
2016-12-24 10:42:05 +02:00
|
|
|
|
|
|
|
this.onPeriodChoose = this.onPeriodChoose.bind(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
onPeriodChoose(p) {
|
|
|
|
this.setState({ period: p })
|
|
|
|
window.history.replaceState(this.state, null, `#!${p}`)
|
2016-11-24 16:29:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-11-25 13:16:42 +01:00
|
|
|
return (
|
|
|
|
<div>
|
2016-11-25 13:38:20 +01:00
|
|
|
<HeaderBar showLogout={true} onLogout={this.props.onLogout} />
|
2016-11-25 13:16:42 +01:00
|
|
|
<div class="container">
|
2016-11-24 16:29:11 +01:00
|
|
|
<Realtime />
|
|
|
|
<div class="clear">
|
2016-12-24 10:42:05 +02:00
|
|
|
<DatePicker period={this.state.period} onChoose={this.onPeriodChoose} />
|
2016-11-24 16:29:11 +01:00
|
|
|
</div>
|
2016-11-26 15:39:29 +01:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-2">
|
2016-12-10 14:16:05 +01:00
|
|
|
<CountWidget title="Visitors" endpoint="visitors" period={this.state.period} />
|
2016-11-26 15:39:29 +01:00
|
|
|
</div>
|
|
|
|
<div class="col-2">
|
|
|
|
<CountWidget title="Pageviews" endpoint="pageviews" period={this.state.period} />
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-12-07 21:40:06 +01:00
|
|
|
<GraphWidget period={this.state.period} />
|
2016-11-24 16:47:33 +01:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-4">
|
|
|
|
<Pageviews period={this.state.period} />
|
|
|
|
</div>
|
|
|
|
<div class="col-2">
|
|
|
|
<Table period={this.state.period} endpoint="languages" title="Languages" headers={["#", "Language", "Count", "%"]} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-2">
|
|
|
|
<Table period={this.state.period} endpoint="screen-resolutions" title="Screen Resolutions" headers={["#", "Resolution", "Count", "%"]} />
|
|
|
|
</div>
|
|
|
|
<div class="col-2">
|
2016-12-11 12:52:10 +01:00
|
|
|
<Table period={this.state.period} endpoint="referrers" title="Referrers" headers={["#", "URL", "Count", "%"]} labelCell={(p) => ( <td><a href={"//" + p.Label}>{p.Label.substring(0, 15).replace('https://', '').replace('http://', '')}</a></td>)} />
|
2016-11-24 16:47:33 +01:00
|
|
|
</div>
|
|
|
|
<div class="col-2">
|
2016-11-25 16:30:38 +01:00
|
|
|
<Table period={this.state.period} endpoint="browsers" title="Browsers" headers={["#", "Browser", "Count", "%"]} onAuthError={this.props.onLogout} />
|
2016-11-24 16:47:33 +01:00
|
|
|
</div>
|
2016-11-24 16:29:11 +01:00
|
|
|
</div>
|
2016-11-25 13:16:42 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
2016-11-24 16:29:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Dashboard
|