mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 10:25:08 +01:00
Merge remote-tracking branch 'remotes/origin/AD-456-ikonotv-branded-page-for-registra' into AD-883-show-notificationsrequests-on-col
This commit is contained in:
commit
6a1f58fdb4
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);
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
import alt from '../alt';
|
||||
import OwnershipFetcher from '../fetchers/ownership_fetcher';
|
||||
|
||||
import Q from 'q';
|
||||
|
||||
class ContractListActions {
|
||||
constructor() {
|
||||
@ -15,13 +15,27 @@ 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){
|
||||
contract.public=true;
|
||||
return Q.Promise((resolve, reject) => {
|
||||
OwnershipFetcher.makeContractPublic(contract)
|
||||
.then((res) => {
|
||||
resolve(res);
|
||||
})
|
||||
.catch((err)=> {
|
||||
console.logGlobal(err);
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default alt.createActions(ContractListActions);
|
||||
|
@ -4,6 +4,7 @@ import React from 'react';
|
||||
|
||||
import Form from '../ascribe_forms/form';
|
||||
import Property from '../ascribe_forms/property';
|
||||
import InputCheckbox from '../ascribe_forms/input_checkbox';
|
||||
|
||||
import GlobalNotificationModel from '../../models/global_notification_model';
|
||||
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
||||
@ -53,7 +54,7 @@ let CreateContractForm = React.createClass({
|
||||
render() {
|
||||
return (
|
||||
<Form
|
||||
url={ApiUrls.ownership_contract}
|
||||
url={ApiUrls.ownership_contract_list}
|
||||
getFormData={this.getFormData}
|
||||
handleSuccess={this.handleCreateSuccess}
|
||||
buttons={
|
||||
@ -111,6 +112,19 @@ let CreateContractForm = React.createClass({
|
||||
placeholder="(e.g. Loan agreement #1)"
|
||||
required/>
|
||||
</Property>
|
||||
<Property
|
||||
name="public"
|
||||
className="ascribe-settings-property-collapsible-toggle"
|
||||
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>)
|
||||
</span>
|
||||
</InputCheckbox>
|
||||
</Property>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ let ActionPanel = React.createClass({
|
||||
onClick: React.PropTypes.func,
|
||||
ignoreFocus: React.PropTypes.bool
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
isFocused: false
|
||||
|
@ -8,7 +8,11 @@ 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';
|
||||
import GlobalNotificationModel from '../../models/global_notification_model';
|
||||
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
||||
|
||||
let ContractSettings = React.createClass({
|
||||
propTypes: {
|
||||
@ -27,23 +31,76 @@ 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);
|
||||
let notification = new GlobalNotificationModel("Service is unavailable", '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={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>
|
||||
|
@ -51,7 +51,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,15 @@ 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){
|
||||
return requests.put('ownership_contract', { 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) {
|
||||
@ -77,7 +78,6 @@ class Requests {
|
||||
throw new Error(`Cannot find a mapping for "${name}"`);
|
||||
}
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
@ -137,15 +137,25 @@ class Requests {
|
||||
return this.request('delete', newUrl);
|
||||
}
|
||||
|
||||
post(url, params) {
|
||||
let paramsCopy = this._merge(params);
|
||||
let newUrl = this.prepareUrl(url, paramsCopy);
|
||||
let body = null;
|
||||
_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){
|
||||
return this._putOrPost(url,params,'put')
|
||||
}
|
||||
|
||||
defaults(options) {
|
||||
|
Loading…
Reference in New Issue
Block a user