Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add AdminPanel #24

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f7f9d6d
Merge pull request #6 from czana/OAB-1_display_cooldown_time_left
czana Jul 10, 2018
676fd3b
Merge branch 'master' of github.com:czana/oab
czana Jul 11, 2018
36bdb1a
user added
czana Jul 11, 2018
7d5a8c9
user added
czana Jul 11, 2018
e922493
add more users
czana Jul 12, 2018
e5c3a81
add user
czana Jul 12, 2018
078b81c
add user
czana Jul 16, 2018
4c99ab5
change webhook
czana Jul 17, 2018
1673392
add user
polakowski Jul 18, 2018
66271d3
migration module
czana Jul 19, 2018
a94bab0
Merge branch 'master' of github.com:czana/oab
czana Jul 19, 2018
57313cf
Update README.md
qbart Jul 19, 2018
b255a80
add user
polakowski Jul 23, 2018
1171d78
more users
czana Jul 24, 2018
2b66795
Merge branch 'master' of github.com:czana/oab
czana Jul 24, 2018
73f1ed1
fix animation
czana Jul 24, 2018
51a9641
Chore: Update dependencies, use .babelrc as preset manager.
Jul 11, 2018
ce7233d
Chore: Rename `.jsx` to `.js` :fire:
Jul 11, 2018
ad8c451
Chore: Prepare webpack configs for development and production.
Jul 11, 2018
877de36
Chore: Optimize lodash to minimize build.
Jul 11, 2018
584786a
Chore: Revert commented code from development
Jul 11, 2018
d4b48a1
Update components
Jul 25, 2018
f8eb4bd
user added
czana Sep 4, 2018
744e9e9
add r.pszczolka i v.kokoshko
czana Nov 19, 2018
1d0363e
users update
czana Jul 8, 2019
b814c6a
add .env to gitignore
czana Jul 8, 2019
0d299a0
fix overriding user bug
czana Jul 8, 2019
9cfef55
Merge branch 'master' of github.com:czana/oab
czana Jul 8, 2019
7c443e9
yarn.lock
czana Jul 8, 2019
f8eb7ff
add AdminPanel
dawidholisz Jul 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"env", "stage-0", "react"
]
}
2 changes: 0 additions & 2 deletions .env

