2016-10-17 10:39:11 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
2016-12-22 08:21:19 +13:00
|
|
|
import { hashHistory, Link } from 'react-router'
|
2016-10-17 10:39:11 +13:00
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
|
import FontAwesome from 'react-fontawesome'
|
2016-11-29 15:36:01 +13:00
|
|
|
|
2016-10-17 10:39:11 +13:00
|
|
|
import SpotifyAuthenticationFrame from '../components/SpotifyAuthenticationFrame'
|
|
|
|
|
import ConfirmationButton from '../components/ConfirmationButton'
|
2016-10-28 09:14:29 +13:00
|
|
|
import PusherConnectionList from '../components/PusherConnectionList'
|
2016-11-08 13:36:13 +13:00
|
|
|
import URISchemesList from '../components/URISchemesList'
|
2016-10-29 22:40:02 +13:00
|
|
|
import VersionManager from '../components/VersionManager'
|
2016-10-23 23:48:06 +13:00
|
|
|
import Header from '../components/Header'
|
2017-02-21 08:35:24 +13:00
|
|
|
import Icon from '../components/Icon'
|
2016-11-29 15:36:01 +13:00
|
|
|
import Thumbnail from '../components/Thumbnail'
|
2016-10-17 10:39:11 +13:00
|
|
|
|
2016-12-12 09:07:47 +13:00
|
|
|
import * as uiActions from '../services/ui/actions'
|
2016-10-28 09:14:29 +13:00
|
|
|
import * as pusherActions from '../services/pusher/actions'
|
2016-10-17 10:39:11 +13:00
|
|
|
import * as mopidyActions from '../services/mopidy/actions'
|
|
|
|
|
import * as spotifyActions from '../services/spotify/actions'
|
|
|
|
|
|
|
|
|
|
class Settings extends React.Component{
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
2016-10-18 08:56:53 +13:00
|
|
|
this.state = {
|
|
|
|
|
mopidy_host: this.props.mopidy.host,
|
2016-10-18 21:57:29 +13:00
|
|
|
mopidy_port: this.props.mopidy.port,
|
2016-10-28 10:48:55 +13:00
|
|
|
pusher_username: this.props.pusher.username,
|
2016-10-18 21:57:29 +13:00
|
|
|
spotify_country: this.props.spotify.country,
|
|
|
|
|
spotify_locale: this.props.spotify.locale
|
2016-10-18 08:56:53 +13:00
|
|
|
};
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resetAllSettings(){
|
2016-10-17 14:27:48 +13:00
|
|
|
localStorage.clear();
|
2017-02-06 10:07:32 +13:00
|
|
|
window.location = '#'
|
|
|
|
|
window.location.reload(true)
|
2016-10-28 15:58:07 +13:00
|
|
|
return false;
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
2016-10-28 15:58:07 +13:00
|
|
|
setMopidyConfig(e){
|
|
|
|
|
e.preventDefault();
|
2016-10-18 21:57:29 +13:00
|
|
|
this.props.mopidyActions.setConfig({ host: this.state.mopidy_host, port: this.state.mopidy_port });
|
2016-10-18 08:56:53 +13:00
|
|
|
window.location.reload(true);
|
2016-10-28 15:58:07 +13:00
|
|
|
return false;
|
2016-10-18 08:56:53 +13:00
|
|
|
}
|
|
|
|
|
|
2016-10-28 15:58:07 +13:00
|
|
|
setSpotifyConfig(e){
|
|
|
|
|
e.preventDefault();
|
2016-10-28 09:14:29 +13:00
|
|
|
this.props.spotifyActions.setConfig({ country: this.state.spotify_country, locale: this.state.spotify_locale });
|
2016-10-28 15:58:07 +13:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 21:36:31 +13:00
|
|
|
handleUsernameChange(username){
|
|
|
|
|
this.setState({pusher_username: username.replace(/\W/g, '')})
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-06 15:47:37 +13:00
|
|
|
renderConnectionStatus(service){
|
2017-02-21 08:35:24 +13:00
|
|
|
if (service == 'Spotify' && !this.props[service.toLowerCase()].authorized){
|
|
|
|
|
return (
|
|
|
|
|
<span className="red-text connection-status">
|
|
|
|
|
<FontAwesome name="exclamation-triangle" />
|
|
|
|
|
|
|
|
|
|
Not connected
|
|
|
|
|
</span>
|
|
|
|
|
)
|
|
|
|
|
} else if (this.props[service.toLowerCase()].connected){
|
2016-11-06 15:47:37 +13:00
|
|
|
return (
|
2017-02-21 05:46:28 +13:00
|
|
|
<span className="green-text connection-status">
|
2016-11-06 15:47:37 +13:00
|
|
|
<FontAwesome name="check" />
|
|
|
|
|
|
2017-02-21 05:46:28 +13:00
|
|
|
{service}
|
2016-11-06 15:47:37 +13:00
|
|
|
</span>
|
|
|
|
|
)
|
2017-02-21 08:35:24 +13:00
|
|
|
} else if (this.props[service.toLowerCase()].connecting){
|
2016-11-06 15:47:37 +13:00
|
|
|
return (
|
2017-02-21 05:46:28 +13:00
|
|
|
<span className="grey-text connection-status">
|
2016-11-06 15:47:37 +13:00
|
|
|
<FontAwesome name="circle-o-notch" spin />
|
|
|
|
|
|
2017-02-21 08:35:24 +13:00
|
|
|
Connecting
|
2016-11-06 15:47:37 +13:00
|
|
|
</span>
|
|
|
|
|
)
|
2017-02-21 08:35:24 +13:00
|
|
|
} else {
|
2016-11-06 15:47:37 +13:00
|
|
|
return (
|
2017-02-21 05:46:28 +13:00
|
|
|
<span className="red-text connection-status">
|
2016-11-06 15:47:37 +13:00
|
|
|
<FontAwesome name="exclamation-triangle" />
|
|
|
|
|
|
2017-02-21 08:35:24 +13:00
|
|
|
Not connected
|
2016-11-06 15:47:37 +13:00
|
|
|
</span>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-29 15:36:01 +13:00
|
|
|
renderSpotifyUser(){
|
2017-02-06 17:02:43 +13:00
|
|
|
|
|
|
|
|
var user = null
|
2017-02-06 13:00:21 +13:00
|
|
|
if (this.props.spotify.me && this.props.spotify.authorized){
|
2017-02-06 17:02:43 +13:00
|
|
|
user = this.props.spotify.me
|
|
|
|
|
} else if (this.props.ui.config && this.props.ui.config.spotify_username){
|
|
|
|
|
if (this.props.ui.users && typeof(this.props.ui.users['spotify:user:'+this.props.ui.config.spotify_username]) !== 'undefined'){
|
|
|
|
|
user = this.props.ui.users['spotify:user:'+this.props.ui.config.spotify_username]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (user){
|
2016-11-29 15:36:01 +13:00
|
|
|
return (
|
2017-02-06 17:02:43 +13:00
|
|
|
<Link className="user" to={global.baseURL+'user/'+user.uri}>
|
|
|
|
|
<Thumbnail circle={true} size="small" images={user.images} />
|
2017-02-06 13:00:21 +13:00
|
|
|
<span className="user-name">
|
2017-02-21 19:36:17 +13:00
|
|
|
{user.display_name ? user.display_name : user.id}
|
2017-02-07 10:00:29 +13:00
|
|
|
{!this.props.spotify.authorized ? <span className="grey-text"> (limited access)</span> : null}
|
2017-02-06 13:00:21 +13:00
|
|
|
</span>
|
|
|
|
|
</Link>
|
|
|
|
|
)
|
|
|
|
|
} else {
|
2016-11-29 15:36:01 +13:00
|
|
|
return (
|
|
|
|
|
<Link className="user">
|
|
|
|
|
<Thumbnail circle={true} size="small" />
|
|
|
|
|
<span className="user-name">
|
2017-02-06 17:02:43 +13:00
|
|
|
Default user
|
2017-02-07 10:00:29 +13:00
|
|
|
<span className="grey-text"> (limited access)</span>
|
2016-11-29 15:36:01 +13:00
|
|
|
</span>
|
|
|
|
|
</Link>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-12 09:07:47 +13:00
|
|
|
renderSendAuthorizationButton(){
|
|
|
|
|
if( !this.props.spotify.authorized ) return null
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<button onClick={e => this.props.uiActions.openModal('send_authorization', {}) }>
|
|
|
|
|
Share authentication
|
|
|
|
|
</button>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-21 05:46:28 +13:00
|
|
|
renderApplyButton(){
|
|
|
|
|
if (this.props.mopidy.host == this.state.mopidy_host && this.props.mopidy.port == this.state.mopidy_port) return null
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="field">
|
|
|
|
|
<div className="name"></div>
|
|
|
|
|
<div className="input">
|
|
|
|
|
<button type="submit" className="secondary">Apply and reload</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-21 08:35:24 +13:00
|
|
|
serviceStatus(service){
|
|
|
|
|
if (this.props[service].connecting){
|
|
|
|
|
return <span className="grey-text">Connecting</span>
|
|
|
|
|
} else if (service == 'spotify' && !this.props[service].authorized){
|
|
|
|
|
return <span className="orange-text">Not authorized</span>
|
|
|
|
|
} else if (this.props[service].connected){
|
|
|
|
|
return <span className="green-text">Connected</span>
|
|
|
|
|
} else {
|
|
|
|
|
return <span className="red-text">Disconnected</span>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-17 10:39:11 +13:00
|
|
|
render(){
|
2017-02-07 10:00:29 +13:00
|
|
|
|
2017-03-06 09:03:20 +13:00
|
|
|
var options = (
|
2017-03-08 09:13:24 +13:00
|
|
|
<span>
|
|
|
|
|
<button onClick={e => hashHistory.push(global.baseURL+'debug')}>
|
|
|
|
|
<FontAwesome name="flask" />
|
|
|
|
|
Debug
|
|
|
|
|
</button>
|
2017-03-22 07:56:45 +13:00
|
|
|
<a className="button" href="https://github.com/jaedb/Iris/wiki" target="_blank">
|
|
|
|
|
<FontAwesome name="question" />
|
|
|
|
|
Help
|
|
|
|
|
</a>
|
2017-03-08 09:13:24 +13:00
|
|
|
</span>
|
2017-02-07 10:00:29 +13:00
|
|
|
)
|
|
|
|
|
|
2016-10-17 10:39:11 +13:00
|
|
|
return (
|
2016-10-26 16:55:47 +13:00
|
|
|
<div className="view settings-view">
|
2017-03-06 09:03:20 +13:00
|
|
|
<Header icon="cog" title="Settings" options={options} uiActions={this.props.uiActions} />
|
2016-10-18 21:57:29 +13:00
|
|
|
|
2016-10-25 14:09:53 +13:00
|
|
|
<section>
|
|
|
|
|
|
2017-02-21 08:35:24 +13:00
|
|
|
<div className="status">
|
|
|
|
|
|
|
|
|
|
<div className="item">
|
|
|
|
|
<Icon name="server" />
|
|
|
|
|
<h4>Mopidy</h4>
|
|
|
|
|
{this.serviceStatus('mopidy')}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="item">
|
|
|
|
|
<Icon name="connection" />
|
|
|
|
|
<h4>Pusher</h4>
|
|
|
|
|
{this.serviceStatus('pusher')}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="item">
|
|
|
|
|
<Icon name="spotify" />
|
|
|
|
|
<h4>Spotify</h4>
|
|
|
|
|
{this.serviceStatus('spotify')}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
2017-02-21 05:46:28 +13:00
|
|
|
<h4 className="underline">System</h4>
|
2016-10-28 15:58:07 +13:00
|
|
|
<form onSubmit={(e) => this.setMopidyConfig(e)}>
|
2017-02-17 08:03:11 +13:00
|
|
|
<div className="field">
|
|
|
|
|
<div className="name">Username</div>
|
|
|
|
|
<div className="input">
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
2017-02-17 21:36:31 +13:00
|
|
|
onChange={e => this.handleUsernameChange(e.target.value)}
|
2017-02-17 08:03:11 +13:00
|
|
|
onBlur={ e => this.props.pusherActions.setUsername(this.state.pusher_username) }
|
|
|
|
|
value={ this.state.pusher_username } />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2016-11-14 11:20:02 +13:00
|
|
|
<div className="field">
|
|
|
|
|
<div className="name">Host</div>
|
2016-10-28 09:14:29 +13:00
|
|
|
<div className="input">
|
2016-11-06 15:47:37 +13:00
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
onChange={ e => this.setState({ mopidy_host: e.target.value })}
|
|
|
|
|
value={ this.state.mopidy_host } />
|
2016-10-28 09:14:29 +13:00
|
|
|
</div>
|
2016-11-14 11:20:02 +13:00
|
|
|
</div>
|
|
|
|
|
<div className="field">
|
|
|
|
|
<div className="name">Port</div>
|
2016-10-28 09:14:29 +13:00
|
|
|
<div className="input">
|
2016-11-06 15:47:37 +13:00
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
onChange={ e => this.setState({ mopidy_port: e.target.value })}
|
|
|
|
|
value={ this.state.mopidy_port } />
|
2016-10-28 09:14:29 +13:00
|
|
|
</div>
|
2016-11-14 11:20:02 +13:00
|
|
|
</div>
|
2017-02-21 05:46:28 +13:00
|
|
|
{this.renderApplyButton()}
|
2016-10-27 16:58:11 +13:00
|
|
|
</form>
|
|
|
|
|
|
2016-10-31 16:49:42 +13:00
|
|
|
<h4 className="underline">Spotify</h4>
|
2016-12-12 09:07:47 +13:00
|
|
|
<form>
|
2016-11-14 11:20:02 +13:00
|
|
|
<div className="field">
|
|
|
|
|
<div className="name">Country</div>
|
2016-10-28 09:14:29 +13:00
|
|
|
<div className="input">
|
2016-11-06 15:47:37 +13:00
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
onChange={ e => this.setState({ spotify_country: e.target.value })}
|
|
|
|
|
onBlur={ e => this.setSpotifyConfig(e) }
|
|
|
|
|
value={ this.state.spotify_country } />
|
2016-10-28 09:14:29 +13:00
|
|
|
</div>
|
2016-11-14 11:20:02 +13:00
|
|
|
</div>
|
|
|
|
|
<div className="field">
|
|
|
|
|
<div className="name">Locale</div>
|
2016-10-28 09:14:29 +13:00
|
|
|
<div className="input">
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
onChange={ e => this.setState({ spotify_locale: e.target.value })}
|
2016-10-31 09:25:15 +13:00
|
|
|
onBlur={ e => this.setSpotifyConfig(e) }
|
2016-10-28 09:14:29 +13:00
|
|
|
value={ this.state.spotify_locale } />
|
|
|
|
|
</div>
|
2016-11-14 11:20:02 +13:00
|
|
|
</div>
|
2016-12-12 09:07:47 +13:00
|
|
|
</form>
|
|
|
|
|
<div className="field current-user">
|
|
|
|
|
<div className="name">Current user</div>
|
|
|
|
|
<div className="input">
|
|
|
|
|
<div className="text">
|
|
|
|
|
{ this.renderSpotifyUser() }
|
2016-11-29 15:36:01 +13:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2016-12-12 09:07:47 +13:00
|
|
|
</div>
|
|
|
|
|
<div className="field">
|
|
|
|
|
<div className="name">Authentication</div>
|
|
|
|
|
<div className="input">
|
|
|
|
|
<SpotifyAuthenticationFrame />
|
|
|
|
|
{ this.renderSendAuthorizationButton() }
|
2016-11-25 22:49:34 +13:00
|
|
|
</div>
|
2016-12-12 09:07:47 +13:00
|
|
|
</div>
|
2016-10-25 14:09:53 +13:00
|
|
|
|
2016-10-31 16:49:42 +13:00
|
|
|
<h4 className="underline">Advanced</h4>
|
2016-11-08 13:36:13 +13:00
|
|
|
|
2016-11-29 15:36:01 +13:00
|
|
|
<div className="field pusher-connections">
|
2016-11-14 11:20:02 +13:00
|
|
|
<div className="name">Connections</div>
|
2016-11-08 13:36:13 +13:00
|
|
|
<div className="input">
|
|
|
|
|
<span className="text">
|
|
|
|
|
<PusherConnectionList />
|
|
|
|
|
</span>
|
2016-10-29 22:40:02 +13:00
|
|
|
</div>
|
2016-11-14 11:20:02 +13:00
|
|
|
</div>
|
2016-11-08 13:36:13 +13:00
|
|
|
|
2016-11-14 11:20:02 +13:00
|
|
|
<div className="field">
|
|
|
|
|
<div className="name">Backends</div>
|
2016-11-08 13:36:13 +13:00
|
|
|
<div className="input">
|
|
|
|
|
<span className="text">
|
|
|
|
|
<URISchemesList />
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2016-11-14 11:20:02 +13:00
|
|
|
</div>
|
2016-11-08 13:36:13 +13:00
|
|
|
|
2016-11-14 11:20:02 +13:00
|
|
|
<div className="field">
|
2017-02-07 10:00:29 +13:00
|
|
|
<div className="name">System</div>
|
2016-12-05 10:20:01 +13:00
|
|
|
<div className="input">
|
|
|
|
|
<ConfirmationButton className="destructive" content="Reset all settings" confirmingContent="Are you sure?" onConfirm={() => this.resetAllSettings()} />
|
2017-02-07 10:00:29 +13:00
|
|
|
<VersionManager />
|
|
|
|
|
</div>
|
2016-12-05 10:20:01 +13:00
|
|
|
</div>
|
2016-10-29 22:40:02 +13:00
|
|
|
|
2017-01-04 16:14:10 +13:00
|
|
|
<h4 className="underline">About</h4>
|
|
|
|
|
|
|
|
|
|
<div className="field">
|
|
|
|
|
<div>
|
|
|
|
|
<em><a href="https://github.com/jaedb/Iris" target="_blank">Iris</a></em> is an open-source project by <a href="https://github.com/jaedb" target="_blank">James Barnsley</a>. It is provided free and with absolutely no warranty. If you paid someone for this software, please let me know.
|
|
|
|
|
<br />
|
|
|
|
|
<br />
|
|
|
|
|
Google Analytics is used to help trace issues and provide valuable insight into how we can continue to make improvements.
|
|
|
|
|
<br />
|
|
|
|
|
</div>
|
|
|
|
|
<br /><br />
|
|
|
|
|
<div>
|
|
|
|
|
<a className="button" href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=james%40barnsley%2enz&lc=NZ&item_name=James%20Barnsley¤cy_code=NZD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted" target="_blank">
|
|
|
|
|
<FontAwesome name="paypal" /> Donate
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
|
|
<a className="button" href="https://github.com/jaedb/Iris" target="_blank">
|
|
|
|
|
<FontAwesome name="github" /> GitHub
|
|
|
|
|
</a>
|
|
|
|
|
|
2017-01-04 17:30:18 +13:00
|
|
|
<a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/" target="_blank" style={{display: 'inline-block', verticalAlign: 'middle'}}><img alt="Creative Commons License" src="https://i.creativecommons.org/l/by-nc/4.0/88x31.png" /></a>
|
2017-01-04 16:14:10 +13:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2016-10-25 14:09:53 +13:00
|
|
|
</section>
|
2017-01-04 16:14:10 +13:00
|
|
|
|
2016-10-17 10:39:11 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
2016-12-12 09:07:47 +13:00
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
2016-10-28 09:14:29 +13:00
|
|
|
pusherActions: bindActionCreators(pusherActions, dispatch),
|
2016-10-17 10:39:11 +13:00
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Settings)
|