Skip to content

Commit

Permalink
Merge pull request #1 from bigchaindb/feat/search-by-payload
Browse files Browse the repository at this point in the history
v0.0.2
  • Loading branch information
diminator committed Apr 30, 2016
2 parents 57fa132 + 5abde5a commit e7751d8
Show file tree
Hide file tree
Showing 20 changed files with 238 additions and 375 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dist/
downloads/
eggs/
.eggs/
node_modules
lib/
lib64/
parts/
Expand Down
54 changes: 48 additions & 6 deletions bigchaindb_common/python/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from time import sleep
from datetime import datetime

import rethinkdb as r

import cryptoconditions as cc
from decorator import contextmanager

Expand All @@ -21,16 +23,56 @@ def take_at_least_seconds(amount_in_seconds):
t_expired = datetime.now() - t_issued


def get_owned_assets(bigchain, vk):
asset_ids = bigchain.get_owned_ids(vk)
def query_reql_response(response, query):
result = list(response)

if result and len(result):
content = result[0]["transaction"]["data"]["payload"]["content"]
if content and query in content:
return result
return None


def get_owned_assets(bigchain, vk, query, table='bigchain'):
assets = []
for asset_id in asset_ids:
result = bigchain.get_transaction(asset_id['txid'] if isinstance(asset_id, dict) else asset_id)
if result:
assets.append(result)
query = query if query else ""

asset_ids = bigchain.get_owned_ids(vk)

if table == 'backlog':
reql_query = r.table(table).filter(lambda transaction: transaction['transaction']['new_owner'] == vk)

response = query_reql_response(reql_query.run(bigchain.conn), query)
if response:
assets += response

elif table == 'bigchain':
for asset_id in asset_ids:
txid = asset_id['txid'] if isinstance(asset_id, dict) else asset_id

reql_query = r.table(table)\
.concat_map(lambda doc: doc['block']['transactions']) \
.filter(lambda transaction: transaction['id'] == txid)
response = query_reql_response(reql_query.run(bigchain.conn), query)
if response:
assets += response

return assets


def get_assets(bigchain, search):
if search:
cursor = r.db('bigchain')\
.table('bigchain')\
.concat_map(lambda doc: doc["block"]["transactions"]\
.filter(lambda transaction: transaction["transaction"]["data"]["payload"]["content"].match(search))).run(bigchain.conn)
else:
cursor = r.db('bigchain') \
.table('bigchain') \
.concat_map(lambda doc: doc["block"]["transactions"]).run(bigchain.conn)
return list(cursor)


def create_asset(bigchain, to, payload):
# a create transaction uses the operation `CREATE` and has no inputs
tx = bigchain.create_transaction(bigchain.me, to, None, 'CREATE', payload=payload)
Expand Down
Binary file modified img/on_the_record_v0.0.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions on_the_record/client/js/components/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import AccountStore from '../stores/account_store';

import AscribeSpinner from '../spinner';

