1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 13:41:57 +02:00

merge 456

This commit is contained in:
diminator 2015-09-08 14:42:51 +02:00
commit 9ad713f781
10 changed files with 157 additions and 83 deletions

View File

@ -23,16 +23,27 @@ class ContractListActions {
}); });
} }
makeContractPublic(contract){
contract.public = true; changeContract(contract){
return Q.Promise((resolve, reject) => { return Q.Promise((resolve, reject) => {
OwnershipFetcher.makeContractPublic(contract) OwnershipFetcher.makeContractPublic(contract)
.then((res) => { .then((res) => {
console.log('Here is the result... ');
resolve(res); resolve(res);
}) })
.catch((err)=> { .catch((err)=> {
console.log('Here we have an error'); console.logGlobal(err);
reject(err);
});
});
}
removeContract(contractId){
return Q.Promise( (resolve, reject) => {
OwnershipFetcher.deleteContract(contractId)
.then((res) => {
resolve(res);
})
.catch( (err) => {
console.logGlobal(err); console.logGlobal(err);
reject(err); reject(err);
}); });

View File

@ -3,7 +3,7 @@
import React from 'react'; import React from 'react';
import AppConstants from '../../constants/application_constants'; import AppConstants from '../../constants/application_constants';
import { getLangText } from '../../utils/lang_utils.js' import { getLangText } from '../../utils/lang_utils.js';
let ButtonSubmitOrClose = React.createClass({ let ButtonSubmitOrClose = React.createClass({
propTypes: { propTypes: {

View File

@ -9,11 +9,15 @@ import InputCheckbox from '../ascribe_forms/input_checkbox';
import GlobalNotificationModel from '../../models/global_notification_model'; import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions'; import GlobalNotificationActions from '../../actions/global_notification_actions';
import ContractListActions from '../../actions/contract_list_actions';
import ReactS3FineUploader from '../ascribe_uploader/react_s3_fine_uploader'; import ReactS3FineUploader from '../ascribe_uploader/react_s3_fine_uploader';
import AppConstants from '../../constants/application_constants'; import AppConstants from '../../constants/application_constants';
import ApiUrls from '../../constants/api_urls'; import ApiUrls from '../../constants/api_urls';
import { getLangText } from '../../utils/lang_utils'; import { getLangText } from '../../utils/lang_utils';
import { getCookie } from '../../utils/fetch_api_utils'; import { getCookie } from '../../utils/fetch_api_utils';
import { formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uploader_utils'; import { formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uploader_utils';
@ -46,8 +50,12 @@ let CreateContractForm = React.createClass({
}, },
handleCreateSuccess(response) { handleCreateSuccess(response) {
ContractListActions.fetchContractList();
let notification = new GlobalNotificationModel(getLangText('Contract %s successfully created', response.name), 'success', 5000); let notification = new GlobalNotificationModel(getLangText('Contract %s successfully created', response.name), 'success', 5000);
GlobalNotificationActions.appendGlobalNotification(notification); GlobalNotificationActions.appendGlobalNotification(notification);
// also refresh contract lists for the rest of the contract settings page
ContractListActions.fetchContractList();
}, },
@ -109,7 +117,7 @@ let CreateContractForm = React.createClass({
label={getLangText('Contract name')}> label={getLangText('Contract name')}>
<input <input
type="text" type="text"
placeholder="(e.g. Loan agreement #1)" placeholder="(e.g. Contract - Loan agreement #1)"
required/> required/>
</Property> </Property>
<Property <Property
@ -118,10 +126,7 @@ let CreateContractForm = React.createClass({
style={{paddingBottom: 0}}> style={{paddingBottom: 0}}>
<InputCheckbox> <InputCheckbox>
<span> <span>
{' ' + getLangText('I agree to the Terms of Service') + ' '} Make contract public (this will replace the current public contract)
(<a href="https://www.ascribe.io/terms" target="_blank" style={{fontSize: '0.9em', color: 'rgba(0,0,0,0.7)'}}>
{getLangText('read')}
</a>)
</span> </span>
</InputCheckbox> </InputCheckbox>
</Property> </Property>

View File

@ -12,8 +12,12 @@ let ActionPanel = React.createClass({
]), ]),
buttons: React.PropTypes.element, buttons: React.PropTypes.element,
onClick: React.PropTypes.func, onClick: React.PropTypes.func,
ignoreFocus: React.PropTypes.bool ignoreFocus: React.PropTypes.bool,
leftColumnWidth: React.PropTypes.string,
rightColumnWidth: React.PropTypes.string
}, },
getInitialState() { getInitialState() {
return { return {
isFocused: false isFocused: false
@ -40,14 +44,21 @@ let ActionPanel = React.createClass({
}, },
render() { render() {
let { leftColumnWidth, rightColumnWidth } = this.props;
return ( return (
<div className={classnames('ascribe-panel-wrapper', {'is-focused': this.state.isFocused})}> <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"> <div className="ascribe-panel-content">
{this.props.content} {this.props.content}
</div> </div>
</div> </div>
<div className="ascribe-panel-table"> <div
className="ascribe-panel-table"
style={{width: rightColumnWidth}}>
<div className="ascribe-panel-content"> <div className="ascribe-panel-content">
{this.props.buttons} {this.props.buttons}
</div> </div>

View File

@ -10,97 +10,141 @@ import ContractListActions from '../../actions/contract_list_actions';
import ActionPanel from '../ascribe_panel/action_panel'; import ActionPanel from '../ascribe_panel/action_panel';
import { getLangText } from '../../utils/lang_utils';
import GlobalNotificationModel from '../../models/global_notification_model'; import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions'; import GlobalNotificationActions from '../../actions/global_notification_actions';
import { getLangText } from '../../utils/lang_utils';
let ContractSettings = React.createClass({ let ContractSettings = React.createClass({
propTypes: { propTypes: {
defaultExpanded: React.PropTypes.bool defaultExpanded: React.PropTypes.bool
}, },
getInitialState(){ getInitialState(){
return ContractListStore.getState(); return ContractListStore.getState();
}, },
componentDidMount() { componentDidMount() {
ContractListStore.listen(this.onChange); ContractListStore.listen(this.onChange);
ContractListActions.fetchContractList(); ContractListActions.fetchContractList();
}, },
componentWillUnmount() { componentWillUnmount() {
ContractListStore.unlisten(this.onChange); ContractListStore.unlisten(this.onChange);
}, },
onChange(state) { onChange(state) {
this.setState(state); this.setState(state);
}, },
makeContractPublic(contract){
console.log(contract); makeContractPublic(contract) {
ContractListActions.makeContractPublic(contract) return () => {
.then(( ) => ContractListActions.fetchContractList()) contract.public = true;
.catch((error)=>{console.log('Error ', error); ContractListActions.changeContract(contract)
let notification = new GlobalNotificationModel('Service is unavailable', 'danger', 10000); .then(() => ContractListActions.fetchContractList())
GlobalNotificationActions.appendGlobalNotification(notification); .catch((err) => {
}); let notification = new GlobalNotificationModel(err, '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(){ getPublicContracts(){
return this.state.contractList.filter((contract) => contract.public); return this.state.contractList.filter((contract) => contract.public);
}, },
getPrivateContracts(){ getPrivateContracts(){
return this.state.contractList.filter((contract) => !contract.public); return this.state.contractList.filter((contract) => !contract.public);
}, },
getblobEndName(contract){
return contract.blob.match(/.*\/(.*)/)[1];
},
render() { render() {
let publicContracts = this.getPublicContracts(); let publicContracts = this.getPublicContracts();
let privateContracts = this.getPrivateContracts(); let privateContracts = this.getPrivateContracts();
console.log(this.state.contractList);
return ( return (
<CollapsibleParagraph <CollapsibleParagraph
title={getLangText('Contract Settings')} title={getLangText('Contract Settings')}
show={true} show={true}
defaultExpanded={false}> defaultExpanded={true}>
{/* this should be this.props.defaultExpanded */}
<CollapsibleParagraph <CollapsibleParagraph
title={getLangText('List Contracts')} title={getLangText('List Contracts')}
show={true} show={true}
defaultExpanded={false}> defaultExpanded={true}>
{<div> <CollapsibleParagraph
<p>Public Contracts</p> title={getLangText('Public Contracts')}
{(publicContracts.length > 0) ? show={true}
publicContracts.map( defaultExpanded={true}>
(contract) => { {publicContracts.map((contract, i) => {
return ( return (
<ActionPanel title = {contract.name} <ActionPanel
content = {this.getblobEndName(contract)} key={i}
buttons = {<span> title={contract.name}
<button className="btn btn-default btn-sm margin-left-2px">UPDATE</button> content={contract.name}
<button className="btn btn-default btn-sm margin-left-2px">REMOVE</button> buttons={
</span>} <div className="pull-right">
/>); <button className="btn btn-default btn-sm margin-left-2px">
} UPDATE
) : null } </button>
</div>} <button
className="btn btn-default btn-sm margin-left-2px"
{<div> onClick={this.removeContract(contract)}>
<p>Private Contracts</p> REMOVE
{(privateContracts.length > 0) ? </button>
privateContracts.map( </div>
(contract) => { }
leftColumnWidth="40%"
rightColumnWidth="60%"/>
);
})}
</CollapsibleParagraph>
<CollapsibleParagraph
title={getLangText('Private Contracts')}
show={true}
defaultExpanded={true}>
{privateContracts.map((contract, i) => {
return ( return (
<ActionPanel title = {contract.name} <ActionPanel
content = {this.getblobEndName(contract)} key={i}
buttons = {<span> <button className="btn btn-default btn-sm margin-left-2px">UPDATE</button> title={contract.name}
<button className="btn btn-default btn-sm margin-left-2px" >REMOVE</button> content={contract.name}
<button className="btn btn-default btn-sm margin-left-2px" buttons={
onClick={this.makeContractPublic.bind(this, contract)}>MAKE PUBLIC</button> </span>} <div className="pull-right">
/>); <button className="btn btn-default btn-sm margin-left-2px">
} UPDATE
) : null} </button>
</div>} <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>
<CollapsibleParagraph <CollapsibleParagraph
title={getLangText('Create Contract')} title={getLangText('Create Contract')}
show={true} show={true}
defaultExpanded={false}> defaultExpanded={true}>
<CreateContractForm /> <CreateContractForm />
</CollapsibleParagraph> </CollapsibleParagraph>
</CollapsibleParagraph> </CollapsibleParagraph>

View File

@ -54,7 +54,7 @@ let ApiUrls = {
'ownership_unconsigns': AppConstants.apiEndpoint + 'ownership/unconsigns/', 'ownership_unconsigns': AppConstants.apiEndpoint + 'ownership/unconsigns/',
'ownership_unconsigns_deny': AppConstants.apiEndpoint + 'ownership/unconsigns/deny/', 'ownership_unconsigns_deny': AppConstants.apiEndpoint + 'ownership/unconsigns/deny/',
'ownership_unconsigns_request': AppConstants.apiEndpoint + 'ownership/unconsigns/request/', 'ownership_unconsigns_request': AppConstants.apiEndpoint + 'ownership/unconsigns/request/',
'ownership_contract': AppConstants.apiEndpoint + 'ownership/contracts/${contract_id}', 'ownership_contract': AppConstants.apiEndpoint + 'ownership/contracts/${contract_id}/',
'ownership_contract_list': AppConstants.apiEndpoint + 'ownership/contracts/', 'ownership_contract_list': AppConstants.apiEndpoint + 'ownership/contracts/',
'piece': AppConstants.apiEndpoint + 'pieces/${piece_id}/', 'piece': AppConstants.apiEndpoint + 'pieces/${piece_id}/',
'piece_extradata': AppConstants.apiEndpoint + 'pieces/${piece_id}/extradata/', 'piece_extradata': AppConstants.apiEndpoint + 'pieces/${piece_id}/extradata/',

View File

@ -25,6 +25,10 @@ let OwnershipFetcher = {
makeContractPublic(contractObj){ makeContractPublic(contractObj){
return requests.put('ownership_contract', { body: contractObj, contract_id: contractObj.id }); return requests.put('ownership_contract', { body: contractObj, contract_id: contractObj.id });
},
deleteContract(contractObjId){
return requests.delete(ApiUrls.ownership_contract, {contract_id: contractObjId});
} }
}; };

View File

@ -52,19 +52,6 @@ export function sumNumList(l) {
return sum; 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 Taken from http://stackoverflow.com/a/4795914/1263876
Behaves like C's format string function Behaves like C's format string function
@ -207,4 +194,14 @@ function _mergeOptions(obj1, obj2) {
*/ */
export function escapeHTML(s) { export function escapeHTML(s) {
return document.createElement('div').appendChild(document.createTextNode(s)).parentNode.innerHTML; 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;
} }

View File

@ -33,7 +33,7 @@ class Requests {
// If this is the case, we can not try to parse it as JSON. // If this is the case, we can not try to parse it as JSON.
if(responseText !== 'None') { if(responseText !== 'None') {
let body = JSON.parse(responseText); let body = JSON.parse(responseText);
if(body && body.errors) { if(body && body.errors) {
let error = new Error('Form Error'); let error = new Error('Form Error');
error.json = body; error.json = body;
@ -119,7 +119,9 @@ class Requests {
return fetch(url, merged) return fetch(url, merged)
.then(this.unpackResponse) .then(this.unpackResponse)
.catch(this.handleError); .catch( () => {
this.handleError();
});
} }
get(url, params) { get(url, params) {
@ -134,28 +136,28 @@ class Requests {
delete(url, params) { delete(url, params) {
let paramsCopy = this._merge(params); let paramsCopy = this._merge(params);
let newUrl = this.prepareUrl(url, paramsCopy, true); let newUrl = this.prepareUrl(url, paramsCopy, true);
return this.request('delete', newUrl); return this.request('delete', newUrl);
} }
_putOrPost(url, paramsAndBody, method){ _putOrPost(url, paramsAndBody, method){
let paramsCopy = this._merge(paramsAndBody); let paramsCopy = this._merge(paramsAndBody);
let params = excludePropFromObject(paramsAndBody,['body']); let params = excludePropFromObject(paramsAndBody, ['body']);
let newUrl = this.prepareUrl(url, params); let newUrl = this.prepareUrl(url, params);
let body = null; let body = null;
if (paramsCopy && paramsCopy.body) { if (paramsCopy && paramsCopy.body) {
console.log(paramsCopy.body);
body = JSON.stringify(paramsCopy.body); body = JSON.stringify(paramsCopy.body);
} }
return this.request(method, newUrl, { body }); return this.request(method, newUrl, { body });
} }
post(url, params) { post(url, params) {
return this._putOrPost(url,params,'post') return this._putOrPost(url, params, 'post');
} }
put(url, params){ put(url, params){
return this._putOrPost(url,params,'put') return this._putOrPost(url, params, 'put');
} }
defaults(options) { defaults(options) {

View File

@ -26,8 +26,8 @@
width: 100%; width: 100%;
/* Shrink the size of the headline for a nested element */ /* 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; padding-left: 1em;
font-size: 90%; font-size: 95%;
} }
} }