2015-08-31 16:36:24 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import CollapsibleParagraph from '../ascribe_collapsible/collapsible_paragraph';
|
2015-09-01 14:42:09 +02:00
|
|
|
import CreateContractForm from '../ascribe_forms/form_create_contract';
|
2015-08-31 16:36:24 +02:00
|
|
|
|
2015-09-02 14:02:23 +02:00
|
|
|
import ContractListStore from '../../stores/contract_list_store';
|
|
|
|
import ContractListActions from '../../actions/contract_list_actions';
|
2015-08-31 16:36:24 +02:00
|
|
|
|
2015-09-03 15:53:02 +02:00
|
|
|
import ActionPanel from '../ascribe_panel/action_panel';
|
|
|
|
|
2015-09-02 14:02:23 +02:00
|
|
|
import { getLangText } from '../../utils/lang_utils';
|
2015-09-03 17:19:29 +02:00
|
|
|
import GlobalNotificationModel from '../../models/global_notification_model';
|
|
|
|
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
2015-08-31 16:36:24 +02:00
|
|
|
|
|
|
|
let ContractSettings = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
defaultExpanded: React.PropTypes.bool
|
|
|
|
},
|
2015-09-02 14:02:23 +02:00
|
|
|
getInitialState(){
|
|
|
|
return ContractListStore.getState();
|
|
|
|
},
|
|
|
|
componentDidMount() {
|
|
|
|
ContractListStore.listen(this.onChange);
|
|
|
|
ContractListActions.fetchContractList();
|
|
|
|
},
|
|
|
|
componentWillUnmount() {
|
|
|
|
ContractListStore.unlisten(this.onChange);
|
|
|
|
},
|
|
|
|
onChange(state) {
|
|
|
|
this.setState(state);
|
|
|
|
},
|
2015-09-03 15:53:02 +02:00
|
|
|
makeContractPublic(contract){
|
|
|
|
ContractListActions.makeContractPublic(contract)
|
|
|
|
.then(( ) => ContractListActions.fetchContractList())
|
2015-09-07 15:08:01 +02:00
|
|
|
.catch((error)=>{
|
2015-09-07 15:43:44 +02:00
|
|
|
let notification = new GlobalNotificationModel(error, 'danger', 10000);
|
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
2015-09-07 11:38:23 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
removeContract(contract){
|
|
|
|
console.log(contract);
|
2015-09-07 15:43:44 +02:00
|
|
|
ContractListActions.removeContract(contract.id)
|
2015-09-07 11:38:23 +02:00
|
|
|
.then(( ) => ContractListActions.fetchContractList())
|
2015-09-07 15:43:44 +02:00
|
|
|
.catch((error) => {
|
|
|
|
console.log('Error', error);
|
|
|
|
let notification = new GlobalNotificationModel(error, 'danger', 10000);
|
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
2015-09-07 11:38:23 +02:00
|
|
|
});
|
2015-09-03 15:53:02 +02:00
|
|
|
},
|
|
|
|
getPublicContracts(){
|
|
|
|
return this.state.contractList.filter((contract) => contract.public);
|
|
|
|
},
|
|
|
|
getPrivateContracts(){
|
|
|
|
return this.state.contractList.filter((contract) => !contract.public);
|
|
|
|
},
|
|
|
|
getblobEndName(contract){
|
|
|
|
return contract.blob.match(/.*\/(.*)/)[1];
|
|
|
|
},
|
2015-08-31 16:36:24 +02:00
|
|
|
render() {
|
2015-09-03 15:53:02 +02:00
|
|
|
let publicContracts = this.getPublicContracts();
|
|
|
|
let privateContracts = this.getPrivateContracts();
|
|
|
|
console.log(this.state.contractList);
|
2015-08-31 16:36:24 +02:00
|
|
|
return (
|
|
|
|
<CollapsibleParagraph
|
|
|
|
title={getLangText('Contract Settings')}
|
|
|
|
show={true}
|
2015-09-03 15:53:02 +02:00
|
|
|
defaultExpanded={false}>
|
2015-09-01 14:42:09 +02:00
|
|
|
{/* this should be this.props.defaultExpanded */}
|
2015-09-02 14:02:23 +02:00
|
|
|
<CollapsibleParagraph
|
|
|
|
title={getLangText('List Contracts')}
|
|
|
|
show={true}
|
2015-09-03 15:53:02 +02:00
|
|
|
defaultExpanded={false}>
|
|
|
|
{<div>
|
|
|
|
<p>Public Contracts</p>
|
|
|
|
{(publicContracts.length > 0) ?
|
|
|
|
publicContracts.map(
|
|
|
|
(contract) => {
|
2015-09-03 18:25:12 +02:00
|
|
|
return (
|
2015-09-03 15:53:02 +02:00
|
|
|
<ActionPanel title = {contract.name}
|
2015-09-07 11:38:23 +02:00
|
|
|
content = {contract.name}
|
2015-09-03 15:53:02 +02:00
|
|
|
buttons = {<span>
|
2015-09-07 15:43:44 +02:00
|
|
|
<button className="btn btn-default btn-sm margin-left-2px">
|
|
|
|
UPDATE
|
|
|
|
</button>
|
|
|
|
<button className="btn btn-default btn-sm margin-left-2px"
|
|
|
|
onClick={this.removeContract.bind(this, contract)}>
|
|
|
|
REMOVE
|
|
|
|
</button>
|
2015-09-03 15:53:02 +02:00
|
|
|
</span>}
|
2015-09-03 18:25:12 +02:00
|
|
|
/>);
|
2015-09-03 15:53:02 +02:00
|
|
|
}
|
|
|
|
) : null }
|
|
|
|
</div>}
|
|
|
|
|
|
|
|
{<div>
|
|
|
|
<p>Private Contracts</p>
|
2015-09-03 18:25:12 +02:00
|
|
|
{(privateContracts.length > 0) ?
|
2015-09-03 15:53:02 +02:00
|
|
|
privateContracts.map(
|
|
|
|
(contract) => {
|
2015-09-03 18:25:12 +02:00
|
|
|
return (
|
2015-09-03 15:53:02 +02:00
|
|
|
<ActionPanel title = {contract.name}
|
2015-09-07 11:38:23 +02:00
|
|
|
content = {contract.name}
|
2015-09-07 15:43:44 +02:00
|
|
|
buttons = {<span>
|
|
|
|
<button className="btn btn-default btn-sm margin-left-2px">
|
|
|
|
UPDATE
|
|
|
|
</button>
|
|
|
|
<button className="btn btn-default btn-sm margin-left-2px"
|
|
|
|
onClick={this.removeContract.bind(this, contract)}>
|
|
|
|
REMOVE
|
|
|
|
</button>
|
|
|
|
<button className="btn btn-default btn-sm margin-left-2px"
|
|
|
|
onClick={this.makeContractPublic.bind(this, contract)}>
|
|
|
|
MAKE PUBLIC
|
|
|
|
</button>
|
|
|
|
</span>}
|
2015-09-03 18:25:12 +02:00
|
|
|
/>);
|
2015-09-03 15:53:02 +02:00
|
|
|
}
|
|
|
|
) : null}
|
|
|
|
</div>}
|
2015-09-02 14:02:23 +02:00
|
|
|
</CollapsibleParagraph>
|
|
|
|
<CollapsibleParagraph
|
|
|
|
title={getLangText('Create Contract')}
|
|
|
|
show={true}
|
2015-09-03 15:53:02 +02:00
|
|
|
defaultExpanded={false}>
|
2015-09-02 14:02:23 +02:00
|
|
|
<CreateContractForm />
|
|
|
|
</CollapsibleParagraph>
|
2015-08-31 16:36:24 +02:00
|
|
|
</CollapsibleParagraph>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default ContractSettings;
|