From f63a7a83ccb651470061c76f13239532d5b1ba2e Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Fri, 28 Nov 2014 15:08:01 +0100 Subject: [PATCH] Product image and description handling --- .../menu_product_component.js.coffee | 5 +++ .../modals/close_list_controller.js.coffee | 5 ++- .../supplier/app/models/product.js.coffee | 11 +++-- .../modifications/model_extensions.js.coffee | 5 +++ .../templates/components/menu-product.emblem | 27 ++++++++---- .../supplier/app/templates/menu.emblem | 4 +- .../modals/product_category_form.emblem | 18 ++++---- .../supplier/app/views/file-upload.js.coffee | 12 ++++++ .../mark_list_helped_button_view.js.coffee | 5 ++- .../user/app/templates/_list_content.emblem | 3 +- .../components/_products_menu.css.sass | 11 ++++- .../product_category_generation.feature | 24 ++++++----- ...ct_category_time_zone_availability.feature | 2 +- spec/acceptance_steps/suppliers/menu_steps.rb | 4 ++ .../suppliers/navigation_steps.rb | 3 ++ .../suppliers/product_category_steps.rb | 43 ++++++++++++++----- wip.md | 1 + 17 files changed, 132 insertions(+), 51 deletions(-) create mode 100644 app/assets/javascripts/supplier/app/views/file-upload.js.coffee create mode 100644 spec/acceptance_steps/suppliers/menu_steps.rb diff --git a/app/assets/javascripts/supplier/app/components/menu_product_component.js.coffee b/app/assets/javascripts/supplier/app/components/menu_product_component.js.coffee index 5d478091..fea85747 100644 --- a/app/assets/javascripts/supplier/app/components/menu_product_component.js.coffee +++ b/app/assets/javascripts/supplier/app/components/menu_product_component.js.coffee @@ -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') diff --git a/app/assets/javascripts/supplier/app/controllers/modals/close_list_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/modals/close_list_controller.js.coffee index dd48bda2..04ae97c4 100644 --- a/app/assets/javascripts/supplier/app/controllers/modals/close_list_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/modals/close_list_controller.js.coffee @@ -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' diff --git a/app/assets/javascripts/supplier/app/models/product.js.coffee b/app/assets/javascripts/supplier/app/models/product.js.coffee index b859c41b..e1b68e02 100644 --- a/app/assets/javascripts/supplier/app/models/product.js.coffee +++ b/app/assets/javascripts/supplier/app/models/product.js.coffee @@ -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') diff --git a/app/assets/javascripts/supplier/app/modifications/model_extensions.js.coffee b/app/assets/javascripts/supplier/app/modifications/model_extensions.js.coffee index ffe2e562..bf4e65fa 100644 --- a/app/assets/javascripts/supplier/app/modifications/model_extensions.js.coffee +++ b/app/assets/javascripts/supplier/app/modifications/model_extensions.js.coffee @@ -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 diff --git a/app/assets/javascripts/supplier/app/templates/components/menu-product.emblem b/app/assets/javascripts/supplier/app/templates/components/menu-product.emblem index 5ef63025..81daa8cf 100644 --- a/app/assets/javascripts/supplier/app/templates/components/menu-product.emblem +++ b/app/assets/javascripts/supplier/app/templates/components/menu-product.emblem @@ -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 diff --git a/app/assets/javascripts/supplier/app/templates/menu.emblem b/app/assets/javascripts/supplier/app/templates/menu.emblem index dee485be..527a6c26 100644 --- a/app/assets/javascripts/supplier/app/templates/menu.emblem +++ b/app/assets/javascripts/supplier/app/templates/menu.emblem @@ -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' diff --git a/app/assets/javascripts/supplier/app/templates/modals/product_category_form.emblem b/app/assets/javascripts/supplier/app/templates/modals/product_category_form.emblem index cc32e0ea..db66bad7 100644 --- a/app/assets/javascripts/supplier/app/templates/modals/product_category_form.emblem +++ b/app/assets/javascripts/supplier/app/templates/modals/product_category_form.emblem @@ -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 diff --git a/app/assets/javascripts/supplier/app/views/file-upload.js.coffee b/app/assets/javascripts/supplier/app/views/file-upload.js.coffee new file mode 100644 index 00000000..74541458 --- /dev/null +++ b/app/assets/javascripts/supplier/app/views/file-upload.js.coffee @@ -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]) diff --git a/app/assets/javascripts/supplier/app/views/mark_list_helped_button_view.js.coffee b/app/assets/javascripts/supplier/app/views/mark_list_helped_button_view.js.coffee index 4c57ab8a..c39c4855 100644 --- a/app/assets/javascripts/supplier/app/views/mark_list_helped_button_view.js.coffee +++ b/app/assets/javascripts/supplier/app/views/mark_list_helped_button_view.js.coffee @@ -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() diff --git a/app/assets/javascripts/user/app/templates/_list_content.emblem b/app/assets/javascripts/user/app/templates/_list_content.emblem index 0c227c45..da117288 100644 --- a/app/assets/javascripts/user/app/templates/_list_content.emblem +++ b/app/assets/javascripts/user/app/templates/_list_content.emblem @@ -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' diff --git a/app/assets/stylesheets/supplier/foundation1/components/_products_menu.css.sass b/app/assets/stylesheets/supplier/foundation1/components/_products_menu.css.sass index 9008e836..9478af14 100644 --- a/app/assets/stylesheets/supplier/foundation1/components/_products_menu.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/components/_products_menu.css.sass @@ -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 diff --git a/spec/acceptance/suppliers/product_category_generation.feature b/spec/acceptance/suppliers/product_category_generation.feature index 8912e7ab..03c74559 100644 --- a/spec/acceptance/suppliers/product_category_generation.feature +++ b/spec/acceptance/suppliers/product_category_generation.feature @@ -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 diff --git a/spec/acceptance/suppliers/product_category_time_zone_availability.feature b/spec/acceptance/suppliers/product_category_time_zone_availability.feature index 411f8d5d..fb5262c4 100644 --- a/spec/acceptance/suppliers/product_category_time_zone_availability.feature +++ b/spec/acceptance/suppliers/product_category_time_zone_availability.feature @@ -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" diff --git a/spec/acceptance_steps/suppliers/menu_steps.rb b/spec/acceptance_steps/suppliers/menu_steps.rb new file mode 100644 index 00000000..3b894727 --- /dev/null +++ b/spec/acceptance_steps/suppliers/menu_steps.rb @@ -0,0 +1,4 @@ +step "the supplier clicks on the new product category button" do + find('.new-product_category-button').click +end + diff --git a/spec/acceptance_steps/suppliers/navigation_steps.rb b/spec/acceptance_steps/suppliers/navigation_steps.rb index 303d9a79..ded0b35e 100644 --- a/spec/acceptance_steps/suppliers/navigation_steps.rb +++ b/spec/acceptance_steps/suppliers/navigation_steps.rb @@ -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 diff --git a/spec/acceptance_steps/suppliers/product_category_steps.rb b/spec/acceptance_steps/suppliers/product_category_steps.rb index ca93107f..e5235f91 100644 --- a/spec/acceptance_steps/suppliers/product_category_steps.rb +++ b/spec/acceptance_steps/suppliers/product_category_steps.rb @@ -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 diff --git a/wip.md b/wip.md index ede1684b..62a1a251 100644 --- a/wip.md +++ b/wip.md @@ -19,6 +19,7 @@ User - splash screen - ios - product variants +- remove active orders on list close Bugs ----