This file was deleted.

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ images/*

.DS_Store

bundle.js

.env

.idea/
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ Alias=kiosk.service
WantedBy=multi-user.target
```

### /lib/systemd/system/kiosk-uploader.service

```conf
[Unit]
Description=Kiosk Uploader
After=systemd-user-sessions.service
Requires=redis.service

[Service]
WorkingDirectory=/home/pi/services/
ExecStart=/home/pi/services/uploader --watch-dir /home/pi/services/data --log-file /home/pi/services/logs/uploader.log
IgnoreSIGPIPE=false
Type=simple

[Install]
Alias=kiosk-uploader.service
WantedBy=multi-user.target
```

Enable & start services:

```bash
Expand Down
22 changes: 13 additions & 9 deletions client/components/Animation.jsx → client/components/Animation.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
import React from 'react'
import random from 'lodash/random'

export default class Animation extends React.Component {

_setAnimation(position) {
const rollerElement = document.querySelector(`.roller.${position}`)
rollerElement.classList.remove('animate')
setTimeout(() => rollerElement.classList.add('animate'))
rollerElement.offsetWidth // reflow hack
rollerElement.classList.add('animate')
}

render() {
const { position, animationTime, rotations, angle, offset, startingIndex } = this.props
const { position, rotations, angle, startingIndex } = this.props

const startingRotationInDegree = startingIndex * angle
const rotationInDegree = startingRotationInDegree + (rotations * angle)
const rotationInDegree = startingRotationInDegree + rotations * angle
const animationTime = random(3, 6, true)
const offset = random(1, 7)

const animation = `roller-${position} ${animationTime}s ease forwards`

this._setAnimation(position)

return (
<style>
{`.roller.animate.${position}{ animation: ${animation}; }` +
`@keyframes roller-${position} {` +
`0% { transform: rotateX(${startingRotationInDegree}deg); }` +
`90% { transform: rotateX(${rotationInDegree + offset}deg); }` +
`100% { transform: rotateX(${rotationInDegree}deg); }`}
{`@keyframes roller-${position} {` +
`0% { transform: rotateX(${startingRotationInDegree}deg); } ` +
`90% { transform: rotateX(${rotationInDegree + offset}deg); } ` +
`100% { transform: rotateX(${rotationInDegree}deg); } }` +
`.roller.animate.${position}{ animation: ${animation}; }`}
</style>
)
}
Expand Down
36 changes: 21 additions & 15 deletions client/components/Game.jsx → client/components/Game.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import React from 'react'
import Roller from './Roller'
import socketIOClient from 'socket.io-client'
import { logResult, resultResponse } from '../modules/result'
import { ToastContainer, toast } from 'react-toastify'
import { resultResponse } from '../modules/result'
import { Link } from 'react-router-dom'

const ROLLERS = ['left', 'center', 'right']

export default class Game extends React.Component {
constructor(props) {
super(props)

this.state = {}
this.socket = socketIOClient('http://localhost:3000')
this.socket = props.socket

ROLLERS.forEach(roller => {
this[roller] = React.createRef()
Expand All @@ -20,11 +18,9 @@ export default class Game extends React.Component {

componentDidMount() {
this.socket.on('SPIN_REQUEST', forcedSpinTo => this._spinMachine(forcedSpinTo))
this.socket.on('NOTIFY', (type, message) => toast[type](message))

// toast.success("Success Notification!", {
// position: toast.POSITION.TOP_CENTER
// });
this.socket.on('ADMIN', () => {
props.history.push('/adminpanel')
})
}

_spinMachine(forcedSpinTo) {
Expand All @@ -33,7 +29,6 @@ export default class Game extends React.Component {
Promise.all(spins).then(results => {
const state = Object.values(results).reduce((a, v) => ({ ...a, ...v }), {})
this.setState(state)

this.socket.emit('SPIN_ENDED', resultResponse(state))
})
}
Expand All @@ -53,10 +48,21 @@ export default class Game extends React.Component {

render() {
return (
<div className="rollers">
<ToastContainer autoClose={5000} position={toast.POSITION.TOP_CENTER} />
<div className="overlay" />
{this._createRollers()}
<div id="game">
<div className="rollers">
<div className="overlay" />
{this._createRollers()}
<div
style={{
'z-index': '9999',
position: 'absolute',
background: 'rgba(255,12,34,0.5)',
padding: '12px'
}}
>
<Link to="/adminpanel">AdminPanel</Link>
</div>
</div>
</div>
)
}
Expand Down
17 changes: 9 additions & 8 deletions client/components/Roller.jsx → client/components/Roller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import ReactDOM from 'react-dom'
import Slot from './Slot'
import Animation from './Animation'
import Polygon, { getR } from '../modules/polygon'
import { times, random } from 'lodash'
import times from 'lodash/times'
import random from 'lodash/random'

export default class Roller extends React.Component {
constructor(props) {
Expand All @@ -16,26 +17,26 @@ export default class Roller extends React.Component {
spin(startingIndex = 0, forcedSpinTo) {
return new Promise(resolve => {
const { count, position } = this.props

let rotations = random(30, 50)
const animationTime = random(3, 6, true)

if (isFinite(forcedSpinTo)) {
rotations = 3 * count + forcedSpinTo - startingIndex
}

setTimeout(() => {
resolve({ [position]: (startingIndex + rotations) % count })
}, animationTime * 1000 + 500)
document.querySelector(`.roller.${position}`).addEventListener(
'animationend',
() => {
resolve({ [position]: (startingIndex + rotations) % count })
},
{ once: true }
)

ReactDOM.render(
<Animation
startingIndex={startingIndex}
position={position}
animationTime={animationTime}
rotations={rotations}
angle={this.polygon.angle}
offset={5}
/>,
document.querySelector(`.styles-roller-${position}`)
)
Expand Down
5 changes: 2 additions & 3 deletions client/components/Slot.jsx → client/components/Slot.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react'

class Slot extends React.Component {

_getStyles() {
const { polygon, number } = this.props
const { translateZ, translateY, rotateX } = polygon.valuesFor(number)
Expand All @@ -17,8 +16,8 @@ class Slot extends React.Component {

render() {
return (
<div style={this._getStyles()} className='slot'>
<img src={ this._getIcon() } />
<div style={this._getStyles()} className="slot">
<img src={this._getIcon()} />
</div>
)
}
Expand Down
13 changes: 13 additions & 0 deletions client/containers/AdminPanel/LastUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react'

const LastUser = ({user}) => {
return (
<div className="last-user">
<p>
Last user: {user}
</p>
</div>
)
}

export default LastUser
60 changes: 60 additions & 0 deletions client/containers/AdminPanel/Panel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, { Component } from 'react'
import { Link } from 'react-router-dom'
import LastUser from './LastUser'

class Panel extends Component {
constructor(props) {
super(props)
this.socket = props.socket
this.state = { lastUser: '' }
}

componentDidMount() {
this.socket.emit('GET_LAST_USER', user => {
console.log('user: ', user)
this.setState({ lastUser: user })
})
}

render() {
return (
<div id="panel">
<div className="sidebar">
<button
className="btn"
onClick={() => {
this.socket.emit('TEST', 'win')
}}
>
Test win
</button>
<button
className="btn"
onClick={() => {
this.socket.emit('TEST', 'win7')
}}
>
Test 7 win
</button>
<button
className="btn"
onClick={() => {
this.socket.emit('TEST', 'servo')
}}
>
Test servo
</button>
</div>
<Link to="/" className="btn btn-exit">
Exit
</Link>
<Link to="/adminPanel/stats" className="btn btn-stats">
Stats
</Link>
<LastUser user={this.state.lastUser} />
</div>
)
}
}

export default Panel
30 changes: 30 additions & 0 deletions client/containers/AdminPanel/Stats/UsersTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react'

const UsersTable = ({ users }) => {
return (
<div className="users-table">
<table>
<thead>
<tr>
<th>User</th>
<th>777</th>
<th>Win</th>
<th>Rolls</th>
</tr>
</thead>
<tbody>
{users.map(user => (
<tr key={user.id}>
<td>{user.userName}</td>
<td>{user.wins7}</td>
<td>{user.wins}</td>
<td>{user.rolls}</td>
</tr>
))}
</tbody>
</table>
</div>
)
}

export default UsersTable
65 changes: 65 additions & 0 deletions client/containers/AdminPanel/Stats/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React from 'react'
import { Link } from 'react-router-dom'
import UsersTable from './UsersTable'

const Stats = props => {
const users = [
{
id: 1,
userName: 'TC',
wins7: 0,
wins: 3,
rolls: 75
},
{
id: 2,
userName: 'TC',
wins7: 15,
wins: 75,
rolls: 7500
},
{
id: 3,
userName: 'TC',
wins7: 0,
wins: 0,
rolls: 13
},
{
id: 4,
userName: 'TC',
wins7: 1,
wins: 0,
rolls: 1
},
{
id: 5,
userName: 'TC',
wins7: 15,
wins: 122,
rolls: 5741
},
{
id: 6,
userName: 'TC',
wins7: 0,
wins: 0,
rolls: 124
}
]

const rollsCount = users.reduce((sum, { rolls }) => sum + rolls, 0)

return (
<div id="stats">
<h1 className="rolls-count">Rolls: {rollsCount}</h1>
<h1 className="users-header">Users:</h1>
<UsersTable users={users} />
<Link to="/adminpanel" className="btn btn-back">
Back
</Link>
</div>
)
}

export default Stats
Loading