const AccountList = React.createClass({
const Accounts = React.createClass({
propTypes: {
activeAccount: React.PropTypes.object,
handleAccountClick: React.PropTypes.func
Expand Down Expand Up @@ -109,4 +109,4 @@ const AccountRow = React.createClass({
}
});

export default AccountList;
export default Accounts;
77 changes: 21 additions & 56 deletions on_the_record/client/js/components/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,19 @@ import { Row, Col, Button, Glyphicon } from 'react-bootstrap/lib/';
import Scroll from 'react-scroll';

import AssetActions from '../actions/asset_actions';
import AssetStore from '../stores/asset_store';

import AscribeSpinner from '../spinner';


var currentPositionY = function() {
var supportPageOffset = window.pageXOffset !== undefined;
var isCSS1Compat = ((document.compatMode || '') === 'CSS1Compat');
return supportPageOffset ? window.pageYOffset : isCSS1Compat ?
document.documentElement.scrollTop : document.body.scrollTop;
};

const Assets = React.createClass({

propTypes: {
assetList: React.PropTypes.object,
activeAccount: React.PropTypes.object
},

getInitialState: function() {
return {value: null};
return { value: null };
},

postAsset(payload) {
Expand All @@ -41,28 +34,28 @@ const Assets = React.createClass({
to: activeAccount.vk,
content: value
};
this.postAsset(payload)
this.setState({value: null});
this.postAsset(payload);
this.setState({ value: null });
Scroll.animateScroll.scrollToBottom();
},

handleInputChange(event) {
this.setState({value: event.target.value});
this.setState({ value: event.target.value });
},

render() {
const { activeAccount } = this.props;
const { assetList } = this.props;
const { value } = this.state;

return (
<div>
<AssetHistory activeAccount={activeAccount}/>
<form onSubmit={this.handleInputSubmit}>
<AssetHistory assetList={ assetList }/>
<form onSubmit={ this.handleInputSubmit }>
<input
className="navbar-fixed-bottom"
autoFocus placeholder="Type your reaction/emoji"
value={value}
onChange={this.handleInputChange}/>
autoFocus placeholder="Type what you want to share on the blockchain"
value={ value }
onChange={ this.handleInputChange }/>
</form>
</div>
);
Expand All @@ -72,44 +65,12 @@ const Assets = React.createClass({

const AssetHistory = React.createClass({
propTypes: {
activeAccount: React.PropTypes.object
},

getInitialState() {
return AssetStore.getState();
},

componentDidMount() {
AssetStore.listen(this.onChange);

this.fetchAssetList();
Scroll.animateScroll.scrollToBottom();
},

componentWillUnmount() {
AssetStore.unlisten(this.onChange);
},

fetchAssetList(){
AssetActions.flushAssetList();
const { activeAccount } = this.props;
const maxScroll = document.documentElement.scrollHeight - document.documentElement.clientHeight;
if ( activeAccount ) {
AssetActions.fetchAssetList(activeAccount.vk);

if (maxScroll - currentPositionY() < 40) {
Scroll.animateScroll.scrollToBottom();
}
}
setTimeout(this.fetchAssetList, 1000);
},

onChange(state) {
this.setState(state);
assetList: React.PropTypes.object
},

render() {
const { assetList } = this.state;
let { assetList } = this.props;
assetList = assetList ? assetList.bigchain.concat(assetList.backlog) : assetList;

if ( assetList && assetList.length > 0 ) {

Expand Down Expand Up @@ -156,20 +117,24 @@ const AssetRow = React.createClass({
render() {
const { asset } = this.props;

const inBacklog = 'assignee' in asset;

let validGlyph = inBacklog ? <Glyphicon glyph="cog"/> : <Glyphicon glyph="ok"/>;
return (
<Row>
<div className='asset-container pull-right'>
<div className='asset-container-id'>
id: {asset.id}
{ asset.id }
</div>
<div className='asset-container-detail'>
{asset.transaction.data ?
{ asset.transaction.data ?
asset.transaction.data.payload.content :
'-'
}
</div>
<div className='asset-container-timestamp pull-right'>
timestamp: {asset.transaction.timestamp}
{ new Date(parseInt(asset.transaction.timestamp, 10)*1000).toGMTString() + ' ' }
{ validGlyph }
</div>
</div>
</Row>
Expand Down
74 changes: 65 additions & 9 deletions on_the_record/client/js/components/on_the_record.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,65 @@ import React from 'react/';

import {Navbar, Row } from 'react-bootstrap/lib/';

import AccountList from './accounts';
import Scroll from 'react-scroll';

import Accounts from './accounts';
import Assets from './assets';
import Search from './search';

import AssetActions from '../actions/asset_actions';
import AssetStore from '../stores/asset_store';

import { mergeOptions } from '../utils/general_utils';

var currentPositionY = function() {
var supportPageOffset = window.pageXOffset !== undefined;
var isCSS1Compat = ((document.compatMode || '') === 'CSS1Compat');
return supportPageOffset ? window.pageYOffset : isCSS1Compat ?
document.documentElement.scrollTop : document.body.scrollTop;
};

const OnTheRecord = React.createClass({

getInitialState() {
return {
activeAccount: null
};
const assetStore = AssetStore.getState();

return mergeOptions(
{
activeAccount: null,
searchQuery: null,
},
assetStore
);
},

componentDidMount() {
AssetStore.listen(this.onChange);

this.fetchAssetList();
Scroll.animateScroll.scrollToBottom();
},

componentWillUnmount() {
AssetStore.unlisten(this.onChange);
},

fetchAssetList(){
AssetActions.flushAssetList();
const { activeAccount, searchQuery } = this.state;
const maxScroll = document.documentElement.scrollHeight - document.documentElement.clientHeight;
if ( activeAccount ) {
AssetActions.fetchAssetList({ accountToFetch: activeAccount.vk, search: searchQuery });

if (maxScroll - currentPositionY() < 40) {
Scroll.animateScroll.scrollToBottom();
}
}
setTimeout(this.fetchAssetList, 1000);
},

onChange(state) {
this.setState(state);
},

setActiveAccount(account){
Expand All @@ -21,8 +71,14 @@ const OnTheRecord = React.createClass({
});
},

handleSearch(query){
this.setState({
searchQuery: query
});
},

render() {
const { activeAccount } = this.state;
const { activeAccount, assetList, assetMeta } = this.state;

let content = (
<div className='content-text'>
Expand All @@ -33,22 +89,22 @@ const OnTheRecord = React.createClass({
if ( activeAccount ) {
content = (
<Assets
assetList={assetList}
activeAccount={activeAccount}/>
);
}

return (
<div>
<Navbar
inverse
fixedTop={true}>
<Navbar inverse fixedTop>
<h1 style={{ textAlign: 'center', color: 'white'}}>"On the Record"</h1>
</Navbar>
<div id="wrapper">
<br />
<div id="sidebar-wrapper">
<div className="sidebar-nav">
<AccountList
<Search assetMeta={assetMeta} handleSearch={this.handleSearch}/>
<Accounts
activeAccount={activeAccount}
handleAccountClick={this.setActiveAccount}/>
</div>
Expand Down
Loading

0 comments on commit e7751d8

Please sign in to comment.