From d4cf44a6dd09eac9b66bcae448abefd9d02ac2a8 Mon Sep 17 00:00:00 2001 From: Paul Mackay Date: Sun, 29 Mar 2015 17:06:05 +0100 Subject: [PATCH 01/36] Use COUNTRY_CODE instead of COUNTRY in application.yml. --- config/application.yml.example | 2 +- config/initializers/spree.rb | 2 +- ...50936_add_address_instances_to_existing_enterprise_groups.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/application.yml.example b/config/application.yml.example index f953cb4601..9eba8eb6ee 100644 --- a/config/application.yml.example +++ b/config/application.yml.example @@ -6,7 +6,7 @@ SECRET_TOKEN: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx TIMEZONE: Melbourne # Default country for dropdowns etc. -DEFAULT_COUNTRY: Australia +DEFAULT_COUNTRY_CODE: AU # Locale for translation. LOCALE: en # Spree zone. diff --git a/config/initializers/spree.rb b/config/initializers/spree.rb index a28763f289..a6a045222d 100644 --- a/config/initializers/spree.rb +++ b/config/initializers/spree.rb @@ -17,7 +17,7 @@ Spree.config do |config| config.checkout_zone = ENV["CHECKOUT_ZONE"] config.currency = ENV['CURRENCY'] if Spree::Country.table_exists? - country = Spree::Country.find_by_name(ENV["DEFAULT_COUNTRY"]) + country = Spree::Country.find_by_iso(ENV['DEFAULT_COUNTRY_CODE']) config.default_country_id = country.id if country.present? else config.default_country_id = 12 # Australia diff --git a/db/migrate/20150115050936_add_address_instances_to_existing_enterprise_groups.rb b/db/migrate/20150115050936_add_address_instances_to_existing_enterprise_groups.rb index 23fc038ce8..3b93ee6386 100644 --- a/db/migrate/20150115050936_add_address_instances_to_existing_enterprise_groups.rb +++ b/db/migrate/20150115050936_add_address_instances_to_existing_enterprise_groups.rb @@ -1,6 +1,6 @@ class AddAddressInstancesToExistingEnterpriseGroups < ActiveRecord::Migration def change - country = Spree::Country.find_by_name(ENV['DEFAULT_COUNTRY']) + country = Spree::Country.find_by_iso(ENV['DEFAULT_COUNTRY_CODE']) state = country.states.first EnterpriseGroup.all.each do |g| next if g.address.present? From 35536a629ce2a6ee32fc74096c98af35f6c460d8 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 10:28:01 +1000 Subject: [PATCH 02/36] Set execute bit --- script/delayed_job.sh | 0 script/prepare_imported_db.rb | 0 script/save_staging_baseline.sh | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 script/delayed_job.sh mode change 100644 => 100755 script/prepare_imported_db.rb mode change 100644 => 100755 script/save_staging_baseline.sh diff --git a/script/delayed_job.sh b/script/delayed_job.sh old mode 100644 new mode 100755 diff --git a/script/prepare_imported_db.rb b/script/prepare_imported_db.rb old mode 100644 new mode 100755 diff --git a/script/save_staging_baseline.sh b/script/save_staging_baseline.sh old mode 100644 new mode 100755 From 7d4a4f8f9d8885f87de4cbe8144b0bab0a4dc8fc Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 12:37:06 +1000 Subject: [PATCH 03/36] Pushing to staging first loads staging baseline data --- script/load_staging_baseline.sh | 26 ++++++++++++++++++++++++++ script/push_to_staging.sh | 5 +++++ 2 files changed, 31 insertions(+) create mode 100644 script/load_staging_baseline.sh diff --git a/script/load_staging_baseline.sh b/script/load_staging_baseline.sh new file mode 100644 index 0000000000..0a59b66d3b --- /dev/null +++ b/script/load_staging_baseline.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Every time staging is deployed, we load a baseline data set before running the new code's +# migrations. This script loads the baseline data set, after first taking a backup of the +# current database. + +set -e + +cd /home/openfoodweb/apps/openfoodweb/current + +echo "Stopping unicorn..." +service unicorn_openfoodweb stop + +echo "Backing up current data..." +mkdir -p db/backup +pg_dump -h localhost -U openfoodweb openfoodweb_production |gzip > db/backup/staging-`date +%Y%m%d%H%M%S`.sql.gz + +echo "Loading baseline data..." +dropdb -U openfoodweb -w openfoodweb_production +createdb -U openfoodweb -w openfoodweb_production +gunzip -c db/backup/staging-baseline.sql.gz |psql -h localhost -U openfoodweb openfoodweb_production + +echo "Restarting unicorn..." +service unicorn_openfoodweb start + +echo "Done!" diff --git a/script/push_to_staging.sh b/script/push_to_staging.sh index e3a16ebb3b..c2c176bb2a 100755 --- a/script/push_to_staging.sh +++ b/script/push_to_staging.sh @@ -2,9 +2,14 @@ set -e +# Add staging git remote if required ST2_TEST=`git remote | grep -s 'staging2' || true` if [[ "$ST2_TEST" != *staging2* ]]; then git remote add staging2 openfoodweb@ofn-staging2:apps/openfoodweb/current fi +echo "--- Loading baseline data" +ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/load_staging_baseline.sh" + +echo "--- Pushing to staging" [[ $(git push staging2 $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]] From d406f9ccdf599b630b547d4f6dba7ae4e3ffd6d3 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 13:14:51 +1000 Subject: [PATCH 04/36] Tests fail unless master has been merged into current branch --- script/includes.sh | 6 ++++++ script/run_tests.sh | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 script/includes.sh diff --git a/script/includes.sh b/script/includes.sh new file mode 100644 index 0000000000..1b0519f940 --- /dev/null +++ b/script/includes.sh @@ -0,0 +1,6 @@ +function exit_unless_master_merged { + if [[ `git branch -a --merged $BUILDKITE_BRANCH` != *origin/master* ]]; then + echo "This branch does not have the current master merged. Please merge master and push again." + exit 1 + fi +} diff --git a/script/run_tests.sh b/script/run_tests.sh index 461ca4ecd8..616d454e5d 100755 --- a/script/run_tests.sh +++ b/script/run_tests.sh @@ -3,11 +3,15 @@ set -e echo "--- Loading environment" +source ./script/includes.sh source /var/lib/jenkins/.rvm/environments/ruby-1.9.3-p392 if [ ! -f config/application.yml ]; then ln -s application.yml.example config/application.yml fi +echo "--- Verifying branch is based on current master" +exit_unless_master_merged + echo "--- Bundling" bundle install From 53c4c8b5b7f4b18ba3227b6330b08eea2b9cceaf Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 13:16:39 +1000 Subject: [PATCH 05/36] Push to staging fails unless master has been merged into current branch --- script/push_to_staging.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/script/push_to_staging.sh b/script/push_to_staging.sh index c2c176bb2a..75bccd6e09 100755 --- a/script/push_to_staging.sh +++ b/script/push_to_staging.sh @@ -1,6 +1,7 @@ #!/bin/bash set -e +source ./script/includes.sh # Add staging git remote if required ST2_TEST=`git remote | grep -s 'staging2' || true` @@ -8,6 +9,9 @@ if [[ "$ST2_TEST" != *staging2* ]]; then git remote add staging2 openfoodweb@ofn-staging2:apps/openfoodweb/current fi +echo "--- Verifying branch is based on current master" +exit_unless_master_merged + echo "--- Loading baseline data" ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/load_staging_baseline.sh" From 1c9a95b3d6094e0dde6bfd5b49f6f51d2939b390 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 13:19:17 +1000 Subject: [PATCH 06/36] Set execute bit --- script/load_staging_baseline.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 script/load_staging_baseline.sh diff --git a/script/load_staging_baseline.sh b/script/load_staging_baseline.sh old mode 100644 new mode 100755 From 6c81109b17945167e171640e2daf88b99b0f0c50 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 14:17:07 +1000 Subject: [PATCH 07/36] Local branch isn't checked out, so we need to test remote branch --- script/includes.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/includes.sh b/script/includes.sh index 1b0519f940..06713fc773 100644 --- a/script/includes.sh +++ b/script/includes.sh @@ -1,5 +1,5 @@ function exit_unless_master_merged { - if [[ `git branch -a --merged $BUILDKITE_BRANCH` != *origin/master* ]]; then + if [[ `git branch -a --merged origin/$BUILDKITE_BRANCH` != *origin/master* ]]; then echo "This branch does not have the current master merged. Please merge master and push again." exit 1 fi From 883a2e0a0e4fdda1909218aeb60d9cd6482ebe2c Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 14:29:59 +1000 Subject: [PATCH 08/36] WIP: Move CI scripts to their own folder --- script/{ => ci}/includes.sh | 0 script/{ => ci}/load_staging_baseline.sh | 0 script/{ => ci}/push_to_production.sh | 0 script/{ => ci}/push_to_staging.sh | 0 script/{ => ci}/run_tests.sh | 0 script/{ => ci}/save_staging_baseline.sh | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename script/{ => ci}/includes.sh (100%) rename script/{ => ci}/load_staging_baseline.sh (100%) rename script/{ => ci}/push_to_production.sh (100%) rename script/{ => ci}/push_to_staging.sh (100%) rename script/{ => ci}/run_tests.sh (100%) rename script/{ => ci}/save_staging_baseline.sh (100%) diff --git a/script/includes.sh b/script/ci/includes.sh similarity index 100% rename from script/includes.sh rename to script/ci/includes.sh diff --git a/script/load_staging_baseline.sh b/script/ci/load_staging_baseline.sh similarity index 100% rename from script/load_staging_baseline.sh rename to script/ci/load_staging_baseline.sh diff --git a/script/push_to_production.sh b/script/ci/push_to_production.sh similarity index 100% rename from script/push_to_production.sh rename to script/ci/push_to_production.sh diff --git a/script/push_to_staging.sh b/script/ci/push_to_staging.sh similarity index 100% rename from script/push_to_staging.sh rename to script/ci/push_to_staging.sh diff --git a/script/run_tests.sh b/script/ci/run_tests.sh similarity index 100% rename from script/run_tests.sh rename to script/ci/run_tests.sh diff --git a/script/save_staging_baseline.sh b/script/ci/save_staging_baseline.sh similarity index 100% rename from script/save_staging_baseline.sh rename to script/ci/save_staging_baseline.sh From 0c0be0112e83e2062474841e273e1b7c5ca02238 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 14:31:30 +1000 Subject: [PATCH 09/36] Update paths to include ci --- script/ci/push_to_production.sh | 2 +- script/ci/push_to_staging.sh | 4 ++-- script/ci/run_tests.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/script/ci/push_to_production.sh b/script/ci/push_to_production.sh index 72fa2a5edc..b731b538ca 100755 --- a/script/ci/push_to_production.sh +++ b/script/ci/push_to_production.sh @@ -9,7 +9,7 @@ if [[ "$PROD_TEST" != *production* ]]; then fi echo "--- Saving baseline data for staging" -ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/save_staging_baseline.sh $BUILDKITE_COMMIT" +ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/ci/save_staging_baseline.sh $BUILDKITE_COMMIT" echo "--- Pushing to production" [[ $(git push production $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]] diff --git a/script/ci/push_to_staging.sh b/script/ci/push_to_staging.sh index 75bccd6e09..582f500a76 100755 --- a/script/ci/push_to_staging.sh +++ b/script/ci/push_to_staging.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -source ./script/includes.sh +source ./script/ci/includes.sh # Add staging git remote if required ST2_TEST=`git remote | grep -s 'staging2' || true` @@ -13,7 +13,7 @@ echo "--- Verifying branch is based on current master" exit_unless_master_merged echo "--- Loading baseline data" -ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/load_staging_baseline.sh" +ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/ci/load_staging_baseline.sh" echo "--- Pushing to staging" [[ $(git push staging2 $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]] diff --git a/script/ci/run_tests.sh b/script/ci/run_tests.sh index 616d454e5d..0ccbc7421d 100755 --- a/script/ci/run_tests.sh +++ b/script/ci/run_tests.sh @@ -3,7 +3,7 @@ set -e echo "--- Loading environment" -source ./script/includes.sh +source ./script/ci/includes.sh source /var/lib/jenkins/.rvm/environments/ruby-1.9.3-p392 if [ ! -f config/application.yml ]; then ln -s application.yml.example config/application.yml From b9e3ff54b8a3ba2e2b895f1a73efa7ab5a7d040b Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 14:47:54 +1000 Subject: [PATCH 10/36] Add build script to merge to master --- script/ci/merge_branch_to_master.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 script/ci/merge_branch_to_master.sh diff --git a/script/ci/merge_branch_to_master.sh b/script/ci/merge_branch_to_master.sh new file mode 100755 index 0000000000..0bb07b43e2 --- /dev/null +++ b/script/ci/merge_branch_to_master.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e +source ./script/ci/includes.sh + +echo "--- Verifying branch is based on current master" +exit_unless_master_merged + +echo "--- Pushing branch" +echo git push origin $BUILDKITE_COMMIT:master From 28c79cdb50d47d505429d9e15f7da448e87858f5 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 21 Apr 2015 16:40:45 +1000 Subject: [PATCH 11/36] Use db:test:load instead of db:test:prepare in CI to avoid conflicts between branches --- script/ci/run_tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/ci/run_tests.sh b/script/ci/run_tests.sh index 0ccbc7421d..9fdbd11333 100755 --- a/script/ci/run_tests.sh +++ b/script/ci/run_tests.sh @@ -15,8 +15,8 @@ exit_unless_master_merged echo "--- Bundling" bundle install -echo "--- Preparing test database" -bundle exec rake db:test:prepare +echo "--- Loading test database" +bundle exec rake db:test:load echo "--- Running tests" bundle exec rspec spec --format progress From 7a78f4870a46e301cab28d0c6734308093ee1cca Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 16:33:44 +1000 Subject: [PATCH 12/36] Use phantomjs for js specs, so we can run them in CI --- config/ng-test.conf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/ng-test.conf.js b/config/ng-test.conf.js index f87aa3d48a..0456d5eb88 100644 --- a/config/ng-test.conf.js +++ b/config/ng-test.conf.js @@ -42,7 +42,7 @@ module.exports = function(config) { autoWatch: true, - browsers: ['Chrome'], + browsers: ['PhantomJS'], junitReporter: { outputFile: 'log/testacular-unit.xml', From 7aeeb6d18feb760bdbe2efb829fec874d5b10a0c Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 16:36:31 +1000 Subject: [PATCH 13/36] Add script to run JS specs in CI --- script/ci/run_js_tests.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 script/ci/run_js_tests.sh diff --git a/script/ci/run_js_tests.sh b/script/ci/run_js_tests.sh new file mode 100755 index 0000000000..91a4be09d9 --- /dev/null +++ b/script/ci/run_js_tests.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -e + +echo "--- Loading environment" +source ./script/ci/includes.sh +load_environment + +echo "--- Verifying branch is based on current master" +exit_unless_master_merged + +echo "--- Bundling" +bundle install + +echo "--- Running tests" +bundle exec rake karma:run From a4a41ae26a5c3a4503253f43fab136f8dd3b8b27 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 22 Apr 2015 11:47:47 +1000 Subject: [PATCH 14/36] Refactor properties_h --- app/models/spree/product_decorator.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index cf7d02bf46..fbd882dfd4 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -25,7 +25,7 @@ Spree::Product.class_eval do validates_presence_of :supplier validates :primary_taxon, presence: { message: "^Product Category can't be blank" } validates :tax_category_id, presence: { message: "^Tax Category can't be blank" }, if: "Spree::Config.products_require_tax_category" - + validates_presence_of :variant_unit, if: :has_variants? validates_presence_of :variant_unit_scale, if: -> p { %w(weight volume).include? p.variant_unit } @@ -108,11 +108,10 @@ Spree::Product.class_eval do def properties_h # Product properties override producer properties - ps = supplier.producer_properties.inject(product_properties) do |properties, property| - if properties.find { |p| p.property.presentation == property.property.presentation } - properties - else - properties + [property] + ps = product_properties.all + supplier.producer_properties.each do |producer_property| + unless ps.find { |product_property| product_property.property.presentation == producer_property.property.presentation } + ps << producer_property end end From 1f293bb787908da5a832af2f63032a91d04ff970 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 22 Apr 2015 11:56:45 +1000 Subject: [PATCH 15/36] Adding inherits properties flag to products --- .../20150422014819_add_inherits_properties_to_product.rb | 5 +++++ db/schema.rb | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20150422014819_add_inherits_properties_to_product.rb diff --git a/db/migrate/20150422014819_add_inherits_properties_to_product.rb b/db/migrate/20150422014819_add_inherits_properties_to_product.rb new file mode 100644 index 0000000000..aba8bbbe45 --- /dev/null +++ b/db/migrate/20150422014819_add_inherits_properties_to_product.rb @@ -0,0 +1,5 @@ +class AddInheritsPropertiesToProduct < ActiveRecord::Migration + def change + add_column :spree_products, :inherits_properties, :boolean, null: false, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index f30408c2ac..627dd8aa8c 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 => 20150410043302) do +ActiveRecord::Schema.define(:version => 20150422014819) do create_table "adjustment_metadata", :force => true do |t| t.integer "adjustment_id" @@ -618,9 +618,9 @@ ActiveRecord::Schema.define(:version => 20150410043302) do t.string "email" t.text "special_instructions" t.integer "distributor_id" + t.integer "order_cycle_id" t.string "currency" t.string "last_ip_address" - t.integer "order_cycle_id" t.integer "cart_id" end @@ -766,6 +766,7 @@ ActiveRecord::Schema.define(:version => 20150410043302) do t.string "variant_unit_name" t.text "notes" t.integer "primary_taxon_id", :null => false + t.boolean "inherits_properties", :default => true, :null => false end add_index "spree_products", ["available_on"], :name => "index_products_on_available_on" From 5d6f265c0adc8b7a96ddb7a78de229509277fd2b Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 22 Apr 2015 12:15:45 +1000 Subject: [PATCH 16/36] Moving spree namespaced serializers into admin --- app/controllers/spree/api/products_controller_decorator.rb | 2 +- app/helpers/admin/injection_helper.rb | 2 +- .../{spree/api => api/admin}/product_serializer.rb | 6 +++--- .../{spree/api => api/admin}/variant_serializer.rb | 2 +- spec/serializers/spree/product_serializer_spec.rb | 6 +++--- spec/serializers/spree/variant_serializer_spec.rb | 6 +++--- 6 files changed, 12 insertions(+), 12 deletions(-) rename app/serializers/{spree/api => api/admin}/product_serializer.rb (76%) rename app/serializers/{spree/api => api/admin}/variant_serializer.rb (88%) diff --git a/app/controllers/spree/api/products_controller_decorator.rb b/app/controllers/spree/api/products_controller_decorator.rb index 0186c6e8df..6e9799c86d 100644 --- a/app/controllers/spree/api/products_controller_decorator.rb +++ b/app/controllers/spree/api/products_controller_decorator.rb @@ -65,7 +65,7 @@ Spree::Api::ProductsController.class_eval do end def render_paged_products(products) - render text: { products: ActiveModel::ArraySerializer.new(products, each_serializer: Spree::Api::ProductSerializer), pages: products.num_pages }.to_json + render text: { products: ActiveModel::ArraySerializer.new(products, each_serializer: Api::Admin::ProductSerializer), pages: products.num_pages }.to_json end end diff --git a/app/helpers/admin/injection_helper.rb b/app/helpers/admin/injection_helper.rb index 14c4f9c20d..36ddccdb9a 100644 --- a/app/helpers/admin/injection_helper.rb +++ b/app/helpers/admin/injection_helper.rb @@ -47,7 +47,7 @@ module Admin end def admin_inject_products - admin_inject_json_ams_array "ofn.admin", "products", @products, Spree::Api::ProductSerializer + admin_inject_json_ams_array "ofn.admin", "products", @products, Api::Admin::ProductSerializer end def admin_inject_taxons diff --git a/app/serializers/spree/api/product_serializer.rb b/app/serializers/api/admin/product_serializer.rb similarity index 76% rename from app/serializers/spree/api/product_serializer.rb rename to app/serializers/api/admin/product_serializer.rb index 8c1a331936..d980013674 100644 --- a/app/serializers/spree/api/product_serializer.rb +++ b/app/serializers/api/admin/product_serializer.rb @@ -1,12 +1,12 @@ -class Spree::Api::ProductSerializer < ActiveModel::Serializer +class Api::Admin::ProductSerializer < ActiveModel::Serializer attributes :id, :name, :variant_unit, :variant_unit_scale, :variant_unit_name, :on_demand attributes :on_hand, :price, :available_on, :permalink_live has_one :supplier, key: :producer_id, embed: :id has_one :primary_taxon, key: :category_id, embed: :id - has_many :variants, key: :variants, serializer: Spree::Api::VariantSerializer # embed: ids - has_one :master, serializer: Spree::Api::VariantSerializer + has_many :variants, key: :variants, serializer: Api::Admin::VariantSerializer # embed: ids + has_one :master, serializer: Api::Admin::VariantSerializer def on_hand object.on_hand.nil? ? 0 : object.on_hand.to_f.finite? ? object.on_hand : "On demand" diff --git a/app/serializers/spree/api/variant_serializer.rb b/app/serializers/api/admin/variant_serializer.rb similarity index 88% rename from app/serializers/spree/api/variant_serializer.rb rename to app/serializers/api/admin/variant_serializer.rb index a2342de6e4..26ad2d7f37 100644 --- a/app/serializers/spree/api/variant_serializer.rb +++ b/app/serializers/api/admin/variant_serializer.rb @@ -1,4 +1,4 @@ -class Spree::Api::VariantSerializer < ActiveModel::Serializer +class Api::Admin::VariantSerializer < ActiveModel::Serializer attributes :id, :options_text, :unit_value, :unit_description, :unit_to_display, :on_demand, :display_as, :display_name, :name_to_display attributes :on_hand, :price diff --git a/spec/serializers/spree/product_serializer_spec.rb b/spec/serializers/spree/product_serializer_spec.rb index bbb65c1c7e..ab6883f9c5 100644 --- a/spec/serializers/spree/product_serializer_spec.rb +++ b/spec/serializers/spree/product_serializer_spec.rb @@ -1,7 +1,7 @@ -describe Spree::Api::ProductSerializer do +describe Api::Admin::ProductSerializer do let(:product) { create(:simple_product) } it "serializes a product" do - serializer = Spree::Api::ProductSerializer.new product + serializer = Api::Admin::ProductSerializer.new product serializer.to_json.should match product.name end -end \ No newline at end of file +end diff --git a/spec/serializers/spree/variant_serializer_spec.rb b/spec/serializers/spree/variant_serializer_spec.rb index e0f26d3423..8f6b1e0bf5 100644 --- a/spec/serializers/spree/variant_serializer_spec.rb +++ b/spec/serializers/spree/variant_serializer_spec.rb @@ -1,7 +1,7 @@ -describe Spree::Api::VariantSerializer do +describe Api::Admin::VariantSerializer do let(:variant) { create(:variant) } it "serializes a variant" do - serializer = Spree::Api::VariantSerializer.new variant + serializer = Api::Admin::VariantSerializer.new variant serializer.to_json.should match variant.options_text end -end \ No newline at end of file +end From f610a709e1f32d3da2fa867a2ba983cd583841b5 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 22 Apr 2015 12:51:00 +1000 Subject: [PATCH 17/36] Adding inherits_properties to BPE --- .../admin/bulk_product_update.js.coffee | 18 +++++++++++------- app/models/spree/product_decorator.rb | 6 ++++-- .../api/admin/product_serializer.rb | 2 +- .../bulk_edit/_products_head.html.haml | 2 ++ .../bulk_edit/_products_product.html.haml | 2 ++ .../features/admin/bulk_product_update_spec.rb | 4 ++++ 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index e8e14413ae..97c19cdd26 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -4,13 +4,14 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout $scope.StatusMessage = StatusMessage $scope.columns = - producer: {name: "Producer", visible: true} - name: {name: "Name", visible: true} - unit: {name: "Unit", visible: true} - price: {name: "Price", visible: true} - on_hand: {name: "On Hand", visible: true} - category: {name: "Category", visible: false} - available_on: {name: "Available On", visible: false} + producer: {name: "Producer", visible: true} + name: {name: "Name", visible: true} + unit: {name: "Unit", visible: true} + price: {name: "Price", visible: true} + on_hand: {name: "On Hand", visible: true} + category: {name: "Category", visible: false} + inherits_properties: {name: "Inherits Properties?", visible: false} + available_on: {name: "Available On", visible: false} $scope.variant_unit_options = VariantUnitManager.variantUnitOptions() @@ -307,6 +308,9 @@ filterSubmitProducts = (productsToFilter) -> if product.hasOwnProperty("category_id") filteredProduct.primary_taxon_id = product.category_id hasUpdatableProperty = true + if product.hasOwnProperty("inherits_properties") + filteredProduct.inherits_properties = product.inherits_properties + hasUpdatableProperty = true if product.hasOwnProperty("available_on") filteredProduct.available_on = product.available_on hasUpdatableProperty = true diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index fbd882dfd4..c127977823 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -18,8 +18,10 @@ Spree::Product.class_eval do delegate_belongs_to :master, :unit_value, :unit_description delegate :images_attributes=, :display_as=, to: :master - attr_accessible :supplier_id, :primary_taxon_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size - attr_accessible :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value, :unit_description, :notes, :images_attributes, :display_as + attr_accessible :supplier_id, :primary_taxon_id, :distributor_ids, :product_distributions_attributes + attr_accessible :group_buy, :group_buy_unit_size, :unit_description, :notes, :images_attributes, :display_as + attr_accessible :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value + attr_accessible :inherits_properties validates_associated :master, message: "^Price and On Hand must be valid" validates_presence_of :supplier diff --git a/app/serializers/api/admin/product_serializer.rb b/app/serializers/api/admin/product_serializer.rb index d980013674..31b2db8ffd 100644 --- a/app/serializers/api/admin/product_serializer.rb +++ b/app/serializers/api/admin/product_serializer.rb @@ -1,5 +1,5 @@ class Api::Admin::ProductSerializer < ActiveModel::Serializer - attributes :id, :name, :variant_unit, :variant_unit_scale, :variant_unit_name, :on_demand + attributes :id, :name, :variant_unit, :variant_unit_scale, :variant_unit_name, :on_demand, :inherits_properties attributes :on_hand, :price, :available_on, :permalink_live diff --git a/app/views/spree/admin/products/bulk_edit/_products_head.html.haml b/app/views/spree/admin/products/bulk_edit/_products_head.html.haml index d6be2a88e0..69cdc465ef 100644 --- a/app/views/spree/admin/products/bulk_edit/_products_head.html.haml +++ b/app/views/spree/admin/products/bulk_edit/_products_head.html.haml @@ -7,6 +7,7 @@ %col.price{ ng: { show: 'columns.price.visible'} } %col.on_hand{ ng: { show: 'columns.on_hand.visible' } } %col.category{ ng: { show: 'columns.category.visible' } } + %col.inherits_properties{ ng: { show: 'columns.inherits_properties.visible' } } %col.available_on{ ng: { show: 'columns.available_on.visible' } } %col.actions %col.actions @@ -22,6 +23,7 @@ %th.price{ 'ng-show' => 'columns.price.visible' } Price %th.on_hand{ 'ng-show' => 'columns.on_hand.visible' } On Hand %th.category{ 'ng-show' => 'columns.category.visible' } Category + %th.inherits_properties{ 'ng-show' => 'columns.inherits_properties.visible' } Inherits Properties? %th.available_on{ 'ng-show' => 'columns.available_on.visible' } Av. On %th.actions %th.actions diff --git a/app/views/spree/admin/products/bulk_edit/_products_product.html.haml b/app/views/spree/admin/products/bulk_edit/_products_product.html.haml index bf527ba507..c850dc849c 100644 --- a/app/views/spree/admin/products/bulk_edit/_products_product.html.haml +++ b/app/views/spree/admin/products/bulk_edit/_products_product.html.haml @@ -20,6 +20,8 @@ %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.category{ 'ng-if' => 'columns.category.visible' } %input.fullwidth{ :type => 'text', id: "p{{product.id}}_category_id", 'ng-model' => 'product.category_id', 'ofn-taxon-autocomplete' => '', 'ofn-track-product' => 'category_id', 'multiple-selection' => 'false', placeholder: 'Category' } + %td.inherits_properties{ 'ng-show' => 'columns.inherits_properties.visible' } + %input{ 'ng-model' => 'product.inherits_properties', :name => 'inherits_properties', 'ofn-track-product' => 'inherits_properties', type: "checkbox" } %td.available_on{ '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" } %td.actions diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index debb234284..bb84edb33f 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -299,6 +299,7 @@ feature %q{ first("div#columns_dropdown", :text => "COLUMNS").click first("div#columns_dropdown div.menu div.menu_item", text: "Available On").click first("div#columns_dropdown div.menu div.menu_item", text: "Category").click + first("div#columns_dropdown div.menu div.menu_item", text: "Inherits Properties?").click within "tr#p_#{p.id}" do expect(page).to have_field "product_name", with: p.name @@ -308,6 +309,7 @@ feature %q{ expect(page).to have_selector "div#s2id_p#{p.id}_category_id a.select2-choice" expect(page).to have_select "variant_unit_with_scale", selected: "Volume (L)" expect(page).to have_field "on_hand", with: "6" + expect(page).to have_checked_field "inherits_properties" fill_in "product_name", with: "Big Bag Of Potatoes" select s2.name, :from => 'producer_id' @@ -317,6 +319,7 @@ feature %q{ select2_select t1.name, from: "p#{p.id}_category_id" fill_in "on_hand", with: "18" fill_in "display_as", with: "Big Bag" + uncheck "inherits_properties" end click_button 'Save Changes' @@ -332,6 +335,7 @@ feature %q{ expect(p.price).to eq 20.0 expect(p.on_hand).to eq 18 expect(p.primary_taxon).to eq t1 + expect(p.inherits_properties).to be false end scenario "updating a product with a variant unit of 'items'" do From 976c24cf4c2b8b3cfd69bbd97fa88bf267d94a32 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 22 Apr 2015 16:06:01 +1000 Subject: [PATCH 18/36] properties_h uses inherit_properties flag, and returns property id rather than presentation --- app/models/spree/product_decorator.rb | 11 ++++--- spec/models/spree/product_spec.rb | 42 ++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index c127977823..8587bf7f7b 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -111,15 +111,18 @@ Spree::Product.class_eval do def properties_h # Product properties override producer properties ps = product_properties.all - supplier.producer_properties.each do |producer_property| - unless ps.find { |product_property| product_property.property.presentation == producer_property.property.presentation } - ps << producer_property + + if inherits_properties + supplier.producer_properties.each do |producer_property| + unless ps.find { |product_property| product_property.property.presentation == producer_property.property.presentation } + ps << producer_property + end end end ps. sort_by { |pp| pp.position }. - map { |pp| {presentation: pp.property.presentation, value: pp.value} } + map { |pp| {id: pp.property.id, value: pp.value} } end def in_distributor?(distributor) diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 400f92754b..fee2e92c7d 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -8,7 +8,7 @@ module Spree it { should belong_to(:primary_taxon) } it { should have_many(:product_distributions) } end - + describe "validations and defaults" do it "is valid when built from factory" do build(:product).should be_valid @@ -122,7 +122,7 @@ module Spree end end end - + describe "scopes" do describe "in_supplier" do @@ -316,8 +316,9 @@ module Spree it "returns product properties as a hash" do product = create(:simple_product) product.set_property 'Organic Certified', 'NASAA 12345' + property = product.properties.last - product.properties_h.should == [{presentation: 'Organic Certified', value: 'NASAA 12345'}] + product.properties_h.should == [{id: property.id, value: 'NASAA 12345'}] end it "returns producer properties as a hash" do @@ -325,8 +326,9 @@ module Spree product = create(:simple_product, supplier: supplier) supplier.set_producer_property 'Organic Certified', 'NASAA 54321' + property = supplier.properties.last - product.properties_h.should == [{presentation: 'Organic Certified', value: 'NASAA 54321'}] + product.properties_h.should == [{id: property.id, value: 'NASAA 54321'}] end it "overrides producer properties with product properties" do @@ -335,8 +337,32 @@ module Spree product.set_property 'Organic Certified', 'NASAA 12345' supplier.set_producer_property 'Organic Certified', 'NASAA 54321' + property = product.properties.last - product.properties_h.should == [{presentation: 'Organic Certified', value: 'NASAA 12345'}] + product.properties_h.should == [{id: property.id, value: 'NASAA 12345'}] + end + + context "when product has an inherit_properties value set to true" do + let(:supplier) { create(:supplier_enterprise) } + let(:product) { create(:simple_product, supplier: supplier, inherits_properties: true) } + + it "inherits producer properties" do + supplier.set_producer_property 'Organic Certified', 'NASAA 54321' + property = supplier.properties.last + + product.properties_h.should == [{id: property.id, value: 'NASAA 54321'}] + end + end + + context "when product has an inherit_properties value set to true" do + let(:supplier) { create(:supplier_enterprise) } + let(:product) { create(:simple_product, supplier: supplier, inherits_properties: false) } + + it "does not inherit producer properties" do + supplier.set_producer_property 'Organic Certified', 'NASAA 54321' + + product.properties_h.should == [] + end end it "sorts by position" do @@ -352,9 +378,9 @@ module Spree supplier.producer_properties.create!({property_id: pb.id, value: '2', position: 2}, {without_protection: true}) product.properties_h.should == - [{presentation: 'A', value: '1'}, - {presentation: 'B', value: '2'}, - {presentation: 'C', value: '3'}] + [{id: pa.id, value: '1'}, + {id: pb.id, value: '2'}, + {id: pc.id, value: '3'}] end end From e5463887847789b022229a57ec88452985922167 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 22 Apr 2015 16:08:52 +1000 Subject: [PATCH 19/36] Rename properties_h to properties_including_inherited --- app/models/spree/product_decorator.rb | 2 +- spec/models/spree/product_spec.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 8587bf7f7b..998436109d 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -108,7 +108,7 @@ Spree::Product.class_eval do # -- Methods - def properties_h + def properties_including_inherited # Product properties override producer properties ps = product_properties.all diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index fee2e92c7d..ccb8be6a25 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -318,7 +318,7 @@ module Spree product.set_property 'Organic Certified', 'NASAA 12345' property = product.properties.last - product.properties_h.should == [{id: property.id, value: 'NASAA 12345'}] + product.properties_including_inherited.should == [{id: property.id, value: 'NASAA 12345'}] end it "returns producer properties as a hash" do @@ -328,7 +328,7 @@ module Spree supplier.set_producer_property 'Organic Certified', 'NASAA 54321' property = supplier.properties.last - product.properties_h.should == [{id: property.id, value: 'NASAA 54321'}] + product.properties_including_inherited.should == [{id: property.id, value: 'NASAA 54321'}] end it "overrides producer properties with product properties" do @@ -339,7 +339,7 @@ module Spree supplier.set_producer_property 'Organic Certified', 'NASAA 54321' property = product.properties.last - product.properties_h.should == [{id: property.id, value: 'NASAA 12345'}] + product.properties_including_inherited.should == [{id: property.id, value: 'NASAA 12345'}] end context "when product has an inherit_properties value set to true" do @@ -350,7 +350,7 @@ module Spree supplier.set_producer_property 'Organic Certified', 'NASAA 54321' property = supplier.properties.last - product.properties_h.should == [{id: property.id, value: 'NASAA 54321'}] + product.properties_including_inherited.should == [{id: property.id, value: 'NASAA 54321'}] end end @@ -361,7 +361,7 @@ module Spree it "does not inherit producer properties" do supplier.set_producer_property 'Organic Certified', 'NASAA 54321' - product.properties_h.should == [] + product.properties_including_inherited.should == [] end end @@ -377,7 +377,7 @@ module Spree product.product_properties.create!({property_id: pc.id, value: '3', position: 3}, {without_protection: true}) supplier.producer_properties.create!({property_id: pb.id, value: '2', position: 2}, {without_protection: true}) - product.properties_h.should == + product.properties_including_inherited.should == [{id: pa.id, value: '1'}, {id: pb.id, value: '2'}, {id: pc.id, value: '3'}] From 4a4b3da551a795f8bb0e3f0d7e2c7d13a4b35e4f Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 22 Apr 2015 16:15:59 +1000 Subject: [PATCH 20/36] Using properties_including_inherited for product properties on the shop page --- app/serializers/api/product_serializer.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/serializers/api/product_serializer.rb b/app/serializers/api/product_serializer.rb index 78f7593e4f..7359c25b1c 100644 --- a/app/serializers/api/product_serializer.rb +++ b/app/serializers/api/product_serializer.rb @@ -31,17 +31,20 @@ class Api::CachedProductSerializer < ActiveModel::Serializer #delegate :cache_key, to: :object attributes :id, :name, :permalink, :count_on_hand, :on_demand, :group_buy, - :notes, :description + :notes, :description, :properties has_many :variants, serializer: Api::VariantSerializer has_many :taxons, serializer: Api::IdSerializer - has_many :properties, serializer: Api::IdSerializer has_many :images, serializer: Api::ImageSerializer has_one :supplier, serializer: Api::IdSerializer has_one :primary_taxon, serializer: Api::TaxonSerializer has_one :master, serializer: Api::VariantSerializer + def properties + object.properties_including_inherited + end + def variants # We use the in_stock? method here instead of the in_stock scope because we need to # look up the stock as overridden by VariantOverrides, and the scope method is not affected From 1c617994fca23c6448128087381fd277965b92fe Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 22 Apr 2015 17:23:44 +1000 Subject: [PATCH 21/36] User can toggle property inheritence from product property page, and checking the box shows a list of producer properties that will be inherited from --- ...perties_warning_and_table.html.haml.deface | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 app/overrides/spree/admin/product_properties/index/add_producer_properties_warning_and_table.html.haml.deface diff --git a/app/overrides/spree/admin/product_properties/index/add_producer_properties_warning_and_table.html.haml.deface b/app/overrides/spree/admin/product_properties/index/add_producer_properties_warning_and_table.html.haml.deface new file mode 100644 index 0000000000..8d2e598c43 --- /dev/null +++ b/app/overrides/spree/admin/product_properties/index/add_producer_properties_warning_and_table.html.haml.deface @@ -0,0 +1,26 @@ +/ insert_after 'table.index.sortable' + +=f.check_box :inherits_properties +=f.label :inherits_properties, "Inherit properties from #{@product.supplier.name}? (unless overridden above)" +%br +%br + +#inherited_properties + %table.index + %thead + %tr{"data-hook" => "producer_properties_header"} + %th= t(:inherited_property) + %th= t(:value) + %th.actions + %tbody#producer_properties{"data-hook" => ""} + - @product.supplier.producer_properties.each do |producer_property| + %tr + %td= producer_property.property.presentation + %td= producer_property.value + %td.actions + +:coffee + $(document).ready -> + $("#inherited_properties").toggle $("input#product_inherits_properties").is(':checked') + $("input#product_inherits_properties").change -> + $("#inherited_properties").toggle $(this).is(':checked') From 0251d8962d8876f30b9d8bb9788eb399c0a845c4 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 22 Apr 2015 21:01:36 +1000 Subject: [PATCH 22/36] Adding sku to BPE --- app/assets/javascripts/admin/bulk_product_update.js.coffee | 4 ++++ app/models/spree/product_decorator.rb | 2 +- app/serializers/api/admin/product_serializer.rb | 2 +- .../spree/admin/products/bulk_edit/_products_head.html.haml | 2 ++ .../admin/products/bulk_edit/_products_product.html.haml | 2 ++ .../admin/products/bulk_edit/_products_variant.html.haml | 2 ++ spec/features/admin/bulk_product_update_spec.rb | 6 +++++- 7 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index 97c19cdd26..8cac0abeda 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -5,6 +5,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout $scope.columns = producer: {name: "Producer", visible: true} + sku: {name: "SKU", visible: false} name: {name: "Name", visible: true} unit: {name: "Unit", visible: true} price: {name: "Price", visible: true} @@ -286,6 +287,9 @@ filterSubmitProducts = (productsToFilter) -> filteredMaster ?= { id: product.master.id } filteredMaster.display_as = product.master.display_as + if product.hasOwnProperty("sku") + filteredProduct.sku = product.sku + hasUpdatableProperty = true if product.hasOwnProperty("name") filteredProduct.name = product.name hasUpdatableProperty = true diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 998436109d..c1df626e0b 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -21,7 +21,7 @@ Spree::Product.class_eval do attr_accessible :supplier_id, :primary_taxon_id, :distributor_ids, :product_distributions_attributes attr_accessible :group_buy, :group_buy_unit_size, :unit_description, :notes, :images_attributes, :display_as attr_accessible :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value - attr_accessible :inherits_properties + attr_accessible :inherits_properties, :sku validates_associated :master, message: "^Price and On Hand must be valid" validates_presence_of :supplier diff --git a/app/serializers/api/admin/product_serializer.rb b/app/serializers/api/admin/product_serializer.rb index 31b2db8ffd..b1f233c044 100644 --- a/app/serializers/api/admin/product_serializer.rb +++ b/app/serializers/api/admin/product_serializer.rb @@ -1,5 +1,5 @@ class Api::Admin::ProductSerializer < ActiveModel::Serializer - attributes :id, :name, :variant_unit, :variant_unit_scale, :variant_unit_name, :on_demand, :inherits_properties + attributes :id, :name, :sku, :variant_unit, :variant_unit_scale, :variant_unit_name, :on_demand, :inherits_properties attributes :on_hand, :price, :available_on, :permalink_live diff --git a/app/views/spree/admin/products/bulk_edit/_products_head.html.haml b/app/views/spree/admin/products/bulk_edit/_products_head.html.haml index 69cdc465ef..2e37da2bc8 100644 --- a/app/views/spree/admin/products/bulk_edit/_products_head.html.haml +++ b/app/views/spree/admin/products/bulk_edit/_products_head.html.haml @@ -1,6 +1,7 @@ %colgroup %col.actions %col.producer{ ng: { show: 'columns.producer.visible' } } + %col.sku{ ng: { show: 'columns.sku.visible' } } %col.name{ ng: { show: 'columns.name.visible' } } %col.unit{ ng: { show: 'columns.unit.visible' } } %col.display_as{ ng: { show: 'columns.unit.visible' } } @@ -17,6 +18,7 @@ %tr %th.left-actions %th.producer{ 'ng-show' => 'columns.producer.visible' } Producer + %th.sku{ 'ng-show' => 'columns.sku.visible' } SKU %th.name{ 'ng-show' => 'columns.name.visible' } Name %th.unit{ 'ng-show' => 'columns.unit.visible' } Unit / Value %th.display_as{ 'ng-show' => 'columns.unit.visible' } Display As diff --git a/app/views/spree/admin/products/bulk_edit/_products_product.html.haml b/app/views/spree/admin/products/bulk_edit/_products_product.html.haml index c850dc849c..0eb9ff5f58 100644 --- a/app/views/spree/admin/products/bulk_edit/_products_product.html.haml +++ b/app/views/spree/admin/products/bulk_edit/_products_product.html.haml @@ -4,6 +4,8 @@ %a{ :class => "add-variant icon-plus-sign", 'ng-click' => "addVariant(product)", 'ng-show' => "!hasVariants(product) && hasUnit(product)" } %td.producer{ 'ng-show' => 'columns.producer.visible' } %select.select2.fullwidth{ 'ng-model' => 'product.producer_id', :name => 'producer_id', 'ofn-track-product' => 'producer_id', 'ng-options' => 'producer.id as producer.name for producer in producers' } + %td.sku{ 'ng-show' => 'columns.sku.visible' } + %input{ 'ng-model' => "product.sku", :name => 'product_sku', 'ofn-track-product' => 'sku', :type => 'text' } %td.name{ 'ng-show' => 'columns.name.visible' } %input{ 'ng-model' => "product.name", :name => 'product_name', 'ofn-track-product' => 'name', :type => 'text' } %td.unit{ 'ng-show' => 'columns.unit.visible' } diff --git a/app/views/spree/admin/products/bulk_edit/_products_variant.html.haml b/app/views/spree/admin/products/bulk_edit/_products_variant.html.haml index 28f6ed6321..7e60cbfd4c 100644 --- a/app/views/spree/admin/products/bulk_edit/_products_variant.html.haml +++ b/app/views/spree/admin/products/bulk_edit/_products_variant.html.haml @@ -3,6 +3,7 @@ %a{ :class => "variant-item icon-caret-right", 'ng-hide' => "$last" } %a{ :class => "add-variant icon-plus-sign", 'ng-click' => "addVariant(product)", 'ng-show' => "$last" } %td{ 'ng-show' => 'columns.producer.visible' } + %td{ 'ng-show' => 'columns.sku.visible' } %td{ 'ng-show' => 'columns.name.visible' } %input{ 'ng-model' => 'variant.display_name', :name => 'variant_display_name', 'ofn-track-variant' => 'display_name', :type => 'text', placeholder: "{{ product.name }}" } %td.unit_value{ 'ng-show' => 'columns.unit.visible' } @@ -15,6 +16,7 @@ %input.field{ 'ng-model' => 'variant.on_hand', 'ng-change' => 'updateOnHand(product)', :name => 'variant_on_hand', 'ng-hide' => 'variant.on_demand', 'ofn-track-variant' => 'on_hand', :type => 'number' } %span{ 'ng-bind' => 'variant.on_hand', :name => 'variant_on_hand', 'ng-show' => 'variant.on_demand' } %td{ 'ng-show' => 'columns.category.visible' } + %td{ 'ng-show' => 'columns.inherits_properties.visible' } %td{ 'ng-show' => 'columns.available_on.visible' } %td.actions %a{ 'ng-click' => 'editWarn(product,variant)', :class => "edit-variant icon-edit no-text", 'ng-show' => "variantSaved(variant)" } diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index bb84edb33f..ac101da5d9 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -287,7 +287,7 @@ feature %q{ s2 = FactoryGirl.create(:supplier_enterprise) t1 = FactoryGirl.create(:taxon) t2 = FactoryGirl.create(:taxon) - p = FactoryGirl.create(:product, supplier: s1, available_on: Date.today, variant_unit: 'volume', variant_unit_scale: 1, primary_taxon: t2) + p = FactoryGirl.create(:product, supplier: s1, available_on: Date.today, variant_unit: 'volume', variant_unit_scale: 1, primary_taxon: t2, sku: "OLD SKU") p.price = 10.0 p.on_hand = 6; p.save! @@ -300,6 +300,7 @@ feature %q{ first("div#columns_dropdown div.menu div.menu_item", text: "Available On").click first("div#columns_dropdown div.menu div.menu_item", text: "Category").click first("div#columns_dropdown div.menu div.menu_item", text: "Inherits Properties?").click + first("div#columns_dropdown div.menu div.menu_item", text: "SKU").click within "tr#p_#{p.id}" do expect(page).to have_field "product_name", with: p.name @@ -310,6 +311,7 @@ feature %q{ expect(page).to have_select "variant_unit_with_scale", selected: "Volume (L)" expect(page).to have_field "on_hand", with: "6" expect(page).to have_checked_field "inherits_properties" + expect(page).to have_field "product_sku", with: p.sku fill_in "product_name", with: "Big Bag Of Potatoes" select s2.name, :from => 'producer_id' @@ -320,6 +322,7 @@ feature %q{ fill_in "on_hand", with: "18" fill_in "display_as", with: "Big Bag" uncheck "inherits_properties" + fill_in "product_sku", with: "NEW SKU" end click_button 'Save Changes' @@ -336,6 +339,7 @@ feature %q{ expect(p.on_hand).to eq 18 expect(p.primary_taxon).to eq t1 expect(p.inherits_properties).to be false + expect(p.sku).to eq "NEW SKU" end scenario "updating a product with a variant unit of 'items'" do From 92e03e208f9d55e085ff09900517c02785776e4a Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 15:53:54 +1000 Subject: [PATCH 23/36] Extract load_environment method --- script/ci/includes.sh | 7 +++++++ script/ci/run_tests.sh | 5 +---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/script/ci/includes.sh b/script/ci/includes.sh index 06713fc773..4b07dacfdc 100644 --- a/script/ci/includes.sh +++ b/script/ci/includes.sh @@ -1,3 +1,10 @@ +function load_environment { + source /var/lib/jenkins/.rvm/environments/ruby-1.9.3-p392 + if [ ! -f config/application.yml ]; then + ln -s application.yml.example config/application.yml + fi +} + function exit_unless_master_merged { if [[ `git branch -a --merged origin/$BUILDKITE_BRANCH` != *origin/master* ]]; then echo "This branch does not have the current master merged. Please merge master and push again." diff --git a/script/ci/run_tests.sh b/script/ci/run_tests.sh index 9fdbd11333..189875f1e1 100755 --- a/script/ci/run_tests.sh +++ b/script/ci/run_tests.sh @@ -4,10 +4,7 @@ set -e echo "--- Loading environment" source ./script/ci/includes.sh -source /var/lib/jenkins/.rvm/environments/ruby-1.9.3-p392 -if [ ! -f config/application.yml ]; then - ln -s application.yml.example config/application.yml -fi +load_environment echo "--- Verifying branch is based on current master" exit_unless_master_merged From 3df2720b3159d4232df61df5078dcabaf04d65ee Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 23 Apr 2015 12:31:06 +1000 Subject: [PATCH 24/36] Making filter selectors more flexible, allowing no active-selectors to be passed in, ie. read-only --- .../darkswarm/directives/active_selector.js.coffee | 14 +++++++------- .../darkswarm/directives/filter_selector.js.coffee | 9 ++++++--- .../templates/filter_selector.html.haml | 7 ++++--- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/darkswarm/directives/active_selector.js.coffee b/app/assets/javascripts/darkswarm/directives/active_selector.js.coffee index 563b5a1716..46be338610 100644 --- a/app/assets/javascripts/darkswarm/directives/active_selector.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/active_selector.js.coffee @@ -6,10 +6,10 @@ Darkswarm.directive "activeSelector", -> replace: true templateUrl: 'active_selector.html' link: (scope, elem, attr)-> - scope.selector.emit = scope.emit - elem.bind "click", -> - scope.$apply -> - scope.selector.active = !scope.selector.active - # This function is a convention, e.g. a callback on the scope applied when active changes - scope.emit() if scope.emit - + unless scope.readOnly && scope.readOnly() + scope.selector.emit = scope.emit + elem.bind "click", -> + scope.$apply -> + scope.selector.active = !scope.selector.active + # This function is a convention, e.g. a callback on the scope applied when active changes + scope.emit() if scope.emit diff --git a/app/assets/javascripts/darkswarm/directives/filter_selector.js.coffee b/app/assets/javascripts/darkswarm/directives/filter_selector.js.coffee index b964219925..28b548d1c3 100644 --- a/app/assets/javascripts/darkswarm/directives/filter_selector.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/filter_selector.js.coffee @@ -5,7 +5,7 @@ Darkswarm.directive "filterSelector", (FilterSelectorsService)-> replace: true scope: objects: "&" - activeSelectors: "=" + activeSelectors: "=?" allSelectors: "=?" # Optional templateUrl: "filter_selector.html" @@ -13,6 +13,9 @@ Darkswarm.directive "filterSelector", (FilterSelectorsService)-> selectors_by_id = {} selectors = null # To get scoping/closure right + scope.readOnly = -> + attr.activeSelectors? + scope.emit = -> scope.activeSelectors = selectors.filter (selector)-> selector.active @@ -23,10 +26,10 @@ Darkswarm.directive "filterSelector", (FilterSelectorsService)-> # when data has been loaded, in order to pass # selectors up scope.$on 'loadFilterSelectors', -> - scope.allSelectors = scope.selectors() + scope.allSelectors = scope.selectors() if attr.allSelectors? scope.$watchCollection "selectors()", (newValue, oldValue) -> - scope.allSelectors = scope.selectors() + scope.allSelectors = scope.selectors() if attr.allSelectors? # Build a list of selectors scope.selectors = -> diff --git a/app/assets/javascripts/templates/filter_selector.html.haml b/app/assets/javascripts/templates/filter_selector.html.haml index cddcd2f523..ecd4fb7d6d 100644 --- a/app/assets/javascripts/templates/filter_selector.html.haml +++ b/app/assets/javascripts/templates/filter_selector.html.haml @@ -1,3 +1,4 @@ -%active-selector{ ng: { repeat: "selector in selectors()", show: "ifDefined(selector.fits, true)" } } - %render-svg{path: "{{selector.object.icon}}", ng: { if: "selector.object.icon"} } - %span {{ selector.object.name }} +%div{ style: "display: inline-block" } + %active-selector{ ng: { repeat: "selector in selectors()", show: "ifDefined(selector.fits, true)" } } + %render-svg{path: "{{selector.object.icon}}", ng: { if: "selector.object.icon"} } + %span {{ selector.object.name }} From ed15b95de031d6fa1862000abed048c9835606d1 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 23 Apr 2015 12:31:20 +1000 Subject: [PATCH 25/36] Adding properties and taxons to producer modal --- .../templates/product_modal.html.haml | 23 ++++++------------- .../darkswarm/_shop-filters.css.sass | 10 ++++---- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/templates/product_modal.html.haml b/app/assets/javascripts/templates/product_modal.html.haml index 1b59838e53..9ae0f2541f 100644 --- a/app/assets/javascripts/templates/product_modal.html.haml +++ b/app/assets/javascripts/templates/product_modal.html.haml @@ -6,24 +6,15 @@ %em from %span.avenir {{ enterprise.name }} + %br - -# TODO: Add product taxons and properties here - -# / TODO: Rob - add in taxons and properties and property pop-overs - -# / %render-svg{path: "{{product.primary_taxon.icon}}"} - -# .pad-top - -# %span.filter-shopfront.taxon-selectors - -# %ul.inline-block - -# %li - -# %a.button.tiny.disabled Grains - -# %li - -# %a.button.tiny.disabled Dairy - -# - -# %span.filter-shopfront.property-selectors.pad-top - -# %ul.inline-block - -# %li - -# %a.button.tiny Organic certified - -# / TODO: Rob - need popover, use will's directive or this? http://pineconellc.github.io/angular-foundation/ + .filter-shopfront.taxon-selectors.inline-block + %ul + %filter-selector{ objects: "[product] | taxonsOf" } + .filter-shopfront.property-selectors.inline-block + %ul + %filter-selector{ objects: "[product] | propertiesOf" } %div{"ng-if" => "product.description"} %hr diff --git a/app/assets/stylesheets/darkswarm/_shop-filters.css.sass b/app/assets/stylesheets/darkswarm/_shop-filters.css.sass index 0d59f260f4..3b31481ee1 100644 --- a/app/assets/stylesheets/darkswarm/_shop-filters.css.sass +++ b/app/assets/stylesheets/darkswarm/_shop-filters.css.sass @@ -4,7 +4,7 @@ @import animations @mixin filter-selector($base-clr, $border-clr, $hover-clr) - ul.inline-block + &.inline-block, ul.inline-block display: inline-block li @@ -14,7 +14,7 @@ margin: 0 0 0.25rem 0.25rem &:hover, &:focus background: transparent - &.active + &.active box-shadow: none a, a.button @@ -48,10 +48,10 @@ svg path fill: $hover-clr - + &.disabled opacity: 0.6 - + &:hover, &:focus border-color: $border-clr color: $base-clr @@ -118,5 +118,3 @@ // Shopfront properties &.property-selectors @include filter-selector(#666, #ccc, #777) - - From e6a98747b416945445a52b49a9f7e7528a4ae029 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 23 Apr 2015 13:32:56 +1000 Subject: [PATCH 26/36] correction in read only logic for filter selectors --- .../javascripts/darkswarm/directives/filter_selector.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/darkswarm/directives/filter_selector.js.coffee b/app/assets/javascripts/darkswarm/directives/filter_selector.js.coffee index 28b548d1c3..95aee1b413 100644 --- a/app/assets/javascripts/darkswarm/directives/filter_selector.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/filter_selector.js.coffee @@ -14,7 +14,7 @@ Darkswarm.directive "filterSelector", (FilterSelectorsService)-> selectors = null # To get scoping/closure right scope.readOnly = -> - attr.activeSelectors? + !attr.activeSelectors? scope.emit = -> scope.activeSelectors = selectors.filter (selector)-> From 7b83438b5ecd8ef6834b5984a86dd9e5748d3197 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 23 Apr 2015 13:51:49 +1000 Subject: [PATCH 27/36] Pulling property values into the shopfront --- .../darkswarm/filters/properties_with_values_of.js.coffee | 7 +++++++ .../javascripts/darkswarm/services/products.js.coffee | 2 ++ app/assets/javascripts/templates/product_modal.html.haml | 2 +- app/models/spree/product_decorator.rb | 2 +- app/serializers/api/product_serializer.rb | 4 ++-- 5 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 app/assets/javascripts/darkswarm/filters/properties_with_values_of.js.coffee diff --git a/app/assets/javascripts/darkswarm/filters/properties_with_values_of.js.coffee b/app/assets/javascripts/darkswarm/filters/properties_with_values_of.js.coffee new file mode 100644 index 0000000000..7cdf962160 --- /dev/null +++ b/app/assets/javascripts/darkswarm/filters/properties_with_values_of.js.coffee @@ -0,0 +1,7 @@ +Darkswarm.filter 'propertiesWithValuesOf', -> + (objects)-> + propertiesWithValues = {} + for object in objects + for property in object.properties_with_values + propertiesWithValues[property.id] = property + propertiesWithValues diff --git a/app/assets/javascripts/darkswarm/services/products.js.coffee b/app/assets/javascripts/darkswarm/services/products.js.coffee index db8bbbb7ee..a07ae1f466 100644 --- a/app/assets/javascripts/darkswarm/services/products.js.coffee +++ b/app/assets/javascripts/darkswarm/services/products.js.coffee @@ -21,6 +21,8 @@ Darkswarm.factory 'Products', ($resource, Enterprises, Dereferencer, Taxons, Pro for product in @products product.supplier = Enterprises.enterprises_by_id[product.supplier.id] Dereferencer.dereference product.taxons, Taxons.taxons_by_id + + product.properties = angular.copy(product.properties_with_values) Dereferencer.dereference product.properties, Properties.properties_by_id # May return different objects! If the variant has already been registered diff --git a/app/assets/javascripts/templates/product_modal.html.haml b/app/assets/javascripts/templates/product_modal.html.haml index 9ae0f2541f..bf66bd4aea 100644 --- a/app/assets/javascripts/templates/product_modal.html.haml +++ b/app/assets/javascripts/templates/product_modal.html.haml @@ -14,7 +14,7 @@ .filter-shopfront.property-selectors.inline-block %ul - %filter-selector{ objects: "[product] | propertiesOf" } + %filter-selector{ objects: "[product] | propertiesWithValuesOf" } %div{"ng-if" => "product.description"} %hr diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index c1df626e0b..7846a0c1e1 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -122,7 +122,7 @@ Spree::Product.class_eval do ps. sort_by { |pp| pp.position }. - map { |pp| {id: pp.property.id, value: pp.value} } + map { |pp| {id: pp.property.id, name: pp.property.presentation, value: pp.value} } end def in_distributor?(distributor) diff --git a/app/serializers/api/product_serializer.rb b/app/serializers/api/product_serializer.rb index 7359c25b1c..0de794796b 100644 --- a/app/serializers/api/product_serializer.rb +++ b/app/serializers/api/product_serializer.rb @@ -31,7 +31,7 @@ class Api::CachedProductSerializer < ActiveModel::Serializer #delegate :cache_key, to: :object attributes :id, :name, :permalink, :count_on_hand, :on_demand, :group_buy, - :notes, :description, :properties + :notes, :description, :properties_with_values has_many :variants, serializer: Api::VariantSerializer has_many :taxons, serializer: Api::IdSerializer @@ -41,7 +41,7 @@ class Api::CachedProductSerializer < ActiveModel::Serializer has_one :primary_taxon, serializer: Api::TaxonSerializer has_one :master, serializer: Api::VariantSerializer - def properties + def properties_with_values object.properties_including_inherited end From 6cde1f77329223c47f89a56d7a1b2a25e3f0edcd Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 23 Apr 2015 14:11:50 +1000 Subject: [PATCH 28/36] Add tooltip with value for selectors --- app/assets/javascripts/templates/active_selector.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/templates/active_selector.html.haml b/app/assets/javascripts/templates/active_selector.html.haml index 7c9412760e..87fb066636 100644 --- a/app/assets/javascripts/templates/active_selector.html.haml +++ b/app/assets/javascripts/templates/active_selector.html.haml @@ -1,2 +1,3 @@ %li{ ng: { class: "{active: selector.active}" } } - %a{ ng: { transclude: true, class: "{active: selector.active}" } } + %a{ "tooltip" => "{{selector.object.value}}", "tooltip-placement" => "bottom", + ng: { transclude: true, class: "{active: selector.active, 'has-tip': selector.object.value}" } } From c66a7e44b6ccc340188661e0c6697eeae1275871 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 23 Apr 2015 15:37:41 +1000 Subject: [PATCH 29/36] Updating product model specs to reflect changes to properties --- .../darkswarm/services/products_spec.js.coffee | 2 +- spec/models/spree/product_spec.rb | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/javascripts/unit/darkswarm/services/products_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/products_spec.js.coffee index 2cb23522e2..590156260d 100644 --- a/spec/javascripts/unit/darkswarm/services/products_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/products_spec.js.coffee @@ -69,7 +69,7 @@ describe 'Products service', -> expect(Products.products[0].taxons[1]).toBe taxons[0] it "dereferences properties", -> - product.properties = [1] + product.properties_with_values = [1] $httpBackend.expectGET("/shop/products").respond([product]) $httpBackend.flush() expect(Products.products[0].properties[1]).toBe properties[0] diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index ccb8be6a25..275d8b1970 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -318,7 +318,7 @@ module Spree product.set_property 'Organic Certified', 'NASAA 12345' property = product.properties.last - product.properties_including_inherited.should == [{id: property.id, value: 'NASAA 12345'}] + product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 12345'}] end it "returns producer properties as a hash" do @@ -328,7 +328,7 @@ module Spree supplier.set_producer_property 'Organic Certified', 'NASAA 54321' property = supplier.properties.last - product.properties_including_inherited.should == [{id: property.id, value: 'NASAA 54321'}] + product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 54321'}] end it "overrides producer properties with product properties" do @@ -339,7 +339,7 @@ module Spree supplier.set_producer_property 'Organic Certified', 'NASAA 54321' property = product.properties.last - product.properties_including_inherited.should == [{id: property.id, value: 'NASAA 12345'}] + product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 12345'}] end context "when product has an inherit_properties value set to true" do @@ -350,7 +350,7 @@ module Spree supplier.set_producer_property 'Organic Certified', 'NASAA 54321' property = supplier.properties.last - product.properties_including_inherited.should == [{id: property.id, value: 'NASAA 54321'}] + product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 54321'}] end end @@ -378,9 +378,9 @@ module Spree supplier.producer_properties.create!({property_id: pb.id, value: '2', position: 2}, {without_protection: true}) product.properties_including_inherited.should == - [{id: pa.id, value: '1'}, - {id: pb.id, value: '2'}, - {id: pc.id, value: '3'}] + [{id: pa.id, name: "A", value: '1'}, + {id: pb.id, name: "B", value: '2'}, + {id: pc.id, name: "C", value: '3'}] end end From 914927604841aa085d8edf011cb42fb8e2e7ceba Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 24 Apr 2015 12:17:39 +1000 Subject: [PATCH 30/36] Kill any postgres connections before dropping and recreating database --- script/ci/includes.sh | 14 ++++++++++++++ script/ci/load_staging_baseline.sh | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/script/ci/includes.sh b/script/ci/includes.sh index 4b07dacfdc..ee59a732d7 100644 --- a/script/ci/includes.sh +++ b/script/ci/includes.sh @@ -11,3 +11,17 @@ function exit_unless_master_merged { exit 1 fi } + +function drop_and_recreate_database { + # Adapted from: http://stackoverflow.com/questions/12924466/capistrano-with-postgresql-error-database-is-being-accessed-by-other-users + psql -U openfoodweb postgres < pg_backend_pid() +AND datname='$1'; +DROP DATABASE $1; +CREATE DATABASE $1; +EOF +} diff --git a/script/ci/load_staging_baseline.sh b/script/ci/load_staging_baseline.sh index 0a59b66d3b..c5408b1328 100755 --- a/script/ci/load_staging_baseline.sh +++ b/script/ci/load_staging_baseline.sh @@ -5,6 +5,7 @@ # current database. set -e +source ./script/ci/includes.sh cd /home/openfoodweb/apps/openfoodweb/current @@ -16,8 +17,7 @@ mkdir -p db/backup pg_dump -h localhost -U openfoodweb openfoodweb_production |gzip > db/backup/staging-`date +%Y%m%d%H%M%S`.sql.gz echo "Loading baseline data..." -dropdb -U openfoodweb -w openfoodweb_production -createdb -U openfoodweb -w openfoodweb_production +drop_and_recreate_database "openfoodweb_production" gunzip -c db/backup/staging-baseline.sql.gz |psql -h localhost -U openfoodweb openfoodweb_production echo "Restarting unicorn..." From bdf462926d0ff77f002735d02ece82416cd98515 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 24 Apr 2015 13:05:01 +1000 Subject: [PATCH 31/36] Ensure that producer properties have a position --- ...ult_and_not_null_to_producer_properties_position.rb | 9 +++++++++ db/schema.rb | 10 +++++----- 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20150424025907_add_default_and_not_null_to_producer_properties_position.rb diff --git a/db/migrate/20150424025907_add_default_and_not_null_to_producer_properties_position.rb b/db/migrate/20150424025907_add_default_and_not_null_to_producer_properties_position.rb new file mode 100644 index 0000000000..8c5a2d1f2c --- /dev/null +++ b/db/migrate/20150424025907_add_default_and_not_null_to_producer_properties_position.rb @@ -0,0 +1,9 @@ +class AddDefaultAndNotNullToProducerPropertiesPosition < ActiveRecord::Migration + def change + ProducerProperty.where(position: nil).each do |producer_property| + producer_property.update_attribute(:position, 0) + end + + change_column :producer_properties, :position, :integer, null: false, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 627dd8aa8c..cb8b503583 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 => 20150422014819) do +ActiveRecord::Schema.define(:version => 20150424025907) do create_table "adjustment_metadata", :force => true do |t| t.integer "adjustment_id" @@ -373,9 +373,9 @@ ActiveRecord::Schema.define(:version => 20150422014819) do t.string "value" t.integer "producer_id" t.integer "property_id" - t.integer "position" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.integer "position", :default => 0, :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "producer_properties", ["position"], :name => "index_producer_properties_on_position" @@ -618,9 +618,9 @@ ActiveRecord::Schema.define(:version => 20150422014819) do t.string "email" t.text "special_instructions" t.integer "distributor_id" - t.integer "order_cycle_id" t.string "currency" t.string "last_ip_address" + t.integer "order_cycle_id" t.integer "cart_id" end From bb2f2a6f5407fff99818770b3a4c0812accb4ddd Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 24 Apr 2015 12:48:39 +1000 Subject: [PATCH 32/36] Also stop delayed job before loading staging baseline --- script/ci/load_staging_baseline.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/script/ci/load_staging_baseline.sh b/script/ci/load_staging_baseline.sh index c5408b1328..2fe132a0e5 100755 --- a/script/ci/load_staging_baseline.sh +++ b/script/ci/load_staging_baseline.sh @@ -9,8 +9,9 @@ source ./script/ci/includes.sh cd /home/openfoodweb/apps/openfoodweb/current -echo "Stopping unicorn..." +echo "Stopping unicorn and delayed job..." service unicorn_openfoodweb stop +RAILS_ENV=staging script/delayed_job -i 0 stop echo "Backing up current data..." mkdir -p db/backup @@ -22,5 +23,6 @@ gunzip -c db/backup/staging-baseline.sql.gz |psql -h localhost -U openfoodweb op echo "Restarting unicorn..." service unicorn_openfoodweb start +# Delayed job is restarted by monit echo "Done!" From 8e2c224d4db605091c140d2e621a7289a99dea58 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 24 Apr 2015 15:00:49 +1000 Subject: [PATCH 33/36] cd before sourcing includes --- script/ci/load_staging_baseline.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/script/ci/load_staging_baseline.sh b/script/ci/load_staging_baseline.sh index 2fe132a0e5..ac7d88569f 100755 --- a/script/ci/load_staging_baseline.sh +++ b/script/ci/load_staging_baseline.sh @@ -5,9 +5,8 @@ # current database. set -e -source ./script/ci/includes.sh - cd /home/openfoodweb/apps/openfoodweb/current +source ./script/ci/includes.sh echo "Stopping unicorn and delayed job..." service unicorn_openfoodweb stop From b1b1bfd8f6bd1d460f5cb7dee2066eab741b1510 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 24 Apr 2015 16:05:39 +1000 Subject: [PATCH 34/36] Resolve conflict for overflow dropdown between multiple single-line-selectors on the one page --- .../darkswarm/directives/single_line_selectors.coffee | 1 + .../javascripts/templates/single_line_selectors.html.haml | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/darkswarm/directives/single_line_selectors.coffee b/app/assets/javascripts/darkswarm/directives/single_line_selectors.coffee index 97e03cb689..93896a41f9 100644 --- a/app/assets/javascripts/darkswarm/directives/single_line_selectors.coffee +++ b/app/assets/javascripts/darkswarm/directives/single_line_selectors.coffee @@ -4,6 +4,7 @@ Darkswarm.directive 'singleLineSelectors', ($timeout, $filter) -> scope: objects: "&" activeSelectors: "=" + selectorName: "@activeSelectors" link: (scope,element,attrs) -> scope.fitting = false diff --git a/app/assets/javascripts/templates/single_line_selectors.html.haml b/app/assets/javascripts/templates/single_line_selectors.html.haml index e1e96e904a..d54ce57bbb 100644 --- a/app/assets/javascripts/templates/single_line_selectors.html.haml +++ b/app/assets/javascripts/templates/single_line_selectors.html.haml @@ -3,12 +3,12 @@ %filter-selector{objects: "objects()", "active-selectors" => "activeSelectors", "all-selectors" => "allSelectors" } %li.more{ ng: { show: "overFlowSelectors().length > 0 || fitting" } } - %a.dropdown{ data: { dropdown: "show-more" }, ng: { class: "{active: selectedOverFlowSelectors().length > 0}" } } + %a.dropdown{ data: { dropdown: "{{ 'show-more-' + selectorName }}" }, ng: { class: "{active: selectedOverFlowSelectors().length > 0}" } } %span + {{ overFlowSelectors().length }} more %i.ofn-i_052-point-down - .f-dropdown.text-right.content#show-more + .f-dropdown.text-right.content{ ng: { attr: { id: "{{ 'show-more-' + selectorName }}" } } } %ul %active-selector{ ng: { repeat: "selector in overFlowSelectors()", hide: "selector.fits" } } - %render-svg{path: "{{selector.object.icon}}"} + %render-svg{path: "{{selector.object.icon}}", ng: { if: "selector.object.icon"}} %span {{ selector.object.name }} From 6a4de7c7e2916d6361a165ade4bd3e5497e12362 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 24 Apr 2015 19:35:18 +1000 Subject: [PATCH 35/36] Hiding filters on list views because styling is broken --- app/views/home/_filters.html.haml | 37 +++++++++++++------------- app/views/producers/_filters.html.haml | 30 ++++++++++----------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/app/views/home/_filters.html.haml b/app/views/home/_filters.html.haml index 7fcda4bbf4..6b339c13c9 100644 --- a/app/views/home/_filters.html.haml +++ b/app/views/home/_filters.html.haml @@ -1,21 +1,22 @@ .row - = render partial: 'shared/components/filter_controls' + -# = render partial: 'shared/components/filter_controls' + .small-12.medium-6.columns   = render partial: 'shared/components/show_profiles' -.row.animate-show{"ng-show" => "filtersActive"} - .small-12.columns - .row.filter-box - .small-12.large-9.columns - %h5.tdhead - .light Filter by - Type - %ul.small-block-grid-2.medium-block-grid-4.large-block-grid-5 - %filter-selector{objects: "Enterprises.hubs | searchEnterprises:query | taxonsOf", "active-selectors" => "activeTaxons"} - .small-12.large-3.columns - %h5.tdhead - .light Filter by - Delivery - %ul.small-block-grid-2.medium-block-grid-4.large-block-grid-2 - %shipping-type-selector{results: "shippingTypes"} - -= render partial: 'shared/components/filter_box' +-# .row.animate-show{"ng-show" => "filtersActive"} +-# .small-12.columns +-# .row.filter-box +-# .small-12.large-9.columns +-# %h5.tdhead +-# .light Filter by +-# Type +-# %ul.small-block-grid-2.medium-block-grid-4.large-block-grid-5 +-# %filter-selector{objects: "Enterprises.hubs | searchEnterprises:query | taxonsOf", "active-selectors" => "activeTaxons"} +-# .small-12.large-3.columns +-# %h5.tdhead +-# .light Filter by +-# Delivery +-# %ul.small-block-grid-2.medium-block-grid-4.large-block-grid-2 +-# %shipping-type-selector{results: "shippingTypes"} +-# +-# = render partial: 'shared/components/filter_box' diff --git a/app/views/producers/_filters.html.haml b/app/views/producers/_filters.html.haml index b548bd90c4..ec23c05b92 100644 --- a/app/views/producers/_filters.html.haml +++ b/app/views/producers/_filters.html.haml @@ -1,15 +1,15 @@ -.row - = render partial: 'shared/components/filter_controls' - .small-12.medium-6.columns.text-right -   - -.row.animate-show{"ng-show" => "filtersActive"} - .small-12.columns - .row.filter-box - .small-12.columns - %h5.tdhead - .light Filter by - Type - %ul.small-block-grid-2.medium-block-grid-4.large-block-grid-6 - %filter-selector{objects: "Enterprises.producers | searchEnterprises:query | taxonsOf", "active-selectors" => "activeTaxons"} - = render partial: 'shared/components/filter_box' +-# .row +-# = render partial: 'shared/components/filter_controls' +-# .small-12.medium-6.columns.text-right +-#   +-# +-# .row.animate-show{"ng-show" => "filtersActive"} +-# .small-12.columns +-# .row.filter-box +-# .small-12.columns +-# %h5.tdhead +-# .light Filter by +-# Type +-# %ul.small-block-grid-2.medium-block-grid-4.large-block-grid-6 +-# %filter-selector{objects: "Enterprises.producers | searchEnterprises:query | taxonsOf", "active-selectors" => "activeTaxons"} +-# = render partial: 'shared/components/filter_box' From 3b61d7a1e0cad0019c4f954e39c1196466ae7abd Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 29 Apr 2015 14:12:08 +1000 Subject: [PATCH 36/36] Add ref for country ISO codoes --- config/application.yml.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/application.yml.example b/config/application.yml.example index 9eba8eb6ee..45fface302 100644 --- a/config/application.yml.example +++ b/config/application.yml.example @@ -5,7 +5,7 @@ SECRET_TOKEN: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx TIMEZONE: Melbourne -# Default country for dropdowns etc. +# Default country for dropdowns etc. See for codes: http://en.wikipedia.org/wiki/ISO_3166-1 DEFAULT_COUNTRY_CODE: AU # Locale for translation. LOCALE: en