2016-11-21 12:24:50 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-11-23 14:51:19 +00:00
|
|
|
const m = require('mithril');
|
2016-11-22 21:33:50 +00:00
|
|
|
import Login from './components/login.js';
|
2016-11-23 14:51:19 +00:00
|
|
|
import Pageviews from './components/pageviews.js';
|
|
|
|
import RealtimeVisits from './components/realtime.js';
|
|
|
|
import VisitsGraph from './components/visits-graph.js';
|
2016-11-23 15:29:07 +00:00
|
|
|
import LogoutButton from './components/logoutButton.js';
|
2016-11-22 21:33:50 +00:00
|
|
|
|
2016-11-23 14:51:19 +00:00
|
|
|
const App = {
|
|
|
|
controller(args) {
|
|
|
|
this.state = {
|
2016-11-23 15:33:52 +00:00
|
|
|
authenticated: document.cookie.indexOf('auth') > -1
|
2016-11-23 14:51:19 +00:00
|
|
|
};
|
2016-11-22 21:33:50 +00:00
|
|
|
|
2016-11-23 14:51:19 +00:00
|
|
|
this.setState = function(nextState) {
|
|
|
|
m.startComputation();
|
|
|
|
for(var k in nextState) {
|
|
|
|
this.state[k] = nextState[k];
|
|
|
|
}
|
|
|
|
m.endComputation();
|
2016-11-22 21:33:50 +00:00
|
|
|
}
|
2016-11-23 14:51:19 +00:00
|
|
|
},
|
|
|
|
view(c) {
|
|
|
|
if( ! c.state.authenticated ) {
|
2016-11-23 15:33:52 +00:00
|
|
|
return m('div.container', [
|
|
|
|
m.component(Login, {
|
2016-11-23 15:29:07 +00:00
|
|
|
onAuth: () => {
|
|
|
|
c.setState({ authenticated: true })
|
|
|
|
}
|
2016-11-23 15:33:52 +00:00
|
|
|
})
|
|
|
|
]);
|
2016-11-23 14:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
m('div.container', [
|
2016-11-23 15:29:07 +00:00
|
|
|
m('div.header.cf', [
|
|
|
|
m('h1.pull-left', 'Ana'),
|
|
|
|
m('div.pull-right', [
|
|
|
|
m.component(LogoutButton, {
|
|
|
|
cb: () => {
|
|
|
|
c.setState({ authenticated: false })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]),
|
|
|
|
]),
|
2016-11-23 14:51:19 +00:00
|
|
|
m.component(RealtimeVisits),
|
|
|
|
m.component(VisitsGraph),
|
|
|
|
m.component(Pageviews),
|
|
|
|
])
|
|
|
|
]
|
2016-11-22 21:33:50 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-21 15:01:14 +00:00
|
|
|
|
2016-11-23 14:51:19 +00:00
|
|
|
|
|
|
|
m.mount(document.getElementById('root'), App)
|