2017-08-05 22:25:25 +12:00
import React , { PropTypes } from 'react'
import { connect } from 'react-redux'
import { Link , hashHistory } from 'react-router'
import { bindActionCreators } from 'redux'
import FontAwesome from 'react-fontawesome'
import SpotifyAuthenticationFrame from '../components/SpotifyAuthenticationFrame'
import ConfirmationButton from '../components/ConfirmationButton'
import PusherConnectionList from '../components/PusherConnectionList'
import URISchemesList from '../components/URISchemesList'
import VersionManager from '../components/VersionManager'
import Header from '../components/Header'
import Thumbnail from '../components/Thumbnail'
import * as uiActions from '../services/ui/actions'
import * as pusherActions from '../services/pusher/actions'
import * as mopidyActions from '../services/mopidy/actions'
import * as spotifyActions from '../services/spotify/actions'
class Debug extends React . Component {
constructor ( props ) {
super ( props ) ;
this . state = {
mopidy _call : 'playlists.asList' ,
mopidy _data : '{}' ,
pusher _data : '{"method":"get_config"}' ,
access _token : this . props . access _token
}
}
callMopidy ( e ) {
e . preventDefault ( )
this . props . mopidyActions . debug ( this . state . mopidy _call , JSON . parse ( this . state . mopidy _data ) )
}
callPusher ( e ) {
e . preventDefault ( )
this . props . pusherActions . debug ( JSON . parse ( this . state . pusher _data ) )
}
render ( ) {
var options = (
< span >
< button className = "no-hover" onClick = { e => hashHistory . push ( global . baseURL + 'settings' ) } >
< FontAwesome name = "reply" / > & nbsp ;
Back
< / b u t t o n >
< / s p a n >
)
return (
< div className = "view debugger-view" >
< Header icon = "cog" title = "Debugger" options = { options } uiActions = { this . props . uiActions } / >
< div className = "content-wrapper" >
< h4 className = "underline" > User interface < / h 4 >
< form >
< div className = "field checkbox" >
< div className = "name" > Debug < / d i v >
< div className = "input" >
< label >
< input
type = "checkbox"
name = "debug_info"
checked = { this . props . debug _info }
onChange = { e => this . props . uiActions . set ( { debug _info : ! this . props . debug _info } ) } / >
< span className = "label" > Show debug info panel < / s p a n >
< / l a b e l >
< / d i v >
< / d i v >
< div className = "field checkbox" >
< div className = "name" > Logging < / d i v >
< div className = "input" >
< label >
< input
type = "checkbox"
name = "log_actions"
checked = { this . props . log _actions }
onChange = { e => this . props . uiActions . set ( { log _actions : ! this . props . log _actions } ) } / >
< span className = "label" > Log actions < / s p a n >
< / l a b e l >
< label >
< input
type = "checkbox"
name = "log_mopidy"
checked = { this . props . log _mopidy }
onChange = { e => this . props . uiActions . set ( { log _mopidy : ! this . props . log _mopidy } ) } / >
< span className = "label" > Log Mopidy < / s p a n >
< / l a b e l >
< label >
< input
type = "checkbox"
name = "log_pusher"
checked = { this . props . log _pusher }
onChange = { e => this . props . uiActions . set ( { log _pusher : ! this . props . log _pusher } ) } / >
< span className = "label" > Log Pusher < / s p a n >
< / l a b e l >
< / d i v >
< / d i v >
< div className = "field" >
< div className = "name" > < / d i v >
< div className = "input" >
< a className = "button secondary" onClick = { e => this . props . uiActions . createNotification ( 'Test notification' ) } > Create notification < / a >
< a className = "button secondary" onClick = { e => this . props . uiActions . startProcess ( 'test_process' , 'Test process' ) } > Start process < / a >
2017-08-23 08:31:42 +12:00
< a className = "button secondary" onClick = { e => this . props . uiActions . processFinished ( 'test_process' ) } > Stop process < / a >
2017-08-05 22:25:25 +12:00
< / d i v >
< / d i v >
< / f o r m >
< h4 className = "underline" > Spotify < / h 4 >
< div className = "field" >
< div className = "name" > Access token < / d i v >
< div className = "input" >
< input
type = "text"
2017-08-06 20:22:16 +12:00
onChange = { e => this . props . spotifyActions . authorizationGranted ( { access _token : e . target . value } ) }
2017-08-05 22:25:25 +12:00
value = { this . state . access _token } / >
< / d i v >
< / d i v >
< h4 className = "underline" > Mopidy < / h 4 >
< form onSubmit = { ( e ) => this . callMopidy ( e ) } >
< div className = "field" >
< div className = "name" > Call < / d i v >
< div className = "input" >
< input
type = "text"
onChange = { e => this . setState ( { mopidy _call : e . target . value } ) }
value = { this . state . mopidy _call } / >
< / d i v >
< / d i v >
< div className = "field" >
< div className = "name" > Data < / d i v >
< div className = "input" >
< textarea
onChange = { e => this . setState ( { mopidy _data : e . target . value } ) }
value = { this . state . mopidy _data } >
< / t e x t a r e a >
< / d i v >
< / d i v >
< div className = "field" >
< div className = "name" > < / d i v >
< div className = "input" >
< button type = "submit" className = "secondary" > Send < / b u t t o n >
< / d i v >
< / d i v >
< / f o r m >
< h4 className = "underline" > Pusher < / h 4 >
< form onSubmit = { ( e ) => this . callPusher ( e ) } >
< div className = "field" >
< div className = "name" > Examples < / d i v >
< div className = "input" >
< select onChange = { e => this . setState ( { pusher _data : e . target . value } ) } >
< option value = '{"method":"get_config"}' > Get config < / o p t i o n >
< option value = '{"method":"get_version"}' > Get version < / o p t i o n >
< option value = '{"method":"get_connections"}' > Get connections < / o p t i o n >
< option value = '{"method":"get_radio"}' > Get radio < / o p t i o n >
< option value = '{"method":"get_queue_metadata"}' > Get queue metadata < / o p t i o n >
< option value = '{"method":"broadcast","data":{"type":"browser_notification","title":"Testing","body":"This is my message"}}' > Broadcast to all clients < / o p t i o n >
< option value = '{"method":"deliver_message","data":{"to":"CONNECTION_ID_HERE","message":{"type":"browser_notification","title":"Testing","body":"This is my message"}}}' > Broadcast to one client < / o p t i o n >
< option value = '{"method":"set_username","data":{"connection_id":"CONNECTION_ID_HERE","username":"NewUsername"}}' > Change username < / o p t i o n >
< option value = '{"method":"refresh_spotify_token"}' > Refresh Spotify token < / o p t i o n >
< option value = '{"method":"perform_upgrade"}' > Perform upgrade ( beta ) < / o p t i o n >
< / s e l e c t >
< / d i v >
< / d i v >
< div className = "field" >
< div className = "name" > Data < / d i v >
< div className = "input" >
< textarea
onChange = { e => this . setState ( { pusher _data : e . target . value } ) }
value = { this . state . pusher _data } >
< / t e x t a r e a >
< / d i v >
< / d i v >
< div className = "field" >
< div className = "name" > < / d i v >
< div className = "input" >
< button type = "submit" className = "secondary" > Send < / b u t t o n >
< / d i v >
< / d i v >
< / f o r m >
< h4 className = "underline" > Response < / h 4 >
< pre >
{ this . props . debug _response ? JSON . stringify ( this . props . debug _response , null , 2 ) : null }
< / p r e >
< / d i v >
< / d i v >
) ;
}
}
/ * *
* Export our component
*
* We also integrate our global store , using connect ( )
* * /
const mapStateToProps = ( state , ownProps ) => {
return {
connection _id : state . pusher . connection _id ,
access _token : ( state . spotify . access _token ? state . spotify . access _token : '' ) ,
log _actions : ( state . ui . log _actions ? state . ui . log _actions : false ) ,
log _pusher : ( state . ui . log _pusher ? state . ui . log _pusher : false ) ,
log _mopidy : ( state . ui . log _mopidy ? state . ui . log _mopidy : false ) ,
debug _info : ( state . ui . debug _info ? state . ui . debug _info : false ) ,
debug _response : state . ui . debug _response
}
}
const mapDispatchToProps = ( dispatch ) => {
return {
uiActions : bindActionCreators ( uiActions , dispatch ) ,
pusherActions : bindActionCreators ( pusherActions , dispatch ) ,
mopidyActions : bindActionCreators ( mopidyActions , dispatch ) ,
spotifyActions : bindActionCreators ( spotifyActions , dispatch )
}
}
export default connect ( mapStateToProps , mapDispatchToProps ) ( Debug )