From 6979644af7472193ddace558896d9bdb6ecc62aa Mon Sep 17 00:00:00 2001 From: Rob H Date: Fri, 16 May 2014 11:28:02 +1000 Subject: [PATCH 01/32] Fiddle with colors and scrolling in admin enterpise sidebar --- .../stylesheets/admin/dashboard_item.css.sass | 1 + .../stylesheets/admin/sidebar-item.css.sass | 22 ++++--- .../admin/enterprises/_sidebar.html.haml | 57 ++++++++++--------- 3 files changed, 46 insertions(+), 34 deletions(-) diff --git a/app/assets/stylesheets/admin/dashboard_item.css.sass b/app/assets/stylesheets/admin/dashboard_item.css.sass index ca33dd99fb..20057764f7 100644 --- a/app/assets/stylesheets/admin/dashboard_item.css.sass +++ b/app/assets/stylesheets/admin/dashboard_item.css.sass @@ -36,6 +36,7 @@ div.dashboard_item .list max-height: 250px overflow-y: auto + overflow-x: hidden .list-title border: solid #5498da diff --git a/app/assets/stylesheets/admin/sidebar-item.css.sass b/app/assets/stylesheets/admin/sidebar-item.css.sass index e3e23f85a4..fc19154e94 100644 --- a/app/assets/stylesheets/admin/sidebar-item.css.sass +++ b/app/assets/stylesheets/admin/sidebar-item.css.sass @@ -17,10 +17,22 @@ div.sidebar_item .list max-height: 400px overflow-y: auto - - .list-item + overflow-x: hidden border: solid #5498da border-width: 0px 1px 0px 1px + &.red + color: #DA5354 + border: solid #DA5354 + border-width: 0px 3px 0px 3px + .list-item + &.odd + background-color: #fcf6ef + &:hover + background-color: #9fc820 + a + color: #DA5354 + + .list-item span.alpha font-weight: bold margin-left: -3px @@ -29,16 +41,12 @@ div.sidebar_item max-width: 160px text-overflow: ellipsis span.omega - padding: 8px 13px 8px 0px + padding: 8px 18px 8px 0px margin-right: -3px text-align: right .icon-remove-sign color: #DA5354 font-size: 18px - &.red - color: #DA5354 - border: solid #DA5354 - border-width: 0px 3px 0px 3px &.even background-color: #fff &.odd diff --git a/app/views/admin/enterprises/_sidebar.html.haml b/app/views/admin/enterprises/_sidebar.html.haml index 578612ec6f..9d226727e9 100644 --- a/app/views/admin/enterprises/_sidebar.html.haml +++ b/app/views/admin/enterprises/_sidebar.html.haml @@ -1,59 +1,62 @@ +- payment_methods_color = @payment_methods.count > 0 ? (@enterprise.payment_methods.count > 0 ? "blue" : "red") : "red" .sidebar_item.four.columns.alpha#payment_methods - .four.columns.alpha.header{ class: "#{@payment_methods.count > 0 ? "blue" : "red"}" } + .four.columns.alpha.header{ class: "#{payment_methods_color}" } %span.four.columns.alpha.centered Payment Methods - - if @payment_methods.count > 0 - .four.columns.alpha.list + .four.columns.alpha.list{ class: "#{payment_methods_color}" } + - if @payment_methods.count > 0 - @payment_methods.each do |payment_method| %a.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{edit_admin_payment_method_path(payment_method)}" } %span.three.columns.alpha = payment_method.name %span.one.column.omega = f.check_box :payment_method_ids, { :multiple => true }, payment_method.id, nil - - else - .four.columns.alpha.list-item.red - %span.three.columns.alpha None Available - %span.one.column.omega - %span.icon-remove-sign - %a.four.columns.alpha.button{ href: "#{new_admin_payment_method_path}", class: "#{@payment_methods.count > 0 ? "blue" : "red"}" } + - else + .four.columns.alpha.list-item + %span.three.columns.alpha None Available + %span.one.column.omega + %span.icon-remove-sign + %a.four.columns.alpha.button{ href: "#{new_admin_payment_method_path}", class: "#{payment_methods_color}" } CREATE NEW %span.icon-arrow-right +- shipping_methods_color = @shipping_methods.count > 0 ? (@enterprise.shipping_methods.count > 0 ? "blue" : "red") : "red" .sidebar_item.four.columns.alpha#shipping_methods - .four.columns.alpha.header{ class: "#{@shipping_methods.count > 0 ? "blue" : "red"}" } + .four.columns.alpha.header{ class: "#{shipping_methods_color}" } %span.four.columns.alpha.centered Shipping Methods - - if @shipping_methods.count > 0 - .four.columns.alpha.list + .four.columns.alpha.list{ class: "#{shipping_methods_color}" } + - if @shipping_methods.count > 0 - @shipping_methods.each do |shipping_method| %a.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{edit_admin_shipping_method_path(shipping_method)}" } %span.three.columns.alpha = shipping_method.name %span.one.column.omega = f.check_box :shipping_method_ids, { :multiple => true }, shipping_method.id, nil - - else - .four.columns.alpha.list-item.red - %span.three.columns.alpha None Available - %span.one.column.omega - %span.icon-remove-sign - %a.four.columns.alpha.button{ href: "#{new_admin_shipping_method_path}", class: "#{@payment_methods.count > 0 ? "blue" : "red"}" } + - else + .four.columns.alpha.list-item + %span.three.columns.alpha None Available + %span.one.column.omega + %span.icon-remove-sign + %a.four.columns.alpha.button{ href: "#{new_admin_shipping_method_path}", class: "#{shipping_methods_color}" } CREATE NEW %span.icon-arrow-right +- enterprise_fees_color = @enterprise_fees.count > 0 ? "blue" : "red" .sidebar_item.four.columns.alpha#enterprise_fees - .four.columns.alpha.header{ class: "#{@enterprise_fees.count > 0 ? "blue" : "red"}" } + .four.columns.alpha.header{ class: "#{enterprise_fees_color}" } %span.four.columns.alpha.centered Enterprise Fees - - if @enterprise_fees.count > 0 - .four.columns.alpha.list + .four.columns.alpha.list{ class: "#{enterprise_fees_color}" } + - if @enterprise_fees.count > 0 - @enterprise_fees.each do |enterprise_fee| %a.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.admin_enterprise_fees_path}" } %span.three.columns.alpha = enterprise_fee.name %span.one.column.omega   - - else - .four.columns.alpha.list-item.red - %span.three.columns.alpha None Available - %span.one.column.omega - %span.icon-remove-sign - %a.four.columns.alpha.button{ href: "#{main_app.admin_enterprise_fees_path}", class: "#{@enterprise_fees.count > 0 ? "blue" : "red"}" } + - else + .four.columns.alpha.list-item.red + %span.three.columns.alpha None Available + %span.one.column.omega + %span.icon-remove-sign + %a.four.columns.alpha.button{ href: "#{main_app.admin_enterprise_fees_path}", class: "#{enterprise_fees_color}" } CREATE NEW %span.icon-arrow-right \ No newline at end of file From 03139cd2deb43e00bb8566a3e4245c713cee0a1a Mon Sep 17 00:00:00 2001 From: Rob H Date: Fri, 16 May 2014 11:42:40 +1000 Subject: [PATCH 02/32] Use existing sidebar content_for --- app/views/admin/enterprises/edit.html.haml | 2 +- app/views/admin/enterprises/new.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/enterprises/edit.html.haml b/app/views/admin/enterprises/edit.html.haml index f0f9c91fd1..534c2b0542 100644 --- a/app/views/admin/enterprises/edit.html.haml +++ b/app/views/admin/enterprises/edit.html.haml @@ -8,7 +8,7 @@ .eleven.columns.alpha = render :partial => 'form', :locals => { :f => f } .one.column   - .four.columns.omega + - content_for :sidebar do = render :partial => 'sidebar', :locals => { :f => f } .twelve.columns.alpha = render :partial => 'spree/admin/shared/edit_resource_links' diff --git a/app/views/admin/enterprises/new.html.haml b/app/views/admin/enterprises/new.html.haml index 9293cd3530..f738d33dc2 100644 --- a/app/views/admin/enterprises/new.html.haml +++ b/app/views/admin/enterprises/new.html.haml @@ -7,7 +7,7 @@ .eleven.columns.alpha = render :partial => 'form', :locals => { :f => f } .one.column   - .four.columns.omega + - content_for :sidebar do = render :partial => 'sidebar', :locals => { :f => f } .twelve.columns.alpha -# Save, Save & Close and Cancel button From 2b414d99e1812ab4592949c68cc5348d679e9468 Mon Sep 17 00:00:00 2001 From: Rob H Date: Fri, 16 May 2014 15:12:47 +1000 Subject: [PATCH 03/32] Revert content_for changes --- app/views/admin/enterprises/edit.html.haml | 2 +- app/views/admin/enterprises/new.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/enterprises/edit.html.haml b/app/views/admin/enterprises/edit.html.haml index 534c2b0542..f0f9c91fd1 100644 --- a/app/views/admin/enterprises/edit.html.haml +++ b/app/views/admin/enterprises/edit.html.haml @@ -8,7 +8,7 @@ .eleven.columns.alpha = render :partial => 'form', :locals => { :f => f } .one.column   - - content_for :sidebar do + .four.columns.omega = render :partial => 'sidebar', :locals => { :f => f } .twelve.columns.alpha = render :partial => 'spree/admin/shared/edit_resource_links' diff --git a/app/views/admin/enterprises/new.html.haml b/app/views/admin/enterprises/new.html.haml index f738d33dc2..9293cd3530 100644 --- a/app/views/admin/enterprises/new.html.haml +++ b/app/views/admin/enterprises/new.html.haml @@ -7,7 +7,7 @@ .eleven.columns.alpha = render :partial => 'form', :locals => { :f => f } .one.column   - - content_for :sidebar do + .four.columns.omega = render :partial => 'sidebar', :locals => { :f => f } .twelve.columns.alpha -# Save, Save & Close and Cancel button From 3bf21d42dd2b3a826926244e26f6a6b5a7d7e236 Mon Sep 17 00:00:00 2001 From: Rob H Date: Wed, 21 May 2014 15:02:59 +1000 Subject: [PATCH 04/32] WIP: removing all payment methods from enterprise edit page --- app/views/admin/enterprises/_sidebar.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/admin/enterprises/_sidebar.html.haml b/app/views/admin/enterprises/_sidebar.html.haml index 9d226727e9..0390cb289a 100644 --- a/app/views/admin/enterprises/_sidebar.html.haml +++ b/app/views/admin/enterprises/_sidebar.html.haml @@ -4,12 +4,13 @@ %span.four.columns.alpha.centered Payment Methods .four.columns.alpha.list{ class: "#{payment_methods_color}" } - if @payment_methods.count > 0 + -# = hidden_field_tag "enterprise[payment_method_ids][]", [] - @payment_methods.each do |payment_method| %a.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{edit_admin_payment_method_path(payment_method)}" } %span.three.columns.alpha = payment_method.name %span.one.column.omega - = f.check_box :payment_method_ids, { :multiple => true }, payment_method.id, nil + = f.check_box :payment_method_ids, { multiple: true }, payment_method.id, nil - else .four.columns.alpha.list-item %span.three.columns.alpha None Available From ed3c23cd90bf3520daa21c737a81ca5df143499e Mon Sep 17 00:00:00 2001 From: Rob H Date: Thu, 22 May 2014 15:28:25 +1000 Subject: [PATCH 05/32] Split 'My Enterprises' dashboard item into Hubs and Producers --- .../enterprises_dashboard.js.coffee | 5 + .../stylesheets/admin/dashboard_item.css.sass | 52 ++++++++- app/models/enterprise.rb | 8 ++ app/models/spree/product_decorator.rb | 6 + .../admin/overview/_enterprises.html.haml | 105 ++++++++++++------ spec/models/enterprise_spec.rb | 10 ++ spec/models/spree/product_spec.rb | 14 +++ 7 files changed, 160 insertions(+), 40 deletions(-) create mode 100644 app/assets/javascripts/admin/controllers/enterprises_dashboard.js.coffee diff --git a/app/assets/javascripts/admin/controllers/enterprises_dashboard.js.coffee b/app/assets/javascripts/admin/controllers/enterprises_dashboard.js.coffee new file mode 100644 index 0000000000..b506c69ecd --- /dev/null +++ b/app/assets/javascripts/admin/controllers/enterprises_dashboard.js.coffee @@ -0,0 +1,5 @@ +Admin.controller "enterprisesDashboard", [ + "$scope" + ($scope) -> + $scope.activeTab = "hubs" +] \ No newline at end of file diff --git a/app/assets/stylesheets/admin/dashboard_item.css.sass b/app/assets/stylesheets/admin/dashboard_item.css.sass index 20057764f7..908fb64e6b 100644 --- a/app/assets/stylesheets/admin/dashboard_item.css.sass +++ b/app/assets/stylesheets/admin/dashboard_item.css.sass @@ -4,7 +4,23 @@ div.dashboard_item .centered text-align: center + .text-icon + margin-top: 7px + display: block + font-size: 16px + font-weight: bold + color: #fff + padding: 0px 6px + border-radius: 10px + &.green + background-color: #9fc820 + &.red + background-color: #DA5354 + &.orange + background-color: #DA7F52 + div.header + height: 50px border-radius: 6px 6px 0px 0px border: 1px solid #5498da position: relative @@ -26,12 +42,36 @@ div.dashboard_item h3 color: #DA7F52 - h3 - padding: 10px 5px 10px 3% + h3.alpha + height: 100% + padding: 10px 5px 0px 3% a border-radius: 0px 4px 0px 0px margin-left: 8px + height: 100% + padding: 15px 2px 0px 2px + + .tabs + height: 30px + border: solid #5498da + border-width: 0px 0px 1px 0px + margin-top: 3px + div.dashboard_tab + cursor: pointer + height: 30px + color: #fff + background-color: #5498da + padding: 5px 5px 0px 5px + text-align: center + font-weight: bold + border: solid #5498da + border-width: 1px 1px 0px 1px + &:hover + background-color: #9fc820 + &.selected + color: #5498da + background-color: #fff .list max-height: 250px @@ -95,10 +135,13 @@ div.dashboard_item color: #fff .icon-ok-sign color: #fff + .text-icon + &.green + color: #9fc820 + background-color: #fff a.button color: #fff - padding: 15px 15px font-size: 110% font-weight: bold text-align: center @@ -111,4 +154,5 @@ div.dashboard_item &:hover background-color: #9fc820 &.bottom - border-radius: 0px 0px 6px 6px \ No newline at end of file + border-radius: 0px 0px 6px 6px + padding: 15px 15px \ No newline at end of file diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index a72c6fdbd6..0b700ba596 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -123,6 +123,14 @@ class Enterprise < ActiveRecord::Base self.supplied_products.where('count_on_hand > 0').present? end + def supplied_and_active_products_on_hand + self.supplied_products.where('spree_products.count_on_hand > 0').active + end + + def active_products_in_order_cycles + self.supplied_and_active_products_on_hand.in_an_active_order_cycle + end + def to_param "#{id}-#{name.parameterize}" end diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 282a93cfb5..622bef3f43 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -75,6 +75,12 @@ Spree::Product.class_eval do scope :in_order_cycle, lambda { |order_cycle| with_order_cycles_inner. merge(Exchange.outgoing). where('order_cycles.id = ?', order_cycle) } + + scope :in_an_active_order_cycle, lambda { with_order_cycles_inner. + merge(OrderCycle.active). + merge(Exchange.outgoing). + where('order_cycles.id IS NOT NULL') } + scope :managed_by, lambda { |user| if user.has_spree_role?('admin') scoped diff --git a/app/views/spree/admin/overview/_enterprises.html.haml b/app/views/spree/admin/overview/_enterprises.html.haml index 4042381502..d8e7b54cb7 100644 --- a/app/views/spree/admin/overview/_enterprises.html.haml +++ b/app/views/spree/admin/overview/_enterprises.html.haml @@ -1,11 +1,15 @@ -%div.dashboard_item.sixteen.columns.alpha#enterprises +%div.dashboard_item.sixteen.columns.alpha#enterprises{ 'ng-app' => 'ofn.admin', 'ng-controller' => "enterprisesDashboard" } %div.header.sixteen.columns.alpha{ :class => "#{@enterprises.count > 0 ? "" : "red"}"} %h3.thirteen.columns.alpha My Enterprises - if @enterprises.any? - %a.three.columns.omega.icon-plus.button.blue{ href: "#{main_app.new_admin_enterprise_path}" } + %a.three.columns.omega.icon-plus.button.blue.white-bottom{ href: "#{main_app.new_admin_enterprise_path}" } CREATE NEW - else %a.with-tip{ title: "Enterprises are Producers and/or Hubs and are the basic unit of organisation within the Open Food Network." } What's this? + - if @enterprises.any? + %div.sixteen.columns.alpha.tabs + %div.dashboard_tab.eight.columns.alpha.blue{ ng: { class: "{selected: activeTab == 'hubs'}", click: "activeTab = 'hubs'" } } HUBS + %div.dashboard_tab.eight.columns.omega.blue{ ng: { class: "{selected: activeTab == 'producers'}", click: "activeTab = 'producers'" } } PRODUCERS - if @enterprises.empty? %div.sixteen.columns.alpha.list-item.red %span.text.fifteen.columns.alpha You don't have any enterprises yet. @@ -15,40 +19,69 @@ CREATE A NEW ENTERPRISE %span.icon-arrow-right - else - %div.sixteen.columns.alpha.list-title - %span.five.columns.alpha Name - %span.centered.three.columns Payment Methods - %span.centered.three.columns Shipping Methods - %span.centered.three.columns Enterprise Fees - %div.sixteen.columns.alpha.list - - @enterprises.each do |enterprise| - %a.sixteen.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.edit_admin_enterprise_path(enterprise)}" } - %span.five.columns.alpha - = enterprise.name - %span.symbol.three.columns.centered - - payment_method_count = enterprise.payment_methods.count - - if payment_method_count < 1 && enterprise.is_distributor - %span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no Payment Methods" } - - elsif enterprise.is_primary_producer - %span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require Payment Methods." } - - else - %span.icon-ok-sign.with-tip{ title: "#{payment_method_count} Payment Method#{payment_method_count > 1 ? "s" : ""}" } - %span.symbol.three.columns.centered - - shipping_method_count = enterprise.shipping_methods.count - - if shipping_method_count < 1 && enterprise.is_distributor - %span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no Shipping Methods" } - - elsif enterprise.is_primary_producer - %span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require Shipping Methods." } - -else - %span.icon-ok-sign.with-tip{ title: "#{shipping_method_count} Shipping Method#{shipping_method_count > 1 ? "s" : ""}" } - %span.symbol.three.columns.centered - - fee_count = enterprise.enterprise_fees.count - - if fee_count > 0 - %span.icon-ok-sign.with-tip{ title: "#{fee_count} Fee#{fee_count > 1 ? "s" : ""}" } - - else - %span.icon-warning-sign.with-tip{ title: "#{enterprise.name} has no Enterprise Fees" } - %span.two.columns.omega.right - %span.icon-arrow-right + %div.hubs_tab{ ng: { show: "activeTab == 'hubs'"} } + %div.sixteen.columns.alpha.list-title + %span.five.columns.alpha Name + %span.centered.three.columns Payment Methods + %span.centered.three.columns Shipping Methods + %span.centered.three.columns Enterprise Fees + %div.sixteen.columns.alpha.list + - @enterprises.is_distributor.each do |enterprise| + %a.sixteen.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.edit_admin_enterprise_path(enterprise)}" } + %span.five.columns.alpha + = enterprise.name + %span.symbol.three.columns.centered + - payment_method_count = enterprise.payment_methods.count + - if payment_method_count < 1 && enterprise.is_distributor + %span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no Payment Methods" } + - elsif enterprise.is_primary_producer + %span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require Payment Methods." } + - else + %span.icon-ok-sign.with-tip{ title: "#{payment_method_count} Payment Method#{payment_method_count > 1 ? "s" : ""}" } + %span.symbol.three.columns.centered + - shipping_method_count = enterprise.shipping_methods.count + - if shipping_method_count < 1 && enterprise.is_distributor + %span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no Shipping Methods" } + - elsif enterprise.is_primary_producer + %span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require Shipping Methods." } + -else + %span.icon-ok-sign.with-tip{ title: "#{shipping_method_count} Shipping Method#{shipping_method_count > 1 ? "s" : ""}" } + %span.symbol.three.columns.centered + - fee_count = enterprise.enterprise_fees.count + - if fee_count > 0 + %span.icon-ok-sign.with-tip{ title: "#{fee_count} Fee#{fee_count > 1 ? "s" : ""}" } + - else + %span.icon-warning-sign.with-tip{ title: "#{enterprise.name} has no Enterprise Fees" } + %span.two.columns.omega.right + %span.icon-arrow-right + %div.producers_tab{ ng: { show: "activeTab == 'producers'"} } + %div.list-title.sixteen.columns.alpha + %span.five.columns.alpha Name + %span.centered.three.columns Total Products + %span.centered.three.columns Active Products + %span.centered.three.columns Products in OCs + %div.sixteen.columns.alpha.list + - @enterprises.is_primary_producer.each do |enterprise| + %a.sixteen.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.edit_admin_enterprise_path(enterprise)}" } + %span.five.columns.alpha + = enterprise.name + %span.symbol.three.columns.centered + %span.one.column.alpha   + %span.text-icon.one.column.centered{ class: "#{enterprise.supplied_products.not_deleted.count > 0 ? "green" : "red" }" } + = enterprise.supplied_products.not_deleted.count + %span.one.column.omega   + %span.symbol.three.columns.centered + %span.one.column.alpha   + %span.text-icon.one.column.centered{ class: "#{enterprise.supplied_and_active_products_on_hand.count > 0 ? "green" : "red" }" } + = enterprise.supplied_and_active_products_on_hand.count + %span.one.column.omega   + %span.symbol.three.columns.centered + %span.one.column.alpha   + %span.text-icon.one.column.centered{ class: "#{enterprise.active_products_in_order_cycles.count > 0 ? "green" : "orange" }" } + = enterprise.active_products_in_order_cycles.count + %span.one.column.omega   + %span.two.columns.omega.right + %span.icon-arrow-right %a.sixteen.columns.alpha.button.bottom.blue{ href: "#{main_app.admin_enterprises_path}" } MANAGE MY ENTERPRISES %span.icon-arrow-right \ No newline at end of file diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 06c4c0850e..6cf933fdd6 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -338,6 +338,16 @@ describe Enterprise do end end + describe "supplied_and_active_products_on_hand" do + it "find only active products which are in stock" do + supplier = create(:supplier_enterprise) + inactive_product = create(:product, supplier: supplier, on_hand: 1, available_on: Date.tomorrow) + out_of_stock_product = create(:product, supplier: supplier, on_hand: 0, available_on: Date.yesterday) + p1 = create(:product, supplier: supplier, on_hand: 1, available_on: Date.yesterday) + supplier.supplied_and_active_products_on_hand.should == [p1] + end + end + describe "finding variants distributed by the enterprise" do it "finds the master variant" do d = create(:distributor_enterprise) diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 6743e404e9..aa37070598 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -230,6 +230,20 @@ module Spree end end + describe "in_an_active_order_cycle" do + it "shows products in order cycle distribution" do + s = create(:supplier_enterprise) + d2 = create(:distributor_enterprise) + d3 = create(:distributor_enterprise) + p1 = create(:product) + p2 = create(:product) + p3 = create(:product) + oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.master], orders_close_at: 1.day.ago) + oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d3], variants: [p3.master], orders_close_at: Date.tomorrow) + Product.in_an_active_order_cycle.should == [p3] + end + end + describe "access roles" do before(:each) do @e1 = create(:enterprise) From 371240652c9fc150263449732ea1b14c9eb266f3 Mon Sep 17 00:00:00 2001 From: Rob H Date: Thu, 22 May 2014 15:30:11 +1000 Subject: [PATCH 06/32] Change 'Overview' menu item to 'Dashboard' --- app/views/spree/admin/shared/_tabs.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/spree/admin/shared/_tabs.html.erb b/app/views/spree/admin/shared/_tabs.html.erb index ab66dbf1de..2228d4ac7b 100644 --- a/app/views/spree/admin/shared/_tabs.html.erb +++ b/app/views/spree/admin/shared/_tabs.html.erb @@ -1,4 +1,4 @@ -<%= tab :overview, :route => :admin, :icon => 'icon-dashboard' %> +<%= tab :dashboard, :route => :admin, :icon => 'icon-dashboard' %> <%= tab :orders, :payments, :creditcard_payments, :shipments, :credit_cards, :return_authorizations, :url => admin_orders_path('q[s]' => 'completed_at desc'), :icon => 'icon-shopping-cart' %> <%= tab :products , :option_types, :properties, :prototypes, :variants, :product_properties, :taxons, :url => bulk_edit_admin_products_path, :icon => 'icon-th-large' %> <%= tab :reports, :icon => 'icon-file' %> From f8776fecffc522857b6849ebcf1d82e8672ac8e7 Mon Sep 17 00:00:00 2001 From: Rob H Date: Thu, 22 May 2014 15:46:26 +1000 Subject: [PATCH 07/32] Move enterprises dashboard controller --- ...ard.js.coffee => enterprises_dashboard_controller.js.coffee} | 2 +- app/views/spree/admin/overview/_enterprises.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/assets/javascripts/admin/controllers/{enterprises_dashboard.js.coffee => enterprises_dashboard_controller.js.coffee} (53%) diff --git a/app/assets/javascripts/admin/controllers/enterprises_dashboard.js.coffee b/app/assets/javascripts/admin/controllers/enterprises_dashboard_controller.js.coffee similarity index 53% rename from app/assets/javascripts/admin/controllers/enterprises_dashboard.js.coffee rename to app/assets/javascripts/admin/controllers/enterprises_dashboard_controller.js.coffee index b506c69ecd..b9584b74cc 100644 --- a/app/assets/javascripts/admin/controllers/enterprises_dashboard.js.coffee +++ b/app/assets/javascripts/admin/controllers/enterprises_dashboard_controller.js.coffee @@ -1,4 +1,4 @@ -Admin.controller "enterprisesDashboard", [ +Admin.controller "enterprisesDashboardCtrl", [ "$scope" ($scope) -> $scope.activeTab = "hubs" diff --git a/app/views/spree/admin/overview/_enterprises.html.haml b/app/views/spree/admin/overview/_enterprises.html.haml index d8e7b54cb7..85dc93c2ee 100644 --- a/app/views/spree/admin/overview/_enterprises.html.haml +++ b/app/views/spree/admin/overview/_enterprises.html.haml @@ -1,4 +1,4 @@ -%div.dashboard_item.sixteen.columns.alpha#enterprises{ 'ng-app' => 'ofn.admin', 'ng-controller' => "enterprisesDashboard" } +%div.dashboard_item.sixteen.columns.alpha#enterprises{ 'ng-app' => 'ofn.admin', 'ng-controller' => "enterprisesDashboardCtrl" } %div.header.sixteen.columns.alpha{ :class => "#{@enterprises.count > 0 ? "" : "red"}"} %h3.thirteen.columns.alpha My Enterprises - if @enterprises.any? From 47f6d32055009b0f92eb26a8cd209d220c03272a Mon Sep 17 00:00:00 2001 From: Rob H Date: Thu, 22 May 2014 15:47:50 +1000 Subject: [PATCH 08/32] Make list items the same height --- app/assets/stylesheets/admin/dashboard_item.css.sass | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/admin/dashboard_item.css.sass b/app/assets/stylesheets/admin/dashboard_item.css.sass index 908fb64e6b..e24d60b277 100644 --- a/app/assets/stylesheets/admin/dashboard_item.css.sass +++ b/app/assets/stylesheets/admin/dashboard_item.css.sass @@ -5,7 +5,7 @@ div.dashboard_item text-align: center .text-icon - margin-top: 7px + margin-top: 8px display: block font-size: 16px font-weight: bold @@ -91,10 +91,11 @@ div.dashboard_item .list-item border: solid #5498da border-width: 0px 1px 0px 1px + height: 38px span.alpha font-weight: bold margin-left: -3px - padding: 10px 2px 10px 5% + padding: 10px 2px 0px 5% span.omega padding-right: 13px margin-right: -3px From e85c144e873ee61d63fc1c29a3272d05d11d97fe Mon Sep 17 00:00:00 2001 From: Rob H Date: Fri, 23 May 2014 11:22:12 +1000 Subject: [PATCH 09/32] Remove reference to 'Admin' from global namespace --- app/assets/javascripts/admin/admin.js.coffee | 2 +- app/assets/javascripts/admin/bulk_order_management.js.coffee | 2 +- app/assets/javascripts/admin/bulk_product_update.js.coffee | 2 +- .../controllers/enterprises_dashboard_controller.js.coffee | 2 +- .../javascripts/admin/directives/confirm_link_path.js.coffee | 2 +- .../javascripts/admin/directives/confirm_model_change.js.coffee | 2 +- app/assets/javascripts/admin/directives/date_picker.js.coffee | 2 +- .../javascripts/admin/directives/datetime_picker.js.coffee | 2 +- app/assets/javascripts/admin/directives/decimal.js.coffee | 2 +- .../javascripts/admin/directives/line_item_upd_attr.js.coffee | 2 +- .../javascripts/admin/directives/select2_min_search.js.coffee | 2 +- .../javascripts/admin/directives/taxon_autocomplete.js.coffee | 2 +- app/assets/javascripts/admin/directives/toggle_column.js.coffee | 2 +- .../javascripts/admin/directives/toggle_variants.js.coffee | 2 +- app/assets/javascripts/admin/directives/track_product.js.coffee | 2 +- app/assets/javascripts/admin/directives/track_variant.js.coffee | 2 +- app/assets/javascripts/admin/filters/range_array.js.coffee | 2 +- app/assets/javascripts/admin/filters/select_filter.js.coffee | 2 +- app/assets/javascripts/admin/filters/variant_filter.js.coffee | 2 +- app/assets/javascripts/admin/services/blank_option.js.coffee | 2 +- app/assets/javascripts/admin/services/confirm_handler.js.coffee | 2 +- app/assets/javascripts/admin/services/data_fetcher.js.coffee | 2 +- app/assets/javascripts/admin/services/data_submitter.js.coffee | 2 +- app/assets/javascripts/admin/services/dirty_products.js.coffee | 2 +- app/assets/javascripts/admin/services/pending_changes.js.coffee | 2 +- app/assets/javascripts/admin/services/switch_class.js.coffee | 2 +- app/assets/javascripts/admin/services/taxons.js.coffee | 2 +- 27 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app/assets/javascripts/admin/admin.js.coffee b/app/assets/javascripts/admin/admin.js.coffee index ba07bb7933..cf88326ba5 100644 --- a/app/assets/javascripts/admin/admin.js.coffee +++ b/app/assets/javascripts/admin/admin.js.coffee @@ -1,3 +1,3 @@ -window.Admin = angular.module("ofn.admin", ["ngResource","ofn.dropdown"]).config ($httpProvider) -> +angular.module("ofn.admin", ["ngResource","ofn.dropdown"]).config ($httpProvider) -> $httpProvider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content") $httpProvider.defaults.headers.common["Accept"] = "application/json, text/javascript, */*" \ No newline at end of file diff --git a/app/assets/javascripts/admin/bulk_order_management.js.coffee b/app/assets/javascripts/admin/bulk_order_management.js.coffee index 7a1edcbca6..9ba34790a8 100644 --- a/app/assets/javascripts/admin/bulk_order_management.js.coffee +++ b/app/assets/javascripts/admin/bulk_order_management.js.coffee @@ -1,4 +1,4 @@ -Admin.controller "AdminOrderMgmtCtrl", [ +angular.module("ofn.admin").controller "AdminOrderMgmtCtrl", [ "$scope", "$http", "dataFetcher", "blankOption", "pendingChanges" ($scope, $http, dataFetcher, blankOption, pendingChanges) -> diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index 4df57d6689..8d50a3dc1f 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -1,4 +1,4 @@ -Admin.controller "AdminProductEditCtrl", [ +angular.module("ofn.admin").controller "AdminProductEditCtrl", [ "$scope", "$timeout", "$http", "dataFetcher", "DirtyProducts" ($scope, $timeout, $http, dataFetcher, DirtyProducts) -> $scope.updateStatusMessage = diff --git a/app/assets/javascripts/admin/controllers/enterprises_dashboard_controller.js.coffee b/app/assets/javascripts/admin/controllers/enterprises_dashboard_controller.js.coffee index b9584b74cc..ad72ff3529 100644 --- a/app/assets/javascripts/admin/controllers/enterprises_dashboard_controller.js.coffee +++ b/app/assets/javascripts/admin/controllers/enterprises_dashboard_controller.js.coffee @@ -1,4 +1,4 @@ -Admin.controller "enterprisesDashboardCtrl", [ +angular.module("ofn.admin").controller "enterprisesDashboardCtrl", [ "$scope" ($scope) -> $scope.activeTab = "hubs" diff --git a/app/assets/javascripts/admin/directives/confirm_link_path.js.coffee b/app/assets/javascripts/admin/directives/confirm_link_path.js.coffee index e0e0511f0c..2c8dba4baf 100644 --- a/app/assets/javascripts/admin/directives/confirm_link_path.js.coffee +++ b/app/assets/javascripts/admin/directives/confirm_link_path.js.coffee @@ -1,4 +1,4 @@ -Admin.directive "ofnConfirmLinkPath", (ofnConfirmHandler) -> +angular.module("ofn.admin").directive "ofnConfirmLinkPath", (ofnConfirmHandler) -> restrict: "A" scope: path: "@ofnConfirmLinkPath" diff --git a/app/assets/javascripts/admin/directives/confirm_model_change.js.coffee b/app/assets/javascripts/admin/directives/confirm_model_change.js.coffee index aba2cd919e..a0b5272981 100644 --- a/app/assets/javascripts/admin/directives/confirm_model_change.js.coffee +++ b/app/assets/javascripts/admin/directives/confirm_model_change.js.coffee @@ -1,4 +1,4 @@ -Admin.directive "ofnConfirmModelChange", (ofnConfirmHandler,$timeout) -> +angular.module("ofn.admin").directive "ofnConfirmModelChange", (ofnConfirmHandler,$timeout) -> restrict: "A" link: (scope, element, attrs) -> handler = ofnConfirmHandler scope, -> scope.fetchOrders() diff --git a/app/assets/javascripts/admin/directives/date_picker.js.coffee b/app/assets/javascripts/admin/directives/date_picker.js.coffee index 3a07bfd3f5..6b5cac3e1b 100644 --- a/app/assets/javascripts/admin/directives/date_picker.js.coffee +++ b/app/assets/javascripts/admin/directives/date_picker.js.coffee @@ -1,4 +1,4 @@ -Admin.directive "datepicker", -> +angular.module("ofn.admin").directive "datepicker", -> require: "ngModel" link: (scope, element, attrs, ngModel) -> element.datepicker diff --git a/app/assets/javascripts/admin/directives/datetime_picker.js.coffee b/app/assets/javascripts/admin/directives/datetime_picker.js.coffee index 232d958b99..b0d91e538a 100644 --- a/app/assets/javascripts/admin/directives/datetime_picker.js.coffee +++ b/app/assets/javascripts/admin/directives/datetime_picker.js.coffee @@ -1,4 +1,4 @@ -Admin.directive "datetimepicker", -> +angular.module("ofn.admin").directive "datetimepicker", -> require: "ngModel" link: (scope, element, attrs, ngModel) -> element.datetimepicker diff --git a/app/assets/javascripts/admin/directives/decimal.js.coffee b/app/assets/javascripts/admin/directives/decimal.js.coffee index 8077f90c06..f4bed8e371 100644 --- a/app/assets/javascripts/admin/directives/decimal.js.coffee +++ b/app/assets/javascripts/admin/directives/decimal.js.coffee @@ -1,4 +1,4 @@ -Admin.directive "ofnDecimal", -> +angular.module("ofn.admin").directive "ofnDecimal", -> require: "ngModel" link: (scope, element, attrs, ngModel) -> numRegExp = /^\d+(\.\d+)?$/ diff --git a/app/assets/javascripts/admin/directives/line_item_upd_attr.js.coffee b/app/assets/javascripts/admin/directives/line_item_upd_attr.js.coffee index a71aa42997..c83d7fdc0f 100644 --- a/app/assets/javascripts/admin/directives/line_item_upd_attr.js.coffee +++ b/app/assets/javascripts/admin/directives/line_item_upd_attr.js.coffee @@ -1,4 +1,4 @@ -Admin.directive "ofnLineItemUpdAttr", [ +angular.module("ofn.admin").directive "ofnLineItemUpdAttr", [ "switchClass", "pendingChanges" (switchClass, pendingChanges) -> require: "ngModel" diff --git a/app/assets/javascripts/admin/directives/select2_min_search.js.coffee b/app/assets/javascripts/admin/directives/select2_min_search.js.coffee index c33beb710e..1d55d886aa 100644 --- a/app/assets/javascripts/admin/directives/select2_min_search.js.coffee +++ b/app/assets/javascripts/admin/directives/select2_min_search.js.coffee @@ -1,4 +1,4 @@ -Admin.directive "ofnSelect2MinSearch", -> +angular.module("ofn.admin").directive "ofnSelect2MinSearch", -> require: 'ngModel' link: (scope, element, attrs, ngModel) -> element.select2 diff --git a/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee b/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee index 0705d04a23..e5713274ef 100644 --- a/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee +++ b/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee @@ -1,4 +1,4 @@ -Admin.directive "ofnTaxonAutocomplete", (Taxons) -> +angular.module("ofn.admin").directive "ofnTaxonAutocomplete", (Taxons) -> # Adapted from Spree's existing taxon autocompletion require: "ngModel" link: (scope,element,attrs,ngModel) -> diff --git a/app/assets/javascripts/admin/directives/toggle_column.js.coffee b/app/assets/javascripts/admin/directives/toggle_column.js.coffee index 2337a0fb58..1b8487eeb1 100644 --- a/app/assets/javascripts/admin/directives/toggle_column.js.coffee +++ b/app/assets/javascripts/admin/directives/toggle_column.js.coffee @@ -1,4 +1,4 @@ -Admin.directive "ofnToggleColumn", -> +angular.module("ofn.admin").directive "ofnToggleColumn", -> link: (scope, element, attrs) -> element.addClass "selected" if scope.column.visible element.click "click", -> diff --git a/app/assets/javascripts/admin/directives/toggle_variants.js.coffee b/app/assets/javascripts/admin/directives/toggle_variants.js.coffee index 8c07490359..879942d698 100644 --- a/app/assets/javascripts/admin/directives/toggle_variants.js.coffee +++ b/app/assets/javascripts/admin/directives/toggle_variants.js.coffee @@ -1,4 +1,4 @@ -Admin.directive "ofnToggleVariants", -> +angular.module("ofn.admin").directive "ofnToggleVariants", -> link: (scope, element, attrs) -> if scope.displayProperties[scope.product.id].showVariants element.removeClass "icon-chevron-right" diff --git a/app/assets/javascripts/admin/directives/track_product.js.coffee b/app/assets/javascripts/admin/directives/track_product.js.coffee index 3667794712..a4ea3865c0 100644 --- a/app/assets/javascripts/admin/directives/track_product.js.coffee +++ b/app/assets/javascripts/admin/directives/track_product.js.coffee @@ -1,4 +1,4 @@ -Admin.directive "ofnTrackProduct", ["DirtyProducts", (DirtyProducts) -> +angular.module("ofn.admin").directive "ofnTrackProduct", ["DirtyProducts", (DirtyProducts) -> require: "ngModel" link: (scope, element, attrs, ngModel) -> ngModel.$parsers.push (viewValue) -> diff --git a/app/assets/javascripts/admin/directives/track_variant.js.coffee b/app/assets/javascripts/admin/directives/track_variant.js.coffee index 189d5043fe..ab17ebcfa5 100644 --- a/app/assets/javascripts/admin/directives/track_variant.js.coffee +++ b/app/assets/javascripts/admin/directives/track_variant.js.coffee @@ -1,4 +1,4 @@ -Admin.directive "ofnTrackVariant", ["DirtyProducts", (DirtyProducts) -> +angular.module("ofn.admin").directive "ofnTrackVariant", ["DirtyProducts", (DirtyProducts) -> require: "ngModel" link: (scope, element, attrs, ngModel) -> ngModel.$parsers.push (viewValue) -> diff --git a/app/assets/javascripts/admin/filters/range_array.js.coffee b/app/assets/javascripts/admin/filters/range_array.js.coffee index 5056476f1b..be4a020442 100644 --- a/app/assets/javascripts/admin/filters/range_array.js.coffee +++ b/app/assets/javascripts/admin/filters/range_array.js.coffee @@ -1,4 +1,4 @@ -Admin.filter "rangeArray", -> +angular.module("ofn.admin").filter "rangeArray", -> return (input,start,end) -> input.push(i) for i in [start..end] input \ No newline at end of file diff --git a/app/assets/javascripts/admin/filters/select_filter.js.coffee b/app/assets/javascripts/admin/filters/select_filter.js.coffee index 562be954b2..2b03abd613 100644 --- a/app/assets/javascripts/admin/filters/select_filter.js.coffee +++ b/app/assets/javascripts/admin/filters/select_filter.js.coffee @@ -1,4 +1,4 @@ -Admin.filter "selectFilter", (blankOption) -> +angular.module("ofn.admin").filter "selectFilter", (blankOption) -> return (lineItems,selectedSupplier,selectedDistributor,selectedOrderCycle) -> filtered = [] filtered.push lineItem for lineItem in lineItems when (angular.equals(selectedSupplier,"0") || lineItem.supplier.id == selectedSupplier) && diff --git a/app/assets/javascripts/admin/filters/variant_filter.js.coffee b/app/assets/javascripts/admin/filters/variant_filter.js.coffee index 039c4cc46f..ddbc0f2711 100644 --- a/app/assets/javascripts/admin/filters/variant_filter.js.coffee +++ b/app/assets/javascripts/admin/filters/variant_filter.js.coffee @@ -1,4 +1,4 @@ -Admin.filter "variantFilter", -> +angular.module("ofn.admin").filter "variantFilter", -> return (lineItems,selectedUnitsProduct,selectedUnitsVariant,sharedResource) -> filtered = [] filtered.push lineItem for lineItem in lineItems when (angular.equals(selectedUnitsProduct,{}) || diff --git a/app/assets/javascripts/admin/services/blank_option.js.coffee b/app/assets/javascripts/admin/services/blank_option.js.coffee index 9913a6511d..42ff69a77b 100644 --- a/app/assets/javascripts/admin/services/blank_option.js.coffee +++ b/app/assets/javascripts/admin/services/blank_option.js.coffee @@ -1,2 +1,2 @@ -Admin.value "blankOption", -> +angular.module("ofn.admin").value "blankOption", -> { id: "0", name: "All" } \ No newline at end of file diff --git a/app/assets/javascripts/admin/services/confirm_handler.js.coffee b/app/assets/javascripts/admin/services/confirm_handler.js.coffee index 51b92848dc..88655e34e3 100644 --- a/app/assets/javascripts/admin/services/confirm_handler.js.coffee +++ b/app/assets/javascripts/admin/services/confirm_handler.js.coffee @@ -1,4 +1,4 @@ -Admin.factory "ofnConfirmHandler", (pendingChanges, $compile, $q) -> +angular.module("ofn.admin").factory "ofnConfirmHandler", (pendingChanges, $compile, $q) -> return (scope, callback) -> template = "
Unsaved changes currently exist, save now or ignore?
" dialogDiv = $compile(template)(scope) diff --git a/app/assets/javascripts/admin/services/data_fetcher.js.coffee b/app/assets/javascripts/admin/services/data_fetcher.js.coffee index 0227d26fc7..735e4cc6bb 100644 --- a/app/assets/javascripts/admin/services/data_fetcher.js.coffee +++ b/app/assets/javascripts/admin/services/data_fetcher.js.coffee @@ -1,4 +1,4 @@ -Admin.factory "dataFetcher", [ +angular.module("ofn.admin").factory "dataFetcher", [ "$http", "$q" ($http, $q) -> return (dataLocation) -> diff --git a/app/assets/javascripts/admin/services/data_submitter.js.coffee b/app/assets/javascripts/admin/services/data_submitter.js.coffee index 6a08ca2d33..7d121ec645 100644 --- a/app/assets/javascripts/admin/services/data_submitter.js.coffee +++ b/app/assets/javascripts/admin/services/data_submitter.js.coffee @@ -1,4 +1,4 @@ -Admin.factory "dataSubmitter", [ +angular.module("ofn.admin").factory "dataSubmitter", [ "$http", "$q", "switchClass" ($http, $q, switchClass) -> return (changeObj) -> diff --git a/app/assets/javascripts/admin/services/dirty_products.js.coffee b/app/assets/javascripts/admin/services/dirty_products.js.coffee index bb8614205e..16c10e1e34 100644 --- a/app/assets/javascripts/admin/services/dirty_products.js.coffee +++ b/app/assets/javascripts/admin/services/dirty_products.js.coffee @@ -1,4 +1,4 @@ -Admin.factory "DirtyProducts", ($parse) -> +angular.module("ofn.admin").factory "DirtyProducts", ($parse) -> # Temporary service to track changes in products on admin bulk product edit dirtyProducts = {} diff --git a/app/assets/javascripts/admin/services/pending_changes.js.coffee b/app/assets/javascripts/admin/services/pending_changes.js.coffee index df66900aa7..d72a4ac7bc 100644 --- a/app/assets/javascripts/admin/services/pending_changes.js.coffee +++ b/app/assets/javascripts/admin/services/pending_changes.js.coffee @@ -1,4 +1,4 @@ -Admin.factory "pendingChanges",[ +angular.module("ofn.admin").factory "pendingChanges",[ "dataSubmitter" (dataSubmitter) -> pendingChanges: {} diff --git a/app/assets/javascripts/admin/services/switch_class.js.coffee b/app/assets/javascripts/admin/services/switch_class.js.coffee index bdd61dac2e..e39c52d1f6 100644 --- a/app/assets/javascripts/admin/services/switch_class.js.coffee +++ b/app/assets/javascripts/admin/services/switch_class.js.coffee @@ -1,4 +1,4 @@ -Admin.factory "switchClass", [ +angular.module("ofn.admin").factory "switchClass", [ "$timeout" ($timeout) -> return (element,classToAdd,removeClasses,timeout) -> diff --git a/app/assets/javascripts/admin/services/taxons.js.coffee b/app/assets/javascripts/admin/services/taxons.js.coffee index 5e17dca657..1779ec3518 100644 --- a/app/assets/javascripts/admin/services/taxons.js.coffee +++ b/app/assets/javascripts/admin/services/taxons.js.coffee @@ -1,4 +1,4 @@ -Admin.factory "Taxons", ($resource) -> +angular.module("ofn.admin").factory "Taxons", ($resource) -> resource = $resource "/admin/taxons/search" return { From 2987ca763db4c755ceaebf761c4c3e43f79ef929 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 23 May 2014 15:09:08 +1000 Subject: [PATCH 10/32] Add additional data sanitisation for foreign key migration --- db/migrate/20140402033428_add_foreign_keys.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/db/migrate/20140402033428_add_foreign_keys.rb b/db/migrate/20140402033428_add_foreign_keys.rb index f072127158..fce1ffd009 100644 --- a/db/migrate/20140402033428_add_foreign_keys.rb +++ b/db/migrate/20140402033428_add_foreign_keys.rb @@ -32,6 +32,11 @@ class AddForeignKeys < ActiveRecord::Migration say "Destroying #{orphaned_exchange_variants.count} orphaned ExchangeVariants (of total #{ExchangeVariant.count})" orphaned_exchange_variants.destroy_all + # Remove orphaned ExchangeFee records + orphaned_exchange_fees = ExchangeFee.joins('LEFT OUTER JOIN enterprise_fees ON enterprise_fees.id=exchange_fees.enterprise_fee_id').where('enterprise_fees.id IS NULL') + say "Destroying #{orphaned_exchange_fees.count} orphaned ExchangeFees (of total #{ExchangeFee.count})" + orphaned_exchange_fees.destroy_all + # Remove orphaned Spree::InventoryUnits orphaned_inventory_units = Spree::InventoryUnit.joins('LEFT OUTER JOIN spree_variants ON spree_variants.id=spree_inventory_units.variant_id').where('spree_variants.id IS NULL') say "Destroying #{orphaned_inventory_units.count} orphaned InventoryUnits (of total #{Spree::InventoryUnit.count})" From 9aadc9d1ce76995f5aaedd193e873211cef436b4 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 23 May 2014 15:10:21 +1000 Subject: [PATCH 11/32] Add initial user import/export via CSV --- lib/tasks/users.rake | 70 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 lib/tasks/users.rake diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake new file mode 100644 index 0000000000..0f8b8a411b --- /dev/null +++ b/lib/tasks/users.rake @@ -0,0 +1,70 @@ +require 'csv' + +namespace :openfoodnetwork do + + namespace :dev do + desc 'export users to CSV' + task export_users: :environment do + CSV.open('db/users.csv', 'wb') do |csv| + csv << header + # Skip some spambot users + users = Spree::User.all.reject { |u| u.email =~ /example.net/ } + users.each do |user| + csv << row(user) + end + end + end + + + desc 'import users from CSV' + task import_users: :environment do + ActionMailer::Base.delivery_method = :test + + CSV.foreach('db/users.csv') do |row| + next if row[0] == 'encrypted_password' + + create_user_from row + end + end + + + private + + def header + ["encrypted_password", "password_salt", "email", "remember_token", "persistence_token", "reset_password_token", "perishable_token", "sign_in_count", "failed_attempts", "last_request_at", "current_sign_in_at", "last_sign_in_at", "current_sign_in_ip", "last_sign_in_ip", "login", "created_at", "updated_at", "authentication_token", "unlock_token", "locked_at", "remember_created_at", "reset_password_sent_at", + + "role_name", + + "ship_address_firstname", "ship_address_lastname", "ship_address_address1", "ship_address_address2", "ship_address_city", "ship_address_zipcode", "ship_address_phone", "ship_address_state", "ship_address_country", "ship_address_created_at", "ship_address_updated_at", "ship_address_company", "ship_address_latitude", "ship_address_longitude", + + "bill_address_firstname", "bill_address_lastname", "bill_address_address1", "bill_address_address2", "bill_address_city", "bill_address_zipcode", "bill_address_phone", "bill_address_state", "bill_address_country", "bill_address_created_at", "bill_address_updated_at", "bill_address_company", "bill_address_latitude", "bill_address_longitude"] + end + + + def row(user) + # sa = user.ship_address + # ba = user.bill_address + + [user.encrypted_password, user.password_salt, user.email, user.remember_token, user.persistence_token, user.reset_password_token, user.perishable_token, user.sign_in_count, user.failed_attempts, user.last_request_at, user.current_sign_in_at, user.last_sign_in_at, user.current_sign_in_ip, user.last_sign_in_ip, user.login, user.created_at, user.updated_at, user.authentication_token, user.unlock_token, user.locked_at, user.remember_created_at, user.reset_password_sent_at, + + user.spree_roles.first.andand.name] + + # sa.andand.firstname, sa.andand.lastname, sa.andand.address1, sa.andand.address2, sa.andand.city, sa.andand.zipcode, sa.andand.phone, sa.andand.state, sa.andand.country, sa.andand.created_at, sa.andand.updated_at, sa.andand.company, sa.andand.latitude, sa.andand.longitude, + + # ba.andand.firstname, ba.andand.lastname, ba.andand.address1, ba.andand.address2, ba.andand.city, ba.andand.zipcode, ba.andand.phone, ba.andand.state, ba.andand.country, ba.andand.created_at, ba.andand.updated_at, ba.andand.company, ba.andand.latitude, ba.andand.longitude] + end + + + def create_user_from(row) + user = Spree::User.create!({password: 'changeme123', password_confirmation: 'changeme123', email: row[2], remember_token: row[3], persistence_token: row[4], reset_password_token: row[5], perishable_token: row[6], sign_in_count: row[7], failed_attempts: row[8], last_request_at: row[9], current_sign_in_at: row[10], last_sign_in_at: row[11], current_sign_in_ip: row[12], last_sign_in_ip: row[13], login: row[14], created_at: row[15], updated_at: row[16], authentication_token: row[17], unlock_token: row[18], locked_at: row[19], remember_created_at: row[20], reset_password_sent_at: row[21]}, without_protection: true) + + user.update_column :encrypted_password, row[0] + user.update_column :password_salt, row[1] + + role = Spree::Role.find_by_name row[24] + user.spree_roles << role if role + rescue ActiveRecord::RecordInvalid => e + puts "#{row[2]} - #{e.message}" + end + end +end From d1028cb912555c1909ae103660623d49c51dc724 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 23 May 2014 17:51:02 +1000 Subject: [PATCH 12/32] User import/export includes addresses --- lib/tasks/users.rake | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake index 0f8b8a411b..323c679fb0 100644 --- a/lib/tasks/users.rake +++ b/lib/tasks/users.rake @@ -7,8 +7,6 @@ namespace :openfoodnetwork do task export_users: :environment do CSV.open('db/users.csv', 'wb') do |csv| csv << header - # Skip some spambot users - users = Spree::User.all.reject { |u| u.email =~ /example.net/ } users.each do |user| csv << row(user) end @@ -30,28 +28,34 @@ namespace :openfoodnetwork do private + def users + # Skip some spambot users + Spree::User.all.reject { |u| u.email =~ /example.net/ } + end + + def header ["encrypted_password", "password_salt", "email", "remember_token", "persistence_token", "reset_password_token", "perishable_token", "sign_in_count", "failed_attempts", "last_request_at", "current_sign_in_at", "last_sign_in_at", "current_sign_in_ip", "last_sign_in_ip", "login", "created_at", "updated_at", "authentication_token", "unlock_token", "locked_at", "remember_created_at", "reset_password_sent_at", "role_name", - "ship_address_firstname", "ship_address_lastname", "ship_address_address1", "ship_address_address2", "ship_address_city", "ship_address_zipcode", "ship_address_phone", "ship_address_state", "ship_address_country", "ship_address_created_at", "ship_address_updated_at", "ship_address_company", "ship_address_latitude", "ship_address_longitude", + "ship_address_firstname", "ship_address_lastname", "ship_address_address1", "ship_address_address2", "ship_address_city", "ship_address_zipcode", "ship_address_phone", "ship_address_state", "ship_address_country", "ship_address_created_at", "ship_address_updated_at", "ship_address_company", - "bill_address_firstname", "bill_address_lastname", "bill_address_address1", "bill_address_address2", "bill_address_city", "bill_address_zipcode", "bill_address_phone", "bill_address_state", "bill_address_country", "bill_address_created_at", "bill_address_updated_at", "bill_address_company", "bill_address_latitude", "bill_address_longitude"] + "bill_address_firstname", "bill_address_lastname", "bill_address_address1", "bill_address_address2", "bill_address_city", "bill_address_zipcode", "bill_address_phone", "bill_address_state", "bill_address_country", "bill_address_created_at", "bill_address_updated_at", "bill_address_company",] end def row(user) - # sa = user.ship_address - # ba = user.bill_address + sa = user.orders.last.andand.ship_address + ba = user.orders.last.andand.bill_address [user.encrypted_password, user.password_salt, user.email, user.remember_token, user.persistence_token, user.reset_password_token, user.perishable_token, user.sign_in_count, user.failed_attempts, user.last_request_at, user.current_sign_in_at, user.last_sign_in_at, user.current_sign_in_ip, user.last_sign_in_ip, user.login, user.created_at, user.updated_at, user.authentication_token, user.unlock_token, user.locked_at, user.remember_created_at, user.reset_password_sent_at, - user.spree_roles.first.andand.name] + user.spree_roles.first.andand.name, - # sa.andand.firstname, sa.andand.lastname, sa.andand.address1, sa.andand.address2, sa.andand.city, sa.andand.zipcode, sa.andand.phone, sa.andand.state, sa.andand.country, sa.andand.created_at, sa.andand.updated_at, sa.andand.company, sa.andand.latitude, sa.andand.longitude, + sa.andand.firstname, sa.andand.lastname, sa.andand.address1, sa.andand.address2, sa.andand.city, sa.andand.zipcode, sa.andand.phone, sa.andand.state, sa.andand.country, sa.andand.created_at, sa.andand.updated_at, sa.andand.company, - # ba.andand.firstname, ba.andand.lastname, ba.andand.address1, ba.andand.address2, ba.andand.city, ba.andand.zipcode, ba.andand.phone, ba.andand.state, ba.andand.country, ba.andand.created_at, ba.andand.updated_at, ba.andand.company, ba.andand.latitude, ba.andand.longitude] + ba.andand.firstname, ba.andand.lastname, ba.andand.address1, ba.andand.address2, ba.andand.city, ba.andand.zipcode, ba.andand.phone, ba.andand.state, ba.andand.country, ba.andand.created_at, ba.andand.updated_at, ba.andand.company,] end @@ -61,8 +65,20 @@ namespace :openfoodnetwork do user.update_column :encrypted_password, row[0] user.update_column :password_salt, row[1] - role = Spree::Role.find_by_name row[24] - user.spree_roles << role if role + # Safer if we don't make new users into admins + #role = Spree::Role.find_by_name row[24] + #user.spree_roles << role if role + + sa_state = Spree::State.find_by_name row[30] + sa_country = Spree::Country.find_by_name row[31] + sa = Spree::Address.create!({firstname: row[23], lastname: row[24], address1: row[25], address2: row[26], city: row[27], zipcode: row[28], phone: row[29], state: sa_state, country: sa_country, created_at: row[32], updated_at: row[33], company: row[34]}, without_protection: true) + user.update_column :ship_address_id, sa.id + + ba_state = Spree::State.find_by_name row[42] + ba_country = Spree::Country.find_by_name row[43] + ba = Spree::Address.create!({firstname: row[35], lastname: row[36], address1: row[37], address2: row[38], city: row[39], zipcode: row[40], phone: row[41], state: ba_state, country: ba_country, created_at: row[44], updated_at: row[45], company: row[46]}, without_protection: true) + user.update_column :bill_address_id, ba.id + rescue ActiveRecord::RecordInvalid => e puts "#{row[2]} - #{e.message}" end From 14611896c07ce45e4465fcc00cd3ac0508cbd959 Mon Sep 17 00:00:00 2001 From: Rob H Date: Fri, 23 May 2014 18:08:29 +1000 Subject: [PATCH 13/32] Simplify new product form --- app/assets/javascripts/admin/all.js | 1 + .../admin/products/products.js.coffee | 1 + .../admin/products/units_controller.js.coffee | 46 +++++++++++++++ .../new/replace_form.html.haml.deface | 56 +++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 app/assets/javascripts/admin/products/products.js.coffee create mode 100644 app/assets/javascripts/admin/products/units_controller.js.coffee create mode 100644 app/overrides/spree/admin/products/new/replace_form.html.haml.deface diff --git a/app/assets/javascripts/admin/all.js b/app/assets/javascripts/admin/all.js index 3cf4fe97e7..30acc576bf 100644 --- a/app/assets/javascripts/admin/all.js +++ b/app/assets/javascripts/admin/all.js @@ -15,5 +15,6 @@ //= require admin/spree_auth //= require admin/spree_promo //= require ./admin +//= require ./products/products //= require_tree . diff --git a/app/assets/javascripts/admin/products/products.js.coffee b/app/assets/javascripts/admin/products/products.js.coffee new file mode 100644 index 0000000000..e922d40a34 --- /dev/null +++ b/app/assets/javascripts/admin/products/products.js.coffee @@ -0,0 +1 @@ +angular.module("admin.products", []) \ No newline at end of file diff --git a/app/assets/javascripts/admin/products/units_controller.js.coffee b/app/assets/javascripts/admin/products/units_controller.js.coffee new file mode 100644 index 0000000000..9070648e21 --- /dev/null +++ b/app/assets/javascripts/admin/products/units_controller.js.coffee @@ -0,0 +1,46 @@ +angular.module("admin.products") + .controller "unitsCtrl", ($scope) -> + $scope.product = { master: {} } + + $scope.$watch -> + $scope.product.variant_unit_with_scale + , -> + if $scope.product.variant_unit_with_scale + match = $scope.product.variant_unit_with_scale.match(/^([^_]+)_([\d\.]+)$/) + if match + $scope.product.variant_unit = match[1] + $scope.product.variant_unit_scale = parseFloat(match[2]) + else + $scope.product.variant_unit = $scope.product.variant_unit_with_scale + $scope.product.variant_unit_scale = null + else + $scope.product.variant_unit = $scope.product.variant_unit_scale = null + + $scope.$watch -> + $scope.product.master.unit_value_with_description + , -> + if $scope.product.master.hasOwnProperty("unit_value_with_description") + match = $scope.product.master.unit_value_with_description.match(/^([\d\.]+(?= |$)|)( |)(.*)$/) + if match + $scope.product.master.unit_value = parseFloat(match[1]) + $scope.product.master.unit_value = null if isNaN($scope.product.master.unit_value) + $scope.product.master.unit_value *= $scope.product.variant_unit_scale if $scope.product.master.unit_value && $scope.product.variant_unit_scale + $scope.product.master.unit_description = match[3] + + $scope.variant_unit_options = [ + ["Weight (g)", "weight_1"], + ["Weight (kg)", "weight_1000"], + ["Weight (T)", "weight_1000000"], + ["Volume (mL)", "volume_0.001"], + ["Volume (L)", "volume_1"], + ["Volume (ML)", "volume_1000000"], + ["Items", "items"] + ] + + $scope.hasVariants = (product) -> + Object.keys(product.variants).length > 0 + + $scope.hasUnit = (product) -> + product.variant_unit_with_scale? + + \ No newline at end of file diff --git a/app/overrides/spree/admin/products/new/replace_form.html.haml.deface b/app/overrides/spree/admin/products/new/replace_form.html.haml.deface new file mode 100644 index 0000000000..94f97a7e78 --- /dev/null +++ b/app/overrides/spree/admin/products/new/replace_form.html.haml.deface @@ -0,0 +1,56 @@ +/ replace "fieldset[data-hook='new_product']" + +%fieldset{ id: "new_product" } + %legend{align: "center"}= t(:new_product) + .row + = f.field_container :name do + = f.label :name, t(:name) + %span.required * + %br/ + = f.text_field :name, :class => 'fullwidth title' + = f.error_message_on :name + .row + .alpha.six.columns + = f.field_container :supplier do + = f.label :supplier + %span.required * + = f.collection_select(:supplier_id, Enterprise.is_primary_producer.managed_by(spree_current_user).by_name, :id, :name, {:include_blank => true}, {:class => "select2 fullwidth"}) + = f.error_message_on :supplier + .five.columns + = f.field_container :price do + = f.label :price, t(:price) + %span.required * + %br/ + = f.text_field :price, :class => 'fullwidth' + = f.error_message_on :price + .five.columns.omega + = f.field_container :on_hand do + = f.label :on_hand, t(:on_hand) + %span.required * + %br/ + = f.text_field :on_hand, :class => 'fullwidth' + = f.error_message_on :on_hand + .row{ 'ng-controller' => 'unitsCtrl' } + .six.columns.alpha + = f.label :variant_unit_with_scale, :units + %select.select2.fullwidth{ id: 'product_variant_unit_with_scale', 'ng-model' => 'product.variant_unit_with_scale', 'ng-options' => 'unit[1] as unit[0] for unit in variant_unit_options' } + %option{'value' => '', 'ng-hide' => "hasUnit(product)"} + %input{ type: 'hidden', 'ng-value' => 'product.variant_unit', name: 'product[variant_unit]' } + %input{ type: 'hidden', 'ng-value' => 'product.variant_unit_scale', name: 'product[variant_unit_scale]' } + .five.columns + = f.label :product_unit_value_with_description, :value + %input.fullwidth{ id: 'product_unit_value_with_description', 'ng-model' => 'product.master.unit_value_with_description', :type => 'text', :placeholder => 'eg. 2', 'ng-disabled' => "!hasUnit(product)" } + %input{ type: 'hidden', 'ng-value' => 'product.master.unit_value', name: 'product[unit_value]' } + %input{ type: 'hidden', 'ng-value' => 'product.master.unit_description', name: 'product[unit_description]' } + .five.columns.omega{ 'ng-show' => "product.variant_unit_with_scale == 'items'" } + = f.label :product_variant_unit_name, :unit_name + %input.fullwidth{ id: 'product_variant_unit_name','ng-model' => 'product.variant_unit_name', :name => 'product[variant_unit_name]', :placeholder => 'eg. bunches',bu :type => 'text' } + #product-from-prototype.clearfix{"data-hook" => "product-from-prototype"} + = render :file => 'spree/admin/prototypes/show' if @prototype + = render :partial => 'spree/admin/shared/new_resource_links' + + +:javascript + angular.element(document.getElementById("new_product")).ready(function() { + angular.bootstrap(document.getElementById("new_product"), ['admin.products']); + }); \ No newline at end of file From 4a9a1029a1c1a139582efab7eefdfb0c472e8d51 Mon Sep 17 00:00:00 2001 From: Rob H Date: Fri, 23 May 2014 22:33:59 +1000 Subject: [PATCH 14/32] Fixed a typo --- .../spree/admin/products/new/replace_form.html.haml.deface | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/overrides/spree/admin/products/new/replace_form.html.haml.deface b/app/overrides/spree/admin/products/new/replace_form.html.haml.deface index 94f97a7e78..c752744ee6 100644 --- a/app/overrides/spree/admin/products/new/replace_form.html.haml.deface +++ b/app/overrides/spree/admin/products/new/replace_form.html.haml.deface @@ -44,7 +44,7 @@ %input{ type: 'hidden', 'ng-value' => 'product.master.unit_description', name: 'product[unit_description]' } .five.columns.omega{ 'ng-show' => "product.variant_unit_with_scale == 'items'" } = f.label :product_variant_unit_name, :unit_name - %input.fullwidth{ id: 'product_variant_unit_name','ng-model' => 'product.variant_unit_name', :name => 'product[variant_unit_name]', :placeholder => 'eg. bunches',bu :type => 'text' } + %input.fullwidth{ id: 'product_variant_unit_name','ng-model' => 'product.variant_unit_name', :name => 'product[variant_unit_name]', :placeholder => 'eg. bunches', :type => 'text' } #product-from-prototype.clearfix{"data-hook" => "product-from-prototype"} = render :file => 'spree/admin/prototypes/show' if @prototype = render :partial => 'spree/admin/shared/new_resource_links' From a7566e34130a6169f98398bbe4ed63b764bdd151 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Sat, 24 May 2014 09:07:52 +1000 Subject: [PATCH 15/32] Revert "Always showing social media" This reverts commit aa23b03f98eec508dcd342e3a4618e97a8aa40e0. --- app/views/modals/_producer.html.haml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/views/modals/_producer.html.haml b/app/views/modals/_producer.html.haml index 6798598f49..be34e3c20a 100644 --- a/app/views/modals/_producer.html.haml +++ b/app/views/modals/_producer.html.haml @@ -17,19 +17,20 @@ %a{"bo-href" => "{{producer.website}}", target: "_blank" } %i.fi-web {{ producer.website }} - %li + {{ producer.twitterific }} + %li{"ng-show" => "producer.twitterific"} %a{"ng-href" => "http://twitter.com/{{producer.twitter}}", target: "_blank"} %i.fi-social-twitter {{ producer.twitter }} - %li + %li{"bo-if" => "producer.facebook"} %a{"bo-href" => "{{producer.facebook}}", target: "_blank"} %i.fi-social-facebook {{ producer.facebook }} - %li + %li{"bo-if" => "producer.linkedin"} %a{"bo-href" => "{{producer.linkedin}}", target: "_blank"} %i.fi-social-linkedin {{ producer.linkedin }} - %li + %li{"bo-if" => "producer.instagram"} %a{"bo-href" => "http://instagram.com/{{producer.instagram}}", target: "_blank"} / Will needs logic to allow user to input @instagramhandle to drive a logical URL %i.fi-social-instagram From 7ac33beb65783c1e5fc7624427edd57ccfc5e75b Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Sat, 24 May 2014 09:07:55 +1000 Subject: [PATCH 16/32] Revert "Adding primary taxon" This reverts commit 58112fb10597ae51e4d7744f9378493abfd217cb. --- app/overrides/add_primary_taxon_to_admin_product.rb | 4 ---- app/overrides/add_primary_taxon_to_admin_product_new.rb | 4 ---- app/views/spree/admin/products/_primary_taxon_form.html.haml | 5 ----- 3 files changed, 13 deletions(-) delete mode 100644 app/overrides/add_primary_taxon_to_admin_product.rb delete mode 100644 app/overrides/add_primary_taxon_to_admin_product_new.rb delete mode 100644 app/views/spree/admin/products/_primary_taxon_form.html.haml diff --git a/app/overrides/add_primary_taxon_to_admin_product.rb b/app/overrides/add_primary_taxon_to_admin_product.rb deleted file mode 100644 index 9f7c5edde5..0000000000 --- a/app/overrides/add_primary_taxon_to_admin_product.rb +++ /dev/null @@ -1,4 +0,0 @@ -Deface::Override.new(:virtual_path => "spree/admin/products/_form", - :insert_top => "[data-hook='admin_product_form_right']", - :partial => "spree/admin/products/primary_taxon_form", - :name => "add_primary_taxon_to_admin_product") diff --git a/app/overrides/add_primary_taxon_to_admin_product_new.rb b/app/overrides/add_primary_taxon_to_admin_product_new.rb deleted file mode 100644 index e5c9d24e7f..0000000000 --- a/app/overrides/add_primary_taxon_to_admin_product_new.rb +++ /dev/null @@ -1,4 +0,0 @@ -Deface::Override.new(:virtual_path => "spree/admin/products/new", - :insert_before => "[data-hook='new_product_attrs']", - :partial => "spree/admin/products/primary_taxon_form", - :name => "add_primary_taxon_to_admin_product_new") diff --git a/app/views/spree/admin/products/_primary_taxon_form.html.haml b/app/views/spree/admin/products/_primary_taxon_form.html.haml deleted file mode 100644 index a844f4f447..0000000000 --- a/app/views/spree/admin/products/_primary_taxon_form.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -= f.field_container :primary_taxon_id do - = f.label :primary_taxon_id - %br - = f.collection_select(:primary_taxon_id, Spree::Taxon.all, :id, :name, {:include_blank => true}, {:class => "select2 fullwidth"}) - = f.error_message_on :primary_taxon_id From 79393476b040707d52bcd182e26ae5fe9ddc6ce4 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Sat, 24 May 2014 09:07:56 +1000 Subject: [PATCH 17/32] Revert "Adding primary taxon to admin forms" This reverts commit 110a6f2d14a8ecb09628abf76f2836a275ff6777. --- .../admin/products/_form/add_notes_field.html.haml.deface | 1 + db/migrate/20140522044009_add_primary_taxon_to_products.rb | 2 -- db/schema.rb | 2 -- spec/features/admin/products_spec.rb | 6 ------ 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface b/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface index dcc7937d6b..dadebd01d4 100644 --- a/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface +++ b/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface @@ -4,3 +4,4 @@ = f.label :notes, t(:notes) = f.text_area :notes, { :class => 'fullwidth', rows: 5 } = f.error_message_on :notes + diff --git a/db/migrate/20140522044009_add_primary_taxon_to_products.rb b/db/migrate/20140522044009_add_primary_taxon_to_products.rb index f6ff3cfe96..ec8e3772b1 100644 --- a/db/migrate/20140522044009_add_primary_taxon_to_products.rb +++ b/db/migrate/20140522044009_add_primary_taxon_to_products.rb @@ -1,7 +1,5 @@ class AddPrimaryTaxonToProducts < ActiveRecord::Migration def change add_column :spree_products, :primary_taxon_id, :integer - add_index :spree_products, :primary_taxon_id - add_foreign_key :spree_products, :spree_taxons, column: :primary_taxon_id end end diff --git a/db/schema.rb b/db/schema.rb index 6005fd7cb5..69e79c2829 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -689,7 +689,6 @@ ActiveRecord::Schema.define(:version => 20140522044009) do add_index "spree_products", ["name"], :name => "index_products_on_name" add_index "spree_products", ["permalink"], :name => "index_products_on_permalink" add_index "spree_products", ["permalink"], :name => "permalink_idx_unique", :unique => true - add_index "spree_products", ["primary_taxon_id"], :name => "index_spree_products_on_primary_taxon_id" create_table "spree_products_promotion_rules", :id => false, :force => true do |t| t.integer "product_id" @@ -1094,7 +1093,6 @@ ActiveRecord::Schema.define(:version => 20140522044009) do add_foreign_key "spree_products", "enterprises", name: "spree_products_supplier_id_fk", column: "supplier_id" add_foreign_key "spree_products", "spree_shipping_categories", name: "spree_products_shipping_category_id_fk", column: "shipping_category_id" add_foreign_key "spree_products", "spree_tax_categories", name: "spree_products_tax_category_id_fk", column: "tax_category_id" - add_foreign_key "spree_products", "spree_taxons", name: "spree_products_primary_taxon_id_fk", column: "primary_taxon_id" add_foreign_key "spree_products_promotion_rules", "spree_products", name: "spree_products_promotion_rules_product_id_fk", column: "product_id" add_foreign_key "spree_products_promotion_rules", "spree_promotion_rules", name: "spree_products_promotion_rules_promotion_rule_id_fk", column: "promotion_rule_id" diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index b9fec1ef9f..b9f9d7a206 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -6,7 +6,6 @@ feature %q{ } do include AuthenticationWorkflow include WebHelper - let!(:taxon) { create(:taxon) } background do @supplier = create(:supplier_enterprise, :name => 'New supplier') @@ -23,7 +22,6 @@ feature %q{ fill_in 'product_name', with: 'A new product !!!' fill_in 'product_price', with: '19.99' - select taxon.name, from: "product_primary_taxon_id" select 'New supplier', from: 'product_supplier_id' click_button 'Create' @@ -45,8 +43,6 @@ feature %q{ product.reload product.distributors.sort.should == [@distributors[0], @distributors[2]].sort - - product.product_distributions.map { |pd| pd.enterprise_fee }.sort.should == [@enterprise_fees[0], @enterprise_fees[2]].sort end @@ -59,7 +55,6 @@ feature %q{ fill_in 'product_name', :with => 'A new product !!!' fill_in 'product_price', :with => '19.99' - select taxon.name, from: "product_primary_taxon_id" select 'New supplier', :from => 'product_supplier_id' choose 'product_group_buy_1' fill_in 'Group buy unit size', :with => '10' @@ -104,7 +99,6 @@ feature %q{ page.should have_selector('#product_supplier_id') select 'Another Supplier', :from => 'product_supplier_id' - select taxon.name, from: "product_primary_taxon_id" # Should only have suppliers listed which the user can manage within "#product_supplier_id" do From ad1f852bdda2cb9e4744ebbf26c55607b70ef523 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Sat, 24 May 2014 09:07:57 +1000 Subject: [PATCH 18/32] Revert "Adding primary taxon field to product" This reverts commit fd1e7ebaa3976327f518e0ef4ee1f347adb8fa8a. --- app/models/enterprise.rb | 1 - app/models/spree/classification_decorator.rb | 10 ---------- app/models/spree/product_decorator.rb | 13 +++++-------- ...0140522044009_add_primary_taxon_to_products.rb | 5 ----- db/schema.rb | 3 +-- spec/factories.rb | 7 ------- spec/models/spree/classification_spec.rb | 15 --------------- spec/models/spree/product_spec.rb | 11 ++--------- 8 files changed, 8 insertions(+), 57 deletions(-) delete mode 100644 app/models/spree/classification_decorator.rb delete mode 100644 db/migrate/20140522044009_add_primary_taxon_to_products.rb delete mode 100644 spec/models/spree/classification_spec.rb diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 5e53316607..a72c6fdbd6 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -15,7 +15,6 @@ class Enterprise < ActiveRecord::Base has_and_belongs_to_many :payment_methods, join_table: 'distributors_payment_methods', class_name: 'Spree::PaymentMethod', foreign_key: 'distributor_id' has_and_belongs_to_many :shipping_methods, join_table: 'distributors_shipping_methods', class_name: 'Spree::ShippingMethod', foreign_key: 'distributor_id' - delegate :latitude, :longitude, :city, :state_name, :to => :address accepts_nested_attributes_for :address diff --git a/app/models/spree/classification_decorator.rb b/app/models/spree/classification_decorator.rb deleted file mode 100644 index 7e34e6890e..0000000000 --- a/app/models/spree/classification_decorator.rb +++ /dev/null @@ -1,10 +0,0 @@ -Spree::Classification.class_eval do - before_destroy :dont_destroy_if_primary_taxon - - def dont_destroy_if_primary_taxon - if product.primary_taxon == taxon - errors.add :base, "Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted" - return false - end - end -end diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 13491f94df..ba7cbc253d 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -6,7 +6,6 @@ Spree::Product.class_eval do belongs_to :supplier, :class_name => 'Enterprise' - belongs_to :primary_taxon, class_name: 'Spree::Taxon' has_many :product_distributions, :dependent => :destroy has_many :distributors, :through => :product_distributions @@ -14,10 +13,9 @@ Spree::Product.class_eval do accepts_nested_attributes_for :product_distributions, :allow_destroy => true delegate_belongs_to :master, :unit_value, :unit_description - attr_accessible :supplier_id, :primary_taxon_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size, :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value, :unit_description, :notes + attr_accessible :supplier_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size, :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value, :unit_description, :notes validates_presence_of :supplier - validates_presence_of :primary_taxon validates_presence_of :variant_unit, if: :has_variants? validates_presence_of :variant_unit_scale, @@ -27,7 +25,6 @@ Spree::Product.class_eval do after_initialize :set_available_on_to_now, :if => :new_record? after_save :update_units - before_save :add_primary_taxon_to_taxons # -- Joins @@ -121,6 +118,10 @@ Spree::Product.class_eval do order_cycle.variants_distributed_by(distributor).where(product_id: self) end + def primary_taxon + self.taxons.order.first + end + # Build a product distribution for each distributor def build_product_distributions_for_user user Enterprise.is_distributor.managed_by(user).each do |distributor| @@ -156,10 +157,6 @@ Spree::Product.class_eval do end end - def add_primary_taxon_to_taxons - taxons << primary_taxon unless taxons.find_by_id(primary_taxon) - end - def self.all_variant_unit_option_types Spree::OptionType.where('name LIKE ?', 'unit_%%') end diff --git a/db/migrate/20140522044009_add_primary_taxon_to_products.rb b/db/migrate/20140522044009_add_primary_taxon_to_products.rb deleted file mode 100644 index ec8e3772b1..0000000000 --- a/db/migrate/20140522044009_add_primary_taxon_to_products.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddPrimaryTaxonToProducts < ActiveRecord::Migration - def change - add_column :spree_products, :primary_taxon_id, :integer - end -end diff --git a/db/schema.rb b/db/schema.rb index 69e79c2829..77df8baf75 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140522044009) do +ActiveRecord::Schema.define(:version => 20140522015012) do create_table "adjustment_metadata", :force => true do |t| t.integer "adjustment_id" @@ -681,7 +681,6 @@ ActiveRecord::Schema.define(:version => 20140522044009) do t.float "variant_unit_scale" t.string "variant_unit_name" t.text "notes" - t.integer "primary_taxon_id" end add_index "spree_products", ["available_on"], :name => "index_products_on_available_on" diff --git a/spec/factories.rb b/spec/factories.rb index 394112125a..6da7824d47 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -2,9 +2,6 @@ require 'ffaker' require 'spree/core/testing_support/factories' FactoryGirl.define do - factory :classification, class: Spree::Classification do - end - factory :order_cycle, :parent => :simple_order_cycle do coordinator_fees { [create(:enterprise_fee, enterprise: coordinator)] } @@ -153,9 +150,6 @@ end FactoryGirl.modify do - factory :product do - primary_taxon { Spree::Taxon.first || FactoryGirl.create(:taxon) } - end factory :simple_product do # Fix product factory name sequence with Kernel.rand so it is not interpreted as a Spree::Product method # Pull request: https://github.com/spree/spree/pull/1964 @@ -163,7 +157,6 @@ FactoryGirl.modify do sequence(:name) { |n| "Product ##{n} - #{Kernel.rand(9999)}" } supplier { Enterprise.is_primary_producer.first || FactoryGirl.create(:supplier_enterprise) } - primary_taxon { Spree::Taxon.first || FactoryGirl.create(:taxon) } on_hand 3 variant_unit 'weight' diff --git a/spec/models/spree/classification_spec.rb b/spec/models/spree/classification_spec.rb deleted file mode 100644 index f26f6da0c0..0000000000 --- a/spec/models/spree/classification_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -module Spree - describe Classification do - let(:product) { create(:simple_product) } - let(:taxon) { create(:taxon) } - let(:classification) { create(:classification, taxon: taxon, product: product) } - - it "won't destroy if classification is the primary taxon" do - product.primary_taxon = taxon - classification.destroy.should be_false - classification.errors.messages[:base].should == ["Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted"] - end - end -end diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 6a50190448..6d90b70761 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -5,7 +5,6 @@ module Spree describe "associations" do it { should belong_to(:supplier) } - it { should belong_to(:primary_taxon) } it { should have_many(:product_distributions) } end @@ -14,12 +13,6 @@ module Spree create(:product).should be_valid end - it "requires a primary taxon" do - product = create(:simple_product) - product.primary_taxon = nil - product.should_not be_valid - end - it "requires a supplier" do product = create(:simple_product) product.supplier = nil @@ -558,10 +551,10 @@ module Spree describe "Taxons" do let(:taxon1) { create(:taxon) } let(:taxon2) { create(:taxon) } - let(:product) { create(:simple_product) } + let(:product) { create(:simple_product, taxons: [taxon1, taxon2]) } it "returns the first taxon as the primary taxon" do - product.taxons.should == [product.primary_taxon] + product.primary_taxon.should == taxon1 end end end From bb1b7cfa90238a8515605b571dfade30116f0298 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Sat, 24 May 2014 09:07:58 +1000 Subject: [PATCH 19/32] Revert "Adding fields to product supplier" This reverts commit 6d24a6555e217f760d8c7bd602e13d5e5a1cde87. --- app/views/shop/products.rabl | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/views/shop/products.rabl b/app/views/shop/products.rabl index ee5e567285..c8b5d5398c 100644 --- a/app/views/shop/products.rabl +++ b/app/views/shop/products.rabl @@ -10,14 +10,7 @@ node do |product| end child :supplier => :supplier do - attributes :id, :name, :description, :long_description, :website, :instagram, :facebook, :linkedin, :twitter - - node :logo do |supplier| - supplier.logo.url - end - node :promo_image do |supplier| - supplier.promo_image.url - end + attributes :id, :name, :description end child :primary_taxon => :primary_taxon do From 69e0e71eb617e75182e58ccacabbf12db427e71f Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Sat, 24 May 2014 09:12:24 +1000 Subject: [PATCH 20/32] Revert "Styling for shop page product modal" This reverts commit 84b6f99321a328a14bfe2044dbebde702860bced. Conflicts: app/assets/stylesheets/darkswarm/images.css.sass app/views/modals/_producer.html.haml --- app/assets/stylesheets/darkswarm/all.scss | 3 ++ .../stylesheets/darkswarm/images.css.sass | 46 ---------------- .../stylesheets/darkswarm/overrides.css.sass | 3 ++ .../stylesheets/darkswarm/shop.css.sass | 3 +- app/views/modals/_producer.html.haml | 52 +++++-------------- app/views/modals/_producers.html.haml | 3 +- app/views/modals/_product.html.haml | 14 +---- 7 files changed, 24 insertions(+), 100 deletions(-) delete mode 100644 app/assets/stylesheets/darkswarm/images.css.sass diff --git a/app/assets/stylesheets/darkswarm/all.scss b/app/assets/stylesheets/darkswarm/all.scss index a8ac8af078..80e43cdc8b 100644 --- a/app/assets/stylesheets/darkswarm/all.scss +++ b/app/assets/stylesheets/darkswarm/all.scss @@ -9,3 +9,6 @@ */ @import 'foundation-icons'; +ofn-modal { + display: block; +} \ No newline at end of file diff --git a/app/assets/stylesheets/darkswarm/images.css.sass b/app/assets/stylesheets/darkswarm/images.css.sass deleted file mode 100644 index 927e906842..0000000000 --- a/app/assets/stylesheets/darkswarm/images.css.sass +++ /dev/null @@ -1,46 +0,0 @@ -@import mixins -@import variables -@import branding - -.product-img - border-bottom: 40px white solid - border-top: 20px white solid - border-left: 20px white solid - border-right: 20px white solid - outline: 1px solid #ccc - @include box-shadow(0 1px 2px 1px rgba(0,0,0,0.25)) - -.producer-hero - position: relative - padding: 0 - -.producer-hero-img - background-color: #999 - width: 100% - height: inherit - max-height: 260px - overflow: hidden - margin-top: 2em - margin-bottom: 1em - - -h3.producer-name - background-color: rgba(255,255,255,0.65) - height: 2.5em - width: 100% - position: absolute - bottom: 0 - padding: 0.5em - -.producer-logo - max-width: 220px - -@media only screen and (max-width: 1024px) - .product-img - margin-top: 2em - margin-bottom: 1em - - - - - diff --git a/app/assets/stylesheets/darkswarm/overrides.css.sass b/app/assets/stylesheets/darkswarm/overrides.css.sass index fcec6b455d..917d6dd2e3 100644 --- a/app/assets/stylesheets/darkswarm/overrides.css.sass +++ b/app/assets/stylesheets/darkswarm/overrides.css.sass @@ -1,2 +1,5 @@ .row max-width: 74em + +.reveal-modal + position: fixed diff --git a/app/assets/stylesheets/darkswarm/shop.css.sass b/app/assets/stylesheets/darkswarm/shop.css.sass index e0030a7d7a..0c2972367a 100644 --- a/app/assets/stylesheets/darkswarm/shop.css.sass +++ b/app/assets/stylesheets/darkswarm/shop.css.sass @@ -81,7 +81,8 @@ padding-top: 1em input.button.right float: left - + + product:hover, product:focus, product:active border-color: $clr-brick @include box-shadow(0 0 3px 0 $clr-brick-bright) diff --git a/app/views/modals/_producer.html.haml b/app/views/modals/_producer.html.haml index be34e3c20a..056f9e488f 100644 --- a/app/views/modals/_producer.html.haml +++ b/app/views/modals/_producer.html.haml @@ -1,40 +1,12 @@ -%ofn-modal{title: "{{producer.name}}"} - .row - .columns.small-12.producer-hero - %img.producer-hero-img{"ng-src" => "{{producer.promo_image}}"} - / Will - scale large images down to 1200px wide, crop in to img aspect ratio 60W:13H - %h3.producer-name {{ producer.name }} - .row - .columns.small-12.large-6{"inject-html" => "producer.long_description"} - .columns.small-12.large-6 - / Will needs logic to add in following only if data is available for each type: - / Will needs better formatting of URLs printed on-screen (minus http://www.) - / Will needs formatting of URLs driving %a regardless of user input (plus http://www.) - %img.producer-logo{"ng-src" => "{{producer.logo}}"} - %h4 Stay in touch with {{ producer.name }} - %ul.small-block-grid-1{bindonce: true} - %li{"bo-if" => "producer.website"} - %a{"bo-href" => "{{producer.website}}", target: "_blank" } - %i.fi-web - {{ producer.website }} - {{ producer.twitterific }} - %li{"ng-show" => "producer.twitterific"} - %a{"ng-href" => "http://twitter.com/{{producer.twitter}}", target: "_blank"} - %i.fi-social-twitter - {{ producer.twitter }} - %li{"bo-if" => "producer.facebook"} - %a{"bo-href" => "{{producer.facebook}}", target: "_blank"} - %i.fi-social-facebook - {{ producer.facebook }} - %li{"bo-if" => "producer.linkedin"} - %a{"bo-href" => "{{producer.linkedin}}", target: "_blank"} - %i.fi-social-linkedin - {{ producer.linkedin }} - %li{"bo-if" => "producer.instagram"} - %a{"bo-href" => "http://instagram.com/{{producer.instagram}}", target: "_blank"} - / Will needs logic to allow user to input @instagramhandle to drive a logical URL - %i.fi-social-instagram - {{ producer.instagram }} - - - %a.close-reveal-modal{"ng-click" => "$close()"} × +%ofn-modal{title: "{{ producer.name }}"} + #producer_modal + .row + .small-12.columns + %img{"ng-src" => "producer.promo_image"} + %h3 {{ producer.name }} + .row + .small-6.columns + %p + {{ producer.description }} + .small-6.columns + Stay in touch with {{ producer.name }} diff --git a/app/views/modals/_producers.html.haml b/app/views/modals/_producers.html.haml index 89d8ccabae..153e4dcae3 100644 --- a/app/views/modals/_producers.html.haml +++ b/app/views/modals/_producers.html.haml @@ -1,3 +1,4 @@ %h2 Producers -%p Our producers make all the delicious food you can shop for on the Open Food Network. +%h5 Our producers make the food! All the delicious! +%p More text goes here. %a.close-reveal-modal{"ng-click" => "cancel()"} × \ No newline at end of file diff --git a/app/views/modals/_product.html.haml b/app/views/modals/_product.html.haml index 70137ba987..acca8f919b 100644 --- a/app/views/modals/_product.html.haml +++ b/app/views/modals/_product.html.haml @@ -1,14 +1,4 @@ %ofn-modal{title: "{{product.name}}"} - .row - .columns.small-12.large-6 - %img.product-img{"ng-src" => "{{product.master.images[0].large_url}}"} - .columns.small-12.large-6 - %h2 - %img{"ng-src" => "{{product.primary_taxon.icon}}"} - {{product.name}} - %p {{product.description}} - / %pre - / {{ product | json }} - %a.close-reveal-modal{"ng-click" => "$close()"} × - \ No newline at end of file + {{ product | json }} + {{ product.description }} From 223caa046c0547dbb6e7e4110ac25204c94fcf4d Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Sat, 24 May 2014 09:15:22 +1000 Subject: [PATCH 21/32] Revert "Producers modal styling and markup" This reverts commit 465728576961706c0137b51952476113ffdd3419. Conflicts: app/assets/stylesheets/darkswarm/images.css.sass app/views/modals/_producer.html.haml --- app/views/modals/_producer.html.haml | 40 +++++++++++++++++++--------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/app/views/modals/_producer.html.haml b/app/views/modals/_producer.html.haml index 056f9e488f..037a95398b 100644 --- a/app/views/modals/_producer.html.haml +++ b/app/views/modals/_producer.html.haml @@ -1,12 +1,28 @@ -%ofn-modal{title: "{{ producer.name }}"} - #producer_modal - .row - .small-12.columns - %img{"ng-src" => "producer.promo_image"} - %h3 {{ producer.name }} - .row - .small-6.columns - %p - {{ producer.description }} - .small-6.columns - Stay in touch with {{ producer.name }} +/ %ofn-modal{title: "{{ producer.name }}"} +/ #producer_modal +/ .row +/ .small-12.columns +/ %img{"ng-src" => "producer.promo_image"} +/ %h3 {{ producer.name }} +/ .row +/ .small-6.columns +/ %p +/ {{ producer.description }} +/ .small-6.columns +/ Stay in touch with {{ producer.name }} +/ %a.close-reveal-modal{"ng-click" => "$close()"} × + + +%ofn-modal{title: "{{producer.name}}"} + .row + .columns.small-12 + %img.product-img{"ng-src" => "{{producer.promo_image.images[0].large_url}}"} + %h3 {{ producer.name }} + .row + .columns.small-12.large-6 + %p {{ producer.description }} + .columns.small-12.large-6 + Stay in touch with {{ producer.name }} + / %pre + / {{ producer | json }} + %a.close-reveal-modal{"ng-click" => "$close()"} × From e119192cf17ec433456c26d2cb8c15c2ad1b9315 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Sat, 24 May 2014 09:21:48 +1000 Subject: [PATCH 22/32] Manually revert merge commit "Hack patching the modals" --- Gemfile.lock | 2 +- .../javascripts/darkswarm/all.js.coffee | 1 - .../product_node_controller.js.coffee | 9 +---- .../javascripts/darkswarm/darkswarm.js.coffee | 1 - .../darkswarm/directives/modal.js.coffee | 8 ---- app/views/modals/_producer.html.haml | 40 ++++++------------- 6 files changed, 15 insertions(+), 46 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index cb0e11cced..733ef43572 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -150,7 +150,7 @@ GEM railties (>= 3.1) sprockets tilt - angularjs-rails (1.2.16) + angularjs-rails (1.2.13) ansi (1.4.2) arel (3.0.3) awesome_nested_set (2.1.5) diff --git a/app/assets/javascripts/darkswarm/all.js.coffee b/app/assets/javascripts/darkswarm/all.js.coffee index 3a039394ca..20d849f60c 100644 --- a/app/assets/javascripts/darkswarm/all.js.coffee +++ b/app/assets/javascripts/darkswarm/all.js.coffee @@ -6,7 +6,6 @@ #= require angular #= require angular-cookies #= require angular-resource -#= require angular-sanitize #= require ../shared/mm-foundation-tpls-0.2.0-SNAPSHOT #= require ../shared/bindonce.min.js #= require ../shared/ng-infinite-scroll.min.js diff --git a/app/assets/javascripts/darkswarm/controllers/products/product_node_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/products/product_node_controller.js.coffee index fa0daababc..959423e3ca 100644 --- a/app/assets/javascripts/darkswarm/controllers/products/product_node_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/products/product_node_controller.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.controller "ProductNodeCtrl", ($scope, $sce) -> +Darkswarm.controller "ProductNodeCtrl", ($scope) -> $scope.price = -> if $scope.product.variants.length > 0 @@ -8,10 +8,5 @@ Darkswarm.controller "ProductNodeCtrl", ($scope, $sce) -> $scope.product.price $scope.producer = $scope.product.supplier - $scope.producer.twitterific = true + $scope.hasVariants = $scope.product.variants.length > 0 - -Darkswarm.filter "unsafe", ($sce) -> - (val) -> - $sce.trustAsHtml val - diff --git a/app/assets/javascripts/darkswarm/darkswarm.js.coffee b/app/assets/javascripts/darkswarm/darkswarm.js.coffee index 8d26384c14..fe128b963a 100644 --- a/app/assets/javascripts/darkswarm/darkswarm.js.coffee +++ b/app/assets/javascripts/darkswarm/darkswarm.js.coffee @@ -5,7 +5,6 @@ window.Darkswarm = angular.module("Darkswarm", ["ngResource", 'infinite-scroll', 'angular-flash.service', 'templates', - 'ngSanitize', 'backstretch']).config ($httpProvider, $tooltipProvider, $locationProvider, $anchorScrollProvider) -> $httpProvider.defaults.headers.post['X-CSRF-Token'] = $('meta[name="csrf-token"]').attr('content') $httpProvider.defaults.headers.put['X-CSRF-Token'] = $('meta[name="csrf-token"]').attr('content') diff --git a/app/assets/javascripts/darkswarm/directives/modal.js.coffee b/app/assets/javascripts/darkswarm/directives/modal.js.coffee index f641c29cb5..6f62c7cb45 100644 --- a/app/assets/javascripts/darkswarm/directives/modal.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/modal.js.coffee @@ -16,11 +16,3 @@ Darkswarm.directive "ofnModal", ($modal)-> elem.on "click", => scope.modalInstance = $modal.open(controller: ctrl, template: contents) - -# TODO THIS IS TERRIBLE PLEASE FIX NG-BIND-HTML -Darkswarm.directive "injectHtml", -> - restrict: 'A' - scope: - injectHtml: "=" - link: (scope, elem, attrs, ctrl)-> - elem.html(scope.injectHtml) diff --git a/app/views/modals/_producer.html.haml b/app/views/modals/_producer.html.haml index 037a95398b..056f9e488f 100644 --- a/app/views/modals/_producer.html.haml +++ b/app/views/modals/_producer.html.haml @@ -1,28 +1,12 @@ -/ %ofn-modal{title: "{{ producer.name }}"} -/ #producer_modal -/ .row -/ .small-12.columns -/ %img{"ng-src" => "producer.promo_image"} -/ %h3 {{ producer.name }} -/ .row -/ .small-6.columns -/ %p -/ {{ producer.description }} -/ .small-6.columns -/ Stay in touch with {{ producer.name }} -/ %a.close-reveal-modal{"ng-click" => "$close()"} × - - -%ofn-modal{title: "{{producer.name}}"} - .row - .columns.small-12 - %img.product-img{"ng-src" => "{{producer.promo_image.images[0].large_url}}"} - %h3 {{ producer.name }} - .row - .columns.small-12.large-6 - %p {{ producer.description }} - .columns.small-12.large-6 - Stay in touch with {{ producer.name }} - / %pre - / {{ producer | json }} - %a.close-reveal-modal{"ng-click" => "$close()"} × +%ofn-modal{title: "{{ producer.name }}"} + #producer_modal + .row + .small-12.columns + %img{"ng-src" => "producer.promo_image"} + %h3 {{ producer.name }} + .row + .small-6.columns + %p + {{ producer.description }} + .small-6.columns + Stay in touch with {{ producer.name }} From 17f09d18528f1211aef99ce1d1676894bae48282 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 22 May 2014 15:49:10 +1000 Subject: [PATCH 23/32] Adding primary taxon field to product --- app/models/enterprise.rb | 1 + app/models/spree/classification_decorator.rb | 10 ++++++++++ app/models/spree/product_decorator.rb | 13 ++++++++----- ...0140522044009_add_primary_taxon_to_products.rb | 5 +++++ db/schema.rb | 3 ++- spec/factories.rb | 7 +++++++ spec/models/spree/classification_spec.rb | 15 +++++++++++++++ spec/models/spree/product_spec.rb | 11 +++++++++-- 8 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 app/models/spree/classification_decorator.rb create mode 100644 db/migrate/20140522044009_add_primary_taxon_to_products.rb create mode 100644 spec/models/spree/classification_spec.rb diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index a72c6fdbd6..5e53316607 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -15,6 +15,7 @@ class Enterprise < ActiveRecord::Base has_and_belongs_to_many :payment_methods, join_table: 'distributors_payment_methods', class_name: 'Spree::PaymentMethod', foreign_key: 'distributor_id' has_and_belongs_to_many :shipping_methods, join_table: 'distributors_shipping_methods', class_name: 'Spree::ShippingMethod', foreign_key: 'distributor_id' + delegate :latitude, :longitude, :city, :state_name, :to => :address accepts_nested_attributes_for :address diff --git a/app/models/spree/classification_decorator.rb b/app/models/spree/classification_decorator.rb new file mode 100644 index 0000000000..7e34e6890e --- /dev/null +++ b/app/models/spree/classification_decorator.rb @@ -0,0 +1,10 @@ +Spree::Classification.class_eval do + before_destroy :dont_destroy_if_primary_taxon + + def dont_destroy_if_primary_taxon + if product.primary_taxon == taxon + errors.add :base, "Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted" + return false + end + end +end diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index ba7cbc253d..13491f94df 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -6,6 +6,7 @@ Spree::Product.class_eval do belongs_to :supplier, :class_name => 'Enterprise' + belongs_to :primary_taxon, class_name: 'Spree::Taxon' has_many :product_distributions, :dependent => :destroy has_many :distributors, :through => :product_distributions @@ -13,9 +14,10 @@ Spree::Product.class_eval do accepts_nested_attributes_for :product_distributions, :allow_destroy => true delegate_belongs_to :master, :unit_value, :unit_description - attr_accessible :supplier_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size, :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value, :unit_description, :notes + attr_accessible :supplier_id, :primary_taxon_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size, :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value, :unit_description, :notes validates_presence_of :supplier + validates_presence_of :primary_taxon validates_presence_of :variant_unit, if: :has_variants? validates_presence_of :variant_unit_scale, @@ -25,6 +27,7 @@ Spree::Product.class_eval do after_initialize :set_available_on_to_now, :if => :new_record? after_save :update_units + before_save :add_primary_taxon_to_taxons # -- Joins @@ -118,10 +121,6 @@ Spree::Product.class_eval do order_cycle.variants_distributed_by(distributor).where(product_id: self) end - def primary_taxon - self.taxons.order.first - end - # Build a product distribution for each distributor def build_product_distributions_for_user user Enterprise.is_distributor.managed_by(user).each do |distributor| @@ -157,6 +156,10 @@ Spree::Product.class_eval do end end + def add_primary_taxon_to_taxons + taxons << primary_taxon unless taxons.find_by_id(primary_taxon) + end + def self.all_variant_unit_option_types Spree::OptionType.where('name LIKE ?', 'unit_%%') end diff --git a/db/migrate/20140522044009_add_primary_taxon_to_products.rb b/db/migrate/20140522044009_add_primary_taxon_to_products.rb new file mode 100644 index 0000000000..ec8e3772b1 --- /dev/null +++ b/db/migrate/20140522044009_add_primary_taxon_to_products.rb @@ -0,0 +1,5 @@ +class AddPrimaryTaxonToProducts < ActiveRecord::Migration + def change + add_column :spree_products, :primary_taxon_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 77df8baf75..69e79c2829 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140522015012) do +ActiveRecord::Schema.define(:version => 20140522044009) do create_table "adjustment_metadata", :force => true do |t| t.integer "adjustment_id" @@ -681,6 +681,7 @@ ActiveRecord::Schema.define(:version => 20140522015012) do t.float "variant_unit_scale" t.string "variant_unit_name" t.text "notes" + t.integer "primary_taxon_id" end add_index "spree_products", ["available_on"], :name => "index_products_on_available_on" diff --git a/spec/factories.rb b/spec/factories.rb index 6da7824d47..394112125a 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -2,6 +2,9 @@ require 'ffaker' require 'spree/core/testing_support/factories' FactoryGirl.define do + factory :classification, class: Spree::Classification do + end + factory :order_cycle, :parent => :simple_order_cycle do coordinator_fees { [create(:enterprise_fee, enterprise: coordinator)] } @@ -150,6 +153,9 @@ end FactoryGirl.modify do + factory :product do + primary_taxon { Spree::Taxon.first || FactoryGirl.create(:taxon) } + end factory :simple_product do # Fix product factory name sequence with Kernel.rand so it is not interpreted as a Spree::Product method # Pull request: https://github.com/spree/spree/pull/1964 @@ -157,6 +163,7 @@ FactoryGirl.modify do sequence(:name) { |n| "Product ##{n} - #{Kernel.rand(9999)}" } supplier { Enterprise.is_primary_producer.first || FactoryGirl.create(:supplier_enterprise) } + primary_taxon { Spree::Taxon.first || FactoryGirl.create(:taxon) } on_hand 3 variant_unit 'weight' diff --git a/spec/models/spree/classification_spec.rb b/spec/models/spree/classification_spec.rb new file mode 100644 index 0000000000..f26f6da0c0 --- /dev/null +++ b/spec/models/spree/classification_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +module Spree + describe Classification do + let(:product) { create(:simple_product) } + let(:taxon) { create(:taxon) } + let(:classification) { create(:classification, taxon: taxon, product: product) } + + it "won't destroy if classification is the primary taxon" do + product.primary_taxon = taxon + classification.destroy.should be_false + classification.errors.messages[:base].should == ["Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted"] + end + end +end diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 6d90b70761..6a50190448 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -5,6 +5,7 @@ module Spree describe "associations" do it { should belong_to(:supplier) } + it { should belong_to(:primary_taxon) } it { should have_many(:product_distributions) } end @@ -13,6 +14,12 @@ module Spree create(:product).should be_valid end + it "requires a primary taxon" do + product = create(:simple_product) + product.primary_taxon = nil + product.should_not be_valid + end + it "requires a supplier" do product = create(:simple_product) product.supplier = nil @@ -551,10 +558,10 @@ module Spree describe "Taxons" do let(:taxon1) { create(:taxon) } let(:taxon2) { create(:taxon) } - let(:product) { create(:simple_product, taxons: [taxon1, taxon2]) } + let(:product) { create(:simple_product) } it "returns the first taxon as the primary taxon" do - product.primary_taxon.should == taxon1 + product.taxons.should == [product.primary_taxon] end end end From 0a8f5d91ba50e24a6455b670b7cc790fde91395d Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 22 May 2014 16:13:47 +1000 Subject: [PATCH 24/32] Adding primary taxon to admin forms --- .../admin/products/_form/add_notes_field.html.haml.deface | 1 - db/migrate/20140522044009_add_primary_taxon_to_products.rb | 2 ++ db/schema.rb | 2 ++ spec/features/admin/products_spec.rb | 6 ++++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface b/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface index dadebd01d4..dcc7937d6b 100644 --- a/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface +++ b/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface @@ -4,4 +4,3 @@ = f.label :notes, t(:notes) = f.text_area :notes, { :class => 'fullwidth', rows: 5 } = f.error_message_on :notes - diff --git a/db/migrate/20140522044009_add_primary_taxon_to_products.rb b/db/migrate/20140522044009_add_primary_taxon_to_products.rb index ec8e3772b1..f6ff3cfe96 100644 --- a/db/migrate/20140522044009_add_primary_taxon_to_products.rb +++ b/db/migrate/20140522044009_add_primary_taxon_to_products.rb @@ -1,5 +1,7 @@ class AddPrimaryTaxonToProducts < ActiveRecord::Migration def change add_column :spree_products, :primary_taxon_id, :integer + add_index :spree_products, :primary_taxon_id + add_foreign_key :spree_products, :spree_taxons, column: :primary_taxon_id end end diff --git a/db/schema.rb b/db/schema.rb index 69e79c2829..6005fd7cb5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -689,6 +689,7 @@ ActiveRecord::Schema.define(:version => 20140522044009) do add_index "spree_products", ["name"], :name => "index_products_on_name" add_index "spree_products", ["permalink"], :name => "index_products_on_permalink" add_index "spree_products", ["permalink"], :name => "permalink_idx_unique", :unique => true + add_index "spree_products", ["primary_taxon_id"], :name => "index_spree_products_on_primary_taxon_id" create_table "spree_products_promotion_rules", :id => false, :force => true do |t| t.integer "product_id" @@ -1093,6 +1094,7 @@ ActiveRecord::Schema.define(:version => 20140522044009) do add_foreign_key "spree_products", "enterprises", name: "spree_products_supplier_id_fk", column: "supplier_id" add_foreign_key "spree_products", "spree_shipping_categories", name: "spree_products_shipping_category_id_fk", column: "shipping_category_id" add_foreign_key "spree_products", "spree_tax_categories", name: "spree_products_tax_category_id_fk", column: "tax_category_id" + add_foreign_key "spree_products", "spree_taxons", name: "spree_products_primary_taxon_id_fk", column: "primary_taxon_id" add_foreign_key "spree_products_promotion_rules", "spree_products", name: "spree_products_promotion_rules_product_id_fk", column: "product_id" add_foreign_key "spree_products_promotion_rules", "spree_promotion_rules", name: "spree_products_promotion_rules_promotion_rule_id_fk", column: "promotion_rule_id" diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index b9f9d7a206..b9fec1ef9f 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -6,6 +6,7 @@ feature %q{ } do include AuthenticationWorkflow include WebHelper + let!(:taxon) { create(:taxon) } background do @supplier = create(:supplier_enterprise, :name => 'New supplier') @@ -22,6 +23,7 @@ feature %q{ fill_in 'product_name', with: 'A new product !!!' fill_in 'product_price', with: '19.99' + select taxon.name, from: "product_primary_taxon_id" select 'New supplier', from: 'product_supplier_id' click_button 'Create' @@ -43,6 +45,8 @@ feature %q{ product.reload product.distributors.sort.should == [@distributors[0], @distributors[2]].sort + + product.product_distributions.map { |pd| pd.enterprise_fee }.sort.should == [@enterprise_fees[0], @enterprise_fees[2]].sort end @@ -55,6 +59,7 @@ feature %q{ fill_in 'product_name', :with => 'A new product !!!' fill_in 'product_price', :with => '19.99' + select taxon.name, from: "product_primary_taxon_id" select 'New supplier', :from => 'product_supplier_id' choose 'product_group_buy_1' fill_in 'Group buy unit size', :with => '10' @@ -99,6 +104,7 @@ feature %q{ page.should have_selector('#product_supplier_id') select 'Another Supplier', :from => 'product_supplier_id' + select taxon.name, from: "product_primary_taxon_id" # Should only have suppliers listed which the user can manage within "#product_supplier_id" do From 2db63540eee3194825e2ed39785484f81c880c56 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 23 May 2014 16:01:24 +1000 Subject: [PATCH 25/32] Adding primary taxon --- app/overrides/add_primary_taxon_to_admin_product.rb | 4 ++++ app/overrides/add_primary_taxon_to_admin_product_new.rb | 4 ++++ app/views/spree/admin/products/_primary_taxon_form.html.haml | 5 +++++ 3 files changed, 13 insertions(+) create mode 100644 app/overrides/add_primary_taxon_to_admin_product.rb create mode 100644 app/overrides/add_primary_taxon_to_admin_product_new.rb create mode 100644 app/views/spree/admin/products/_primary_taxon_form.html.haml diff --git a/app/overrides/add_primary_taxon_to_admin_product.rb b/app/overrides/add_primary_taxon_to_admin_product.rb new file mode 100644 index 0000000000..9f7c5edde5 --- /dev/null +++ b/app/overrides/add_primary_taxon_to_admin_product.rb @@ -0,0 +1,4 @@ +Deface::Override.new(:virtual_path => "spree/admin/products/_form", + :insert_top => "[data-hook='admin_product_form_right']", + :partial => "spree/admin/products/primary_taxon_form", + :name => "add_primary_taxon_to_admin_product") diff --git a/app/overrides/add_primary_taxon_to_admin_product_new.rb b/app/overrides/add_primary_taxon_to_admin_product_new.rb new file mode 100644 index 0000000000..e5c9d24e7f --- /dev/null +++ b/app/overrides/add_primary_taxon_to_admin_product_new.rb @@ -0,0 +1,4 @@ +Deface::Override.new(:virtual_path => "spree/admin/products/new", + :insert_before => "[data-hook='new_product_attrs']", + :partial => "spree/admin/products/primary_taxon_form", + :name => "add_primary_taxon_to_admin_product_new") diff --git a/app/views/spree/admin/products/_primary_taxon_form.html.haml b/app/views/spree/admin/products/_primary_taxon_form.html.haml new file mode 100644 index 0000000000..a844f4f447 --- /dev/null +++ b/app/views/spree/admin/products/_primary_taxon_form.html.haml @@ -0,0 +1,5 @@ += f.field_container :primary_taxon_id do + = f.label :primary_taxon_id + %br + = f.collection_select(:primary_taxon_id, Spree::Taxon.all, :id, :name, {:include_blank => true}, {:class => "select2 fullwidth"}) + = f.error_message_on :primary_taxon_id From e6461ba01eb374e3e7a82d045516393836e9bea8 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Sat, 24 May 2014 10:34:22 +1000 Subject: [PATCH 26/32] Fix enterprises spec - primary taxons change --- spec/models/enterprise_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index f375b8890a..fac9286d9b 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -422,8 +422,8 @@ describe Enterprise do let(:supplier) { create(:supplier_enterprise) } let(:taxon1) { create(:taxon) } let(:taxon2) { create(:taxon) } - let(:product1) { create(:simple_product, taxons: [taxon1]) } - let(:product2) { create(:simple_product, taxons: [taxon1, taxon2]) } + let(:product1) { create(:simple_product, primary_taxon: taxon1, taxons: [taxon1]) } + let(:product2) { create(:simple_product, primary_taxon: taxon1, taxons: [taxon1, taxon2]) } it "gets all taxons of all distributed products" do Spree::Product.stub(:in_distributor).and_return [product1, product2] From acbe49b8dea8e7bd1c8c3a91e98fd40930ed946b Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Sat, 24 May 2014 17:11:36 +1000 Subject: [PATCH 27/32] Revert primary taxons --- app/models/enterprise.rb | 1 - app/models/spree/classification_decorator.rb | 10 ---------- app/models/spree/product_decorator.rb | 13 +++++-------- .../add_primary_taxon_to_admin_product.rb | 4 ---- .../add_primary_taxon_to_admin_product_new.rb | 4 ---- .../_form/add_notes_field.html.haml.deface | 1 + .../admin/products/_primary_taxon_form.html.haml | 5 ----- ...0140522044009_add_primary_taxon_to_products.rb | 7 ------- db/schema.rb | 5 +---- spec/factories.rb | 7 ------- spec/features/admin/products_spec.rb | 6 ------ spec/models/enterprise_spec.rb | 4 ++-- spec/models/spree/classification_spec.rb | 15 --------------- spec/models/spree/product_spec.rb | 11 ++--------- 14 files changed, 11 insertions(+), 82 deletions(-) delete mode 100644 app/models/spree/classification_decorator.rb delete mode 100644 app/overrides/add_primary_taxon_to_admin_product.rb delete mode 100644 app/overrides/add_primary_taxon_to_admin_product_new.rb delete mode 100644 app/views/spree/admin/products/_primary_taxon_form.html.haml delete mode 100644 db/migrate/20140522044009_add_primary_taxon_to_products.rb delete mode 100644 spec/models/spree/classification_spec.rb diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 5e53316607..a72c6fdbd6 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -15,7 +15,6 @@ class Enterprise < ActiveRecord::Base has_and_belongs_to_many :payment_methods, join_table: 'distributors_payment_methods', class_name: 'Spree::PaymentMethod', foreign_key: 'distributor_id' has_and_belongs_to_many :shipping_methods, join_table: 'distributors_shipping_methods', class_name: 'Spree::ShippingMethod', foreign_key: 'distributor_id' - delegate :latitude, :longitude, :city, :state_name, :to => :address accepts_nested_attributes_for :address diff --git a/app/models/spree/classification_decorator.rb b/app/models/spree/classification_decorator.rb deleted file mode 100644 index 7e34e6890e..0000000000 --- a/app/models/spree/classification_decorator.rb +++ /dev/null @@ -1,10 +0,0 @@ -Spree::Classification.class_eval do - before_destroy :dont_destroy_if_primary_taxon - - def dont_destroy_if_primary_taxon - if product.primary_taxon == taxon - errors.add :base, "Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted" - return false - end - end -end diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 13491f94df..ba7cbc253d 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -6,7 +6,6 @@ Spree::Product.class_eval do belongs_to :supplier, :class_name => 'Enterprise' - belongs_to :primary_taxon, class_name: 'Spree::Taxon' has_many :product_distributions, :dependent => :destroy has_many :distributors, :through => :product_distributions @@ -14,10 +13,9 @@ Spree::Product.class_eval do accepts_nested_attributes_for :product_distributions, :allow_destroy => true delegate_belongs_to :master, :unit_value, :unit_description - attr_accessible :supplier_id, :primary_taxon_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size, :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value, :unit_description, :notes + attr_accessible :supplier_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size, :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value, :unit_description, :notes validates_presence_of :supplier - validates_presence_of :primary_taxon validates_presence_of :variant_unit, if: :has_variants? validates_presence_of :variant_unit_scale, @@ -27,7 +25,6 @@ Spree::Product.class_eval do after_initialize :set_available_on_to_now, :if => :new_record? after_save :update_units - before_save :add_primary_taxon_to_taxons # -- Joins @@ -121,6 +118,10 @@ Spree::Product.class_eval do order_cycle.variants_distributed_by(distributor).where(product_id: self) end + def primary_taxon + self.taxons.order.first + end + # Build a product distribution for each distributor def build_product_distributions_for_user user Enterprise.is_distributor.managed_by(user).each do |distributor| @@ -156,10 +157,6 @@ Spree::Product.class_eval do end end - def add_primary_taxon_to_taxons - taxons << primary_taxon unless taxons.find_by_id(primary_taxon) - end - def self.all_variant_unit_option_types Spree::OptionType.where('name LIKE ?', 'unit_%%') end diff --git a/app/overrides/add_primary_taxon_to_admin_product.rb b/app/overrides/add_primary_taxon_to_admin_product.rb deleted file mode 100644 index 9f7c5edde5..0000000000 --- a/app/overrides/add_primary_taxon_to_admin_product.rb +++ /dev/null @@ -1,4 +0,0 @@ -Deface::Override.new(:virtual_path => "spree/admin/products/_form", - :insert_top => "[data-hook='admin_product_form_right']", - :partial => "spree/admin/products/primary_taxon_form", - :name => "add_primary_taxon_to_admin_product") diff --git a/app/overrides/add_primary_taxon_to_admin_product_new.rb b/app/overrides/add_primary_taxon_to_admin_product_new.rb deleted file mode 100644 index e5c9d24e7f..0000000000 --- a/app/overrides/add_primary_taxon_to_admin_product_new.rb +++ /dev/null @@ -1,4 +0,0 @@ -Deface::Override.new(:virtual_path => "spree/admin/products/new", - :insert_before => "[data-hook='new_product_attrs']", - :partial => "spree/admin/products/primary_taxon_form", - :name => "add_primary_taxon_to_admin_product_new") diff --git a/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface b/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface index dcc7937d6b..dadebd01d4 100644 --- a/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface +++ b/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface @@ -4,3 +4,4 @@ = f.label :notes, t(:notes) = f.text_area :notes, { :class => 'fullwidth', rows: 5 } = f.error_message_on :notes + diff --git a/app/views/spree/admin/products/_primary_taxon_form.html.haml b/app/views/spree/admin/products/_primary_taxon_form.html.haml deleted file mode 100644 index a844f4f447..0000000000 --- a/app/views/spree/admin/products/_primary_taxon_form.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -= f.field_container :primary_taxon_id do - = f.label :primary_taxon_id - %br - = f.collection_select(:primary_taxon_id, Spree::Taxon.all, :id, :name, {:include_blank => true}, {:class => "select2 fullwidth"}) - = f.error_message_on :primary_taxon_id diff --git a/db/migrate/20140522044009_add_primary_taxon_to_products.rb b/db/migrate/20140522044009_add_primary_taxon_to_products.rb deleted file mode 100644 index f6ff3cfe96..0000000000 --- a/db/migrate/20140522044009_add_primary_taxon_to_products.rb +++ /dev/null @@ -1,7 +0,0 @@ -class AddPrimaryTaxonToProducts < ActiveRecord::Migration - def change - add_column :spree_products, :primary_taxon_id, :integer - add_index :spree_products, :primary_taxon_id - add_foreign_key :spree_products, :spree_taxons, column: :primary_taxon_id - end -end diff --git a/db/schema.rb b/db/schema.rb index 6005fd7cb5..77df8baf75 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140522044009) do +ActiveRecord::Schema.define(:version => 20140522015012) do create_table "adjustment_metadata", :force => true do |t| t.integer "adjustment_id" @@ -681,7 +681,6 @@ ActiveRecord::Schema.define(:version => 20140522044009) do t.float "variant_unit_scale" t.string "variant_unit_name" t.text "notes" - t.integer "primary_taxon_id" end add_index "spree_products", ["available_on"], :name => "index_products_on_available_on" @@ -689,7 +688,6 @@ ActiveRecord::Schema.define(:version => 20140522044009) do add_index "spree_products", ["name"], :name => "index_products_on_name" add_index "spree_products", ["permalink"], :name => "index_products_on_permalink" add_index "spree_products", ["permalink"], :name => "permalink_idx_unique", :unique => true - add_index "spree_products", ["primary_taxon_id"], :name => "index_spree_products_on_primary_taxon_id" create_table "spree_products_promotion_rules", :id => false, :force => true do |t| t.integer "product_id" @@ -1094,7 +1092,6 @@ ActiveRecord::Schema.define(:version => 20140522044009) do add_foreign_key "spree_products", "enterprises", name: "spree_products_supplier_id_fk", column: "supplier_id" add_foreign_key "spree_products", "spree_shipping_categories", name: "spree_products_shipping_category_id_fk", column: "shipping_category_id" add_foreign_key "spree_products", "spree_tax_categories", name: "spree_products_tax_category_id_fk", column: "tax_category_id" - add_foreign_key "spree_products", "spree_taxons", name: "spree_products_primary_taxon_id_fk", column: "primary_taxon_id" add_foreign_key "spree_products_promotion_rules", "spree_products", name: "spree_products_promotion_rules_product_id_fk", column: "product_id" add_foreign_key "spree_products_promotion_rules", "spree_promotion_rules", name: "spree_products_promotion_rules_promotion_rule_id_fk", column: "promotion_rule_id" diff --git a/spec/factories.rb b/spec/factories.rb index 394112125a..6da7824d47 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -2,9 +2,6 @@ require 'ffaker' require 'spree/core/testing_support/factories' FactoryGirl.define do - factory :classification, class: Spree::Classification do - end - factory :order_cycle, :parent => :simple_order_cycle do coordinator_fees { [create(:enterprise_fee, enterprise: coordinator)] } @@ -153,9 +150,6 @@ end FactoryGirl.modify do - factory :product do - primary_taxon { Spree::Taxon.first || FactoryGirl.create(:taxon) } - end factory :simple_product do # Fix product factory name sequence with Kernel.rand so it is not interpreted as a Spree::Product method # Pull request: https://github.com/spree/spree/pull/1964 @@ -163,7 +157,6 @@ FactoryGirl.modify do sequence(:name) { |n| "Product ##{n} - #{Kernel.rand(9999)}" } supplier { Enterprise.is_primary_producer.first || FactoryGirl.create(:supplier_enterprise) } - primary_taxon { Spree::Taxon.first || FactoryGirl.create(:taxon) } on_hand 3 variant_unit 'weight' diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index b9fec1ef9f..b9f9d7a206 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -6,7 +6,6 @@ feature %q{ } do include AuthenticationWorkflow include WebHelper - let!(:taxon) { create(:taxon) } background do @supplier = create(:supplier_enterprise, :name => 'New supplier') @@ -23,7 +22,6 @@ feature %q{ fill_in 'product_name', with: 'A new product !!!' fill_in 'product_price', with: '19.99' - select taxon.name, from: "product_primary_taxon_id" select 'New supplier', from: 'product_supplier_id' click_button 'Create' @@ -45,8 +43,6 @@ feature %q{ product.reload product.distributors.sort.should == [@distributors[0], @distributors[2]].sort - - product.product_distributions.map { |pd| pd.enterprise_fee }.sort.should == [@enterprise_fees[0], @enterprise_fees[2]].sort end @@ -59,7 +55,6 @@ feature %q{ fill_in 'product_name', :with => 'A new product !!!' fill_in 'product_price', :with => '19.99' - select taxon.name, from: "product_primary_taxon_id" select 'New supplier', :from => 'product_supplier_id' choose 'product_group_buy_1' fill_in 'Group buy unit size', :with => '10' @@ -104,7 +99,6 @@ feature %q{ page.should have_selector('#product_supplier_id') select 'Another Supplier', :from => 'product_supplier_id' - select taxon.name, from: "product_primary_taxon_id" # Should only have suppliers listed which the user can manage within "#product_supplier_id" do diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index fac9286d9b..f375b8890a 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -422,8 +422,8 @@ describe Enterprise do let(:supplier) { create(:supplier_enterprise) } let(:taxon1) { create(:taxon) } let(:taxon2) { create(:taxon) } - let(:product1) { create(:simple_product, primary_taxon: taxon1, taxons: [taxon1]) } - let(:product2) { create(:simple_product, primary_taxon: taxon1, taxons: [taxon1, taxon2]) } + let(:product1) { create(:simple_product, taxons: [taxon1]) } + let(:product2) { create(:simple_product, taxons: [taxon1, taxon2]) } it "gets all taxons of all distributed products" do Spree::Product.stub(:in_distributor).and_return [product1, product2] diff --git a/spec/models/spree/classification_spec.rb b/spec/models/spree/classification_spec.rb deleted file mode 100644 index f26f6da0c0..0000000000 --- a/spec/models/spree/classification_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -module Spree - describe Classification do - let(:product) { create(:simple_product) } - let(:taxon) { create(:taxon) } - let(:classification) { create(:classification, taxon: taxon, product: product) } - - it "won't destroy if classification is the primary taxon" do - product.primary_taxon = taxon - classification.destroy.should be_false - classification.errors.messages[:base].should == ["Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted"] - end - end -end diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 6a50190448..6d90b70761 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -5,7 +5,6 @@ module Spree describe "associations" do it { should belong_to(:supplier) } - it { should belong_to(:primary_taxon) } it { should have_many(:product_distributions) } end @@ -14,12 +13,6 @@ module Spree create(:product).should be_valid end - it "requires a primary taxon" do - product = create(:simple_product) - product.primary_taxon = nil - product.should_not be_valid - end - it "requires a supplier" do product = create(:simple_product) product.supplier = nil @@ -558,10 +551,10 @@ module Spree describe "Taxons" do let(:taxon1) { create(:taxon) } let(:taxon2) { create(:taxon) } - let(:product) { create(:simple_product) } + let(:product) { create(:simple_product, taxons: [taxon1, taxon2]) } it "returns the first taxon as the primary taxon" do - product.taxons.should == [product.primary_taxon] + product.primary_taxon.should == taxon1 end end end From 403e957111a594bbb7a07219b5705e5af5d52574 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Sat, 24 May 2014 11:14:14 +1000 Subject: [PATCH 28/32] Further removal of references to 'Admin' from global namespace --- .../controllers/enterprise_relationships_controller.js.coffee | 2 +- .../admin/services/enterprise_relationships.js.coffee | 2 +- app/assets/javascripts/admin/services/enterprises.js.coffee | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/admin/controllers/enterprise_relationships_controller.js.coffee b/app/assets/javascripts/admin/controllers/enterprise_relationships_controller.js.coffee index c66e79c046..665753a522 100644 --- a/app/assets/javascripts/admin/controllers/enterprise_relationships_controller.js.coffee +++ b/app/assets/javascripts/admin/controllers/enterprise_relationships_controller.js.coffee @@ -1,4 +1,4 @@ -Admin.controller "AdminEnterpriseRelationshipsCtrl", ($scope, EnterpriseRelationships, Enterprises) -> +angular.module("ofn.admin").controller "AdminEnterpriseRelationshipsCtrl", ($scope, EnterpriseRelationships, Enterprises) -> $scope.EnterpriseRelationships = EnterpriseRelationships $scope.Enterprises = Enterprises diff --git a/app/assets/javascripts/admin/services/enterprise_relationships.js.coffee b/app/assets/javascripts/admin/services/enterprise_relationships.js.coffee index 0469aa5637..e07b992112 100644 --- a/app/assets/javascripts/admin/services/enterprise_relationships.js.coffee +++ b/app/assets/javascripts/admin/services/enterprise_relationships.js.coffee @@ -1,4 +1,4 @@ -Admin.factory 'EnterpriseRelationships', ($http, enterprise_relationships) -> +angular.module("ofn.admin").factory 'EnterpriseRelationships', ($http, enterprise_relationships) -> new class EnterpriseRelationships create_errors: "" diff --git a/app/assets/javascripts/admin/services/enterprises.js.coffee b/app/assets/javascripts/admin/services/enterprises.js.coffee index 778a915c22..5b5fd6a009 100644 --- a/app/assets/javascripts/admin/services/enterprises.js.coffee +++ b/app/assets/javascripts/admin/services/enterprises.js.coffee @@ -1,4 +1,4 @@ -Admin.factory 'Enterprises', (my_enterprises, all_enterprises) -> +angular.module("ofn.admin").factory 'Enterprises', (my_enterprises, all_enterprises) -> new class Enterprises constructor: -> @my_enterprises = my_enterprises From cc2498bb9bae1f514217aa8686b6cc7d02bbb0b4 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Sat, 24 May 2014 18:26:02 +1000 Subject: [PATCH 29/32] Fix spec fails - group buy and available on removed from new product form --- spec/features/admin/bulk_product_update_spec.rb | 2 -- spec/features/admin/products_spec.rb | 15 ++++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index 7174da9758..d89280df80 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -236,9 +236,7 @@ feature %q{ fill_in 'product_name', :with => 'Big Bag Of Apples' select(s.name, :from => 'product_supplier_id') - choose('product_group_buy_0') fill_in 'product_price', :with => '10.00' - fill_in 'product_available_on', :with => Date.today.strftime("%Y/%m/%d") click_button 'Create' URI.parse(current_url).path.should == '/admin/products/bulk_edit' diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index b9f9d7a206..efe531224d 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -46,23 +46,20 @@ feature %q{ product.product_distributions.map { |pd| pd.enterprise_fee }.sort.should == [@enterprise_fees[0], @enterprise_fees[2]].sort end + scenario "making a product into a group buy product" do + product = create(:simple_product, name: 'group buy product') - scenario "creating a group buy product" do login_to_admin_section - click_link 'Products' - click_link 'New Product' + visit spree.edit_admin_product_path(product) - fill_in 'product_name', :with => 'A new product !!!' - fill_in 'product_price', :with => '19.99' - select 'New supplier', :from => 'product_supplier_id' choose 'product_group_buy_1' fill_in 'Group buy unit size', :with => '10' - click_button 'Create' + click_button 'Update' - flash_message.should == 'Product "A new product !!!" has been successfully created!' - product = Spree::Product.find_by_name('A new product !!!') + flash_message.should == 'Product "group buy product" has been successfully updated!' + product.reload product.group_buy.should be_true product.group_buy_unit_size.should == 10.0 end From 09ce8697afda30a890323c62a66b8285842c20c0 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 28 May 2014 16:55:04 +1000 Subject: [PATCH 30/32] Only trigger taxon search AJAX when column visible - fixes deadlocks in specs --- app/views/spree/admin/products/bulk_edit.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/spree/admin/products/bulk_edit.html.haml b/app/views/spree/admin/products/bulk_edit.html.haml index ee74fd9662..fa295adb47 100644 --- a/app/views/spree/admin/products/bulk_edit.html.haml +++ b/app/views/spree/admin/products/bulk_edit.html.haml @@ -132,7 +132,7 @@ %td{ 'ng-show' => 'columns.on_hand.visible' } %span{ 'ng-bind' => 'product.on_hand', :name => 'on_hand', 'ng-show' => '!hasOnDemandVariants(product) && (hasVariants(product) || product.on_demand)' } %input.field{ 'ng-model' => 'product.on_hand', :name => 'on_hand', 'ofn-track-product' => 'on_hand', 'ng-hide' => 'hasVariants(product) || product.on_demand', :type => 'number' } - %td{ 'ng-show' => 'columns.taxons.visible' } + %td{ 'ng-if' => 'columns.taxons.visible' } %input.fullwidth{ :type => 'text', 'ng-model' => 'product.taxon_ids', 'ofn-taxon-autocomplete' => '', 'ofn-track-product' => 'taxon_ids' } %td{ 'ng-show' => 'columns.available_on.visible' } %input{ 'ng-model' => 'product.available_on', :name => 'available_on', 'ofn-track-product' => 'available_on', 'datetimepicker' => 'product.available_on', type: "text" } From 2a630a855acda49a0abd17b1ed29c5ee9006d007 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 29 May 2014 09:28:08 +1000 Subject: [PATCH 31/32] Move primary taxon field into Rob's new product form --- .../add_primary_taxon_field.html.haml.deface | 3 +++ .../new/replace_form.html.haml.deface | 25 ++++++++++++------- .../products/_primary_taxon_form.html.haml | 5 ++++ 3 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 app/overrides/spree/admin/products/_form/add_primary_taxon_field.html.haml.deface create mode 100644 app/views/spree/admin/products/_primary_taxon_form.html.haml diff --git a/app/overrides/spree/admin/products/_form/add_primary_taxon_field.html.haml.deface b/app/overrides/spree/admin/products/_form/add_primary_taxon_field.html.haml.deface new file mode 100644 index 0000000000..efd7ccbfaf --- /dev/null +++ b/app/overrides/spree/admin/products/_form/add_primary_taxon_field.html.haml.deface @@ -0,0 +1,3 @@ +/ insert_top "[data-hook='admin_product_form_right']" + += render 'spree/admin/products/primary_taxon_form', f: f \ No newline at end of file diff --git a/app/overrides/spree/admin/products/new/replace_form.html.haml.deface b/app/overrides/spree/admin/products/new/replace_form.html.haml.deface index c752744ee6..e964e9a704 100644 --- a/app/overrides/spree/admin/products/new/replace_form.html.haml.deface +++ b/app/overrides/spree/admin/products/new/replace_form.html.haml.deface @@ -2,20 +2,25 @@ %fieldset{ id: "new_product" } %legend{align: "center"}= t(:new_product) + .row - = f.field_container :name do - = f.label :name, t(:name) - %span.required * - %br/ - = f.text_field :name, :class => 'fullwidth title' - = f.error_message_on :name - .row - .alpha.six.columns + .alpha.eleven.columns + = f.field_container :name do + = f.label :name, t(:name) + %span.required * + %br/ + = f.text_field :name, :class => 'fullwidth title' + = f.error_message_on :name + .five.columns.omega = f.field_container :supplier do = f.label :supplier %span.required * = f.collection_select(:supplier_id, Enterprise.is_primary_producer.managed_by(spree_current_user).by_name, :id, :name, {:include_blank => true}, {:class => "select2 fullwidth"}) = f.error_message_on :supplier + + .row + .alpha.six.columns + = render 'spree/admin/products/primary_taxon_form', f: f .five.columns = f.field_container :price do = f.label :price, t(:price) @@ -30,6 +35,7 @@ %br/ = f.text_field :on_hand, :class => 'fullwidth' = f.error_message_on :on_hand + .row{ 'ng-controller' => 'unitsCtrl' } .six.columns.alpha = f.label :variant_unit_with_scale, :units @@ -45,6 +51,7 @@ .five.columns.omega{ 'ng-show' => "product.variant_unit_with_scale == 'items'" } = f.label :product_variant_unit_name, :unit_name %input.fullwidth{ id: 'product_variant_unit_name','ng-model' => 'product.variant_unit_name', :name => 'product[variant_unit_name]', :placeholder => 'eg. bunches', :type => 'text' } + #product-from-prototype.clearfix{"data-hook" => "product-from-prototype"} = render :file => 'spree/admin/prototypes/show' if @prototype = render :partial => 'spree/admin/shared/new_resource_links' @@ -53,4 +60,4 @@ :javascript angular.element(document.getElementById("new_product")).ready(function() { angular.bootstrap(document.getElementById("new_product"), ['admin.products']); - }); \ No newline at end of file + }); diff --git a/app/views/spree/admin/products/_primary_taxon_form.html.haml b/app/views/spree/admin/products/_primary_taxon_form.html.haml new file mode 100644 index 0000000000..a844f4f447 --- /dev/null +++ b/app/views/spree/admin/products/_primary_taxon_form.html.haml @@ -0,0 +1,5 @@ += f.field_container :primary_taxon_id do + = f.label :primary_taxon_id + %br + = f.collection_select(:primary_taxon_id, Spree::Taxon.all, :id, :name, {:include_blank => true}, {:class => "select2 fullwidth"}) + = f.error_message_on :primary_taxon_id From fdff442ec66e814a2fdae0973a212a099f5d28f5 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 29 May 2014 10:54:08 +1000 Subject: [PATCH 32/32] Do not fetch products JSON on every shopping page --- .../order_cycle_controller.js.coffee | 14 ++++++++------ .../darkswarm/services/order.js.coffee | 2 +- .../darkswarm/services/order_cycle.js.coffee | 6 +++--- .../darkswarm/services/product.js.coffee | 2 +- app/views/shop/show.html.haml | 19 ++++++++++--------- .../shopping_shared/_order_cycles.html.haml | 2 -- 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/darkswarm/controllers/order_cycle_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/order_cycle_controller.js.coffee index 29e81ae861..555e49c539 100644 --- a/app/assets/javascripts/darkswarm/controllers/order_cycle_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/order_cycle_controller.js.coffee @@ -1,15 +1,17 @@ -Darkswarm.controller "OrderCycleCtrl", ($scope, $rootScope, OrderCycle, $timeout) -> +Darkswarm.controller "OrderCycleCtrl", ($scope, OrderCycle, $timeout) -> $scope.order_cycle = OrderCycle.order_cycle $scope.OrderCycle = OrderCycle - $scope.changeOrderCycle = -> - OrderCycle.push_order_cycle() - $timeout -> - $("#order_cycle_id").trigger("closeTrigger") - # Timeout forces this to be evaluated after everything is loaded # This is a hack. We should probably write our own "popover" directive # That takes an expression instead of a trigger, and binds to that $timeout => if !$scope.OrderCycle.selected() $("#order_cycle_id").trigger("openTrigger") + + +Darkswarm.controller "OrderCycleChangeCtrl", ($scope, OrderCycle, Product, $timeout) -> + $scope.changeOrderCycle = -> + OrderCycle.push_order_cycle Product.update + $timeout -> + $("#order_cycle_id").trigger("closeTrigger") diff --git a/app/assets/javascripts/darkswarm/services/order.js.coffee b/app/assets/javascripts/darkswarm/services/order.js.coffee index 2357fd42da..8078cf8fc3 100644 --- a/app/assets/javascripts/darkswarm/services/order.js.coffee +++ b/app/assets/javascripts/darkswarm/services/order.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.factory 'Order', ($resource, Product, order, $http, CheckoutFormState, flash, Navigation)-> +Darkswarm.factory 'Order', ($resource, order, $http, CheckoutFormState, flash, Navigation)-> new class Order errors: {} diff --git a/app/assets/javascripts/darkswarm/services/order_cycle.js.coffee b/app/assets/javascripts/darkswarm/services/order_cycle.js.coffee index 1bb23446a2..0c5176328b 100644 --- a/app/assets/javascripts/darkswarm/services/order_cycle.js.coffee +++ b/app/assets/javascripts/darkswarm/services/order_cycle.js.coffee @@ -1,10 +1,10 @@ -Darkswarm.factory 'OrderCycle', ($resource, Product, orderCycleData) -> +Darkswarm.factory 'OrderCycle', ($resource, orderCycleData) -> class OrderCycle @order_cycle = orderCycleData # Object or {} due to RABL - @push_order_cycle: -> + @push_order_cycle: (callback) -> new $resource("/shop/order_cycle").save {order_cycle_id: @order_cycle.order_cycle_id}, (order_data)-> OrderCycle.order_cycle.orders_close_at = order_data.orders_close_at - Product.update() + callback() @orders_close_at: -> @order_cycle.orders_close_at if @selected() diff --git a/app/assets/javascripts/darkswarm/services/product.js.coffee b/app/assets/javascripts/darkswarm/services/product.js.coffee index e58b83bacc..406e122de1 100644 --- a/app/assets/javascripts/darkswarm/services/product.js.coffee +++ b/app/assets/javascripts/darkswarm/services/product.js.coffee @@ -9,7 +9,7 @@ Darkswarm.factory 'Product', ($resource) -> products: null loading: true - update: -> + update: => @data.products = $resource("/shop/products").query => @data.loading = false @data diff --git a/app/views/shop/show.html.haml b/app/views/shop/show.html.haml index b94bd59bf9..d4b36a5e29 100644 --- a/app/views/shop/show.html.haml +++ b/app/views/shop/show.html.haml @@ -1,19 +1,20 @@ %shop.darkswarm - content_for :order_cycle_form do - %strong.avenir Ready for - %select.avenir#order_cycle_id{"ng-model" => "order_cycle.order_cycle_id", - "ng-change" => "changeOrderCycle()", - "ng-options" => "oc.id as oc.time for oc in #{@order_cycles.map {|oc| {time: pickup_time(oc), id: oc.id}}.to_json}", - "popover-placement" => "bottom", "popover" => "When do you want to get your order?", "popover-trigger" => "openTrigger"} + %div{"ng-controller" => "OrderCycleChangeCtrl"} + %strong.avenir Ready for + %select.avenir#order_cycle_id{"ng-model" => "order_cycle.order_cycle_id", + "ng-change" => "changeOrderCycle()", + "ng-options" => "oc.id as oc.time for oc in #{@order_cycles.map {|oc| {time: pickup_time(oc), id: oc.id}}.to_json}", + "popover-placement" => "bottom", "popover" => "When do you want to get your order?", "popover-trigger" => "openTrigger"} - %closing{"ng-if" => "OrderCycle.selected()"} - Orders close - %strong {{ OrderCycle.orders_close_at() | date_in_words }} + %closing{"ng-if" => "OrderCycle.selected()"} + Orders close + %strong {{ OrderCycle.orders_close_at() | date_in_words }} = render partial: "shopping_shared/details" .row = render partial: "shop/products/form" -= render partial: "shared/footer" \ No newline at end of file += render partial: "shared/footer" diff --git a/app/views/shopping_shared/_order_cycles.html.haml b/app/views/shopping_shared/_order_cycles.html.haml index 91517e0c1c..195389df91 100644 --- a/app/views/shopping_shared/_order_cycles.html.haml +++ b/app/views/shopping_shared/_order_cycles.html.haml @@ -14,5 +14,3 @@ - else %form.custom = yield :order_cycle_form - -