mirror of
https://github.com/ascribe/onion.git
synced 2024-12-23 01:39:36 +01:00
contract listing being done
This commit is contained in:
parent
6555c02f23
commit
d2f8b658af
24
.gitignore~
Normal file
24
.gitignore~
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
lib-cov
|
||||||
|
*.seed
|
||||||
|
*.log
|
||||||
|
*.csv
|
||||||
|
*.dat
|
||||||
|
*.out
|
||||||
|
*.pid
|
||||||
|
*.gz
|
||||||
|
*.sublime-project
|
||||||
|
.idea
|
||||||
|
spool-project.sublime-project
|
||||||
|
*.sublime-workspace
|
||||||
|
*.sublime-workspace
|
||||||
|
webapp-dependencies.txt
|
||||||
|
|
||||||
|
pids
|
||||||
|
logs
|
||||||
|
results
|
||||||
|
README.md~
|
||||||
|
node_modules/*
|
||||||
|
|
||||||
|
build
|
||||||
|
|
||||||
|
.DS_Store
|
@ -43,6 +43,7 @@ class ContractActions {
|
|||||||
/* No email was entered - Ignore and keep going*/
|
/* No email was entered - Ignore and keep going*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default alt.createActions(ContractActions);
|
export default alt.createActions(ContractActions);
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
import alt from '../alt';
|
import alt from '../alt';
|
||||||
import OwnershipFetcher from '../fetchers/ownership_fetcher';
|
import OwnershipFetcher from '../fetchers/ownership_fetcher';
|
||||||
|
|
||||||
|
|
||||||
class ContractListActions {
|
class ContractListActions {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.generateActions(
|
this.generateActions(
|
||||||
@ -15,13 +14,23 @@ class ContractListActions {
|
|||||||
fetchContractList() {
|
fetchContractList() {
|
||||||
OwnershipFetcher.fetchContractList()
|
OwnershipFetcher.fetchContractList()
|
||||||
.then((contracts) => {
|
.then((contracts) => {
|
||||||
this.actions.updateContractList(contracts);
|
this.actions.updateContractList(contracts.results);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.logGlobal(err);
|
console.logGlobal(err);
|
||||||
this.actions.updateContractList([]);
|
this.actions.updateContractList([]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
makeContractPublic(contract){
|
||||||
|
OwnershipFetcher.makeContractPublic(contract)
|
||||||
|
.then((res) =>{
|
||||||
|
return res;
|
||||||
|
})
|
||||||
|
.catch((err)=>{
|
||||||
|
console.logGlobal(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default alt.createActions(ContractListActions);
|
export default alt.createActions(ContractListActions);
|
||||||
|
@ -44,7 +44,7 @@ let CreateContractForm = React.createClass({
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Form
|
<Form
|
||||||
url={ApiUrls.ownership_contract}
|
url={ApiUrls.ownership_contract_list}
|
||||||
getFormData={this.getFormData}
|
getFormData={this.getFormData}
|
||||||
buttons={
|
buttons={
|
||||||
<button
|
<button
|
||||||
|
@ -14,7 +14,6 @@ let ActionPanel = React.createClass({
|
|||||||
onClick: React.PropTypes.func,
|
onClick: React.PropTypes.func,
|
||||||
ignoreFocus: React.PropTypes.bool
|
ignoreFocus: React.PropTypes.bool
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
return {
|
return {
|
||||||
isFocused: false
|
isFocused: false
|
||||||
|
@ -8,6 +8,8 @@ import CreateContractForm from '../ascribe_forms/form_create_contract';
|
|||||||
import ContractListStore from '../../stores/contract_list_store';
|
import ContractListStore from '../../stores/contract_list_store';
|
||||||
import ContractListActions from '../../actions/contract_list_actions';
|
import ContractListActions from '../../actions/contract_list_actions';
|
||||||
|
|
||||||
|
import ActionPanel from '../ascribe_panel/action_panel';
|
||||||
|
|
||||||
import { getLangText } from '../../utils/lang_utils';
|
import { getLangText } from '../../utils/lang_utils';
|
||||||
|
|
||||||
let ContractSettings = React.createClass({
|
let ContractSettings = React.createClass({
|
||||||
@ -27,23 +29,73 @@ let ContractSettings = React.createClass({
|
|||||||
onChange(state) {
|
onChange(state) {
|
||||||
this.setState(state);
|
this.setState(state);
|
||||||
},
|
},
|
||||||
|
makeContractPublic(contract){
|
||||||
|
console.log(contract);
|
||||||
|
ContractListActions.makeContractPublic(contract)
|
||||||
|
.then(( ) => ContractListActions.fetchContractList())
|
||||||
|
.catch((error)=>{console.log("Error ", error)})
|
||||||
|
},
|
||||||
|
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() {
|
render() {
|
||||||
|
let publicContracts = this.getPublicContracts();
|
||||||
|
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={true}>
|
defaultExpanded={false}>
|
||||||
{/* this should be this.props.defaultExpanded */}
|
{/* this should be this.props.defaultExpanded */}
|
||||||
<CollapsibleParagraph
|
<CollapsibleParagraph
|
||||||
title={getLangText('List Contracts')}
|
title={getLangText('List Contracts')}
|
||||||
show={true}
|
show={true}
|
||||||
defaultExpanded={true}>
|
defaultExpanded={false}>
|
||||||
{this.state.contractList}
|
{<div>
|
||||||
|
<p>Public Contracts</p>
|
||||||
|
{(publicContracts.length > 0) ?
|
||||||
|
publicContracts.map(
|
||||||
|
(contract) => {
|
||||||
|
return(
|
||||||
|
<ActionPanel title = {contract.name}
|
||||||
|
content = {this.getblobEndName(contract)}
|
||||||
|
buttons = {<span>
|
||||||
|
<button className="btn btn-default btn-sm margin-left-2px">UPDATE</button>
|
||||||
|
<button className="btn btn-default btn-sm margin-left-2px">REMOVE</button>
|
||||||
|
</span>}
|
||||||
|
/>)
|
||||||
|
}
|
||||||
|
) : null }
|
||||||
|
</div>}
|
||||||
|
|
||||||
|
{<div>
|
||||||
|
<p>Private Contracts</p>
|
||||||
|
{(privateContracts.length>0) ?
|
||||||
|
privateContracts.map(
|
||||||
|
(contract) => {
|
||||||
|
return(
|
||||||
|
<ActionPanel title = {contract.name}
|
||||||
|
content = {this.getblobEndName(contract)}
|
||||||
|
buttons = {<span> <button className="btn btn-default btn-sm margin-left-2px">UPDATE</button>
|
||||||
|
<button className="btn btn-default btn-sm margin-left-2px" >REMOVE</button>
|
||||||
|
<button className="btn btn-default btn-sm margin-left-2px"
|
||||||
|
onClick={this.makeContractPublic.bind(this, contract)}>MAKE PUBLIC</button> </span>}
|
||||||
|
/>)
|
||||||
|
}
|
||||||
|
) : null}
|
||||||
|
</div>}
|
||||||
</CollapsibleParagraph>
|
</CollapsibleParagraph>
|
||||||
<CollapsibleParagraph
|
<CollapsibleParagraph
|
||||||
title={getLangText('Create Contract')}
|
title={getLangText('Create Contract')}
|
||||||
show={true}
|
show={true}
|
||||||
defaultExpanded={true}>
|
defaultExpanded={false}>
|
||||||
<CreateContractForm />
|
<CreateContractForm />
|
||||||
</CollapsibleParagraph>
|
</CollapsibleParagraph>
|
||||||
</CollapsibleParagraph>
|
</CollapsibleParagraph>
|
||||||
|
@ -46,7 +46,8 @@ 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/',
|
'ownership_contract':AppConstants.apiEndpoint + 'ownership/contracts/${contract_id}',
|
||||||
|
"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/',
|
||||||
'piece_first_edition_id': AppConstants.apiEndpoint + 'pieces/${piece_id}/edition_index/',
|
'piece_first_edition_id': AppConstants.apiEndpoint + 'pieces/${piece_id}/edition_index/',
|
||||||
|
@ -16,11 +16,16 @@ let OwnershipFetcher = {
|
|||||||
* Fetch the contracts of the logged-in user from the API.
|
* Fetch the contracts of the logged-in user from the API.
|
||||||
*/
|
*/
|
||||||
fetchContractList(){
|
fetchContractList(){
|
||||||
return requests.get(ApiUrls.ownership_contract);
|
return requests.get(ApiUrls.ownership_contract_list);
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchLoanPieceRequestList(){
|
fetchLoanPieceRequestList(){
|
||||||
return requests.get(ApiUrls.ownership_loans_pieces_request);
|
return requests.get(ApiUrls.ownership_loans_pieces_request);
|
||||||
|
},
|
||||||
|
|
||||||
|
makeContractPublic(contractObj){
|
||||||
|
console.log(contractObj);
|
||||||
|
return requests.put('ownership_contract_list',{ body: contractObj, contract_id:contractObj.id });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -52,6 +52,19 @@ 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
|
||||||
|
@ -6,6 +6,7 @@ import { argsToQueryParams, getCookie } from '../utils/fetch_api_utils';
|
|||||||
|
|
||||||
import AppConstants from '../constants/application_constants';
|
import AppConstants from '../constants/application_constants';
|
||||||
|
|
||||||
|
import {excludePropFromObject} from '../utils/general_utils';
|
||||||
|
|
||||||
class Requests {
|
class Requests {
|
||||||
_merge(defaults, options) {
|
_merge(defaults, options) {
|
||||||
@ -137,15 +138,25 @@ class Requests {
|
|||||||
return this.request('delete', newUrl);
|
return this.request('delete', newUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
post(url, params) {
|
_putOrPost(url,paramsAndBody,method){
|
||||||
let paramsCopy = this._merge(params);
|
let paramsCopy = this._merge(paramsAndBody);
|
||||||
let newUrl = this.prepareUrl(url, paramsCopy);
|
let params = excludePropFromObject(paramsAndBody,['body']);
|
||||||
|
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('post', newUrl, { body });
|
return this.request(method, newUrl, { body });
|
||||||
|
}
|
||||||
|
|
||||||
|
post(url, params) {
|
||||||
|
return this._putOrPost(url,params,'post')
|
||||||
|
}
|
||||||
|
|
||||||
|
put(url, params){
|
||||||
|
console.log(params);
|
||||||
|
return this._putOrPost(url,params,'put')
|
||||||
}
|
}
|
||||||
|
|
||||||
defaults(options) {
|
defaults(options) {
|
||||||
|
Loading…
Reference in New Issue
Block a user