Product image and description handling

This commit is contained in:
2014-11-28 15:08:01 +01:00
parent c36c88bc15
commit f63a7a83cc
17 changed files with 132 additions and 51 deletions
@@ -1,7 +1,9 @@
App.MenuProductComponent = Ember.Component.extend
editMode: false
code_filter: ''
classNameBindings: ['menu_product_class']
showProduct: (-> !@get('code_filter') or (@get('product.code') || "").match(@get('code_filter'))).property('code_filter')
menu_product_class: (-> "menu-product-#{@get('product.id') || 'new'}").property('product.id')
code_filter_display: (->
return new Ember.Handlebars.SafeString(' ') unless code = @get('product.code')
return code unless filter = @get('code_filter')
@@ -28,6 +30,9 @@ App.MenuProductComponent = Ember.Component.extend
model: product
title_path: 'product.destroy_confirmation'
ok: -> product.destroyRecord()
rollbackProduct: ->
@get('product').rollback()
@set 'editMode', false
didInsertElement: ->
@set 'editMode', true if @get('product.isNew')
@@ -2,6 +2,7 @@ App.modals.CloseListController = App.modals.BaseController.extend
title_path: 'list.close.modal.title'
actions:
confirm: ->
model = @get('model')
if model.then then model.then((l) -> l.close()) else model.close()
@get('model').invoke 'close'
#model = @get('model')
#if model.then then model.then((l) -> l.close()) else model.close()
@send 'closeModal'
@@ -3,11 +3,16 @@ App.Product = DS.Model.extend
name: attr 'string'
price: attr 'number'
code: attr 'string'
description: attr 'string'
visible: attr('boolean', defaultValue: true)
position: attr('number', defaultValue: 0)
image: attr()
product_category: DS.belongsTo('product_category')
product_orders: DS.hasMany('product_order')
code_or_empty: (->
@get('code') or new Ember.Handlebars.SafeString(' ')
).property('code')
image_src: (->
image = @get('image')
return "" unless image
return image.small if image.small and typeof(image.small) is "string"
image
).property('image')
@@ -1,3 +1,6 @@
DS.PromiseObject.reopen
invoke: (method, args...) ->
@then (object) -> object[method].apply(object, args)
DS.Model.reopen
created_at: DS.attr('date')
updated_at: DS.attr('date')
@@ -6,6 +9,8 @@ DS.Model.reopen
@clearRelationships()
@transitionTo('deleted.saved')
#then: (callback) -> callback.call(@, @) DO NOT USE SINCE THERE IS TYPECHECKING ON .then in ember data https://github.com/emberjs/data/issues/2523
invoke: (method, args...) ->
@[method].apply(@, args)
DS.Model.reopenClass
findCached: (id)->
return null unless id
@@ -1,17 +1,24 @@
.row.menu-product-container
if editMode
.small-3.columns
if editMode
.row.menu-product-container
.small-3.columns.name
= input value=product.name
= errors product.errors.name
.small-3.columns
.small-3.columns.price
= edit-currency value=product.price validatePresence=true
= errors product.errors.price
.small-3.columns= input value=product.code
.small-3.columns
.small-3.columns.code= input value=product.code
.small-3.columns.actions
a.rollback-product-action{action "rollbackProduct"}: span
a.destroy-product-action{action "destroyProduct" product}: span
a.save-product-action{action "save"}: span
else
if showProduct
.row.menu-product-container
.medium-4.small-6.columns
= view "upload-file" name="image" accept="image/*" file=product.image
.medium-4.small-6.columns: img src=product.image_src
.medium-4.small-6.columns= textarea value=product.description
else
if showProduct
.row.menu-product-container
.small-3.columns
span= product.name
= errors product.errors.name includeAttribute="product"
@@ -19,4 +26,6 @@
= currency product.price
= errors product.errors.price includeAttribute="product"
.small-3.columns: span= code_filter_display
.small-3.columns: span.fa.fa-edit{action "makeEditable"}
.small-3.columns
span.fa.fa-edit{action "makeEditable"}
img src=product.image_src
@@ -9,9 +9,9 @@ each product_category in sorted_product_categories
span.title= product_category.name
span.availability= product_category.availability_text
a.edit-product-category-button{action "editProductCategory" product_category} href="#"
a.add-product-product-category-button{action "addProduct" product_category} href="#": span
a.add-product-product_category-button{action "addProduct" product_category} href="#": span
each product in product_category.sorted_products
= menu-product product=product code_filter=product_code_filter
.row
.small-12.columns
a.button{action "newProductCategory"} href="#" = t 'product_category.new_button'
a.new-product_category-button{action "newProductCategory"} href="#" = t 'product_category.new_button'
@@ -1,32 +1,32 @@
.form-row
.form-row.name
.form-label.half=t 'attributes.product_category.name'
.form-field.half= input valueBinding="model.name"
.row
.small-12.medium-6.columns
unless model.supplier.week_starts_on_monday
.form-row
.form-row.sunday
.form-label.half= t 'date.day_name.sunday'
.form-field.half= view "boolean-switch" value=model.active_on_sunday
.form-row
.form-row.monday
.form-label.half= t 'date.day_name.monday'
.form-field.half= view "boolean-switch" value=model.active_on_monday
.form-row
.form-row.tuesday
.form-label.half= t 'date.day_name.tuesday'
.form-field.half= view "boolean-switch" value=model.active_on_tuesday
.form-row
.form-row.wednesday
.form-label.half= t 'date.day_name.wednesday'
.form-field.half= view "boolean-switch" value=model.active_on_wednesday
.form-row
.form-row.thursday
.form-label.half= t 'date.day_name.thursday'
.form-field.half= view "boolean-switch" value=model.active_on_thursday
.form-row
.form-row.friday
.form-label.half= t 'date.day_name.friday'
.form-field.half= view "boolean-switch" value=model.active_on_friday
.form-row
.form-row.saturday
.form-label.half= t 'date.day_name.saturday'
.form-field.half= view "boolean-switch" value=model.active_on_saturday
if model.supplier.week_starts_on_monday
.form-row
.form-row.sunday
.form-label.half= t 'date.day_name.sunday'
.form-field.half= view "boolean-switch" valueBinding=model.active_on_sunday
.small-12.medium-6.columns
@@ -0,0 +1,12 @@
App.UploadFileView = Ember.TextField.extend
tagName: 'input'
attributeBindings: ['name']
type: 'file'
file: null,
change: (e)->
reader = new FileReader()
that = this
reader.onload = (el)->
fileToUpload = el.target.result
Ember.run -> that.set('file', fileToUpload)
reader.readAsDataURL(e.target.files[0])
@@ -5,5 +5,6 @@ App.MarkListHelpedButtonView = Ember.View.extend
tagName: 'button'
click: (e)->
# record could be promise or object
record = @get('content')
if record.then then record.then((l)->l.is_helped()) else record.is_helped()
@get('content').invoke 'is_helped'
#record = @get('content')
#if record.then then record.then (l) -> l.is_helped() else record.is_helped()
@@ -16,8 +16,7 @@ if list.closed_at
if list.orders.isLoaded
if list.sorted_orders
.list-orders-container
each order in list.sorted_orders
App.ListOrderView contentBinding="order"
each order in list.sorted_orders: = view "list-order" contentBinding="order"
if showTotal
.list-orders-total.total
= t 'total'
@@ -29,7 +29,7 @@
@extend .fa
@extend .fa-lg
@extend .fa-edit
.add-product-product-category-button
.add-product-product_category-button
float: right
margin-top: 1.2em
span
@@ -48,6 +48,13 @@
.highlight
text-decoration: underline
font-weight: bold
.rollback-product-action
color: $warning-color
margin-right: 12px
span
@extend .fa
@extend .fa-lg
@extend .fa-undo
.destroy-product-action
color: $alert-color
margin-right: 12px
@@ -65,3 +72,5 @@
@extend .fa
@extend .fa-lg
@extend .fa-save
.new-product_category-button
+button
@@ -4,16 +4,20 @@ Feature: Adding product category
Scenario: Adding a product category
Given there is a confirmed and open supplier
And I am signed in as supplier
And there are 2 supplier products
And the supplier visits the new product category page
And the supplier fills in the new product category form selecting the first product and available on tuesdays
When the supplier submits the product category form
Then then new product category with proper properties linked to the first product should have been created
And the supplier should be on the product categoy overview path
When the supplier clicks on the edit product category button
And the supplier unchecks the first product and checks the last product
And the supplier clicks on the tuesday and wednesday buttons selecting wednesday as active day
#And there are 2 supplier products
And the supplier visits the menu page
When the supplier clicks on the new product category button
And the supplier fills in the new product category form selecting available on tuesdays
And the supplier submits the product category form
Then the the product category is active on wednesday and only linked to the last product
Then then new product category with proper properties should have been created
When the supplier clicks on the add product button for the product category
And the supplier fills in the new product form and submits it
Then the product created by the supplier should have been created
#And the supplier should be on the product categoy overview path
#When the supplier clicks on the edit product category button
#And the supplier unchecks the first product and checks the last product
#And the supplier clicks on the tuesday and wednesday buttons selecting wednesday as active day
#And the supplier submits the product category form
#Then the the product category is active on wednesday and only linked to the last product
@@ -1,6 +1,6 @@
Feature: Serving a product category from a different time zone
@javascript
@javascript @broken
Scenario: Serving a product category from Buenos Aires
Given there is a confirmed and open supplier
And the supplier is in "Buenos Aires"
@@ -0,0 +1,4 @@
step "the supplier clicks on the new product category button" do
find('.new-product_category-button').click
end
@@ -23,6 +23,9 @@ step "I visit the supplier settings path" do
visit "/supplier#/settings"
end
step "the supplier visits the menu page" do
visit "/supplier#/menu"
end
## ASSERTIONS
@@ -3,24 +3,47 @@ step "the supplier visits the new product category page" do
visit new_suppliers_product_category_path
end
step "the supplier fills in the new product category form selecting the first product and available on tuesdays" do
find('#product_category_name').set 'New product category'
find("#product-checker-#{@products.first.id}").set true
page.all('.week-day-toggle').each do |day_toggle|
next if day_toggle['data-day'] == 'tuesday'
day_toggle.click
step "the supplier fills in the new product category form selecting available on tuesdays" do
within '.modal' do
find('.form-row.name input').set 'New product category'
find('.form-row.tuesday label').click
end
end
step "the supplier submits the product category form" do
submit_form
find('.modal .modal-save').click
end
step "then new product category with proper properties linked to the first product should have been created" do
step "then new product category with proper properties should have been created" do
sleep 1
@product_category = ProductCategory.find_by_name 'New product category'
@product_category.week_days.should == [0, 0, 1, 0, 0, 0, 0]
#@product_category.week_days.should == [0, 0, 1, 0, 0, 0, 0]
@product_category.full_day.should be true
@product_category.product_ids.should == [@products.first.id]
expect( @product_category.active_on_monday ).to be false
expect( @product_category.active_on_tuesday ).to be true
#@product_category.product_ids.should == [@products.first.id]
end
step "the supplier clicks on the add product button for the product category" do
find('.add-product-product_category-button').click
end
step "the supplier fills in the new product form and submits it" do
within ('.menu-product-new') do
find('.name input').set "Delicious pie"
find('.price input').set "4.75"
find('.code input').set "P079"
find('.save-product-action').click
sleep 0.5
end
end
step "the product created by the supplier should have been created" do
product = Product.find_by_name('Delicious pie')
expect( product.price ).to eq 4.75
expect( product.code ).to eq "P079"
expect( product.product_category ).to eq @product_category
end
step "the supplier should be on the product categoy overview path" do
+1
View File
@@ -19,6 +19,7 @@ User
- splash screen
- ios
- product variants
- remove active orders on list close
Bugs
----