mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +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*/
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default alt.createActions(ContractActions);
|
||||
|
@ -3,7 +3,6 @@
|
||||
import alt from '../alt';
|
||||
import OwnershipFetcher from '../fetchers/ownership_fetcher';
|
||||
|
||||
|
||||
class ContractListActions {
|
||||
constructor() {
|
||||
this.generateActions(
|
||||
@ -15,13 +14,23 @@ class ContractListActions {
|
||||
fetchContractList() {
|
||||
OwnershipFetcher.fetchContractList()
|
||||
.then((contracts) => {
|
||||
this.actions.updateContractList(contracts);
|
||||
this.actions.updateContractList(contracts.results);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.logGlobal(err);
|
||||
this.actions.updateContractList([]);
|
||||
});
|
||||
}
|
||||
|
||||
makeContractPublic(contract){
|
||||
OwnershipFetcher.makeContractPublic(contract)
|
||||
.then((res) =>{
|
||||
return res;
|
||||
})
|
||||
.catch((err)=>{
|
||||
console.logGlobal(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default alt.createActions(ContractListActions);
|
||||
|
@ -44,7 +44,7 @@ let CreateContractForm = React.createClass({
|
||||
render() {
|
||||
return (
|
||||
<Form
|
||||
url={ApiUrls.ownership_contract}
|
||||
url={ApiUrls.ownership_contract_list}
|
||||
getFormData={this.getFormData}
|
||||
buttons={
|
||||
<button
|
||||
|
@ -14,7 +14,6 @@ let ActionPanel = React.createClass({
|
||||
onClick: React.PropTypes.func,
|
||||
ignoreFocus: React.PropTypes.bool
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
isFocused: false
|
||||
|
@ -8,6 +8,8 @@ import CreateContractForm from '../ascribe_forms/form_create_contract';
|
||||
import ContractListStore from '../../stores/contract_list_store';
|
||||
import ContractListActions from '../../actions/contract_list_actions';
|
||||
|
||||
import ActionPanel from '../ascribe_panel/action_panel';
|
||||
|
||||
import { getLangText } from '../../utils/lang_utils';
|
||||
|
||||
let ContractSettings = React.createClass({
|
||||
@ -27,23 +29,73 @@ let ContractSettings = React.createClass({
|
||||
onChange(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() {
|
||||
let publicContracts = this.getPublicContracts();
|
||||
let privateContracts = this.getPrivateContracts();
|
||||
console.log(this.state.contractList);
|
||||
return (
|
||||
<CollapsibleParagraph
|
||||
title={getLangText('Contract Settings')}
|
||||
show={true}
|
||||
defaultExpanded={true}>
|
||||
defaultExpanded={false}>
|
||||
{/* this should be this.props.defaultExpanded */}
|
||||
<CollapsibleParagraph
|
||||
title={getLangText('List Contracts')}
|
||||
show={true}
|
||||
defaultExpanded={true}>
|
||||
{this.state.contractList}
|
||||
defaultExpanded={false}>
|
||||
{<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
|
||||
title={getLangText('Create Contract')}
|
||||
show={true}
|
||||
defaultExpanded={true}>
|
||||
defaultExpanded={false}>
|
||||
<CreateContractForm />
|
||||
</CollapsibleParagraph>
|
||||
</CollapsibleParagraph>
|
||||
|
@ -46,7 +46,8 @@ let ApiUrls = {
|
||||
'ownership_unconsigns': AppConstants.apiEndpoint + 'ownership/unconsigns/',
|
||||
'ownership_unconsigns_deny': AppConstants.apiEndpoint + 'ownership/unconsigns/deny/',
|
||||
'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_extradata': AppConstants.apiEndpoint + 'pieces/${piece_id}/extradata/',
|
||||
'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.
|
||||
*/
|
||||
fetchContractList(){
|
||||
return requests.get(ApiUrls.ownership_contract);
|
||||
return requests.get(ApiUrls.ownership_contract_list);
|
||||
},
|
||||
|
||||
fetchLoanPieceRequestList(){
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -6,6 +6,7 @@ import { argsToQueryParams, getCookie } from '../utils/fetch_api_utils';
|
||||
|
||||
import AppConstants from '../constants/application_constants';
|
||||
|
||||
import {excludePropFromObject} from '../utils/general_utils';
|
||||
|
||||
class Requests {
|
||||
_merge(defaults, options) {
|
||||
@ -137,15 +138,25 @@ class Requests {
|
||||
return this.request('delete', newUrl);
|
||||
}
|
||||
|
||||
post(url, params) {
|
||||
let paramsCopy = this._merge(params);
|
||||
let newUrl = this.prepareUrl(url, paramsCopy);
|
||||
_putOrPost(url,paramsAndBody,method){
|
||||
let paramsCopy = this._merge(paramsAndBody);
|
||||
let params = excludePropFromObject(paramsAndBody,['body']);
|
||||
let newUrl = this.prepareUrl(url, params);
|
||||
let body = null;
|
||||
|
||||
if (paramsCopy && paramsCopy.body) {
|
||||
console.log(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) {
|
||||
|
Loading…
Reference in New Issue
Block a user