2015-06-23 16:02:48 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import Router from 'react-router';
|
|
|
|
|
|
|
|
import UserActions from '../actions/user_actions';
|
|
|
|
import UserStore from '../stores/user_store';
|
|
|
|
|
|
|
|
import WalletSettingsActions from '../actions/wallet_settings_actions';
|
|
|
|
import WalletSettingsStore from '../stores/wallet_settings_store';
|
|
|
|
|
|
|
|
import ApplicationActions from '../actions/application_actions';
|
|
|
|
import ApplicationStore from '../stores/application_store';
|
|
|
|
|
|
|
|
import GlobalNotificationModel from '../models/global_notification_model';
|
|
|
|
import GlobalNotificationActions from '../actions/global_notification_actions';
|
|
|
|
|
2015-07-02 11:54:33 +02:00
|
|
|
import ReactS3FineUploader from './ascribe_uploader/react_s3_fine_uploader';
|
|
|
|
|
2015-06-23 16:02:48 +02:00
|
|
|
import CollapsibleParagraph from './ascribe_collapsible/collapsible_paragraph';
|
|
|
|
import Form from './ascribe_forms/form';
|
|
|
|
import Property from './ascribe_forms/property';
|
2015-07-27 14:39:19 +02:00
|
|
|
import InputCheckbox from './ascribe_forms/input_checkbox';
|
2015-06-23 16:02:48 +02:00
|
|
|
|
|
|
|
import apiUrls from '../constants/api_urls';
|
|
|
|
import AppConstants from '../constants/application_constants';
|
2015-07-01 18:58:13 +02:00
|
|
|
import { getLangText } from '../utils/lang_utils';
|
2015-06-23 16:02:48 +02:00
|
|
|
|
2015-07-02 11:54:33 +02:00
|
|
|
import { getCookie } from '../utils/fetch_api_utils';
|
2015-06-23 16:02:48 +02:00
|
|
|
|
|
|
|
let SettingsContainer = React.createClass({
|
|
|
|
mixins: [Router.Navigation],
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2015-07-15 13:20:34 +02:00
|
|
|
<div className="settings-container">
|
2015-06-23 16:02:48 +02:00
|
|
|
<AccountSettings />
|
|
|
|
<APISettings />
|
2015-07-02 11:54:33 +02:00
|
|
|
<BitcoinWalletSettings />
|
|
|
|
<LoanContractSettings />
|
|
|
|
<br />
|
|
|
|
<br />
|
2015-06-23 16:02:48 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let AccountSettings = React.createClass({
|
|
|
|
getInitialState() {
|
|
|
|
return UserStore.getState();
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
UserStore.listen(this.onChange);
|
|
|
|
UserActions.fetchCurrentUser();
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
UserStore.unlisten(this.onChange);
|
|
|
|
},
|
|
|
|
|
|
|
|
onChange(state) {
|
|
|
|
this.setState(state);
|
|
|
|
},
|
|
|
|
|
|
|
|
handleSuccess(){
|
|
|
|
UserActions.fetchCurrentUser();
|
2015-07-01 18:58:13 +02:00
|
|
|
let notification = new GlobalNotificationModel(getLangText('username succesfully updated'), 'success', 5000);
|
2015-06-23 16:02:48 +02:00
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
},
|
2015-07-27 14:39:19 +02:00
|
|
|
|
|
|
|
getFormDataProfile(){
|
|
|
|
return {'email': this.state.currentUser.email};
|
|
|
|
},
|
2015-06-23 16:02:48 +02:00
|
|
|
render() {
|
|
|
|
let content = <img src={AppConstants.baseUrl + 'static/img/ascribe_animated_medium.gif'} />;
|
2015-07-27 14:39:19 +02:00
|
|
|
let profile = null;
|
|
|
|
|
2015-06-23 16:02:48 +02:00
|
|
|
if (this.state.currentUser.username) {
|
|
|
|
content = (
|
|
|
|
<Form
|
|
|
|
url={apiUrls.users_username}
|
|
|
|
handleSuccess={this.handleSuccess}>
|
|
|
|
<Property
|
|
|
|
name='username'
|
2015-07-01 18:58:13 +02:00
|
|
|
label={getLangText('Username')}>
|
2015-06-23 16:02:48 +02:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
defaultValue={this.state.currentUser.username}
|
2015-07-01 18:58:13 +02:00
|
|
|
placeholder={getLangText('Enter your username')}
|
2015-06-23 16:02:48 +02:00
|
|
|
required/>
|
|
|
|
</Property>
|
|
|
|
<Property
|
|
|
|
name='email'
|
2015-07-01 18:58:13 +02:00
|
|
|
label={getLangText('Email')}
|
2015-06-23 16:02:48 +02:00
|
|
|
editable={false}>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
defaultValue={this.state.currentUser.email}
|
2015-07-01 18:58:13 +02:00
|
|
|
placeholder={getLangText('Enter your username')}
|
2015-06-23 16:02:48 +02:00
|
|
|
required/>
|
|
|
|
</Property>
|
|
|
|
<hr />
|
|
|
|
</Form>
|
|
|
|
);
|
2015-07-27 14:39:19 +02:00
|
|
|
profile = (
|
|
|
|
<Form
|
|
|
|
url={apiUrls.users_profile}
|
|
|
|
handleSuccess={this.handleSuccess}
|
|
|
|
getFormData={this.getFormDataProfile}>
|
|
|
|
<Property
|
|
|
|
name="hash_locally"
|
|
|
|
className="ascribe-settings-property-collapsible-toggle"
|
|
|
|
style={{paddingBottom: 0}}>
|
|
|
|
<InputCheckbox
|
|
|
|
defaultValue={true}
|
|
|
|
required={false}>
|
|
|
|
<span>
|
|
|
|
{' ' + getLangText('Enable hash option for slow connections. ' +
|
|
|
|
'Computes and uploads a hash of the work instead.')}
|
|
|
|
</span>
|
|
|
|
</InputCheckbox>
|
|
|
|
</Property>
|
|
|
|
{/*<Property
|
|
|
|
name='language'
|
|
|
|
label={getLangText('Choose your Language')}
|
|
|
|
editable={true}>
|
|
|
|
<select id="select-lang" name="language">
|
|
|
|
<option value="fr">
|
|
|
|
Français
|
|
|
|
</option>
|
|
|
|
<option value="en"
|
|
|
|
selected="selected">
|
|
|
|
English
|
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
</Property>*/}
|
|
|
|
<hr />
|
|
|
|
</Form>
|
|
|
|
);
|
2015-06-23 16:02:48 +02:00
|
|
|
}
|
|
|
|
return (
|
|
|
|
<CollapsibleParagraph
|
2015-07-01 18:58:13 +02:00
|
|
|
title={getLangText('Account')}
|
2015-06-23 16:02:48 +02:00
|
|
|
show={true}
|
|
|
|
defaultExpanded={true}>
|
|
|
|
{content}
|
2015-07-27 14:39:19 +02:00
|
|
|
{profile}
|
2015-07-15 14:52:14 +02:00
|
|
|
{/*<Form
|
2015-06-23 16:02:48 +02:00
|
|
|
url={AppConstants.serverUrl + 'api/users/set_language/'}>
|
|
|
|
<Property
|
|
|
|
name='language'
|
2015-07-01 18:58:13 +02:00
|
|
|
label={getLangText('Choose your Language')}
|
2015-06-23 16:02:48 +02:00
|
|
|
editable={true}>
|
|
|
|
<select id="select-lang" name="language">
|
|
|
|
<option value="fr">
|
|
|
|
Français
|
|
|
|
</option>
|
|
|
|
<option value="en"
|
|
|
|
selected="selected">
|
|
|
|
English
|
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
</Property>
|
|
|
|
<hr />
|
2015-07-15 14:52:14 +02:00
|
|
|
</Form>*/}
|
2015-06-23 16:02:48 +02:00
|
|
|
</CollapsibleParagraph>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let BitcoinWalletSettings = React.createClass({
|
|
|
|
|
2015-07-08 17:46:52 +02:00
|
|
|
propTypes: {
|
|
|
|
defaultExpanded: React.PropTypes.bool
|
|
|
|
},
|
|
|
|
|
2015-06-23 16:02:48 +02:00
|
|
|
getInitialState() {
|
|
|
|
return WalletSettingsStore.getState();
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
WalletSettingsStore.listen(this.onChange);
|
|
|
|
WalletSettingsActions.fetchWalletSettings();
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
WalletSettingsStore.unlisten(this.onChange);
|
|
|
|
},
|
|
|
|
|
|
|
|
onChange(state) {
|
|
|
|
this.setState(state);
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let content = <img src={AppConstants.baseUrl + 'static/img/ascribe_animated_medium.gif'} />;
|
|
|
|
if (this.state.walletSettings.btc_public_key) {
|
|
|
|
content = (
|
|
|
|
<Form >
|
|
|
|
<Property
|
|
|
|
name='btc_public_key'
|
2015-07-01 18:58:13 +02:00
|
|
|
label={getLangText('Bitcoin public key')}
|
2015-06-23 16:02:48 +02:00
|
|
|
editable={false}>
|
|
|
|
<pre className="ascribe-pre">{this.state.walletSettings.btc_public_key}</pre>
|
|
|
|
</Property>
|
|
|
|
<Property
|
|
|
|
name='btc_root_address'
|
2015-07-01 18:58:13 +02:00
|
|
|
label={getLangText('Root Address')}
|
2015-06-23 16:02:48 +02:00
|
|
|
editable={false}>
|
|
|
|
<pre className="ascribe-pre">{this.state.walletSettings.btc_root_address}</pre>
|
|
|
|
</Property>
|
|
|
|
<hr />
|
|
|
|
</Form>);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<CollapsibleParagraph
|
2015-07-01 18:58:13 +02:00
|
|
|
title={getLangText('Crypto Wallet')}
|
2015-06-23 16:02:48 +02:00
|
|
|
show={true}
|
2015-07-08 17:46:52 +02:00
|
|
|
defaultExpanded={this.props.defaultExpanded}>
|
2015-06-23 16:02:48 +02:00
|
|
|
{content}
|
|
|
|
</CollapsibleParagraph>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-02 11:54:33 +02:00
|
|
|
let LoanContractSettings = React.createClass({
|
2015-07-08 17:46:52 +02:00
|
|
|
propTypes: {
|
|
|
|
defaultExpanded: React.PropTypes.bool
|
|
|
|
},
|
2015-07-02 11:54:33 +02:00
|
|
|
|
|
|
|
render() {
|
2015-06-23 16:02:48 +02:00
|
|
|
|
2015-07-02 11:54:33 +02:00
|
|
|
return (
|
|
|
|
<CollapsibleParagraph
|
|
|
|
title="Loan Contract Settings"
|
|
|
|
show={true}
|
2015-07-08 17:46:52 +02:00
|
|
|
defaultExpanded={this.props.defaultExpanded}>
|
2015-07-02 11:54:33 +02:00
|
|
|
<FileUploader />
|
|
|
|
</CollapsibleParagraph>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let FileUploader = React.createClass({
|
2015-06-23 16:02:48 +02:00
|
|
|
propTypes: {
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2015-07-02 11:54:33 +02:00
|
|
|
<Form>
|
|
|
|
<Property
|
|
|
|
label="Contract file">
|
|
|
|
<ReactS3FineUploader
|
|
|
|
keyRoutine={{
|
|
|
|
url: AppConstants.serverUrl + 's3/key/',
|
|
|
|
fileClass: 'contract'
|
|
|
|
}}
|
|
|
|
createBlobRoutine={{
|
|
|
|
url: apiUrls.ownership_loans_contract
|
|
|
|
}}
|
|
|
|
validation={{
|
|
|
|
itemLimit: 100000,
|
|
|
|
sizeLimit: '10000000'
|
|
|
|
}}
|
|
|
|
session={{
|
|
|
|
endpoint: apiUrls.ownership_loans_contract,
|
|
|
|
customHeaders: {
|
2015-07-16 18:17:45 +02:00
|
|
|
'X-CSRFToken': getCookie(AppConstants.csrftoken)
|
2015-07-02 11:54:33 +02:00
|
|
|
},
|
|
|
|
cors: {
|
|
|
|
expected: true,
|
|
|
|
sendCredentials: true
|
|
|
|
}
|
|
|
|
}}
|
2015-07-02 17:57:33 +02:00
|
|
|
signature={{
|
|
|
|
endpoint: AppConstants.serverUrl + 's3/signature/',
|
|
|
|
customHeaders: {
|
2015-07-16 18:17:45 +02:00
|
|
|
'X-CSRFToken': getCookie(AppConstants.csrftoken)
|
2015-07-02 17:57:33 +02:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
deleteFile={{
|
|
|
|
enabled: true,
|
|
|
|
method: 'DELETE',
|
|
|
|
endpoint: AppConstants.serverUrl + 's3/delete',
|
|
|
|
customHeaders: {
|
2015-07-16 18:17:45 +02:00
|
|
|
'X-CSRFToken': getCookie(AppConstants.csrftoken)
|
2015-07-02 17:57:33 +02:00
|
|
|
}
|
|
|
|
}}
|
2015-07-02 11:54:33 +02:00
|
|
|
areAssetsDownloadable={true}
|
|
|
|
areAssetsEditable={true}/>
|
|
|
|
</Property>
|
|
|
|
<hr />
|
|
|
|
</Form>
|
2015-06-23 16:02:48 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let APISettings = React.createClass({
|
2015-07-08 17:46:52 +02:00
|
|
|
propTypes: {
|
|
|
|
defaultExpanded: React.PropTypes.bool
|
|
|
|
},
|
|
|
|
|
2015-06-23 16:02:48 +02:00
|
|
|
getInitialState() {
|
|
|
|
return ApplicationStore.getState();
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
ApplicationStore.listen(this.onChange);
|
|
|
|
ApplicationActions.fetchApplication();
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
ApplicationStore.unlisten(this.onChange);
|
|
|
|
},
|
|
|
|
|
|
|
|
onChange(state) {
|
|
|
|
this.setState(state);
|
|
|
|
},
|
|
|
|
handleCreateSuccess: function(){
|
|
|
|
ApplicationActions.fetchApplication();
|
2015-07-01 18:58:13 +02:00
|
|
|
let notification = new GlobalNotificationModel(getLangText('Application successfully created'), 'success', 5000);
|
2015-06-23 16:02:48 +02:00
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
},
|
|
|
|
|
|
|
|
handleTokenRefresh: function(event){
|
|
|
|
let applicationName = event.target.getAttribute('data-id');
|
|
|
|
ApplicationActions.refreshApplicationToken(applicationName);
|
2015-07-01 18:58:13 +02:00
|
|
|
let notification = new GlobalNotificationModel(getLangText('Token refreshed'), 'success', 2000);
|
2015-06-23 16:02:48 +02:00
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
},
|
|
|
|
render() {
|
|
|
|
let content = <img src={AppConstants.baseUrl + 'static/img/ascribe_animated_medium.gif'} />;
|
|
|
|
if (this.state.applications.length > -1) {
|
|
|
|
content = this.state.applications.map(function(app) {
|
|
|
|
return (
|
|
|
|
<Property
|
|
|
|
name={app.name}
|
|
|
|
label={app.name}>
|
|
|
|
<div className="row-same-height">
|
2015-07-15 13:20:34 +02:00
|
|
|
<div className="no-padding col-xs-6 col-sm-10 col-xs-height col-middle">
|
2015-06-23 16:02:48 +02:00
|
|
|
{'Bearer ' + app.bearer_token.token}
|
|
|
|
</div>
|
2015-07-15 13:20:34 +02:00
|
|
|
<div className="col-xs-6 col-sm-2 col-xs-height">
|
2015-06-23 16:02:48 +02:00
|
|
|
<button
|
|
|
|
className="pull-right btn btn-default btn-sm"
|
|
|
|
onClick={this.handleTokenRefresh}
|
|
|
|
data-id={app.name}>
|
2015-07-01 18:58:13 +02:00
|
|
|
{getLangText('REFRESH')}
|
2015-06-23 16:02:48 +02:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Property>);
|
|
|
|
}, this);
|
|
|
|
content = (
|
|
|
|
<div>
|
|
|
|
<Form>
|
|
|
|
{content}
|
|
|
|
<hr />
|
|
|
|
</Form>
|
|
|
|
</div>);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<CollapsibleParagraph
|
2015-07-01 18:58:13 +02:00
|
|
|
title={getLangText('API Integration')}
|
2015-06-23 16:02:48 +02:00
|
|
|
show={true}
|
2015-07-08 17:46:52 +02:00
|
|
|
defaultExpanded={this.props.defaultExpanded}>
|
2015-06-23 16:02:48 +02:00
|
|
|
<Form
|
|
|
|
url={apiUrls.applications}
|
|
|
|
handleSuccess={this.handleCreateSuccess}>
|
|
|
|
<Property
|
|
|
|
name='name'
|
2015-07-01 18:58:13 +02:00
|
|
|
label={getLangText('Application Name')}>
|
2015-06-23 16:02:48 +02:00
|
|
|
<input
|
|
|
|
type="text"
|
2015-07-01 18:58:13 +02:00
|
|
|
placeholder={getLangText('Enter the name of your app')}
|
2015-06-23 16:02:48 +02:00
|
|
|
required/>
|
|
|
|
</Property>
|
|
|
|
<hr />
|
|
|
|
</Form>
|
|
|
|
<pre>
|
|
|
|
Usage: curl <url> -H 'Authorization: Bearer <token>'
|
|
|
|
</pre>
|
|
|
|
{content}
|
|
|
|
</CollapsibleParagraph>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-15 14:52:14 +02:00
|
|
|
export default SettingsContainer;
|