mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
create refresh added, conflicts resolved
This commit is contained in:
commit
5b0cbc92ad
@ -23,7 +23,8 @@ class ContractListActions {
|
||||
});
|
||||
}
|
||||
|
||||
makeContractPublic(contract){
|
||||
|
||||
changeContract(contract){
|
||||
return Q.Promise((resolve, reject) => {
|
||||
OwnershipFetcher.makeContractPublic(contract)
|
||||
.then((res) => {
|
||||
@ -40,11 +41,9 @@ class ContractListActions {
|
||||
return Q.Promise( (resolve, reject) => {
|
||||
OwnershipFetcher.deleteContract(contractId)
|
||||
.then((res) => {
|
||||
console.log('Success...');
|
||||
resolve(res);
|
||||
})
|
||||
.catch( (err) => {
|
||||
console.log('Bad news...');
|
||||
console.logGlobal(err);
|
||||
reject(err);
|
||||
});
|
||||
|
@ -8,7 +8,9 @@ import InputCheckbox from '../ascribe_forms/input_checkbox';
|
||||
|
||||
import GlobalNotificationModel from '../../models/global_notification_model';
|
||||
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
||||
|
||||
import ContractListActions from '../../actions/contract_list_actions';
|
||||
|
||||
import ReactS3FineUploader from '../ascribe_uploader/react_s3_fine_uploader';
|
||||
|
||||
import AppConstants from '../../constants/application_constants';
|
||||
@ -51,6 +53,9 @@ let CreateContractForm = React.createClass({
|
||||
ContractListActions.fetchContractList();
|
||||
let notification = new GlobalNotificationModel(getLangText('Contract %s successfully created', response.name), 'success', 5000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
|
||||
// also refresh contract lists for the rest of the contract settings page
|
||||
ContractListActions.fetchContractList();
|
||||
},
|
||||
|
||||
|
||||
@ -112,7 +117,7 @@ let CreateContractForm = React.createClass({
|
||||
label={getLangText('Contract name')}>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="(e.g. Loan agreement #1)"
|
||||
placeholder="(e.g. Contract - Loan agreement #1)"
|
||||
required/>
|
||||
</Property>
|
||||
<Property
|
||||
@ -121,10 +126,7 @@ let CreateContractForm = React.createClass({
|
||||
style={{paddingBottom: 0}}>
|
||||
<InputCheckbox>
|
||||
<span>
|
||||
{' ' + getLangText('I agree to the Terms of Service') + ' '}
|
||||
(<a href="https://www.ascribe.io/terms" target="_blank" style={{fontSize: '0.9em', color: 'rgba(0,0,0,0.7)'}}>
|
||||
{getLangText('read')}
|
||||
</a>)
|
||||
Make contract public (this will replace the current public contract)
|
||||
</span>
|
||||
</InputCheckbox>
|
||||
</Property>
|
||||
|
@ -12,8 +12,12 @@ let ActionPanel = React.createClass({
|
||||
]),
|
||||
buttons: React.PropTypes.element,
|
||||
onClick: React.PropTypes.func,
|
||||
ignoreFocus: React.PropTypes.bool
|
||||
ignoreFocus: React.PropTypes.bool,
|
||||
|
||||
leftColumnWidth: React.PropTypes.string,
|
||||
rightColumnWidth: React.PropTypes.string
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
isFocused: false
|
||||
@ -40,14 +44,21 @@ let ActionPanel = React.createClass({
|
||||
},
|
||||
|
||||
render() {
|
||||
|
||||
let { leftColumnWidth, rightColumnWidth } = this.props;
|
||||
|
||||
return (
|
||||
<div className={classnames('ascribe-panel-wrapper', {'is-focused': this.state.isFocused})}>
|
||||
<div className="ascribe-panel-table">
|
||||
<div
|
||||
className="ascribe-panel-table"
|
||||
style={{width: leftColumnWidth}}>
|
||||
<div className="ascribe-panel-content">
|
||||
{this.props.content}
|
||||
</div>
|
||||
</div>
|
||||
<div className="ascribe-panel-table">
|
||||
<div
|
||||
className="ascribe-panel-table"
|
||||
style={{width: rightColumnWidth}}>
|
||||
<div className="ascribe-panel-content">
|
||||
{this.props.buttons}
|
||||
</div>
|
||||
|
@ -10,122 +10,141 @@ import ContractListActions from '../../actions/contract_list_actions';
|
||||
|
||||
import ActionPanel from '../ascribe_panel/action_panel';
|
||||
|
||||
import { getLangText } from '../../utils/lang_utils';
|
||||
import GlobalNotificationModel from '../../models/global_notification_model';
|
||||
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
||||
|
||||
import { getLangText } from '../../utils/lang_utils';
|
||||
|
||||
let ContractSettings = React.createClass({
|
||||
propTypes: {
|
||||
defaultExpanded: React.PropTypes.bool
|
||||
},
|
||||
|
||||
getInitialState(){
|
||||
return ContractListStore.getState();
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
ContractListStore.listen(this.onChange);
|
||||
ContractListActions.fetchContractList();
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
ContractListStore.unlisten(this.onChange);
|
||||
},
|
||||
|
||||
onChange(state) {
|
||||
this.setState(state);
|
||||
},
|
||||
makeContractPublic(contract){
|
||||
ContractListActions.makeContractPublic(contract)
|
||||
.then( ( ) => ContractListActions.fetchContractList())
|
||||
.catch((error)=>{
|
||||
let notification = new GlobalNotificationModel(error, 'danger', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
});
|
||||
|
||||
makeContractPublic(contract) {
|
||||
return () => {
|
||||
contract.public = true;
|
||||
ContractListActions.changeContract(contract)
|
||||
.then(() => ContractListActions.fetchContractList())
|
||||
.catch((err) => {
|
||||
let notification = new GlobalNotificationModel(err, 'danger', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
});
|
||||
};
|
||||
},
|
||||
removeContract(contract){
|
||||
console.log(contract);
|
||||
ContractListActions.removeContract(contract.id)
|
||||
.then(
|
||||
() => {
|
||||
ContractListActions.fetchContractList();
|
||||
})
|
||||
.catch((error) => {
|
||||
let notification = new GlobalNotificationModel(error, 'danger', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
});
|
||||
|
||||
removeContract(contract) {
|
||||
return () => {
|
||||
ContractListActions.removeContract(contract.id)
|
||||
.then(( ) => ContractListActions.fetchContractList())
|
||||
.catch((err) => {
|
||||
let notification = new GlobalNotificationModel(err, 'danger', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
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];
|
||||
},
|
||||
|
||||
render() {
|
||||
let publicContracts = this.getPublicContracts();
|
||||
let privateContracts = this.getPrivateContracts();
|
||||
console.log(this.state.contractList);
|
||||
|
||||
return (
|
||||
<CollapsibleParagraph
|
||||
title={getLangText('Contract Settings')}
|
||||
show={true}
|
||||
defaultExpanded={false}>
|
||||
{/* this should be this.props.defaultExpanded */}
|
||||
defaultExpanded={true}>
|
||||
<CollapsibleParagraph
|
||||
title={getLangText('List Contracts')}
|
||||
show={true}
|
||||
defaultExpanded={false}>
|
||||
{<div>
|
||||
<p>Public Contracts</p>
|
||||
{(publicContracts.length > 0) ?
|
||||
publicContracts.map(
|
||||
(contract) => {
|
||||
defaultExpanded={true}>
|
||||
<CollapsibleParagraph
|
||||
title={getLangText('Public Contracts')}
|
||||
show={true}
|
||||
defaultExpanded={true}>
|
||||
{publicContracts.map((contract, i) => {
|
||||
return (
|
||||
<ActionPanel title = {contract.name}
|
||||
content = {contract.name}
|
||||
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>
|
||||
</span>}
|
||||
/>);
|
||||
}
|
||||
) : null }
|
||||
</div>}
|
||||
|
||||
{<div>
|
||||
<p>Private Contracts</p>
|
||||
{(privateContracts.length > 0) ?
|
||||
privateContracts.map(
|
||||
(contract) => {
|
||||
<ActionPanel
|
||||
key={i}
|
||||
title={contract.name}
|
||||
content={contract.name}
|
||||
buttons={
|
||||
<div className="pull-right">
|
||||
<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(contract)}>
|
||||
REMOVE
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
leftColumnWidth="40%"
|
||||
rightColumnWidth="60%"/>
|
||||
);
|
||||
})}
|
||||
</CollapsibleParagraph>
|
||||
<CollapsibleParagraph
|
||||
title={getLangText('Private Contracts')}
|
||||
show={true}
|
||||
defaultExpanded={true}>
|
||||
{privateContracts.map((contract, i) => {
|
||||
return (
|
||||
<ActionPanel title = {contract.name}
|
||||
content = {contract.name}
|
||||
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>}
|
||||
/>);
|
||||
}
|
||||
) : null}
|
||||
</div>}
|
||||
<ActionPanel
|
||||
key={i}
|
||||
title={contract.name}
|
||||
content={contract.name}
|
||||
buttons={
|
||||
<div className="pull-right">
|
||||
<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(contract)}>
|
||||
REMOVE
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-default btn-sm margin-left-2px"
|
||||
onClick={this.makeContractPublic(contract)}>
|
||||
MAKE PUBLIC
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
leftColumnWidth="40%"
|
||||
rightColumnWidth="60%"/>
|
||||
);
|
||||
})}
|
||||
</CollapsibleParagraph>
|
||||
</CollapsibleParagraph>
|
||||
<CollapsibleParagraph
|
||||
title={getLangText('Create Contract')}
|
||||
show={true}
|
||||
defaultExpanded={false}>
|
||||
defaultExpanded={true}>
|
||||
<CreateContractForm />
|
||||
</CollapsibleParagraph>
|
||||
</CollapsibleParagraph>
|
||||
|
@ -52,19 +52,6 @@ export function sumNumList(l) {
|
||||
return sum;
|
||||
}
|
||||
|
||||
export function excludePropFromObject(obj, propList){
|
||||
let clonedObj = mergeOptions({},obj);
|
||||
for (let item in propList){
|
||||
console.log(item);
|
||||
if (clonedObj[propList[item]]){
|
||||
console.log('deleting... ');
|
||||
delete clonedObj[propList[item]];
|
||||
}
|
||||
}
|
||||
console.log(clonedObj);
|
||||
return clonedObj;
|
||||
}
|
||||
|
||||
/*
|
||||
Taken from http://stackoverflow.com/a/4795914/1263876
|
||||
Behaves like C's format string function
|
||||
@ -207,4 +194,14 @@ function _mergeOptions(obj1, obj2) {
|
||||
*/
|
||||
export function escapeHTML(s) {
|
||||
return document.createElement('div').appendChild(document.createTextNode(s)).parentNode.innerHTML;
|
||||
}
|
||||
|
||||
export function excludePropFromObject(obj, propList){
|
||||
let clonedObj = mergeOptions({}, obj);
|
||||
for (let item in propList){
|
||||
if (clonedObj[propList[item]]){
|
||||
delete clonedObj[propList[item]];
|
||||
}
|
||||
}
|
||||
return clonedObj;
|
||||
}
|
@ -33,7 +33,7 @@ class Requests {
|
||||
// If this is the case, we can not try to parse it as JSON.
|
||||
if(responseText !== 'None') {
|
||||
let body = JSON.parse(responseText);
|
||||
|
||||
|
||||
if(body && body.errors) {
|
||||
let error = new Error('Form Error');
|
||||
error.json = body;
|
||||
@ -136,6 +136,7 @@ class Requests {
|
||||
delete(url, params) {
|
||||
let paramsCopy = this._merge(params);
|
||||
let newUrl = this.prepareUrl(url, paramsCopy, true);
|
||||
|
||||
return this.request('delete', newUrl);
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@
|
||||
width: 100%;
|
||||
|
||||
/* Shrink the size of the headline for a nested element */
|
||||
.ascribe-collapsible-wrapper > div:first-child {
|
||||
.ascribe-collapsible-wrapper > .ascribe-collapsible-content {
|
||||
padding-left: 1em;
|
||||
font-size: 90%;
|
||||
font-size: 95%;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user