Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
danReynolds committed May 7, 2017
1 parent cb76ba9 commit fe2e4fc
Show file tree
Hide file tree
Showing 23 changed files with 185 additions and 70 deletions.
20 changes: 10 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
GIT
remote: git@github.com:danReynolds/ruby-tesseract-ocr.git
revision: de79ccb87fe1d4edea4ca69fc9c66dc05d87a0f5
specs:
tesseract-ocr (0.1.8)
call-me
ffi-extra
ffi-inline
iso-639

GIT
remote: https://github.com/danReynolds/ingreedy.git
revision: 9476ec6a44f8af34aeed682bd6a4807790dec2d0
Expand All @@ -21,16 +31,6 @@ GIT
oauth (~> 0.4, >= 0.4.4)
oauth2 (~> 1.0, >= 0.8.0)

GIT
remote: https://github.com/meh/ruby-tesseract-ocr.git
revision: e0180d793cda4ad487364504df099ecbd5e30b28
specs:
tesseract-ocr (0.1.8)
call-me
ffi-extra
ffi-inline
iso-639

GEM
remote: https://rubygems.org/
specs:
Expand Down
27 changes: 12 additions & 15 deletions app/assets/javascripts/components/checkout.js.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var Checkout = React.createClass({
componentDidMount: function() {
// Hack: Input fields have a dynamic method defined on turbolinks
// load by Materialize-JS that needs to be called
$('.collapsible').collapsible({ accordion: false });

document.addEventListener('turbolinks:load', setTimeout(() => (
Materialize.updateTextFields()
), 1));
Expand Down Expand Up @@ -154,30 +156,25 @@ var Checkout = React.createClass({

return (
<div className='checkout'>
<div className='card'>
<form
onSubmit={this.handleSubmit}
className='checkoutForm'>
<form
onSubmit={this.handleSubmit}
className='checkoutForm'>
<div className='card'>
<div className='card-content'>
<h3>Pay for your groceries</h3>
<div className='row'>
<div className='col l12'>
{this.renderUsers()}
</div>
</div>
<div className='totals'>
<div className='total'>Total: ${total}</div>
<div className='estimated-total'>Estimated Total: ${this.props.total}</div>
<div className='card-header'>
<h3>Payments</h3>
</div>
<PaymentList
/>
</div>
<div className='card-action'>
<input
type='submit'
value='Checkout'
className='btn'/>
</div>
</form>
</div>
</div>
</form>
</div>
);
}
Expand Down
25 changes: 25 additions & 0 deletions app/assets/javascripts/components/checkout/payment-list.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class PaymentList extends React.Component {
constructor(props) {
super(props);

this.state = {
payments: []
}
}

renderPayments() {

}

render() {
return (
<div className='payment-list'>
<ul>
<li>
<div>From</div>
</li>
</ul>
</div>
)
}
}
30 changes: 30 additions & 0 deletions app/assets/javascripts/components/item-requesters.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class ItemRequesters extends React.Component {
static propTypes = {
users: React.PropTypes.array,
requesterIds: React.PropTypes.array,
editable: React.PropTypes.bool,
index: React.PropTypes.number
}

static defaultProps = {
editable: false
}

constructor(props) {
super(props);
}

render() {
const { users, requesterIds, index } = this.props;
const requesterImages = users.filter(user => requesterIds.includes(user.id))
.map(user => {
const { id, image } = user;
return <img key={`requester-${index}-${id}`} src={image} />
});
return (
<div className='item-requesters'>
{requesterImages}
</div>
)
}
}
53 changes: 26 additions & 27 deletions app/assets/javascripts/components/itemlist.js.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,46 +190,45 @@ var ItemList = React.createClass({

renderItems: function() {
const { items: { unit_types } } = this.props;
const { users, modal: { selection } } = this.state;
const estimated = this.isEstimatedTotal();
var displayItems = this.itemsForPage(
this.state.modal.selection.reduce(function(acc, item, index) {
var requester = this.state.users.filter(function(user) {
return user.id === item.grocery_item.requester_id;
})[0];
const displayItems = this.itemsForPage(selection);

if (requester) {
acc.push({item: item, requester: requester, index: index});
}
return acc;
}.bind(this), [])
);

var itemContent = displayItems.map(function(data) {
var quantityId = "quantity-" + data.index;
var priceId = "price-" + data.index;
var unitsId = "units-" + data.index;
const { item, item: { grocery_item } } = data;
const { price, estimated_price, quantity, units } = grocery_item;
var itemContent = displayItems.map(function(displayItem, index) {
var quantityId = `quantity-${index}`;
var priceId = `price-${index}`;
var unitsId = `units-${index}`;
const { grocery_item } = displayItem;
const {
price,
estimated_price,
quantity,
units,
requester_ids
} = grocery_item;

return (
<li key={'item-' + data.index}
ref={'item-' + data.index}
data-index={data.index}
<li key={`item-${index}`}
ref={`item-${index}`}
data-index={index}
className='collection-item dismissable'>
<div ref={'collapsible-' + data.index} className='collapsible-header'>
<img src={data.requester.image} />
<div ref={`collapsible-${index}`} className='collapsible-header'>
<ItemRequesters
index={index}
requesterIds={requester_ids}
users={users} />
<p>
<strong>{data.requester.name}</strong> wants <strong>{grocery_item.display_name}</strong>
test
</p>
<div className={`badge price ${price ? 'confirmed' : ''}`}>
${parseFloat(grocery_item.price || grocery_item.estimated_price).toFixed(2)}
</div>
</div>
<ItemListEditor
<ItemListItemEditor
quantity={quantity}
price={price}
estimatedPrice={estimated_price}
id={data.index}
id={index}
units={units}
unitTypes={unit_types}
getSelectedIndex={this.getSelectedIndex}
Expand Down Expand Up @@ -270,7 +269,7 @@ var ItemList = React.createClass({
render: function() {
var content, pagination;
if (this.state.modal.loading || !this.state.modal.selection) {
content = <Loader />
content = <Loader />;
} else {
content = this.state.modal.selection.length ? this.renderItems() : this.renderNoItems();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ItemListEditor extends React.Component {
class ItemListItemEditor extends React.Component {
static propTypes = {
price: React.PropTypes.any,
estimatedPrice: React.PropTypes.any,
Expand Down Expand Up @@ -79,7 +79,7 @@ class ItemListEditor extends React.Component {
return (
<div className='itemlist-editor collapsible-body'>
<div className="valign-wrapper">
<div className="col l3 s3">
<div className="col l2 s3">
<label htmlFor={quantityId}>Quantity</label>
<input
onChange={this.handleItemFieldChange}
Expand All @@ -89,7 +89,7 @@ class ItemListEditor extends React.Component {
step="any"
value={quantity} />
</div>
<div className="col s3">
<div className="col l2 s3">
<label
className={oldPrice ? '' : 'estimated'}
htmlFor={priceId}
Expand All @@ -104,7 +104,7 @@ class ItemListEditor extends React.Component {
step="any"
value={newPrice} />
</div>
<div className="col l3 s3">
<div className="col l2 s3">
<label htmlFor={unitsId}>Units</label>
<input
ref={(input) => { this.autocomplete = input; }}
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/mixins/pagination.js.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var Pagination = {
},

itemsForPage: function(items) {
return items.splice(this.state.pageSize * this.state.pageNumber, this.state.pageSize);
return items.slice(this.state.pageSize * this.state.pageNumber, this.state.pageSize);
},

handlePageChange: function(e) {
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/components/checkout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
clear: both;
}

.card {
margin: 0;
}

ul {
max-height: 24rem;
overflow: auto;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.itemlist-editor {
.itemlist-item-editor {
.estimated {
padding: 3px;
border-radius: 2px;
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/user_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ def leave

def do_payment
Payment.create!(
payment_params.merge({
payment_params.merge(
payer_id: current_user.id,
user_group_id: @user_group.id
}.to_h)
)
)
end

Expand Down
3 changes: 2 additions & 1 deletion app/models/groceries_items.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class GroceriesItems < ApplicationRecord
include FractionalNumberToWords
belongs_to :requester, class_name: User
belongs_to :item
belongs_to :grocery
has_and_belongs_to_many :payments
has_and_belongs_to_many :requesters, class_name: User, join_table: 'groceries_items_users'

validates :price, numericality: { greater_than_or_equal_to: 0 }
validates :quantity, numericality: { greater_than_or_equal_to: 0 }
Expand Down
4 changes: 4 additions & 0 deletions app/models/groceries_items_payments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class GroceriesItemsPayments < ApplicationRecord
belongs_to :groceries_items
belongs_to :payments
end
4 changes: 4 additions & 0 deletions app/models/groceries_items_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class GroceriesItemsUsers < ApplicationRecord
belongs_to :groceries_item
belongs_to :user
end
2 changes: 2 additions & 0 deletions app/models/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class Payment < ApplicationRecord
belongs_to :grocery
belongs_to :payee, class_name: User
belongs_to :payer, class_name: User
has_many :items, through: :groceries_items
has_and_belongs_to_many :groceries_items, class_name: GroceriesItems

validates :price, numericality: { greater_than_or_equal_to: 0 }
validates_presence_of :payee, :payer, :user_group
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ class User < ApplicationRecord

has_many :grocery_payments
has_many :user_payments
has_many :requests, class_name: GroceriesItems, foreign_key: :requester_id
has_many :user_groups_users, class_name: UserGroupsUsers
has_many :user_groups, through: :user_groups_users
has_many :groceries, through: :user_groups
has_many :friends, -> { distinct }, through: :user_groups, source: :users
has_many :owned_user_groups, class_name: UserGroup, foreign_key: :owner_id
has_and_belongs_to_many :requests, class_name: GroceriesItems, join_table: 'groceries_items_users'
belongs_to :default_group, class_name: UserGroup, foreign_key: :user_group_default_id

acts_as_user roles: :admin
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/groceries_items_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class GroceriesItemsSerializer < ActiveModel::Serializer
attributes :id, :units, :display_name, :requester_id
attributes :id, :units, :display_name, :requester_ids
attribute :price do
object.price.format(symbol: false).to_f
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/groceries/checkouts/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.container.groceries-checkout
.row
.col.l10.offset-l1
.col.l12
= react_component 'Checkout', @checkout_data
8 changes: 8 additions & 0 deletions db/migrate/20170430202932_add_items_to_payments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class AddItemsToPayments < ActiveRecord::Migration[5.0]
def change
create_join_table :groceries_items, :payments do |t|
t.index :payment_id
t.index :groceries_item_id
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddMultipleRequestersToGroceriesItems < ActiveRecord::Migration[5.0]
def change
create_join_table :groceries_items, :users do |t|
t.index :user_id
t.index :groceries_item_id
end


end
end
6 changes: 6 additions & 0 deletions db/migrate/20170430231809_rename_groceries_items_columns.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class RenameGroceriesItemsColumns < ActiveRecord::Migration[5.0]
def change
rename_column :groceries_items_users, :groceries_item_id, :groceries_items_id
rename_column :groceries_items_payments, :groceries_item_id, :groceries_items_id
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class MigrateGroceriesItemsRequestersToMultipleModel < ActiveRecord::Migration[5.0]
def change
GroceriesItems.all.each do |groceries_item|
if requester_id = groceries_item.requester_id
groceries_item.requesters << User.find(requester_id)
end
end

remove_column :groceries_items, :requester_id
end
end

0 comments on commit fe2e4fc

Please sign in to comment.