From 3775cd29cb93ea93b995c15f976801083fe6d9a9 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 25 Sep 2014 11:34:49 +1000 Subject: [PATCH 001/142] generalise search filter to any enterprise --- .../javascripts/darkswarm/filters/filter_hubs.js.coffee | 9 --------- .../darkswarm/filters/filter_producers.js.coffee | 6 ------ .../darkswarm/filters/search_enterprises.js.coffee | 9 +++++++++ app/views/home/_hubs.html.haml | 2 +- app/views/producers/index.html.haml | 2 +- 5 files changed, 11 insertions(+), 17 deletions(-) delete mode 100644 app/assets/javascripts/darkswarm/filters/filter_hubs.js.coffee delete mode 100644 app/assets/javascripts/darkswarm/filters/filter_producers.js.coffee create mode 100644 app/assets/javascripts/darkswarm/filters/search_enterprises.js.coffee diff --git a/app/assets/javascripts/darkswarm/filters/filter_hubs.js.coffee b/app/assets/javascripts/darkswarm/filters/filter_hubs.js.coffee deleted file mode 100644 index b6adb84508..0000000000 --- a/app/assets/javascripts/darkswarm/filters/filter_hubs.js.coffee +++ /dev/null @@ -1,9 +0,0 @@ -Darkswarm.filter 'hubs', (Matcher)-> - (hubs, text) -> - hubs ||= [] - text ?= "" - - hubs.filter (hub)=> - Matcher.match [ - hub.name, hub.address.zipcode, hub.address.city, hub.address.state - ], text diff --git a/app/assets/javascripts/darkswarm/filters/filter_producers.js.coffee b/app/assets/javascripts/darkswarm/filters/filter_producers.js.coffee deleted file mode 100644 index ed5b8c1bea..0000000000 --- a/app/assets/javascripts/darkswarm/filters/filter_producers.js.coffee +++ /dev/null @@ -1,6 +0,0 @@ -Darkswarm.filter 'filterProducers', (hubsFilter)-> - (producers, text) -> - producers ||= [] - text ?= "" - hubsFilter(producers, text) - diff --git a/app/assets/javascripts/darkswarm/filters/search_enterprises.js.coffee b/app/assets/javascripts/darkswarm/filters/search_enterprises.js.coffee new file mode 100644 index 0000000000..20d0fd91c9 --- /dev/null +++ b/app/assets/javascripts/darkswarm/filters/search_enterprises.js.coffee @@ -0,0 +1,9 @@ +Darkswarm.filter 'searchEnterprises', (Matcher)-> + (enterprises, text) -> + enterprises ||= [] + text ?= "" + + enterprises.filter (enterprise)=> + Matcher.match [ + enterprise.name, enterprise.address.zipcode, enterprise.address.city, enterprise.address.state + ], text diff --git a/app/views/home/_hubs.html.haml b/app/views/home/_hubs.html.haml index 24e4b037ba..b7a14fc7bf 100644 --- a/app/views/home/_hubs.html.haml +++ b/app/views/home/_hubs.html.haml @@ -17,7 +17,7 @@ .row{bindonce: true} .small-12.columns .active_table - %hub.active_table_node.row.animate-repeat{"ng-repeat" => "hub in filteredHubs = (hubs | hubs:query | taxons:activeTaxons | shipping:shippingTypes | showProfiles:show_profiles )", + %hub.active_table_node.row.animate-repeat{"ng-repeat" => "hub in filteredHubs = (hubs | searchEnterprises:query | taxons:activeTaxons | shipping:shippingTypes | showProfiles:show_profiles )", "ng-class" => "{'closed' : !open(), 'open' : open(), 'inactive' : !hub.active, 'current' : current()}", "scroll-after-load" => true, "ng-controller" => "HubNodeCtrl", diff --git a/app/views/producers/index.html.haml b/app/views/producers/index.html.haml index cba8011caf..095cff2a11 100644 --- a/app/views/producers/index.html.haml +++ b/app/views/producers/index.html.haml @@ -24,7 +24,7 @@ .active_table %producer.active_table_node.row.animate-repeat{id: "{{producer.path}}", "scroll-after-load" => true, - "ng-repeat" => "producer in producers = (Producers.visible | showProfiles:show_profiles | filterProducers:query | taxons:activeTaxons)", + "ng-repeat" => "producer in producers = (Producers.visible | showProfiles:show_profiles | searchEnterprises:query | taxons:activeTaxons)", "ng-controller" => "ProducerNodeCtrl", "ng-class" => "{'closed' : !open(), 'open' : open(), 'inactive' : !producer.active}", id: "{{producer.hash}}"} From 0e2774882f2ff4e58cab17b29b2cf847fb75482d Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 25 Sep 2014 13:03:18 +1000 Subject: [PATCH 002/142] dry enterprise angular --- ...offee => enterprises_controller.js.coffee} | 10 +++-- .../producers_controller.js.coffee | 14 ------ ....js.coffee => enterproise_modal.js.coffee} | 2 +- .../directives/producer_modal.js.coffee | 10 ----- .../services/enterprise_modal.js.coffee | 7 +++ .../darkswarm/services/enterprises.js.coffee | 15 ++++--- .../darkswarm/services/hubs.js.coffee | 9 ---- .../darkswarm/services/map.js.coffee | 6 +-- .../darkswarm/services/map_modal.js.coffee | 12 ----- .../darkswarm/services/producers.js.coffee | 7 --- ...l.html.haml => enterprise_modal.html.haml} | 0 .../templates/map_modal_producer.html.haml | 4 -- .../templates/producer_modal.html.haml | 3 -- app/views/home/_hubs.html.haml | 4 +- app/views/producers/index.html.haml | 4 +- .../filters/filter_hubs_spec.js.coffee | 45 ------------------- .../filters/filter_producers_spec.js.coffee | 28 ------------ .../filters/search_enterprises_spec.js.coffee | 45 +++++++++++++++++++ 18 files changed, 76 insertions(+), 149 deletions(-) rename app/assets/javascripts/darkswarm/controllers/{hubs_controller.js.coffee => enterprises_controller.js.coffee} (61%) delete mode 100644 app/assets/javascripts/darkswarm/controllers/producers_controller.js.coffee rename app/assets/javascripts/darkswarm/directives/{hub_modal.js.coffee => enterproise_modal.js.coffee} (84%) delete mode 100644 app/assets/javascripts/darkswarm/directives/producer_modal.js.coffee create mode 100644 app/assets/javascripts/darkswarm/services/enterprise_modal.js.coffee delete mode 100644 app/assets/javascripts/darkswarm/services/hubs.js.coffee delete mode 100644 app/assets/javascripts/darkswarm/services/map_modal.js.coffee delete mode 100644 app/assets/javascripts/darkswarm/services/producers.js.coffee rename app/assets/javascripts/templates/{hub_modal.html.haml => enterprise_modal.html.haml} (100%) delete mode 100644 app/assets/javascripts/templates/map_modal_producer.html.haml delete mode 100644 app/assets/javascripts/templates/producer_modal.html.haml delete mode 100644 spec/javascripts/unit/darkswarm/filters/filter_hubs_spec.js.coffee delete mode 100644 spec/javascripts/unit/darkswarm/filters/filter_producers_spec.js.coffee create mode 100644 spec/javascripts/unit/darkswarm/filters/search_enterprises_spec.js.coffee diff --git a/app/assets/javascripts/darkswarm/controllers/hubs_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee similarity index 61% rename from app/assets/javascripts/darkswarm/controllers/hubs_controller.js.coffee rename to app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee index b44d63eadf..dc1218a14b 100644 --- a/app/assets/javascripts/darkswarm/controllers/hubs_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee @@ -1,13 +1,15 @@ -Darkswarm.controller "HubsCtrl", ($scope, Hubs, Search, $document, $rootScope, HashNavigation, FilterSelectorsService, MapModal) -> - $scope.Hubs = Hubs - $scope.hubs = Hubs.visible +Darkswarm.controller "EnterprisesCtrl", ($scope, Enterprises, Search, $document, $rootScope, HashNavigation, FilterSelectorsService, EnterpriseModal) -> + $scope.Enterprises = Enterprises $scope.totalActive = FilterSelectorsService.totalActive $scope.clearAll = FilterSelectorsService.clearAll $scope.filterText = FilterSelectorsService.filterText $scope.FilterSelectorsService = FilterSelectorsService $scope.query = Search.search() + $scope.openModal = EnterpriseModal.open + $scope.activeTaxons = [] + $scope.show_profiles = false + $scope.filtersActive = false $scope.show_profiles = false - $scope.openModal = MapModal.open $scope.$watch "query", (query)-> Search.search query diff --git a/app/assets/javascripts/darkswarm/controllers/producers_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/producers_controller.js.coffee deleted file mode 100644 index b16dcdfa77..0000000000 --- a/app/assets/javascripts/darkswarm/controllers/producers_controller.js.coffee +++ /dev/null @@ -1,14 +0,0 @@ -Darkswarm.controller "ProducersCtrl", ($scope, Producers, $filter, FilterSelectorsService, Search, MapModal) -> - $scope.Producers = Producers - $scope.totalActive = FilterSelectorsService.totalActive - $scope.clearAll = FilterSelectorsService.clearAll - $scope.filterText = FilterSelectorsService.filterText - $scope.FilterSelectorsService = FilterSelectorsService - $scope.filtersActive = false - $scope.activeTaxons = [] - $scope.query = Search.search() - $scope.show_profiles = false - $scope.openModal = MapModal.open - - $scope.$watch "query", (query)-> - Search.search query diff --git a/app/assets/javascripts/darkswarm/directives/hub_modal.js.coffee b/app/assets/javascripts/darkswarm/directives/enterproise_modal.js.coffee similarity index 84% rename from app/assets/javascripts/darkswarm/directives/hub_modal.js.coffee rename to app/assets/javascripts/darkswarm/directives/enterproise_modal.js.coffee index 6eb0299ab4..60f3810f41 100644 --- a/app/assets/javascripts/darkswarm/directives/hub_modal.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/enterproise_modal.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.directive "hubModal", ($modal)-> +Darkswarm.directive "enterpriseModal", ($modal)-> restrict: 'E' replace: true template: "{{enterprise.name}}" diff --git a/app/assets/javascripts/darkswarm/directives/producer_modal.js.coffee b/app/assets/javascripts/darkswarm/directives/producer_modal.js.coffee deleted file mode 100644 index af2b13f157..0000000000 --- a/app/assets/javascripts/darkswarm/directives/producer_modal.js.coffee +++ /dev/null @@ -1,10 +0,0 @@ -Darkswarm.directive "producerModal", ($modal)-> - restrict: 'E' - replace: true - template: "" - transclude: true - link: (scope, elem, attrs, ctrl)-> - elem.on "click", (ev)=> - ev.stopPropagation() - scope.modalInstance = $modal.open(controller: ctrl, templateUrl: 'producer_modal.html', scope: scope) - diff --git a/app/assets/javascripts/darkswarm/services/enterprise_modal.js.coffee b/app/assets/javascripts/darkswarm/services/enterprise_modal.js.coffee new file mode 100644 index 0000000000..1cd0727cd8 --- /dev/null +++ b/app/assets/javascripts/darkswarm/services/enterprise_modal.js.coffee @@ -0,0 +1,7 @@ +Darkswarm.factory "EnterpriseModal", ($modal, $rootScope)-> + new class EnterpriseModal + open: (enterprise)-> + scope = $rootScope.$new(true) # Spawn an isolate to contain the enterprise + + scope.enterprise = enterprise + $modal.open(templateUrl: "enterprise_modal.html", scope: scope) diff --git a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee index 50143e006b..2451c14739 100644 --- a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee @@ -1,13 +1,17 @@ -Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer)-> +Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer, visibleFilter)-> new class Enterprises - enterprises_by_id: {} # id/object pairs for lookup + enterprises_by_id: {} # id/object pairs for lookup constructor: -> - @enterprises = enterprises + @enterprises = visibleFilter enterprises for enterprise in enterprises @enterprises_by_id[enterprise.id] = enterprise @dereferenceEnterprises() @dereferenceTaxons() - + @producers = @enterprises.filter (enterprise)-> + enterprise.is_primary_producer + @hubs = @enterprises.filter (enterprise)-> + enterprise.is_distributor + dereferenceEnterprises: -> if CurrentHub.hub?.id CurrentHub.hub = @enterprises_by_id[CurrentHub.hub.id] @@ -16,6 +20,7 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer) Dereferencer.dereference enterprise.producers, @enterprises_by_id dereferenceTaxons: -> - for enterprise in @enterprises + for enterprise in @enterprises Dereferencer.dereference enterprise.taxons, Taxons.taxons_by_id Dereferencer.dereference enterprise.supplied_taxons, Taxons.taxons_by_id + diff --git a/app/assets/javascripts/darkswarm/services/hubs.js.coffee b/app/assets/javascripts/darkswarm/services/hubs.js.coffee deleted file mode 100644 index ac7dc3a0eb..0000000000 --- a/app/assets/javascripts/darkswarm/services/hubs.js.coffee +++ /dev/null @@ -1,9 +0,0 @@ -Darkswarm.factory 'Hubs', ($filter, Enterprises, visibleFilter) -> - new class Hubs - constructor: -> - @hubs = @order Enterprises.enterprises.filter (hub)-> - hub.is_distributor - @visible = visibleFilter @hubs - - order: (hubs)-> - $filter('orderBy')(hubs, ['-active', '+orders_close_at']) diff --git a/app/assets/javascripts/darkswarm/services/map.js.coffee b/app/assets/javascripts/darkswarm/services/map.js.coffee index 43750acdb2..703c3c54bf 100644 --- a/app/assets/javascripts/darkswarm/services/map.js.coffee +++ b/app/assets/javascripts/darkswarm/services/map.js.coffee @@ -1,7 +1,7 @@ -Darkswarm.factory "OfnMap", (Enterprises, MapModal, visibleFilter)-> +Darkswarm.factory "OfnMap", (Enterprises, EnterpriseModal, visibleFilter)-> new class OfnMap constructor: -> - @enterprises = (@extend(enterprise) for enterprise in visibleFilter(Enterprises.enterprises)) + @enterprises = (@extend(enterprise) for enterprise in visibleFilter(Enterprises.enterprises)) # Adding methods to each enterprise @@ -14,4 +14,4 @@ Darkswarm.factory "OfnMap", (Enterprises, MapModal, visibleFilter)-> icon: enterprise.icon id: enterprise.id reveal: => - MapModal.open enterprise + EnterpriseModal.open enterprise diff --git a/app/assets/javascripts/darkswarm/services/map_modal.js.coffee b/app/assets/javascripts/darkswarm/services/map_modal.js.coffee deleted file mode 100644 index c9ed30f558..0000000000 --- a/app/assets/javascripts/darkswarm/services/map_modal.js.coffee +++ /dev/null @@ -1,12 +0,0 @@ -Darkswarm.factory "MapModal", ($modal, $rootScope)-> - new class MapModal - open: (enterprise)-> - scope = $rootScope.$new(true) # Spawn an isolate to contain the enterprise - - scope.enterprise = enterprise - if enterprise.is_distributor - scope.hub = enterprise - $modal.open(templateUrl: "hub_modal.html", scope: scope) - else - scope.producer = enterprise - $modal.open(templateUrl: "map_modal_producer.html", scope: scope) diff --git a/app/assets/javascripts/darkswarm/services/producers.js.coffee b/app/assets/javascripts/darkswarm/services/producers.js.coffee deleted file mode 100644 index 65d8e42c5d..0000000000 --- a/app/assets/javascripts/darkswarm/services/producers.js.coffee +++ /dev/null @@ -1,7 +0,0 @@ -Darkswarm.factory 'Producers', (Enterprises, visibleFilter) -> - new class Producers - constructor: -> - @producers = Enterprises.enterprises.filter (enterprise)-> - enterprise.is_primary_producer - @visible = visibleFilter @producers - diff --git a/app/assets/javascripts/templates/hub_modal.html.haml b/app/assets/javascripts/templates/enterprise_modal.html.haml similarity index 100% rename from app/assets/javascripts/templates/hub_modal.html.haml rename to app/assets/javascripts/templates/enterprise_modal.html.haml diff --git a/app/assets/javascripts/templates/map_modal_producer.html.haml b/app/assets/javascripts/templates/map_modal_producer.html.haml deleted file mode 100644 index dff26519d3..0000000000 --- a/app/assets/javascripts/templates/map_modal_producer.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -%ng-include{src: "'partials/enterprise_header.html'"} -%ng-include{src: "'partials/enterprise_details.html'"} -%ng-include{src: "'partials/hub_actions.html'"} -%ng-include{src: "'partials/close.html'"} diff --git a/app/assets/javascripts/templates/producer_modal.html.haml b/app/assets/javascripts/templates/producer_modal.html.haml deleted file mode 100644 index db6f927e21..0000000000 --- a/app/assets/javascripts/templates/producer_modal.html.haml +++ /dev/null @@ -1,3 +0,0 @@ -%ng-include{src: "'partials/enterprise_header.html'"} -%ng-include{src: "'partials/enterprise_details.html'"} -%ng-include{src: "'partials/close.html'"} diff --git a/app/views/home/_hubs.html.haml b/app/views/home/_hubs.html.haml index b7a14fc7bf..9e9215ff83 100644 --- a/app/views/home/_hubs.html.haml +++ b/app/views/home/_hubs.html.haml @@ -1,5 +1,5 @@ = inject_enterprises -#hubs.hubs{"ng-controller" => "HubsCtrl"} +#hubs.hubs{"ng-controller" => "EnterprisesCtrl"} .row .small-12.columns %h1 Shop in your local area @@ -17,7 +17,7 @@ .row{bindonce: true} .small-12.columns .active_table - %hub.active_table_node.row.animate-repeat{"ng-repeat" => "hub in filteredHubs = (hubs | searchEnterprises:query | taxons:activeTaxons | shipping:shippingTypes | showProfiles:show_profiles )", + %hub.active_table_node.row.animate-repeat{"ng-repeat" => "hub in hubs = (Enterprises.hubs | searchEnterprises:query | taxons:activeTaxons | shipping:shippingTypes | showProfiles:show_profiles | orderBy:['-active', '+orders_close_at'])", "ng-class" => "{'closed' : !open(), 'open' : open(), 'inactive' : !hub.active, 'current' : current()}", "scroll-after-load" => true, "ng-controller" => "HubNodeCtrl", diff --git a/app/views/producers/index.html.haml b/app/views/producers/index.html.haml index 095cff2a11..e012f4c1ee 100644 --- a/app/views/producers/index.html.haml +++ b/app/views/producers/index.html.haml @@ -1,5 +1,5 @@ = inject_enterprises -.producers.pad-top{"ng-controller" => "ProducersCtrl"} +.producers.pad-top{"ng-controller" => "EnterprisesCtrl"} .row .small-12.columns.pad-top %h1 Find local producers @@ -24,7 +24,7 @@ .active_table %producer.active_table_node.row.animate-repeat{id: "{{producer.path}}", "scroll-after-load" => true, - "ng-repeat" => "producer in producers = (Producers.visible | showProfiles:show_profiles | searchEnterprises:query | taxons:activeTaxons)", + "ng-repeat" => "producer in producers = (Enterprises.producers | showProfiles:show_profiles | searchEnterprises:query | taxons:activeTaxons)", "ng-controller" => "ProducerNodeCtrl", "ng-class" => "{'closed' : !open(), 'open' : open(), 'inactive' : !producer.active}", id: "{{producer.hash}}"} diff --git a/spec/javascripts/unit/darkswarm/filters/filter_hubs_spec.js.coffee b/spec/javascripts/unit/darkswarm/filters/filter_hubs_spec.js.coffee deleted file mode 100644 index fc2702a72b..0000000000 --- a/spec/javascripts/unit/darkswarm/filters/filter_hubs_spec.js.coffee +++ /dev/null @@ -1,45 +0,0 @@ -describe 'filtering Hubs', -> - filter = null - filterHubs = null - hubs = [{ - name: "frogs" - other: "roger" - address: - zipcode: "cats" - city: "cambridge" - state: "kansas" - }, { - name: "donkeys" - other: "roger" - address: - zipcode: "" - city: "Wellington" - state: "uzbekistan" - }] - - beforeEach -> - module 'Darkswarm' - inject ($filter) -> - filter = $filter - filterHubs = $filter('hubs') - - it 'has a hub filter', -> - expect(filter('hubs')).not.toBeNull() - - it "filters by name", -> - expect(filterHubs(hubs, 'donkeys').length).toEqual 1 - - it "is case insensitive", -> - expect(filterHubs(hubs, 'DONKEYS').length).toEqual 1 - - it "filters by state", -> - expect(filterHubs(hubs, 'kansas').length).toEqual 1 - - it "filters by zipcode", -> - expect(filterHubs(hubs, 'cats').length).toEqual 1 - - it "gives all hubs when no argument is specified", -> - expect(filterHubs(hubs, '').length).toEqual 2 - - it "does not filter by anything else", -> - expect(filterHubs(hubs, 'roger').length).toEqual 0 diff --git a/spec/javascripts/unit/darkswarm/filters/filter_producers_spec.js.coffee b/spec/javascripts/unit/darkswarm/filters/filter_producers_spec.js.coffee deleted file mode 100644 index 29d8986b56..0000000000 --- a/spec/javascripts/unit/darkswarm/filters/filter_producers_spec.js.coffee +++ /dev/null @@ -1,28 +0,0 @@ -describe 'filtering producers', -> - filter = null - filterProducers = null - producers = [{ - name: "frogs" - other: "roger" - address: - zipcode: "cats" - city: "cambridge" - state: "kansas" - }, { - name: "donkeys" - other: "roger" - address: - zipcode: "" - city: "Wellington" - state: "uzbekistan" - }] - - beforeEach -> - module 'Darkswarm' - inject ($filter) -> - filter = $filter - filterProducers = $filter('filterProducers') - - - it 'has a producer filter', -> - expect(filter('filterProducers')).not.toBeNull() diff --git a/spec/javascripts/unit/darkswarm/filters/search_enterprises_spec.js.coffee b/spec/javascripts/unit/darkswarm/filters/search_enterprises_spec.js.coffee new file mode 100644 index 0000000000..61e58071e2 --- /dev/null +++ b/spec/javascripts/unit/darkswarm/filters/search_enterprises_spec.js.coffee @@ -0,0 +1,45 @@ +describe 'filtering Enterprises', -> + filter = null + searchEnterprises = null + enterprises = [{ + name: "frogs" + other: "roger" + address: + zipcode: "cats" + city: "cambridge" + state: "kansas" + }, { + name: "donkeys" + other: "roger" + address: + zipcode: "" + city: "Wellington" + state: "uzbekistan" + }] + + beforeEach -> + module 'Darkswarm' + inject ($filter) -> + filter = $filter + searchEnterprises = $filter('enterprises') + + it 'has a enterprise filter', -> + expect(filter('enterprises')).not.toBeNull() + + it "filters by name", -> + expect(searchEnterprises(enterprises, 'donkeys').length).toEqual 1 + + it "is case insensitive", -> + expect(searchEnterprises(enterprises, 'DONKEYS').length).toEqual 1 + + it "filters by state", -> + expect(searchEnterprises(enterprises, 'kansas').length).toEqual 1 + + it "filters by zipcode", -> + expect(searchEnterprises(enterprises, 'cats').length).toEqual 1 + + it "gives all enterprises when no argument is specified", -> + expect(searchEnterprises(enterprises, '').length).toEqual 2 + + it "does not filter by anything else", -> + expect(searchEnterprises(enterprises, 'roger').length).toEqual 0 From 096324cf5ede02700f88610bc3332a6502912db9 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 25 Sep 2014 13:46:08 +1000 Subject: [PATCH 003/142] bugfix filters --- app/views/home/_hubs.html.haml | 2 +- app/views/producers/_filters.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/home/_hubs.html.haml b/app/views/home/_hubs.html.haml index 9e9215ff83..b80b9305a3 100644 --- a/app/views/home/_hubs.html.haml +++ b/app/views/home/_hubs.html.haml @@ -26,7 +26,7 @@ = render partial: 'home/skinny' = render partial: 'home/fat' - .row{"ng-show" => "filteredHubs.length == 0"} + .row{"ng-show" => "hubs.length == 0"} .columns.small-12 %p.no-results Sorry, no results found for diff --git a/app/views/producers/_filters.html.haml b/app/views/producers/_filters.html.haml index 37bf55f7c7..cd36389c8b 100644 --- a/app/views/producers/_filters.html.haml +++ b/app/views/producers/_filters.html.haml @@ -8,6 +8,6 @@ .light Filter by Type %ul.small-block-grid-2.medium-block-grid-4.large-block-grid-6 - %taxon-selector{objects: "Producers.visible | filterProducers:query ", + %taxon-selector{objects: "Enterprises.producers | searchEnterprises:query ", results: "activeTaxons"} From bab9123ca81e3f47e57f070777066c5ab4f8a9d1 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 25 Sep 2014 14:01:06 +1000 Subject: [PATCH 004/142] delete unused javascript --- app/assets/javascripts/search/all.js | 18 - .../gmaps4rails/gmaps4rails.base.js.coffee | 444 ------------------ .../gmaps4rails/gmaps4rails.bing.js.coffee | 174 ------- .../gmaps4rails.googlemaps.js.coffee | 339 ------------- .../gmaps4rails.mapquest.js.coffee | 145 ------ .../gmaps4rails.openlayers.js.coffee | 261 ---------- .../javascripts/search/jquery.backstretch.js | 4 - .../javascripts/search/jquery.offcanvas.js | 62 --- .../search/modernizr.foundation.js | 4 - .../javascripts/shop/checkout.js.coffee | 3 - app/assets/javascripts/store/all.js | 15 - .../store/checkout_adjustments.js.coffee | 8 - .../store/controllers/cart.js.coffee | 20 - .../store/factories/cart.js.coffee | 11 - app/assets/javascripts/store/products.js | 47 -- .../javascripts/store/shop_front.js.coffee | 4 - 16 files changed, 1559 deletions(-) delete mode 100644 app/assets/javascripts/search/all.js delete mode 100644 app/assets/javascripts/search/gmaps4rails/gmaps4rails.base.js.coffee delete mode 100644 app/assets/javascripts/search/gmaps4rails/gmaps4rails.bing.js.coffee delete mode 100644 app/assets/javascripts/search/gmaps4rails/gmaps4rails.googlemaps.js.coffee delete mode 100644 app/assets/javascripts/search/gmaps4rails/gmaps4rails.mapquest.js.coffee delete mode 100644 app/assets/javascripts/search/gmaps4rails/gmaps4rails.openlayers.js.coffee delete mode 100644 app/assets/javascripts/search/jquery.backstretch.js delete mode 100644 app/assets/javascripts/search/jquery.offcanvas.js delete mode 100644 app/assets/javascripts/search/modernizr.foundation.js delete mode 100644 app/assets/javascripts/shop/checkout.js.coffee delete mode 100644 app/assets/javascripts/store/all.js delete mode 100644 app/assets/javascripts/store/checkout_adjustments.js.coffee delete mode 100644 app/assets/javascripts/store/controllers/cart.js.coffee delete mode 100644 app/assets/javascripts/store/factories/cart.js.coffee delete mode 100644 app/assets/javascripts/store/products.js delete mode 100644 app/assets/javascripts/store/shop_front.js.coffee diff --git a/app/assets/javascripts/search/all.js b/app/assets/javascripts/search/all.js deleted file mode 100644 index c684eed4b1..0000000000 --- a/app/assets/javascripts/search/all.js +++ /dev/null @@ -1,18 +0,0 @@ -// This is a manifest file that'll be compiled into including all the files listed below. -// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically -// be included in the compiled file accessible from http://example.com/assets/application.js -// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the -// the compiled file. -// - -//= require jquery -//= require jquery_ujs -//= require jquery-ui -//= require spin -//= require foundation -//= require_tree . -// - -// Hacky fix for issue - http://foundation.zurb.com/forum/posts/2112-foundation-5100-syntax-error-in-js -Foundation.set_namespace = function() {}; -$(function(){ $(document).foundation(); }); diff --git a/app/assets/javascripts/search/gmaps4rails/gmaps4rails.base.js.coffee b/app/assets/javascripts/search/gmaps4rails/gmaps4rails.base.js.coffee deleted file mode 100644 index 684215a438..0000000000 --- a/app/assets/javascripts/search/gmaps4rails/gmaps4rails.base.js.coffee +++ /dev/null @@ -1,444 +0,0 @@ -Gmaps = {} - -Gmaps.triggerOldOnload = -> - Gmaps.oldOnload() if typeof(Gmaps.oldOnload) == 'function' - -Gmaps.loadMaps = -> - #loop through all variable names. - #there should only be maps inside so it trigger their load function - for key, value of Gmaps - searchLoadIncluded = key.search(/load/) - if searchLoadIncluded == -1 - load_function_name = "load_" + key - Gmaps[load_function_name]() - -window.Gmaps = Gmaps - -class @Gmaps4Rails - - constructor: -> - #map config - @map = null #DEPRECATED: will still contain a copy of serviceObject below as transition - @serviceObject = null #contains the map we're working on - @visibleInfoWindow = null #contains the current opened infowindow - @userLocation = null #contains user's location if geolocalization was performed and successful - - #empty slots - @geolocationSuccess = -> false #triggered when geolocation succeeds. Can be customized. - @geolocationFailure = -> false #triggered when geolocation fails. If customized, must be like= function(navigator_handles_geolocation){} where 'navigator_handles_geolocation' is a boolean - @callback = -> false #to let user set a custom callback function - @customClusterer = -> false #to let user set custom clusterer pictures - @infobox = -> false #to let user use custom infoboxes - @jsTemplate = false #to let user create infowindows client side - - @default_map_options = - id: 'map' - draggable: true - detect_location: false # should the browser attempt to use geolocation detection features of HTML5? - center_on_user: false # centers map on the location detected through the browser - center_latitude: 0 - center_longitude: 0 - zoom: 7 - maxZoom: null - minZoom: null - auto_adjust : true # adjust the map to the markers if set to true - auto_zoom: true # zoom given by auto-adjust - bounds: [] # adjust map to these limits. Should be [{"lat": , "lng": }] - raw: {} # raw json to pass additional options - - @default_markers_conf = - #Marker config - title: "" - #MarkerImage config - picture : "" - width: 22 - length: 32 - draggable: false # how to modify: <%= gmaps( "markers" => { "data" => @object.to_gmaps4rails, "options" => { "draggable" => true }}) %> - #clustering config - do_clustering: false # do clustering if set to true - randomize: false # Google maps can't display two markers which have the same coordinates. This randomizer enables to prevent this situation from happening. - max_random_distance: 100 # in meters. Each marker coordinate could be altered by this distance in a random direction - list_container: null # id of the ul that will host links to all markers - offset: 0 # used when adding_markers to an existing map. Because new markers are concated with previous one, offset is here to prevent the existing from being re-created. - raw: {} # raw json to pass additional options - - #Stored variables - @markers = [] # contains all markers. A marker contains the following: {"description": , "longitude": , "title":, "latitude":, "picture": "", "width": "", "length": "", "sidebar": "", "serviceObject": google_marker} - @boundsObject = null # contains current bounds from markers, polylines etc... - @polygons = [] # contains raw data, array of arrays (first element could be a hash containing options) - @polylines = [] # contains raw data, array of arrays (first element could be a hash containing options) - @circles = [] # contains raw data, array of hash - @markerClusterer = null # contains all marker clusterers - @markerImages = [] - - #Polyline Styling - @polylines_conf = #default style for polylines - strokeColor: "#FF0000" - strokeOpacity: 1 - strokeWeight: 2 - clickable: false - zIndex: null - - #tnitializes the map - initialize : -> - @serviceObject = @createMap() - @map = @serviceObject #beware, soon deprecated - if (@map_options.detect_location == true or @map_options.center_on_user == true) - @findUserLocation(this) - #resets sidebar if needed - @resetSidebarContent() - - findUserLocation : (map_object) -> - if (navigator.geolocation) - #try to retrieve user's position - positionSuccessful = (position) -> - map_object.userLocation = map_object.createLatLng(position.coords.latitude, position.coords.longitude) - #change map's center to focus on user's geoloc if asked - if(map_object.map_options.center_on_user == true) - map_object.centerMapOnUser() - map_object.geolocationSuccess() - positionFailure = -> - map_object.geolocationFailure(true) - - navigator.geolocation.getCurrentPosition( positionSuccessful, positionFailure) - else - #failure but the navigator doesn't handle geolocation - map_object.geolocationFailure(false) - - - #//////////////////////////////////////////////////// - #//////////////////// DIRECTIONS //////////////////// - #//////////////////////////////////////////////////// - - create_direction : -> - directionsDisplay = new google.maps.DirectionsRenderer() - directionsService = new google.maps.DirectionsService() - - directionsDisplay.setMap(@serviceObject) - #display panel only if required - if @direction_conf.display_panel - directionsDisplay.setPanel(document.getElementById(@direction_conf.panel_id)) - - directionsDisplay.setOptions - suppressMarkers: false - suppressInfoWindows: false - suppressPolylines: false - - request = - origin: @direction_conf.origin - destination: @direction_conf.destination - waypoints: @direction_conf.waypoints - optimizeWaypoints: @direction_conf.optimizeWaypoints - unitSystem: google.maps.DirectionsUnitSystem[@direction_conf.unitSystem] - avoidHighways: @direction_conf.avoidHighways - avoidTolls: @direction_conf.avoidTolls - region: @direction_conf.region - travelMode: google.maps.DirectionsTravelMode[@direction_conf.travelMode] - language: "en" - - directionsService.route request, (response, status) -> - if (status == google.maps.DirectionsStatus.OK) - directionsDisplay.setDirections(response) - - #//////////////////////////////////////////////////// - #///////////////////// CIRCLES ////////////////////// - #//////////////////////////////////////////////////// - - #Loops through all circles - #Loops through all circles and draws them - create_circles : -> - for circle in @circles - @create_circle circle - - create_circle : (circle) -> - #by convention, default style configuration could be integrated in the first element - if circle == @circles[0] - @circles_conf.strokeColor = circle.strokeColor if circle.strokeColor? - @circles_conf.strokeOpacity = circle.strokeOpacity if circle.strokeOpacity? - @circles_conf.strokeWeight = circle.strokeWeight if circle.strokeWeight? - @circles_conf.fillColor = circle.fillColor if circle.fillColor? - @circles_conf.fillOpacity = circle.fillOpacity if circle.fillOpacity? - - if circle.lat? and circle.lng? - # always check if a config is given, if not, use defaults - # NOTE: is there a cleaner way to do this? Maybe a hash merge of some sort? - newCircle = new google.maps.Circle - center: @createLatLng(circle.lat, circle.lng) - strokeColor: circle.strokeColor || @circles_conf.strokeColor - strokeOpacity: circle.strokeOpacity || @circles_conf.strokeOpacity - strokeWeight: circle.strokeWeight || @circles_conf.strokeWeight - fillOpacity: circle.fillOpacity || @circles_conf.fillOpacity - fillColor: circle.fillColor || @circles_conf.fillColor - clickable: circle.clickable || @circles_conf.clickable - zIndex: circle.zIndex || @circles_conf.zIndex - radius: circle.radius - - circle.serviceObject = newCircle - newCircle.setMap(@serviceObject) - - # clear circles - clear_circles : -> - for circle in @circles - @clear_circle circle - - clear_circle : (circle) -> - circle.serviceObject.setMap(null) - - hide_circles : -> - for circle in @circles - @hide_circle circle - - hide_circle : (circle) -> - circle.serviceObject.setMap(null) - - show_circles : -> - for circle in @circles - @show_circle @circle - - show_circle : (circle) -> - circle.serviceObject.setMap(@serviceObject) - - #//////////////////////////////////////////////////// - #///////////////////// POLYGONS ///////////////////// - #//////////////////////////////////////////////////// - - #polygons is an array of arrays. It loops. - create_polygons : -> - for polygon in @polygons - @create_polygon(polygon) - - #creates a single polygon, triggered by create_polygons - create_polygon : (polygon) -> - polygon_coordinates = [] - - #Polygon points are in an Array, that's why looping is necessary - for point in polygon - latlng = @createLatLng(point.lat, point.lng) - polygon_coordinates.push(latlng) - #first element of an Array could contain specific configuration for this particular polygon. If no config given, use default - if point == polygon[0] - strokeColor = point.strokeColor || @polygons_conf.strokeColor - strokeOpacity = point.strokeOpacity || @polygons_conf.strokeOpacity - strokeWeight = point.strokeWeight || @polygons_conf.strokeWeight - fillColor = point.fillColor || @polygons_conf.fillColor - fillOpacity = point.fillOpacity || @polygons_conf.fillOpacity - clickable = point.clickable || @polygons_conf.clickable - - #Construct the polygon - new_poly = new google.maps.Polygon - paths: polygon_coordinates - strokeColor: strokeColor - strokeOpacity: strokeOpacity - strokeWeight: strokeWeight - fillColor: fillColor - fillOpacity: fillOpacity - clickable: clickable - map: @serviceObject - - #save polygon in list - polygon.serviceObject = new_poly - - - - #//////////////////////////////////////////////////// - #///////////////////// MARKERS ////////////////////// - #//////////////////////////////////////////////////// - - #creates, clusterizes and adjusts map - create_markers : -> - @createServiceMarkersFromMarkers() - @clusterize() - - #create google.maps Markers from data provided by user - createServiceMarkersFromMarkers : -> - for marker, index in @markers - if not @markers[index].serviceObject? - #extract options, test if value passed or use default - Lat = @markers[index].lat - Lng = @markers[index].lng - - #alter coordinates if randomize is true - if @markers_conf.randomize - LatLng = @randomize(Lat, Lng) - #retrieve coordinates from the array - Lat = LatLng[0] - Lng = LatLng[1] - - #save object - @markers[index].serviceObject = @createMarker - "marker_picture": if @markers[index].picture then @markers[index].picture else @markers_conf.picture - "marker_width": if @markers[index].width then @markers[index].width else @markers_conf.width - "marker_height": if @markers[index].height then @markers[index].height else @markers_conf.length - "marker_title": if @markers[index].title then @markers[index].title else null - "marker_anchor": if @markers[index].marker_anchor then @markers[index].marker_anchor else null - "shadow_anchor": if @markers[index].shadow_anchor then @markers[index].shadow_anchor else null - "shadow_picture": if @markers[index].shadow_picture then @markers[index].shadow_picture else null - "shadow_width": if @markers[index].shadow_width then @markers[index].shadow_width else null - "shadow_height": if @markers[index].shadow_height then @markers[index].shadow_height else null - "marker_draggable": if @markers[index].draggable then @markers[index].draggable else @markers_conf.draggable - "rich_marker": if @markers[index].rich_marker then @markers[index].rich_marker else null - "zindex": if @markers[index].zindex then @markers[index].zindex else null - "Lat": Lat - "Lng": Lng - "index": index - - #add infowindowstuff if enabled - @createInfoWindow(@markers[index]) - #create sidebar if enabled - @createSidebar(@markers[index]) - - @markers_conf.offset = @markers.length - - #creates Image Anchor Position or return null if nothing passed - createImageAnchorPosition : (anchorLocation) -> - if (anchorLocation == null) - return null - else - return @createPoint(anchorLocation[0], anchorLocation[1]) - - - #replace old markers with new markers on an existing map - replaceMarkers : (new_markers, adjustBounds = true) -> - @clearMarkers() - #reset previous markers - @markers = new Array - #reset current bounds - @boundsObject = @createLatLngBounds() if adjustBounds - #reset sidebar content if exists - @resetSidebarContent() - #add new markers - @markers_conf.offset = 0 - @addMarkers(new_markers, adjustBounds) - - #add new markers to on an existing map - addMarkers : (new_markers, adjustBounds = true) -> - #update the list of markers to take into account - @markers = @markers.concat(new_markers) - #put markers on the map - @create_markers() - @adjustMapToBounds() if adjustBounds - - #//////////////////////////////////////////////////// - #///////////////////// SIDEBAR ////////////////////// - #//////////////////////////////////////////////////// - - #//creates sidebar - createSidebar : (marker_container) -> - if (@markers_conf.list_container) - ul = document.getElementById(@markers_conf.list_container) - li = document.createElement('li') - aSel = document.createElement('a') - aSel.href = 'javascript:void(0);' - html = if marker_container.sidebar? then marker_container.sidebar else "Marker" - aSel.innerHTML = html - currentMap = this - aSel.onclick = @sidebar_element_handler(currentMap, marker_container.serviceObject, 'click') - li.appendChild(aSel) - ul.appendChild(li) - - #moves map to marker clicked + open infowindow - sidebar_element_handler : (currentMap, marker, eventType) -> - return () -> - currentMap.map.panTo(marker.position) - google.maps.event.trigger(marker, eventType) - - - resetSidebarContent : -> - if @markers_conf.list_container isnt null - ul = document.getElementById(@markers_conf.list_container) - ul.innerHTML = "" - - #//////////////////////////////////////////////////// - #////////////////// MISCELLANEOUS /////////////////// - #//////////////////////////////////////////////////// - - #to make the map fit the different LatLng points - adjustMapToBounds : -> - #FIRST_STEP: retrieve all bounds - #create the bounds object only if necessary - if @map_options.auto_adjust or @map_options.bounds isnt null - @boundsObject = @createLatLngBounds() - - #if autodjust is true, must get bounds from markers polylines etc... - if @map_options.auto_adjust - #from markers - @extendBoundsWithMarkers() - - #from polylines: - @updateBoundsWithPolylines() - - #from polygons: - @updateBoundsWithPolygons() - - #from circles - @updateBoundsWithCircles() - - #in every case, I've to take into account the bounds set up by the user - @extendMapBounds() - - #SECOND_STEP: ajust the map to the bounds - @adaptMapToBounds() - - #//////////////////////////////////////////////////// - #/////////////////// POLYLINES ////////////////////// - #//////////////////////////////////////////////////// - - #replace old markers with new markers on an existing map - replacePolylines : (new_polylines) -> - #reset previous polylines and kill them from map - @destroy_polylines() - #set new polylines - @polylines = new_polylines - #create - @create_polylines() - #.... and adjust map boundaries - @adjustMapToBounds() - - destroy_polylines : -> - for polyline in @polylines - #delete polylines from map - polyline.serviceObject.setMap(null) - #empty array - @polylines = [] - - #polylines is an array of arrays. It loops. - create_polylines : -> - for polyline in @polylines - @create_polyline polyline - - #//////////////////////////////////////////////////// - #///////////////// Basic functions ////////////////// - #///////////////////tests coded////////////////////// - - #//basic function to check existence of a variable - exists : (var_name) -> - return (var_name != "" and typeof var_name != "undefined") - - - #randomize - randomize : (Lat0, Lng0) -> - #distance in meters between 0 and max_random_distance (positive or negative) - dx = @markers_conf.max_random_distance * @random() - dy = @markers_conf.max_random_distance * @random() - Lat = parseFloat(Lat0) + (180/Math.PI)*(dy/6378137) - Lng = parseFloat(Lng0) + ( 90/Math.PI)*(dx/6378137)/Math.cos(Lat0) - return [Lat, Lng] - - mergeObjectWithDefault : (object1, object2) -> - copy_object1 = {} - for key, value of object1 - copy_object1[key] = value - - for key, value of object2 - unless copy_object1[key]? - copy_object1[key] = value - return copy_object1 - - mergeWithDefault : (objectName) -> - default_object = @["default_" + objectName] - object = @[objectName] - @[objectName] = @mergeObjectWithDefault(object, default_object) - return true - - #gives a value between -1 and 1 - random : -> return(Math.random() * 2 -1) diff --git a/app/assets/javascripts/search/gmaps4rails/gmaps4rails.bing.js.coffee b/app/assets/javascripts/search/gmaps4rails/gmaps4rails.bing.js.coffee deleted file mode 100644 index 9eb53a6b76..0000000000 --- a/app/assets/javascripts/search/gmaps4rails/gmaps4rails.bing.js.coffee +++ /dev/null @@ -1,174 +0,0 @@ -###################################################################################################### -############################################## Bing Maps ########################################## -###################################################################################################### - -#// http://wiki.openstreetmap.org/wiki/OpenLayers -#// http://openlayers.org/dev/examples -#//http://docs.openlayers.org/contents.html - -class @Gmaps4RailsBing extends Gmaps4Rails - - constructor: -> - super - @map_options = - type: "road" # aerial, auto, birdseye, collinsBart, mercator, ordnanceSurvey, road - @markers_conf = - infobox: "description" #description or htmlContent - - @mergeWithDefault("map_options") - @mergeWithDefault("markers_conf") - - #//////////////////////////////////////////////////// - #/////////////// Basic Objects ////////////// - #//////////////////////////////////////////////////// - - getMapType: -> - switch @map_options.type - when "road" then return Microsoft.Maps.MapTypeId.road - when "aerial" then return Microsoft.Maps.MapTypeId.aerial - when "auto" then return Microsoft.Maps.MapTypeId.auto - when "birdseye" then return Microsoft.Maps.MapTypeId.birdseye - when "collinsBart" then return Microsoft.Maps.MapTypeId.collinsBart - when "mercator" then return Microsoft.Maps.MapTypeId.mercator - when "ordnanceSurvey" then return Microsoft.Maps.MapTypeId.ordnanceSurvey - else return Microsoft.Maps.MapTypeId.auto - - createPoint: (lat, lng) -> - return new Microsoft.Maps.Point(lat, lng) - - createLatLng:(lat, lng) -> - return new Microsoft.Maps.Location(lat, lng) - - createLatLngBounds: -> - - createMap: -> - return new Microsoft.Maps.Map(document.getElementById(@map_options.id), { - credentials: @map_options.provider_key, - mapTypeId: @getMapType(), - center: @createLatLng(@map_options.center_latitude, @map_options.center_longitude), - zoom: @map_options.zoom - }) - - createSize: (width, height) -> - return new google.maps.Size(width, height) - - #//////////////////////////////////////////////////// - #////////////////////// Markers ///////////////////// - #//////////////////////////////////////////////////// - - createMarker: (args) -> - markerLatLng = @createLatLng(args.Lat, args.Lng) - marker - #// Marker sizes are expressed as a Size of X,Y - if args.marker_picture == "" - marker = new Microsoft.Maps.Pushpin(@createLatLng(args.Lat, args.Lng), { - draggable: args.marker_draggable, - anchor: @createImageAnchorPosition(args.Lat, args.Lng), - text: args.marker_title - } - ); - else - marker = new Microsoft.Maps.Pushpin(@createLatLng(args.Lat, args.Lng), { - draggable: args.marker_draggable, - anchor: @createImageAnchorPosition(args.Lat, args.Lng), - icon: args.marker_picture, - height: args.marker_height, - text: args.marker_title, - width: args.marker_width - } - ); - @addToMap(marker) - return marker - - #// clear markers - clearMarkers: -> - for marker in @markers - @clearMarker marker - - clearMarker: (marker) -> - @removeFromMap(marker.serviceObject) - - #//show and hide markers - showMarkers: -> - for marker in @markers - @showMarker marker - - showMarker: (marker) -> - marker.serviceObject.setOptions({ visible: true }) - - hideMarkers: -> - for marker in @markers - @hideMarker marker - - hideMarker: (marker) -> - marker.serviceObject.setOptions({ visible: false }) - - extendBoundsWithMarkers: -> - locationsArray = [] - for marker in @markers - locationsArray.push(marker.serviceObject.getLocation()) - @boundsObject = Microsoft.Maps.LocationRect.fromLocations(locationsArray) - - #//////////////////////////////////////////////////// - #/////////////////// Clusterer ////////////////////// - #//////////////////////////////////////////////////// - - createClusterer: (markers_array) -> - - clearClusterer: -> - - #//creates clusters - clusterize: -> - - #//////////////////////////////////////////////////// - #/////////////////// INFO WINDOW //////////////////// - #//////////////////////////////////////////////////// - - #// creates infowindows - createInfoWindow: (marker_container) -> - if marker_container.description? - #//create the infowindow - if @markers_conf.infobox == "description" - marker_container.info_window = new Microsoft.Maps.Infobox(marker_container.serviceObject.getLocation(), { description: marker_container.description, visible: false, showCloseButton: true}) - else - marker_container.info_window = new Microsoft.Maps.Infobox(marker_container.serviceObject.getLocation(), { htmlContent: marker_container.description, visible: false}) - - #//add the listener associated - currentMap = this - Microsoft.Maps.Events.addHandler(marker_container.serviceObject, 'click', @openInfoWindow(currentMap, marker_container.info_window)) - @addToMap(marker_container.info_window) - - openInfoWindow: (currentMap, infoWindow) -> - return -> - # Close the latest selected marker before opening the current one. - if currentMap.visibleInfoWindow - currentMap.visibleInfoWindow.setOptions({ visible: false }) - infoWindow.setOptions({ visible:true }) - currentMap.visibleInfoWindow = infoWindow - - #//////////////////////////////////////////////////// - #/////////////////// Other methods ////////////////// - #//////////////////////////////////////////////////// - - fitBounds: -> - @serviceObject.setView({bounds: @boundsObject}) - - addToMap: (object)-> - @serviceObject.entities.push(object) - - removeFromMap: (object)-> - @serviceObject.entities.remove(object) - - centerMapOnUser: -> - @serviceObject.setView({ center: @userLocation}) - - updateBoundsWithPolylines: ()-> - - updateBoundsWithPolygons: ()-> - - updateBoundsWithCircles: ()-> - - extendMapBounds :-> - - adaptMapToBounds: -> - @fitBounds() \ No newline at end of file diff --git a/app/assets/javascripts/search/gmaps4rails/gmaps4rails.googlemaps.js.coffee b/app/assets/javascripts/search/gmaps4rails/gmaps4rails.googlemaps.js.coffee deleted file mode 100644 index ed52ddc15a..0000000000 --- a/app/assets/javascripts/search/gmaps4rails/gmaps4rails.googlemaps.js.coffee +++ /dev/null @@ -1,339 +0,0 @@ -####################################################################################################### -############################################## Google maps ########################################## -####################################################################################################### - -class @Gmaps4RailsGoogle extends Gmaps4Rails - - constructor: -> - super - #Map settings - @map_options = - disableDefaultUI: false - disableDoubleClickZoom: false - type: "ROADMAP" # HYBRID, ROADMAP, SATELLITE, TERRAIN - - #markers + info styling - @markers_conf = - clusterer_gridSize: 50 - clusterer_maxZoom: 5 - custom_cluster_pictures: null - custom_infowindow_class: null - - @mergeWithDefault("map_options") - @mergeWithDefault("markers_conf") - - @kml_options = - clickable: true - preserveViewport: false - suppressInfoWindows: false - - #Polygon Styling - @polygons_conf = # default style for polygons - strokeColor: "#FFAA00" - strokeOpacity: 0.8 - strokeWeight: 2 - fillColor: "#000000" - fillOpacity: 0.35 - clickable: false - - #Circle Styling - @circles_conf = #default style for circles - fillColor: "#00AAFF" - fillOpacity: 0.35 - strokeColor: "#FFAA00" - strokeOpacity: 0.8 - strokeWeight: 2 - clickable: false - zIndex: null - - #Direction Settings - @direction_conf = - panel_id: null - display_panel: false - origin: null - destination: null - waypoints: [] #[{location: "toulouse,fr", stopover: true}, {location: "Clermont-Ferrand, fr", stopover: true}] - optimizeWaypoints: false - unitSystem: "METRIC" #IMPERIAL - avoidHighways: false - avoidTolls: false - region: null - travelMode: "DRIVING" #WALKING, BICYCLING - - #//////////////////////////////////////////////////// - #/////////////// Basic Objects ////////////// - #//////////////////////////////////////////////////// - - createPoint : (lat, lng) -> - return new google.maps.Point(lat, lng) - - createLatLng : (lat, lng) -> - return new google.maps.LatLng(lat, lng) - - createLatLngBounds : -> - return new google.maps.LatLngBounds() - - createMap : -> - defaultOptions = - maxZoom: @map_options.maxZoom - minZoom: @map_options.minZoom - zoom: @map_options.zoom - center: @createLatLng(@map_options.center_latitude, @map_options.center_longitude) - mapTypeId: google.maps.MapTypeId[@map_options.type] - mapTypeControl: @map_options.mapTypeControl - disableDefaultUI: @map_options.disableDefaultUI - disableDoubleClickZoom: @map_options.disableDoubleClickZoom - draggable: @map_options.draggable - - mergedOptions = @mergeObjectWithDefault @map_options.raw, defaultOptions - - return new google.maps.Map document.getElementById(@map_options.id), mergedOptions - - - createMarkerImage : (markerPicture, markerSize, origin, anchor, scaledSize) -> - return new google.maps.MarkerImage(markerPicture, markerSize, origin, anchor, scaledSize) - - createSize : (width, height) -> - return new google.maps.Size(width, height) - - #//////////////////////////////////////////////////// - #////////////////////// Markers ///////////////////// - #//////////////////////////////////////////////////// - - createMarker : (args) -> - markerLatLng = @createLatLng(args.Lat, args.Lng) - #Marker sizes are expressed as a Size of X,Y - if args.marker_picture == "" and args.rich_marker == null - defaultOptions = {position: markerLatLng, map: @serviceObject, title: args.marker_title, draggable: args.marker_draggable, zIndex: args.zindex} - mergedOptions = @mergeObjectWithDefault @markers_conf.raw, defaultOptions - return new google.maps.Marker mergedOptions - - if (args.rich_marker != null) - return new RichMarker({ - position: markerLatLng - map: @serviceObject - draggable: args.marker_draggable - content: args.rich_marker - flat: if args.marker_anchor == null then false else args.marker_anchor[1] - anchor: if args.marker_anchor == null then 0 else args.marker_anchor[0] - zIndex: args.zindex - }) - - #default behavior - #calculate MarkerImage anchor location - imageAnchorPosition = @createImageAnchorPosition args.marker_anchor - shadowAnchorPosition = @createImageAnchorPosition args.shadow_anchor - #create or retrieve existing MarkerImages - markerImage = @createOrRetrieveImage(args.marker_picture, args.marker_width, args.marker_height, imageAnchorPosition) - shadowImage = @createOrRetrieveImage(args.shadow_picture, args.shadow_width, args.shadow_height, shadowAnchorPosition) - defaultOptions = {position: markerLatLng, map: @serviceObject, icon: markerImage, title: args.marker_title, draggable: args.marker_draggable, shadow: shadowImage, zIndex: args.zindex} - mergedOptions = @mergeObjectWithDefault @markers_conf.raw, defaultOptions - return new google.maps.Marker mergedOptions - - #checks if obj is included in arr Array and returns the position or false - includeMarkerImage : (arr, obj) -> - for object, index in arr - return index if object.url == obj - return false - - #checks if MarkerImage exists before creating a new one - #returns a MarkerImage or false if ever something wrong is passed as argument - createOrRetrieveImage : (currentMarkerPicture, markerWidth, markerHeight, imageAnchorPosition) -> - return null if (currentMarkerPicture == "" or currentMarkerPicture == null ) - - test_image_index = @includeMarkerImage(@markerImages, currentMarkerPicture) - switch test_image_index - when false - markerImage = @createMarkerImage(currentMarkerPicture, @createSize(markerWidth, markerHeight), null, imageAnchorPosition, null ) - @markerImages.push(markerImage) - return markerImage - break - else - return @markerImages[test_image_index] if typeof test_image_index == 'number' - return false - - #clear markers - clearMarkers : -> - for marker in @markers - @clearMarker marker - - #show and hide markers - showMarkers : -> - for marker in @markers - @showMarker marker - - hideMarkers : -> - for marker in @markers - @hideMarker marker - - clearMarker : (marker) -> - marker.serviceObject.setMap(null) - - showMarker : (marker) -> - marker.serviceObject.setVisible(true) - - hideMarker : (marker) -> - marker.serviceObject.setVisible(false) - - extendBoundsWithMarkers : -> - for marker in @markers - @boundsObject.extend(marker.serviceObject.position) - - #//////////////////////////////////////////////////// - #/////////////////// Clusterer ////////////////////// - #//////////////////////////////////////////////////// - - createClusterer : (markers_array) -> - return new MarkerClusterer( @serviceObject, markers_array, { maxZoom: @markers_conf.clusterer_maxZoom, gridSize: @markers_conf.clusterer_gridSize, styles: @customClusterer() }) - - clearClusterer : -> - @markerClusterer.clearMarkers() - - #creates clusters - clusterize : -> - if @markers_conf.do_clustering == true - #first clear the existing clusterer if any - @clearClusterer() if @markerClusterer != null - - markers_array = new Array - for marker in @markers - markers_array.push(marker.serviceObject) - - @markerClusterer = @createClusterer(markers_array) - - #//////////////////////////////////////////////////// - #/////////////////// INFO WINDOW //////////////////// - #//////////////////////////////////////////////////// - - #// creates infowindows - createInfoWindow : (marker_container) -> - if typeof(@jsTemplate) == "function" or marker_container.description? - marker_container.description = @jsTemplate(marker_container) if typeof(@jsTemplate) == "function" - if @markers_conf.custom_infowindow_class != null - #creating custom infowindow - boxText = document.createElement("div") - boxText.setAttribute("class", @markers_conf.custom_infowindow_class) #to customize - boxText.innerHTML = marker_container.description - marker_container.infowindow = new InfoBox(@infobox(boxText)) - currentMap = this - google.maps.event.addListener(marker_container.serviceObject, 'click', @openInfoWindow(currentMap, marker_container.infowindow, marker_container.serviceObject)) - else - #create default infowindow - marker_container.infowindow = new google.maps.InfoWindow({content: marker_container.description }) - #add the listener associated - currentMap = this - google.maps.event.addListener(marker_container.serviceObject, 'click', @openInfoWindow(currentMap, marker_container.infowindow, marker_container.serviceObject)) - - openInfoWindow : (currentMap, infoWindow, marker) -> - return -> - # Close the latest selected marker before opening the current one. - currentMap.visibleInfoWindow.close() if currentMap.visibleInfoWindow != null - infoWindow.open(currentMap.serviceObject, marker) - currentMap.visibleInfoWindow = infoWindow - - #//////////////////////////////////////////////////// - #///////////////// KML ////////////////// - #//////////////////////////////////////////////////// - - createKmlLayer : (kml) -> - kml_options = kml.options || {} - kml_options = @mergeObjectWithDefault(kml_options, @kml_options) - kml = new google.maps.KmlLayer( kml.url, kml_options) - kml.setMap(@serviceObject) - return kml - - #//////////////////////////////////////////////////// - #/////////////////// POLYLINES ////////////////////// - #//////////////////////////////////////////////////// - - #creates a single polyline, triggered by create_polylines - create_polyline : (polyline) -> - polyline_coordinates = [] - - #2 cases here, either we have a coded array of LatLng or we have an Array of LatLng - for element in polyline - #if we have a coded array - if element.coded_array? - decoded_array = new google.maps.geometry.encoding.decodePath(element.coded_array) - #loop through every point in the array - for point in decoded_array - polyline_coordinates.push(point) - - #or we have an array of latlng - else - #by convention, a single polyline could be customized in the first array or it uses default values - if element == polyline[0] - strokeColor = element.strokeColor || @polylines_conf.strokeColor - strokeOpacity = element.strokeOpacity || @polylines_conf.strokeOpacity - strokeWeight = element.strokeWeight || @polylines_conf.strokeWeight - clickable = element.clickable || @polylines_conf.clickable - zIndex = element.zIndex || @polylines_conf.zIndex - - #add latlng if positions provided - if element.lat? && element.lng? - latlng = @createLatLng(element.lat, element.lng) - polyline_coordinates.push(latlng) - - # Construct the polyline - new_poly = new google.maps.Polyline - path: polyline_coordinates - strokeColor: strokeColor - strokeOpacity: strokeOpacity - strokeWeight: strokeWeight - clickable: clickable - zIndex: zIndex - - #save polyline - polyline.serviceObject = new_poly - new_poly.setMap(@serviceObject) - - - updateBoundsWithPolylines: ()-> - for polyline in @polylines - polyline_points = polyline.serviceObject.latLngs.getArray()[0].getArray() - for point in polyline_points - @boundsObject.extend point - - #//////////////////////////////////////////////////// - #///////////////// KML ////////////////// - #//////////////////////////////////////////////////// - - create_kml : -> - for kml in @kml - kml.serviceObject = @createKmlLayer kml - - #//////////////////////////////////////////////////// - #/////////////////// Other methods ////////////////// - #//////////////////////////////////////////////////// - - fitBounds : -> - @serviceObject.fitBounds(@boundsObject) unless @boundsObject.isEmpty() - - centerMapOnUser : -> - @serviceObject.setCenter(@userLocation) - - updateBoundsWithPolygons: ()-> - for polygon in @polygons - polygon_points = polygon.serviceObject.latLngs.getArray()[0].getArray() - for point in polygon_points - @boundsObject.extend point - - updateBoundsWithCircles: ()-> - for circle in @circles - @boundsObject.extend(circle.serviceObject.getBounds().getNorthEast()) - @boundsObject.extend(circle.serviceObject.getBounds().getSouthWest()) - - extendMapBounds: ()-> - for bound in @map_options.bounds - #create points from bounds provided - @boundsObject.extend @createLatLng(bound.lat, bound.lng) - - adaptMapToBounds:()-> - #if autozoom is false, take user info into account - if !@map_options.auto_zoom - map_center = @boundsObject.getCenter() - @map_options.center_latitude = map_center.lat() - @map_options.center_longitude = map_center.lng() - @serviceObject.setCenter(map_center) - else - @fitBounds() diff --git a/app/assets/javascripts/search/gmaps4rails/gmaps4rails.mapquest.js.coffee b/app/assets/javascripts/search/gmaps4rails/gmaps4rails.mapquest.js.coffee deleted file mode 100644 index 08fca694d0..0000000000 --- a/app/assets/javascripts/search/gmaps4rails/gmaps4rails.mapquest.js.coffee +++ /dev/null @@ -1,145 +0,0 @@ -####################################################################################################### -############################################## Map Quest ############################################# -####################################################################################################### -# http://developer.mapquest.com/web/documentation/sdk/javascript/v7.0/api/MQA.Poi.html - -class @Gmaps4RailsMapquest extends Gmaps4Rails - - constructor: -> - super - #Map settings - @map_options = {type: "map"} #map type (map, sat, hyb) - @markers_conf = {} - @mergeWithDefault "markers_conf" - @mergeWithDefault "map_options" - - #//////////////////////////////////////////////////// - #/////////////// Basic Objects ////////////// - #//////////////////////////////////////////////////// - - createPoint: (lat, lng) -> - return new MQA.Poi({lat: lat, lng: lng}) - - createLatLng: (lat, lng) -> - return {lat: lat, lng: lng} - - createLatLngBounds: -> - - createMap: -> - map = new MQA.TileMap( #// Constructs an instance of MQA.TileMap - document.getElementById(@map_options.id), #//the id of the element on the page you want the map to be added into - @map_options.zoom, #//intial zoom level of the map - {lat: @map_options.center_latitude, lng: @map_options.center_longitude}, - @map_options.type) #//map type (map, sat, hyb) - - MQA.withModule('zoomcontrol3', (-> - map.addControl( - new MQA.LargeZoomControl3(), - new MQA.MapCornerPlacement(MQA.MapCorner.TOP_LEFT) - ) - )) - return map - - createMarkerImage: (markerPicture, markerSize, origin, anchor, scaledSize) -> - - #//////////////////////////////////////////////////// - #////////////////////// Markers ///////////////////// - #//////////////////////////////////////////////////// - - createMarker: (args)-> - marker = new MQA.Poi( {lat: args.Lat, lng: args.Lng} ) - - if args.marker_picture != "" - icon = new MQA.Icon(args.marker_picture, args.marker_height, args.marker_width) - marker.setIcon(icon) - if args.marker_anchor != null - marker.setBias({x: args.marker_anchor[0], y: args.marker_anchor[1]}) - - if args.shadow_picture != "" - icon = new MQA.Icon(args.shadow_picture, args.shadow_height, args.shadow_width) - marker.setShadow(icon) - - if args.shadow_anchor != null - marker.setShadowOffset({x: args.shadow_anchor[0], y: args.shadow_anchor[1]}) - - @addToMap marker - return marker - - - #// clear markers - clearMarkers: -> - for marker in markers - @clearMarker marker - - #//show and hide markers - showMarkers: -> - for marker in markers - @showMarker marker - - hideMarkers: -> - for marker in markers - @hideMarker marker - - clearMarker: (marker) -> - @removeFromMap(marker.serviceObject) - - showMarker: (marker) -> - #// marker.serviceObject - - hideMarker: (marker) -> - #// marker.serviceObject - - extendBoundsWithMarkers: -> - if @markers.length >=2 - @boundsObject = new MQA.RectLL(@markers[0].serviceObject.latLng, @markers[1].serviceObject.latLng) - for marker in @markers - @boundsObject.extend marker.serviceObject.latLng - - #//////////////////////////////////////////////////// - #/////////////////// Clusterer ////////////////////// - #//////////////////////////////////////////////////// - - createClusterer: (markers_array) -> - - clearClusterer: -> - - #//creates clusters - clusterize: -> - - #//////////////////////////////////////////////////// - #/////////////////// INFO WINDOW //////////////////// - #//////////////////////////////////////////////////// - - #// creates infowindows - createInfoWindow: (marker_container) -> - marker_container.serviceObject.setInfoTitleHTML(marker_container.description) - #//TODO: how to disable the mouseover display when using setInfoContentHTML? - #//marker_container.serviceObject.setInfoContentHTML(marker_container.description); - - #//////////////////////////////////////////////////// - #/////////////////// Other methods ////////////////// - #//////////////////////////////////////////////////// - - fitBounds: -> - @serviceObject.zoomToRect @boundsObject if @markers.length >=2 - @serviceObject.setCenter @markers[0].serviceObject.latLng if @markers.length == 1 - - centerMapOnUser: -> - @serviceObject.setCenter @userLocation - - addToMap: (object) -> - @serviceObject.addShape object - - removeFromMap: (object)-> - @serviceObject.removeShape object - - updateBoundsWithPolylines: ()-> - - updateBoundsWithPolygons: ()-> - - updateBoundsWithCircles: ()-> - - extendMapBounds :-> - - adaptMapToBounds: -> - @fitBounds() \ No newline at end of file diff --git a/app/assets/javascripts/search/gmaps4rails/gmaps4rails.openlayers.js.coffee b/app/assets/javascripts/search/gmaps4rails/gmaps4rails.openlayers.js.coffee deleted file mode 100644 index 1cddc04e39..0000000000 --- a/app/assets/javascripts/search/gmaps4rails/gmaps4rails.openlayers.js.coffee +++ /dev/null @@ -1,261 +0,0 @@ -####################################################################################################### -############################################## Open Layers ########################################## -####################################################################################################### - -#// http://wiki.openstreetmap.org/wiki/OpenLayers -#// http://openlayers.org/dev/examples -#//http://docs.openlayers.org/contents.html - -class @Gmaps4RailsOpenlayers extends Gmaps4Rails - - constructor: -> - super - @map_options = {} - @mergeWithDefault "map_options" - @markers_conf = {} - @mergeWithDefault "markers_conf" - - @openMarkers = null - @markersLayer = null - @markersControl = null - @polylinesLayer = null - - #//////////////////////////////////////////////////// - #/////////////// Basic Objects //////////////////// - #//////////////////////////////////////////////////// - - createPoint: (lat, lng)-> - - createLatLng: (lat, lng)-> - return new OpenLayers.LonLat(lng, lat).transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")) # transform from WGS 1984 to Spherical Mercator Projection - - createAnchor: (offset)-> - return null if offset == null - return new OpenLayers.Pixel(offset[0], offset[1]) - - createSize: (width, height)-> - return new OpenLayers.Size(width, height) - - createLatLngBounds: -> - return new OpenLayers.Bounds() - - createMap: -> - #//todo add customization: kind of map and other map options - map = new OpenLayers.Map(@map_options.id) - map.addLayer(new OpenLayers.Layer.OSM()) - map.setCenter(@createLatLng(@map_options.center_latitude, @map_options.center_longitude), #// Center of the map - @map_options.zoom) #// Zoom level - return map - - #//////////////////////////////////////////////////// - #////////////////////// Markers ///////////////////// - #//////////////////////////////////////////////////// - #//http://openlayers.org/dev/examples/marker-shadow.html - createMarker: (args) -> - style_mark = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']) - style_mark.fillOpacity = 1 - - #//creating markers' dedicated layer - if (@markersLayer == null) - @markersLayer = new OpenLayers.Layer.Vector("Markers", null) - @serviceObject.addLayer(@markersLayer) - #//TODO move? - @markersLayer.events.register("featureselected", @markersLayer, @onFeatureSelect) - @markersLayer.events.register("featureunselected", @markersLayer, @onFeatureUnselect) - @markersControl = new OpenLayers.Control.SelectFeature(@markersLayer) - @serviceObject.addControl(@markersControl) - @markersControl.activate() - #//showing default pic if none available - if args.marker_picture == "" - #style_mark.graphicWidth = 24 - style_mark.graphicHeight = 30 - style_mark.externalGraphic = "http://openlayers.org/dev/img/marker-blue.png" - #//creating custom pic - else - style_mark.graphicWidth = args.marker_width - style_mark.graphicHeight = args.marker_height - style_mark.externalGraphic = args.marker_picture - #//adding anchor if any - if args.marker_anchor != null - style_mark.graphicXOffset = args.marker_anchor[0] - style_mark.graphicYOffset = args.marker_anchor[1] - #//adding shadow if any - if args.shadow_picture != "" - style_mark.backgroundGraphic = args.shadow_picture - style_mark.backgroundWidth = args.shadow_width - style_mark.backgroundHeight = args.shadow_height - #//adding shadow's anchor if any - if args.shadow_anchor != null - style_mark.backgroundXOffset = args.shadow_anchor[0] - style_mark.backgroundYOffset = args.shadow_anchor[1] - - style_mark.graphicTitle = args.marker_title - marker = new OpenLayers.Feature.Vector( - new OpenLayers.Geometry.Point(args.Lng, args.Lat), - null, - style_mark) - #//changing coordinates so that it actually appears on the map! - marker.geometry.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")) - #//adding layer to the map - @markersLayer.addFeatures([marker]) - - return marker - - #//clear markers - clearMarkers: -> - @clearMarkersLayerIfExists() - @markersLayer = null - @boundsObject = new OpenLayers.Bounds() - - clearMarkersLayerIfExists: -> - @serviceObject.removeLayer(@markersLayer) if @markersLayer != null and @serviceObject.getLayer(@markersLayer.id) != null - - extendBoundsWithMarkers: -> - console.log "here" - for marker in @markers - @boundsObject.extend(@createLatLng(marker.lat,marker.lng)) - - #//////////////////////////////////////////////////// - #/////////////////// Clusterer ////////////////////// - #//////////////////////////////////////////////////// - #//too ugly to be considered valid :( - - createClusterer: (markers_array)-> - options = - pointRadius: "${radius}" - fillColor: "#ffcc66" - fillOpacity: 0.8 - strokeColor: "#cc6633" - strokeWidth: "${width}" - strokeOpacity: 0.8 - funcs = - context: - width: (feature) -> - return (feature.cluster) ? 2 : 1 - radius: (feature) -> - pix = 2 - pix = Math.min(feature.attributes.count, 7) + 2 if feature.cluster - return pix - - style = new OpenLayers.Style options, funcs - - strategy = new OpenLayers.Strategy.Cluster() - - clusters = new OpenLayers.Layer.Vector "Clusters", - strategies: [strategy] - styleMap: new OpenLayers.StyleMap - "default": style - "select": - fillColor: "#8aeeef" - strokeColor: "#32a8a9" - - @clearMarkersLayerIfExists() - @serviceObject.addLayer(clusters) - clusters.addFeatures(markers_array) - return clusters - - clusterize: -> - - if @markers_conf.do_clustering == true - #//first clear the existing clusterer if any - if @markerClusterer != null - @clearClusterer() - markers_array = new Array - for marker in @markers - markers_array.push(marker.serviceObject) - @markerClusterer = @createClusterer markers_array - - clearClusterer: -> - @serviceObject.removeLayer @markerClusterer - - #//////////////////////////////////////////////////// - #/////////////////// INFO WINDOW //////////////////// - #//////////////////////////////////////////////////// - - #// creates infowindows - createInfoWindow: (marker_container) -> - marker_container.serviceObject.infoWindow = marker_container.description if marker_container.description? - - onPopupClose: (evt) -> - #// 'this' is the popup. - @markersControl.unselect @feature - - onFeatureSelect: (evt) -> - feature = evt.feature - popup = new OpenLayers.Popup.FramedCloud("featurePopup", - feature.geometry.getBounds().getCenterLonLat(), - new OpenLayers.Size(300,200), - feature.infoWindow, - null, true, @onPopupClose) - feature.popup = popup - popup.feature = feature - @map.addPopup popup - - onFeatureUnselect: (evt) -> - feature = evt.feature - if feature.popup - #//popup.feature = null; - @map.removePopup feature.popup - feature.popup.destroy() - feature.popup = null - - #//////////////////////////////////////////////////// - #/////////////////// POLYLINES ////////////////////// - #//////////////////////////////////////////////////// - - create_polyline : (polyline) -> - - if(@polylinesLayer == null) - @polylinesLayer = new OpenLayers.Layer.Vector("Polylines", null) - @serviceObject.addLayer(@polylinesLayer) - @polylinesLayer.events.register("featureselected", @polylinesLayer, @onFeatureSelect) - @polylinesLayer.events.register("featureunselected", @polylinesLayer, @onFeatureUnselect) - @polylinesControl = new OpenLayers.Control.DrawFeature(@polylinesLayer, OpenLayers.Handler.Path) - @serviceObject.addControl(@polylinesControl) - - polyline_coordinates = [] - - for element in polyline - #by convention, a single polyline could be customized in the first array or it uses default values - if element == polyline[0] - strokeColor = element.strokeColor || @polylines_conf.strokeColor - strokeOpacity = element.strokeOpacity || @polylines_conf.strokeOpacity - strokeWeight = element.strokeWeight || @polylines_conf.strokeWeight - clickable = element.clickable || @polylines_conf.clickable - zIndex = element.zIndex || @polylines_conf.zIndex - - #add latlng if positions provided - if element.lat? && element.lng? - latlng = new OpenLayers.Geometry.Point(element.lng, element.lat) - polyline_coordinates.push(latlng) - - line_points = new OpenLayers.Geometry.LineString(polyline_coordinates); - line_style = { strokeColor: strokeColor, strokeOpacity: strokeOpacity, strokeWidth: strokeWeight }; - - polyline = new OpenLayers.Feature.Vector(line_points, null, line_style); - polyline.geometry.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")) - - @polylinesLayer.addFeatures([polyline]) - - return polyline - - updateBoundsWithPolylines: ()-> - - updateBoundsWithPolygons: ()-> - - updateBoundsWithCircles: ()-> - - # #//////////////////////////////////////////////////// - # #/////////////////// Other methods ////////////////// - # #//////////////////////////////////////////////////// - - fitBounds: -> - @serviceObject.zoomToExtent(@boundsObject, true) - - centerMapOnUser: -> - @serviceObject.setCenter @userLocation - - extendMapBounds :-> - - adaptMapToBounds: -> - @fitBounds() diff --git a/app/assets/javascripts/search/jquery.backstretch.js b/app/assets/javascripts/search/jquery.backstretch.js deleted file mode 100644 index 4cb7175e99..0000000000 --- a/app/assets/javascripts/search/jquery.backstretch.js +++ /dev/null @@ -1,4 +0,0 @@ -/*! Backstretch - v2.0.4 - 2013-06-19 - * http://srobbin.com/jquery-plugins/backstretch/ - * Copyright (c) 2013 Scott Robbin; Licensed MIT */ -(function(a,d,p){a.fn.backstretch=function(c,b){(c===p||0===c.length)&&a.error("No images were supplied for Backstretch");0===a(d).scrollTop()&&d.scrollTo(0,0);return this.each(function(){var d=a(this),g=d.data("backstretch");if(g){if("string"==typeof c&&"function"==typeof g[c]){g[c](b);return}b=a.extend(g.options,b);g.destroy(!0)}g=new q(this,c,b);d.data("backstretch",g)})};a.backstretch=function(c,b){return a("body").backstretch(c,b).data("backstretch")};a.expr[":"].backstretch=function(c){return a(c).data("backstretch")!==p};a.fn.backstretch.defaults={centeredX:!0,centeredY:!0,duration:5E3,fade:0};var r={left:0,top:0,overflow:"hidden",margin:0,padding:0,height:"100%",width:"100%",zIndex:-999999},s={position:"absolute",display:"none",margin:0,padding:0,border:"none",width:"auto",height:"auto",maxHeight:"none",maxWidth:"none",zIndex:-999999},q=function(c,b,e){this.options=a.extend({},a.fn.backstretch.defaults,e||{});this.images=a.isArray(b)?b:[b];a.each(this.images,function(){a("")[0].src=this});this.isBody=c===document.body;this.$container=a(c);this.$root=this.isBody?l?a(d):a(document):this.$container;c=this.$container.children(".backstretch").first();this.$wrap=c.length?c:a('
').css(r).appendTo(this.$container);this.isBody||(c=this.$container.css("position"),b=this.$container.css("zIndex"),this.$container.css({position:"static"===c?"relative":c,zIndex:"auto"===b?0:b,background:"none"}),this.$wrap.css({zIndex:-999998}));this.$wrap.css({position:this.isBody&&l?"fixed":"absolute"});this.index=0;this.show(this.index);a(d).on("resize.backstretch",a.proxy(this.resize,this)).on("orientationchange.backstretch",a.proxy(function(){this.isBody&&0===d.pageYOffset&&(d.scrollTo(0,1),this.resize())},this))};q.prototype={resize:function(){try{var a={left:0,top:0},b=this.isBody?this.$root.width():this.$root.innerWidth(),e=b,g=this.isBody?d.innerHeight?d.innerHeight:this.$root.height():this.$root.innerHeight(),j=e/this.$img.data("ratio"),f;j>=g?(f=(j-g)/2,this.options.centeredY&&(a.top="-"+f+"px")):(j=g,e=j*this.$img.data("ratio"),f=(e-b)/2,this.options.centeredX&&(a.left="-"+f+"px"));this.$wrap.css({width:b,height:g}).find("img:not(.deleteable)").css({width:e,height:j}).css(a)}catch(h){}return this},show:function(c){if(!(Math.abs(c)>this.images.length-1)){var b=this,e=b.$wrap.find("img").addClass("deleteable"),d={relatedTarget:b.$container[0]};b.$container.trigger(a.Event("backstretch.before",d),[b,c]);this.index=c;clearInterval(b.interval);b.$img=a("").css(s).bind("load",function(f){var h=this.width||a(f.target).width();f=this.height||a(f.target).height();a(this).data("ratio",h/f);a(this).fadeIn(b.options.speed||b.options.fade,function(){e.remove();b.paused||b.cycle();a(["after","show"]).each(function(){b.$container.trigger(a.Event("backstretch."+this,d),[b,c])})});b.resize()}).appendTo(b.$wrap);b.$img.attr("src",b.images[c]);return b}},next:function(){return this.show(this.indexe||d.operamini&&"[object OperaMini]"==={}.toString.call(d.operamini)||n&&7458>t||-1e||h&&6>h||"palmGetResource"in d&&e&&534>e||-1=k)})(jQuery,window); \ No newline at end of file diff --git a/app/assets/javascripts/search/jquery.offcanvas.js b/app/assets/javascripts/search/jquery.offcanvas.js deleted file mode 100644 index 4f65c081b9..0000000000 --- a/app/assets/javascripts/search/jquery.offcanvas.js +++ /dev/null @@ -1,62 +0,0 @@ -//;(function (window, document, $) { -// alert($("#sidebarButton").html()); -//}(this, document, jQuery)); - - - - -//;(function (window, document, $) { -// // Set the negative margin on the top menu for slide-menu pages -// var $selector1 = $('#topMenu'), -// events = 'click.fndtn'; -// if ($selector1.length > 0) $selector1.css("margin-top", $selector1.height() * -1); -// -// // Watch for clicks to show the sidebar -// var $selector2 = $('#sidebarButton'); -// if ($selector2.length > 0) { -// $('#sidebarButton').on(events, function (e) { -// console.log("testing one two three"); -// e.preventDefault(); -// $('body').toggleClass('active'); -// }); -// } -// else { -// console.log("not supposed to be there"); -// } -// -// // Watch for clicks to show the menu for slide-menu pages -// var $selector3 = $('#menuButton'); -// if ($selector3.length > 0) { -// $('#menuButton').on(events, function (e) { -// e.preventDefault(); -// $('body').toggleClass('active-menu'); -// }); -// } -// -// // // Adjust sidebars and sizes when resized -// // $(window).resize(function() { -// // // if (!navigator.userAgent.match(/Android/i)) $('body').removeClass('active'); -// // var $selector4 = $('#topMenu'); -// // if ($selector4.length > 0) $selector4.css("margin-top", $selector4.height() * -1); -// // }); -// -// // Switch panels for the paneled nav on mobile -// var $selector5 = $('#switchPanels'); -// if ($selector5.length > 0) { -// $('#switchPanels dd').on(events, function (e) { -// e.preventDefault(); -// var switchToPanel = $(this).children('a').attr('href'), -// switchToIndex = $(switchToPanel).index(); -// $(this).toggleClass('active').siblings().removeClass('active'); -// $(switchToPanel).parent().css("left", (switchToIndex * (-100) + '%')); -// }); -// } -// -// $('#nav li a').on(events, function (e) { -// alert("test"); -// e.preventDefault(); -// var href = $(this).attr('href'), -// $target = $(href); -// $('html, body').animate({scrollTop : $target.offset().top}, 300); -// }); -//}(this, document, jQuery)); diff --git a/app/assets/javascripts/search/modernizr.foundation.js b/app/assets/javascripts/search/modernizr.foundation.js deleted file mode 100644 index 4eb3d0655f..0000000000 --- a/app/assets/javascripts/search/modernizr.foundation.js +++ /dev/null @@ -1,4 +0,0 @@ -/* Modernizr 2.6.2 (Custom Build) | MIT & BSD - * Build: http://modernizr.com/download/#-inlinesvg-svg-svgclippaths-touch-shiv-mq-cssclasses-teststyles-prefixes-ie8compat-load - */ -;window.Modernizr=function(a,b,c){function y(a){j.cssText=a}function z(a,b){return y(m.join(a+";")+(b||""))}function A(a,b){return typeof a===b}function B(a,b){return!!~(""+a).indexOf(b)}function C(a,b,d){for(var e in a){var f=b[a[e]];if(f!==c)return d===!1?a[e]:A(f,"function")?f.bind(d||b):f}return!1}var d="2.6.2",e={},f=!0,g=b.documentElement,h="modernizr",i=b.createElement(h),j=i.style,k,l={}.toString,m=" -webkit- -moz- -o- -ms- ".split(" "),n={svg:"http://www.w3.org/2000/svg"},o={},p={},q={},r=[],s=r.slice,t,u=function(a,c,d,e){var f,i,j,k,l=b.createElement("div"),m=b.body,n=m||b.createElement("body");if(parseInt(d,10))while(d--)j=b.createElement("div"),j.id=e?e[d]:h+(d+1),l.appendChild(j);return f=["­",'"].join(""),l.id=h,(m?l:n).innerHTML+=f,n.appendChild(l),m||(n.style.background="",n.style.overflow="hidden",k=g.style.overflow,g.style.overflow="hidden",g.appendChild(n)),i=c(l,a),m?l.parentNode.removeChild(l):(n.parentNode.removeChild(n),g.style.overflow=k),!!i},v=function(b){var c=a.matchMedia||a.msMatchMedia;if(c)return c(b).matches;var d;return u("@media "+b+" { #"+h+" { position: absolute; } }",function(b){d=(a.getComputedStyle?getComputedStyle(b,null):b.currentStyle)["position"]=="absolute"}),d},w={}.hasOwnProperty,x;!A(w,"undefined")&&!A(w.call,"undefined")?x=function(a,b){return w.call(a,b)}:x=function(a,b){return b in a&&A(a.constructor.prototype[b],"undefined")},Function.prototype.bind||(Function.prototype.bind=function(b){var c=this;if(typeof c!="function")throw new TypeError;var d=s.call(arguments,1),e=function(){if(this instanceof e){var a=function(){};a.prototype=c.prototype;var f=new a,g=c.apply(f,d.concat(s.call(arguments)));return Object(g)===g?g:f}return c.apply(b,d.concat(s.call(arguments)))};return e}),o.touch=function(){var c;return"ontouchstart"in a||a.DocumentTouch&&b instanceof DocumentTouch?c=!0:u(["@media (",m.join("touch-enabled),("),h,")","{#modernizr{top:9px;position:absolute}}"].join(""),function(a){c=a.offsetTop===9}),c},o.svg=function(){return!!b.createElementNS&&!!b.createElementNS(n.svg,"svg").createSVGRect},o.inlinesvg=function(){var a=b.createElement("div");return a.innerHTML="",(a.firstChild&&a.firstChild.namespaceURI)==n.svg},o.svgclippaths=function(){return!!b.createElementNS&&/SVGClipPath/.test(l.call(b.createElementNS(n.svg,"clipPath")))};for(var D in o)x(o,D)&&(t=D.toLowerCase(),e[t]=o[D](),r.push((e[t]?"":"no-")+t));return e.addTest=function(a,b){if(typeof a=="object")for(var d in a)x(a,d)&&e.addTest(d,a[d]);else{a=a.toLowerCase();if(e[a]!==c)return e;b=typeof b=="function"?b():b,typeof f!="undefined"&&f&&(g.className+=" "+(b?"":"no-")+a),e[a]=b}return e},y(""),i=k=null,function(a,b){function k(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function l(){var a=r.elements;return typeof a=="string"?a.split(" "):a}function m(a){var b=i[a[g]];return b||(b={},h++,a[g]=h,i[h]=b),b}function n(a,c,f){c||(c=b);if(j)return c.createElement(a);f||(f=m(c));var g;return f.cache[a]?g=f.cache[a].cloneNode():e.test(a)?g=(f.cache[a]=f.createElem(a)).cloneNode():g=f.createElem(a),g.canHaveChildren&&!d.test(a)?f.frag.appendChild(g):g}function o(a,c){a||(a=b);if(j)return a.createDocumentFragment();c=c||m(a);var d=c.frag.cloneNode(),e=0,f=l(),g=f.length;for(;e",f="hidden"in a,j=a.childNodes.length==1||function(){b.createElement("a");var a=b.createDocumentFragment();return typeof a.cloneNode=="undefined"||typeof a.createDocumentFragment=="undefined"||typeof a.createElement=="undefined"}()}catch(c){f=!0,j=!0}})();var r={elements:c.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video",shivCSS:c.shivCSS!==!1,supportsUnknownElements:j,shivMethods:c.shivMethods!==!1,type:"default",shivDocument:q,createElement:n,createDocumentFragment:o};a.html5=r,q(b)}(this,b),e._version=d,e._prefixes=m,e.mq=v,e.testStyles=u,g.className=g.className.replace(/(^|\s)no-js(\s|$)/,"$1$2")+(f?" js "+r.join(" "):""),e}(this,this.document),function(a,b,c){function d(a){return"[object Function]"==o.call(a)}function e(a){return"string"==typeof a}function f(){}function g(a){return!a||"loaded"==a||"complete"==a||"uninitialized"==a}function h(){var a=p.shift();q=1,a?a.t?m(function(){("c"==a.t?B.injectCss:B.injectJs)(a.s,0,a.a,a.x,a.e,1)},0):(a(),h()):q=0}function i(a,c,d,e,f,i,j){function k(b){if(!o&&g(l.readyState)&&(u.r=o=1,!q&&h(),l.onload=l.onreadystatechange=null,b)){"img"!=a&&m(function(){t.removeChild(l)},50);for(var d in y[c])y[c].hasOwnProperty(d)&&y[c][d].onload()}}var j=j||B.errorTimeout,l=b.createElement(a),o=0,r=0,u={t:d,s:c,e:f,a:i,x:j};1===y[c]&&(r=1,y[c]=[]),"object"==a?l.data=c:(l.src=c,l.type=a),l.width=l.height="0",l.onerror=l.onload=l.onreadystatechange=function(){k.call(this,r)},p.splice(e,0,u),"img"!=a&&(r||2===y[c]?(t.insertBefore(l,s?null:n),m(k,j)):y[c].push(l))}function j(a,b,c,d,f){return q=0,b=b||"j",e(a)?i("c"==b?v:u,a,b,this.i++,c,d,f):(p.splice(this.i++,0,a),1==p.length&&h()),this}function k(){var a=B;return a.loader={load:j,i:0},a}var l=b.documentElement,m=a.setTimeout,n=b.getElementsByTagName("script")[0],o={}.toString,p=[],q=0,r="MozAppearance"in l.style,s=r&&!!b.createRange().compareNode,t=s?l:n.parentNode,l=a.opera&&"[object Opera]"==o.call(a.opera),l=!!b.attachEvent&&!l,u=r?"object":l?"script":"img",v=l?"script":u,w=Array.isArray||function(a){return"[object Array]"==o.call(a)},x=[],y={},z={timeout:function(a,b){return b.length&&(a.timeout=b[0]),a}},A,B;B=function(a){function b(a){var a=a.split("!"),b=x.length,c=a.pop(),d=a.length,c={url:c,origUrl:c,prefixes:a},e,f,g;for(f=0;f - $('#cart_adjustments').hide() - - $('th.cart-adjustment-header').html('Distribution...') - $('th.cart-adjustment-header a').click -> - $('#cart_adjustments').toggle() - $('th.cart-adjustment-header a').html('Distribution') - false diff --git a/app/assets/javascripts/store/controllers/cart.js.coffee b/app/assets/javascripts/store/controllers/cart.js.coffee deleted file mode 100644 index cc7538249e..0000000000 --- a/app/assets/javascripts/store/controllers/cart.js.coffee +++ /dev/null @@ -1,20 +0,0 @@ -'use strict' - -angular.module('store', ['ngResource']). - controller('CartCtrl', ['$scope', '$window', 'CartFactory', ($scope, $window, CartFactory) -> - - $scope.state = 'Empty' - - $scope.loadCart = (cart_id) -> - if cart_id? - CartFactory.load cart_id, (cart) -> - $scope.cart = cart - if $scope.cart?.orders?.length > 0 - $scope.state = "There's something there...." - - $scope.addVariant = (variant, quantity) -> - - ]) - .config(['$httpProvider', ($httpProvider) -> - $httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content') - ]) diff --git a/app/assets/javascripts/store/factories/cart.js.coffee b/app/assets/javascripts/store/factories/cart.js.coffee deleted file mode 100644 index e327fc336d..0000000000 --- a/app/assets/javascripts/store/factories/cart.js.coffee +++ /dev/null @@ -1,11 +0,0 @@ -'use strict' - -angular.module('store'). - factory('CartFactory', ['$resource', '$window', '$http', ($resource, $window, $http) -> - Cart = $resource '/open_food_network/cart/:cart_id.json', {}, - { 'show': { method: 'GET'} } - - load: (id, callback) -> - Cart.show {cart_id: id}, (cart) -> - callback(cart) - ]) diff --git a/app/assets/javascripts/store/products.js b/app/assets/javascripts/store/products.js deleted file mode 100644 index 127e8ce28f..0000000000 --- a/app/assets/javascripts/store/products.js +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Update the price on the product details page in real time when the variant or the quantity are changed. - **/ - -$(document).ready(function() { - // Product page with variant choice - $("#product-variants input[type='radio']").change(products_update_price_with_variant); - $("#quantity").change(products_update_price_with_variant); - $("#quantity").change(); - - // Product page with master price only - $(".add-to-cart input.title:not(#quantity):not(.max_quantity)").change(products_update_price_without_variant).change(); - - // Product page other - $("#distributor_id").change(function() { - var distributor_html = distributors[$(this).val()]; - if(!distributor_html) { - distributor_html = 'When you select a distributor for your order, their address and pickup times will be displayed here.'; - } - $("#product-distributor-details .distributor-details").html(distributor_html); - }); -}); - - -function products_update_price_with_variant() { - var variant_price = $("#product-variants input[type='radio']:checked").parent().find("span.price").html().trim(); - variant_price = variant_price.substr(2, variant_price.length-3); - - var quantity = $("#quantity").val(); - - $("#product-price span.price").html("$"+(parseFloat(variant_price) * parseInt(quantity)).toFixed(2)); -} - - -function products_update_price_without_variant() { - var master_price = $("#product-price span.price").data('master-price'); - if(master_price == null) { - // Store off the master price - master_price = $("#product-price span.price").html(); - master_price = master_price.substring(1); - $("#product-price span.price").data('master-price', master_price); - } - - var quantity = $(this).val(); - - $("#product-price span.price").html("$"+(parseFloat(master_price)*parseInt(quantity)).toFixed(2)); -} diff --git a/app/assets/javascripts/store/shop_front.js.coffee b/app/assets/javascripts/store/shop_front.js.coffee deleted file mode 100644 index 1a7044732f..0000000000 --- a/app/assets/javascripts/store/shop_front.js.coffee +++ /dev/null @@ -1,4 +0,0 @@ -$(document).ready -> - $("#order_order_cycle_id").change -> $("#order_cycle_select").submit() - $("#reset_order_cycle").click -> return false unless confirm "Changing your collection date will clear your cart." - $(".shop-distributor.empties-cart").click -> return false unless confirm "Changing your location will clear your cart." From 04c5dff497c0f9b286f2ca7ab408e9bc50fca8f5 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 25 Sep 2014 19:47:00 +1000 Subject: [PATCH 005/142] fixup merge --- app/views/producers/index.html.haml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/views/producers/index.html.haml b/app/views/producers/index.html.haml index 371c873f64..cf5bd4bed9 100644 --- a/app/views/producers/index.html.haml +++ b/app/views/producers/index.html.haml @@ -1,10 +1,5 @@ -<<<<<<< HEAD = inject_enterprises .producers.pad-top{"ng-controller" => "EnterprisesCtrl"} -======= -= inject_enterprises -.producers.pad-top{"ng-controller" => "ProducersCtrl"} ->>>>>>> master .row .small-12.columns.pad-top %h1 Find local producers From 4b576d1590e0b3b4289d30a2b527306f92ae3650 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 25 Sep 2014 23:54:31 +1000 Subject: [PATCH 006/142] refactor enterprise specs --- .../darkswarm/services/enterprises.js.coffee | 3 +- .../filters/search_enterprises_spec.js.coffee | 19 +++----- .../services/enterprise_spec.js.coffee | 26 +++++++---- .../darkswarm/services/hubs_spec.js.coffee | 45 ------------------- .../services/producers_spec.js.coffee | 21 --------- 5 files changed, 27 insertions(+), 87 deletions(-) delete mode 100644 spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee delete mode 100644 spec/javascripts/unit/darkswarm/services/producers_spec.js.coffee diff --git a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee index 2451c14739..b5136dec35 100644 --- a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee @@ -2,7 +2,7 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer, new class Enterprises enterprises_by_id: {} # id/object pairs for lookup constructor: -> - @enterprises = visibleFilter enterprises + @enterprises = enterprises for enterprise in enterprises @enterprises_by_id[enterprise.id] = enterprise @dereferenceEnterprises() @@ -10,6 +10,7 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer, @producers = @enterprises.filter (enterprise)-> enterprise.is_primary_producer @hubs = @enterprises.filter (enterprise)-> + enterprise.is_distributor dereferenceEnterprises: -> diff --git a/spec/javascripts/unit/darkswarm/filters/search_enterprises_spec.js.coffee b/spec/javascripts/unit/darkswarm/filters/search_enterprises_spec.js.coffee index 61e58071e2..2717e50cfb 100644 --- a/spec/javascripts/unit/darkswarm/filters/search_enterprises_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/filters/search_enterprises_spec.js.coffee @@ -1,6 +1,5 @@ describe 'filtering Enterprises', -> filter = null - searchEnterprises = null enterprises = [{ name: "frogs" other: "roger" @@ -20,26 +19,22 @@ describe 'filtering Enterprises', -> beforeEach -> module 'Darkswarm' inject ($filter) -> - filter = $filter - searchEnterprises = $filter('enterprises') - - it 'has a enterprise filter', -> - expect(filter('enterprises')).not.toBeNull() + filter = $filter('searchEnterprises') it "filters by name", -> - expect(searchEnterprises(enterprises, 'donkeys').length).toEqual 1 + expect(filter(enterprises, 'donkeys').length).toEqual 1 it "is case insensitive", -> - expect(searchEnterprises(enterprises, 'DONKEYS').length).toEqual 1 + expect(filter(enterprises, 'DONKEYS').length).toEqual 1 it "filters by state", -> - expect(searchEnterprises(enterprises, 'kansas').length).toEqual 1 + expect(filter(enterprises, 'kansas').length).toEqual 1 it "filters by zipcode", -> - expect(searchEnterprises(enterprises, 'cats').length).toEqual 1 + expect(filter(enterprises, 'cats').length).toEqual 1 it "gives all enterprises when no argument is specified", -> - expect(searchEnterprises(enterprises, '').length).toEqual 2 + expect(filter(enterprises, '').length).toEqual 2 it "does not filter by anything else", -> - expect(searchEnterprises(enterprises, 'roger').length).toEqual 0 + expect(filter(enterprises, 'roger').length).toEqual 0 diff --git a/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee index 59d4ae9826..a38517293f 100644 --- a/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee @@ -1,24 +1,24 @@ describe "Enterprises service", -> Enterprises = null - CurrentHubMock = {} + CurrentHubMock = {} taxons = [ {id: 1, name: "test"} ] enterprises = [ - {id: 1, type: "hub", producers: [{id: 2}], taxons: [{id: 1}]}, - {id: 2, type: "producer", hubs: [{id: 1}]}, - {id: 3, type: "producer", hubs: [{id: 1}]} + {id: 1, is_distributor: true, is_primary_producer: false, producers: [{id: 2}], taxons: [{id: 1}]}, + {id: 2, is_distributor: false, is_primary_producer: true, hubs: [{id: 1}]}, + {id: 3, is_distributor: false, is_primary_producer: true, hubs: [{id: 1}]} ] beforeEach -> module 'Darkswarm' module ($provide)-> - $provide.value "CurrentHub", CurrentHubMock + $provide.value "CurrentHub", CurrentHubMock null - angular.module('Darkswarm').value('enterprises', enterprises) - angular.module('Darkswarm').value('taxons', taxons) + angular.module('Darkswarm').value('enterprises', enterprises) + angular.module('Darkswarm').value('taxons', taxons) inject ($injector)-> - Enterprises = $injector.get("Enterprises") + Enterprises = $injector.get("Enterprises") it "stores enterprises as id/object pairs", -> expect(Enterprises.enterprises_by_id["1"]).toBe enterprises[0] @@ -36,3 +36,13 @@ describe "Enterprises service", -> it "dereferences taxons", -> expect(Enterprises.enterprises[0].taxons[0]).toBe taxons[0] + + it "filters Enterprise.hubs into a new array", -> + expect(Enterprises.hubs[0]).toBe Enterprises.enterprises[0] + # Because the $filter is a new sorted array + # We check to see the objects in both arrays are still the same + Enterprises.enterprises[0].active = false + expect(Enterprises.hubs[0].active).toBe false + + it "delegates producers array to Enterprises", -> + expect(Enterprises.producers[0]).toBe enterprises[1] diff --git a/spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee deleted file mode 100644 index f2620da65b..0000000000 --- a/spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee +++ /dev/null @@ -1,45 +0,0 @@ -describe "Hubs service", -> - Hubs = null - Enterprises = null - CurrentHubMock = {} - hubs = [ - { - id: 2 - active: false - orders_close_at: new Date() - is_distributor: true - has_hub_listing: true - } - { - id: 3 - active: false - orders_close_at: new Date() - is_distributor: true - has_hub_listing: true - } - { - id: 1 - active: true - orders_close_at: new Date() - is_distributor: true - has_hub_listing: true - } - ] - - - beforeEach -> - module 'Darkswarm' - angular.module('Darkswarm').value('enterprises', hubs) - module ($provide)-> - $provide.value "CurrentHub", CurrentHubMock - null - inject ($injector)-> - Enterprises = $injector.get("Enterprises") - Hubs = $injector.get("Hubs") - - it "filters Enterprise.hubs into a new array", -> - expect(Hubs.hubs[0]).toBe Enterprises.enterprises[2] - # Because the $filter is a new sorted array - # We check to see the objects in both arrays are still the same - Enterprises.enterprises[2].active = false - expect(Hubs.hubs[0].active).toBe false diff --git a/spec/javascripts/unit/darkswarm/services/producers_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/producers_spec.js.coffee deleted file mode 100644 index dc9ac0fc8f..0000000000 --- a/spec/javascripts/unit/darkswarm/services/producers_spec.js.coffee +++ /dev/null @@ -1,21 +0,0 @@ -describe "Producers service", -> - Producers = null - Enterprises = null - CurrentHubMock = - hub: - id: 1 - enterprises = [ - {is_primary_producer: true} - ] - - beforeEach -> - module 'Darkswarm' - module ($provide)-> - $provide.value "CurrentHub", CurrentHubMock - null - angular.module('Darkswarm').value('enterprises', enterprises) - inject ($injector)-> - Producers = $injector.get("Producers") - - it "delegates producers array to Enterprises", -> - expect(Producers.producers[0]).toBe enterprises[0] From ceb978783c9ee99e1b9e61b1d033cf42bccb8095 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 26 Sep 2014 00:25:19 +1000 Subject: [PATCH 007/142] update missed taxon selector filter --- app/views/home/_filters.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/home/_filters.html.haml b/app/views/home/_filters.html.haml index ff13a0c33c..52fceb6688 100644 --- a/app/views/home/_filters.html.haml +++ b/app/views/home/_filters.html.haml @@ -10,7 +10,7 @@ .light Filter by Type %ul.small-block-grid-2.medium-block-grid-4.large-block-grid-5 - %taxon-selector{objects: "hubs | hubs:query", + %taxon-selector{objects: "Enterprises.hubs | searchEnterprises:query", results: "activeTaxons"} .small-12.large-3.columns %h5.tdhead From a73541da715ecd4706841f957811e919f7cb93ab Mon Sep 17 00:00:00 2001 From: summerscope Date: Fri, 26 Sep 2014 12:07:38 +1000 Subject: [PATCH 008/142] Change styling for register modals --- app/assets/stylesheets/darkswarm/modal-login.css.sass | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/darkswarm/modal-login.css.sass b/app/assets/stylesheets/darkswarm/modal-login.css.sass index 38fe5dee3a..61108145bb 100644 --- a/app/assets/stylesheets/darkswarm/modal-login.css.sass +++ b/app/assets/stylesheets/darkswarm/modal-login.css.sass @@ -1,6 +1,13 @@ // Styling for login modal to style tabs +.reveal-modal.login-modal + border-bottom-color: #efefef + .login-modal background: #efefef .tabs-content - background: #fff \ No newline at end of file + background: #fff + padding-top: 10px + + + \ No newline at end of file From c1460afaee256dcc950bb185372d6e46a91b0d9c Mon Sep 17 00:00:00 2001 From: summerscope Date: Fri, 26 Sep 2014 12:07:58 +1000 Subject: [PATCH 009/142] Tweak language around the long description --- app/assets/javascripts/templates/registration/about.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/templates/registration/about.html.haml b/app/assets/javascripts/templates/registration/about.html.haml index 57f7c482e6..d014c96d90 100644 --- a/app/assets/javascripts/templates/registration/about.html.haml +++ b/app/assets/javascripts/templates/registration/about.html.haml @@ -28,8 +28,8 @@ .row .small-12.columns %label{ for: 'enterprise_long_desc' } Long Description: - %textarea.chunky.small-12.columns{ id: 'enterprise_long_desc', placeholder: "We recommend keeping your description to under 600 characters or 150 words. Why? Cus people are lazy, and don't like to read too much text online. ;)", ng: { model: 'enterprise.long_description' } } - %small {{ enterprise.long_description.length }} characters used + %textarea.chunky.small-12.columns{ id: 'enterprise_long_desc', rows: 6, placeholder: "This is your opportunity to tell the story of your enterprise - what makes you different and wonderful? We'd suggest keeping your description to under 600 characters or 150 words.", ng: { model: 'enterprise.long_description' } } + %small {{ enterprise.long_description.length }} characters / up to 600 recommended .small-12.large-4.columns .row .small-12.columns From 3406f926fc3b8b7e31af9f94d7e0ea45b4e9356a Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 26 Sep 2014 14:48:37 +1000 Subject: [PATCH 010/142] fix enterprsie model logic --- app/models/enterprise.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index ecd948aa7a..a81655a1de 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -215,7 +215,7 @@ class Enterprise < ActiveRecord::Base # Type: full - single - profile becomes Sells: all - own - none # Remove this return later. return "none" if !is_distributor || type == "profile" - return "own" if suppliers == [self] || type == "single" + return "own" if type == "single" || suppliers == [self] "all" end From c43b8abcbc833950e1d135def0043233abe859c5 Mon Sep 17 00:00:00 2001 From: summerscope Date: Fri, 26 Sep 2014 14:55:10 +1000 Subject: [PATCH 011/142] Changing the markup to give a class where is a producer --- .../javascripts/templates/partials/enterprise_header.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/templates/partials/enterprise_header.html.haml b/app/assets/javascripts/templates/partials/enterprise_header.html.haml index 8edca0280b..8612ba968e 100644 --- a/app/assets/javascripts/templates/partials/enterprise_header.html.haml +++ b/app/assets/javascripts/templates/partials/enterprise_header.html.haml @@ -5,7 +5,7 @@ %a{"bo-href" => "enterprise.path", "ofn-empties-cart" => "enterprise", bindonce: true} %i{"ng-class" => "enterprise.icon_font"} %span {{ enterprise.name }} - %h3{"ng-if" => "!enterprise.has_shopfront"} + %h3{"ng-if" => "!enterprise.has_shopfront", "ng-class" => "{'is_producer' : enterprise.is_primary_producer}"} %i{"ng-class" => "enterprise.icon_font"} %span {{ enterprise.name }} .small-12.medium-5.large-4.columns.text-right.small-only-text-left From 3adf571c1f55edd3a60b4d28164855869e0de943 Mon Sep 17 00:00:00 2001 From: summerscope Date: Fri, 26 Sep 2014 14:55:35 +1000 Subject: [PATCH 012/142] Style the modal headers --- .../stylesheets/darkswarm/modal-enterprises.css.sass | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/assets/stylesheets/darkswarm/modal-enterprises.css.sass b/app/assets/stylesheets/darkswarm/modal-enterprises.css.sass index 2ceaa96373..305566ad58 100644 --- a/app/assets/stylesheets/darkswarm/modal-enterprises.css.sass +++ b/app/assets/stylesheets/darkswarm/modal-enterprises.css.sass @@ -42,6 +42,10 @@ margin-bottom: 0 padding-bottom: 0 line-height: 1 + + h3 > i + color: $clr-brick + p line-height: 2.4 @media all and (max-width: 640px) @@ -50,6 +54,10 @@ h3 a:hover span border-bottom: 1px solid $clr-brick-bright + .is_producer + &, & * + color: $clr-turquoise + // ABOUT Enterprise From 0c99007323b285db28c6ed0ebf964743c814a6c1 Mon Sep 17 00:00:00 2001 From: summerscope Date: Fri, 26 Sep 2014 17:45:15 +1000 Subject: [PATCH 013/142] Tweak the modal styling for register modals --- .../darkswarm/directives/registration_limit_modal.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/darkswarm/directives/registration_limit_modal.js.coffee b/app/assets/javascripts/darkswarm/directives/registration_limit_modal.js.coffee index 1fecfbf804..2b38b3d31f 100644 --- a/app/assets/javascripts/darkswarm/directives/registration_limit_modal.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/registration_limit_modal.js.coffee @@ -3,7 +3,7 @@ Darkswarm.directive "ofnRegistrationLimitModal", (Navigation, $modal, Loading) - link: (scope, elem, attr)-> scope.modalInstance = $modal.open templateUrl: 'registration/limit_reached.html' - windowClass: "login-modal large" + windowClass: "login-modal register-modal xlarge" backdrop: 'static' scope.modalInstance.result.then scope.close, scope.close From beb85e862a5def9b3724fd2d7267f6321d71b282 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sat, 27 Sep 2014 15:21:27 +1000 Subject: [PATCH 014/142] get type > sells migration mostly working --- .../admin/enterprises_controller.rb | 15 +++++----- .../admin/overview_controller_decorator.rb | 3 +- app/models/enterprise.rb | 29 ++++++++----------- app/models/spree/ability_decorator.rb | 2 +- app/serializers/api/enterprise_serializer.rb | 11 ++++--- app/views/admin/enterprises/_form.html.haml | 22 ++++++-------- app/views/admin/enterprises/index.html.haml | 5 +--- app/views/json/partials/_enterprise.rabl | 4 +-- .../overview/_enterprises_hubs_tab.html.haml | 2 +- ...140927005043_enterprise_config_refactor.rb | 23 +++++++++++++++ db/schema.rb | 11 ++++--- 11 files changed, 71 insertions(+), 56 deletions(-) create mode 100644 db/migrate/20140927005043_enterprise_config_refactor.rb diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index bde7bff431..bbb8073deb 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -3,8 +3,8 @@ module Admin before_filter :load_enterprise_set, :only => :index before_filter :load_countries, :except => :index before_filter :load_methods_and_fees, :only => [:new, :edit, :update, :create] - before_filter :check_type, only: :update - before_filter :check_bulk_type, only: :bulk_update + before_filter :check_sells, only: :update + before_filter :check_bulk_sells, only: :bulk_update before_filter :override_owner, only: :create before_filter :check_owner, only: :update before_filter :check_bulk_owner, only: :bulk_update @@ -50,7 +50,8 @@ module Admin end def collection - Enterprise.managed_by(spree_current_user).order('is_distributor DESC, is_primary_producer ASC, name') + # TODO is_distributor DESC, + Enterprise.managed_by(spree_current_user).order('is_primary_producer ASC, name') end def collection_actions @@ -63,16 +64,16 @@ module Admin @enterprise_fees = EnterpriseFee.managed_by(spree_current_user).for_enterprise(@enterprise).order(:fee_type, :name).all end - def check_bulk_type + def check_bulk_sells unless spree_current_user.admin? params[:enterprise_set][:collection_attributes].each do |i, enterprise_params| - enterprise_params.delete :type + enterprise_params.delete :sells end end end - def check_type - params[:enterprise].delete :type unless spree_current_user.admin? + def check_sells + params[:enterprise].delete :sells unless spree_current_user.admin? end def override_owner diff --git a/app/controllers/spree/admin/overview_controller_decorator.rb b/app/controllers/spree/admin/overview_controller_decorator.rb index a2288dab88..1cf8cb6f4e 100644 --- a/app/controllers/spree/admin/overview_controller_decorator.rb +++ b/app/controllers/spree/admin/overview_controller_decorator.rb @@ -1,6 +1,7 @@ Spree::Admin::OverviewController.class_eval do def index - @enterprises = Enterprise.managed_by(spree_current_user).order('is_distributor DESC, is_primary_producer ASC, name') + # TODO is_distributor DESC, + @enterprises = Enterprise.managed_by(spree_current_user).order('is_primary_producer ASC, name') @product_count = Spree::Product.active.managed_by(spree_current_user).count @order_cycle_count = OrderCycle.active.managed_by(spree_current_user).count end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index a81655a1de..a078652d68 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -1,5 +1,5 @@ class Enterprise < ActiveRecord::Base - TYPES = %w(full single profile) + SELLS = %w(none own any) ENTERPRISE_SEARCH_RADIUS = 100 self.inheritance_column = nil @@ -47,7 +47,7 @@ class Enterprise < ActiveRecord::Base validates :name, presence: true - validates :type, presence: true, inclusion: {in: TYPES} + validates :sells, presence: true, inclusion: {in: SELLS} validates :address, presence: true, associated: true validates_presence_of :owner validate :enforce_ownership_limit, if: lambda { owner_id_changed? } @@ -59,7 +59,7 @@ class Enterprise < ActiveRecord::Base scope :by_name, order('name') scope :visible, where(:visible => true) scope :is_primary_producer, where(:is_primary_producer => true) - scope :is_distributor, where(:is_distributor => true) + scope :is_distributor, where('sells != ?', 'none') scope :supplying_variant_in, lambda { |variants| joins(:supplied_products => :variants_including_master).where('spree_variants.id IN (?)', variants).select('DISTINCT enterprises.*') } scope :with_supplied_active_products_on_hand, lambda { joins(:supplied_products) @@ -210,13 +210,8 @@ class Enterprise < ActiveRecord::Base Spree::Variant.joins(:product => :product_distributions).where('product_distributions.distributor_id=?', self.id) end - # Replaces currententerprse type field. - def sells - # Type: full - single - profile becomes Sells: all - own - none - # Remove this return later. - return "none" if !is_distributor || type == "profile" - return "own" if type == "single" || suppliers == [self] - "all" + def is_distributor + not self.sells == "none" end # Simplify enterprise categories for frontend logic and icons, and maybe other things. @@ -224,21 +219,21 @@ class Enterprise < ActiveRecord::Base # Make this crazy logic human readable so we can argue about it sanely. # This can be simplified later, it's like this for readablitlty during changes. category = is_primary_producer ? "producer_" : "non_producer_" - category << "sell_" + sells + category << "sells_" + sells # Map backend cases to front end cases. case category - when "producer_sell_all" + when "producer_sells_any" "producer_hub" # Producer hub who sells own and others produce and supplies other hubs. - when "producer_sell_own" + when "producer_sells_own" "producer_shop" # Producer with shopfront and supplies other hubs. - when "producer_sell_none" + when "producer_sells_none" "producer" # Producer only supplies through others. - when "non_producer_sell_all" + when "non_producer_sells_any" "hub" # Hub selling others products in order cycles. - when "non_producer_sell_own" + when "non_producer_sells_own" "hub" # Wholesaler selling through own shopfront? - when "non_producer_sell_none" + when "non_producer_sells_none" "hub_profile" # Hub selling outside the system. end end diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index 3ce7066867..1391e0485c 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -73,7 +73,7 @@ class AbilityDecorator # during the order creation process from the admin backend order.distributor.nil? || user.enterprises.include?(order.distributor) end - can [:admin, :bulk_management], Spree::Order if user.admin? || user.enterprises.any?(&:is_distributor?) + can [:admin, :bulk_management], Spree::Order if user.admin? || user.enterprises.any?(&:is_distributor) can [:admin, :create], Spree::LineItem can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Payment diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index 6841337024..20379d5193 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -17,8 +17,7 @@ end class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer attributes :orders_close_at, :active - #TODO: Remove these later - attributes :icon, :icon_font, :producer_icon_font, :has_shopfront, :has_hub_listing, :enterprise_category + attributes :icon, :icon_font, :producer_icon_font, :has_shopfront, :has_hub_listing, :enterprise_category, :is_distributor def orders_close_at OrderCycle.first_closing_for(object).andand.orders_close_at @@ -33,12 +32,16 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer end def has_shopfront - object.is_distributor && object.type != 'profile' + object.is_distributor + end + + def is_distributor + object.is_distributor end # Used to select enterprises for hub listing def has_hub_listing - has_shopfront || object.enterprise_category == "hub_profile" + object.is_distributor || object.enterprise_category == "hub_profile" end # Map svg icons. diff --git a/app/views/admin/enterprises/_form.html.haml b/app/views/admin/enterprises/_form.html.haml index 6f86c3e703..8afa2750fa 100644 --- a/app/views/admin/enterprises/_form.html.haml +++ b/app/views/admin/enterprises/_form.html.haml @@ -33,12 +33,8 @@ .row .three.columns.alpha %label Enterprise Type(s) - .with-tip{'data-powertip' => "Select 'Producer' if you are a primary producer of food. Select 'Hub' if you want a shop-front. You can choose either or both."} + .with-tip{'data-powertip' => "Select 'Producer' if you are a primary producer of food."} %a What's this? - .two.columns - = f.check_box :is_distributor, 'ng-model' => 'Enterprise.is_distributor' -   - = f.label :is_distributor, 'Hub' .five.columns.omega = f.check_box :is_primary_producer, 'ng-model' => 'Enterprise.is_primary_producer'   @@ -47,21 +43,21 @@ .row .alpha.eleven.columns .three.columns.alpha - = f.label :type, 'Profile type' - .with-tip{'data-powertip' => "Full - enterprise may have products and relationships.
Single - enterprise may have products but no relationships.
Profile - enterprise has a profile but no products or relationships.
"} + = f.label :sells, 'Sells' + .with-tip{'data-powertip' => "None - enterprise does not sell to customers directly.
Own - Enterprise sells own products to customers.
Any - Enterprise can sell own or other enterprises products.
"} %a What's this? .two.columns - = f.radio_button :type, "full" + = f.radio_button :sells, "none"   - = f.label :type, "Full", value: "full" + = f.label :sells, "None", value: "none" .two.columns - = f.radio_button :type, "single" + = f.radio_button :sells, "own"   - = f.label :type, "Single", value: "single" + = f.label :sells, "Own", value: "own" .four.columns.omega - = f.radio_button :type, "profile" + = f.radio_button :sells, "any"   - = f.label :type, "Profile", value: "profile" + = f.label :sells, "Any", value: "any" .row .three.columns.alpha %label Visible in search? diff --git a/app/views/admin/enterprises/index.html.haml b/app/views/admin/enterprises/index.html.haml index 03e5335155..79f59d7171 100644 --- a/app/views/admin/enterprises/index.html.haml +++ b/app/views/admin/enterprises/index.html.haml @@ -37,12 +37,9 @@ %td = enterprise_form.check_box :is_primary_producer Producer - %br/ - = enterprise_form.check_box :is_distributor - Hub %td= enterprise_form.check_box :visible - if spree_current_user.admin? - %td= enterprise_form.select :type, Enterprise::TYPES, {}, class: 'select2 fullwidth' + %td= enterprise_form.select :sells, Enterprise::SELLS, {}, class: 'select2 fullwidth' - if spree_current_user.admin? %td= enterprise_form.select :owner_id, enterprise.users.map{ |e| [ e.email, e.id ] }, {}, class: "select2 fullwidth" %td{"data-hook" => "admin_users_index_row_actions"} diff --git a/app/views/json/partials/_enterprise.rabl b/app/views/json/partials/_enterprise.rabl index 5b52898482..b8800e22ae 100644 --- a/app/views/json/partials/_enterprise.rabl +++ b/app/views/json/partials/_enterprise.rabl @@ -21,9 +21,9 @@ node :promo_image do |enterprise| end node :icon do |e| - if e.is_primary_producer? and e.is_distributor? + if e.is_primary_producer and e.is_distributor image_path "map_003-producer-shop.svg" - elsif e.is_primary_producer? + elsif e.is_primary_producer image_path "map_001-producer-only.svg" else image_path "map_005-hub.svg" diff --git a/app/views/spree/admin/overview/_enterprises_hubs_tab.html.haml b/app/views/spree/admin/overview/_enterprises_hubs_tab.html.haml index cb177f9fb3..6cfd9c3bc5 100644 --- a/app/views/spree/admin/overview/_enterprises_hubs_tab.html.haml +++ b/app/views/spree/admin/overview/_enterprises_hubs_tab.html.haml @@ -8,7 +8,7 @@ - if can? :admin, EnterpriseFee %span.centered.three.columns Enterprise Fees %div.sixteen.columns.alpha.list - - @enterprises.is_distributor.each do |enterprise| + - @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 diff --git a/db/migrate/20140927005043_enterprise_config_refactor.rb b/db/migrate/20140927005043_enterprise_config_refactor.rb new file mode 100644 index 0000000000..636b535be3 --- /dev/null +++ b/db/migrate/20140927005043_enterprise_config_refactor.rb @@ -0,0 +1,23 @@ +class EnterpriseConfigRefactor < ActiveRecord::Migration + def up + add_column :enterprises, :sells, :string, null: false, default: 'none' + + Enterprise.all do |enterprise| + enterprise.sells = sells_what?(enterprise) + enterprise.save! + end + + remove_column :enterprises, :type + remove_column :enterprises, :is_distributor + end + + def down + end + + #TODO make this work + def sells_what?(enterprise) + return "none" if !enterprise.is_distributor || enterprise.type == "profile" + return "own" if enterprise.type == "single" || enterprise.suppliers == [enterprise] + return "any" + end +end diff --git a/db/schema.rb b/db/schema.rb index 73f10210a7..67084cc347 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 => 20140904003026) do +ActiveRecord::Schema.define(:version => 20140927005043) do create_table "adjustment_metadata", :force => true do |t| t.integer "adjustment_id" @@ -238,7 +238,6 @@ ActiveRecord::Schema.define(:version => 20140904003026) do t.string "description" t.text "long_description" t.boolean "is_primary_producer" - t.boolean "is_distributor" t.string "contact" t.string "phone" t.string "email" @@ -249,8 +248,8 @@ ActiveRecord::Schema.define(:version => 20140904003026) do t.integer "address_id" t.string "pickup_times" t.string "next_collection_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.text "distributor_info" t.string "logo_file_name" t.string "logo_content_type" @@ -264,8 +263,8 @@ ActiveRecord::Schema.define(:version => 20140904003026) do t.string "facebook" t.string "instagram" t.string "linkedin" - t.string "type", :default => "profile", :null => false - t.integer "owner_id", :null => false + t.integer "owner_id", :null => false + t.string "sells", :default => "none", :null => false end add_index "enterprises", ["address_id"], :name => "index_enterprises_on_address_id" From b821107c2749ebd003d6201eef2f3efbdfcd37dc Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sat, 27 Sep 2014 18:14:10 +1000 Subject: [PATCH 015/142] bugfix migration ad specs --- .../enterprise_controller.js.coffee | 3 +- .../templates/registration/details.html.haml | 2 +- app/views/admin/enterprises/_form.html.haml | 8 +-- .../_sidebar_enterprise_fees.html.haml | 2 +- .../_sidebar_payment_methods.html.haml | 2 +- .../_sidebar_shipping_methods.html.haml | 2 +- config/ng-test.conf.js | 7 ++ db/schema.rb | 10 +-- .../admin/enterprises_controller_spec.rb | 34 ++++----- .../admin/payment_methods_controller_spec.rb | 2 +- spec/factories.rb | 7 +- spec/features/admin/enterprise_user_spec.rb | 4 +- spec/features/admin/enterprises_spec.rb | 39 ++++++----- spec/features/consumer/registration_spec.rb | 2 +- .../consumer/shopping/shopping_spec.rb | 2 +- spec/models/enterprise_spec.rb | 69 ++++++------------- spec/models/order_cycle_spec.rb | 4 +- 17 files changed, 94 insertions(+), 105 deletions(-) diff --git a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee index c5b38191ba..a872661b27 100644 --- a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee +++ b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee @@ -3,6 +3,7 @@ angular.module("admin.enterprises") $scope.Enterprise = Enterprise.enterprise $scope.PaymentMethods = PaymentMethods.paymentMethods $scope.ShippingMethods = ShippingMethods.shippingMethods + $scope.Enterprise.sells = "none" for payment_method in $scope.PaymentMethods payment_method.selected = payment_method.id in $scope.Enterprise.payment_method_ids @@ -32,4 +33,4 @@ angular.module("admin.enterprises") $scope.ShippingMethods.reduce (count, shipping_method) -> count++ if shipping_method.selected count - , 0 \ No newline at end of file + , 0 diff --git a/app/assets/javascripts/templates/registration/details.html.haml b/app/assets/javascripts/templates/registration/details.html.haml index bb358a1864..cecf588e11 100644 --- a/app/assets/javascripts/templates/registration/details.html.haml +++ b/app/assets/javascripts/templates/registration/details.html.haml @@ -20,7 +20,7 @@ %label Choose one: .row .small-12.medium-4.large-4.columns{ 'data-equalizer-watch' => true } - %a.panel#producer-panel{ href: "#", ng: { click: "enterprise.is_distributor = false; enterprise.is_primary_producer = true", class: "{selected: (!enterprise.is_distributor && enterprise.is_primary_producer)}" } } + %a.panel#producer-panel{ href: "#", ng: { click: "enterprise.is_primary_producer = true", class: "{selected: (!enterprise.is_distributor && enterprise.is_primary_producer)}" } } .left / %render-svg{ path: "/assets/map-icon-producer.svg" } %h4 I'm A Producer diff --git a/app/views/admin/enterprises/_form.html.haml b/app/views/admin/enterprises/_form.html.haml index 8afa2750fa..0904cee944 100644 --- a/app/views/admin/enterprises/_form.html.haml +++ b/app/views/admin/enterprises/_form.html.haml @@ -32,7 +32,7 @@ .row .three.columns.alpha - %label Enterprise Type(s) + %label Primary Producer .with-tip{'data-powertip' => "Select 'Producer' if you are a primary producer of food."} %a What's this? .five.columns.omega @@ -47,15 +47,15 @@ .with-tip{'data-powertip' => "None - enterprise does not sell to customers directly.
Own - Enterprise sells own products to customers.
Any - Enterprise can sell own or other enterprises products.
"} %a What's this? .two.columns - = f.radio_button :sells, "none" + = f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells'   = f.label :sells, "None", value: "none" .two.columns - = f.radio_button :sells, "own" + = f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells'   = f.label :sells, "Own", value: "own" .four.columns.omega - = f.radio_button :sells, "any" + = f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells'   = f.label :sells, "Any", value: "any" .row diff --git a/app/views/admin/enterprises/_sidebar_enterprise_fees.html.haml b/app/views/admin/enterprises/_sidebar_enterprise_fees.html.haml index 50de7e07d9..1e73416218 100644 --- a/app/views/admin/enterprises/_sidebar_enterprise_fees.html.haml +++ b/app/views/admin/enterprises/_sidebar_enterprise_fees.html.haml @@ -1,5 +1,5 @@ - enterprise_fees_color = @enterprise_fees.count > 0 ? "blue" : "red" -.sidebar_item.four.columns.alpha#enterprise_fees{ ng: { show: 'Enterprise.is_distributor' } } +.sidebar_item.four.columns.alpha#enterprise_fees{ ng: { show: 'Enterprise.sells != "none"' } } .four.columns.alpha.header{ class: "#{enterprise_fees_color}" } %span.four.columns.alpha.centered Enterprise Fees .four.columns.alpha.list{ class: "#{enterprise_fees_color}" } diff --git a/app/views/admin/enterprises/_sidebar_payment_methods.html.haml b/app/views/admin/enterprises/_sidebar_payment_methods.html.haml index 8994c60be5..9b88dcdd13 100644 --- a/app/views/admin/enterprises/_sidebar_payment_methods.html.haml +++ b/app/views/admin/enterprises/_sidebar_payment_methods.html.haml @@ -1,4 +1,4 @@ -.sidebar_item.four.columns.alpha#payment_methods{ ng: { show: 'Enterprise.is_distributor' } } +.sidebar_item.four.columns.alpha#payment_methods{ ng: { show: 'Enterprise.sells != "none"' } } .four.columns.alpha.header{ ng: { class: "paymentMethodsColor()" } } %span.four.columns.alpha.centered Payment Methods .four.columns.alpha.list{ ng: { class: "paymentMethodsColor()" } } diff --git a/app/views/admin/enterprises/_sidebar_shipping_methods.html.haml b/app/views/admin/enterprises/_sidebar_shipping_methods.html.haml index 6d4a858366..aea1c51111 100644 --- a/app/views/admin/enterprises/_sidebar_shipping_methods.html.haml +++ b/app/views/admin/enterprises/_sidebar_shipping_methods.html.haml @@ -1,4 +1,4 @@ -.sidebar_item.four.columns.alpha#shipping_methods{ ng: { show: 'Enterprise.is_distributor' } } +.sidebar_item.four.columns.alpha#shipping_methods{ ng: { show: 'Enterprise.sells != "none"' } } .four.columns.alpha.header{ ng: { class: "shippingMethodsColor()" } } %span.four.columns.alpha.centered Shipping Methods .four.columns.alpha.list{ ng: { class: "shippingMethodsColor()" } } diff --git a/config/ng-test.conf.js b/config/ng-test.conf.js index eadaf984ae..f87aa3d48a 100644 --- a/config/ng-test.conf.js +++ b/config/ng-test.conf.js @@ -27,9 +27,16 @@ module.exports = function(config) { 'app/assets/javascripts/admin/util.js.erb' ], + preprocessors: { + '**/*.coffee': ['coffee'] + }, + coffeePreprocessor: { options: { sourceMap: true + }, + transformPath: function(path) { + return path.replace(/\.coffee$/, '.js'); } }, diff --git a/db/schema.rb b/db/schema.rb index 67084cc347..e0d47470b7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -248,8 +248,8 @@ ActiveRecord::Schema.define(:version => 20140927005043) do t.integer "address_id" t.string "pickup_times" t.string "next_collection_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.text "distributor_info" t.string "logo_file_name" t.string "logo_content_type" @@ -263,8 +263,10 @@ ActiveRecord::Schema.define(:version => 20140927005043) do t.string "facebook" t.string "instagram" t.string "linkedin" - t.integer "owner_id", :null => false - t.string "sells", :default => "none", :null => false + t.integer "owner_id", :null => false + t.string "sell", :default => "none", :null => false + t.string "sells", :default => "none", :null => false + t.string "type", :default => "profile", :null => false end add_index "enterprises", ["address_id"], :name => "index_enterprises_on_address_id" diff --git a/spec/controllers/admin/enterprises_controller_spec.rb b/spec/controllers/admin/enterprises_controller_spec.rb index a522624489..f0ac8639f7 100644 --- a/spec/controllers/admin/enterprises_controller_spec.rb +++ b/spec/controllers/admin/enterprises_controller_spec.rb @@ -84,28 +84,28 @@ module Admin end describe "updating an enterprise" do - let(:profile_enterprise) { create(:enterprise, type: 'profile') } + let(:profile_enterprise) { create(:enterprise, sells: 'none') } context "as manager" do - it "does not allow 'type' to be changed" do + it "does not allow 'sells' to be changed" do profile_enterprise.enterprise_roles.build(user: user).save controller.stub spree_current_user: user - enterprise_params = { id: profile_enterprise.id, enterprise: { type: 'full' } } + enterprise_params = { id: profile_enterprise.id, enterprise: { sells: 'any' } } spree_put :update, enterprise_params profile_enterprise.reload - expect(profile_enterprise.type).to eq 'profile' + expect(profile_enterprise.sells).to eq 'none' end end context "as super admin" do - it "allows 'type' to be changed" do + it "allows 'sells' to be changed" do controller.stub spree_current_user: admin_user - enterprise_params = { id: profile_enterprise.id, enterprise: { type: 'full' } } + enterprise_params = { id: profile_enterprise.id, enterprise: { sells: 'any' } } spree_put :update, enterprise_params profile_enterprise.reload - expect(profile_enterprise.type).to eq 'full' + expect(profile_enterprise.sells).to eq 'any' end end end @@ -123,38 +123,38 @@ module Admin user.save! user end - let!(:profile_enterprise1) { create(:enterprise, type: 'profile', owner: original_owner ) } - let!(:profile_enterprise2) { create(:enterprise, type: 'profile', owner: original_owner ) } + let!(:profile_enterprise1) { create(:enterprise, sells: 'none', owner: original_owner ) } + let!(:profile_enterprise2) { create(:enterprise, sells: 'none', owner: original_owner ) } context "as manager" do - it "does not allow 'type' or 'owner' to be changed" do + it "does not allow 'sells' or 'owner' to be changed" do profile_enterprise1.enterprise_roles.build(user: new_owner).save profile_enterprise2.enterprise_roles.build(user: new_owner).save controller.stub spree_current_user: new_owner - bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, type: 'full', owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, type: 'full', owner_id: new_owner.id } } } } + bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, sells: 'any', owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, sells: 'any', owner_id: new_owner.id } } } } spree_put :bulk_update, bulk_enterprise_params profile_enterprise1.reload profile_enterprise2.reload - expect(profile_enterprise1.type).to eq 'profile' - expect(profile_enterprise2.type).to eq 'profile' + expect(profile_enterprise1.sells).to eq 'none' + expect(profile_enterprise2.sells).to eq 'none' expect(profile_enterprise1.owner).to eq original_owner expect(profile_enterprise2.owner).to eq original_owner end end context "as super admin" do - it "allows 'type' and 'owner' to be changed" do + it "allows 'sells' and 'owner' to be changed" do profile_enterprise1.enterprise_roles.build(user: new_owner).save profile_enterprise2.enterprise_roles.build(user: new_owner).save controller.stub spree_current_user: admin_user - bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, type: 'full', owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, type: 'full', owner_id: new_owner.id } } } } + bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, sells: 'any', owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, sells: 'any', owner_id: new_owner.id } } } } spree_put :bulk_update, bulk_enterprise_params profile_enterprise1.reload profile_enterprise2.reload - expect(profile_enterprise1.type).to eq 'full' - expect(profile_enterprise2.type).to eq 'full' + expect(profile_enterprise1.sells).to eq 'any' + expect(profile_enterprise2.sells).to eq 'any' expect(profile_enterprise1.owner).to eq new_owner expect(profile_enterprise2.owner).to eq new_owner end diff --git a/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/spec/controllers/spree/admin/payment_methods_controller_spec.rb index f3266f69c2..c27fe16f19 100644 --- a/spec/controllers/spree/admin/payment_methods_controller_spec.rb +++ b/spec/controllers/spree/admin/payment_methods_controller_spec.rb @@ -73,4 +73,4 @@ describe Spree::Admin::PaymentMethodsController do end end end -end \ No newline at end of file +end diff --git a/spec/factories.rb b/spec/factories.rb index db035ba16a..63c733524e 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -92,7 +92,8 @@ FactoryGirl.define do factory :enterprise, :class => Enterprise do owner { FactoryGirl.create :user } sequence(:name) { |n| "Enterprise #{n}" } - type 'full' + sells 'any' + is_primary_producer false description 'enterprise' long_description '

Hello, world!

This is a paragraph.

' email 'enterprise@example.com' @@ -101,12 +102,12 @@ FactoryGirl.define do factory :supplier_enterprise, :parent => :enterprise do is_primary_producer true - is_distributor false + sells "none" end factory :distributor_enterprise, :parent => :enterprise do is_primary_producer false - is_distributor true + sells "any" end factory :enterprise_relationship do diff --git a/spec/features/admin/enterprise_user_spec.rb b/spec/features/admin/enterprise_user_spec.rb index 77378f6cbd..fa92013a73 100644 --- a/spec/features/admin/enterprise_user_spec.rb +++ b/spec/features/admin/enterprise_user_spec.rb @@ -11,10 +11,10 @@ feature %q{ let!(:user) { create_enterprise_user } let!(:supplier1) { create(:supplier_enterprise, name: 'Supplier 1') } let!(:supplier2) { create(:supplier_enterprise, name: 'Supplier 2') } - let(:supplier_profile) { create(:supplier_enterprise, name: 'Supplier profile', type: 'profile') } + let(:supplier_profile) { create(:supplier_enterprise, name: 'Supplier profile', sells: 'none') } let!(:distributor1) { create(:distributor_enterprise, name: 'Distributor 3') } let!(:distributor2) { create(:distributor_enterprise, name: 'Distributor 4') } - let(:distributor_profile) { create(:distributor_enterprise, name: 'Distributor profile', type: 'profile') } + let(:distributor_profile) { create(:distributor_enterprise, name: 'Distributor profile', sells: 'none') } describe "creating an enterprise user" do context "with a limitted number of owned enterprises" do diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index abaab5cd2d..b97e7600c4 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -16,7 +16,7 @@ feature %q{ within("tr.enterprise-#{s.id}") do expect(page).to have_content s.name - expect(page).to have_select "enterprise_set_collection_attributes_1_type" + expect(page).to have_select "enterprise_set_collection_attributes_1_sells" expect(page).to have_content "Edit Profile" expect(page).to have_content "Delete" expect(page).to_not have_content "Payment Methods" @@ -26,7 +26,7 @@ feature %q{ within("tr.enterprise-#{d.id}") do expect(page).to have_content d.name - expect(page).to have_select "enterprise_set_collection_attributes_0_type" + expect(page).to have_select "enterprise_set_collection_attributes_0_sells" expect(page).to have_content "Edit Profile" expect(page).to have_content "Delete" expect(page).to have_content "Payment Methods" @@ -37,7 +37,7 @@ feature %q{ scenario "editing enterprises in bulk" do s = create(:supplier_enterprise) - d = create(:distributor_enterprise, type: 'profile') + d = create(:distributor_enterprise, sells: 'none') d_manager = create_enterprise_user d_manager.enterprise_roles.build(enterprise: d).save expect(d.owner).to_not eq d_manager @@ -48,14 +48,14 @@ feature %q{ within("tr.enterprise-#{d.id}") do expect(page).to have_checked_field "enterprise_set_collection_attributes_0_visible" uncheck "enterprise_set_collection_attributes_0_visible" - select 'full', from: "enterprise_set_collection_attributes_0_type" + select 'any', from: "enterprise_set_collection_attributes_0_sells" select d_manager.email, from: 'enterprise_set_collection_attributes_0_owner_id' end click_button "Update" flash_message.should == 'Enterprises updated successfully' distributor = Enterprise.find(d.id) expect(distributor.visible).to eq false - expect(distributor.type).to eq 'full' + expect(distributor.sells).to eq 'any' expect(distributor.owner).to eq d_manager end @@ -82,15 +82,16 @@ feature %q{ click_link 'New Enterprise' # Checking shipping and payment method sidebars work + choose "Any" uncheck 'enterprise_is_primary_producer' - check 'enterprise_is_distributor' + page.should_not have_checked_field "enterprise_payment_method_ids_#{payment_method.id}" page.should_not have_checked_field "enterprise_shipping_method_ids_#{shipping_method.id}" # Filling in details fill_in 'enterprise_name', :with => 'Eaterprises' select2_search admin.email, from: 'Owner' - choose 'Full' + choose 'Any' check "enterprise_payment_method_ids_#{payment_method.id}" check "enterprise_shipping_method_ids_#{shipping_method.id}" select2_search eg1.name, from: 'Groups' @@ -134,18 +135,20 @@ feature %q{ end fill_in 'enterprise_name', :with => 'Eaterprises' - choose 'Single' + choose 'Own' select2_search user.email, from: 'Owner' fill_in 'enterprise_description', :with => 'Connecting farmers and eaters' fill_in 'enterprise_long_description', :with => 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.' # Check Angularjs switching of sidebar elements uncheck 'enterprise_is_primary_producer' - uncheck 'enterprise_is_distributor' - page.should have_selector "#payment_methods", visible: false - page.should have_selector "#shipping_methods", visible: false - page.should have_selector "#enterprise_fees", visible: false - check 'enterprise_is_distributor' + #TODO something needed here ? sells=any? not sure what js is_distributor was connected to + # uncheck 'enterprise_is_distributor' + # page.should have_selector "#payment_methods", visible: false + # page.should have_selector "#shipping_methods", visible: false + # page.should have_selector "#enterprise_fees", visible: false + #TODO something needed here ? sells=any? not sure what js is_distributor was connected to + # check 'enterprise_is_distributor' page.should have_selector "#payment_methods" page.should have_selector "#shipping_methods" page.should have_selector "#enterprise_fees" @@ -275,16 +278,18 @@ feature %q{ within("tr.enterprise-#{distributor1.id}") do expect(page).to have_content distributor1.name - expect(page).to have_checked_field "enterprise_set_collection_attributes_0_is_distributor" + # TODO expect sell= ? + # expect(page).to have_checked_field "enterprise_set_collection_attributes_0_is_distributor" expect(page).to have_unchecked_field "enterprise_set_collection_attributes_0_is_primary_producer" - expect(page).to_not have_select "enterprise_set_collection_attributes_0_type" + expect(page).to_not have_select "enterprise_set_collection_attributes_0_sells" end within("tr.enterprise-#{supplier1.id}") do expect(page).to have_content supplier1.name - expect(page).to have_unchecked_field "enterprise_set_collection_attributes_1_is_distributor" + # TODO expect sells= ? + # expect(page).to have_unchecked_field "enterprise_set_collection_attributes_1_is_distributor" expect(page).to have_checked_field "enterprise_set_collection_attributes_1_is_primary_producer" - expect(page).to_not have_select "enterprise_set_collection_attributes_1_type" + expect(page).to_not have_select "enterprise_set_collection_attributes_1_sells" end expect(page).to_not have_content "supplier2.name" diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index 7ac46a8970..5ed9c59fcb 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -49,7 +49,7 @@ feature "Registration", js: true do expect(page).to have_content 'Nice one!' e = Enterprise.find_by_name('My Awesome Enterprise') expect(e.address.address1).to eq "123 Abc Street" - expect(e.is_distributor).to eq true + expect(e.sells).to eq "none" expect(e.is_primary_producer).to eq true expect(e.contact).to eq "Saskia Munroe" diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index 56c578f91b..d4db6bff29 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -167,7 +167,7 @@ feature "As a consumer I want to shop with a distributor", js: true do visit shop_path end - it "should save group buy data to ze cart" do + it "should save group buy data to the cart" do fill_in "variants[#{variant.id}]", with: 6 fill_in "variant_attributes[#{variant.id}][max_quantity]", with: 7 page.should have_in_cart product.name diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 68067b5ac5..8f9a57f64c 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -502,64 +502,37 @@ describe Enterprise do end end - pending "provide enterprise category" do + describe "provide enterprise category" do - # Swap type values full > sell_all, single > sell_own profile > sell_none - # swap is_distributor for new can_supply flag. - let(:producer_sell_all_can_supply) { - create(:enterprise, is_primary_producer: true, type: "full", is_distributor: true) + let(:producer_sell_all) { + create(:enterprise, is_primary_producer: true, sells: "any") } - let(:producer_sell_all_cant_supply) { - create(:enterprise, is_primary_producer: true, type: "full", is_distributor: false) + let(:producer_sell_own) { + create(:enterprise, is_primary_producer: true, sells: "own") } - let(:producer_sell_own_can_supply) { - create(:enterprise, is_primary_producer: true, type: "single", is_distributor: true) + let(:producer_sell_none) { + create(:enterprise, is_primary_producer: true, sells: "none") } - let(:producer_sell_own_cant_supply) { - create(:enterprise, is_primary_producer: true, type: "single", is_distributor: false) + let(:non_producer_sell_all) { + create(:enterprise, is_primary_producer: false, sells: "any") } - let(:producer_sell_none_can_supply) { - create(:enterprise, is_primary_producer: true, type: "profile", is_distributor: true) + let(:non_producer_sell_own) { + create(:enterprise, is_primary_producer: false, sells: "own") } - let(:producer_sell_none_cant_supply) { - create(:enterprise, is_primary_producer: true, type: "profile", is_distributor: false) - } - let(:non_producer_sell_all_can_supply) { - create(:enterprise, is_primary_producer: true, type: "full", is_distributor: true) - } - let(:non_producer_sell_all_cant_supply) { - create(:enterprise, is_primary_producer: true, type: "full", is_distributor: false) - } - let(:non_producer_sell_own_can_supply) { - create(:enterprise, is_primary_producer: true, type: "single", is_distributor: true) - } - let(:non_producer_sell_own_cant_supply) { - create(:enterprise, is_primary_producer: true, type: "single", is_distributor: false) - } - let(:non_producer_sell_none_can_supply) { - create(:enterprise, is_primary_producer: false, type: "profile", is_distributor: true) - } - let(:non_producer_sell_none_cant_supply) { - create(:enterprise, is_primary_producer: false, type: "profile", is_distributor: false) + let(:non_producer_sell_none) { + create(:enterprise, is_primary_producer: false, sells: "none") } it "should output enterprise categories" do - producer_sell_all_can_supply.is_primary_producer.should == true - producer_sell_all_can_supply.supplies.should == true - producer_sell_all_can_supply.type.should == "full" + producer_sell_all.is_primary_producer.should == true + producer_sell_all.sells.should == "any" - producer_sell_all_can_supply.enterprise_category.should == "producer_hub" - producer_sell_all_cant_supply.enterprise_category.should == "producer_hub" - producer_sell_own_can_supply.enterprise_category.should == "producer_shop" - producer_sell_own_cant_supply.enterprise_category.should == "producer_shop" - producer_sell_none_can_supply.enterprise_category.should == "producer" - producer_sell_none_cant_supply.enterprise_category.should == "producer_profile" - non_producer_sell_all_can_supply.enterprise_category.should == "hub" - non_producer_sell_all_cant_supply.enterprise_category.should == "hub" - non_producer_sell_own_can_supply.enterprise_category.should == "hub" - non_producer_sell_own_cant_supply.enterprise_category.should == "hub" - non_producer_sell_none_can_supply.enterprise_category.should == "hub_profile" - non_producer_sell_none_cant_supply.enterprise_category.should == "hub_profile" + producer_sell_all.enterprise_category.should == "producer_hub" + producer_sell_own.enterprise_category.should == "producer_shop" + producer_sell_none.enterprise_category.should == "producer" + non_producer_sell_all.enterprise_category.should == "hub" + non_producer_sell_own.enterprise_category.should == "hub" + non_producer_sell_none.enterprise_category.should == "hub_profile" end end end diff --git a/spec/models/order_cycle_spec.rb b/spec/models/order_cycle_spec.rb index 9785d5ed2d..56aa51a0d0 100644 --- a/spec/models/order_cycle_spec.rb +++ b/spec/models/order_cycle_spec.rb @@ -44,8 +44,8 @@ describe OrderCycle do end it "finds order cycles accessible by a user" do - e1 = create(:enterprise, is_primary_producer: true, is_distributor: true) - e2 = create(:enterprise, is_primary_producer: true, is_distributor: true) + e1 = create(:enterprise, is_primary_producer: true, sells: "any") + e2 = create(:enterprise, is_primary_producer: true, sells: "any") user = create(:user, enterprises: [e2], spree_roles: []) user.spree_roles = [] From 5c0d84664351c9e497dbec5b57e5c6f3d9a52bb8 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 28 Sep 2014 11:55:46 +1000 Subject: [PATCH 016/142] bugfix sells and is_distributor specs and code --- .../enterprise_controller.js.coffee | 1 - .../templates/registration/details.html.haml | 11 +++++----- .../admin/enterprises_controller.rb | 2 +- .../admin/overview_controller_decorator.rb | 2 +- .../api/admin/enterprise_serializer.rb | 4 ++-- .../admin/enterprises/_sidebar.html.haml | 4 ++-- .../_sidebar_enterprise_fees.html.haml | 2 +- app/views/admin/enterprises/index.html.haml | 6 ++--- spec/features/admin/enterprise_user_spec.rb | 5 ++++- spec/features/admin/enterprises_spec.rb | 22 +++++++++++++------ spec/features/consumer/registration_spec.rb | 3 ++- 11 files changed, 37 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee index a872661b27..20b7bca613 100644 --- a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee +++ b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee @@ -3,7 +3,6 @@ angular.module("admin.enterprises") $scope.Enterprise = Enterprise.enterprise $scope.PaymentMethods = PaymentMethods.paymentMethods $scope.ShippingMethods = ShippingMethods.shippingMethods - $scope.Enterprise.sells = "none" for payment_method in $scope.PaymentMethods payment_method.selected = payment_method.id in $scope.Enterprise.payment_method_ids diff --git a/app/assets/javascripts/templates/registration/details.html.haml b/app/assets/javascripts/templates/registration/details.html.haml index cecf588e11..39af0d1cb6 100644 --- a/app/assets/javascripts/templates/registration/details.html.haml +++ b/app/assets/javascripts/templates/registration/details.html.haml @@ -1,24 +1,25 @@ .container#registration-details{bindonce: true} .header %h2 Let's Get Started - %h5{ bo: { if: "enterprise.type != 'single'" } } Woot! First we need to know what sort of enterprise you are: - %h5{ bo: { if: "enterprise.type == 'single'" } } Woot! First we need to know the name of your farm: + %h5{ bo: { if: "enterprise.sells != 'own'" } } Woot! First we need to know what sort of enterprise you are: + %h5{ bo: { if: "enterprise.sells == 'own'" } } Woot! First we need to know the name of your farm: %ng-include{ src: "'registration/steps.html'" } %form{ name: 'details', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "selectIfValid('address',details)" } } .row .small-12.columns.field - %label{ for: 'enterprise_name', bo: { if: "enterprise.type != 'single'" } } Enterprise Name: - %label{ for: 'enterprise_name', bo: { if: "enterprise.type == 'single'" } } Farm Name: + %label{ for: 'enterprise_name', bo: { if: "enterprise.sells != 'own'" } } Enterprise Name: + %label{ for: 'enterprise_name', bo: { if: "enterprise.sells == 'own'" } } Farm Name: %input.chunky.small-12.columns{ id: 'enterprise_name', name: 'name', placeholder: "eg. Charlie's Awesome Farm", required: true, ng: { model: 'enterprise.name' } } %span.error.small-12.columns{ ng: { show: "details.name.$error.required && submitted" } } You need to enter a name for your enterprise! - .row#enterprise-types{ 'data-equalizer' => true, bo: { if: "enterprise.type != 'single'" } } + .row#enterprise-types{ 'data-equalizer' => true, bo: { if: "enterprise.sells != 'own'" } } .small-12.columns.field .row .small-12.columns %label Choose one: .row + -# TODO redesign this to refelct the extra options available. .small-12.medium-4.large-4.columns{ 'data-equalizer-watch' => true } %a.panel#producer-panel{ href: "#", ng: { click: "enterprise.is_primary_producer = true", class: "{selected: (!enterprise.is_distributor && enterprise.is_primary_producer)}" } } .left diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index bbb8073deb..1beb854a47 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -50,7 +50,7 @@ module Admin end def collection - # TODO is_distributor DESC, + # TODO was ordered with is_distributor DESC as well, not sure why or how we want ot sort this now Enterprise.managed_by(spree_current_user).order('is_primary_producer ASC, name') end diff --git a/app/controllers/spree/admin/overview_controller_decorator.rb b/app/controllers/spree/admin/overview_controller_decorator.rb index 1cf8cb6f4e..4ae1c1b095 100644 --- a/app/controllers/spree/admin/overview_controller_decorator.rb +++ b/app/controllers/spree/admin/overview_controller_decorator.rb @@ -1,6 +1,6 @@ Spree::Admin::OverviewController.class_eval do def index - # TODO is_distributor DESC, + # TODO was sorted with is_distributor DESC as well, not sure why or how we want ot sort this now @enterprises = Enterprise.managed_by(spree_current_user).order('is_primary_producer ASC, name') @product_count = Spree::Product.active.managed_by(spree_current_user).count @order_cycle_count = OrderCycle.active.managed_by(spree_current_user).count diff --git a/app/serializers/api/admin/enterprise_serializer.rb b/app/serializers/api/admin/enterprise_serializer.rb index 80acf6d7c4..5164256424 100644 --- a/app/serializers/api/admin/enterprise_serializer.rb +++ b/app/serializers/api/admin/enterprise_serializer.rb @@ -1,3 +1,3 @@ class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer - attributes :name, :id, :is_primary_producer, :is_distributor, :payment_method_ids, :shipping_method_ids -end \ No newline at end of file + attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :payment_method_ids, :shipping_method_ids +end diff --git a/app/views/admin/enterprises/_sidebar.html.haml b/app/views/admin/enterprises/_sidebar.html.haml index ac4966fa80..a4c149c9e9 100644 --- a/app/views/admin/enterprises/_sidebar.html.haml +++ b/app/views/admin/enterprises/_sidebar.html.haml @@ -1,6 +1,6 @@ +- if can? :admin, EnterpriseFee + = render 'sidebar_enterprise_fees', f: f - if can? :admin, Spree::PaymentMethod = render 'sidebar_payment_methods', f: f - if can? :admin, Spree::ShippingMethod = render 'sidebar_shipping_methods', f: f -- if can? :admin, EnterpriseFee - = render 'sidebar_enterprise_fees', f: f diff --git a/app/views/admin/enterprises/_sidebar_enterprise_fees.html.haml b/app/views/admin/enterprises/_sidebar_enterprise_fees.html.haml index 1e73416218..b192201528 100644 --- a/app/views/admin/enterprises/_sidebar_enterprise_fees.html.haml +++ b/app/views/admin/enterprises/_sidebar_enterprise_fees.html.haml @@ -1,5 +1,5 @@ - enterprise_fees_color = @enterprise_fees.count > 0 ? "blue" : "red" -.sidebar_item.four.columns.alpha#enterprise_fees{ ng: { show: 'Enterprise.sells != "none"' } } +.sidebar_item.four.columns.alpha#enterprise_fees{ ng: { show: 'Enterprise.sells != "none" || Enterprise.is_primary_producer' } } .four.columns.alpha.header{ class: "#{enterprise_fees_color}" } %span.four.columns.alpha.centered Enterprise Fees .four.columns.alpha.list{ class: "#{enterprise_fees_color}" } diff --git a/app/views/admin/enterprises/index.html.haml b/app/views/admin/enterprises/index.html.haml index 79f59d7171..a29c7e3a30 100644 --- a/app/views/admin/enterprises/index.html.haml +++ b/app/views/admin/enterprises/index.html.haml @@ -23,9 +23,9 @@ %tr{"data-hook" => "enterprises_header"} %th Name %th Role - %th Visible? - if spree_current_user.admin? - %th Type + %th Sells + %th Visible? - if spree_current_user.admin? %th Owner %th @@ -37,9 +37,9 @@ %td = enterprise_form.check_box :is_primary_producer Producer - %td= enterprise_form.check_box :visible - if spree_current_user.admin? %td= enterprise_form.select :sells, Enterprise::SELLS, {}, class: 'select2 fullwidth' + %td= enterprise_form.check_box :visible - if spree_current_user.admin? %td= enterprise_form.select :owner_id, enterprise.users.map{ |e| [ e.email, e.id ] }, {}, class: "select2 fullwidth" %td{"data-hook" => "admin_users_index_row_actions"} diff --git a/spec/features/admin/enterprise_user_spec.rb b/spec/features/admin/enterprise_user_spec.rb index fa92013a73..22f322e51e 100644 --- a/spec/features/admin/enterprise_user_spec.rb +++ b/spec/features/admin/enterprise_user_spec.rb @@ -53,7 +53,10 @@ feature %q{ end end - describe "with only a profile-level enterprise" do + # This case no longer exists as anyone with an enterprise can supply into the system. + # Or can they?? There is no producer profile anyway. + # TODO discuss what parts of this are still necessary in which cases. + pending "with only a profile-level enterprise" do before do user.enterprise_roles.create! enterprise: supplier_profile user.enterprise_roles.create! enterprise: distributor_profile diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index b97e7600c4..f661f87419 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -142,16 +142,23 @@ feature %q{ # Check Angularjs switching of sidebar elements uncheck 'enterprise_is_primary_producer' - #TODO something needed here ? sells=any? not sure what js is_distributor was connected to - # uncheck 'enterprise_is_distributor' - # page.should have_selector "#payment_methods", visible: false - # page.should have_selector "#shipping_methods", visible: false - # page.should have_selector "#enterprise_fees", visible: false - #TODO something needed here ? sells=any? not sure what js is_distributor was connected to - # check 'enterprise_is_distributor' + choose 'None' + page.should have_selector "#enterprise_fees", visible: false + page.should have_selector "#payment_methods", visible: false + page.should have_selector "#shipping_methods", visible: false + check 'enterprise_is_primary_producer' + page.should have_selector "#enterprise_fees" + page.should have_selector "#payment_methods", visible: false + page.should have_selector "#shipping_methods", visible: false + uncheck 'enterprise_is_primary_producer' + choose 'Own' + page.should have_selector "#enterprise_fees" page.should have_selector "#payment_methods" page.should have_selector "#shipping_methods" + choose 'Any' page.should have_selector "#enterprise_fees" + page.should have_selector "#payment_methods" + page.should have_selector "#shipping_methods" select2_search eg1.name, from: 'Groups' @@ -182,6 +189,7 @@ feature %q{ @enterprise.reload expect(@enterprise.owner).to eq user + #TODO fix so the sells field actually saves something page.should have_checked_field "enterprise_payment_method_ids_#{payment_method.id}" page.should have_checked_field "enterprise_shipping_method_ids_#{shipping_method.id}" page.should have_selector "a.list-item", text: enterprise_fee.name diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index 5ed9c59fcb..57013342bc 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -3,7 +3,8 @@ require 'spec_helper' feature "Registration", js: true do include WebHelper - describe "Registering a Profile" do + # TODO fix this after removal of is_distributor. + pending "Registering a Profile" do let(:user) { create(:user, password: "password", password_confirmation: "password") } it "Allows a logged in user to register a profile" do From 58f13a3e062e0e54a476fe377fa2a96575603856 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 28 Sep 2014 12:57:27 +1000 Subject: [PATCH 017/142] update migration --- .../20140927005043_enterprise_config_refactor.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/db/migrate/20140927005043_enterprise_config_refactor.rb b/db/migrate/20140927005043_enterprise_config_refactor.rb index 636b535be3..95cf7ab7c5 100644 --- a/db/migrate/20140927005043_enterprise_config_refactor.rb +++ b/db/migrate/20140927005043_enterprise_config_refactor.rb @@ -2,7 +2,7 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration def up add_column :enterprises, :sells, :string, null: false, default: 'none' - Enterprise.all do |enterprise| + Enterprise.all.each do |enterprise| enterprise.sells = sells_what?(enterprise) enterprise.save! end @@ -14,10 +14,11 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration def down end - #TODO make this work - def sells_what?(enterprise) - return "none" if !enterprise.is_distributor || enterprise.type == "profile" - return "own" if enterprise.type == "single" || enterprise.suppliers == [enterprise] + def sells_what?(enterprise) + is_distributor = enterprise.read_attribute(:is_distributor) + type = enterprise.read_attribute(:type) + return "none" if !is_distributor || type == "profile" + return "own" if type == "single" || enterprise.suppliers == [enterprise] return "any" end end From dc7c9ea2727a4ce23be8cfa2111d9a4c4dfa0e5c Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 28 Sep 2014 22:37:26 +1000 Subject: [PATCH 018/142] commit updated schema --- db/schema.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index e0d47470b7..67084cc347 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -248,8 +248,8 @@ ActiveRecord::Schema.define(:version => 20140927005043) do t.integer "address_id" t.string "pickup_times" t.string "next_collection_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.text "distributor_info" t.string "logo_file_name" t.string "logo_content_type" @@ -263,10 +263,8 @@ ActiveRecord::Schema.define(:version => 20140927005043) do t.string "facebook" t.string "instagram" t.string "linkedin" - t.integer "owner_id", :null => false - t.string "sell", :default => "none", :null => false - t.string "sells", :default => "none", :null => false - t.string "type", :default => "profile", :null => false + t.integer "owner_id", :null => false + t.string "sells", :default => "none", :null => false end add_index "enterprises", ["address_id"], :name => "index_enterprises_on_address_id" From a49991c696738da54820da7795c9214f14bddfdb Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 28 Sep 2014 22:55:49 +1000 Subject: [PATCH 019/142] set abilities tests to pending, need to discuss further --- spec/models/spree/ability_spec.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index 7402c1b527..759feb499d 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -6,12 +6,13 @@ module Spree describe User do - describe "broad permissions" do + # TODO work out what permissions are meant to be now... + pending "broad permissions" do subject { AbilityDecorator.new(user) } let(:user) { create(:user) } - let(:enterprise_full) { create(:enterprise, type: 'full') } - let(:enterprise_single) { create(:enterprise, type: 'single') } - let(:enterprise_profile) { create(:enterprise, type: 'profile') } + let(:enterprise_full) { create(:enterprise, sells: 'full') } + let(:enterprise_single) { create(:enterprise, sells: 'single') } + let(:enterprise_profile) { create(:enterprise, sells: 'profile') } describe "creating enterprises" do it "can create enterprises straight off the bat" do From 206c8da0ba8faeb4124f14ba837cd7f80077b831 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Tue, 30 Sep 2014 23:53:45 +1000 Subject: [PATCH 020/142] remove unused css* --- app/assets/stylesheets/distributors.css.scss | 3 - app/assets/stylesheets/groups.css.scss | 3 - app/assets/stylesheets/shop/checkout.css.scss | 3 - app/assets/stylesheets/store/all.css | 13 - .../store/openfoodnetwork.css.scss | 381 ------------------ .../stylesheets/store/variables.css.scss | 64 --- .../store/variables_changes.css.scss | 1 - 7 files changed, 468 deletions(-) delete mode 100644 app/assets/stylesheets/distributors.css.scss delete mode 100644 app/assets/stylesheets/groups.css.scss delete mode 100644 app/assets/stylesheets/shop/checkout.css.scss delete mode 100644 app/assets/stylesheets/store/all.css delete mode 100644 app/assets/stylesheets/store/openfoodnetwork.css.scss delete mode 100644 app/assets/stylesheets/store/variables.css.scss delete mode 100644 app/assets/stylesheets/store/variables_changes.css.scss diff --git a/app/assets/stylesheets/distributors.css.scss b/app/assets/stylesheets/distributors.css.scss deleted file mode 100644 index de8cd669a0..0000000000 --- a/app/assets/stylesheets/distributors.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the distributors controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/groups.css.scss b/app/assets/stylesheets/groups.css.scss deleted file mode 100644 index c2a5f9013b..0000000000 --- a/app/assets/stylesheets/groups.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the groups controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/shop/checkout.css.scss b/app/assets/stylesheets/shop/checkout.css.scss deleted file mode 100644 index 727d410b19..0000000000 --- a/app/assets/stylesheets/shop/checkout.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the Shop::Checkout controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/store/all.css b/app/assets/stylesheets/store/all.css deleted file mode 100644 index c1d3d851bc..0000000000 --- a/app/assets/stylesheets/store/all.css +++ /dev/null @@ -1,13 +0,0 @@ -/* - * This is a manifest file that'll automatically include all the stylesheets available in this directory - * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at - * the top of the compiled file, but it's generally better to create a new file per style scope. - * - - *= require store/spree_core - *= require store/spree_auth - *= require store/spree_promo - - *= require_self - *= require_tree . -*/ diff --git a/app/assets/stylesheets/store/openfoodnetwork.css.scss b/app/assets/stylesheets/store/openfoodnetwork.css.scss deleted file mode 100644 index f98642cc22..0000000000 --- a/app/assets/stylesheets/store/openfoodnetwork.css.scss +++ /dev/null @@ -1,381 +0,0 @@ -@import "screen"; -@import "compass/css3/border-radius"; - -/* General purpose styles */ - -a:hover { - color: lighten($link_text_color, 20) !important; -} - -/* Cleared div for clearing previous floating elements */ -div.cleared { - clear: both; -} - -p.hint { - margin: 0 0 0.5em 0; - padding: 0; - color: #6a6a6a; -} - -table { - tbody, tfoot { - tr { - &.alt, &.odd { - background-color: lighten($link_text_color, 75) !important; - } - } - } -} - - - -/* Style current distributor in main nav bar */ -#header { - margin-bottom: 40px; - - #logo { - position: relative; - margin-top: 40px; - padding-top: 10px; - - h1 { - position: absolute; - top: 10px; - left: 0px; - } - - .change-location { - position: absolute; - top: 22px; - right: -104px; - } - } -} - -nav #main-nav-bar { - position: absolute; - top: 0px; - left: 10px; - width: 100%; - - #link-to-cart { - position: relative; - top: 40px; - right: 16px; - } - - li { - &#current-distribution { - float: right; - clear: right; - margin: 0.5em 5px 0 0; - - a { - font-size: 12px; - padding: 0; - } - } - } -} - -nav#top-nav-bar { - position: relative; - z-index: 999; - margin-top: 20px; -} - - -/* Based on Spree's nav#taxonomies style. Copied instead of - * extended with SASS because SASS does not allow extending - * nested selectors. - */ -nav#filters { - .filter_name { - text-transform: uppercase; - border-bottom: 1px solid lighten($body_text_color, 60); - margin-bottom: 5px; - font-size: $main_navigation_header_font_size; - } - - .filter_choices { - padding-left: 20px; - margin-bottom: 5px; - list-style: disc outside; - - li { - a { - font-size: $main_navigation_font_size; - } - span.inactive { - color: #999; - } - } - } - - input[type=submit] { - margin-bottom: 15px; - } -} - - -/* Distributor and order cycle selection and display */ -#distribution-choice { - margin-bottom: 2em; - padding: 5px; - border: 2px solid #ccc; - @include border-radius(10px); -} - -#distribution-selection { - overflow: auto; - margin-bottom: 2em; - padding: 20px; - background-color: #f3f3f3; - - .distributors { - float: left; - margin-right: 4em; - - option.local { - background-color: #cfc; - } - option.remote { - background-color: #fcc; - } - } - - .order-cycles { - - select { - padding: 10px; - margin-top: 15px; - border: 2px solid white; - width: 100%; - } - - float: left; - - tr.local { - background-color: #cfc; - } - tr.remote { - background-color: #fcc; - } - } -} - -.countdown-panel { - background: url("../countdown.png") no-repeat left; - min-height: 60px; - min-width: 70px; - padding-left: 77px; -} - - -/* Style the product source on the product details page in the - * same manner as the product properties table above it. - */ -#product-source { - @extend #product-properties; -} -#product-properties td, #product-source td { - width: 50%; -} - - -/* Apply Spree's ul#products style to ul.product-listing. When viewing products - * split by distributor, a separate product listing is displayed for local and - * remote products, so the #products id is removed to avoid its duplication. - */ -ul.product-listing { - &:after { - content: " "; - display: block; - clear: both; - visibility: hidden; - line-height: 0; - height: 0; - } - - li { - text-align: center; - font-weight: bold; - margin-bottom: 20px; - - a { - display: block; - - &.info { - height: 35px; - margin-top: 5px; - font-size: $product_list_name_font_size; - color: $product_link_text_color; - border-bottom: 1px solid lighten($body_text_color, 60); - overflow: hidden; - } - } - - .product-image { - border: 1px solid lighten($body_text_color, 60); - padding: 5px; - min-height: 110px; - background-color: $product_background_color; - - &:hover { - border-color: $link_text_color; - } - - } - - .price { - color: $link_text_color; - font-size: $product_list_price_font_size; - padding-top: 5px; - display: block; - } - } -} - - -/* Enterprise description */ -.enterprise-description { - margin-bottom: 2em; -} - - -/* Supplier page distributor listing */ -#supplier-distributors li a.inactive { - color: #999; -} - - -/* Highlight local products in distributor-split product listings */ -#products-local ul { - margin-bottom: 1em; - padding: 10px; - @include border-radius(10px); - background-color: #def; -} - - -/* Distributor details on product details page */ -fieldset#product-distributor-details { - float: right; - margin-top: 0; - width: 250px; - @extend #shipping; -} - -#product-variants { - float: none; - - ul { - list-style-type: none; - } -} - - -/* Add to cart form on product details page */ -#cart-form { - .error-distributor { - font-size: 120%; - font-weight: bold; - color: #f00; - - a { - color: #f00; - text-decoration: underline; - } - } - - .distributor-fixed { - } -} - - -/* View cart form */ -#subtotal { - width: 100%; -} -.links { - float: right; - text-align: right; -} -#empty-cart { - float: left; - margin-top: 15px !important; - - p { - padding: 0; - } -} - -/* Checkout address page */ -#checkout .alternative-available-distributors { - padding-top: 30px; -} - - -/* Delivery fees table on checkout page */ -#delivery-fees { - clear: both; - padding-top: 6em; - - table#delivery { - width: 100%; - - tbody { - tr { - td.item-shipping-cost, td.item-shipping-method { - text-align: center; - } - td.item-shipping-cost { - @extend span.price; - @extend span.price.selling; - } - } - } - } - - .subtotal { - width: 100%; - text-align: right; - text-transform: uppercase; - margin-top: 15px; - - span.order-total { - @extend span.price; - } - } -} - -/* Alert for EFT Payment during checkout process */ -div#eft-payment-alert { - border: 2px solid red; - padding-left: 5px; -} - -/* Large 'Save and Continue/Process My Order' button under Order Summary on the checkout pages */ -#add_new_save_checkout_button { - display: none; - margin-top: 30px; - padding-top: 10px; - border-top: 1px solid #d9d9db; -} - -.secondary { - color: #6A6A6A; -} - -.hide { - display: none; -} - - -/* Distributor details */ -.distributor-details .next-collection-at { - font-size: 20px; - font-weight: bold; - color: #de790c; -} diff --git a/app/assets/stylesheets/store/variables.css.scss b/app/assets/stylesheets/store/variables.css.scss deleted file mode 100644 index 4cb074ae48..0000000000 --- a/app/assets/stylesheets/store/variables.css.scss +++ /dev/null @@ -1,64 +0,0 @@ -/*--------------------------------------*/ -/* Colors -/*--------------------------------------*/ -$c_green: #8dba53 !default; /* Spree green */ -$c_red: #e45353 !default; /* Error red */ - -$layout_background_color: #FFFFFF !default; -$title_text_color: #404042 !default; -$body_text_color: #404042 !default; -$link_text_color: #00ADEE !default; - -$product_background_color: #FFFFFF !default; -$product_title_text_color: #404042 !default; -$product_body_text_color: #404042 !default; -$product_link_text_color: #BBBBBB !default; - -/*--------------------------------------*/ -/* Fonts import from remote -/*--------------------------------------*/ -@import url(//fonts.googleapis.com/css?family=Ubuntu:400,700,400italic,700italic|&subset=latin,cyrillic,greek,greek-ext,latin-ext,cyrillic-ext); - -/*--------------------------------------*/ -/* Font families -/*--------------------------------------*/ -$ff_base: 'Ubuntu', sans-serif !default; - -/*-------------------------------------- - | Font sizes - |-------------------------------------- - |- Navigation - | */ - $header_navigation_font_size: 14px !default; - $horizontal_navigation_font_size: 16px !default; - $main_navigation_header_font_size: 14px !default; - $main_navigation_font_size: 12px !default; -/*|------------------------------------ - |- Product Listing - | */ - $product_list_name_font_size: 12px !default; - $product_list_price_font_size: 16px !default; - $product_list_header_font_size: 20px !default; - $product_list_search_font_size: 14px !default; -/*|------------------------------------ - |- Product Details - | */ - $product_detail_name_font_size: 24px !default; - $product_detail_description_font_size: 12px !default; - $product_detail_price_font_size: 20px !default; - $product_detail_title_font_size: 14px !default; -/*|------------------------------------ - |- Basic - | */ - $heading_font_size: 24px !default; - $sub_heading_font_size: 14px !default; - $button_font_size: 12px !default; - $input_box_font_size: 13px !default; - $base_font_size: 12px !default; - $border_color: lighten($body_text_color, 60) !default; - $default_border: 1px solid $border_color !default; - $button_border_color: rgba(0, 138, 189, .75) !default; - $table_head_color: lighten($body_text_color, 60) !default; - - -@import "./store/variables_changes.css.scss"; diff --git a/app/assets/stylesheets/store/variables_changes.css.scss b/app/assets/stylesheets/store/variables_changes.css.scss deleted file mode 100644 index c4007abd2f..0000000000 --- a/app/assets/stylesheets/store/variables_changes.css.scss +++ /dev/null @@ -1 +0,0 @@ -$link_text_color: #006066; From fa41f6dc40306d2b9be4609a7887ff7e0789d7f6 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Wed, 1 Oct 2014 13:02:03 +1000 Subject: [PATCH 021/142] add rollback to migration --- ...140927005043_enterprise_config_refactor.rb | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/db/migrate/20140927005043_enterprise_config_refactor.rb b/db/migrate/20140927005043_enterprise_config_refactor.rb index 95cf7ab7c5..de2bf1d407 100644 --- a/db/migrate/20140927005043_enterprise_config_refactor.rb +++ b/db/migrate/20140927005043_enterprise_config_refactor.rb @@ -12,13 +12,36 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration end def down + # This process is lossy. Producer profiles wont exist. + add_column :enterprises, :type, :string, null: false, default: 'profile' + add_column :enterprises, :is_distributor, :boolean + + Enterprise.all.each do |enterprise| + enterprise.type = type?(enterprise) + enterprise.is_distributor = distributes?(enterprise) + enterprise.save! + end + + remove_column :enterprises, :sells end def sells_what?(enterprise) is_distributor = enterprise.read_attribute(:is_distributor) type = enterprise.read_attribute(:type) return "none" if !is_distributor || type == "profile" - return "own" if type == "single" || enterprise.suppliers == [enterprise] + return "own" if type == "single" return "any" end + + def distributes?(enterprise) + return true if enterprise.read_attribute(:sells) != "none" + return false + end + + def type?(enterprise) + sells = enterprise.read_attribute(:sells) + return "profile" if !enterprise.is_primary_producer and sells == "none" + return "single" if sells == "own" + return "full" + end end From 47991f192e1e5372674060f756c2905d204a3ff3 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Wed, 1 Oct 2014 16:49:47 +1000 Subject: [PATCH 022/142] tweak migration --- db/migrate/20140927005043_enterprise_config_refactor.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20140927005043_enterprise_config_refactor.rb b/db/migrate/20140927005043_enterprise_config_refactor.rb index de2bf1d407..f7d120c469 100644 --- a/db/migrate/20140927005043_enterprise_config_refactor.rb +++ b/db/migrate/20140927005043_enterprise_config_refactor.rb @@ -28,8 +28,8 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration def sells_what?(enterprise) is_distributor = enterprise.read_attribute(:is_distributor) type = enterprise.read_attribute(:type) + return "own" if type == "single" && (is_distributor || is_primary_producer) return "none" if !is_distributor || type == "profile" - return "own" if type == "single" return "any" end @@ -40,7 +40,7 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration def type?(enterprise) sells = enterprise.read_attribute(:sells) - return "profile" if !enterprise.is_primary_producer and sells == "none" + return "profile" if sells == "none" return "single" if sells == "own" return "full" end From 56a9658b146634f358526c3870eeae98990c08dc Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Wed, 1 Oct 2014 16:55:41 +1000 Subject: [PATCH 023/142] update ability spec --- spec/models/spree/ability_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index 7677f55eed..5ec2dc2190 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -10,13 +10,13 @@ module Spree pending "broad permissions" do subject { AbilityDecorator.new(user) } let(:user) { create(:user) } - let(:enterprise_full) { create(:enterprise, sells: 'full') } - let(:enterprise_single) { create(:enterprise, sells: 'single') } - let(:enterprise_profile) { create(:enterprise, sells: 'profile') } + let(:enterprise_any) { create(:enterprise, sells: 'any') } + let(:enterprise_own) { create(:enterprise, sells: 'own') } + let(:enterprise_none) { create(:enterprise, sells: 'none') } - context "as manager of a 'full' type enterprise" do + context "as manager of a 'any' type enterprise" do before do - user.enterprise_roles.create! enterprise: enterprise_full + user.enterprise_roles.create! enterprise: enterprise_any end it { subject.can_manage_products?(user).should be_true } @@ -24,9 +24,9 @@ module Spree it { subject.can_manage_orders?(user).should be_true } end - context "as manager of a 'single' type enterprise" do + context "as manager of a 'own' type enterprise" do before do - user.enterprise_roles.create! enterprise: enterprise_single + user.enterprise_roles.create! enterprise: enterprise_own end it { subject.can_manage_products?(user).should be_true } @@ -34,9 +34,9 @@ module Spree it { subject.can_manage_orders?(user).should be_true } end - context "as manager of a 'profile' type enterprise" do + context "as manager of a 'none' type enterprise" do before do - user.enterprise_roles.create! enterprise: enterprise_profile + user.enterprise_roles.create! enterprise: enterprise_none end it { subject.can_manage_products?(user).should be_true } From 54b138b2ccebc5f3c1b0e2d1b5c32ba13cca12e2 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Wed, 1 Oct 2014 18:47:22 +1000 Subject: [PATCH 024/142] add transclusion to modal directive by default --- .../darkswarm/directives/enterprise_modal.js.coffee | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 app/assets/javascripts/darkswarm/directives/enterprise_modal.js.coffee diff --git a/app/assets/javascripts/darkswarm/directives/enterprise_modal.js.coffee b/app/assets/javascripts/darkswarm/directives/enterprise_modal.js.coffee new file mode 100644 index 0000000000..fa6378afe2 --- /dev/null +++ b/app/assets/javascripts/darkswarm/directives/enterprise_modal.js.coffee @@ -0,0 +1,9 @@ +Darkswarm.directive "enterpriseModal", ($modal)-> + restrict: 'E' + replace: true + template: "" + transclude: true + link: (scope, elem, attrs, ctrl)-> + elem.on "click", (ev)=> + ev.stopPropagation() + scope.modalInstance = $modal.open(controller: ctrl, templateUrl: 'enterprise_modal.html', scope: scope) From ccdcf16cecc421f28ad1bdf483a2e67d53b2f70b Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Wed, 1 Oct 2014 18:47:50 +1000 Subject: [PATCH 025/142] rename file --- .../darkswarm/directives/enterproise_modal.js.coffee | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 app/assets/javascripts/darkswarm/directives/enterproise_modal.js.coffee diff --git a/app/assets/javascripts/darkswarm/directives/enterproise_modal.js.coffee b/app/assets/javascripts/darkswarm/directives/enterproise_modal.js.coffee deleted file mode 100644 index 60f3810f41..0000000000 --- a/app/assets/javascripts/darkswarm/directives/enterproise_modal.js.coffee +++ /dev/null @@ -1,8 +0,0 @@ -Darkswarm.directive "enterpriseModal", ($modal)-> - restrict: 'E' - replace: true - template: "{{enterprise.name}}" - link: (scope, elem, attrs, ctrl)-> - elem.on "click", (ev)=> - ev.stopPropagation() - scope.modalInstance = $modal.open(controller: ctrl, templateUrl: 'hub_modal.html', scope: scope) From 3877bed62b9793d865913eeb274340568eca448e Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Wed, 1 Oct 2014 18:51:49 +1000 Subject: [PATCH 026/142] use enterprise modal --- app/views/groups/index.html.haml | 5 +++-- app/views/home/_fat.html.haml | 2 +- app/views/shop/products/_summary.html.haml | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/views/groups/index.html.haml b/app/views/groups/index.html.haml index b033c93d12..1aa5b02629 100644 --- a/app/views/groups/index.html.haml +++ b/app/views/groups/index.html.haml @@ -40,8 +40,9 @@ %h5 Our hubs & producers %ul.small-block-grid-2 %li{"ng-repeat" => "enterprise in group.enterprises", "scroll-after-load" => true} - %hub-modal{"ng-if" => "enterprise.is_distributor"} - %producer-modal{"ng-if" => "!enterprise.is_distributor", "show-hub-actions" => 'true'} + %enterprise-modal{"ng-if" => "enterprise.is_distributor"} + {{ enterprise.name }} + %enterprise-modal{"ng-if" => "!enterprise.is_distributor", "show-hub-actions" => 'true'} {{ enterprise.name }} diff --git a/app/views/home/_fat.html.haml b/app/views/home/_fat.html.haml index 406431b9b7..b3741e5aec 100644 --- a/app/views/home/_fat.html.haml +++ b/app/views/home/_fat.html.haml @@ -23,7 +23,7 @@ %label Our producers %ul.small-block-grid-2.medium-block-grid-1.large-block-grid-2 %li{"ng-repeat" => "enterprise in hub.producers"} - %producer-modal + %enterprise-modal %i.ofn-i_036-producers %span {{ enterprise.name }} diff --git a/app/views/shop/products/_summary.html.haml b/app/views/shop/products/_summary.html.haml index 25c71f276a..82d5f7c297 100644 --- a/app/views/shop/products/_summary.html.haml +++ b/app/views/shop/products/_summary.html.haml @@ -10,7 +10,7 @@ %em from %span - %producer-modal + %enterprise-modal %i.ofn-i_036-producers {{ enterprise.name }} From 47dc0017352771e3d5f431f4c163ebaf1e601999 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Wed, 1 Oct 2014 20:27:53 +1000 Subject: [PATCH 027/142] merge has_shopfront and is_distibutor --- .../darkswarm/filters/show_profiles.js.coffee | 2 +- .../templates/partials/enterprise_header.html.haml | 8 ++++---- .../templates/partials/hub_actions.html.haml | 2 +- .../templates/partials/hub_details.html.haml | 2 +- .../stylesheets/darkswarm/producer_node.css.sass | 2 +- app/serializers/api/enterprise_serializer.rb | 14 +------------- app/views/home/_hubs.html.haml | 2 +- app/views/home/_skinny.html.haml | 4 ++-- app/views/producers/_skinny.html.haml | 8 ++++---- 9 files changed, 16 insertions(+), 28 deletions(-) diff --git a/app/assets/javascripts/darkswarm/filters/show_profiles.js.coffee b/app/assets/javascripts/darkswarm/filters/show_profiles.js.coffee index e3fce7d2f6..b76dc8373e 100644 --- a/app/assets/javascripts/darkswarm/filters/show_profiles.js.coffee +++ b/app/assets/javascripts/darkswarm/filters/show_profiles.js.coffee @@ -4,4 +4,4 @@ Darkswarm.filter 'showProfiles', ()-> show_profiles ?= true enterprises.filter (enterprise)=> - show_profiles or enterprise.has_shopfront + show_profiles or enterprise.is_distributor diff --git a/app/assets/javascripts/templates/partials/enterprise_header.html.haml b/app/assets/javascripts/templates/partials/enterprise_header.html.haml index 8612ba968e..27a57ed90b 100644 --- a/app/assets/javascripts/templates/partials/enterprise_header.html.haml +++ b/app/assets/javascripts/templates/partials/enterprise_header.html.haml @@ -1,13 +1,13 @@ -.highlight{"ng-class" => "{'has_shopfront' : enterprise.has_shopfront}"} +.highlight{"ng-class" => "{'is_distributor' : enterprise.is_distributor}"} .highlight-top.row .small-12.medium-7.large-8.columns - %h3{"ng-if" => "enterprise.has_shopfront"} + %h3{"ng-if" => "enterprise.is_distributor"} %a{"bo-href" => "enterprise.path", "ofn-empties-cart" => "enterprise", bindonce: true} %i{"ng-class" => "enterprise.icon_font"} %span {{ enterprise.name }} - %h3{"ng-if" => "!enterprise.has_shopfront", "ng-class" => "{'is_producer' : enterprise.is_primary_producer}"} + %h3{"ng-if" => "!enterprise.is_distributor", "ng-class" => "{'is_producer' : enterprise.is_primary_producer}"} %i{"ng-class" => "enterprise.icon_font"} %span {{ enterprise.name }} .small-12.medium-5.large-4.columns.text-right.small-only-text-left %p {{ [enterprise.address.city, enterprise.address.state_name] | printArray}} - %img.hero-img{"ng-src" => "{{enterprise.promo_image}}"} \ No newline at end of file + %img.hero-img{"ng-src" => "{{enterprise.promo_image}}"} diff --git a/app/assets/javascripts/templates/partials/hub_actions.html.haml b/app/assets/javascripts/templates/partials/hub_actions.html.haml index fa9ff4e183..61e74afb42 100644 --- a/app/assets/javascripts/templates/partials/hub_actions.html.haml +++ b/app/assets/javascripts/templates/partials/hub_actions.html.haml @@ -1,4 +1,4 @@ -.row.pad-top{bindonce: true, "ng-if" => "enterprise.hubs.length > 0 && enterprise.has_shopfront"} +.row.pad-top{bindonce: true, "ng-if" => "enterprise.hubs.length > 0 && enterprise.is_distributor"} .cta-container.small-12.columns %label Shop for diff --git a/app/assets/javascripts/templates/partials/hub_details.html.haml b/app/assets/javascripts/templates/partials/hub_details.html.haml index 27933cefcb..815200821a 100644 --- a/app/assets/javascripts/templates/partials/hub_details.html.haml +++ b/app/assets/javascripts/templates/partials/hub_details.html.haml @@ -1,4 +1,4 @@ -.row.pad-top{bindonce: true, ng: { if: 'enterprise.has_shopfront' } } +.row.pad-top{bindonce: true, ng: { if: 'enterprise.is_distributor' } } .cta-container.small-12.columns .row .small-4.columns diff --git a/app/assets/stylesheets/darkswarm/producer_node.css.sass b/app/assets/stylesheets/darkswarm/producer_node.css.sass index 22541055f4..7bac2dde6d 100644 --- a/app/assets/stylesheets/darkswarm/producer_node.css.sass +++ b/app/assets/stylesheets/darkswarm/producer_node.css.sass @@ -32,7 +32,7 @@ span text-decoration: underline - &.has_shopfront, &.has_shopfront i.ofn-i_059-producer, &.has_shopfront i.ofn-i_060-producer-reversed + &.is_distributor, &.is_distributor i.ofn-i_059-producer, &.is_distributor i.ofn-i_060-producer-reversed color: $clr-brick &:hover, &:active, &:focus color: $clr-brick-bright diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index 20379d5193..4179dae44c 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -17,7 +17,7 @@ end class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer attributes :orders_close_at, :active - attributes :icon, :icon_font, :producer_icon_font, :has_shopfront, :has_hub_listing, :enterprise_category, :is_distributor + attributes :icon, :icon_font, :producer_icon_font, :has_hub_listing, :enterprise_category, :is_distributor def orders_close_at OrderCycle.first_closing_for(object).andand.orders_close_at @@ -27,18 +27,6 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer @options[:active_distributors].andand.include? object end - def enterprise_category - object.enterprise_category - end - - def has_shopfront - object.is_distributor - end - - def is_distributor - object.is_distributor - end - # Used to select enterprises for hub listing def has_hub_listing object.is_distributor || object.enterprise_category == "hub_profile" diff --git a/app/views/home/_hubs.html.haml b/app/views/home/_hubs.html.haml index 67cb6abb40..ff6adddb3e 100644 --- a/app/views/home/_hubs.html.haml +++ b/app/views/home/_hubs.html.haml @@ -18,7 +18,7 @@ .small-12.columns .active_table %hub.active_table_node.row.animate-repeat{"ng-repeat" => "hub in filteredHubs = (hubs | hubs:query | taxons:activeTaxons | shipping:shippingTypes | showProfiles:show_profiles )", - "ng-class" => "{'is_profile' : !hub.has_shopfront, 'closed' : !open(), 'open' : open(), 'inactive' : !hub.active, 'current' : current()}", + "ng-class" => "{'is_profile' : !hub.is_distributor, 'closed' : !open(), 'open' : open(), 'inactive' : !hub.active, 'current' : current()}", "scroll-after-load" => true, "ng-controller" => "HubNodeCtrl", id: "{{hub.hash}}"} diff --git a/app/views/home/_skinny.html.haml b/app/views/home/_skinny.html.haml index 2010bffe1e..7100a06974 100644 --- a/app/views/home/_skinny.html.haml +++ b/app/views/home/_skinny.html.haml @@ -1,4 +1,4 @@ -.row.active_table_row{"ng-if" => "hub.has_shopfront", "ng-click" => "toggle()", "ng-class" => "{'closed' : !open(), 'has_shopfront' : producer.has_shopfront}", bindonce: true} +.row.active_table_row{"ng-if" => "hub.is_distributor", "ng-click" => "toggle()", "ng-class" => "{'closed' : !open(), 'is_distributor' : producer.is_distributor}", bindonce: true} .columns.small-12.medium-6.large-5.skinny-head %a.hub{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"} @@ -24,7 +24,7 @@ %em Shopping here %span.margin-top{ bo: { if: "!current()" } } Orders closed -.row.active_table_row{"ng-if" => "!hub.has_shopfront", "ng-class" => "closed"} +.row.active_table_row{"ng-if" => "!hub.is_distributor", "ng-class" => "closed"} .columns.small-12.medium-6.large-5.skinny-head %a.hub{"ng-click" => "openModal(hub)", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"} %i{ng: {class: "hub.icon_font"}} diff --git a/app/views/producers/_skinny.html.haml b/app/views/producers/_skinny.html.haml index 37767b3789..aaa59b20e8 100644 --- a/app/views/producers/_skinny.html.haml +++ b/app/views/producers/_skinny.html.haml @@ -1,11 +1,11 @@ -.row.active_table_row{"ng-click" => "toggle()", "ng-class" => "{'closed' : !open(), 'has_shopfront' : producer.has_shopfront}"} +.row.active_table_row{"ng-click" => "toggle()", "ng-class" => "{'closed' : !open(), 'is_distributor' : producer.is_distributor}"} .columns.small-12.medium-4.large-4.skinny-head - %span{"bo-if" => "producer.has_shopfront" } - %a.has_shopfront{"bo-href" => "producer.path" } + %span{"bo-if" => "producer.is_distributor" } + %a.is_distributor{"bo-href" => "producer.path" } %i{ng: {class: "producer.producer_icon_font"}} %span.margin-top %strong {{ producer.name }} - %span.producer-name{"bo-if" => "!producer.has_shopfront" } + %span.producer-name{"bo-if" => "!producer.is_distributor" } %i{ng: {class: "producer.producer_icon_font"}} %span.margin-top %strong {{ producer.name }} From e62e87549aa03143abfde4b2c654dd3610419da2 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 2 Oct 2014 10:41:43 +1000 Subject: [PATCH 028/142] commit this elsewhere --- config/ng-test.conf.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/config/ng-test.conf.js b/config/ng-test.conf.js index f87aa3d48a..eadaf984ae 100644 --- a/config/ng-test.conf.js +++ b/config/ng-test.conf.js @@ -27,16 +27,9 @@ module.exports = function(config) { 'app/assets/javascripts/admin/util.js.erb' ], - preprocessors: { - '**/*.coffee': ['coffee'] - }, - coffeePreprocessor: { options: { sourceMap: true - }, - transformPath: function(path) { - return path.replace(/\.coffee$/, '.js'); } }, From 4c1fc5671f7f61b4619a7d81df2b126420779797 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 2 Oct 2014 10:43:17 +1000 Subject: [PATCH 029/142] Minor fixes --- .../spree/admin/overview/_enterprises_hubs_tab.html.haml | 2 +- spec/features/admin/enterprises_spec.rb | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/app/views/spree/admin/overview/_enterprises_hubs_tab.html.haml b/app/views/spree/admin/overview/_enterprises_hubs_tab.html.haml index 6cfd9c3bc5..cb177f9fb3 100644 --- a/app/views/spree/admin/overview/_enterprises_hubs_tab.html.haml +++ b/app/views/spree/admin/overview/_enterprises_hubs_tab.html.haml @@ -8,7 +8,7 @@ - if can? :admin, EnterpriseFee %span.centered.three.columns Enterprise Fees %div.sixteen.columns.alpha.list - - @enterprises.each do |enterprise| + - @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 diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index f661f87419..7ea81ea930 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -189,7 +189,6 @@ feature %q{ @enterprise.reload expect(@enterprise.owner).to eq user - #TODO fix so the sells field actually saves something page.should have_checked_field "enterprise_payment_method_ids_#{payment_method.id}" page.should have_checked_field "enterprise_shipping_method_ids_#{shipping_method.id}" page.should have_selector "a.list-item", text: enterprise_fee.name @@ -286,16 +285,12 @@ feature %q{ within("tr.enterprise-#{distributor1.id}") do expect(page).to have_content distributor1.name - # TODO expect sell= ? - # expect(page).to have_checked_field "enterprise_set_collection_attributes_0_is_distributor" expect(page).to have_unchecked_field "enterprise_set_collection_attributes_0_is_primary_producer" expect(page).to_not have_select "enterprise_set_collection_attributes_0_sells" end within("tr.enterprise-#{supplier1.id}") do expect(page).to have_content supplier1.name - # TODO expect sells= ? - # expect(page).to have_unchecked_field "enterprise_set_collection_attributes_1_is_distributor" expect(page).to have_checked_field "enterprise_set_collection_attributes_1_is_primary_producer" expect(page).to_not have_select "enterprise_set_collection_attributes_1_sells" end From ce9b132ab5cc44a937603857e1b247ec7ca736de Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 2 Oct 2014 13:10:46 +1000 Subject: [PATCH 030/142] only show visible enterprises --- .../javascripts/darkswarm/services/enterprises.js.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee index b5136dec35..2451c14739 100644 --- a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee @@ -2,7 +2,7 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer, new class Enterprises enterprises_by_id: {} # id/object pairs for lookup constructor: -> - @enterprises = enterprises + @enterprises = visibleFilter enterprises for enterprise in enterprises @enterprises_by_id[enterprise.id] = enterprise @dereferenceEnterprises() @@ -10,7 +10,6 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer, @producers = @enterprises.filter (enterprise)-> enterprise.is_primary_producer @hubs = @enterprises.filter (enterprise)-> - enterprise.is_distributor dereferenceEnterprises: -> From 1e84e4fa85bb9899802ea45c16a9ed8e108e918b Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 2 Oct 2014 13:11:19 +1000 Subject: [PATCH 031/142] own and any instead of single and full for abilities --- app/models/spree/ability_decorator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index 8dc0f95381..6da00753b6 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -23,7 +23,7 @@ class AbilityDecorator end def can_manage_orders?(user) - ( user.enterprises.map(&:type) & %w(single full) ).any? + ( user.enterprises.map(&:sells) & %w(own any) ).any? end def can_manage_relationships?(user) From f29898886d510bd77041df63c1015669555cab6d Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 2 Oct 2014 13:24:59 +1000 Subject: [PATCH 032/142] return basic css and js for oldskool login that somehow still exists --- app/assets/javascripts/store/all.js | 13 +++++++++++++ app/assets/stylesheets/store/all.css | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 app/assets/javascripts/store/all.js create mode 100644 app/assets/stylesheets/store/all.css diff --git a/app/assets/javascripts/store/all.js b/app/assets/javascripts/store/all.js new file mode 100644 index 0000000000..723f03af31 --- /dev/null +++ b/app/assets/javascripts/store/all.js @@ -0,0 +1,13 @@ +// This is a manifest file that'll be compiled into including all the files listed below. +// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically +// be included in the compiled file accessible from http://example.com/assets/application.js +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// the compiled file. +// + +//= require 'jquery' +//= require store/spree_core +//= require store/spree_auth +//= require store/spree_promo + +//= require_tree . diff --git a/app/assets/stylesheets/store/all.css b/app/assets/stylesheets/store/all.css new file mode 100644 index 0000000000..c1d3d851bc --- /dev/null +++ b/app/assets/stylesheets/store/all.css @@ -0,0 +1,13 @@ +/* + * This is a manifest file that'll automatically include all the stylesheets available in this directory + * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at + * the top of the compiled file, but it's generally better to create a new file per style scope. + * + + *= require store/spree_core + *= require store/spree_auth + *= require store/spree_promo + + *= require_self + *= require_tree . +*/ From 526ab8b80f88cce765e5a53caef7a6937261a06a Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 2 Oct 2014 16:28:01 +1000 Subject: [PATCH 033/142] use is_distributor bool --- app/views/admin/enterprises/_sidebar_payment_methods.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/enterprises/_sidebar_payment_methods.html.haml b/app/views/admin/enterprises/_sidebar_payment_methods.html.haml index 9b88dcdd13..8994c60be5 100644 --- a/app/views/admin/enterprises/_sidebar_payment_methods.html.haml +++ b/app/views/admin/enterprises/_sidebar_payment_methods.html.haml @@ -1,4 +1,4 @@ -.sidebar_item.four.columns.alpha#payment_methods{ ng: { show: 'Enterprise.sells != "none"' } } +.sidebar_item.four.columns.alpha#payment_methods{ ng: { show: 'Enterprise.is_distributor' } } .four.columns.alpha.header{ ng: { class: "paymentMethodsColor()" } } %span.four.columns.alpha.centered Payment Methods .four.columns.alpha.list{ ng: { class: "paymentMethodsColor()" } } From b3520c438560d4791ce15d4a4912760c2fc0c310 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 2 Oct 2014 16:49:32 +1000 Subject: [PATCH 034/142] Bugfix for specs --- .../admin/reports_controller_decorator.rb | 2 ++ app/models/spree/ability_decorator.rb | 20 +++++++++++++------ spec/factories.rb | 1 - spec/models/spree/ability_spec.rb | 11 +++++----- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index 0abfd783b5..f0fa2c592b 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -592,10 +592,12 @@ Spree::Admin::ReportsController.class_eval do private def load_data + # Load distributors either owned by the user or selling their enterprises products. my_distributors = Enterprise.is_distributor.managed_by(spree_current_user) my_suppliers = Enterprise.is_primary_producer.managed_by(spree_current_user) distributors_of_my_products = Enterprise.with_distributed_products_outer.merge(Spree::Product.in_any_supplier(my_suppliers)) @distributors = my_distributors | distributors_of_my_products + # Load suppliers either owned by the user or supplying products their enterprises distribute. suppliers_of_products_I_distribute = my_distributors.map { |d| Spree::Product.in_distributor(d) }.flatten.map(&:supplier).uniq @suppliers = my_suppliers | suppliers_of_products_I_distribute @order_cycles = OrderCycle.active_or_complete.accessible_by(spree_current_user).order('orders_close_at DESC') diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index 6da00753b6..c158e90993 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -1,6 +1,8 @@ class AbilityDecorator include CanCan::Ability + # All abilites are allocated from this initialiser, currently in 5 chunks. + # Spree also defines other abilities. def initialize(user) add_base_abilities user if is_new_user? user add_enterprise_management_abilities user if can_manage_enterprises? user @@ -9,19 +11,22 @@ class AbilityDecorator add_relationship_management_abilities user if can_manage_relationships? user end - + # New users have no enterprises. def is_new_user?(user) user.enterprises.blank? end + # Users can manage an enterprise if they have one. def can_manage_enterprises?(user) user.enterprises.present? end + # Users can manage products if they have an enterprise. def can_manage_products?(user) can_manage_enterprises? user end + # Users can manage orders if they have a sells own/any enterprise. def can_manage_orders?(user) ( user.enterprises.map(&:sells) & %w(own any) ).any? end @@ -30,6 +35,7 @@ class AbilityDecorator can_manage_enterprises? user end + # New users can create an enterprise, and gain other permissions from doing this. def add_base_abilities(user) can [:create], Enterprise end @@ -47,6 +53,12 @@ class AbilityDecorator can [:read, :edit, :update, :bulk_update], Enterprise do |enterprise| user.enterprises.include? enterprise end + + # All enterprises can have fees, though possibly suppliers don't need them? + can [:index, :create], EnterpriseFee + can [:admin, :read, :edit, :bulk_update, :destroy], EnterpriseFee do |enterprise_fee| + user.enterprises.include? enterprise_fee.enterprise + end end def add_product_management_abilities(user) @@ -66,6 +78,7 @@ class AbilityDecorator can [:admin, :index, :read, :search], Spree::Taxon can [:admin, :index, :read, :create, :edit], Spree::Classification + end def add_order_management_abilities(user) @@ -90,11 +103,6 @@ class AbilityDecorator end can [:for_order_cycle], Enterprise - can [:index, :create], EnterpriseFee - can [:admin, :read, :edit, :bulk_update, :destroy], EnterpriseFee do |enterprise_fee| - user.enterprises.include? enterprise_fee.enterprise - end - can [:admin, :index, :read, :create, :edit, :update], ExchangeVariant can [:admin, :index, :read, :create, :edit, :update], Exchange can [:admin, :index, :read, :create, :edit, :update], ExchangeFee diff --git a/spec/factories.rb b/spec/factories.rb index 63c733524e..f9c65eb7ff 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -93,7 +93,6 @@ FactoryGirl.define do owner { FactoryGirl.create :user } sequence(:name) { |n| "Enterprise #{n}" } sells 'any' - is_primary_producer false description 'enterprise' long_description '

Hello, world!

This is a paragraph.

' email 'enterprise@example.com' diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index 5ec2dc2190..4169222fa8 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -6,8 +6,7 @@ module Spree describe User do - # TODO work out what permissions are meant to be now... - pending "broad permissions" do + describe "broad permissions" do subject { AbilityDecorator.new(user) } let(:user) { create(:user) } let(:enterprise_any) { create(:enterprise, sells: 'any') } @@ -240,15 +239,15 @@ module Spree end end - context 'Order Cycle co-ordinator' do - + context 'Order Cycle co-ordinator, distributor enterprise manager' do let (:user) do user = create(:user) user.spree_roles = [] - s1.enterprise_roles.build(user: user).save + d1.enterprise_roles.build(user: user).save user end - let(:oc1) { create(:simple_order_cycle, {coordinator: s1}) } + + let(:oc1) { create(:simple_order_cycle, {coordinator: d1}) } let(:oc2) { create(:simple_order_cycle) } it "should be able to read/write OrderCycles they are the co-ordinator of" do From 7313aecd1908cd604a8110d7c00f55037edb3625 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 3 Oct 2014 12:19:58 +1000 Subject: [PATCH 035/142] add route checking, not working yet... --- .../enterprises/controllers/enterprise_controller.js.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee index c5b38191ba..959708e146 100644 --- a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee +++ b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee @@ -1,8 +1,10 @@ angular.module("admin.enterprises") - .controller "enterpriseCtrl", ($scope, Enterprise, PaymentMethods, ShippingMethods) -> + .controller "enterpriseCtrl", ($scope, $rootScope, Enterprise, PaymentMethods, ShippingMethods) -> $scope.Enterprise = Enterprise.enterprise $scope.PaymentMethods = PaymentMethods.paymentMethods $scope.ShippingMethods = ShippingMethods.shippingMethods + $scope.$on "$routeChangeStart", (event, newUrl, oldUrl) -> + event.preventDefault() for payment_method in $scope.PaymentMethods payment_method.selected = payment_method.id in $scope.Enterprise.payment_method_ids @@ -32,4 +34,4 @@ angular.module("admin.enterprises") $scope.ShippingMethods.reduce (count, shipping_method) -> count++ if shipping_method.selected count - , 0 \ No newline at end of file + , 0 From 8805079faa0ae5ccbebd8d6d43c4e0d3253ac3b3 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 3 Oct 2014 14:03:34 +1000 Subject: [PATCH 036/142] use attubutes instead of save! --- .../20140927005043_enterprise_config_refactor.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/migrate/20140927005043_enterprise_config_refactor.rb b/db/migrate/20140927005043_enterprise_config_refactor.rb index f7d120c469..3b3265333d 100644 --- a/db/migrate/20140927005043_enterprise_config_refactor.rb +++ b/db/migrate/20140927005043_enterprise_config_refactor.rb @@ -3,8 +3,7 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration add_column :enterprises, :sells, :string, null: false, default: 'none' Enterprise.all.each do |enterprise| - enterprise.sells = sells_what?(enterprise) - enterprise.save! + enterprise.update_attributes({:sells => sells_what?(enterprise)}) end remove_column :enterprises, :type @@ -17,9 +16,10 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration add_column :enterprises, :is_distributor, :boolean Enterprise.all.each do |enterprise| - enterprise.type = type?(enterprise) - enterprise.is_distributor = distributes?(enterprise) - enterprise.save! + enterprise.update_attributes({ + :type => type?(enterprise), + :is_distributor => distributes?(enterprise) + }) end remove_column :enterprises, :sells From 01063367c420ed4b7b540bd25eb5f1e7f507599e Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sat, 4 Oct 2014 00:59:17 +1000 Subject: [PATCH 037/142] clickable show profiles label --- app/views/shared/components/_show_profiles.html.haml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/shared/components/_show_profiles.html.haml b/app/views/shared/components/_show_profiles.html.haml index c2232c3555..6b714a1c6e 100644 --- a/app/views/shared/components/_show_profiles.html.haml +++ b/app/views/shared/components/_show_profiles.html.haml @@ -1,6 +1,7 @@ .small-12.medium-6.columns.text-right .profile-checkbox - %input{"ng-model" => "show_profiles", type: "checkbox", name: "profile"}>< - %label Show profiles - %button.button.secondary.tiny.help-btn.ng-scope{:popover => "Profiles do not have a shopfront on the Open Food Network, but may have their own physical or online shop elsewhere", "popover-placement" => "left"}>< + %button.button.secondary.tiny.help-btn.ng-scope{:popover => "Profiles do not have a shopfront on the Open Food Network, but may have their own physical or online shop elsewhere", "popover-placement" => "left"} %i.ofn-i_013-help + %label + %input{"ng-model" => "show_profiles", type: "checkbox", name: "profile"} + Show profiles From 2670d2b0adf1bc591bf5f33302412b5972bdc654 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sat, 4 Oct 2014 00:59:41 +1000 Subject: [PATCH 038/142] cleanup serializer --- app/serializers/api/enterprise_serializer.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index 4179dae44c..e23b4dd8fa 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -40,7 +40,6 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer "producer_hub" => "/assets/map_005-hub.svg", "producer_shop" => "/assets/map_003-producer-shop.svg", "producer" => "/assets/map_001-producer-only.svg", - "producer_profile" => "/assets/map_002-producer-only-profile.svg", } icons[object.enterprise_category] end @@ -53,7 +52,6 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer "producer_hub" => "ofn-i_063-hub", "producer_shop" => "ofn-i_059-producer", "producer" => "ofn-i_059-producer", - "producer_profile" => "ofn-i_060-producer-reversed", } icon_fonts[object.enterprise_category] end @@ -68,8 +66,6 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer "producer_hub" => "ofn-i_059-producer", "producer_shop" => "ofn-i_059-producer", "producer" => "ofn-i_059-producer", - "producer_profile" => "ofn-i_060-producer-reversed", - "empty" => "", } icon_fonts[object.enterprise_category] end From a552fb18da86f5ac36c25d6b180de64e4c8e7f23 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sat, 4 Oct 2014 01:00:02 +1000 Subject: [PATCH 039/142] style profile check --- app/assets/stylesheets/darkswarm/ui.css.sass | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/darkswarm/ui.css.sass b/app/assets/stylesheets/darkswarm/ui.css.sass index 3bbce61552..d18adae1b4 100644 --- a/app/assets/stylesheets/darkswarm/ui.css.sass +++ b/app/assets/stylesheets/darkswarm/ui.css.sass @@ -74,8 +74,10 @@ button.success, .button.success .profile-checkbox display: inline-block - input[type="checkbox"] + label + label margin: 0 0.2rem + float: right + // Responsive @media screen and (min-width: 768px) From b3482a087bfdaa50abee9e06e9d1775f9e1edf68 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sat, 4 Oct 2014 01:00:37 +1000 Subject: [PATCH 040/142] separate enterprises from visible enterprises --- .../darkswarm/services/enterprises.js.coffee | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee index 2451c14739..108be61879 100644 --- a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee @@ -2,15 +2,16 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer, new class Enterprises enterprises_by_id: {} # id/object pairs for lookup constructor: -> - @enterprises = visibleFilter enterprises + @enterprises = enterprises for enterprise in enterprises @enterprises_by_id[enterprise.id] = enterprise @dereferenceEnterprises() @dereferenceTaxons() - @producers = @enterprises.filter (enterprise)-> - enterprise.is_primary_producer - @hubs = @enterprises.filter (enterprise)-> - enterprise.is_distributor + @visible = visibleFilter @enterprises + @producers = @visible.filter (enterprise)-> + enterprise.enterprise_category in ["producer_hub", "producer_shop", "producer"] + @hubs = @visible.filter (enterprise)-> + enterprise.enterprise_category in ["hub", "hub_profile", "producer_hub", "producer_shop"] dereferenceEnterprises: -> if CurrentHub.hub?.id From 698126edb2186172a66b814a0fdac457487a3666 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sat, 4 Oct 2014 01:01:04 +1000 Subject: [PATCH 041/142] specifify visible enterprises in tests --- .../unit/darkswarm/services/enterprise_spec.js.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee index a38517293f..90774672d2 100644 --- a/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee @@ -5,9 +5,9 @@ describe "Enterprises service", -> {id: 1, name: "test"} ] enterprises = [ - {id: 1, is_distributor: true, is_primary_producer: false, producers: [{id: 2}], taxons: [{id: 1}]}, - {id: 2, is_distributor: false, is_primary_producer: true, hubs: [{id: 1}]}, - {id: 3, is_distributor: false, is_primary_producer: true, hubs: [{id: 1}]} + {id: 1, visible: true, is_distributor: true, is_primary_producer: false, producers: [{id: 2}], taxons: [{id: 1}]}, + {id: 2, visible: true, is_distributor: false, is_primary_producer: true, hubs: [{id: 1}]}, + {id: 3, visible: true, is_distributor: false, is_primary_producer: true, hubs: [{id: 1}]} ] beforeEach -> module 'Darkswarm' From 58c39b340d1e1a09624690f995e11ea576bb0f4b Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 5 Oct 2014 01:43:50 +1000 Subject: [PATCH 042/142] remove duplicate default value assignment --- .../darkswarm/controllers/enterprises_controller.js.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee index dc1218a14b..1e43c17465 100644 --- a/app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee @@ -9,7 +9,6 @@ Darkswarm.controller "EnterprisesCtrl", ($scope, Enterprises, Search, $document, $scope.activeTaxons = [] $scope.show_profiles = false $scope.filtersActive = false - $scope.show_profiles = false $scope.$watch "query", (query)-> Search.search query From 2f76a7ba801b4c59740e35e6bd41666f133d3321 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 5 Oct 2014 01:44:12 +1000 Subject: [PATCH 043/142] add comment for hub sells own case --- app/models/enterprise.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index fc14c80440..e20c06fa55 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -232,7 +232,7 @@ class Enterprise < ActiveRecord::Base when "non_producer_sells_any" "hub" # Hub selling others products in order cycles. when "non_producer_sells_own" - "hub" # Wholesaler selling through own shopfront? + "hub" # Wholesaler selling through own shopfront? Does this need a separate name? Should it exist? when "non_producer_sells_none" "hub_profile" # Hub selling outside the system. end From 9eb770aed79af1d9380185ba286c9d1e20a20c7b Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 5 Oct 2014 01:44:40 +1000 Subject: [PATCH 044/142] fix sidebar show/hide --- app/views/admin/enterprises/_sidebar_payment_methods.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/enterprises/_sidebar_payment_methods.html.haml b/app/views/admin/enterprises/_sidebar_payment_methods.html.haml index 8994c60be5..9b88dcdd13 100644 --- a/app/views/admin/enterprises/_sidebar_payment_methods.html.haml +++ b/app/views/admin/enterprises/_sidebar_payment_methods.html.haml @@ -1,4 +1,4 @@ -.sidebar_item.four.columns.alpha#payment_methods{ ng: { show: 'Enterprise.is_distributor' } } +.sidebar_item.four.columns.alpha#payment_methods{ ng: { show: 'Enterprise.sells != "none"' } } .four.columns.alpha.header{ ng: { class: "paymentMethodsColor()" } } %span.four.columns.alpha.centered Payment Methods .four.columns.alpha.list{ ng: { class: "paymentMethodsColor()" } } From 017d6b12738b454c8b83babc7934f6de0cc8bf33 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Mon, 6 Oct 2014 01:35:46 +1100 Subject: [PATCH 045/142] move for order cycles permission, for now, but needs review --- spec/models/spree/ability_spec.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index 4169222fa8..f9a1b9fcd3 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -239,7 +239,7 @@ module Spree end end - context 'Order Cycle co-ordinator, distributor enterprise manager' do + context 'Order Cycle co-ordinator, distriutor enterprise manager' do let (:user) do user = create(:user) user.spree_roles = [] @@ -265,6 +265,11 @@ module Spree it "should be able to read/write EnterpriseFees" do should have_ability([:admin, :index, :read, :create, :edit, :bulk_update, :destroy], for: EnterpriseFee) end + + #TODO clarify :for_order_cycle and its purpose - and possibly rename it. + it "should be able to do something with order cycles (??)" do + should have_ability([:for_order_cycle], Enterprise) + end end context 'enterprise manager' do @@ -284,7 +289,7 @@ module Spree end it 'should have the ability administrate and create enterpises' do - should have_ability([:admin, :index, :for_order_cycle, :create], for: Enterprise) + should have_ability([:admin, :index, :create], for: Enterprise) end end end From c495e967cb8782a703bd333cf8018a4576fd3f58 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Mon, 6 Oct 2014 01:36:18 +1100 Subject: [PATCH 046/142] bugfix and extend angular enterprise spec --- .../services/enterprise_spec.js.coffee | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee index 90774672d2..ff051b1d43 100644 --- a/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee @@ -5,10 +5,16 @@ describe "Enterprises service", -> {id: 1, name: "test"} ] enterprises = [ - {id: 1, visible: true, is_distributor: true, is_primary_producer: false, producers: [{id: 2}], taxons: [{id: 1}]}, - {id: 2, visible: true, is_distributor: false, is_primary_producer: true, hubs: [{id: 1}]}, - {id: 3, visible: true, is_distributor: false, is_primary_producer: true, hubs: [{id: 1}]} + {id: 1, visible: true, enterprise_category: "hub", producers: [{id: 5}], taxons: [{id: 1}]}, + {id: 2, visible: true, enterprise_category: "hub", producers: [{id: 6}]} + {id: 3, visible: true, enterprise_category: "hub_profile"} + {id: 4, visible: false, enterprise_category: "hub", producers: [{id: 7}]} + {id: 5, visible: true, enterprise_category: "producer_hub", hubs: [{id: 1}]}, + {id: 6, visible: true, enterprise_category: "producer_shop", hubs: [{id: 2}]}, + {id: 7, visible: true, enterprise_category: "producer", hubs: [{id: 2}]} + {id: 8, visible: false, enterprise_category: "producer", hubs: [{id: 2}]} ] + H1: 0 beforeEach -> module 'Darkswarm' module ($provide)-> @@ -31,8 +37,8 @@ describe "Enterprises service", -> expect(Enterprises.enterprises[0]).toBe Enterprises.enterprises_by_id["1"] it "dereferences references to other enterprises", -> - expect(Enterprises.enterprises_by_id["1"].producers[0]).toBe enterprises[1] - expect(Enterprises.enterprises_by_id["3"].hubs[0]).toBe enterprises[0] + expect(Enterprises.enterprises_by_id["1"].producers[0]).toBe enterprises[4] + expect(Enterprises.enterprises_by_id["5"].hubs[0]).toBe enterprises[0] it "dereferences taxons", -> expect(Enterprises.enterprises[0].taxons[0]).toBe taxons[0] @@ -44,5 +50,26 @@ describe "Enterprises service", -> Enterprises.enterprises[0].active = false expect(Enterprises.hubs[0].active).toBe false - it "delegates producers array to Enterprises", -> - expect(Enterprises.producers[0]).toBe enterprises[1] + it "filters Enterprises.producers into a new array", -> + expect(Enterprises.producers[0]).toBe Enterprises.enterprises[4] + Enterprises.enterprises[4].active = false + expect(Enterprises.producers[0].active).toBe false + + it "only includes visible enterprises in hubs array", -> + expect(Enterprises.hubs).toContain Enterprises.enterprises[0] + expect(Enterprises.hubs).not.toContain Enterprises.enterprises[3] + + it "only includes visible enterprises in producers array", -> + expect(Enterprises.producers).toContain Enterprises.enterprises[4] + expect(Enterprises.producers).not.toContain Enterprises.enterprises[7] + + it "includes hub, hub_profile, producer_hub and, producer_shop enterprises in hubs array", -> + expect(Enterprises.hubs).toContain Enterprises.enterprises[0] + expect(Enterprises.hubs).toContain Enterprises.enterprises[2] + expect(Enterprises.hubs).toContain Enterprises.enterprises[4] + expect(Enterprises.hubs).toContain Enterprises.enterprises[5] + + it "includes producer_hub, producer_shop and producer enterprises in producers array", -> + expect(Enterprises.producers).toContain Enterprises.enterprises[4] + expect(Enterprises.producers).toContain Enterprises.enterprises[5] + expect(Enterprises.producers).toContain Enterprises.enterprises[6] From 76e170eb3a8dc19a53313e3a02b4cff78f275acc Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Mon, 6 Oct 2014 10:44:49 +1100 Subject: [PATCH 047/142] move icons into cached, for now --- app/serializers/api/enterprise_serializer.rb | 102 +++++++++---------- 1 file changed, 48 insertions(+), 54 deletions(-) diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index e23b4dd8fa..892027c5a0 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -17,8 +17,6 @@ end class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer attributes :orders_close_at, :active - attributes :icon, :icon_font, :producer_icon_font, :has_hub_listing, :enterprise_category, :is_distributor - def orders_close_at OrderCycle.first_closing_for(object).andand.orders_close_at end @@ -27,9 +25,54 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer @options[:active_distributors].andand.include? object end - # Used to select enterprises for hub listing - def has_hub_listing - object.is_distributor || object.enterprise_category == "hub_profile" + +end + +class Api::CachedEnterpriseSerializer < ActiveModel::Serializer + cached + delegate :cache_key, to: :object + + attributes :name, :id, :description, :latitude, :longitude, + :long_description, :website, :instagram, :linkedin, :twitter, + :facebook, :is_primary_producer, :is_distributor, :phone, :visible, + :email, :hash, :logo, :promo_image, :path, :pickup, :delivery, + :icon, :icon_font, :producer_icon_font, :enterprise_category + + has_many :distributed_taxons, key: :taxons, serializer: Api::IdSerializer + has_many :supplied_taxons, serializer: Api::IdSerializer + has_many :distributors, key: :hubs, serializer: Api::IdSerializer + has_many :suppliers, key: :producers, serializer: Api::IdSerializer + + has_one :address, serializer: Api::AddressSerializer + + def pickup + object.shipping_methods.where(:require_ship_address => false).present? + end + + def delivery + object.shipping_methods.where(:require_ship_address => true).present? + end + + def email + object.email.to_s.reverse + end + + def hash + object.to_param + end + + def logo + object.logo(:medium) if object.logo.exists? + end + + def promo_image + object.promo_image(:large) if object.promo_image.exists? + end + + # TODO when ActiveSerializers supports URL helpers + # Then refactor. See readme https://github.com/rails-api/active_model_serializers + def path + "/enterprises/#{object.to_param}/shop" end # Map svg icons. @@ -69,53 +112,4 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer } icon_fonts[object.enterprise_category] end - -end - -class Api::CachedEnterpriseSerializer < ActiveModel::Serializer - cached - delegate :cache_key, to: :object - - attributes :name, :id, :description, :latitude, :longitude, - :long_description, :website, :instagram, :linkedin, :twitter, - :facebook, :is_primary_producer, :is_distributor, :phone, :visible, - :email, :hash, :logo, :promo_image, :path, - :pickup, :delivery - - has_many :distributed_taxons, key: :taxons, serializer: Api::IdSerializer - has_many :supplied_taxons, serializer: Api::IdSerializer - has_many :distributors, key: :hubs, serializer: Api::IdSerializer - has_many :suppliers, key: :producers, serializer: Api::IdSerializer - - has_one :address, serializer: Api::AddressSerializer - - def pickup - object.shipping_methods.where(:require_ship_address => false).present? - end - - def delivery - object.shipping_methods.where(:require_ship_address => true).present? - end - - def email - object.email.to_s.reverse - end - - def hash - object.to_param - end - - def logo - object.logo(:medium) if object.logo.exists? - end - - def promo_image - object.promo_image(:large) if object.promo_image.exists? - end - - # TODO when ActiveSerializers supports URL helpers - # Then refactor. See readme https://github.com/rails-api/active_model_serializers - def path - "/enterprises/#{object.to_param}/shop" - end end From cc6af82823d35030a6f402106a5f037ea6cbfec7 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Mon, 6 Oct 2014 15:40:41 +1100 Subject: [PATCH 048/142] move reports abilitiy to can manage products block, producers need to use this too --- app/models/spree/ability_decorator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index c158e90993..a5d5f8be33 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -79,6 +79,8 @@ class AbilityDecorator can [:admin, :index, :read, :search], Spree::Taxon can [:admin, :index, :read, :create, :edit], Spree::Classification + # Reports page + can [:admin, :index, :customers, :orders_and_distributors, :group_buys, :bulk_coop, :payments, :orders_and_fulfillment, :products_and_inventory], :report end def add_order_management_abilities(user) @@ -118,8 +120,6 @@ class AbilityDecorator (user.enterprises & shipping_method.distributors).any? end - # Reports page - can [:admin, :index, :customers, :orders_and_distributors, :group_buys, :bulk_coop, :payments, :orders_and_fulfillment, :products_and_inventory], :report end From 922e335e836ac481b3006f60513f635c6ec6fa37 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Mon, 6 Oct 2014 15:42:23 +1100 Subject: [PATCH 049/142] add is_hub to model --- app/models/enterprise.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index e20c06fa55..5f36aec8f0 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -214,6 +214,10 @@ class Enterprise < ActiveRecord::Base not self.sells == "none" end + def is_hub + self.enterprise_category.in Array['hub', 'hub_profile', 'producer_hub', 'producer_shop'] + end + # Simplify enterprise categories for frontend logic and icons, and maybe other things. def enterprise_category # Make this crazy logic human readable so we can argue about it sanely. From 2ae325455a60bd268970e14cd5f0b0bf9c8ce756 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Mon, 6 Oct 2014 22:58:48 +1100 Subject: [PATCH 050/142] fix producer taxon filtering bug --- .../javascripts/darkswarm/filters/taxons.js.coffee | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/darkswarm/filters/taxons.js.coffee b/app/assets/javascripts/darkswarm/filters/taxons.js.coffee index 3eb32ce1a4..a7ccc9b0cc 100644 --- a/app/assets/javascripts/darkswarm/filters/taxons.js.coffee +++ b/app/assets/javascripts/darkswarm/filters/taxons.js.coffee @@ -1,13 +1,16 @@ -Darkswarm.filter 'taxons', (Matcher)-> - # Filter anything that responds to object.taxons, and/or object.primary_taxon +Darkswarm.filter 'taxons', ()-> + # Filter anything that responds to object.taxons, object.supplied_taxon or object.primary_taxon. (objects, ids) -> objects ||= [] ids ?= [] if ids.length == 0 + # No taxons selected, pass all objects through. objects else objects.filter (obj)-> taxons = obj.taxons - taxons.concat obj.supplied_taxons if obj.supplied_taxons + # Combine object taxons with supplied taxons, if they exist. + taxons = taxons.concat obj.supplied_taxons if obj.supplied_taxons + # Match primary taxon if it exists, then taxon array. obj.primary_taxon?.id in ids || taxons.some (taxon)-> taxon.id in ids From 881e82e825d6474b0cf265dc644f3501f4b41509 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Mon, 6 Oct 2014 22:59:06 +1100 Subject: [PATCH 051/142] add some angular documentation --- .../admin/enterprises/services/enterprise.js.coffee | 3 ++- .../darkswarm/filters/capitalize.js.coffee | 3 ++- .../darkswarm/filters/localize_currency.js.coffee | 11 +++++------ .../darkswarm/filters/search_enterprises.js.coffee | 1 + ...rofiles.js.coffee => show_hub_profiles.js.coffee} | 5 +++-- .../darkswarm/services/enterprise_modal.js.coffee | 1 + .../darkswarm/services/enterprises.js.coffee | 12 ++++++++---- .../javascripts/darkswarm/services/matcher.js.coffee | 11 ++++++----- .../javascripts/darkswarm/services/taxons.js.coffee | 3 ++- .../components/_enterprise_no_results.html.haml | 5 +++++ .../shared/components/_enterprise_search.html.haml | 7 +++++++ 11 files changed, 42 insertions(+), 20 deletions(-) rename app/assets/javascripts/darkswarm/filters/{show_profiles.js.coffee => show_hub_profiles.js.coffee} (55%) create mode 100644 app/views/shared/components/_enterprise_no_results.html.haml create mode 100644 app/views/shared/components/_enterprise_search.html.haml diff --git a/app/assets/javascripts/admin/enterprises/services/enterprise.js.coffee b/app/assets/javascripts/admin/enterprises/services/enterprise.js.coffee index b6e6a6147e..26061ef720 100644 --- a/app/assets/javascripts/admin/enterprises/services/enterprise.js.coffee +++ b/app/assets/javascripts/admin/enterprises/services/enterprise.js.coffee @@ -1,4 +1,5 @@ angular.module("admin.enterprises") + # Populate Enterprise.enterprise with enterprise json array from the page. .factory 'Enterprise', (enterprise) -> new class Enterprise - enterprise: enterprise \ No newline at end of file + enterprise: enterprise diff --git a/app/assets/javascripts/darkswarm/filters/capitalize.js.coffee b/app/assets/javascripts/darkswarm/filters/capitalize.js.coffee index acbd3fd637..5c2272135b 100644 --- a/app/assets/javascripts/darkswarm/filters/capitalize.js.coffee +++ b/app/assets/javascripts/darkswarm/filters/capitalize.js.coffee @@ -1,4 +1,5 @@ Darkswarm.filter "capitalize", -> + # Convert to basic sentence case. (input, scope) -> - input = input.toLowerCase() if input? + input = input.toLowerCase() if input? input.substring(0, 1).toUpperCase() + input.substring(1) diff --git a/app/assets/javascripts/darkswarm/filters/localize_currency.js.coffee b/app/assets/javascripts/darkswarm/filters/localize_currency.js.coffee index ffa98c5a33..7087e09fc3 100644 --- a/app/assets/javascripts/darkswarm/filters/localize_currency.js.coffee +++ b/app/assets/javascripts/darkswarm/filters/localize_currency.js.coffee @@ -1,15 +1,14 @@ -# Convert number to string currency using injected currency configuration. -# -# @requires currencyConfig json - /app/serializers/api/currency_config_serializer.rb -# @return: string Darkswarm.filter "localizeCurrency", (currencyConfig)-> + # Convert number to string currency using injected currency configuration. (amount) -> + # Set country code (eg. "US"). currency_code = if currencyConfig.display_currency then " " + currencyConfig.currency else "" + # Set decimal points, 2 or 0 if hide_cents. decimals = if currencyConfig.hide_cents == "true" then 0 else 2 - # We need to use parseFloat before toFixed as the amount should be a passed in as a string. + # We need to use parseFloat before toFixed as the amount should come in as a string. amount_fixed = parseFloat(amount).toFixed(decimals) - # Build the final price string. + # Build the final price string. TODO use spree decimal point and spacer character settings. if currencyConfig.symbol_position == 'before' currencyConfig.symbol + amount_fixed + currency_code else diff --git a/app/assets/javascripts/darkswarm/filters/search_enterprises.js.coffee b/app/assets/javascripts/darkswarm/filters/search_enterprises.js.coffee index 20d0fd91c9..2c42fe93d3 100644 --- a/app/assets/javascripts/darkswarm/filters/search_enterprises.js.coffee +++ b/app/assets/javascripts/darkswarm/filters/search_enterprises.js.coffee @@ -1,4 +1,5 @@ Darkswarm.filter 'searchEnterprises', (Matcher)-> + # Search multiple fields of enterprises for matching text fragment. (enterprises, text) -> enterprises ||= [] text ?= "" diff --git a/app/assets/javascripts/darkswarm/filters/show_profiles.js.coffee b/app/assets/javascripts/darkswarm/filters/show_hub_profiles.js.coffee similarity index 55% rename from app/assets/javascripts/darkswarm/filters/show_profiles.js.coffee rename to app/assets/javascripts/darkswarm/filters/show_hub_profiles.js.coffee index b76dc8373e..b97a0c35e4 100644 --- a/app/assets/javascripts/darkswarm/filters/show_profiles.js.coffee +++ b/app/assets/javascripts/darkswarm/filters/show_hub_profiles.js.coffee @@ -1,7 +1,8 @@ -Darkswarm.filter 'showProfiles', ()-> +Darkswarm.filter 'showHubProfiles', ()-> + # Filter hub_profile enterprises in or out. (enterprises, show_profiles) -> enterprises ||= [] - show_profiles ?= true + show_profiles ?= false enterprises.filter (enterprise)=> show_profiles or enterprise.is_distributor diff --git a/app/assets/javascripts/darkswarm/services/enterprise_modal.js.coffee b/app/assets/javascripts/darkswarm/services/enterprise_modal.js.coffee index 1cd0727cd8..a0fb3ce5c5 100644 --- a/app/assets/javascripts/darkswarm/services/enterprise_modal.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprise_modal.js.coffee @@ -1,4 +1,5 @@ Darkswarm.factory "EnterpriseModal", ($modal, $rootScope)-> + # Build a modal popup for an enterprise. new class EnterpriseModal open: (enterprise)-> scope = $rootScope.$new(true) # Spawn an isolate to contain the enterprise diff --git a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee index 108be61879..e6a8c621dd 100644 --- a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee @@ -1,16 +1,20 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer, visibleFilter)-> new class Enterprises - enterprises_by_id: {} # id/object pairs for lookup + enterprises_by_id: {} constructor: -> + # Populate Enterprises.enterprises from json in page. @enterprises = enterprises + # Map enterprises to id/object pairs for lookup. for enterprise in enterprises @enterprises_by_id[enterprise.id] = enterprise + # Replace enterprise and taxons ids with actual objects. @dereferenceEnterprises() @dereferenceTaxons() - @visible = visibleFilter @enterprises - @producers = @visible.filter (enterprise)-> + # Remove non-visible enterprises. + @visible_enterprises = visibleFilter @enterprises + @producers = @visible_enterprises.filter (enterprise)-> enterprise.enterprise_category in ["producer_hub", "producer_shop", "producer"] - @hubs = @visible.filter (enterprise)-> + @hubs = @visible_enterprises.filter (enterprise)-> enterprise.enterprise_category in ["hub", "hub_profile", "producer_hub", "producer_shop"] dereferenceEnterprises: -> diff --git a/app/assets/javascripts/darkswarm/services/matcher.js.coffee b/app/assets/javascripts/darkswarm/services/matcher.js.coffee index aadd6a4128..9360afdd1f 100644 --- a/app/assets/javascripts/darkswarm/services/matcher.js.coffee +++ b/app/assets/javascripts/darkswarm/services/matcher.js.coffee @@ -1,6 +1,7 @@ Darkswarm.factory "Matcher", -> - new class Matcher - match: (properties, text)-> - properties.some (prop)-> - prop ||= "" - prop.toLowerCase().indexOf(text.toLowerCase()) != -1 + # Match text fragment in an array of strings. + new class Matcher + match: (properties, text)-> + properties.some (prop)-> + prop ||= "" + prop.toLowerCase().indexOf(text.toLowerCase()) != -1 diff --git a/app/assets/javascripts/darkswarm/services/taxons.js.coffee b/app/assets/javascripts/darkswarm/services/taxons.js.coffee index cbe6c118e0..72ccc4078a 100644 --- a/app/assets/javascripts/darkswarm/services/taxons.js.coffee +++ b/app/assets/javascripts/darkswarm/services/taxons.js.coffee @@ -1,8 +1,9 @@ Darkswarm.factory "Taxons", (taxons)-> new class Taxons - taxons: taxons + taxons: taxons taxons_by_id: {} constructor: -> + # Map taxons to id/object pairs for lookup. for taxon in @taxons @taxons_by_id[taxon.id] = taxon diff --git a/app/views/shared/components/_enterprise_no_results.html.haml b/app/views/shared/components/_enterprise_no_results.html.haml new file mode 100644 index 0000000000..2e6edd0875 --- /dev/null +++ b/app/views/shared/components/_enterprise_no_results.html.haml @@ -0,0 +1,5 @@ +%producer.row{"ng-show" => "filteredEnterprises.length == 0"} + %p.no-results + Sorry, no results found for + %strong {{query}}. + Try another search? diff --git a/app/views/shared/components/_enterprise_search.html.haml b/app/views/shared/components/_enterprise_search.html.haml new file mode 100644 index 0000000000..0ccb23220c --- /dev/null +++ b/app/views/shared/components/_enterprise_search.html.haml @@ -0,0 +1,7 @@ +#active-table-search.row + .small-12.columns + %input{type: :text, + "ng-model" => "query", + placeholder: "Search by name or suburb...", + "ng-debounce" => "150", + "ofn-disable-enter" => true} From 7805d46743d6f6c17c09406a0e37771b7fa32974 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Mon, 6 Oct 2014 23:20:43 +1100 Subject: [PATCH 052/142] more angular documentation --- .../darkswarm/controllers/tabs/producers_controller.js.coffee | 3 ++- .../javascripts/darkswarm/services/current_hub.js.coffee | 3 ++- .../javascripts/darkswarm/services/current_order.js.coffee | 1 + .../javascripts/darkswarm/services/enterprises.js.coffee | 1 - app/assets/javascripts/darkswarm/services/taxons.js.coffee | 1 + app/assets/javascripts/darkswarm/services/variants.js.coffee | 2 ++ 6 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/darkswarm/controllers/tabs/producers_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/tabs/producers_controller.js.coffee index 6db73f7af3..f397adc80f 100644 --- a/app/assets/javascripts/darkswarm/controllers/tabs/producers_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/tabs/producers_controller.js.coffee @@ -1,3 +1,4 @@ Darkswarm.controller "ProducersTabCtrl", ($scope, CurrentHub, Enterprises) -> - # Injecting Enterprises so CurrentHub.producers is dereferenced + # Injecting Enterprises so CurrentHub.producers is dereferenced. + # We should probably dereference here instead and separate out CurrentHub dereferencing from the Enterprise factory. $scope.CurrentHub = CurrentHub diff --git a/app/assets/javascripts/darkswarm/services/current_hub.js.coffee b/app/assets/javascripts/darkswarm/services/current_hub.js.coffee index 5e6a385b8a..ade8d75d18 100644 --- a/app/assets/javascripts/darkswarm/services/current_hub.js.coffee +++ b/app/assets/javascripts/darkswarm/services/current_hub.js.coffee @@ -1,3 +1,4 @@ -Darkswarm.factory 'CurrentHub', ($location, $filter, currentHub) -> +Darkswarm.factory 'CurrentHub', (currentHub) -> + # Populate CurrentHub.hub from json in page. This is probably redundant now. new class CurrentHub hub: currentHub diff --git a/app/assets/javascripts/darkswarm/services/current_order.js.coffee b/app/assets/javascripts/darkswarm/services/current_order.js.coffee index cd2402f0c0..6570ddcd06 100644 --- a/app/assets/javascripts/darkswarm/services/current_order.js.coffee +++ b/app/assets/javascripts/darkswarm/services/current_order.js.coffee @@ -1,3 +1,4 @@ Darkswarm.factory 'CurrentOrder', (currentOrder) -> + # Populate Currentorder.order from json in page. This is probably redundant now. new class CurrentOrder order: currentOrder diff --git a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee index e6a8c621dd..7e6aa0a1c7 100644 --- a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee @@ -10,7 +10,6 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer, # Replace enterprise and taxons ids with actual objects. @dereferenceEnterprises() @dereferenceTaxons() - # Remove non-visible enterprises. @visible_enterprises = visibleFilter @enterprises @producers = @visible_enterprises.filter (enterprise)-> enterprise.enterprise_category in ["producer_hub", "producer_shop", "producer"] diff --git a/app/assets/javascripts/darkswarm/services/taxons.js.coffee b/app/assets/javascripts/darkswarm/services/taxons.js.coffee index 72ccc4078a..984eb0df22 100644 --- a/app/assets/javascripts/darkswarm/services/taxons.js.coffee +++ b/app/assets/javascripts/darkswarm/services/taxons.js.coffee @@ -1,5 +1,6 @@ Darkswarm.factory "Taxons", (taxons)-> new class Taxons + # Populate Taxons.taxons from json in page. taxons: taxons taxons_by_id: {} constructor: -> diff --git a/app/assets/javascripts/darkswarm/services/variants.js.coffee b/app/assets/javascripts/darkswarm/services/variants.js.coffee index bc2050e4d4..1b87be5369 100644 --- a/app/assets/javascripts/darkswarm/services/variants.js.coffee +++ b/app/assets/javascripts/darkswarm/services/variants.js.coffee @@ -5,6 +5,8 @@ Darkswarm.factory 'Variants', -> @variants[variant.id] ||= @extend variant extend: (variant)-> + # Add totalPrice and basPricePercentage methods to calculate line item values. + # This should probably be on a line item object! variant.totalPrice = -> variant.price_with_fees * variant.line_item.quantity variant.basePricePercentage = Math.round(variant.price / variant.price_with_fees * 100) From ec6805f573d5e010655532c065c697b3d2b2554d Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Mon, 6 Oct 2014 23:51:19 +1100 Subject: [PATCH 053/142] use shared partial for no results --- app/views/home/_hubs.html.haml | 18 +++--------------- app/views/producers/index.html.haml | 22 +++------------------- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/app/views/home/_hubs.html.haml b/app/views/home/_hubs.html.haml index c034747a7b..27aea75a7f 100644 --- a/app/views/home/_hubs.html.haml +++ b/app/views/home/_hubs.html.haml @@ -4,20 +4,13 @@ .small-12.columns %h1 Shop in your local area - #active-table-search.row.pad-top - .small-12.columns - %input{type: :text, - "ng-model" => "query", - placeholder: "Search by name or suburb...", - "ng-debounce" => "150", - "ofn-disable-enter" => true} - + = render partial: "shared/components/enterprise_search" = render partial: "home/filters" .row{bindonce: true} .small-12.columns .active_table - %hub.active_table_node.row.animate-repeat{"ng-repeat" => "hub in hubs = (Enterprises.hubs | searchEnterprises:query | taxons:activeTaxons | shipping:shippingTypes | showProfiles:show_profiles | orderBy:['-active', '+orders_close_at'])", + %hub.active_table_node.row.animate-repeat{"ng-repeat" => "hub in filteredEnterprises = (Enterprises.hubs | searchEnterprises:query | taxons:activeTaxons | shipping:shippingTypes | showHubProfiles:show_profiles | orderBy:['-active', '+orders_close_at'])", "ng-class" => "{'is_profile' : !hub.is_distributor, 'closed' : !open(), 'open' : open(), 'inactive' : !hub.active, 'current' : current()}", "scroll-after-load" => true, "ng-controller" => "HubNodeCtrl", @@ -26,9 +19,4 @@ = render partial: 'home/skinny' = render partial: 'home/fat' - .row{"ng-show" => "hubs.length == 0"} - .columns.small-12 - %p.no-results - Sorry, no results found for - %strong {{query}}. - Try another search? + = render partial: 'shared/components/enterprise_no_results' diff --git a/app/views/producers/index.html.haml b/app/views/producers/index.html.haml index cf5bd4bed9..114e7d8459 100644 --- a/app/views/producers/index.html.haml +++ b/app/views/producers/index.html.haml @@ -3,20 +3,8 @@ .row .small-12.columns.pad-top %h1 Find local producers - / %div - / Find a - / %ofn-modal{title: "producer"} - / = render partial: "modals/producers" - / from the list below: - - #active-table-search.row - .small-12.columns - %input.animate-show{type: :text, - "ng-model" => "query", - placeholder: "Search by producer or suburb...", - "ng-debounce" => "150", - "ofn-disable-enter" => true} + = render partial: "shared/components/enterprise_search" = render partial: "producers/filters" .row{bindonce: true} @@ -24,7 +12,7 @@ .active_table %producer.active_table_node.row.animate-repeat{id: "{{producer.path}}", "scroll-after-load" => true, - "ng-repeat" => "producer in producers = (Enterprises.producers | searchEnterprises:query | taxons:activeTaxons)", + "ng-repeat" => "producer in filteredEnterprises = (Enterprises.producers | searchEnterprises:query | taxons:activeTaxons)", "ng-controller" => "ProducerNodeCtrl", "ng-class" => "{'closed' : !open(), 'open' : open(), 'inactive' : !producer.active}", id: "{{producer.hash}}"} @@ -33,10 +21,6 @@ = render partial: 'producers/skinny' = render partial: 'producers/fat' - %producer.row{"ng-show" => "producers.length == 0"} - %p.no-results - Sorry, no results found for - %strong {{query}}. - Try another search? + = render partial: 'shared/components/enterprise_no_results' = render partial: "shared/footer" From e476324c604cc57fa0f90b905da5e85c2ec2a483 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Tue, 7 Oct 2014 00:22:45 +1100 Subject: [PATCH 054/142] fix for_order_cycle test --- spec/models/spree/ability_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index f9a1b9fcd3..5920a66f3c 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -268,7 +268,7 @@ module Spree #TODO clarify :for_order_cycle and its purpose - and possibly rename it. it "should be able to do something with order cycles (??)" do - should have_ability([:for_order_cycle], Enterprise) + should have_ability([:admin, :index, :for_order_cycle, :create], for: Enterprise) end end From 6fc36a3e6c2f28d87dbf2aa2c67003cb0c4e97a4 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Tue, 7 Oct 2014 10:48:04 +1100 Subject: [PATCH 055/142] swap redundant producer modal for general enterprise modal --- app/views/modals/_producer.html.haml | 56 ------------------- .../shopping_shared/_producers.html.haml | 5 +- 2 files changed, 3 insertions(+), 58 deletions(-) delete mode 100644 app/views/modals/_producer.html.haml diff --git a/app/views/modals/_producer.html.haml b/app/views/modals/_producer.html.haml deleted file mode 100644 index 51a45cfe5f..0000000000 --- a/app/views/modals/_producer.html.haml +++ /dev/null @@ -1,56 +0,0 @@ -%ofn-modal{title: "{{enterprise.name}}"} - .highlight - .highlight-top - %p.right - {{ [enterprise.address.city, enterprise.address.state_name] | printArray}} - %h3 - %i.ofn-i_036-producers - {{ enterprise.name }} - %img.hero-img{"ng-src" => "{{enterprise.promo_image}}"} - - .row{bindonce: true} - .small-12.large-8.columns - %div{"ng-show" => "enterprise.long_description.length > 0 || enterprise.logo"} - %p.modal-header About - .about-container - %img.enterprise-logo{"bo-src" => "enterprise.logo", "bo-if" => "enterprise.logo"} - %p.text-small{"ng-bind-html" => "enterprise.long_description"} - - .small-12.large-4.columns - %div.modal-centered{"bo-if" => "enterprise.email || enterprise.website || enterprise.phone"} - %p.modal-header Contact - %p{"bo-if" => "enterprise.phone"} - {{ enterprise.phone }} - - %p{"bo-if" => "enterprise.email"} - %a{"ng-href" => "{{enterprise.email | stripUrl}}", target: "_blank", mailto: true } - %span.email - {{ enterprise.email | stripUrl }} - - %p{"bo-show" => "enterprise.website"} - %a{"ng-href" => "http://{{enterprise.website}}", target: "_blank" } - {{ enterprise.website | stripUrl }} - - %div.modal-centered{"bo-if" => "enterprise.twitter || enterprise.facebook || enterprise.linkedin || enterprise.instagram"} - %p.modal-header Follow - .follow-icons{bindonce: true} - %span{"bo-show" => "enterprise.twitter"} - %a{"ng-href" => "http://twitter.com/{{enterprise.twitter}}", target: "_blank"} - %i.ofn-i_041-twitter - - %span{"bo-show" => "enterprise.facebook"} - %a{"ng-href" => "http://{{enterprise.facebook | stripUrl}}", target: "_blank"} - %i.ofn-i_044-facebook - - %span{"bo-show" => "enterprise.linkedin"} - %a{"ng-href" => "http://{{enterprise.linkedin | stripUrl}}", target: "_blank"} - %i.ofn-i_042-linkedin - - %span{"bo-show" => "enterprise.instagram"} - %a{"ng-href" => "http://instagram.com/{{enterprise.instagram}}", target: "_blank"} - %i.ofn-i_043-instagram - - %a.close-reveal-modal{"ng-click" => "$close()"} - %i.ofn-i_009-close - - diff --git a/app/views/shopping_shared/_producers.html.haml b/app/views/shopping_shared/_producers.html.haml index d6ff09be4c..25c0c0599d 100644 --- a/app/views/shopping_shared/_producers.html.haml +++ b/app/views/shopping_shared/_producers.html.haml @@ -4,5 +4,6 @@ %h5 {{CurrentHub.hub.name}}'s producers: %ul.small-block-grid-2.large-block-grid-4 %li{"ng-repeat" => "enterprise in CurrentHub.hub.producers"} - %i.ofn-i_036-producers - = render partial: "modals/producer" + %enterprise-modal + %i.ofn-i_036-producers + {{ enterprise.name }} From 9b6db2bff48aa4162724eed27cc713cfe65ac744 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Tue, 7 Oct 2014 10:49:17 +1100 Subject: [PATCH 056/142] simplify tab selection --- .../controllers/tabs/producers_controller.js.coffee | 2 +- .../darkswarm/controllers/tabs_controller.js.coffee | 13 +++---------- app/views/shopping_shared/_tabs.html.haml | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/darkswarm/controllers/tabs/producers_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/tabs/producers_controller.js.coffee index f397adc80f..7a5ebb78f3 100644 --- a/app/assets/javascripts/darkswarm/controllers/tabs/producers_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/tabs/producers_controller.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.controller "ProducersTabCtrl", ($scope, CurrentHub, Enterprises) -> +Darkswarm.controller "ProducersTabCtrl", ($scope, CurrentHub, Enterprises, EnterpriseModal) -> # Injecting Enterprises so CurrentHub.producers is dereferenced. # We should probably dereference here instead and separate out CurrentHub dereferencing from the Enterprise factory. $scope.CurrentHub = CurrentHub diff --git a/app/assets/javascripts/darkswarm/controllers/tabs_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/tabs_controller.js.coffee index eb501bcb4a..70522d0d1b 100644 --- a/app/assets/javascripts/darkswarm/controllers/tabs_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/tabs_controller.js.coffee @@ -1,16 +1,9 @@ Darkswarm.controller "TabsCtrl", ($scope, $rootScope, $location, OrderCycle) -> + # Return active if supplied path matches url hash path. $scope.active = (path)-> - if !OrderCycle.selected() and $location.hash() == "" and path == "about" - true - else - $location.hash() == path - - - $scope.tabs = ["contact", "about", "groups", "producers"] - for tab in $scope.tabs - $scope[tab] = - path: tab + $location.hash() == path + # Toggle tab selected status by setting the url hash path. $scope.select = (tab)-> if $scope.active(tab.path) $location.hash "" diff --git a/app/views/shopping_shared/_tabs.html.haml b/app/views/shopping_shared/_tabs.html.haml index 7a78a191b6..acb3481fcc 100644 --- a/app/views/shopping_shared/_tabs.html.haml +++ b/app/views/shopping_shared/_tabs.html.haml @@ -9,6 +9,6 @@ %tab{heading: heading, id: "tab_#{name}", - active: "active(#{name}.path)", + active: "active(\'#{name}\')", select: "select(#{name})"} = render "shopping_shared/#{name}" From e7b847542fa49dac112fd30c6039c5c76e206156 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Wed, 8 Oct 2014 00:05:55 +1100 Subject: [PATCH 057/142] bugfix tab selection --- .../darkswarm/controllers/tabs_controller.js.coffee | 6 +++--- app/views/shopping_shared/_tabs.html.haml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/darkswarm/controllers/tabs_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/tabs_controller.js.coffee index 70522d0d1b..0bbe0bbd23 100644 --- a/app/assets/javascripts/darkswarm/controllers/tabs_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/tabs_controller.js.coffee @@ -4,8 +4,8 @@ Darkswarm.controller "TabsCtrl", ($scope, $rootScope, $location, OrderCycle) -> $location.hash() == path # Toggle tab selected status by setting the url hash path. - $scope.select = (tab)-> - if $scope.active(tab.path) + $scope.select = (path)-> + if $scope.active(path) $location.hash "" else - $location.hash tab.path + $location.hash path diff --git a/app/views/shopping_shared/_tabs.html.haml b/app/views/shopping_shared/_tabs.html.haml index acb3481fcc..c19ec56755 100644 --- a/app/views/shopping_shared/_tabs.html.haml +++ b/app/views/shopping_shared/_tabs.html.haml @@ -1,14 +1,14 @@ #tabs{"ng-controller" => "TabsCtrl"} .row %tabset.small-12.columns - // WILL can we add some logic here to make the distributor name not appear at small sizes? e.g. add a class?) + -# Build all tabs. - for name, heading in { about: "About #{current_distributor.name}", producers: "Producers", groups: "Groups", contact: "Contact"} - + -# tabs take tab path in 'active' and 'select' functions defined in TabsCtrl. %tab{heading: heading, id: "tab_#{name}", active: "active(\'#{name}\')", - select: "select(#{name})"} + select: "select(\'#{name}\')"} = render "shopping_shared/#{name}" From 83f9867632c85a2ba5ad0f19b6e636816806213d Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 9 Oct 2014 13:15:19 +1100 Subject: [PATCH 058/142] Move registration login into own folder, reinstate ofn-inline-alert --- .../{ => registration}/registration_controller.js.coffee | 0 .../{ => registration}/registration_form_controller.js.coffee | 0 .../directives/{inline_flash.js.coffee => inline_alert.js.coffee} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename app/assets/javascripts/darkswarm/controllers/{ => registration}/registration_controller.js.coffee (100%) rename app/assets/javascripts/darkswarm/controllers/{ => registration}/registration_form_controller.js.coffee (100%) rename app/assets/javascripts/darkswarm/directives/{inline_flash.js.coffee => inline_alert.js.coffee} (100%) diff --git a/app/assets/javascripts/darkswarm/controllers/registration_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/registration/registration_controller.js.coffee similarity index 100% rename from app/assets/javascripts/darkswarm/controllers/registration_controller.js.coffee rename to app/assets/javascripts/darkswarm/controllers/registration/registration_controller.js.coffee diff --git a/app/assets/javascripts/darkswarm/controllers/registration_form_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee similarity index 100% rename from app/assets/javascripts/darkswarm/controllers/registration_form_controller.js.coffee rename to app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee diff --git a/app/assets/javascripts/darkswarm/directives/inline_flash.js.coffee b/app/assets/javascripts/darkswarm/directives/inline_alert.js.coffee similarity index 100% rename from app/assets/javascripts/darkswarm/directives/inline_flash.js.coffee rename to app/assets/javascripts/darkswarm/directives/inline_alert.js.coffee From 49c8e2f8cba89f0207b7d24a78178bf7bddda713 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 9 Oct 2014 13:16:09 +1100 Subject: [PATCH 059/142] Remove used styling for inline flash --- .../darkswarm/registration.css.sass | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/app/assets/stylesheets/darkswarm/registration.css.sass b/app/assets/stylesheets/darkswarm/registration.css.sass index 3261fc0fd4..547f834406 100644 --- a/app/assets/stylesheets/darkswarm/registration.css.sass +++ b/app/assets/stylesheets/darkswarm/registration.css.sass @@ -16,24 +16,6 @@ .buttons - ofn-inline-flash - display: block - padding: 15px - position: relative - margin-bottom: 10px - &.brick - background-color: $clr-brick-light - border: 2px solid $clr-brick - color: $clr-brick - &.turquoise - background-color: $clr-turquoise-light - border: 2px solid $clr-turquoise - color: $clr-turquoise - .close-button - position: absolute - top: 0px - right: 0px - .field margin-bottom: 15px From 31c4aad9e167ef5241d7df1e80a66b4083f25399 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 9 Oct 2014 13:21:30 +1100 Subject: [PATCH 060/142] JS for closing alerts works --- .../darkswarm/directives/inline_alert.js.coffee | 13 +++++++------ .../templates/registration/about.html.haml | 9 ++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/darkswarm/directives/inline_alert.js.coffee b/app/assets/javascripts/darkswarm/directives/inline_alert.js.coffee index 46550b854f..9b37934375 100644 --- a/app/assets/javascripts/darkswarm/directives/inline_alert.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/inline_alert.js.coffee @@ -1,6 +1,7 @@ -Darkswarm.directive "ofnInlineFlash", -> - restrict: 'E' - controller: ($scope) -> - $scope.visible = true - $scope.closeFlash = -> - $scope.visible = false +Darkswarm.directive "ofnInlineAlert", -> + restrict: 'A' + scope: true + link: (scope, elem, attrs) -> + scope.visible = true + scope.close = -> + scope.visible = false diff --git a/app/assets/javascripts/templates/registration/about.html.haml b/app/assets/javascripts/templates/registration/about.html.haml index d014c96d90..704a7e3815 100644 --- a/app/assets/javascripts/templates/registration/about.html.haml +++ b/app/assets/javascripts/templates/registration/about.html.haml @@ -12,13 +12,12 @@ %form{ name: 'about', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "update('images',about)" } } .row .small-12.columns - .alert-box.alert{"data-alert" => ""} + .alert-box.alert{ "ofn-inline-alert" => true, ng: { show: "visible" } } {{ enterprise.name }} won't be visible on the Open Food Network until you enter a long and short description. - %a.close{:href => "#"} × - - .alert-box.info{"data-alert" => ""} + %a.close{ ng: { click: "close()" } } × + .alert-box.info{ "ofn-inline-alert" => true, ng: { show: "visible" } } {{ enterprise.name }} has been created on the Open Food Network. If you leave at any point from here onwards, your enterprise will be saved, and you can always login to the admin section to update or continue filling out your enterprise details. - %a.close{:href => "#"} × + %a.close{ ng: { click: "close()" } } × .small-12.large-8.columns .row From fc3a132c12fe31a34e75e3944868517999141129 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 9 Oct 2014 13:46:32 +1100 Subject: [PATCH 061/142] Closing auth dialog on pages other than home returns the user to home --- .../darkswarm/services/authentication_service.js.coffee | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/darkswarm/services/authentication_service.js.coffee b/app/assets/javascripts/darkswarm/services/authentication_service.js.coffee index 5f5ae520e3..f2d7049e67 100644 --- a/app/assets/javascripts/darkswarm/services/authentication_service.js.coffee +++ b/app/assets/javascripts/darkswarm/services/authentication_service.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.factory "AuthenticationService", (Navigation, $modal, $location, Redirections)-> +Darkswarm.factory "AuthenticationService", (Navigation, $modal, $location, Redirections, Loading)-> new class AuthenticationService selectedPath: "/login" @@ -25,4 +25,9 @@ Darkswarm.factory "AuthenticationService", (Navigation, $modal, $location, Redir active: Navigation.active close: -> - Navigation.navigate "/" + if location.pathname == "/" + Navigation.navigate "/" + else + Loading.message = "Taking you back to the home page" + location.hash = "" + location.pathname = "/" From d1e3f74c03149a9cd57de0c82cfa28a57c827cf0 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 9 Oct 2014 15:56:54 +1100 Subject: [PATCH 062/142] Add loading gif to image uploaders --- .../templates/registration/images/logo.html.haml | 8 ++++++-- .../templates/registration/images/promo.html.haml | 8 ++++++-- app/assets/stylesheets/darkswarm/registration.css.sass | 8 +++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/templates/registration/images/logo.html.haml b/app/assets/javascripts/templates/registration/images/logo.html.haml index 803b103a58..4b19c14cff 100644 --- a/app/assets/javascripts/templates/registration/images/logo.html.haml +++ b/app/assets/javascripts/templates/registration/images/logo.html.haml @@ -36,6 +36,10 @@ .row.pad-top .small-12.columns.center #image-placeholder.logo - %img{ ng: { show: "imageSrc()", src: '{{ imageSrc() }}' } } - .message{ ng: { hide: "imageSrc()" } } + %img{ ng: { show: "imageSrc() && !imageUploader.isUploading", src: '{{ imageSrc() }}' } } + .message{ ng: { hide: "imageSrc() || imageUploader.isUploading" } } Your logo will appear here for review once uploaded + .loading{ ng: { hide: "!imageUploader.isUploading" } } + %img.spinner{ src: "/assets/loading.gif" } + %br/ + Uploading... diff --git a/app/assets/javascripts/templates/registration/images/promo.html.haml b/app/assets/javascripts/templates/registration/images/promo.html.haml index f134834d5c..d98721dc6d 100644 --- a/app/assets/javascripts/templates/registration/images/promo.html.haml +++ b/app/assets/javascripts/templates/registration/images/promo.html.haml @@ -34,6 +34,10 @@ .row.pad-top .small-12.columns.center #image-placeholder.promo - %img{ ng: { show: "imageSrc()", src: '{{ imageSrc() }}' } } - .message{ ng: { hide: "imageSrc()" } } + %img{ ng: { show: "imageSrc() && !imageUploader.isUploading", src: '{{ imageSrc() }}' } } + .message{ ng: { hide: "imageSrc() || imageUploader.isUploading" } } Your logo will appear here for review once uploaded + .loading{ ng: { hide: "!imageUploader.isUploading" } } + %img.spinner{ src: "/assets/loading.gif" } + %br/ + Uploading... diff --git a/app/assets/stylesheets/darkswarm/registration.css.sass b/app/assets/stylesheets/darkswarm/registration.css.sass index 547f834406..707d5a93e7 100644 --- a/app/assets/stylesheets/darkswarm/registration.css.sass +++ b/app/assets/stylesheets/darkswarm/registration.css.sass @@ -92,19 +92,25 @@ font-size: 18px font-weight: bold color: #373737 - background-color: #e1e1e1 + background-color: #f1f1f1 text-align: center border: 3px dashed #494949 margin-left: auto margin-right: auto + .spinner + width: 100px &.logo .message padding-top: 6em + .loading + padding-top: 4em width: 306px height: 306px &.promo .message padding-top: 4em + .loading + padding-top: 1em width: 726px height: 166px From 9b275cc5f03825436572a462e843c4a82c980a21 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 9 Oct 2014 17:26:31 +1100 Subject: [PATCH 063/142] WIP: Shuffling around order of cards in registration --- .../registration_controller.js.coffee | 2 +- .../templates/registration/address.html.haml | 60 --------------- .../templates/registration/contact.html.haml | 9 ++- .../templates/registration/details.html.haml | 74 ++++++++++++------- .../templates/registration/steps.html.haml | 2 - .../templates/registration/type.html.haml | 42 +++++++++++ .../darkswarm/registration.css.sass | 2 +- spec/features/consumer/registration_spec.rb | 13 ++-- 8 files changed, 103 insertions(+), 101 deletions(-) delete mode 100644 app/assets/javascripts/templates/registration/address.html.haml create mode 100644 app/assets/javascripts/templates/registration/type.html.haml diff --git a/app/assets/javascripts/darkswarm/controllers/registration/registration_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/registration/registration_controller.js.coffee index 2fcc0f32fd..3be0378619 100644 --- a/app/assets/javascripts/darkswarm/controllers/registration/registration_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/registration/registration_controller.js.coffee @@ -3,7 +3,7 @@ Darkswarm.controller "RegistrationCtrl", ($scope, RegistrationService, Enterpris $scope.enterprise = EnterpriseRegistrationService.enterprise $scope.select = RegistrationService.select - $scope.steps = ['details','address','contact','about','images','social'] + $scope.steps = ['details','contact','type','about','images','social'] $scope.countries = availableCountries diff --git a/app/assets/javascripts/templates/registration/address.html.haml b/app/assets/javascripts/templates/registration/address.html.haml deleted file mode 100644 index 6fe39e9285..0000000000 --- a/app/assets/javascripts/templates/registration/address.html.haml +++ /dev/null @@ -1,60 +0,0 @@ -.container#registration-address - .header - %h2 - Greetings - %span{ ng: { class: "{brick: enterprise.is_distributor, turquoise: !enterprise.is_distributor}" } } - {{ enterprise.name }} - - %h5 Now we need to know where you are - %ng-include{ src: "'registration/steps.html'" } - %form{ name: 'address', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "selectIfValid('contact',address)" } } - .row.content - .small-12.medium-12.large-7.columns - .row - .small-12.columns.field - %label{ for: 'enterprise_address' } Address: - %input.chunky.small-12.columns{ id: 'enterprise_address', name: 'address1', required: true, placeholder: "eg. 123 Cranberry Drive", required: true, ng: { model: 'enterprise.address.address1' } } - %span.error.small-12.columns{ ng: { show: "address.address1.$error.required && submitted" } } - You need to enter an address. - .row - .small-12.large-8.columns.field - %label{ for: 'enterprise_city' } Suburb: - %input.chunky.small-12.columns{ id: 'enterprise_city', name: 'city', required: true, placeholder: "eg. Northcote", ng: { model: 'enterprise.address.city' } } - %span.error.small-12.columns{ ng: { show: "address.city.$error.required && submitted" } } - You need to enter a suburb. - .small-12.large-4.columns.field - %label{ for: 'enterprise_zipcode' } Postcode: - %input.chunky.small-12.columns{ id: 'enterprise_zipcode', name: 'zipcode', required: true, placeholder: "eg. 3070", ng: { model: 'enterprise.address.zipcode' } } - %span.error.small-12.columns{ ng: { show: "address.zipcode.$error.required && submitted" } } - You need to enter a postcode. - .row - .small-12.large-8.columns.field - %label{ for: 'enterprise_country' } Country: - %select.chunky.small-12.columns{ id: 'enterprise_country', name: 'country', required: true, ng: { model: 'enterprise.country', options: 'c as c.name for c in countries' } } - %span.error.small-12.columns{ ng: { show: "address.country.$error.required && submitted" } } - You need to enter a country. - .small-12.large-4.columns.field - %label{ for: 'enterprise_state' } State: - %select.chunky.small-12.columns{ id: 'enterprise_state', name: 'state', ng: { model: 'enterprise.address.state_id', options: 's.id as s.abbr for s in enterprise.country.states', show: 'countryHasStates()', required: 'countryHasStates()' } } - %span.error.small-12.columns{ ng: { show: "address.state.$error.required && submitted" } } - You need to enter a state. - .small-12.medium-12.large-5.hide-for-small-only - // This is the location area - / %h6 - / Location display - / %i.ofn-i_013-help.has-tip{ 'data-tooltip' => true, title: "Choose how you want to display your enterprise's address on the Open Food Network. By default, full location is shown everywhere including street name and number."} - / .row - / .small-12.columns - / %label.indent-checkbox - / %input{ type: 'checkbox', id: 'enterpise_suburb_only', ng: { model: 'enterprise.suburb_only' } } - / Hide my street name and street number from the public (ie. only show the suburb) - / .small-12.columns - / %label.indent-checkbox - / %input{ type: 'checkbox', id: 'enterprise_on_map', ng: { model: 'enterprise.on_map' } } - / Blur my location on the map (show an approximate, not exact pin) - - .row.buttons - .small-12.columns - %input.button.secondary{ type: "button", value: "Back", ng: { click: "select('details')" } } -   - %input.button.primary{ type: "submit", value: "Continue" } diff --git a/app/assets/javascripts/templates/registration/contact.html.haml b/app/assets/javascripts/templates/registration/contact.html.haml index c7262248d0..87272cdd5a 100644 --- a/app/assets/javascripts/templates/registration/contact.html.haml +++ b/app/assets/javascripts/templates/registration/contact.html.haml @@ -1,12 +1,12 @@ .container#registration-contact .header - %h2 Last step to create your enterprise! + %h2 Greetings! %h5 Who is responsible for managing - %span{ ng: { class: "{brick: enterprise.is_distributor, turquoise: !enterprise.is_distributor}" } } + %span.turquoise {{ enterprise.name }}? %ng-include{ src: "'registration/steps.html'" } - %form{ name: 'contact', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "create(contact)" } } + %form{ name: 'contact', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "selectIfValid('type',contact)" } } .row.content .small-12.medium-12.large-7.columns .row @@ -39,8 +39,9 @@ / .small-12.columns / %label.indent-checkbox / %input{ type: 'checkbox', id: 'contact_phone_profile', ng: { model: 'enterprise.phone_in_profile' } }   Display phone in profile + .row.buttons .small-12.columns - %input.button.secondary{ type: "button", value: "Back", ng: { click: "select('address')" } } + %input.button.secondary{ type: "button", value: "Back", ng: { click: "select('details')" } }   %input.button.primary{ type: "submit", value: "Continue" } diff --git a/app/assets/javascripts/templates/registration/details.html.haml b/app/assets/javascripts/templates/registration/details.html.haml index bb358a1864..a3ff0676c4 100644 --- a/app/assets/javascripts/templates/registration/details.html.haml +++ b/app/assets/javascripts/templates/registration/details.html.haml @@ -1,10 +1,10 @@ .container#registration-details{bindonce: true} .header %h2 Let's Get Started - %h5{ bo: { if: "enterprise.type != 'single'" } } Woot! First we need to know what sort of enterprise you are: - %h5{ bo: { if: "enterprise.type == 'single'" } } Woot! First we need to know the name of your farm: + %h5{ bo: { if: "enterprise.type != 'single'" } } Woot! First we need to know a little bit about your enterprise: + %h5{ bo: { if: "enterprise.type == 'single'" } } Woot! First we need to know a little bit about your farm: %ng-include{ src: "'registration/steps.html'" } - %form{ name: 'details', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "selectIfValid('address',details)" } } + %form{ name: 'details', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "selectIfValid('contact',details)" } } .row .small-12.columns.field %label{ for: 'enterprise_name', bo: { if: "enterprise.type != 'single'" } } Enterprise Name: @@ -12,31 +12,51 @@ %input.chunky.small-12.columns{ id: 'enterprise_name', name: 'name', placeholder: "eg. Charlie's Awesome Farm", required: true, ng: { model: 'enterprise.name' } } %span.error.small-12.columns{ ng: { show: "details.name.$error.required && submitted" } } You need to enter a name for your enterprise! + .row + .small-12.medium-12.large-7.columns + .row + .small-12.columns.field + %label{ for: 'enterprise_address' } Address: + %input.chunky.small-12.columns{ id: 'enterprise_address', name: 'address1', required: true, placeholder: "eg. 123 Cranberry Drive", required: true, ng: { model: 'enterprise.address.address1' } } + %span.error.small-12.columns{ ng: { show: "details.address1.$error.required && submitted" } } + You need to enter an address. + .row + .small-12.large-8.columns.field + %label{ for: 'enterprise_city' } Suburb: + %input.chunky.small-12.columns{ id: 'enterprise_city', name: 'city', required: true, placeholder: "eg. Northcote", ng: { model: 'enterprise.address.city' } } + %span.error.small-12.columns{ ng: { show: "details.city.$error.required && submitted" } } + You need to enter a suburb. + .small-12.large-4.columns.field + %label{ for: 'enterprise_zipcode' } Postcode: + %input.chunky.small-12.columns{ id: 'enterprise_zipcode', name: 'zipcode', required: true, placeholder: "eg. 3070", ng: { model: 'enterprise.address.zipcode' } } + %span.error.small-12.columns{ ng: { show: "details.zipcode.$error.required && submitted" } } + You need to enter a postcode. + .row + .small-12.large-8.columns.field + %label{ for: 'enterprise_country' } Country: + %select.chunky.small-12.columns{ id: 'enterprise_country', name: 'country', required: true, ng: { model: 'enterprise.country', options: 'c as c.name for c in countries' } } + %span.error.small-12.columns{ ng: { show: "details.country.$error.required && submitted" } } + You need to enter a country. + .small-12.large-4.columns.field + %label{ for: 'enterprise_state' } State: + %select.chunky.small-12.columns{ id: 'enterprise_state', name: 'state', ng: { model: 'enterprise.address.state_id', options: 's.id as s.abbr for s in enterprise.country.states', show: 'countryHasStates()', required: 'countryHasStates()' } } + %span.error.small-12.columns{ ng: { show: "details.state.$error.required && submitted" } } + You need to enter a state. + .small-12.medium-12.large-5.hide-for-small-only + // This is the location area + / %h6 + / Location display + / %i.ofn-i_013-help.has-tip{ 'data-tooltip' => true, title: "Choose how you want to display your enterprise's address on the Open Food Network. By default, full location is shown everywhere including street name and number."} + / .row + / .small-12.columns + / %label.indent-checkbox + / %input{ type: 'checkbox', id: 'enterpise_suburb_only', ng: { model: 'enterprise.suburb_only' } } + / Hide my street name and street number from the public (ie. only show the suburb) + / .small-12.columns + / %label.indent-checkbox + / %input{ type: 'checkbox', id: 'enterprise_on_map', ng: { model: 'enterprise.on_map' } } + / Blur my location on the map (show an approximate, not exact pin) - .row#enterprise-types{ 'data-equalizer' => true, bo: { if: "enterprise.type != 'single'" } } - .small-12.columns.field - .row - .small-12.columns - %label Choose one: - .row - .small-12.medium-4.large-4.columns{ 'data-equalizer-watch' => true } - %a.panel#producer-panel{ href: "#", ng: { click: "enterprise.is_distributor = false; enterprise.is_primary_producer = true", class: "{selected: (!enterprise.is_distributor && enterprise.is_primary_producer)}" } } - .left - / %render-svg{ path: "/assets/map-icon-producer.svg" } - %h4 I'm A Producer - %p Producers make yummy things to eat &/or drink. You're a producer if you grow it, raise it, brew it, bake it, ferment it, milk it or mould it. - .small-12.medium-4.large-4.columns{ 'data-equalizer-watch' => true } - %a.panel#hub-panel{ href: "#", ng: { click: "enterprise.is_distributor = true; enterprise.is_primary_producer = false", class: "{selected: (enterprise.is_distributor && !enterprise.is_primary_producer)}" } } - .left - / %render-svg{ path: "/assets/map-icon-hub.svg" } - %h4 I'm A Hub - %p Hubs connect the producer to the eater. Hubs can be co-ops, independent retailers, buying groups, wholesalers, CSA box schemes, farm-gate stalls, etc. - .small-12.medium-4.large-4.columns{ 'data-equalizer-watch' => true } - %a.panel#both-panel{ href: "#", ng: { click: "enterprise.is_distributor = true; enterprise.is_primary_producer = true", class: "{selected: (enterprise.is_distributor && enterprise.is_primary_producer)}" } } - .left - / %render-svg{path: "/assets/map-icon-both.svg"} - %h4 I'm Both - %p Hey there, Jack-of-all-trades! Not only do you produce things to eat &/or drink, you also want to sell your yummies through an Open Food Network shopfront. .row.buttons .small-12.columns %input.button.primary.right{ type: "submit", value: "Continue" } diff --git a/app/assets/javascripts/templates/registration/steps.html.haml b/app/assets/javascripts/templates/registration/steps.html.haml index 65e3cb6b48..8b420de293 100644 --- a/app/assets/javascripts/templates/registration/steps.html.haml +++ b/app/assets/javascripts/templates/registration/steps.html.haml @@ -1,5 +1,3 @@ .row#progress-bar .small-12.medium-2.columns.item{ ng: { repeat: 'step in steps', class: "{active: (currentStep() == step),'show-for-medium-up': (currentStep() != step)}" } } {{ $index+1 + ". " + step }} - - \ No newline at end of file diff --git a/app/assets/javascripts/templates/registration/type.html.haml b/app/assets/javascripts/templates/registration/type.html.haml new file mode 100644 index 0000000000..0834bf1528 --- /dev/null +++ b/app/assets/javascripts/templates/registration/type.html.haml @@ -0,0 +1,42 @@ +.container#registration-type{bindonce: true} + .header + %h2 + Last step to create your enterprise! + + %h5 + Is + %span{ ng: { class: "{brick: enterprise.is_distributor, turquoise: !enterprise.is_distributor}" } } + {{ enterprise.name }} + a primary producer? + %ng-include{ src: "'registration/steps.html'" } + %form{ name: 'type', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "create(type)" } } + .row#enterprise-types{ 'data-equalizer' => true, bo: { if: "enterprise.type != 'single'" } } + .small-12.columns.field + .row + .small-12.columns + %label Choose one: + .row + .small-12.medium-4.large-4.columns{ 'data-equalizer-watch' => true } + %a.panel#producer-panel{ href: "#", ng: { click: "enterprise.is_distributor = false; enterprise.is_primary_producer = true", class: "{selected: (!enterprise.is_distributor && enterprise.is_primary_producer)}" } } + .left + / %render-svg{ path: "/assets/map-icon-producer.svg" } + %h4 I'm A Producer + %p Producers make yummy things to eat &/or drink. You're a producer if you grow it, raise it, brew it, bake it, ferment it, milk it or mould it. + .small-12.medium-4.large-4.columns{ 'data-equalizer-watch' => true } + %a.panel#hub-panel{ href: "#", ng: { click: "enterprise.is_distributor = true; enterprise.is_primary_producer = false", class: "{selected: (enterprise.is_distributor && !enterprise.is_primary_producer)}" } } + .left + / %render-svg{ path: "/assets/map-icon-hub.svg" } + %h4 I'm A Hub + %p Hubs connect the producer to the eater. Hubs can be co-ops, independent retailers, buying groups, wholesalers, CSA box schemes, farm-gate stalls, etc. + .small-12.medium-4.large-4.columns{ 'data-equalizer-watch' => true } + %a.panel#both-panel{ href: "#", ng: { click: "enterprise.is_distributor = true; enterprise.is_primary_producer = true", class: "{selected: (enterprise.is_distributor && enterprise.is_primary_producer)}" } } + .left + / %render-svg{path: "/assets/map-icon-both.svg"} + %h4 I'm Both + %p Hey there, Jack-of-all-trades! Not only do you produce things to eat &/or drink, you also want to sell your yummies through an Open Food Network shopfront. + + .row.buttons + .small-12.columns + %input.button.secondary{ type: "button", value: "Back", ng: { click: "select('contact')" } } +   + %input.button.primary{ type: "submit", value: "Continue" } diff --git a/app/assets/stylesheets/darkswarm/registration.css.sass b/app/assets/stylesheets/darkswarm/registration.css.sass index 707d5a93e7..08568007f2 100644 --- a/app/assets/stylesheets/darkswarm/registration.css.sass +++ b/app/assets/stylesheets/darkswarm/registration.css.sass @@ -115,7 +115,7 @@ height: 166px -#registration-details +#registration-type #enterprise-types a.panel display: block diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index 7ac46a8970..ebcea88a89 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -22,13 +22,10 @@ feature "Registration", js: true do expect(URI.parse(current_url).path).to eq registration_path # Done reading introduction - click_button_and_ensure_content "Let's get started!", "Woot! First we need to know what sort of enterprise you are:" + click_button_and_ensure_content "Let's get started!", "Woot! First we need to know a little bit about your enterprise:" # Filling in details fill_in 'enterprise_name', with: "My Awesome Enterprise" - click_link 'both-panel' - - click_button_and_ensure_content "Continue", "Greetings My Awesome Enterprise" # Filling in address fill_in 'enterprise_address', with: '123 Abc Street' @@ -45,6 +42,11 @@ feature "Registration", js: true do fill_in 'enterprise_phone', with: '12 3456 7890' click_button 'Continue' + # Choosing a type + expect(page).to have_content 'Last step to create your enterprise!' + click_link 'both-panel' + click_button 'Continue' + # Enterprise should be created expect(page).to have_content 'Nice one!' e = Enterprise.find_by_name('My Awesome Enterprise') @@ -109,10 +111,9 @@ feature "Registration", js: true do expect(URI.parse(current_url).path).to eq store_registration_path # Done reading introduction - click_button_and_ensure_content "Let's get started!", "Woot! First we need to know the name of your farm:" + click_button_and_ensure_content "Let's get started!", "Woot! First we need to know a little bit about your farm:" # Details Page - expect(page).to have_content "Woot! First we need to know the name of your farm:" expect(page).to_not have_selector '#enterprise-types' # Everything from here should be covered in 'profile' spec From d5ea2a0206c648a9098a0efc12250a47befbde7f Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 10 Oct 2014 15:40:05 +1100 Subject: [PATCH 064/142] Make Enterprise and EnterpriseGroup promo images jpg format --- app/models/enterprise.rb | 2 +- app/models/enterprise_group.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index dfb7945878..b5a89339ac 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -34,7 +34,7 @@ class Enterprise < ActiveRecord::Base path: 'public/images/enterprises/logos/:id/:style/:basename.:extension' has_attached_file :promo_image, - styles: { large: "1200x260#", medium: "720x156#", thumb: "100x100>" }, + styles: { large: ["1200x260#", :jpg], medium: ["720x156#", :jpg], thumb: ["100x100>", :jpg] }, url: '/images/enterprises/promo_images/:id/:style/:basename.:extension', path: 'public/images/enterprises/promo_images/:id/:style/:basename.:extension' diff --git a/app/models/enterprise_group.rb b/app/models/enterprise_group.rb index cdc9d9932a..6e61b1a564 100644 --- a/app/models/enterprise_group.rb +++ b/app/models/enterprise_group.rb @@ -15,7 +15,7 @@ class EnterpriseGroup < ActiveRecord::Base path: 'public/images/enterprise_groups/logos/:id/:style/:basename.:extension' has_attached_file :promo_image, - styles: {large: "1200x260#"}, + styles: {large: ["1200x260#", :jpg]}, url: '/images/enterprise_groups/promo_images/:id/:style/:basename.:extension', path: 'public/images/enterprise_groups/promo_images/:id/:style/:basename.:extension' From b8b19368dff6ac8908e3fec3d5616951d81c0fa8 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 10 Oct 2014 16:54:38 +1100 Subject: [PATCH 065/142] WIP: Making enterprise emails confirmable --- app/models/enterprise.rb | 2 ++ ...141010043405_add_confirmable_to_enterprise.rb | 16 ++++++++++++++++ db/schema.rb | 7 ++++++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20141010043405_add_confirmable_to_enterprise.rb diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index dfb7945878..e5b92b0382 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -2,6 +2,8 @@ class Enterprise < ActiveRecord::Base TYPES = %w(full single profile) ENTERPRISE_SEARCH_RADIUS = 100 + devise :confirmable, reconfirmable: true + self.inheritance_column = nil acts_as_gmappable :process_geocoding => false diff --git a/db/migrate/20141010043405_add_confirmable_to_enterprise.rb b/db/migrate/20141010043405_add_confirmable_to_enterprise.rb new file mode 100644 index 0000000000..22203fe419 --- /dev/null +++ b/db/migrate/20141010043405_add_confirmable_to_enterprise.rb @@ -0,0 +1,16 @@ +class AddConfirmableToEnterprise < ActiveRecord::Migration + def up + add_column :enterprises, :confirmation_token, :string + add_column :enterprises, :confirmed_at, :datetime + add_column :enterprises, :confirmation_sent_at, :datetime + add_column :enterprises, :unconfirmed_email, :string + add_index :enterprises, :confirmation_token, :unique => true + + # Existing enterprises are assumed to be confirmed + Enterprise.update_all(:confirmed_at => Time.now) + end + + def down + remove_columns :enterprises, :confirmation_token, :confirmed_at, :confirmation_sent_at, :unconfirmed_email + end +end diff --git a/db/schema.rb b/db/schema.rb index 73f10210a7..ee364758d7 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 => 20140904003026) do +ActiveRecord::Schema.define(:version => 20141010043405) do create_table "adjustment_metadata", :force => true do |t| t.integer "adjustment_id" @@ -266,9 +266,14 @@ ActiveRecord::Schema.define(:version => 20140904003026) do t.string "linkedin" t.string "type", :default => "profile", :null => false t.integer "owner_id", :null => false + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" + t.string "unconfirmed_email" end add_index "enterprises", ["address_id"], :name => "index_enterprises_on_address_id" + add_index "enterprises", ["confirmation_token"], :name => "index_enterprises_on_confirmation_token", :unique => true add_index "enterprises", ["owner_id"], :name => "index_enterprises_on_owner_id" create_table "exchange_fees", :force => true do |t| From d4318263f600f0688bfebd4a68c28a059ff7a92b Mon Sep 17 00:00:00 2001 From: summerscope Date: Fri, 10 Oct 2014 18:18:33 +1100 Subject: [PATCH 066/142] Registration modals styling WIP --- .../darkswarm/registration.css.sass | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/app/assets/stylesheets/darkswarm/registration.css.sass b/app/assets/stylesheets/darkswarm/registration.css.sass index 08568007f2..b0d0757720 100644 --- a/app/assets/stylesheets/darkswarm/registration.css.sass +++ b/app/assets/stylesheets/darkswarm/registration.css.sass @@ -2,26 +2,25 @@ @import mixins #registration-modal - .header + header text-align: center - background-color: #efefef - padding-bottom: 1rem + // background-color: #efefef + @media all and (max-width: 64em) + text-align: left .container background-color: #ffffff - .content - // margin-bottom: 15px i font-size: 150% - .buttons - .field - margin-bottom: 15px + margin-bottom: 1em - input.chunky + .chunky padding: 8px - font-size: 105% + font-size: 1rem + margin: 0 + width: 100% label.indent-checkbox display: block @@ -33,9 +32,9 @@ label margin-bottom: 3px - ol, ul - // font-size: 80% + ol, ul, p font-size: 0.875rem + ol, ul padding: 0 margin: 0 ol @@ -44,22 +43,24 @@ .highlight-box background: white padding: 1rem 1.2rem - @media all and (max-width: 640px) + @media all and (max-width: 64em) margin-top: 1rem #progress-bar margin-bottom: 15px .item - padding: 12px 0px + font-size: 0.75rem + padding: 10px 0px text-transform: uppercase text-align: center - background-color: #333 - border: 2px solid #333 + background-color: $clr-blue + border: 2px solid $clr-blue color: #fff .item.active - background-color: #cccccc - border: 2px solid #333 - color: #333 + background-color: $disabled-light + border: 2px solid $clr-blue + color: $clr-blue + font-weight: 700 @include box-shadow(inset 0 0 1px 0 #fff) From 89a51bf1da9fafe86565906cb16bbe44830fb50f Mon Sep 17 00:00:00 2001 From: summerscope Date: Fri, 10 Oct 2014 18:19:42 +1100 Subject: [PATCH 067/142] Adjustments to layout, responsive logic, simplify column structure --- .../templates/registration/details.html.haml | 116 ++++++++++-------- 1 file changed, 65 insertions(+), 51 deletions(-) diff --git a/app/assets/javascripts/templates/registration/details.html.haml b/app/assets/javascripts/templates/registration/details.html.haml index a3ff0676c4..d4b0abc4f8 100644 --- a/app/assets/javascripts/templates/registration/details.html.haml +++ b/app/assets/javascripts/templates/registration/details.html.haml @@ -1,62 +1,76 @@ .container#registration-details{bindonce: true} - .header - %h2 Let's Get Started - %h5{ bo: { if: "enterprise.type != 'single'" } } Woot! First we need to know a little bit about your enterprise: - %h5{ bo: { if: "enterprise.type == 'single'" } } Woot! First we need to know a little bit about your farm: %ng-include{ src: "'registration/steps.html'" } + .row + .small-12.columns + %header + %h2 Let's Get Started + %h5{ bo: { if: "enterprise.type != 'single'" } } Woot! First we need to know a little bit about your enterprise: + %h5{ bo: { if: "enterprise.type == 'single'" } } Woot! First we need to know a little bit about your farm: + %form{ name: 'details', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "selectIfValid('contact',details)" } } + .row - .small-12.columns.field - %label{ for: 'enterprise_name', bo: { if: "enterprise.type != 'single'" } } Enterprise Name: - %label{ for: 'enterprise_name', bo: { if: "enterprise.type == 'single'" } } Farm Name: - %input.chunky.small-12.columns{ id: 'enterprise_name', name: 'name', placeholder: "eg. Charlie's Awesome Farm", required: true, ng: { model: 'enterprise.name' } } - %span.error.small-12.columns{ ng: { show: "details.name.$error.required && submitted" } } - You need to enter a name for your enterprise! + .small-12.medium-9.large-12.columns.end + .field + %label{ for: 'enterprise_name', bo: { if: "enterprise.type != 'single'" } } Enterprise Name: + %label{ for: 'enterprise_name', bo: { if: "enterprise.type == 'single'" } } Farm Name: + %input.chunky{ id: 'enterprise_name', name: 'name', placeholder: "e.g. Charlie's Awesome Farm", required: true, ng: { model: 'enterprise.name' } } + %span.error{ ng: { show: "details.name.$error.required && submitted" } } + Please choose a unique name for your enterprise + .row - .small-12.medium-12.large-7.columns + .small-12.medium-9.large-6.columns + .field + %label{ for: 'enterprise_address' } Address line 1: + %input.chunky{ id: 'enterprise_address', name: 'address1', required: true, placeholder: "e.g. 123 Cranberry Drive", required: true, ng: { model: 'enterprise.address.address1' } } + %span.error{ ng: { show: "details.address1.$error.required && submitted" } } + Please enter an address + .field + %label{ for: 'enterprise_address2' } Address line 2: + %input.chunky{ id: 'enterprise_address2', name: 'address2', required: false, placeholder: "", required: false, ng: { model: 'enterprise.address.address2' } } + + .small-12.medium-9.large-6.columns.end .row - .small-12.columns.field - %label{ for: 'enterprise_address' } Address: - %input.chunky.small-12.columns{ id: 'enterprise_address', name: 'address1', required: true, placeholder: "eg. 123 Cranberry Drive", required: true, ng: { model: 'enterprise.address.address1' } } - %span.error.small-12.columns{ ng: { show: "details.address1.$error.required && submitted" } } - You need to enter an address. + .small-12.medium-8.large-8.columns + .field + %label{ for: 'enterprise_city' } Suburb: + %input.chunky{ id: 'enterprise_city', name: 'city', required: true, placeholder: "e.g. Northcote", ng: { model: 'enterprise.address.city' } } + %span.error{ ng: { show: "details.city.$error.required && submitted" } } + Please enter a suburb + .small-12.medium-4.large-4.columns + .field + %label{ for: 'enterprise_zipcode' } Postcode: + %input.chunky{ id: 'enterprise_zipcode', name: 'zipcode', required: true, placeholder: "e.g. 3070", ng: { model: 'enterprise.address.zipcode' } } + %span.error{ ng: { show: "details.zipcode.$error.required && submitted" } } + Postcode required .row - .small-12.large-8.columns.field - %label{ for: 'enterprise_city' } Suburb: - %input.chunky.small-12.columns{ id: 'enterprise_city', name: 'city', required: true, placeholder: "eg. Northcote", ng: { model: 'enterprise.address.city' } } - %span.error.small-12.columns{ ng: { show: "details.city.$error.required && submitted" } } - You need to enter a suburb. - .small-12.large-4.columns.field - %label{ for: 'enterprise_zipcode' } Postcode: - %input.chunky.small-12.columns{ id: 'enterprise_zipcode', name: 'zipcode', required: true, placeholder: "eg. 3070", ng: { model: 'enterprise.address.zipcode' } } - %span.error.small-12.columns{ ng: { show: "details.zipcode.$error.required && submitted" } } - You need to enter a postcode. - .row - .small-12.large-8.columns.field - %label{ for: 'enterprise_country' } Country: - %select.chunky.small-12.columns{ id: 'enterprise_country', name: 'country', required: true, ng: { model: 'enterprise.country', options: 'c as c.name for c in countries' } } - %span.error.small-12.columns{ ng: { show: "details.country.$error.required && submitted" } } - You need to enter a country. - .small-12.large-4.columns.field - %label{ for: 'enterprise_state' } State: - %select.chunky.small-12.columns{ id: 'enterprise_state', name: 'state', ng: { model: 'enterprise.address.state_id', options: 's.id as s.abbr for s in enterprise.country.states', show: 'countryHasStates()', required: 'countryHasStates()' } } - %span.error.small-12.columns{ ng: { show: "details.state.$error.required && submitted" } } - You need to enter a state. - .small-12.medium-12.large-5.hide-for-small-only - // This is the location area - / %h6 - / Location display - / %i.ofn-i_013-help.has-tip{ 'data-tooltip' => true, title: "Choose how you want to display your enterprise's address on the Open Food Network. By default, full location is shown everywhere including street name and number."} - / .row - / .small-12.columns - / %label.indent-checkbox - / %input{ type: 'checkbox', id: 'enterpise_suburb_only', ng: { model: 'enterprise.suburb_only' } } - / Hide my street name and street number from the public (ie. only show the suburb) - / .small-12.columns - / %label.indent-checkbox - / %input{ type: 'checkbox', id: 'enterprise_on_map', ng: { model: 'enterprise.on_map' } } - / Blur my location on the map (show an approximate, not exact pin) + .small-12.medium-4.large-4.columns + .field + %label{ for: 'enterprise_state' } State: + %select.chunky{ id: 'enterprise_state', name: 'state', ng: { model: 'enterprise.address.state_id', options: 's.id as s.abbr for s in enterprise.country.states', show: 'countryHasStates()', required: 'countryHasStates()' } } + %span.error{ ng: { show: "details.state.$error.required && submitted" } } + State required + .small-12.medium-8.large-8.columns + .field + %label{ for: 'enterprise_country' } Country: + %select.chunky{ id: 'enterprise_country', name: 'country', required: true, ng: { model: 'enterprise.country', options: 'c as c.name for c in countries' } } + %span.error{ ng: { show: "details.country.$error.required && submitted" } } + Please select a country + / .small-12.medium-12.large-5.hide-for-small-only + / %h6 + / Location display + / %i.ofn-i_013-help.has-tip{ 'data-tooltip' => true, title: "Choose how you want to display your enterprise's address on the Open Food Network. By default, full location is shown everywhere including street name and number."} + / .row + / .small-12.columns + / %label.indent-checkbox + / %input{ type: 'checkbox', id: 'enterpise_suburb_only', ng: { model: 'enterprise.suburb_only' } } + / Hide my street name and street number from the public (ie. only show the suburb) + / .small-12.columns + / %label.indent-checkbox + / %input{ type: 'checkbox', id: 'enterprise_on_map', ng: { model: 'enterprise.on_map' } } + / Blur my location on the map (show an approximate, not exact pin) .row.buttons .small-12.columns + %hr %input.button.primary.right{ type: "submit", value: "Continue" } From a4e72f6fbc32db94a33e5966e20bf42233f31cf5 Mon Sep 17 00:00:00 2001 From: summerscope Date: Fri, 10 Oct 2014 18:20:38 +1100 Subject: [PATCH 068/142] Making the header more semantically meaningful for HTML5. Add in row to make spacing consistent. Steps bar moves to top --- .../templates/registration/about.html.haml | 20 +++-- .../templates/registration/contact.html.haml | 15 ++-- .../templates/registration/finished.html.haml | 19 +++-- .../templates/registration/images.html.haml | 9 +- .../registration/introduction.html.haml | 82 ++++++++++--------- .../registration/limit_reached.html.haml | 31 +++---- .../templates/registration/social.html.haml | 11 ++- .../templates/registration/type.html.haml | 20 +++-- 8 files changed, 117 insertions(+), 90 deletions(-) diff --git a/app/assets/javascripts/templates/registration/about.html.haml b/app/assets/javascripts/templates/registration/about.html.haml index 704a7e3815..160a2012d3 100644 --- a/app/assets/javascripts/templates/registration/about.html.haml +++ b/app/assets/javascripts/templates/registration/about.html.haml @@ -1,14 +1,16 @@ .container#registration-about - .header - %h2 Nice one! - %h5 - Now let's flesh out the details about - %span.brick{"ng-show" => "enterprise.is_distributor"} - {{ enterprise.name }} - %span.turquoise{"ng-show" => "!enterprise.is_distributor" } - {{ enterprise.name }} - %ng-include{ src: "'registration/steps.html'" } + .row + .small-12.columns + %header + %h2 Nice one! + %h5 + Now let's flesh out the details about + %span.brick{"ng-show" => "enterprise.is_distributor"} + {{ enterprise.name }} + %span.turquoise{"ng-show" => "!enterprise.is_distributor" } + {{ enterprise.name }} + %form{ name: 'about', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "update('images',about)" } } .row .small-12.columns diff --git a/app/assets/javascripts/templates/registration/contact.html.haml b/app/assets/javascripts/templates/registration/contact.html.haml index 87272cdd5a..fdb606da25 100644 --- a/app/assets/javascripts/templates/registration/contact.html.haml +++ b/app/assets/javascripts/templates/registration/contact.html.haml @@ -1,11 +1,14 @@ .container#registration-contact - .header - %h2 Greetings! - %h5 - Who is responsible for managing - %span.turquoise - {{ enterprise.name }}? %ng-include{ src: "'registration/steps.html'" } + .row + .small-12.columns + %header + %h2 Greetings! + %h5 + Who is responsible for managing + %span.turquoise + {{ enterprise.name }}? + %form{ name: 'contact', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "selectIfValid('type',contact)" } } .row.content .small-12.medium-12.large-7.columns diff --git a/app/assets/javascripts/templates/registration/finished.html.haml b/app/assets/javascripts/templates/registration/finished.html.haml index 75489c607a..b26e623b84 100644 --- a/app/assets/javascripts/templates/registration/finished.html.haml +++ b/app/assets/javascripts/templates/registration/finished.html.haml @@ -1,12 +1,15 @@ .container#registration-finished - .header - %h2 Well done! - %h5 - You have successfully completed the profile for - %span.brick{"ng-show" => "enterprise.is_distributor"} - {{ enterprise.name }} - %span.turquoise{"ng-show" => "!enterprise.is_distributor" } - {{ enterprise.name }} + .row + .small-12.columns + %header + %h2 Well done! + %h5 + You have successfully completed the profile for + %span.brick{"ng-show" => "enterprise.is_distributor"} + {{ enterprise.name }} + %span.turquoise{"ng-show" => "!enterprise.is_distributor" } + {{ enterprise.name }} + .content{ style: 'text-align: center'} %h3 Why not check it out on the Open Food Network? %a.button.primary{ type: "button", href: "/map" } Go to Map Page > diff --git a/app/assets/javascripts/templates/registration/images.html.haml b/app/assets/javascripts/templates/registration/images.html.haml index 889bc4596f..b2a5dcfd08 100644 --- a/app/assets/javascripts/templates/registration/images.html.haml +++ b/app/assets/javascripts/templates/registration/images.html.haml @@ -1,8 +1,11 @@ .container#registration-images{ 'nv-file-drop' => true, uploader: "imageUploader", options:"{ alias: imageStep }", ng: { controller: "EnterpriseImageCtrl" } } - .header - %h2 Thanks! - %h5 Let's upload some pretty pictures so your profile looks great! :) %ng-include{ src: "'registration/steps.html'" } + .row + .small-12.columns + %header + %h2 Thanks! + %h5 Let's upload some pretty pictures so your profile looks great! :) + %form{ name: 'images', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "select('social')" } } .row{ ng: { repeat: 'image_step in imageSteps', show: "imageStep == image_step" } } %ng-include{ src: "'registration/images/'+ image_step + '.html'" } diff --git a/app/assets/javascripts/templates/registration/introduction.html.haml b/app/assets/javascripts/templates/registration/introduction.html.haml index ccefdefbe0..60a8547b4a 100644 --- a/app/assets/javascripts/templates/registration/introduction.html.haml +++ b/app/assets/javascripts/templates/registration/introduction.html.haml @@ -1,39 +1,45 @@ -%div - .header - %h2 Hi there! - %h4 This wizard will step you through creating a profile - .row - .small-12.medium-3.large-2.columns.text-right.hide-for-small-only - %img{:src => "/assets/potatoes.png"} - .small-12.medium-9.large-10.columns - %p - Your profile gives you an online presence on the - %strong Open Food Network, - allowing you to easily connect with potential customers or partners. You can always choose to update your info later, as well as choose to upgrade your Profile to and Online Store, where you can sell products, track orders and receive payments. Creating a profile takes about 5-10 minutes. - .row{ 'data-equalizer' => true } - .small-12.medium-6.large-6.columns.pad-top{ 'data-equalizer-watch' => true } - %h5 You'll need the following: - %ul.check-list - %li - Your enterprise address and contact details - %li - Your logo image - %li - A pretty picture for your profile header - %li - Some 'About Us' text - - .small-12.medium-6.large-6.columns{ 'data-equalizer-watch' => true} - .highlight-box - %h5 Your profile entitles you to: - %ul.small-block-grid-1 - %li - %i.ofn-i_020-search - A searchable listing - %li - %i.ofn-i_040-hub - A pin on the OFN map - .row - .small-12.columns +.row + .small-12.columns + %header + %h2 Hi there! + %h4 + %small + %i.ofn-i_040-hub + Create your enterprise profile + .hide-for-large-up %hr - %input.button.primary{ type: "button", value: "Let's get started!", ng: { click: "select('details')" } } + %input.button.small.primary{ type: "button", value: "Let's get started!", ng: { click: "select('details')" } } + %hr + +.row{ 'data-equalizer' => true } + .small-12.medium-12.large-6.columns.pad-top{ 'data-equalizer-watch' => true } + %h5 You'll need: + %ul.check-list + %li + 5-10 minutes + %li + Enterprise address + %li + Primary contact details + %li + Your logo image + %li + Landscape image for your profile + %li + 'About Us' text + + .small-9.medium-8.large-5.columns.pad-top.end{ 'data-equalizer-watch' => true} + %h5 + What do I get? + %p + Your profile helps people + %strong find + and + %strong contact + you on the Open Food Network. + %p Use this space to tell the story of your enterprise, to help drive connections to your social and online presence. + +.row.show-for-large-up + .small-12.columns + %hr + %input.button.primary.right{ type: "button", value: "Let's get started!", ng: { click: "select('details')" } } diff --git a/app/assets/javascripts/templates/registration/limit_reached.html.haml b/app/assets/javascripts/templates/registration/limit_reached.html.haml index e2131c1727..778d980289 100644 --- a/app/assets/javascripts/templates/registration/limit_reached.html.haml +++ b/app/assets/javascripts/templates/registration/limit_reached.html.haml @@ -1,15 +1,16 @@ -%div - .header.center - %h2 Oh no! - %h4 You have reached the limit! - .row - .small-12.medium-3.large-2.columns.text-right.hide-for-small-only - %img{:src => "/assets/potatoes.png"} - .small-12.medium-9.large-10.columns - %p - You have reached the limit for the number of enterprises you are allowed to own on the - %strong Open Food Network. - .row - .small-12.columns - %hr - %input.button.primary{ type: "button", value: "Return to the homepage", ng: { click: "close()" } } +.row + .small-12.columns + %header + %h2 Oh no! + %h4 You have reached the limit! +.row + .small-12.medium-3.large-2.columns.text-right.hide-for-small-only + %img{:src => "/assets/potatoes.png"} + .small-12.medium-9.large-10.columns + %p + You have reached the limit for the number of enterprises you are allowed to own on the + %strong Open Food Network. +.row + .small-12.columns + %hr + %input.button.primary{ type: "button", value: "Return to the homepage", ng: { click: "close()" } } diff --git a/app/assets/javascripts/templates/registration/social.html.haml b/app/assets/javascripts/templates/registration/social.html.haml index 1b3490ffa0..a2053ea189 100644 --- a/app/assets/javascripts/templates/registration/social.html.haml +++ b/app/assets/javascripts/templates/registration/social.html.haml @@ -1,8 +1,13 @@ .container#registration-social - .header - %h2 Last step! - %h5 How can people find {{ enterprise.name }} online? + %ng-include{ src: "'registration/steps.html'" } + + .row + .small-12.columns + %header + %h2 Last step! + %h5 How can people find {{ enterprise.name }} online? + %form{ name: 'social', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "update('finished',social)" } } .row.content .small-12.large-7.columns diff --git a/app/assets/javascripts/templates/registration/type.html.haml b/app/assets/javascripts/templates/registration/type.html.haml index 0834bf1528..1586f4e6e2 100644 --- a/app/assets/javascripts/templates/registration/type.html.haml +++ b/app/assets/javascripts/templates/registration/type.html.haml @@ -1,14 +1,18 @@ .container#registration-type{bindonce: true} - .header - %h2 - Last step to create your enterprise! - %h5 - Is - %span{ ng: { class: "{brick: enterprise.is_distributor, turquoise: !enterprise.is_distributor}" } } - {{ enterprise.name }} - a primary producer? %ng-include{ src: "'registration/steps.html'" } + + .row + .small-12.columns + %header + %h2 + Last step to create your enterprise! + %h5 + Is + %span{ ng: { class: "{brick: enterprise.is_distributor, turquoise: !enterprise.is_distributor}" } } + {{ enterprise.name }} + a primary producer? + %form{ name: 'type', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "create(type)" } } .row#enterprise-types{ 'data-equalizer' => true, bo: { if: "enterprise.type != 'single'" } } .small-12.columns.field From 01c179856a4906deb5e2fda80e3ceaabc77689f9 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 12 Oct 2014 21:19:59 +1100 Subject: [PATCH 069/142] set maxlength for short description field --- app/views/admin/enterprises/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/enterprises/_form.html.haml b/app/views/admin/enterprises/_form.html.haml index 921807b425..9a3cf1bf39 100644 --- a/app/views/admin/enterprises/_form.html.haml +++ b/app/views/admin/enterprises/_form.html.haml @@ -177,7 +177,7 @@ .alpha.three.columns = f.label :description, 'Short Description' .omega.eight.columns - = f.text_field :description, placeholder: 'Tell us about your enterprise in one or two sentences' + = f.text_field :description, maxlength: 255, placeholder: 'Tell us about your enterprise in one or two sentences' .row .alpha.three.columns = f.label :long_description, 'About Us' From 5dd9879b96abd020c82d63bb1a4af8802cafca6f Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 12 Oct 2014 21:57:01 +1100 Subject: [PATCH 070/142] validate description max lenth --- app/models/enterprise.rb | 2 +- spec/models/enterprise_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index dfb7945878..3d1d8ff9bd 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -1,7 +1,6 @@ class Enterprise < ActiveRecord::Base TYPES = %w(full single profile) ENTERPRISE_SEARCH_RADIUS = 100 - self.inheritance_column = nil acts_as_gmappable :process_geocoding => false @@ -52,6 +51,7 @@ class Enterprise < ActiveRecord::Base validates :email, presence: true validates_presence_of :owner validate :enforce_ownership_limit, if: lambda { owner_id_changed? && !owner_id.nil? } + validates_length_of :description, :maximum => 255 before_validation :ensure_owner_is_manager, if: lambda { owner_id_changed? && !owner_id.nil? } before_validation :set_unused_address_fields diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 241d1fafc7..fff57f6f21 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -86,6 +86,7 @@ describe Enterprise do subject { FactoryGirl.create(:distributor_enterprise, :address => FactoryGirl.create(:address)) } it { should validate_presence_of(:name) } it { should validate_presence_of(:email) } + it { should validate_length_of(:description, :maximum => 255) } it "requires an owner" do expect{ From 5e4186587117eb57917e5f85045e3be2a43152cb Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Tue, 14 Oct 2014 00:25:46 +1100 Subject: [PATCH 071/142] add utils angular module and navigation check factory --- app/assets/javascripts/admin/all.js | 1 + .../enterprise_controller.js.coffee | 10 +++-- .../admin/enterprises/enterprises.js.coffee | 2 +- .../utils/services/navigation_check.js.coffee | 37 +++++++++++++++++++ .../javascripts/admin/utils/utils.js.coffee | 1 + 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 app/assets/javascripts/admin/utils/services/navigation_check.js.coffee create mode 100644 app/assets/javascripts/admin/utils/utils.js.coffee diff --git a/app/assets/javascripts/admin/all.js b/app/assets/javascripts/admin/all.js index f8d3ceb721..7dc9d1116f 100644 --- a/app/assets/javascripts/admin/all.js +++ b/app/assets/javascripts/admin/all.js @@ -22,6 +22,7 @@ //= require ./payment_methods/payment_methods //= require ./products/products //= require ./shipping_methods/shipping_methods +//= require ./utils/utils //= require ./users/users //= require textAngular.min.js //= require textAngular-sanitize.min.js diff --git a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee index 045b6e3422..6558c789a2 100644 --- a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee +++ b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee @@ -1,11 +1,15 @@ angular.module("admin.enterprises") - .controller "enterpriseCtrl", ($scope, Enterprise, longDescription, PaymentMethods, ShippingMethods) -> + .controller "enterpriseCtrl", ($scope, longDescription, Enterprise, PaymentMethods, ShippingMethods, NavigationCheck) -> $scope.Enterprise = Enterprise.enterprise $scope.PaymentMethods = PaymentMethods.paymentMethods $scope.ShippingMethods = ShippingMethods.shippingMethods + # htmlVariable is used by textAngular wysiwyg for the long descrtiption. $scope.htmlVariable = longDescription - $scope.$on "$routeChangeStart", (event, newUrl, oldUrl) -> - event.preventDefault() + # Provide a callback for a warning message displayed when leaving the page. + navigationCallback = -> + "You are editing an enterprise!" + + NavigationCheck.register navigationCallback for payment_method in $scope.PaymentMethods payment_method.selected = payment_method.id in $scope.Enterprise.payment_method_ids diff --git a/app/assets/javascripts/admin/enterprises/enterprises.js.coffee b/app/assets/javascripts/admin/enterprises/enterprises.js.coffee index 9b67bc14f4..e1e43854d1 100644 --- a/app/assets/javascripts/admin/enterprises/enterprises.js.coffee +++ b/app/assets/javascripts/admin/enterprises/enterprises.js.coffee @@ -1 +1 @@ -angular.module("admin.enterprises", ["admin.payment_methods", "admin.shipping_methods", "admin.users", "textAngular"]) \ No newline at end of file +angular.module("admin.enterprises", ["admin.payment_methods", "admin.utils", "admin.shipping_methods", "admin.users", "textAngular"]) \ No newline at end of file diff --git a/app/assets/javascripts/admin/utils/services/navigation_check.js.coffee b/app/assets/javascripts/admin/utils/services/navigation_check.js.coffee new file mode 100644 index 0000000000..1aea4e087f --- /dev/null +++ b/app/assets/javascripts/admin/utils/services/navigation_check.js.coffee @@ -0,0 +1,37 @@ +angular.module("admin.utils") + .factory "NavigationCheck", ($window, $rootScope) -> + callbacks = [] + + # Action for regular browser navigation. + onBeforeUnloadHandler = ($event) -> + message = getMessage() + if message + ($event or $window.event).preventDefault() + message + + # Action for angular navigation. + locationChangeStartHandler = ($event) -> + message = getMessage() + if message and not $window.confirm(message) + $event.stopPropagation() if $event.stopPropagation + $event.preventDefault() if $event.preventDefault + $event.cancelBubble = true + $event.returnValue = false + + # Runs callback functions to retreive most recently added non-empty message. + getMessage = -> + message = null + message = callback() ? message for callback in callbacks + message + + register = (callback) -> + callbacks.push callback + + if $window.addEventListener + $window.addEventListener "beforeunload", onBeforeUnloadHandler + else + $window.onbeforeunload = onBeforeUnloadHandler + + $rootScope.$on "$locationChangeStart", locationChangeStartHandler + + return register: register diff --git a/app/assets/javascripts/admin/utils/utils.js.coffee b/app/assets/javascripts/admin/utils/utils.js.coffee new file mode 100644 index 0000000000..4d58ae930a --- /dev/null +++ b/app/assets/javascripts/admin/utils/utils.js.coffee @@ -0,0 +1 @@ +angular.module("admin.utils", []) \ No newline at end of file From 908c242d36b01c29350671f74e40f72df6b8b42f Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 10:48:05 +1100 Subject: [PATCH 072/142] Confirmation email when creating enterprise --- app/mailers/enterprise_mailer.rb | 8 ++++++++ app/mailers/spree/user_mailer_decorator.rb | 2 +- app/models/enterprise.rb | 6 ++++++ .../enterprise_mailer/confirmation_instructions.html.haml | 5 +++++ config/routes.rb | 2 ++ 5 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 app/views/enterprise_mailer/confirmation_instructions.html.haml diff --git a/app/mailers/enterprise_mailer.rb b/app/mailers/enterprise_mailer.rb index 73c09e1e56..f5f92aed3f 100644 --- a/app/mailers/enterprise_mailer.rb +++ b/app/mailers/enterprise_mailer.rb @@ -1,10 +1,18 @@ +require 'devise/mailers/helpers' class EnterpriseMailer < Spree::BaseMailer + include Devise::Mailers::Helpers + def creation_confirmation(enterprise) find_enterprise(enterprise) subject = "#{@enterprise.name} is now on #{Spree::Config[:site_name]}" mail(:to => @enterprise.owner.email, :from => from_address, :subject => subject) end + def confirmation_instructions(record, token, opts={}) + @token = token + devise_mail(record, :confirmation_instructions, opts) + end + private def find_enterprise(enterprise) @enterprise = enterprise.is_a?(Enterprise) ? enterprise : Enterprise.find(enterprise) diff --git a/app/mailers/spree/user_mailer_decorator.rb b/app/mailers/spree/user_mailer_decorator.rb index ff8bdc4691..dd21a3d0d7 100644 --- a/app/mailers/spree/user_mailer_decorator.rb +++ b/app/mailers/spree/user_mailer_decorator.rb @@ -1,5 +1,5 @@ Spree::UserMailer.class_eval do - + def signup_confirmation(user) @user = user mail(:to => user.email, :from => from_address, diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index e5b92b0382..411f144f13 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -262,6 +262,12 @@ class Enterprise < ActiveRecord::Base select('DISTINCT spree_taxons.*') end + protected + + def devise_mailer + EnterpriseMailer + end + private def send_creation_email diff --git a/app/views/enterprise_mailer/confirmation_instructions.html.haml b/app/views/enterprise_mailer/confirmation_instructions.html.haml new file mode 100644 index 0000000000..277e27aae5 --- /dev/null +++ b/app/views/enterprise_mailer/confirmation_instructions.html.haml @@ -0,0 +1,5 @@ +%p= "Welcome #{@resource.contact}!" + +%p= "You can confirm this email address for #{@resource.name} using the link below:" + +%p= link_to 'Confirm this email address', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 3e063641dd..9cdac4142d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,6 +35,8 @@ Openfoodnetwork::Application.routes.draw do end end + devise_for :enterprise + namespace :admin do resources :order_cycles do post :bulk_update, on: :collection, as: :bulk_update From 6e699b2e8bb86c8ceddc78a3da332bbfd683f035 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 11:52:04 +1100 Subject: [PATCH 073/142] Mailer tests --- spec/mailers/enterprise_mailer_spec.rb | 5 ++++ spec/models/enterprise_spec.rb | 35 ++++++++++++++++---------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/spec/mailers/enterprise_mailer_spec.rb b/spec/mailers/enterprise_mailer_spec.rb index 412870bad7..6b53d7d561 100644 --- a/spec/mailers/enterprise_mailer_spec.rb +++ b/spec/mailers/enterprise_mailer_spec.rb @@ -10,4 +10,9 @@ describe EnterpriseMailer do EnterpriseMailer.creation_confirmation(@enterprise).deliver ActionMailer::Base.deliveries.count.should == 1 end + + it "should send an email confirmation when given an enterprise" do + EnterpriseMailer.confirmation_instructions(@enterprise, 'token').deliver + ActionMailer::Base.deliveries.count.should == 1 + end end \ No newline at end of file diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 241d1fafc7..4861157d87 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -3,6 +3,15 @@ require 'spec_helper' describe Enterprise do include AuthenticationWorkflow + describe "creation" do + it "should send a confirmation email" do + mail_message = double "Mail::Message" + EnterpriseMailer.should_receive(:confirmation_instructions).and_return mail_message + mail_message.should_receive :deliver + create(:enterprise) + end + end + describe "associations" do it { should belong_to(:owner) } it { should have_many(:supplied_products) } @@ -507,40 +516,40 @@ describe Enterprise do # Swap type values full > sell_all, single > sell_own profile > sell_none # swap is_distributor for new can_supply flag. - let(:producer_sell_all_can_supply) { + let(:producer_sell_all_can_supply) { create(:enterprise, is_primary_producer: true, type: "full", is_distributor: true) } - let(:producer_sell_all_cant_supply) { + let(:producer_sell_all_cant_supply) { create(:enterprise, is_primary_producer: true, type: "full", is_distributor: false) } - let(:producer_sell_own_can_supply) { + let(:producer_sell_own_can_supply) { create(:enterprise, is_primary_producer: true, type: "single", is_distributor: true) } - let(:producer_sell_own_cant_supply) { + let(:producer_sell_own_cant_supply) { create(:enterprise, is_primary_producer: true, type: "single", is_distributor: false) } - let(:producer_sell_none_can_supply) { + let(:producer_sell_none_can_supply) { create(:enterprise, is_primary_producer: true, type: "profile", is_distributor: true) } - let(:producer_sell_none_cant_supply) { + let(:producer_sell_none_cant_supply) { create(:enterprise, is_primary_producer: true, type: "profile", is_distributor: false) } let(:non_producer_sell_all_can_supply) { create(:enterprise, is_primary_producer: true, type: "full", is_distributor: true) } - let(:non_producer_sell_all_cant_supply) { + let(:non_producer_sell_all_cant_supply) { create(:enterprise, is_primary_producer: true, type: "full", is_distributor: false) } - let(:non_producer_sell_own_can_supply) { + let(:non_producer_sell_own_can_supply) { create(:enterprise, is_primary_producer: true, type: "single", is_distributor: true) } - let(:non_producer_sell_own_cant_supply) { + let(:non_producer_sell_own_cant_supply) { create(:enterprise, is_primary_producer: true, type: "single", is_distributor: false) } - let(:non_producer_sell_none_can_supply) { + let(:non_producer_sell_none_can_supply) { create(:enterprise, is_primary_producer: false, type: "profile", is_distributor: true) } - let(:non_producer_sell_none_cant_supply) { + let(:non_producer_sell_none_cant_supply) { create(:enterprise, is_primary_producer: false, type: "profile", is_distributor: false) } @@ -555,8 +564,8 @@ describe Enterprise do producer_sell_own_cant_supply.enterprise_category.should == "producer_shop" producer_sell_none_can_supply.enterprise_category.should == "producer" producer_sell_none_cant_supply.enterprise_category.should == "producer_profile" - non_producer_sell_all_can_supply.enterprise_category.should == "hub" - non_producer_sell_all_cant_supply.enterprise_category.should == "hub" + non_producer_sell_all_can_supply.enterprise_category.should == "hub" + non_producer_sell_all_cant_supply.enterprise_category.should == "hub" non_producer_sell_own_can_supply.enterprise_category.should == "hub" non_producer_sell_own_cant_supply.enterprise_category.should == "hub" non_producer_sell_none_can_supply.enterprise_category.should == "hub_profile" From 56f4d5af0fb8550170fd7f7925096c7228556767 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 12:27:55 +1100 Subject: [PATCH 074/142] Visibility in the front end is contingent upon enterprise being confirmed --- app/serializers/api/enterprise_serializer.rb | 5 +++++ .../serializers/enterprise_serializer_spec.rb | 20 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index 6841337024..ce3412ab10 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -102,6 +102,11 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer has_one :address, serializer: Api::AddressSerializer + def visible + binding.pry + object.visible && object.confirmed? + end + def pickup object.shipping_methods.where(:require_ship_address => false).present? end diff --git a/spec/serializers/enterprise_serializer_spec.rb b/spec/serializers/enterprise_serializer_spec.rb index 5fe57a99e2..f3409f2d57 100644 --- a/spec/serializers/enterprise_serializer_spec.rb +++ b/spec/serializers/enterprise_serializer_spec.rb @@ -13,9 +13,27 @@ describe Api::EnterpriseSerializer do serializer = Api::EnterpriseSerializer.new enterprise serializer.to_json.should match taxon.id.to_s end - + it "will render urls" do serializer = Api::EnterpriseSerializer.new enterprise serializer.to_json.should match "map_005-hub.svg" end + + describe "visibility" do + before do + enterprise.stub(:visible).and_return true + end + + it "is visible when confirmed" do + enterprise.stub(:confirmed?).and_return true + serializer = Api::EnterpriseSerializer.new enterprise + expect(serializer.to_json).to match "\"visible\":true" + end + + it "is not visible when unconfirmed" do + enterprise.stub(:confirmed?).and_return false + serializer = Api::EnterpriseSerializer.new enterprise + expect(serializer.to_json).to match "\"visible\":false" + end + end end From 1bdc55cb3356d946a564b5a1b49b6a31c43a18b6 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 13:03:39 +1100 Subject: [PATCH 075/142] Adding confirmed scope to enterprises --- app/models/enterprise.rb | 1 + spec/models/enterprise_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 411f144f13..977b35390b 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -61,6 +61,7 @@ class Enterprise < ActiveRecord::Base scope :by_name, order('name') scope :visible, where(:visible => true) + scope :confirmed, where('confirmed_at IS NOT NULL') scope :is_primary_producer, where(:is_primary_producer => true) scope :is_distributor, where(:is_distributor => true) scope :supplying_variant_in, lambda { |variants| joins(:supplied_products => :variants_including_master).where('spree_variants.id IN (?)', variants).select('DISTINCT enterprises.*') } diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 4861157d87..692509890d 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -111,6 +111,7 @@ describe Enterprise do it { should delegate(:city).to(:address) } it { should delegate(:state_name).to(:address) } end + describe "scopes" do describe 'active' do it 'find active enterprises' do @@ -120,6 +121,17 @@ describe Enterprise do end end + describe "confirmed" do + it "find enterprises with a confirmed date" do + s1 = create(:supplier_enterprise, confirmed_at: Time.now) + d1 = create(:distributor_enterprise, confirmed_at: Time.now) + s2 = create(:supplier_enterprise, confirmed_at: nil) + d2 = create(:distributor_enterprise, confirmed_at: nil) + expect(Enterprise.confirmed).to include s1, d1 + expect(Enterprise.confirmed).to_not include s2, d2 + end + end + describe "distributors_with_active_order_cycles" do it "finds active distributors by order cycles" do s = create(:supplier_enterprise) From c76a3815c03eac35f02f611beda7aeb2038c8290 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 15:45:47 +1100 Subject: [PATCH 076/142] Add unconfirmed scope --- app/models/enterprise.rb | 1 + spec/models/enterprise_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 977b35390b..954667f3e1 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -62,6 +62,7 @@ class Enterprise < ActiveRecord::Base scope :by_name, order('name') scope :visible, where(:visible => true) scope :confirmed, where('confirmed_at IS NOT NULL') + scope :unconfirmed, where('confirmed_at IS NULL') scope :is_primary_producer, where(:is_primary_producer => true) scope :is_distributor, where(:is_distributor => true) scope :supplying_variant_in, lambda { |variants| joins(:supplied_products => :variants_including_master).where('spree_variants.id IN (?)', variants).select('DISTINCT enterprises.*') } diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 692509890d..7dc1d986a1 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -132,6 +132,17 @@ describe Enterprise do end end + describe "unconfirmed" do + it "find enterprises without a confirmed date" do + s1 = create(:supplier_enterprise, confirmed_at: Time.now) + d1 = create(:distributor_enterprise, confirmed_at: Time.now) + s2 = create(:supplier_enterprise, confirmed_at: nil) + d2 = create(:distributor_enterprise, confirmed_at: nil) + expect(Enterprise.unconfirmed).to_not include s1, d1 + expect(Enterprise.unconfirmed).to include s2, d2 + end + end + describe "distributors_with_active_order_cycles" do it "finds active distributors by order cycles" do s = create(:supplier_enterprise) From c59662758caaf9f60a3899bedf06fc6c0975a4a1 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 15:46:21 +1100 Subject: [PATCH 077/142] Add alerts for unconfirmed enterprises to overview page --- app/assets/stylesheets/admin/alert.css.sass | 10 +++++++++ .../admin/overview/_unconfirmed.html.haml | 4 ++++ .../spree/admin/overview/index.html.haml | 21 ++++++++++--------- 3 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 app/assets/stylesheets/admin/alert.css.sass create mode 100644 app/views/spree/admin/overview/_unconfirmed.html.haml diff --git a/app/assets/stylesheets/admin/alert.css.sass b/app/assets/stylesheets/admin/alert.css.sass new file mode 100644 index 0000000000..5404e1a0e2 --- /dev/null +++ b/app/assets/stylesheets/admin/alert.css.sass @@ -0,0 +1,10 @@ +.alert + border: 3px solid #DA5354 + border-radius: 6px + margin-bottom: 20px + color: #DA5354 + padding: 5px 10px + h6 + color: #DA5354 + .message + font-weight: bold diff --git a/app/views/spree/admin/overview/_unconfirmed.html.haml b/app/views/spree/admin/overview/_unconfirmed.html.haml new file mode 100644 index 0000000000..05c4df2a0d --- /dev/null +++ b/app/views/spree/admin/overview/_unconfirmed.html.haml @@ -0,0 +1,4 @@ +- @enterprises.unconfirmed.each do |enterprise| + .alert + %h6= "Action Required: Please confirm the email address for #{enterprise.name}." + %span.message= "We've sent a confirmation email to #{enterprise.email}, so please check there for further instructions. Thanks!" \ No newline at end of file diff --git a/app/views/spree/admin/overview/index.html.haml b/app/views/spree/admin/overview/index.html.haml index a46a31b404..0709ceb54f 100644 --- a/app/views/spree/admin/overview/index.html.haml +++ b/app/views/spree/admin/overview/index.html.haml @@ -1,17 +1,18 @@ %h1{ :style => 'margin-bottom: 30px'} Dashboard -- if @enterprises.empty? +- if @enterprises.unconfirmed.any? - = render partial: "spree/admin/overview/enterprises" + = render partial: "spree/admin/overview/unconfirmed" -- else - - if can? :admin, Spree::Product - = render partial: "spree/admin/overview/products" + %hr - %div.two.columns -   +- if can? :admin, Spree::Product + = render partial: "spree/admin/overview/products" - - if can? :admin, OrderCycle - = render partial: "spree/admin/overview/order_cycles" + %div.two.columns +   - = render partial: "spree/admin/overview/enterprises" +- if can? :admin, OrderCycle + = render partial: "spree/admin/overview/order_cycles" + += render partial: "spree/admin/overview/enterprises" From e0e8ba814f1f1122716a663c8b9c294ff572f273 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 16:20:45 +1100 Subject: [PATCH 078/142] Show explanation of confirm process on final page of registration --- .../templates/registration/finished.html.haml | 16 +++++++++------- .../templates/registration/social.html.haml | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/templates/registration/finished.html.haml b/app/assets/javascripts/templates/registration/finished.html.haml index 75489c607a..3d0daf5633 100644 --- a/app/assets/javascripts/templates/registration/finished.html.haml +++ b/app/assets/javascripts/templates/registration/finished.html.haml @@ -2,17 +2,19 @@ .header %h2 Well done! %h5 - You have successfully completed the profile for + That's all of the details we need for %span.brick{"ng-show" => "enterprise.is_distributor"} {{ enterprise.name }} %span.turquoise{"ng-show" => "!enterprise.is_distributor" } {{ enterprise.name }} .content{ style: 'text-align: center'} - %h3 Why not check it out on the Open Food Network? - %a.button.primary{ type: "button", href: "/map" } Go to Map Page > - %br - %br + %h3 There's just one last thing we need you to do: + %h5 We've sent a confirmation email to {{ enterprise.email }}, so please follow the instructions there to finalise the creation of your enterprise. - %h3 Next step - add some products: - %a.button.primary{ type: "button", href: "/admin/products/new" } Add a Product > + -# perhaps a pretty picture here? + + %br/ + %br/ + + %a.button.primary{ type: "button", href: "/" } Take me home > diff --git a/app/assets/javascripts/templates/registration/social.html.haml b/app/assets/javascripts/templates/registration/social.html.haml index 1b3490ffa0..f9d958e7e8 100644 --- a/app/assets/javascripts/templates/registration/social.html.haml +++ b/app/assets/javascripts/templates/registration/social.html.haml @@ -1,6 +1,6 @@ .container#registration-social .header - %h2 Last step! + %h2 Almost there! %h5 How can people find {{ enterprise.name }} online? %ng-include{ src: "'registration/steps.html'" } %form{ name: 'social', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "update('finished',social)" } } From 0940af6b660e3d1673b3539e343176009be7ada5 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 16:21:11 +1100 Subject: [PATCH 079/142] Remove bad pry --- app/serializers/api/enterprise_serializer.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index ce3412ab10..d750704657 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -103,7 +103,6 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer has_one :address, serializer: Api::AddressSerializer def visible - binding.pry object.visible && object.confirmed? end From 20cb11a298ecd357fa18823e145f17481e131b62 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 16:28:52 +1100 Subject: [PATCH 080/142] Update registration spec --- spec/features/consumer/registration_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index 7ac46a8970..e8a7e4aa09 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -75,7 +75,7 @@ feature "Registration", js: true do click_button 'Continue' # Filling in social - expect(page).to have_content 'Last step!' + expect(page).to have_content 'Almost there!' fill_in 'enterprise_website', with: 'www.shop.com' fill_in 'enterprise_facebook', with: 'FaCeBoOk' fill_in 'enterprise_linkedin', with: 'LiNkEdIn' @@ -84,7 +84,7 @@ feature "Registration", js: true do click_button 'Continue' # Done - expect(page).to have_content "You have successfully completed the profile for My Awesome Enterprise" + expect(page).to have_content "That's all of the details we need for My Awesome Enterprise" e.reload expect(e.website).to eq "www.shop.com" expect(e.facebook).to eq "FaCeBoOk" From 96878f5dcb373a9a900086525cbd5953e67c6cf7 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 17:22:56 +1100 Subject: [PATCH 081/142] Don't require confirmation for enterprises where the email address has already been confirmed for another enterprise --- app/models/enterprise.rb | 6 ++++++ spec/models/enterprise_spec.rb | 22 ++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 954667f3e1..1bcd989f2a 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -8,6 +8,8 @@ class Enterprise < ActiveRecord::Base acts_as_gmappable :process_geocoding => false + before_create :check_email + after_create :send_creation_email has_and_belongs_to_many :groups, class_name: 'EnterpriseGroup' @@ -272,6 +274,10 @@ class Enterprise < ActiveRecord::Base private + def check_email + skip_confirmation! if owner.enterprises.confirmed.map(&:email).include?(email) + end + def send_creation_email EnterpriseMailer.creation_confirmation(self).deliver end diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 7dc1d986a1..6f828b2f10 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -3,12 +3,22 @@ require 'spec_helper' describe Enterprise do include AuthenticationWorkflow - describe "creation" do - it "should send a confirmation email" do - mail_message = double "Mail::Message" - EnterpriseMailer.should_receive(:confirmation_instructions).and_return mail_message - mail_message.should_receive :deliver - create(:enterprise) + describe "sending emails" do + describe "on creation" do + let!(:user) { create_enterprise_user( enterprise_limit: 2 ) } + let!(:enterprise) { create(:enterprise, owner: user, confirmed_at: Time.now) } + + it "when the email address has not already been confirmed" do + mail_message = double "Mail::Message" + EnterpriseMailer.should_receive(:confirmation_instructions).and_return mail_message + mail_message.should_receive :deliver + create(:enterprise, owner: user, email: "unknown@email.com" ) + end + + it "when the email address has already been confirmed" do + EnterpriseMailer.should_not_receive(:confirmation_instructions) + e = create(:enterprise, owner: user, email: enterprise.email) + end end end From 0d715ce61551b4acc9e54f165d200b5034d4409c Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 10 Oct 2014 19:36:37 +1100 Subject: [PATCH 082/142] split report permissions --- app/models/spree/ability_decorator.rb | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index 5fdb4c2342..a62eae3935 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -1,6 +1,8 @@ class AbilityDecorator include CanCan::Ability + # All abilites are allocated from this initialiser, currently in 5 chunks. + # Spree also defines other abilities. def initialize(user) add_base_abilities user if is_new_user? user add_enterprise_management_abilities user if can_manage_enterprises? user @@ -9,19 +11,22 @@ class AbilityDecorator add_relationship_management_abilities user if can_manage_relationships? user end - + # New users have no enterprises. def is_new_user?(user) user.enterprises.blank? end + # Users can manage an enterprise if they have one. def can_manage_enterprises?(user) user.enterprises.present? end + # Users can manage products if they have an enterprise. def can_manage_products?(user) can_manage_enterprises? user end + # Users can manage orders if they have a sells own/any enterprise. def can_manage_orders?(user) ( user.enterprises.map(&:type) & %w(single full) ).any? end @@ -30,6 +35,7 @@ class AbilityDecorator can_manage_enterprises? user end + # New users can create an enterprise, and gain other permissions from doing this. def add_base_abilities(user) can [:create], Enterprise end @@ -47,6 +53,12 @@ class AbilityDecorator can [:read, :edit, :update, :bulk_update], Enterprise do |enterprise| user.enterprises.include? enterprise end + + # All enterprises can have fees, though possibly suppliers don't need them? + can [:index, :create], EnterpriseFee + can [:admin, :read, :edit, :bulk_update, :destroy], EnterpriseFee do |enterprise_fee| + user.enterprises.include? enterprise_fee.enterprise + end end def add_product_management_abilities(user) @@ -66,6 +78,9 @@ class AbilityDecorator can [:admin, :index, :read, :search], Spree::Taxon can [:admin, :index, :read, :create, :edit], Spree::Classification + + # Reports page + can [:admin, :index, :customers, :orders_and_fulfillment, :products_and_inventory], :report end def add_order_management_abilities(user) @@ -76,7 +91,7 @@ class AbilityDecorator # during the order creation process from the admin backend order.distributor.nil? || user.enterprises.include?(order.distributor) end - can [:admin, :bulk_management], Spree::Order if user.admin? || user.enterprises.any?(&:is_distributor?) + can [:admin, :bulk_management], Spree::Order if user.admin? || user.enterprises.any?(&:is_distributor) can [:admin, :create], Spree::LineItem can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Payment @@ -90,11 +105,6 @@ class AbilityDecorator end can [:for_order_cycle], Enterprise - can [:index, :create], EnterpriseFee - can [:admin, :read, :edit, :bulk_update, :destroy], EnterpriseFee do |enterprise_fee| - user.enterprises.include? enterprise_fee.enterprise - end - can [:admin, :index, :read, :create, :edit, :update], ExchangeVariant can [:admin, :index, :read, :create, :edit, :update], Exchange can [:admin, :index, :read, :create, :edit, :update], ExchangeFee @@ -111,7 +121,7 @@ class AbilityDecorator end # Reports page - can [:admin, :index, :customers, :orders_and_distributors, :group_buys, :bulk_coop, :payments, :orders_and_fulfillment, :products_and_inventory], :report + can [:admin, :index, :customers, :group_buys, :bulk_coop, :payments, :orders_and_fulfillment, :products_and_inventory], :report end From e44fed2ff0cb6d7ea6a8a733caf1a672c94ac9c7 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 12 Oct 2014 14:00:32 +1100 Subject: [PATCH 083/142] add authorization to reports listings on index page --- .../spree/admin/reports_controller_decorator.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index 0abfd783b5..c7f5aa363a 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -608,12 +608,10 @@ Spree::Admin::ReportsController.class_eval do :payments => {:name => "Payment Reports", :description => "Reports for Payments"}, :orders_and_fulfillment => {:name => "Orders & Fulfillment Reports", :description => ''}, :customers => {:name => "Customers", :description => 'Customer details'}, - :products_and_inventory => {:name => "Products & Inventory", :description => ''} + :products_and_inventory => {:name => "Products & Inventory", :description => ''}, + :sales_total => { :name => "Sales Total", :description => "Sales Total For All Orders" } } - if spree_current_user.has_spree_role? 'admin' - reports[:sales_total] = { :name => "Sales Total", :description => "Sales Total For All Orders" } - end - reports + reports.select { |action, details| can? action, :report } end def total_units(line_items) From 46df14c0d96290ba928d8d35decec94c22d7936e Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 12 Oct 2014 14:13:52 +1100 Subject: [PATCH 084/142] refator reports controller a little --- .../admin/reports_controller_decorator.rb | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index c7f5aa363a..3a3ca9de48 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -6,24 +6,6 @@ require 'open_food_network/order_grouper' require 'open_food_network/customers_report' Spree::Admin::ReportsController.class_eval do - # Fetches user's distributors, suppliers and order_cycles - before_filter :load_data, only: [:customers, :products_and_inventory] - - # Render a partial for orders and fulfillment description - respond_override :index => { :html => { :success => lambda { - @reports[:orders_and_fulfillment][:description] = - render_to_string(partial: 'orders_and_fulfillment_description', layout: false, locals: {report_types: REPORT_TYPES[:orders_and_fulfillment]}).html_safe - @reports[:products_and_inventory][:description] = - render_to_string(partial: 'products_and_inventory_description', layout: false, locals: {report_types: REPORT_TYPES[:products_and_inventory]}).html_safe - @reports[:customers][:description] = - render_to_string(partial: 'customers_description', layout: false, locals: {report_types: REPORT_TYPES[:customers]}).html_safe - } } } - - # OVERRIDING THIS so we use a method not a constant for available reports - def index - @reports = available_reports - respond_with(@reports) - end REPORT_TYPES = { orders_and_fulfillment: [ @@ -42,6 +24,26 @@ Spree::Admin::ReportsController.class_eval do ] } + # Fetches user's distributors, suppliers and order_cycles + before_filter :load_data, only: [:customers, :products_and_inventory] + + # Render a partial for orders and fulfillment description + respond_override :index => { :html => { :success => lambda { + @reports[:orders_and_fulfillment][:description] = + render_to_string(partial: 'orders_and_fulfillment_description', layout: false, locals: {report_types: REPORT_TYPES[:orders_and_fulfillment]}).html_safe + @reports[:products_and_inventory][:description] = + render_to_string(partial: 'products_and_inventory_description', layout: false, locals: {report_types: REPORT_TYPES[:products_and_inventory]}).html_safe + @reports[:customers][:description] = + render_to_string(partial: 'customers_description', layout: false, locals: {report_types: REPORT_TYPES[:customers]}).html_safe + } } } + + + # Overide spree reports list. + def index + @reports = authorized_reports + respond_with(@reports) + end + # This action is short because we refactored it like bosses def customers @report_types = REPORT_TYPES[:customers] @@ -601,7 +603,7 @@ Spree::Admin::ReportsController.class_eval do @order_cycles = OrderCycle.active_or_complete.accessible_by(spree_current_user).order('orders_close_at DESC') end - def available_reports + def authorized_reports reports = { :orders_and_distributors => {:name => "Orders And Distributors", :description => "Orders with distributor details"}, :bulk_coop => {:name => "Bulk Co-Op", :description => "Reports for Bulk Co-Op orders"}, @@ -611,7 +613,8 @@ Spree::Admin::ReportsController.class_eval do :products_and_inventory => {:name => "Products & Inventory", :description => ''}, :sales_total => { :name => "Sales Total", :description => "Sales Total For All Orders" } } - reports.select { |action, details| can? action, :report } + # Return only reports the user is authorized to view. + reports.select { |action| can? action, :report } end def total_units(line_items) From 1577c01a77300830196eb9115c6907dda2e0b965 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 12 Oct 2014 22:21:59 +1100 Subject: [PATCH 085/142] add reports abilities specs --- spec/models/spree/ability_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index 2d2d1cfb01..62e1973e7f 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -151,6 +151,14 @@ module Spree should_not have_ability(:destroy, for: er2) end + it "should be able to read some reports" do + should have_ability([:admin, :index, :customers, :orders_and_fulfillment, :products_and_inventory], for: :reports) + end + + it "should not be able to read other reports" do + should_not have_ability([:sales_total, :group_buys, :bulk_coop, :payments], for: :reports) + end + end context "when is a distributor enterprise user" do @@ -237,6 +245,15 @@ module Spree it "should not be able to destroy enterprise relationships for other enterprises" do should_not have_ability(:destroy, for: er1) end + + it "should be able to read some reports" do + should have_ability([:admin, :index, :customers, :group_buys, :bulk_coop, :payments, :orders_and_fulfillment, :products_and_inventory], for: :reports) + end + + it "should not be able to read other reports" do + should_not have_ability([:sales_total], for: :reports) + end + end context 'Order Cycle co-ordinator' do From 9343c3608b8999dd3be8d39883be60564023a96c Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 12 Oct 2014 22:22:35 +1100 Subject: [PATCH 086/142] allow supplier enterprise manager to see bulk coop reports --- app/models/spree/ability_decorator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index a62eae3935..abf4aeac66 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -80,7 +80,7 @@ class AbilityDecorator can [:admin, :index, :read, :create, :edit], Spree::Classification # Reports page - can [:admin, :index, :customers, :orders_and_fulfillment, :products_and_inventory], :report + can [:admin, :index, :customers, :bulk_coop, :orders_and_fulfillment, :products_and_inventory], :report end def add_order_management_abilities(user) From fd7191f476549d187fdef676540b1f7b149f92d4 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 16 Oct 2014 05:26:38 +1100 Subject: [PATCH 087/142] add missing orders_and_distributors perm --- app/models/spree/ability_decorator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index abf4aeac66..2d4831ec0b 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -121,7 +121,7 @@ class AbilityDecorator end # Reports page - can [:admin, :index, :customers, :group_buys, :bulk_coop, :payments, :orders_and_fulfillment, :products_and_inventory], :report + can [:admin, :index, :customers, :group_buys, :bulk_coop, :payments, :orders_and_distributors, :orders_and_fulfillment, :products_and_inventory], :report end From 63e50dc88cc8b49539395b0bb8d5fda8db16c721 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 16 Oct 2014 11:34:06 +1100 Subject: [PATCH 088/142] Fiddle with alert styling --- app/assets/stylesheets/admin/alert.css.sass | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/admin/alert.css.sass b/app/assets/stylesheets/admin/alert.css.sass index 5404e1a0e2..d86cb38f55 100644 --- a/app/assets/stylesheets/admin/alert.css.sass +++ b/app/assets/stylesheets/admin/alert.css.sass @@ -1,10 +1,15 @@ .alert - border: 3px solid #DA5354 + border: 3px solid #919191 border-radius: 6px margin-bottom: 20px - color: #DA5354 + color: #919191 padding: 5px 10px h6 - color: #DA5354 + color: #919191 .message font-weight: bold + &:hover + border-color: #DA5354 + color: #DA5354 + h6 + color: #DA5354 From 7e23479f3a0af1f79b1a9dae19124925d5964045 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 16 Oct 2014 12:08:12 +1100 Subject: [PATCH 089/142] Consistency --- spec/features/admin/variants_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/admin/variants_spec.rb b/spec/features/admin/variants_spec.rb index 1904f3d5af..19767d8ea2 100644 --- a/spec/features/admin/variants_spec.rb +++ b/spec/features/admin/variants_spec.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require 'spec_helper' feature %q{ As an admin From 0e03b5f2097c619da588aeba282ffce58db2ef15 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 16 Oct 2014 12:41:11 +1100 Subject: [PATCH 090/142] Admin can change the format that Spree::Images are stored/served in --- .../image_settings_controller_decorator.rb | 11 +++++ app/helpers/admin/image_settings_helper.rb | 21 +++++++++ app/models/spree/image_decorator.rb | 23 ++++++++++ .../edit/add_image_format.html.haml.deface | 11 +++++ spec/features/admin/image_settings_spec.rb | 43 +++++++++++++++++++ spec/models/spree/image_spec.rb | 18 ++++++++ 6 files changed, 127 insertions(+) create mode 100644 app/controllers/spree/admin/image_settings_controller_decorator.rb create mode 100644 app/helpers/admin/image_settings_helper.rb create mode 100644 app/models/spree/image_decorator.rb create mode 100644 app/overrides/spree/admin/image_settings/edit/add_image_format.html.haml.deface create mode 100644 spec/features/admin/image_settings_spec.rb create mode 100644 spec/models/spree/image_spec.rb diff --git a/app/controllers/spree/admin/image_settings_controller_decorator.rb b/app/controllers/spree/admin/image_settings_controller_decorator.rb new file mode 100644 index 0000000000..5fe7dae551 --- /dev/null +++ b/app/controllers/spree/admin/image_settings_controller_decorator.rb @@ -0,0 +1,11 @@ +Spree::Admin::ImageSettingsController.class_eval do + # Spree stores attachent definitions in JSON. This converts the style name and format to + # strings. However, when paperclip encounters these, it doesn't recognise the format. + # Here we solve that problem by converting format and style name to symbols. + def update_paperclip_settings_with_format_styles + update_paperclip_settings_without_format_styles + Spree::Image.reformat_styles + end + + alias_method_chain :update_paperclip_settings, :format_styles +end diff --git a/app/helpers/admin/image_settings_helper.rb b/app/helpers/admin/image_settings_helper.rb new file mode 100644 index 0000000000..10c34fe372 --- /dev/null +++ b/app/helpers/admin/image_settings_helper.rb @@ -0,0 +1,21 @@ +module Admin + module ImageSettingsHelper + def admin_image_settings_format_options + [['Unchanged', ''], ['PNG', 'png'], ['JPEG', 'jpg']] + end + + def admin_image_settings_geometry_from_style(style) + geometry, format = admin_image_settings_split_style style + geometry + end + + def admin_image_settings_format_from_style(style) + geometry, format = admin_image_settings_split_style style + format + end + + def admin_image_settings_split_style(style) + [style, nil].flatten[0..1] + end + end +end diff --git a/app/models/spree/image_decorator.rb b/app/models/spree/image_decorator.rb new file mode 100644 index 0000000000..7d86aae3a6 --- /dev/null +++ b/app/models/spree/image_decorator.rb @@ -0,0 +1,23 @@ +Spree::Image.class_eval do + # Spree stores attachent definitions in JSON. This converts the style name and format to + # strings. However, when paperclip encounters these, it doesn't recognise the format. + # Here we solve that problem by converting format and style name to symbols. + # See also: ImageSettingsController decorator. + # + # eg. {'mini' => ['48x48>', 'png']} is converted to {mini: ['48x48>', :png]} + def self.format_styles(styles) + styles_a = styles.map do |name, style| + style[1] = style[1].to_sym if style.is_a? Array + [name.to_sym, style] + end + + Hash[styles_a] + end + + def self.reformat_styles + Spree::Image.attachment_definitions[:attachment][:styles] = + format_styles(Spree::Image.attachment_definitions[:attachment][:styles]) + end + + reformat_styles +end diff --git a/app/overrides/spree/admin/image_settings/edit/add_image_format.html.haml.deface b/app/overrides/spree/admin/image_settings/edit/add_image_format.html.haml.deface new file mode 100644 index 0000000000..deb79b5bbf --- /dev/null +++ b/app/overrides/spree/admin/image_settings/edit/add_image_format.html.haml.deface @@ -0,0 +1,11 @@ +/ replace_contents '#styles_list' + +- @styles.each_with_index do |(style_name, style_value), index| + .field.three.columns + = label_tag "attachment_styles[#{style_name}]", style_name + %a.destroy_style.with-tip{:alt => t(:destroy), :href => "#", :title => t(:destroy)} + %i.icon-trash + = text_field_tag "attachment_styles[#{style_name}][]", admin_image_settings_geometry_from_style(style_value), :class => 'fullwidth' + %br/ + - current_format = admin_image_settings_format_from_style(style_value) || '' + = select_tag "attachment_styles[#{style_name}][]", options_for_select(admin_image_settings_format_options, current_format), :class => 'fullwidth', :id => "attachment_styles_format_#{style_name}" diff --git a/spec/features/admin/image_settings_spec.rb b/spec/features/admin/image_settings_spec.rb new file mode 100644 index 0000000000..a83a072235 --- /dev/null +++ b/spec/features/admin/image_settings_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +feature %q{ + As an admin + I want to manage image formats +} do + include AuthenticationWorkflow + include WebHelper + + before(:all) do + styles = {"mini" => "48x48>", + "small" => "100x100>", + "product" => "240x240>", + "large" => "600x600>"} + + Spree::Config[:attachment_styles] = ActiveSupport::JSON.encode(styles) + Spree::Image.attachment_definitions[:attachment][:styles] = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles]) + Spree::Image.reformat_styles + end + + scenario "setting the image format for a paperclip style" do + # When I go to the image settings page + login_to_admin_section + visit spree.edit_admin_image_settings_path + + # All the styles should default to "Unchanged" + page.should have_select 'attachment_styles_format_mini', selected: 'Unchanged' + page.should have_select 'attachment_styles_format_small', selected: 'Unchanged' + page.should have_select 'attachment_styles_format_product', selected: 'Unchanged' + page.should have_select 'attachment_styles_format_large', selected: 'Unchanged' + + # When I change a style to "PNG" and save + select 'PNG', from: 'attachment_styles_format_mini' + click_button 'Update' + + # Then the change should be saved to the image formats + page.should have_content "Image Settings successfully updated." + page.should have_select 'attachment_styles_format_mini', selected: 'PNG' + + styles = Spree::Image.attachment_definitions[:attachment][:styles] + styles[:mini].should == ['48x48>', :png] + end +end diff --git a/spec/models/spree/image_spec.rb b/spec/models/spree/image_spec.rb new file mode 100644 index 0000000000..56665fa641 --- /dev/null +++ b/spec/models/spree/image_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +module Spree + describe Image do + describe "attachment definitions" do + let(:name_str) { {"mini" => "48x48>"} } + let(:formatted) { {mini: ["48x48>", "png"]} } + + it "converts style names to symbols" do + Image.format_styles(name_str).should == {:mini => "48x48>"} + end + + it "converts formats to symbols" do + Image.format_styles(formatted).should == {:mini => ["48x48>", :png]} + end + end + end +end From 2e8417d9e867dc2764452ac89fd0e24179b18d7a Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 16 Oct 2014 16:05:07 +1100 Subject: [PATCH 091/142] bugfix migration and add indexes --- db/migrate/20140927005043_enterprise_config_refactor.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/db/migrate/20140927005043_enterprise_config_refactor.rb b/db/migrate/20140927005043_enterprise_config_refactor.rb index 3b3265333d..e50b4497d7 100644 --- a/db/migrate/20140927005043_enterprise_config_refactor.rb +++ b/db/migrate/20140927005043_enterprise_config_refactor.rb @@ -1,6 +1,8 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration def up add_column :enterprises, :sells, :string, null: false, default: 'none' + add_index :enterprises, :sells + add_index :enterprises, [:is_primary_producer, :sells] Enterprise.all.each do |enterprise| enterprise.update_attributes({:sells => sells_what?(enterprise)}) @@ -23,10 +25,13 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration end remove_column :enterprises, :sells + remove_index :enterprises, :sells + remove_index :enterprises, [:is_primary_producer, :sells] end def sells_what?(enterprise) is_distributor = enterprise.read_attribute(:is_distributor) + is_primary_producer = enterprise.read_attribute(:is_primary_producer) type = enterprise.read_attribute(:type) return "own" if type == "single" && (is_distributor || is_primary_producer) return "none" if !is_distributor || type == "profile" From 7db68795a4c64dffb989ba2b00e9c23c3d0c63ab Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 16 Oct 2014 16:06:54 +1100 Subject: [PATCH 092/142] Redirect to admin root after confirmation --- .../devise/confirmations_controller_decorator.rb | 7 +++++++ .../devise/confirmation_controller_spec.rb | 15 +++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 app/controllers/devise/confirmations_controller_decorator.rb create mode 100644 spec/controllers/devise/confirmation_controller_spec.rb diff --git a/app/controllers/devise/confirmations_controller_decorator.rb b/app/controllers/devise/confirmations_controller_decorator.rb new file mode 100644 index 0000000000..ef34f28445 --- /dev/null +++ b/app/controllers/devise/confirmations_controller_decorator.rb @@ -0,0 +1,7 @@ +Devise::ConfirmationsController.class_eval do + protected + # Override of devise method in Devise::ConfirmationsController + def after_confirmation_path_for(resource_name, resource) + spree.admin_path + end +end \ No newline at end of file diff --git a/spec/controllers/devise/confirmation_controller_spec.rb b/spec/controllers/devise/confirmation_controller_spec.rb new file mode 100644 index 0000000000..eda5dc4823 --- /dev/null +++ b/spec/controllers/devise/confirmation_controller_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe Devise::ConfirmationsController do + context "after confirmation" do + before do + e = create(:enterprise) + @request.env["devise.mapping"] = Devise.mappings[:enterprise] + spree_get :show, confirmation_token: e.confirmation_token + end + + it "should redirect to admin root" do + expect(response).to redirect_to spree.admin_path + end + end +end \ No newline at end of file From f0a3296e521ef61e285036a5b670085b683ff436 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 16 Oct 2014 16:22:18 +1100 Subject: [PATCH 093/142] change enterprise category name ans use symbols instead of strings --- .../darkswarm/services/enterprises.js.coffee | 4 +- .../darkswarm/services/variants.js.coffee | 3 +- app/models/enterprise.rb | 25 +++++------- .../api/admin/enterprise_serializer.rb | 2 +- app/serializers/api/enterprise_serializer.rb | 38 +++++++++---------- .../_sidebar_enterprise_fees.html.haml | 2 +- .../services/enterprise_spec.js.coffee | 16 ++++---- spec/models/enterprise_spec.rb | 12 +++--- 8 files changed, 48 insertions(+), 54 deletions(-) diff --git a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee index 7e6aa0a1c7..6040f1d150 100644 --- a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee @@ -12,9 +12,9 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer, @dereferenceTaxons() @visible_enterprises = visibleFilter @enterprises @producers = @visible_enterprises.filter (enterprise)-> - enterprise.enterprise_category in ["producer_hub", "producer_shop", "producer"] + enterprise.category in ["producer_hub", "producer_shop", "producer"] @hubs = @visible_enterprises.filter (enterprise)-> - enterprise.enterprise_category in ["hub", "hub_profile", "producer_hub", "producer_shop"] + enterprise.category in ["hub", "hub_profile", "producer_hub", "producer_shop"] dereferenceEnterprises: -> if CurrentHub.hub?.id diff --git a/app/assets/javascripts/darkswarm/services/variants.js.coffee b/app/assets/javascripts/darkswarm/services/variants.js.coffee index 1b87be5369..6562bd9e0b 100644 --- a/app/assets/javascripts/darkswarm/services/variants.js.coffee +++ b/app/assets/javascripts/darkswarm/services/variants.js.coffee @@ -5,8 +5,7 @@ Darkswarm.factory 'Variants', -> @variants[variant.id] ||= @extend variant extend: (variant)-> - # Add totalPrice and basPricePercentage methods to calculate line item values. - # This should probably be on a line item object! + # Add totalPrice method to calculate line item total. This should be on a line item! variant.totalPrice = -> variant.price_with_fees * variant.line_item.quantity variant.basePricePercentage = Math.round(variant.price / variant.price_with_fees * 100) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index c81ac042e5..ab4dccf8ec 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -215,31 +215,26 @@ class Enterprise < ActiveRecord::Base not self.sells == "none" end - def is_hub - self.enterprise_category.in Array['hub', 'hub_profile', 'producer_hub', 'producer_shop'] - end - # Simplify enterprise categories for frontend logic and icons, and maybe other things. - def enterprise_category + def category # Make this crazy logic human readable so we can argue about it sanely. - # This can be simplified later, it's like this for readablitlty during changes. - category = is_primary_producer ? "producer_" : "non_producer_" - category << "sells_" + sells + cat = is_primary_producer ? "producer_" : "non_producer_" + cat << "sells_" + sells # Map backend cases to front end cases. - case category + case cat when "producer_sells_any" - "producer_hub" # Producer hub who sells own and others produce and supplies other hubs. + :producer_hub # Producer hub who sells own and others produce and supplies other hubs. when "producer_sells_own" - "producer_shop" # Producer with shopfront and supplies other hubs. + :producer_shop # Producer with shopfront and supplies other hubs. when "producer_sells_none" - "producer" # Producer only supplies through others. + :producer # Producer only supplies through others. when "non_producer_sells_any" - "hub" # Hub selling others products in order cycles. + :hub # Hub selling others products in order cycles. when "non_producer_sells_own" - "hub" # Wholesaler selling through own shopfront? Does this need a separate name? Should it exist? + :hub # Wholesaler selling through own shopfront? Does this need a separate name? Should it exist? when "non_producer_sells_none" - "hub_profile" # Hub selling outside the system. + :hub_profile # Hub selling outside the system. end end diff --git a/app/serializers/api/admin/enterprise_serializer.rb b/app/serializers/api/admin/enterprise_serializer.rb index 5164256424..e6d00b7aae 100644 --- a/app/serializers/api/admin/enterprise_serializer.rb +++ b/app/serializers/api/admin/enterprise_serializer.rb @@ -1,3 +1,3 @@ class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer - attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :payment_method_ids, :shipping_method_ids + attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :category, :payment_method_ids, :shipping_method_ids end diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index 892027c5a0..3e6708b526 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -36,7 +36,7 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer :long_description, :website, :instagram, :linkedin, :twitter, :facebook, :is_primary_producer, :is_distributor, :phone, :visible, :email, :hash, :logo, :promo_image, :path, :pickup, :delivery, - :icon, :icon_font, :producer_icon_font, :enterprise_category + :icon, :icon_font, :producer_icon_font, :category has_many :distributed_taxons, key: :taxons, serializer: Api::IdSerializer has_many :supplied_taxons, serializer: Api::IdSerializer @@ -78,25 +78,25 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer # Map svg icons. def icon icons = { - "hub" => "/assets/map_005-hub.svg", - "hub_profile" => "/assets/map_006-hub-profile.svg", - "producer_hub" => "/assets/map_005-hub.svg", - "producer_shop" => "/assets/map_003-producer-shop.svg", - "producer" => "/assets/map_001-producer-only.svg", + :hub => "/assets/map_005-hub.svg", + :hub_profile => "/assets/map_006-hub-profile.svg", + :producer_hub => "/assets/map_005-hub.svg", + :producer_shop => "/assets/map_003-producer-shop.svg", + :producer => "/assets/map_001-producer-only.svg", } - icons[object.enterprise_category] + icons[object.category] end # Choose regular icon font for enterprises. def icon_font icon_fonts = { - "hub" => "ofn-i_063-hub", - "hub_profile" => "ofn-i_064-hub-reversed", - "producer_hub" => "ofn-i_063-hub", - "producer_shop" => "ofn-i_059-producer", - "producer" => "ofn-i_059-producer", + :hub => "ofn-i_063-hub", + :hub_profile => "ofn-i_064-hub-reversed", + :producer_hub => "ofn-i_063-hub", + :producer_shop => "ofn-i_059-producer", + :producer => "ofn-i_059-producer", } - icon_fonts[object.enterprise_category] + icon_fonts[object.category] end # Choose producer page icon font - yes, sadly its got to be different. @@ -104,12 +104,12 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer # producer-hub has a producer icon without needing to duplicate the category logic in angular. def producer_icon_font icon_fonts = { - "hub" => "", - "hub_profile" => "", - "producer_hub" => "ofn-i_059-producer", - "producer_shop" => "ofn-i_059-producer", - "producer" => "ofn-i_059-producer", + :hub => "", + :hub_profile => "", + :producer_hub => "ofn-i_059-producer", + :producer_shop => "ofn-i_059-producer", + :producer => "ofn-i_059-producer", } - icon_fonts[object.enterprise_category] + icon_fonts[object.category] end end diff --git a/app/views/admin/enterprises/_sidebar_enterprise_fees.html.haml b/app/views/admin/enterprises/_sidebar_enterprise_fees.html.haml index b192201528..566d87b832 100644 --- a/app/views/admin/enterprises/_sidebar_enterprise_fees.html.haml +++ b/app/views/admin/enterprises/_sidebar_enterprise_fees.html.haml @@ -1,5 +1,5 @@ - enterprise_fees_color = @enterprise_fees.count > 0 ? "blue" : "red" -.sidebar_item.four.columns.alpha#enterprise_fees{ ng: { show: 'Enterprise.sells != "none" || Enterprise.is_primary_producer' } } +.sidebar_item.four.columns.alpha#enterprise_fees{ ng: { show: 'Enterprise.category != "producer_hub"' } } .four.columns.alpha.header{ class: "#{enterprise_fees_color}" } %span.four.columns.alpha.centered Enterprise Fees .four.columns.alpha.list{ class: "#{enterprise_fees_color}" } diff --git a/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee index ff051b1d43..94dd7d39d2 100644 --- a/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee @@ -5,14 +5,14 @@ describe "Enterprises service", -> {id: 1, name: "test"} ] enterprises = [ - {id: 1, visible: true, enterprise_category: "hub", producers: [{id: 5}], taxons: [{id: 1}]}, - {id: 2, visible: true, enterprise_category: "hub", producers: [{id: 6}]} - {id: 3, visible: true, enterprise_category: "hub_profile"} - {id: 4, visible: false, enterprise_category: "hub", producers: [{id: 7}]} - {id: 5, visible: true, enterprise_category: "producer_hub", hubs: [{id: 1}]}, - {id: 6, visible: true, enterprise_category: "producer_shop", hubs: [{id: 2}]}, - {id: 7, visible: true, enterprise_category: "producer", hubs: [{id: 2}]} - {id: 8, visible: false, enterprise_category: "producer", hubs: [{id: 2}]} + {id: 1, visible: true, category: "hub", producers: [{id: 5}], taxons: [{id: 1}]}, + {id: 2, visible: true, category: "hub", producers: [{id: 6}]} + {id: 3, visible: true, category: "hub_profile"} + {id: 4, visible: false, category: "hub", producers: [{id: 7}]} + {id: 5, visible: true, category: "producer_hub", hubs: [{id: 1}]}, + {id: 6, visible: true, category: "producer_shop", hubs: [{id: 2}]}, + {id: 7, visible: true, category: "producer", hubs: [{id: 2}]} + {id: 8, visible: false, category: "producer", hubs: [{id: 2}]} ] H1: 0 beforeEach -> diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index ccd4b6b75f..6fae275583 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -528,12 +528,12 @@ describe Enterprise do producer_sell_all.is_primary_producer.should == true producer_sell_all.sells.should == "any" - producer_sell_all.enterprise_category.should == "producer_hub" - producer_sell_own.enterprise_category.should == "producer_shop" - producer_sell_none.enterprise_category.should == "producer" - non_producer_sell_all.enterprise_category.should == "hub" - non_producer_sell_own.enterprise_category.should == "hub" - non_producer_sell_none.enterprise_category.should == "hub_profile" + producer_sell_all.category.should == :producer_hub + producer_sell_own.category.should == :producer_shop + producer_sell_none.category.should == :producer + non_producer_sell_all.category.should == :hub + non_producer_sell_own.category.should == :hub + non_producer_sell_none.category.should == :hub_profile end end end From 027189ac3c488ea48f97e71b8c3b22fe8d52b170 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 16 Oct 2014 16:23:20 +1100 Subject: [PATCH 094/142] rename check methods --- app/controllers/admin/enterprises_controller.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 1beb854a47..7d38e408d6 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -3,11 +3,11 @@ module Admin before_filter :load_enterprise_set, :only => :index before_filter :load_countries, :except => :index before_filter :load_methods_and_fees, :only => [:new, :edit, :update, :create] - before_filter :check_sells, only: :update - before_filter :check_bulk_sells, only: :bulk_update + before_filter :check_can_change_sells, only: :update + before_filter :check_can_change_bulk_sells, only: :bulk_update before_filter :override_owner, only: :create - before_filter :check_owner, only: :update - before_filter :check_bulk_owner, only: :bulk_update + before_filter :check_can_change_owner, only: :update + before_filter :check_can_change_bulk_owner, only: :bulk_update helper 'spree/products' include OrderCyclesHelper @@ -64,7 +64,7 @@ module Admin @enterprise_fees = EnterpriseFee.managed_by(spree_current_user).for_enterprise(@enterprise).order(:fee_type, :name).all end - def check_bulk_sells + def check_can_change_bulk_sells unless spree_current_user.admin? params[:enterprise_set][:collection_attributes].each do |i, enterprise_params| enterprise_params.delete :sells @@ -72,7 +72,7 @@ module Admin end end - def check_sells + def check_can_change_sells params[:enterprise].delete :sells unless spree_current_user.admin? end @@ -80,13 +80,13 @@ module Admin params[:enterprise][:owner_id] = spree_current_user.id unless spree_current_user.admin? end - def check_owner + def check_can_change_owner unless ( spree_current_user == @enterprise.owner ) || spree_current_user.admin? params[:enterprise].delete :owner_id end end - def check_bulk_owner + def check_can_change_bulk_owner unless spree_current_user.admin? params[:enterprise_set][:collection_attributes].each do |i, enterprise_params| enterprise_params.delete :owner_id From c5afd8cebffaffbc4e7aba9b776037286b3e28b7 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 16 Oct 2014 16:24:34 +1100 Subject: [PATCH 095/142] move visible filter to pages, and use category --- app/views/home/_hubs.html.haml | 4 ++-- app/views/producers/index.html.haml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/home/_hubs.html.haml b/app/views/home/_hubs.html.haml index 27aea75a7f..5f589f9cb4 100644 --- a/app/views/home/_hubs.html.haml +++ b/app/views/home/_hubs.html.haml @@ -10,8 +10,8 @@ .row{bindonce: true} .small-12.columns .active_table - %hub.active_table_node.row.animate-repeat{"ng-repeat" => "hub in filteredEnterprises = (Enterprises.hubs | searchEnterprises:query | taxons:activeTaxons | shipping:shippingTypes | showHubProfiles:show_profiles | orderBy:['-active', '+orders_close_at'])", - "ng-class" => "{'is_profile' : !hub.is_distributor, 'closed' : !open(), 'open' : open(), 'inactive' : !hub.active, 'current' : current()}", + %hub.active_table_node.row.animate-repeat{"ng-repeat" => "hub in filteredEnterprises = (Enterprises.hubs | visibleFilter | searchEnterprises:query | taxons:activeTaxons | shipping:shippingTypes | showHubProfiles:show_profiles | orderBy:['-active', '+orders_close_at'])", + "ng-class" => "{'is_profile' : hub.category == 'hub_profile', 'closed' : !open(), 'open' : open(), 'inactive' : !hub.active, 'current' : current()}", "scroll-after-load" => true, "ng-controller" => "HubNodeCtrl", id: "{{hub.hash}}"} diff --git a/app/views/producers/index.html.haml b/app/views/producers/index.html.haml index 114e7d8459..a59a0ac151 100644 --- a/app/views/producers/index.html.haml +++ b/app/views/producers/index.html.haml @@ -12,7 +12,7 @@ .active_table %producer.active_table_node.row.animate-repeat{id: "{{producer.path}}", "scroll-after-load" => true, - "ng-repeat" => "producer in filteredEnterprises = (Enterprises.producers | searchEnterprises:query | taxons:activeTaxons)", + "ng-repeat" => "producer in filteredEnterprises = (Enterprises.producers | visibleFilter | searchEnterprises:query | taxons:activeTaxons)", "ng-controller" => "ProducerNodeCtrl", "ng-class" => "{'closed' : !open(), 'open' : open(), 'inactive' : !producer.active}", id: "{{producer.hash}}"} From 425105174ee200986b6d4e3f12fdd8790a2700e1 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 16 Oct 2014 16:25:18 +1100 Subject: [PATCH 096/142] return space remover --- app/views/shared/components/_show_profiles.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shared/components/_show_profiles.html.haml b/app/views/shared/components/_show_profiles.html.haml index 6b714a1c6e..638cc47c27 100644 --- a/app/views/shared/components/_show_profiles.html.haml +++ b/app/views/shared/components/_show_profiles.html.haml @@ -1,6 +1,6 @@ .small-12.medium-6.columns.text-right .profile-checkbox - %button.button.secondary.tiny.help-btn.ng-scope{:popover => "Profiles do not have a shopfront on the Open Food Network, but may have their own physical or online shop elsewhere", "popover-placement" => "left"} + %button.button.secondary.tiny.help-btn.ng-scope{:popover => "Profiles do not have a shopfront on the Open Food Network, but may have their own physical or online shop elsewhere", "popover-placement" => "left"}>< %i.ofn-i_013-help %label %input{"ng-model" => "show_profiles", type: "checkbox", name: "profile"} From 8d01bb7ebfe20897459927c7377488834a18cc97 Mon Sep 17 00:00:00 2001 From: summerscope Date: Thu, 16 Oct 2014 16:45:15 +1100 Subject: [PATCH 097/142] Pretty responsive email template!!!!!!!! --- .../confirmation_instructions.html.haml | 101 +++++++++++++++++- 1 file changed, 98 insertions(+), 3 deletions(-) diff --git a/app/views/enterprise_mailer/confirmation_instructions.html.haml b/app/views/enterprise_mailer/confirmation_instructions.html.haml index 277e27aae5..19bab3f5ee 100644 --- a/app/views/enterprise_mailer/confirmation_instructions.html.haml +++ b/app/views/enterprise_mailer/confirmation_instructions.html.haml @@ -1,5 +1,100 @@ -%p= "Welcome #{@resource.contact}!" +/ ORIGINAL & UGLY: +/ %p= "Welcome #{@resource.contact}!" +/ %p= "Please confirm your email address for #{@resource.name}." +/ %p= "Click the link below to activate your enterprise:" +/ %p= link_to 'Confirm this email address', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) -%p= "You can confirm this email address for #{@resource.name} using the link below:" -%p= link_to 'Confirm this email address', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) \ No newline at end of file +%html{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;", :xmlns => "http://www.w3.org/1999/xhtml"} + %head{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + / If you delete this meta tag, Half Life 3 will never be released. + %meta{:content => "width=device-width", :name => "viewport", :style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"}/ + %meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type", :style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"}/ + %title{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} Open Food Network + %link{:href => "http://rohanmitchell.com/random/template/basic-email-template/stylesheets/email.css", :rel => "stylesheet", :style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;", :type => "text/css"}/ + %body{:bgcolor => "#FFFFFF", :style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;-webkit-font-smoothing: antialiased;-webkit-text-size-adjust: none;height: 100%;width: 100%!important;"} + / HEADER + %table.head-wrap{:bgcolor => "#333333", :style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;width: 100%;"} + %tr{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %td{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %td.header.container{:style => "margin: 0 auto!important;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;display: block!important;max-width: 600px!important;clear: both!important;"} + .content{:style => "margin: 0 auto;padding: 15px;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;max-width: 600px;display: block;"} + %table{:bgcolor => "#333333", :style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;width: 100%;"} + %tr{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %td{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %img{:src => "https://openfoodnetwork.org.au/assets/ofn_logo_beta-8e4dfc79deb25def2d107dea52dce492.png", :style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;max-width: 100%;", :width => "200"}/ + %td{:align => "right", :style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %h6.collapse{:style => "margin: 0!important;padding: 0;font-family: \"HelveticaNeue-Light\", \"Helvetica Neue Light\", \"Helvetica Neue\", Helvetica, Arial, \"Lucida Grande\", sans-serif;line-height: 1.1;margin-bottom: 15px;color: #999;font-weight: 900;font-size: 14px;text-transform: uppercase;"} Open Food Network + %td{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + / /HEADER + / BODY + %table.body-wrap{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;width: 100%;"} + %tr{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %td{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %td.container{:bgcolor => "#FFFFFF", :style => "margin: 0 auto!important;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;display: block!important;max-width: 600px!important;clear: both!important;"} + .content{:style => "margin: 0 auto;padding: 15px;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;max-width: 600px;display: block;"} + %table{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;width: 100%;"} + %tr{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %td{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %h3{:style => "margin: 0;padding: 0;font-family: \"HelveticaNeue-Light\", \"Helvetica Neue Light\", \"Helvetica Neue\", Helvetica, Arial, \"Lucida Grande\", sans-serif;line-height: 1.1;margin-bottom: 15px;color: #000;font-weight: 500;font-size: 27px;"}= "Welcome, #{@resource.contact}!" + %p.lead{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;margin-bottom: 10px;font-weight: normal;font-size: 17px;line-height: 1.6;"} + = "Please confirm email address for your enterprise " + %strong + = "#{@resource.name}." + %p   + / Callout Panel + %p.callout{:style => "margin: 0; padding: 15px;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;margin-bottom: 15px;font-weight: normal;font-size: 14px;line-height: 1.6;background-color: #e1f0f5;"} + = "Click the link below to confirm email and to activate your enterprise. This link can be used only once:" + %br + %strong + = link_to 'Confirm this email address »', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) + / /Callout Panel + %p   + %p{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;margin-bottom: 10px;font-weight: normal;font-size: 14px;line-height: 1.6;"}= "We're so excited that you're joining the Open Food Network! Don't hestitate to get in touch if you have any questions." + %p   + / social & contact + %table.social{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;background-color: #ebebeb;width: 100%;", :width => "100%"} + %tr{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %td{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + / column 1 + %table.column{:align => "left", :style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;width: 280px;float: left;min-width: 279px;"} + %tr{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %td{:style => "margin: 0;padding: 15px;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %h5{:style => "margin: 0;padding: 0;font-family: \"HelveticaNeue-Light\", \"Helvetica Neue Light\", \"Helvetica Neue\", Helvetica, Arial, \"Lucida Grande\", sans-serif;line-height: 1.1;margin-bottom: 15px;color: #000;font-weight: 900;font-size: 17px;"} Connect with Us: + %p{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;margin-bottom: 10px;font-weight: normal;font-size: 14px;line-height: 1.6;"} + %a.soc-btn.fb{:href => "https://www.facebook.com/OpenFoodNet", :style => "margin: 0;padding: 3px 7px;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;color: #FFF;font-size: 12px;margin-bottom: 10px;text-decoration: none;font-weight: bold;display: block;text-align: center;background-color: #3B5998!important;", :target => "_blank"} Facebook + %a.soc-btn.tw{:href => "https://twitter.com/OpenFoodNet", :style => "margin: 0;padding: 3px 7px;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;color: #FFF;font-size: 12px;margin-bottom: 10px;text-decoration: none;font-weight: bold;display: block;text-align: center;background-color: #1daced!important;", :target => "_blank"} Twitter + %a.soc-btn.li{:href => "http://www.linkedin.com/groups/Open-Food-Foundation-4743336", :style => "margin: 0;padding: 3px 7px;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;color: #FFF;font-size: 12px;margin-bottom: 10px;text-decoration: none;font-weight: bold;display: block;text-align: center;background-color: #0073b2!important;", :target => "_blank"} LinkedIn + / /column 1 + / column 2 + %table.column{:align => "left", :style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;width: 280px;float: left;min-width: 279px;"} + %tr{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %td{:style => "margin: 0;padding: 15px;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %h5{:style => "margin: 0;padding: 0;font-family: \"HelveticaNeue-Light\", \"Helvetica Neue Light\", \"Helvetica Neue\", Helvetica, Arial, \"Lucida Grande\", sans-serif;line-height: 1.1;margin-bottom: 15px;color: #000;font-weight: 900;font-size: 17px;"} Email us: + %p{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;margin-bottom: 10px;font-weight: normal;font-size: 14px;line-height: 1.6;"} + %strong{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %a{:href => "hello@openfoodnetwork.org", :style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;color: #0096ad;"} hello@openfoodnetwork.org + / /column 2 + %span.clear{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;display: block;clear: both;"} + / /social & contact + / /content + %td{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + / /BODY + / FOOTER + %table.footer-wrap{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;width: 100%;clear: both!important;"} + %tr{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %td{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %td.container{:style => "margin: 0 auto!important;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;display: block!important;max-width: 600px!important;clear: both!important;"} + / content + .content{:style => "margin: 0 auto;padding: 15px;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;max-width: 600px;display: block;"} + %table{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;width: 100%;"} + %tr{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %td{:align => "center", :style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + %p{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;margin-bottom: 10px;font-weight: normal;font-size: 14px;line-height: 1.6;"} + %a{:href => "https://openfoodnetwork.org.au/Terms-of-service.pdf", :style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;color: #0096ad;", :target => "_blank"} Terms of service + | + %a{:href => "http://www.openfoodnetwork.org.au", :style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;color: #0096ad;", :target => "_blank"} Open Food Network + / | Unsubscribe + / /content + %td{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"} + / /FOOTER From 1b0000a1de86a262138a8b328f89fe4f9d2094c6 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 16 Oct 2014 16:48:01 +1100 Subject: [PATCH 098/142] use bangs --- .../20140927005043_enterprise_config_refactor.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/db/migrate/20140927005043_enterprise_config_refactor.rb b/db/migrate/20140927005043_enterprise_config_refactor.rb index e50b4497d7..619a768636 100644 --- a/db/migrate/20140927005043_enterprise_config_refactor.rb +++ b/db/migrate/20140927005043_enterprise_config_refactor.rb @@ -5,7 +5,7 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration add_index :enterprises, [:is_primary_producer, :sells] Enterprise.all.each do |enterprise| - enterprise.update_attributes({:sells => sells_what?(enterprise)}) + enterprise.update_attributes!({:sells => sells_what?(enterprise)}) end remove_column :enterprises, :type @@ -18,7 +18,7 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration add_column :enterprises, :is_distributor, :boolean Enterprise.all.each do |enterprise| - enterprise.update_attributes({ + enterprise.update_attributes!({ :type => type?(enterprise), :is_distributor => distributes?(enterprise) }) @@ -30,21 +30,20 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration end def sells_what?(enterprise) - is_distributor = enterprise.read_attribute(:is_distributor) - is_primary_producer = enterprise.read_attribute(:is_primary_producer) - type = enterprise.read_attribute(:type) + is_distributor = enterprise.read_attribute!(:is_distributor) + is_primary_producer = enterprise.read_attribute!(:is_primary_producer) + type = enterprise.read_attribute!(:type) return "own" if type == "single" && (is_distributor || is_primary_producer) return "none" if !is_distributor || type == "profile" return "any" end def distributes?(enterprise) - return true if enterprise.read_attribute(:sells) != "none" - return false + enterprise.read_attribute!(:sells) != "none" end def type?(enterprise) - sells = enterprise.read_attribute(:sells) + sells = enterprise.read_attribute!(:sells) return "profile" if sells == "none" return "single" if sells == "own" return "full" From f145db46f1fd19f15bb8869b61c093ee2e0dd664 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 16 Oct 2014 16:49:49 +1100 Subject: [PATCH 099/142] use self.x --- app/models/enterprise.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index ab4dccf8ec..3654f272d4 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -212,14 +212,14 @@ class Enterprise < ActiveRecord::Base end def is_distributor - not self.sells == "none" + self.sells != "none" end # Simplify enterprise categories for frontend logic and icons, and maybe other things. def category # Make this crazy logic human readable so we can argue about it sanely. - cat = is_primary_producer ? "producer_" : "non_producer_" - cat << "sells_" + sells + cat = self.is_primary_producer ? "producer_" : "non_producer_" + cat << "sells_" + self.sells # Map backend cases to front end cases. case cat @@ -261,7 +261,7 @@ class Enterprise < ActiveRecord::Base end def strip_url(url) - url.andand.sub /(https?:\/\/)?/, '' + url.andand.sub(/(https?:\/\/)?/, '') end def set_unused_address_fields From a1d74649f378aac592b4119b4f7fa4b7fc318c61 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 16 Oct 2014 16:50:19 +1100 Subject: [PATCH 100/142] rename spec and clear todo --- spec/models/spree/ability_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index 5920a66f3c..0274099aa7 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -266,8 +266,7 @@ module Spree should have_ability([:admin, :index, :read, :create, :edit, :bulk_update, :destroy], for: EnterpriseFee) end - #TODO clarify :for_order_cycle and its purpose - and possibly rename it. - it "should be able to do something with order cycles (??)" do + it "should be able to add enterprises to order cycles" do should have_ability([:admin, :index, :for_order_cycle, :create], for: Enterprise) end end From 6fd9741daf04cbbb7b145416719bb0ce1b3c4b88 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Thu, 16 Oct 2014 16:51:09 +1100 Subject: [PATCH 101/142] use build instead of create, and reorganise code --- spec/models/enterprise_spec.rb | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 6fae275583..2d5f986096 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -505,24 +505,12 @@ describe Enterprise do describe "provide enterprise category" do - let(:producer_sell_all) { - create(:enterprise, is_primary_producer: true, sells: "any") - } - let(:producer_sell_own) { - create(:enterprise, is_primary_producer: true, sells: "own") - } - let(:producer_sell_none) { - create(:enterprise, is_primary_producer: true, sells: "none") - } - let(:non_producer_sell_all) { - create(:enterprise, is_primary_producer: false, sells: "any") - } - let(:non_producer_sell_own) { - create(:enterprise, is_primary_producer: false, sells: "own") - } - let(:non_producer_sell_none) { - create(:enterprise, is_primary_producer: false, sells: "none") - } + let(:producer_sell_all) { build(:enterprise, is_primary_producer: true, sells: "any") } + let(:producer_sell_own) { build(:enterprise, is_primary_producer: true, sells: "own") } + let(:producer_sell_none) { build(:enterprise, is_primary_producer: true, sells: "none") } + let(:non_producer_sell_all) { build(:enterprise, is_primary_producer: false, sells: "any") } + let(:non_producer_sell_own) { build(:enterprise, is_primary_producer: false, sells: "own") } + let(:non_producer_sell_none) { build(:enterprise, is_primary_producer: false, sells: "none") } it "should output enterprise categories" do producer_sell_all.is_primary_producer.should == true From 1150e69500a85c0c21597aaaa6f0559ccb1efdd9 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 17 Oct 2014 03:59:48 +1100 Subject: [PATCH 102/142] fix visible bug --- app/views/home/_hubs.html.haml | 2 +- app/views/producers/index.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/home/_hubs.html.haml b/app/views/home/_hubs.html.haml index 5f589f9cb4..1e5151469e 100644 --- a/app/views/home/_hubs.html.haml +++ b/app/views/home/_hubs.html.haml @@ -10,7 +10,7 @@ .row{bindonce: true} .small-12.columns .active_table - %hub.active_table_node.row.animate-repeat{"ng-repeat" => "hub in filteredEnterprises = (Enterprises.hubs | visibleFilter | searchEnterprises:query | taxons:activeTaxons | shipping:shippingTypes | showHubProfiles:show_profiles | orderBy:['-active', '+orders_close_at'])", + %hub.active_table_node.row.animate-repeat{"ng-repeat" => "hub in filteredEnterprises = (Enterprises.hubs | visible | searchEnterprises:query | taxons:activeTaxons | shipping:shippingTypes | showHubProfiles:show_profiles | orderBy:['-active', '+orders_close_at'])", "ng-class" => "{'is_profile' : hub.category == 'hub_profile', 'closed' : !open(), 'open' : open(), 'inactive' : !hub.active, 'current' : current()}", "scroll-after-load" => true, "ng-controller" => "HubNodeCtrl", diff --git a/app/views/producers/index.html.haml b/app/views/producers/index.html.haml index a59a0ac151..0e46795701 100644 --- a/app/views/producers/index.html.haml +++ b/app/views/producers/index.html.haml @@ -12,7 +12,7 @@ .active_table %producer.active_table_node.row.animate-repeat{id: "{{producer.path}}", "scroll-after-load" => true, - "ng-repeat" => "producer in filteredEnterprises = (Enterprises.producers | visibleFilter | searchEnterprises:query | taxons:activeTaxons)", + "ng-repeat" => "producer in filteredEnterprises = (Enterprises.producers | visible | searchEnterprises:query | taxons:activeTaxons)", "ng-controller" => "ProducerNodeCtrl", "ng-class" => "{'closed' : !open(), 'open' : open(), 'inactive' : !producer.active}", id: "{{producer.hash}}"} From 4defb38cf4eb9f35cbd1d2e315c0f6774fee92f5 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 17 Oct 2014 04:01:36 +1100 Subject: [PATCH 103/142] update karma config --- config/ng-test.conf.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config/ng-test.conf.js b/config/ng-test.conf.js index eadaf984ae..f87aa3d48a 100644 --- a/config/ng-test.conf.js +++ b/config/ng-test.conf.js @@ -27,9 +27,16 @@ module.exports = function(config) { 'app/assets/javascripts/admin/util.js.erb' ], + preprocessors: { + '**/*.coffee': ['coffee'] + }, + coffeePreprocessor: { options: { sourceMap: true + }, + transformPath: function(path) { + return path.replace(/\.coffee$/, '.js'); } }, From dd3101f27a4b5c549a0c807067191b2e0dff7a14 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 17 Oct 2014 06:14:39 +1100 Subject: [PATCH 104/142] remove some bangs --- .../20140927005043_enterprise_config_refactor.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/migrate/20140927005043_enterprise_config_refactor.rb b/db/migrate/20140927005043_enterprise_config_refactor.rb index 619a768636..6161ff00a6 100644 --- a/db/migrate/20140927005043_enterprise_config_refactor.rb +++ b/db/migrate/20140927005043_enterprise_config_refactor.rb @@ -30,20 +30,20 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration end def sells_what?(enterprise) - is_distributor = enterprise.read_attribute!(:is_distributor) - is_primary_producer = enterprise.read_attribute!(:is_primary_producer) - type = enterprise.read_attribute!(:type) + is_distributor = enterprise.read_attribute(:is_distributor) + is_primary_producer = enterprise.read_attribute(:is_primary_producer) + type = enterprise.read_attribute(:type) return "own" if type == "single" && (is_distributor || is_primary_producer) return "none" if !is_distributor || type == "profile" return "any" end def distributes?(enterprise) - enterprise.read_attribute!(:sells) != "none" + enterprise.read_attribute(:sells) != "none" end def type?(enterprise) - sells = enterprise.read_attribute!(:sells) + sells = enterprise.read_attribute(:sells) return "profile" if sells == "none" return "single" if sells == "own" return "full" From bda1eafcecfb272260001b5093b72d8f7e7e9263 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 17 Oct 2014 06:37:22 +1100 Subject: [PATCH 105/142] add migrating for dummy emails --- db/migrate/20140927005000_add_dummy_for_missing_emails.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 db/migrate/20140927005000_add_dummy_for_missing_emails.rb diff --git a/db/migrate/20140927005000_add_dummy_for_missing_emails.rb b/db/migrate/20140927005000_add_dummy_for_missing_emails.rb new file mode 100644 index 0000000000..39b0cf988b --- /dev/null +++ b/db/migrate/20140927005000_add_dummy_for_missing_emails.rb @@ -0,0 +1,7 @@ +class AddDummyForMissingEmails < ActiveRecord::Migration + def up + Enterprise.all.each do |enterprise| + enterprise.update_attributes({:email => "missing@example.com"}) if enterprise.read_attribute(:email).blank? + end + end +end From 245c1eb30582fdd8941e030abe29b51377319ece Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 17 Oct 2014 07:40:08 +1100 Subject: [PATCH 106/142] use a directive for navigation check to attach it to the page instead of the controller --- .../enterprises/controllers/enterprise_controller.js.coffee | 6 ++---- .../admin/utils/directives/navigation_check.js.coffee | 4 ++++ app/views/admin/enterprises/_ng_form.html.haml | 2 +- app/views/admin/enterprises/index.html.haml | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee diff --git a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee index 6558c789a2..688bf45a99 100644 --- a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee +++ b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee @@ -1,16 +1,14 @@ angular.module("admin.enterprises") - .controller "enterpriseCtrl", ($scope, longDescription, Enterprise, PaymentMethods, ShippingMethods, NavigationCheck) -> + .controller "enterpriseCtrl", ($scope, longDescription, Enterprise, PaymentMethods, ShippingMethods) -> $scope.Enterprise = Enterprise.enterprise $scope.PaymentMethods = PaymentMethods.paymentMethods $scope.ShippingMethods = ShippingMethods.shippingMethods # htmlVariable is used by textAngular wysiwyg for the long descrtiption. $scope.htmlVariable = longDescription # Provide a callback for a warning message displayed when leaving the page. - navigationCallback = -> + $scope.navigationCallback = -> "You are editing an enterprise!" - NavigationCheck.register navigationCallback - for payment_method in $scope.PaymentMethods payment_method.selected = payment_method.id in $scope.Enterprise.payment_method_ids diff --git a/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee b/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee new file mode 100644 index 0000000000..26964a677d --- /dev/null +++ b/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee @@ -0,0 +1,4 @@ +angular.module("admin.utils").directive "navigationCheck", (NavigationCheck)-> + link: ($scope) -> + # Define navigationCallback on the controller. + NavigationCheck.register($scope.navigationCallback) diff --git a/app/views/admin/enterprises/_ng_form.html.haml b/app/views/admin/enterprises/_ng_form.html.haml index 18e9d6ed36..74b4347f16 100644 --- a/app/views/admin/enterprises/_ng_form.html.haml +++ b/app/views/admin/enterprises/_ng_form.html.haml @@ -3,7 +3,7 @@ = admin_inject_payment_methods = admin_inject_shipping_methods -.sixteen.columns.alpha{ ng: { app: 'admin.enterprises', controller: 'enterpriseCtrl' } } +.sixteen.columns.alpha{ ng: { app: 'admin.enterprises', controller: 'enterpriseCtrl' }, "navigation-check" => "" } .eleven.columns.alpha = render 'form', f: f .one.column   diff --git a/app/views/admin/enterprises/index.html.haml b/app/views/admin/enterprises/index.html.haml index 03e5335155..b2a215b1c6 100644 --- a/app/views/admin/enterprises/index.html.haml +++ b/app/views/admin/enterprises/index.html.haml @@ -8,7 +8,7 @@ = render 'admin/shared/enterprises_sub_menu' -= form_for @enterprise_set, :url => main_app.bulk_update_admin_enterprises_path do |f| += form_for @enterprise_set, url: main_app.bulk_update_admin_enterprises_path do |f| %table#listing_enterprises.index %colgroup %col{style: "width: 25%;"}/ From 9536b3e764c7f3a5d82ae91b0c801f71e85d7410 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 17 Oct 2014 07:58:08 +1100 Subject: [PATCH 107/142] add navigation directive default --- .../admin/utils/directives/navigation_check.js.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee b/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee index 26964a677d..7eae3d69cd 100644 --- a/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee +++ b/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee @@ -1,4 +1,6 @@ angular.module("admin.utils").directive "navigationCheck", (NavigationCheck)-> link: ($scope) -> - # Define navigationCallback on the controller. + # Define navigationCallback on a controller in $scope, otherwise this default will be used: + $scope.navigationCallback ||= -> + "You will lose any unsaved work!" NavigationCheck.register($scope.navigationCallback) From 1a40c83a4888d039a8f6ea73015dd70d68d08b88 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 17 Oct 2014 07:59:51 +1100 Subject: [PATCH 108/142] update chema with indexes --- db/schema.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/schema.rb b/db/schema.rb index 67084cc347..b06de91dc8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -268,7 +268,9 @@ ActiveRecord::Schema.define(:version => 20140927005043) do end add_index "enterprises", ["address_id"], :name => "index_enterprises_on_address_id" + add_index "enterprises", ["is_primary_producer", "sells"], :name => "index_enterprises_on_is_primary_producer_and_sells" add_index "enterprises", ["owner_id"], :name => "index_enterprises_on_owner_id" + add_index "enterprises", ["sells"], :name => "index_enterprises_on_sells" create_table "exchange_fees", :force => true do |t| t.integer "exchange_id" From b853f908d32cd06fa23adb37db5f4d9e1f6c3619 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 17 Oct 2014 08:08:10 +1100 Subject: [PATCH 109/142] bugfix email dummy --- db/migrate/20140927005000_add_dummy_for_missing_emails.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20140927005000_add_dummy_for_missing_emails.rb b/db/migrate/20140927005000_add_dummy_for_missing_emails.rb index 39b0cf988b..8775eacd4e 100644 --- a/db/migrate/20140927005000_add_dummy_for_missing_emails.rb +++ b/db/migrate/20140927005000_add_dummy_for_missing_emails.rb @@ -1,7 +1,7 @@ class AddDummyForMissingEmails < ActiveRecord::Migration def up Enterprise.all.each do |enterprise| - enterprise.update_attributes({:email => "missing@example.com"}) if enterprise.read_attribute(:email).blank? + enterprise.update_column({:email => "missing@example.com"}) if enterprise.read_attribute(:email).blank? end end end From 2e3cb171a30adfbc7afad6bb9e127b64fb7bec79 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 17 Oct 2014 08:22:21 +1100 Subject: [PATCH 110/142] don't remove indexes after you remove one of their columns! --- db/migrate/20140927005043_enterprise_config_refactor.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/db/migrate/20140927005043_enterprise_config_refactor.rb b/db/migrate/20140927005043_enterprise_config_refactor.rb index 6161ff00a6..f9e8c936ce 100644 --- a/db/migrate/20140927005043_enterprise_config_refactor.rb +++ b/db/migrate/20140927005043_enterprise_config_refactor.rb @@ -25,8 +25,6 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration end remove_column :enterprises, :sells - remove_index :enterprises, :sells - remove_index :enterprises, [:is_primary_producer, :sells] end def sells_what?(enterprise) From 6a6f6037541a57ece64357ed3d11cc8ace660eac Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 17 Oct 2014 10:03:34 +1100 Subject: [PATCH 111/142] Correct syntax for update column --- db/migrate/20140927005000_add_dummy_for_missing_emails.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20140927005000_add_dummy_for_missing_emails.rb b/db/migrate/20140927005000_add_dummy_for_missing_emails.rb index 8775eacd4e..08f638e2a3 100644 --- a/db/migrate/20140927005000_add_dummy_for_missing_emails.rb +++ b/db/migrate/20140927005000_add_dummy_for_missing_emails.rb @@ -1,7 +1,7 @@ class AddDummyForMissingEmails < ActiveRecord::Migration def up Enterprise.all.each do |enterprise| - enterprise.update_column({:email => "missing@example.com"}) if enterprise.read_attribute(:email).blank? + enterprise.update_column(:email, "missing@example.com") if enterprise.read_attribute(:email).blank? end end end From 4884734ab5bbe10c23d93437b04df0009b2f0e09 Mon Sep 17 00:00:00 2001 From: summerscope Date: Fri, 17 Oct 2014 10:43:19 +1100 Subject: [PATCH 112/142] Align Continue buttons right consistently --- .../javascripts/templates/registration/about.html.haml | 4 +++- .../javascripts/templates/registration/contact.html.haml | 3 +-- .../javascripts/templates/registration/images.html.haml | 5 ++--- .../javascripts/templates/registration/social.html.haml | 3 +-- app/assets/javascripts/templates/registration/type.html.haml | 5 ++--- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/templates/registration/about.html.haml b/app/assets/javascripts/templates/registration/about.html.haml index 160a2012d3..64ed3df0c1 100644 --- a/app/assets/javascripts/templates/registration/about.html.haml +++ b/app/assets/javascripts/templates/registration/about.html.haml @@ -40,6 +40,8 @@ .small-12.columns %label{ for: 'enterprise_acn' } ACN: %input.chunky.small-12.columns{ id: 'enterprise_acn', placeholder: "eg. 123 456 789", ng: { model: 'enterprise.acn' } } + .row.buttons.pad-top .small-12.columns - %input.button.primary{ type: "submit", value: "Continue" } + %input.button.primary.right{ type: "submit", value: "Continue" } + diff --git a/app/assets/javascripts/templates/registration/contact.html.haml b/app/assets/javascripts/templates/registration/contact.html.haml index fdb606da25..b87073431e 100644 --- a/app/assets/javascripts/templates/registration/contact.html.haml +++ b/app/assets/javascripts/templates/registration/contact.html.haml @@ -46,5 +46,4 @@ .row.buttons .small-12.columns %input.button.secondary{ type: "button", value: "Back", ng: { click: "select('details')" } } -   - %input.button.primary{ type: "submit", value: "Continue" } + %input.button.primary.right{ type: "submit", value: "Continue" } diff --git a/app/assets/javascripts/templates/registration/images.html.haml b/app/assets/javascripts/templates/registration/images.html.haml index b2a5dcfd08..3c0615a216 100644 --- a/app/assets/javascripts/templates/registration/images.html.haml +++ b/app/assets/javascripts/templates/registration/images.html.haml @@ -18,6 +18,5 @@ .row.buttons.pad-top{ ng: { if: "imageStep == 'promo'" } } .small-12.columns - %input.button.primary{ type: "button", value: "Back", ng: { click: "imageSelect('logo')" } } -   - %input.button.primary{ type: "submit", value: "Continue" } + %input.button.secondary{ type: "button", value: "Back", ng: { click: "imageSelect('logo')" } } + %input.button.primary.right{ type: "submit", value: "Continue" } diff --git a/app/assets/javascripts/templates/registration/social.html.haml b/app/assets/javascripts/templates/registration/social.html.haml index 3195b97a29..ba07a28062 100644 --- a/app/assets/javascripts/templates/registration/social.html.haml +++ b/app/assets/javascripts/templates/registration/social.html.haml @@ -35,5 +35,4 @@ .row.buttons .small-12.columns %input.button.secondary{ type: "button", value: "Back", ng: { click: "select('images')" } } -   - %input.button.primary{ type: "submit", value: "Continue" } + %input.button.primary.right{ type: "submit", value: "Continue" } diff --git a/app/assets/javascripts/templates/registration/type.html.haml b/app/assets/javascripts/templates/registration/type.html.haml index 164537d58e..aed5c9c3de 100644 --- a/app/assets/javascripts/templates/registration/type.html.haml +++ b/app/assets/javascripts/templates/registration/type.html.haml @@ -33,9 +33,8 @@ %h4 I'm A Hub %p Hubs connect the producer to the eater. Hubs can be co-ops, independent retailers, buying groups, wholesalers, CSA box schemes, farm-gate stalls, etc. - .row.buttons .small-12.columns %input.button.secondary{ type: "button", value: "Back", ng: { click: "select('contact')" } } -   - %input.button.primary{ type: "submit", value: "Continue" } + %input.button.primary.right{ type: "submit", value: "Continue" } + From c4d47ccc2060207cb6b91a4b6adfcc4677af4145 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 17 Oct 2014 10:46:30 +1100 Subject: [PATCH 113/142] Change enterprise attributes defined in reg controller --- app/controllers/registration_controller.rb | 4 ++-- spec/features/consumer/registration_spec.rb | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/registration_controller.rb b/app/controllers/registration_controller.rb index 4fae68bb79..a7401abf60 100644 --- a/app/controllers/registration_controller.rb +++ b/app/controllers/registration_controller.rb @@ -7,11 +7,11 @@ class RegistrationController < BaseController layout 'registration' def index - @enterprise_attributes = { type: 'profile' } + @enterprise_attributes = { sells: 'none' } end def store - @enterprise_attributes = { is_distributor: true, is_primary_producer: true, type: 'single' } + @enterprise_attributes = { is_primary_producer: true, sells: 'own' } render :index end diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index 91bd92eb91..8c55ae3a68 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -3,8 +3,7 @@ require 'spec_helper' feature "Registration", js: true do include WebHelper - # TODO fix this after removal of is_distributor. - pending "Registering a Profile" do + describe "Registering a Profile" do let(:user) { create(:user, password: "password", password_confirmation: "password") } it "Allows a logged in user to register a profile" do @@ -18,7 +17,7 @@ feature "Registration", js: true do # Enter Login details fill_in "Email", with: user.email fill_in "Password", with: user.password - click_login_and_ensure_content "This wizard will step you through creating a profile" + click_login_and_ensure_content "Hi there!" expect(URI.parse(current_url).path).to eq registration_path @@ -45,8 +44,11 @@ feature "Registration", js: true do # Choosing a type expect(page).to have_content 'Last step to create your enterprise!' - click_link 'both-panel' + click_link 'producer-panel' click_button 'Continue' + sleep 2 + click_button 'Continue' + save_screenshot '/Users/rob/Desktop/ss.png' # Enterprise should be created expect(page).to have_content 'Nice one!' @@ -107,7 +109,7 @@ feature "Registration", js: true do # Enter Login details fill_in "Email", with: user.email fill_in "Password", with: user.password - click_login_and_ensure_content "This wizard will step you through creating a profile" + click_login_and_ensure_content "Hi there!" expect(URI.parse(current_url).path).to eq store_registration_path From 81715aaf5d06b49686cabef91f35f379d298f14e Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 17 Oct 2014 10:49:54 +1100 Subject: [PATCH 114/142] Remove unrequired store registration action --- app/controllers/registration_controller.rb | 7 +---- config/routes.rb | 1 - .../registration_controller_spec.rb | 12 --------- spec/features/consumer/registration_spec.rb | 27 ------------------- 4 files changed, 1 insertion(+), 46 deletions(-) diff --git a/app/controllers/registration_controller.rb b/app/controllers/registration_controller.rb index a7401abf60..5a21d28a44 100644 --- a/app/controllers/registration_controller.rb +++ b/app/controllers/registration_controller.rb @@ -2,7 +2,7 @@ require 'open_food_network/spree_api_key_loader' class RegistrationController < BaseController include OpenFoodNetwork::SpreeApiKeyLoader - before_filter :load_spree_api_key, only: [:index, :store] + before_filter :load_spree_api_key, only: [:index] before_filter :check_user, except: :authenticate layout 'registration' @@ -10,11 +10,6 @@ class RegistrationController < BaseController @enterprise_attributes = { sells: 'none' } end - def store - @enterprise_attributes = { is_primary_producer: true, sells: 'own' } - render :index - end - private def check_user diff --git a/config/routes.rb b/config/routes.rb index 9cdac4142d..ca4a6b59ff 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,7 +6,6 @@ Openfoodnetwork::Application.routes.draw do get "/map", to: "map#index", as: :map get "/register", to: "registration#index", as: :registration - get "/register/store", to: "registration#store", as: :store_registration get "/register/auth", to: "registration#authenticate", as: :registration_auth resource :shop, controller: "shop" do diff --git a/spec/controllers/registration_controller_spec.rb b/spec/controllers/registration_controller_spec.rb index e51a28f73a..8ef292dc68 100644 --- a/spec/controllers/registration_controller_spec.rb +++ b/spec/controllers/registration_controller_spec.rb @@ -7,11 +7,6 @@ describe RegistrationController do get :index response.should redirect_to registration_auth_path(anchor: "signup?after_login=/register") end - - it "store" do - get :store - response.should redirect_to registration_auth_path(anchor: "signup?after_login=/register/store") - end end describe "redirecting when user has reached enterprise ownership limit" do @@ -41,12 +36,5 @@ describe RegistrationController do expect(assigns(:spree_api_key)).to eq user.spree_api_key end end - - describe "store" do - it "loads the spree api key" do - get :store - expect(assigns(:spree_api_key)).to eq user.spree_api_key - end - end end end diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index 8c55ae3a68..551490363c 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -46,9 +46,6 @@ feature "Registration", js: true do expect(page).to have_content 'Last step to create your enterprise!' click_link 'producer-panel' click_button 'Continue' - sleep 2 - click_button 'Continue' - save_screenshot '/Users/rob/Desktop/ss.png' # Enterprise should be created expect(page).to have_content 'Nice one!' @@ -97,30 +94,6 @@ feature "Registration", js: true do expect(e.twitter).to eq "@TwItTeR" expect(e.instagram).to eq "@InStAgRaM" end - - it "Allows a logged in user to register a store" do - visit store_registration_path - - expect(URI.parse(current_url).path).to eq registration_auth_path - - page.has_selector? "dd", text: "Log in" - switch_to_login_tab - - # Enter Login details - fill_in "Email", with: user.email - fill_in "Password", with: user.password - click_login_and_ensure_content "Hi there!" - - expect(URI.parse(current_url).path).to eq store_registration_path - - # Done reading introduction - click_button_and_ensure_content "Let's get started!", "Woot! First we need to know a little bit about your farm:" - - # Details Page - expect(page).to_not have_selector '#enterprise-types' - - # Everything from here should be covered in 'profile' spec - end end def switch_to_login_tab From 2c5208ce6b9e8aaac7de6ac8a4b20436bf95ffec Mon Sep 17 00:00:00 2001 From: summerscope Date: Fri, 17 Oct 2014 11:17:46 +1100 Subject: [PATCH 115/142] Change ent type page, simplify! --- .../templates/registration/type.html.haml | 36 ++++++++++--------- .../darkswarm/registration.css.sass | 18 ++++++++-- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/templates/registration/type.html.haml b/app/assets/javascripts/templates/registration/type.html.haml index aed5c9c3de..2c39f2a863 100644 --- a/app/assets/javascripts/templates/registration/type.html.haml +++ b/app/assets/javascripts/templates/registration/type.html.haml @@ -6,32 +6,34 @@ .small-12.columns %header %h2 - Last step to create your enterprise! - %h5 - Is + Last step to add %span{ ng: { class: "{brick: !enterprise.is_primary_producer, turquoise: enterprise.is_primary_producer}" } } {{ enterprise.name }} - a primary producer? + ! + %h4 + Are you a producer? %form{ name: 'type', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "create(type)" } } .row#enterprise-types{ 'data-equalizer' => true, bo: { if: "enterprise.type != 'own'" } } .small-12.columns.field .row - .small-12.columns - %label Choose one: + .small-12.medium-6.large-6.columns{ 'data-equalizer-watch' => true } + %a.btnpanel#producer-panel{ href: "#", ng: { click: "enterprise.is_primary_producer = true", class: "{selected: (enterprise.is_primary_producer)}" } } + %i.ofn-i_059-producer + %h4 Yes, I'm a producer + + .small-12.medium-6.large-6.columns{ 'data-equalizer-watch' => true } + %a.btnpanel#hub-panel{ href: "#", ng: { click: "enterprise.is_primary_producer = false", class: "{selected: (!enterprise.is_primary_producer)}" } } + %i.ofn-i_063-hub + %h4 No, I'm not a producer .row - .small-12.medium-6.large-6.columns{ 'data-equalizer-watch' => true } - %a.panel#producer-panel{ href: "#", ng: { click: "enterprise.is_primary_producer = true", class: "{selected: (enterprise.is_primary_producer)}" } } - .left - / %render-svg{ path: "/assets/map-icon-producer.svg" } - %h4 I'm A Producer + .small-12.columns + .panel.callout + .left + %i.ofn-i_013-help +   %p Producers make yummy things to eat &/or drink. You're a producer if you grow it, raise it, brew it, bake it, ferment it, milk it or mould it. - .small-12.medium-6.large-6.columns{ 'data-equalizer-watch' => true } - %a.panel#hub-panel{ href: "#", ng: { click: "enterprise.is_primary_producer = false", class: "{selected: (!enterprise.is_primary_producer)}" } } - .left - / %render-svg{ path: "/assets/map-icon-hub.svg" } - %h4 I'm A Hub - %p Hubs connect the producer to the eater. Hubs can be co-ops, independent retailers, buying groups, wholesalers, CSA box schemes, farm-gate stalls, etc. + / %p Hubs connect the producer to the eater. Hubs can be co-ops, independent retailers, buying groups, wholesalers, CSA box schemes, farm-gate stalls, etc. .row.buttons .small-12.columns diff --git a/app/assets/stylesheets/darkswarm/registration.css.sass b/app/assets/stylesheets/darkswarm/registration.css.sass index b0d0757720..f63eb30421 100644 --- a/app/assets/stylesheets/darkswarm/registration.css.sass +++ b/app/assets/stylesheets/darkswarm/registration.css.sass @@ -118,20 +118,32 @@ #registration-type #enterprise-types - a.panel + a.btnpanel display: block + padding: 1rem + margin-bottom: 1rem background-color: #efefef color: black - @media all and (min-width: 768px) - min-height: 200px + text-align: center + border: 1px solid transparent + i + font-size: 3rem + h4 + margin-top: 1rem + &:hover background-color: #fff + &#producer-panel:hover + border: 1px solid $clr-turquoise &, & * color: $clr-turquoise + &#hub-panel:hover, &#both-panel:hover + border: 1px solid $clr-brick &, & * color: $clr-brick + &.selected &, & * color: #fff From 4aa2aa5aee8f93d74c80ea26ad969899182f13b0 Mon Sep 17 00:00:00 2001 From: summerscope Date: Fri, 17 Oct 2014 11:56:25 +1100 Subject: [PATCH 116/142] Tweaking layout, text, styling for registration box --- .../templates/registration/about.html.haml | 32 ++++++++--------- .../templates/registration/images.html.haml | 4 +-- .../templates/registration/social.html.haml | 35 ++++++++++++------- .../templates/registration/type.html.haml | 3 +- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/app/assets/javascripts/templates/registration/about.html.haml b/app/assets/javascripts/templates/registration/about.html.haml index 64ed3df0c1..5b7d2e6df6 100644 --- a/app/assets/javascripts/templates/registration/about.html.haml +++ b/app/assets/javascripts/templates/registration/about.html.haml @@ -6,40 +6,40 @@ %h2 Nice one! %h5 Now let's flesh out the details about - %span.brick{"ng-show" => "enterprise.is_distributor"} - {{ enterprise.name }} - %span.turquoise{"ng-show" => "!enterprise.is_distributor" } + %span{ ng: { class: "{brick: !enterprise.is_primary_producer, turquoise: enterprise.is_primary_producer}" } } {{ enterprise.name }} %form{ name: 'about', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "update('images',about)" } } .row .small-12.columns - .alert-box.alert{ "ofn-inline-alert" => true, ng: { show: "visible" } } - {{ enterprise.name }} won't be visible on the Open Food Network until you enter a long and short description. - %a.close{ ng: { click: "close()" } } × .alert-box.info{ "ofn-inline-alert" => true, ng: { show: "visible" } } - {{ enterprise.name }} has been created on the Open Food Network. If you leave at any point from here onwards, your enterprise will be saved, and you can always login to the admin section to update or continue filling out your enterprise details. + %h6 Success! {{ enterprise.name }} added to the Open Food Network + %span If you exit the wizard at any stage, login and go to admin to edit or update your enterprise details. %a.close{ ng: { click: "close()" } } × .small-12.large-8.columns .row .small-12.columns - %label{ for: 'enterprise_description' } Short Description: - %input.chunky.small-12.columns{ id: 'enterprise_description', placeholder: "A short sentence describing your enterprise", ng: { model: 'enterprise.description' } } + .field + %label{ for: 'enterprise_description' } Short Description: + %input.chunky{ id: 'enterprise_description', placeholder: "A short sentence describing your enterprise", ng: { model: 'enterprise.description' } } .row .small-12.columns - %label{ for: 'enterprise_long_desc' } Long Description: - %textarea.chunky.small-12.columns{ id: 'enterprise_long_desc', rows: 6, placeholder: "This is your opportunity to tell the story of your enterprise - what makes you different and wonderful? We'd suggest keeping your description to under 600 characters or 150 words.", ng: { model: 'enterprise.long_description' } } - %small {{ enterprise.long_description.length }} characters / up to 600 recommended + .field + %label{ for: 'enterprise_long_desc' } Long Description: + %textarea.chunky{ id: 'enterprise_long_desc', rows: 6, placeholder: "This is your opportunity to tell the story of your enterprise - what makes you different and wonderful? We'd suggest keeping your description to under 600 characters or 150 words.", ng: { model: 'enterprise.long_description' } } + %small {{ enterprise.long_description.length }} characters / up to 600 recommended .small-12.large-4.columns .row .small-12.columns - %label{ for: 'enterprise_abn' } ABN: - %input.chunky.small-12.columns{ id: 'enterprise_abn', placeholder: "eg. 99 123 456 789", ng: { model: 'enterprise.abn' } } + .field + %label{ for: 'enterprise_abn' } ABN: + %input.chunky{ id: 'enterprise_abn', placeholder: "eg. 99 123 456 789", ng: { model: 'enterprise.abn' } } .row .small-12.columns - %label{ for: 'enterprise_acn' } ACN: - %input.chunky.small-12.columns{ id: 'enterprise_acn', placeholder: "eg. 123 456 789", ng: { model: 'enterprise.acn' } } + .field + %label{ for: 'enterprise_acn' } ACN: + %input.chunky{ id: 'enterprise_acn', placeholder: "eg. 123 456 789", ng: { model: 'enterprise.acn' } } .row.buttons.pad-top .small-12.columns diff --git a/app/assets/javascripts/templates/registration/images.html.haml b/app/assets/javascripts/templates/registration/images.html.haml index 3c0615a216..5b2ac39b5a 100644 --- a/app/assets/javascripts/templates/registration/images.html.haml +++ b/app/assets/javascripts/templates/registration/images.html.haml @@ -12,9 +12,9 @@ .row.buttons.pad-top{ ng: { if: "imageStep == 'logo'" } } .small-12.columns - %input.button.primary{ type: "button", value: "Back", ng: { click: "select('about')" } } + %input.button.secondary{ type: "button", value: "Back", ng: { click: "select('about')" } }   - %input.button.primary{ type: "button", value: "Continue", ng: { click: "imageSelect('promo')" } } + %input.button.primary.right{ type: "button", value: "Continue", ng: { click: "imageSelect('promo')" } } .row.buttons.pad-top{ ng: { if: "imageStep == 'promo'" } } .small-12.columns diff --git a/app/assets/javascripts/templates/registration/social.html.haml b/app/assets/javascripts/templates/registration/social.html.haml index ba07a28062..4f448734f1 100644 --- a/app/assets/javascripts/templates/registration/social.html.haml +++ b/app/assets/javascripts/templates/registration/social.html.haml @@ -4,35 +4,46 @@ .row .small-12.columns %header - %h2 Almost there! - %h5 How can people find {{ enterprise.name }} online? + %h2 Final step! + %h5 + How can people find + %span{ ng: { class: "{brick: !enterprise.is_primary_producer, turquoise: enterprise.is_primary_producer}" } } + {{ enterprise.name }} + online? %form{ name: 'social', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "update('finished',social)" } } .row.content .small-12.large-7.columns .row .small-12.columns - %label{ for: 'enterprise_website' } Website: - %input.chunky.small-12.columns{ id: 'enterprise_website', placeholder: "eg. openfoodnetwork.org.au", ng: { model: 'enterprise.website' } } + .field + %label{ for: 'enterprise_website' } Website: + %input.chunky{ id: 'enterprise_website', placeholder: "eg. openfoodnetwork.org.au", ng: { model: 'enterprise.website' } } .row .small-12.columns - %label{ for: 'enterprise_facebook' } Facebook: - %input.chunky.small-12.columns{ id: 'enterprise_facebook', placeholder: "eg. www.facebook.com/PageNameHere", ng: { model: 'enterprise.facebook' } } + .field + %label{ for: 'enterprise_facebook' } Facebook: + %input.chunky{ id: 'enterprise_facebook', placeholder: "eg. www.facebook.com/PageNameHere", ng: { model: 'enterprise.facebook' } } .row .small-12.columns - %label{ for: 'enterprise_linkedin' } LinkedIn: - %input.chunky.small-12.columns{ id: 'enterprise_linkedin', placeholder: "eg. www.linkedin.com/YourNameHere", ng: { model: 'enterprise.linkedin' } } + .field + %label{ for: 'enterprise_linkedin' } LinkedIn: + %input.chunky{ id: 'enterprise_linkedin', placeholder: "eg. www.linkedin.com/YourNameHere", ng: { model: 'enterprise.linkedin' } } .small-12.large-5.columns .row .small-12.columns - %label{ for: 'enterprise_twitter' } Twitter: - %input.chunky.small-12.columns{ id: 'enterprise_twitter', placeholder: "eg. @twitter_handle", ng: { model: 'enterprise.twitter' } } + .field + %label{ for: 'enterprise_twitter' } Twitter: + %input.chunky{ id: 'enterprise_twitter', placeholder: "eg. @twitter_handle", ng: { model: 'enterprise.twitter' } } .row .small-12.columns - %label{ for: 'enterprise_instagram' } Instagram: - %input.chunky.small-12.columns{ id: 'enterprise_instagram', placeholder: "eg. @instagram_handle", ng: { model: 'enterprise.instagram' } } + .field + %label{ for: 'enterprise_instagram' } Instagram: + %input.chunky{ id: 'enterprise_instagram', placeholder: "eg. @instagram_handle", ng: { model: 'enterprise.instagram' } } .row.buttons .small-12.columns %input.button.secondary{ type: "button", value: "Back", ng: { click: "select('images')" } } %input.button.primary.right{ type: "submit", value: "Continue" } + + diff --git a/app/assets/javascripts/templates/registration/type.html.haml b/app/assets/javascripts/templates/registration/type.html.haml index 2c39f2a863..c23d2c24e8 100644 --- a/app/assets/javascripts/templates/registration/type.html.haml +++ b/app/assets/javascripts/templates/registration/type.html.haml @@ -8,8 +8,7 @@ %h2 Last step to add %span{ ng: { class: "{brick: !enterprise.is_primary_producer, turquoise: enterprise.is_primary_producer}" } } - {{ enterprise.name }} - ! + {{ enterprise.name }}! %h4 Are you a producer? From 4abc59f66d6ce55534eb83d386b91e49ad0ba90a Mon Sep 17 00:00:00 2001 From: summerscope Date: Fri, 17 Oct 2014 12:02:21 +1100 Subject: [PATCH 117/142] Change styling on the enterprise name because we dont know what type it is yet --- .../javascripts/templates/registration/contact.html.haml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/assets/javascripts/templates/registration/contact.html.haml b/app/assets/javascripts/templates/registration/contact.html.haml index b87073431e..916a614c0b 100644 --- a/app/assets/javascripts/templates/registration/contact.html.haml +++ b/app/assets/javascripts/templates/registration/contact.html.haml @@ -5,9 +5,7 @@ %header %h2 Greetings! %h5 - Who is responsible for managing - %span.turquoise - {{ enterprise.name }}? + Who is responsible for managing {{ enterprise.name }}? %form{ name: 'contact', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "selectIfValid('type',contact)" } } .row.content From b671543a951243f9a74cb0d5d9ada66f7b4ea5e0 Mon Sep 17 00:00:00 2001 From: summerscope Date: Fri, 17 Oct 2014 12:25:04 +1100 Subject: [PATCH 118/142] Style and make pretty the finished step of profile creation --- .../templates/registration/finished.html.haml | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/templates/registration/finished.html.haml b/app/assets/javascripts/templates/registration/finished.html.haml index 5319e98baa..f647a2d8bb 100644 --- a/app/assets/javascripts/templates/registration/finished.html.haml +++ b/app/assets/javascripts/templates/registration/finished.html.haml @@ -1,23 +1,24 @@ .container#registration-finished .row - .small-12.columns + .small-12.columns.pad-top %header - %h2 Well done! - %h5 - That's all of the details we need for - %span.brick{"ng-show" => "enterprise.is_distributor"} - {{ enterprise.name }} - %span.turquoise{"ng-show" => "!enterprise.is_distributor" } - {{ enterprise.name }} + %h2 Finished! + .panel.callout + %p + Thanks for filling out the details for + %span{ ng: { class: "{brick: !enterprise.is_primary_producer, turquoise: enterprise.is_primary_producer}" } } + {{ enterprise.name }} + %p You can change or update your enterprise at any stage by logging into Open Food Network and going to Admin. + .row + .small-12.columns.text-center + %h4 + Activate + %span{ ng: { class: "{brick: !enterprise.is_primary_producer, turquoise: enterprise.is_primary_producer}" } } + {{ enterprise.name }} - .content{ style: 'text-align: center'} + %p + We've sent a confirmation email to + %strong {{ enterprise.email }}. + %br Please follow the instructions there to make your enterprise visible on the Open Food Network. - %h3 There's just one last thing we need you to do: - %h5 We've sent a confirmation email to {{ enterprise.email }}, so please follow the instructions there to finalise the creation of your enterprise. - - -# perhaps a pretty picture here? - - %br/ - %br/ - - %a.button.primary{ type: "button", href: "/" } Take me home > + %a.button.primary{ type: "button", href: "/" } Open Food Network home > From a6bc9e66f671f4ad6266479f526f645e85ed3f1d Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 17 Oct 2014 11:40:28 +1100 Subject: [PATCH 119/142] Only send one enterprise creation confirmation email --- app/mailers/enterprise_mailer.rb | 12 ++++++------ app/models/enterprise.rb | 6 ------ .../creation_confirmation.html.haml | 9 --------- spec/mailers/enterprise_mailer_spec.rb | 12 +++++------- 4 files changed, 11 insertions(+), 28 deletions(-) delete mode 100644 app/views/enterprise_mailer/creation_confirmation.html.haml diff --git a/app/mailers/enterprise_mailer.rb b/app/mailers/enterprise_mailer.rb index f5f92aed3f..4e37d112e0 100644 --- a/app/mailers/enterprise_mailer.rb +++ b/app/mailers/enterprise_mailer.rb @@ -2,14 +2,14 @@ require 'devise/mailers/helpers' class EnterpriseMailer < Spree::BaseMailer include Devise::Mailers::Helpers - def creation_confirmation(enterprise) - find_enterprise(enterprise) - subject = "#{@enterprise.name} is now on #{Spree::Config[:site_name]}" - mail(:to => @enterprise.owner.email, :from => from_address, :subject => subject) - end - def confirmation_instructions(record, token, opts={}) @token = token + find_enterprise(record) + opts = { + subject: "Please confirm your email for #{@enterprise.name}", + to: [ @enterprise.owner.email, @enterprise.email ].uniq, + from: from_address, + } devise_mail(record, :confirmation_instructions, opts) end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 22182a4c9a..069c8860cc 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -10,8 +10,6 @@ class Enterprise < ActiveRecord::Base before_create :check_email - after_create :send_creation_email - has_and_belongs_to_many :groups, class_name: 'EnterpriseGroup' has_many :producer_properties, foreign_key: 'producer_id' has_many :supplied_products, :class_name => 'Spree::Product', :foreign_key => 'supplier_id', :dependent => :destroy @@ -272,10 +270,6 @@ class Enterprise < ActiveRecord::Base skip_confirmation! if owner.enterprises.confirmed.map(&:email).include?(email) end - def send_creation_email - EnterpriseMailer.creation_confirmation(self).deliver - end - def strip_url(url) url.andand.sub(/(https?:\/\/)?/, '') end diff --git a/app/views/enterprise_mailer/creation_confirmation.html.haml b/app/views/enterprise_mailer/creation_confirmation.html.haml deleted file mode 100644 index 0df3bf06a0..0000000000 --- a/app/views/enterprise_mailer/creation_confirmation.html.haml +++ /dev/null @@ -1,9 +0,0 @@ -%h1 - = @enterprise.name + " has been created" - -%h3 - Why not check it out on - %a{ href: "#{map_url}" } - = Spree::Config[:site_name] + "?" - -If you have any questions, please get in touch with us at: hello@openfoodnetwork.org diff --git a/spec/mailers/enterprise_mailer_spec.rb b/spec/mailers/enterprise_mailer_spec.rb index 6b53d7d561..dd1e150eb7 100644 --- a/spec/mailers/enterprise_mailer_spec.rb +++ b/spec/mailers/enterprise_mailer_spec.rb @@ -1,18 +1,16 @@ require 'spec_helper' describe EnterpriseMailer do + let!(:enterprise) { create(:enterprise) } + before do - @enterprise = create(:enterprise) ActionMailer::Base.deliveries = [] end - it "should send an email when given an enterprise" do - EnterpriseMailer.creation_confirmation(@enterprise).deliver - ActionMailer::Base.deliveries.count.should == 1 - end - it "should send an email confirmation when given an enterprise" do - EnterpriseMailer.confirmation_instructions(@enterprise, 'token').deliver + EnterpriseMailer.confirmation_instructions(enterprise, 'token').deliver ActionMailer::Base.deliveries.count.should == 1 + mail = ActionMailer::Base.deliveries.first + expect(mail.subject).to eq "Please confirm your email for #{enterprise.name}" end end \ No newline at end of file From e9a3f8ce9175f943234c3321fca86291c3ac9a94 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 17 Oct 2014 12:14:33 +1100 Subject: [PATCH 120/142] Require user to choose producer or not --- .../templates/registration/type.html.haml | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/templates/registration/type.html.haml b/app/assets/javascripts/templates/registration/type.html.haml index c23d2c24e8..48d45cb66a 100644 --- a/app/assets/javascripts/templates/registration/type.html.haml +++ b/app/assets/javascripts/templates/registration/type.html.haml @@ -6,30 +6,36 @@ .small-12.columns %header %h2 - Last step to add + Last step to add %span{ ng: { class: "{brick: !enterprise.is_primary_producer, turquoise: enterprise.is_primary_producer}" } } {{ enterprise.name }}! %h4 - Are you a producer? + Are you a producer? %form{ name: 'type', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "create(type)" } } .row#enterprise-types{ 'data-equalizer' => true, bo: { if: "enterprise.type != 'own'" } } .small-12.columns.field .row .small-12.medium-6.large-6.columns{ 'data-equalizer-watch' => true } - %a.btnpanel#producer-panel{ href: "#", ng: { click: "enterprise.is_primary_producer = true", class: "{selected: (enterprise.is_primary_producer)}" } } + %a.btnpanel#producer-panel{ href: "#", ng: { click: "enterprise.is_primary_producer = true", class: "{selected: enterprise.is_primary_producer}" } } %i.ofn-i_059-producer %h4 Yes, I'm a producer - + .small-12.medium-6.large-6.columns{ 'data-equalizer-watch' => true } - %a.btnpanel#hub-panel{ href: "#", ng: { click: "enterprise.is_primary_producer = false", class: "{selected: (!enterprise.is_primary_producer)}" } } + %a.btnpanel#hub-panel{ href: "#", ng: { click: "enterprise.is_primary_producer = false", class: "{selected: enterprise.is_primary_producer == false}" } } %i.ofn-i_063-hub %h4 No, I'm not a producer + + .row + .small-12.columns + %input.chunky{ id: 'enterprise_is_primary_producer', name: 'is_primary_producer', hidden: true, required: true, ng: { model: 'enterprise.is_primary_producer' } } + %span.error{ ng: { show: "type.is_primary_producer.$error.required && submitted" } } + Please choose one. Are you are producer? .row .small-12.columns .panel.callout - .left - %i.ofn-i_013-help + .left + %i.ofn-i_013-help   %p Producers make yummy things to eat &/or drink. You're a producer if you grow it, raise it, brew it, bake it, ferment it, milk it or mould it. / %p Hubs connect the producer to the eater. Hubs can be co-ops, independent retailers, buying groups, wholesalers, CSA box schemes, farm-gate stalls, etc. @@ -38,4 +44,3 @@ .small-12.columns %input.button.secondary{ type: "button", value: "Back", ng: { click: "select('contact')" } } %input.button.primary.right{ type: "submit", value: "Continue" } - From eda0b16a5f7b703633025ec5836464e260190054 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 17 Oct 2014 12:18:00 +1100 Subject: [PATCH 121/142] Make state abbreviations upper case --- app/serializers/api/state_serializer.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/serializers/api/state_serializer.rb b/app/serializers/api/state_serializer.rb index bcf9221ec5..7a76e340b4 100644 --- a/app/serializers/api/state_serializer.rb +++ b/app/serializers/api/state_serializer.rb @@ -1,3 +1,7 @@ class Api::StateSerializer < ActiveModel::Serializer attributes :id, :name, :abbr + + def abbr + object.abbr.upcase + end end \ No newline at end of file From 4d078feea24bab8bf0108f41b01e5d28a3778ee5 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 17 Oct 2014 16:12:51 +1100 Subject: [PATCH 122/142] Add default scope to devise to stop it from checking other devise enabled models (in this case :enterprise) --- config/initializers/devise.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 config/initializers/devise.rb diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb new file mode 100644 index 0000000000..9fef52fc8c --- /dev/null +++ b/config/initializers/devise.rb @@ -0,0 +1,5 @@ +Devise.setup do |config| + # Add a default scope to devise, to prevent it from checking + # whether other devise enabled models are signed into a session or not + config.default_scope = :spree_user +end \ No newline at end of file From e24a774d54f7d0d7042ecf0e88fe2670882a6328 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 17 Oct 2014 16:16:17 +1100 Subject: [PATCH 123/142] Adding schema --- db/schema.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index b62f63a725..974dc8ac9b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -263,12 +263,12 @@ ActiveRecord::Schema.define(:version => 20141010043405) do t.string "facebook" t.string "instagram" t.string "linkedin" - t.integer "owner_id", :null => false - t.string "sells", :default => "none", :null => false + t.integer "owner_id", :null => false t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.string "unconfirmed_email" + t.string "sells", :default => "none", :null => false end add_index "enterprises", ["address_id"], :name => "index_enterprises_on_address_id" From 5b3ff9160dc2559236fe7e044e1cc1a3a51cf593 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 17 Oct 2014 17:15:16 +1100 Subject: [PATCH 124/142] Fix Registration spec --- spec/features/consumer/registration_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index 551490363c..ea09450467 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -32,7 +32,7 @@ feature "Registration", js: true do fill_in 'enterprise_city', with: 'Northcote' fill_in 'enterprise_zipcode', with: '3070' select 'Australia', from: 'enterprise_country' - select 'Vic', from: 'enterprise_state' + select 'VIC', from: 'enterprise_state' click_button 'Continue' # Filling in Contact Details @@ -43,7 +43,7 @@ feature "Registration", js: true do click_button 'Continue' # Choosing a type - expect(page).to have_content 'Last step to create your enterprise!' + expect(page).to have_content 'Last step to add My Awesome Enterprise!' click_link 'producer-panel' click_button 'Continue' @@ -77,7 +77,7 @@ feature "Registration", js: true do click_button 'Continue' # Filling in social - expect(page).to have_content 'Almost there!' + expect(page).to have_content 'How can people find My Awesome Enterprise online?' fill_in 'enterprise_website', with: 'www.shop.com' fill_in 'enterprise_facebook', with: 'FaCeBoOk' fill_in 'enterprise_linkedin', with: 'LiNkEdIn' @@ -86,7 +86,7 @@ feature "Registration", js: true do click_button 'Continue' # Done - expect(page).to have_content "That's all of the details we need for My Awesome Enterprise" + expect(page).to have_content "Finished!" e.reload expect(e.website).to eq "www.shop.com" expect(e.facebook).to eq "FaCeBoOk" From 338ba74652449f10df8242d6f690d690e41f69c8 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 17 Oct 2014 17:15:49 +1100 Subject: [PATCH 125/142] Only show enterprise partial when no enterprises exist --- .../spree/admin/overview/index.html.haml | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/views/spree/admin/overview/index.html.haml b/app/views/spree/admin/overview/index.html.haml index 0709ceb54f..d83a71bc40 100644 --- a/app/views/spree/admin/overview/index.html.haml +++ b/app/views/spree/admin/overview/index.html.haml @@ -6,13 +6,19 @@ %hr -- if can? :admin, Spree::Product - = render partial: "spree/admin/overview/products" +- if @enterprises.empty? - %div.two.columns -   + = render partial: "spree/admin/overview/enterprises" -- if can? :admin, OrderCycle - = render partial: "spree/admin/overview/order_cycles" +- else -= render partial: "spree/admin/overview/enterprises" + - if can? :admin, Spree::Product + = render partial: "spree/admin/overview/products" + + %div.two.columns +   + + - if can? :admin, OrderCycle + = render partial: "spree/admin/overview/order_cycles" + + = render partial: "spree/admin/overview/enterprises" From f499cc375be29b98ba925a7040a434821306fa4d Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 17 Oct 2014 17:32:27 +1100 Subject: [PATCH 126/142] Adding confirmed_at to enterprise factory --- spec/factories.rb | 1 + spec/features/consumer/producers_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/factories.rb b/spec/factories.rb index f9c65eb7ff..60b94b08c0 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -97,6 +97,7 @@ FactoryGirl.define do long_description '

Hello, world!

This is a paragraph.

' email 'enterprise@example.com' address { FactoryGirl.create(:address) } + confirmed_at { Time.now } end factory :supplier_enterprise, :parent => :enterprise do diff --git a/spec/features/consumer/producers_spec.rb b/spec/features/consumer/producers_spec.rb index 98bef7f084..6e09365195 100644 --- a/spec/features/consumer/producers_spec.rb +++ b/spec/features/consumer/producers_spec.rb @@ -3,14 +3,14 @@ require 'spec_helper' feature %q{ As a consumer I want to see a list of producers - So that I can shop at hubs distributing their products + So that I can shop at hubs distributing their products }, js: true do include UIComponentHelper let!(:producer) { create(:supplier_enterprise) } let!(:invisible_producer) { create(:supplier_enterprise, visible: false) } let(:taxon) { create(:taxon) } let!(:product) { create(:simple_product, supplier: producer, taxons: [taxon]) } - + before do visit producers_path end @@ -20,7 +20,7 @@ feature %q{ expand_active_table_node producer.name page.should have_content producer.supplied_taxons.first.name.split.map(&:capitalize).join(' ') end - + it "doesn't show invisible producers" do page.should_not have_content invisible_producer.name end From cae8d566df88fdc6ec270b8eeab14400988a63a3 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 17 Oct 2014 17:49:18 +1100 Subject: [PATCH 127/142] Explicit confirmed_at to ensure that confirmation emails are sent --- spec/models/enterprise_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index b6204c3fd3..151275ec71 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -6,18 +6,18 @@ describe Enterprise do describe "sending emails" do describe "on creation" do let!(:user) { create_enterprise_user( enterprise_limit: 2 ) } - let!(:enterprise) { create(:enterprise, owner: user, confirmed_at: Time.now) } + let!(:enterprise) { create(:enterprise, owner: user) } it "when the email address has not already been confirmed" do mail_message = double "Mail::Message" EnterpriseMailer.should_receive(:confirmation_instructions).and_return mail_message mail_message.should_receive :deliver - create(:enterprise, owner: user, email: "unknown@email.com" ) + create(:enterprise, owner: user, email: "unknown@email.com", confirmed_at: nil ) end it "when the email address has already been confirmed" do EnterpriseMailer.should_not_receive(:confirmation_instructions) - e = create(:enterprise, owner: user, email: enterprise.email) + e = create(:enterprise, owner: user, email: enterprise.email, confirmed_at: nil) end end end @@ -133,8 +133,8 @@ describe Enterprise do describe "confirmed" do it "find enterprises with a confirmed date" do - s1 = create(:supplier_enterprise, confirmed_at: Time.now) - d1 = create(:distributor_enterprise, confirmed_at: Time.now) + s1 = create(:supplier_enterprise) + d1 = create(:distributor_enterprise) s2 = create(:supplier_enterprise, confirmed_at: nil) d2 = create(:distributor_enterprise, confirmed_at: nil) expect(Enterprise.confirmed).to include s1, d1 @@ -144,8 +144,8 @@ describe Enterprise do describe "unconfirmed" do it "find enterprises without a confirmed date" do - s1 = create(:supplier_enterprise, confirmed_at: Time.now) - d1 = create(:distributor_enterprise, confirmed_at: Time.now) + s1 = create(:supplier_enterprise) + d1 = create(:distributor_enterprise) s2 = create(:supplier_enterprise, confirmed_at: nil) d2 = create(:distributor_enterprise, confirmed_at: nil) expect(Enterprise.unconfirmed).to_not include s1, d1 From 361116a9ec0ab14cfc3b883d40e6476ccae8e800 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 17 Oct 2014 18:31:35 +1100 Subject: [PATCH 128/142] Explicitly set confirmed_at for unconfirmed enterprise --- spec/controllers/devise/confirmation_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/devise/confirmation_controller_spec.rb b/spec/controllers/devise/confirmation_controller_spec.rb index eda5dc4823..b8719bbd8f 100644 --- a/spec/controllers/devise/confirmation_controller_spec.rb +++ b/spec/controllers/devise/confirmation_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Devise::ConfirmationsController do context "after confirmation" do before do - e = create(:enterprise) + e = create(:enterprise, confirmed_at: nil) @request.env["devise.mapping"] = Devise.mappings[:enterprise] spree_get :show, confirmation_token: e.confirmation_token end From 577cb06371632251bbaabfb237eb5f4c4f95b938 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sat, 18 Oct 2014 01:42:29 +1100 Subject: [PATCH 129/142] make navCallback actually versatile --- .../controllers/enterprise_controller.js.coffee | 2 +- .../admin/utils/directives/navigation_check.js.coffee | 11 +++++++---- app/views/admin/enterprises/_ng_form.html.haml | 2 +- app/views/admin/order_cycles/index.html.haml | 2 -- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee index 688bf45a99..0fa452a8d6 100644 --- a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee +++ b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee @@ -6,7 +6,7 @@ angular.module("admin.enterprises") # htmlVariable is used by textAngular wysiwyg for the long descrtiption. $scope.htmlVariable = longDescription # Provide a callback for a warning message displayed when leaving the page. - $scope.navigationCallback = -> + $scope.enterpriseNavCallback = -> "You are editing an enterprise!" for payment_method in $scope.PaymentMethods diff --git a/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee b/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee index 7eae3d69cd..6f5128d7bf 100644 --- a/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee +++ b/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee @@ -1,6 +1,9 @@ -angular.module("admin.utils").directive "navigationCheck", (NavigationCheck)-> - link: ($scope) -> +angular.module("admin.utils").directive "navCheck", (NavigationCheck)-> + restrict: 'A' + scope: + navCallback: '&' + link: (scope,element,attributes) -> # Define navigationCallback on a controller in $scope, otherwise this default will be used: - $scope.navigationCallback ||= -> + scope.navCallback ||= -> "You will lose any unsaved work!" - NavigationCheck.register($scope.navigationCallback) + NavigationCheck.register(scope.navCallback) diff --git a/app/views/admin/enterprises/_ng_form.html.haml b/app/views/admin/enterprises/_ng_form.html.haml index 74b4347f16..e3ebe95877 100644 --- a/app/views/admin/enterprises/_ng_form.html.haml +++ b/app/views/admin/enterprises/_ng_form.html.haml @@ -3,7 +3,7 @@ = admin_inject_payment_methods = admin_inject_shipping_methods -.sixteen.columns.alpha{ ng: { app: 'admin.enterprises', controller: 'enterpriseCtrl' }, "navigation-check" => "" } +.sixteen.columns.alpha{ ng: { app: 'admin.enterprises', controller: 'enterpriseCtrl' }, nav: { check: '', callback: 'enterpriseNavCallback()' }} .eleven.columns.alpha = render 'form', f: f .one.column   diff --git a/app/views/admin/order_cycles/index.html.haml b/app/views/admin/order_cycles/index.html.haml index 1fac06f507..f9f832d83d 100644 --- a/app/views/admin/order_cycles/index.html.haml +++ b/app/views/admin/order_cycles/index.html.haml @@ -5,8 +5,6 @@ %li#new_order_cycle_link = button_link_to "New Order Cycle", main_app.new_admin_order_cycle_path, :icon => 'icon-plus', :id => 'admin_new_order_cycle_link' - - = form_for @order_cycle_set, :url => main_app.bulk_update_admin_order_cycles_path do |f| %table.index#listing_order_cycles %colgroup From 87cc1d6217ae2f033e839c9631d79547f5811f1c Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sat, 18 Oct 2014 01:42:58 +1100 Subject: [PATCH 130/142] create db/backup folder if it dosnt exist --- script/backup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/script/backup.sh b/script/backup.sh index 462aef6abe..114a8352c6 100755 --- a/script/backup.sh +++ b/script/backup.sh @@ -4,4 +4,5 @@ set -e +mkdir -p db/backup ssh $1 "pg_dump -h localhost -U openfoodweb openfoodweb_production |gzip" > db/backup/$1-`date +%Y%m%d`.sql.gz From b71a40ae6dc75b7fc34389a86688cb2359ea847f Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sat, 18 Oct 2014 03:26:57 +1100 Subject: [PATCH 131/142] show all permitted enterprises in order cycle summery --- app/views/admin/order_cycles/_row.html.haml | 4 ++-- spec/features/admin/order_cycles_spec.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/views/admin/order_cycles/_row.html.haml b/app/views/admin/order_cycles/_row.html.haml index 75e84de025..3b8c6f34bc 100644 --- a/app/views/admin/order_cycles/_row.html.haml +++ b/app/views/admin/order_cycles/_row.html.haml @@ -5,12 +5,12 @@ %td= order_cycle_form.text_field :orders_open_at, :class => 'datetimepicker', :value => order_cycle.orders_open_at %td= order_cycle_form.text_field :orders_close_at, :class => 'datetimepicker', :value => order_cycle.orders_close_at %td.suppliers - - order_cycle.suppliers.managed_by(spree_current_user).each do |s| + - order_cycle.suppliers.merge(OpenFoodNetwork::Permissions.new(spree_current_user).order_cycle_enterprises).each do |s| = s.name %br/ %td= order_cycle.coordinator.name %td.distributors - - order_cycle.distributors.managed_by(spree_current_user).each do |d| + - order_cycle.distributors.merge(OpenFoodNetwork::Permissions.new(spree_current_user).order_cycle_enterprises).each do |d| = d.name %br/ diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index febd966109..be91d442e1 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -471,6 +471,10 @@ feature %q{ # I should see only the order cycle I am coordinating page.should have_content oc_user_coordinating.name page.should_not have_content oc_for_other_user.name + + # The order cycle should show enterprises that I manage + page.should have_selector 'td.suppliers', text: supplier_managed.name + page.should have_selector 'td.distributors', text: distributor_managed.name # The order cycle should not show enterprises that I don't manage page.should_not have_selector 'td.suppliers', text: supplier_unmanaged.name From 2a7dd8b8f1eeeb331d929e2a64041c6fbd1ed04d Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sat, 18 Oct 2014 06:53:38 +1100 Subject: [PATCH 132/142] update ability specs for reports --- spec/models/spree/ability_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index 62e1973e7f..796aed2592 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -152,11 +152,11 @@ module Spree end it "should be able to read some reports" do - should have_ability([:admin, :index, :customers, :orders_and_fulfillment, :products_and_inventory], for: :reports) + should have_ability([:admin, :index, :customers, :bulk_coop, :orders_and_fulfillment, :products_and_inventory], for: :reports) end it "should not be able to read other reports" do - should_not have_ability([:sales_total, :group_buys, :bulk_coop, :payments], for: :reports) + should_not have_ability([:sales_total, :group_buys, :payments, :orders_and_distributors], for: :reports) end end @@ -247,7 +247,7 @@ module Spree end it "should be able to read some reports" do - should have_ability([:admin, :index, :customers, :group_buys, :bulk_coop, :payments, :orders_and_fulfillment, :products_and_inventory], for: :reports) + should have_ability([:admin, :index, :customers, :group_buys, :bulk_coop, :payments, :orders_and_distributors, :orders_and_fulfillment, :products_and_inventory], for: :reports) end it "should not be able to read other reports" do From 9e0f8100d935ee416c1c320034a47b6b2954a612 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sat, 18 Oct 2014 08:28:08 +1100 Subject: [PATCH 133/142] only producers have product permissions --- app/models/spree/ability_decorator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index 4a77a2651b..1fb824d09c 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -23,7 +23,7 @@ class AbilityDecorator # Users can manage products if they have an enterprise. def can_manage_products?(user) - can_manage_enterprises? user + can_manage_enterprises?(user) && user.enterprises.is_primary_producer.present? end # Users can manage orders if they have a sells own/any enterprise. From fec8f08966b4695a51a17867599c0c371fcbd685 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sat, 18 Oct 2014 16:15:41 +1100 Subject: [PATCH 134/142] use sql for migration --- ...140927005043_enterprise_config_refactor.rb | 53 ++++++++++--------- db/schema.rb | 2 +- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/db/migrate/20140927005043_enterprise_config_refactor.rb b/db/migrate/20140927005043_enterprise_config_refactor.rb index f9e8c936ce..f497e62f10 100644 --- a/db/migrate/20140927005043_enterprise_config_refactor.rb +++ b/db/migrate/20140927005043_enterprise_config_refactor.rb @@ -4,8 +4,19 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration add_index :enterprises, :sells add_index :enterprises, [:is_primary_producer, :sells] - Enterprise.all.each do |enterprise| - enterprise.update_attributes!({:sells => sells_what?(enterprise)}) + # Combine is_distributor and type into sells. + db.select_values("SELECT id FROM enterprises").each do |enterprise_id| + distributor = db.select_values("SELECT is_distributor FROM enterprises WHERE id = #{db.quote(enterprise_id)}") + primary_producer = db.select_value("SELECT is_distributor FROM enterprises WHERE id = #{db.quote(enterprise_id)}") + type = db.select_value("SELECT type FROM enterprises WHERE id = #{db.quote(enterprise_id)}") + if type == "single" && (distributor || primary_producer) + sells = "own" + elsif !distributor || type == "profile" + sells = "none" + else + sells = "any" + end + db.update("UPDATE enterprises SET sells = #{db.quote(sells)} WHERE id = #{db.quote(enterprise_id)}") end remove_column :enterprises, :type @@ -17,33 +28,25 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration add_column :enterprises, :type, :string, null: false, default: 'profile' add_column :enterprises, :is_distributor, :boolean - Enterprise.all.each do |enterprise| - enterprise.update_attributes!({ - :type => type?(enterprise), - :is_distributor => distributes?(enterprise) - }) + # Combine is_distributor and type into sells. + db.select_values("SELECT id FROM enterprises").each do |enterprise_id| + sells = db.select_value("SELECT sells FROM enterprises WHERE id = #{db.quote(enterprise_id)}") + case sells + when "own" + type = "single" + when "any" + type = "full" + else + type = "profile" + end + distributor = sells != "none" + db.update("UPDATE enterprises SET type = #{db.quote(type)}, is_distributor = #{db.quote(distributor)} WHERE id = #{db.quote(enterprise_id)}") end remove_column :enterprises, :sells end - def sells_what?(enterprise) - is_distributor = enterprise.read_attribute(:is_distributor) - is_primary_producer = enterprise.read_attribute(:is_primary_producer) - type = enterprise.read_attribute(:type) - return "own" if type == "single" && (is_distributor || is_primary_producer) - return "none" if !is_distributor || type == "profile" - return "any" - end - - def distributes?(enterprise) - enterprise.read_attribute(:sells) != "none" - end - - def type?(enterprise) - sells = enterprise.read_attribute(:sells) - return "profile" if sells == "none" - return "single" if sells == "own" - return "full" + def db + ActiveRecord::Base.connection end end diff --git a/db/schema.rb b/db/schema.rb index 974dc8ac9b..114dcd6b73 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -264,11 +264,11 @@ ActiveRecord::Schema.define(:version => 20141010043405) do t.string "instagram" t.string "linkedin" t.integer "owner_id", :null => false + t.string "sells", :default => "none", :null => false t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.string "unconfirmed_email" - t.string "sells", :default => "none", :null => false end add_index "enterprises", ["address_id"], :name => "index_enterprises_on_address_id" From 4308f7d09c4949ac1ee9de640e195567d19637f7 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Oct 2014 09:43:10 +1100 Subject: [PATCH 135/142] Revert "use sql for migration" This reverts commit fec8f08966b4695a51a17867599c0c371fcbd685. --- ...140927005043_enterprise_config_refactor.rb | 53 +++++++++---------- db/schema.rb | 2 +- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/db/migrate/20140927005043_enterprise_config_refactor.rb b/db/migrate/20140927005043_enterprise_config_refactor.rb index f497e62f10..f9e8c936ce 100644 --- a/db/migrate/20140927005043_enterprise_config_refactor.rb +++ b/db/migrate/20140927005043_enterprise_config_refactor.rb @@ -4,19 +4,8 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration add_index :enterprises, :sells add_index :enterprises, [:is_primary_producer, :sells] - # Combine is_distributor and type into sells. - db.select_values("SELECT id FROM enterprises").each do |enterprise_id| - distributor = db.select_values("SELECT is_distributor FROM enterprises WHERE id = #{db.quote(enterprise_id)}") - primary_producer = db.select_value("SELECT is_distributor FROM enterprises WHERE id = #{db.quote(enterprise_id)}") - type = db.select_value("SELECT type FROM enterprises WHERE id = #{db.quote(enterprise_id)}") - if type == "single" && (distributor || primary_producer) - sells = "own" - elsif !distributor || type == "profile" - sells = "none" - else - sells = "any" - end - db.update("UPDATE enterprises SET sells = #{db.quote(sells)} WHERE id = #{db.quote(enterprise_id)}") + Enterprise.all.each do |enterprise| + enterprise.update_attributes!({:sells => sells_what?(enterprise)}) end remove_column :enterprises, :type @@ -28,25 +17,33 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration add_column :enterprises, :type, :string, null: false, default: 'profile' add_column :enterprises, :is_distributor, :boolean - # Combine is_distributor and type into sells. - db.select_values("SELECT id FROM enterprises").each do |enterprise_id| - sells = db.select_value("SELECT sells FROM enterprises WHERE id = #{db.quote(enterprise_id)}") - case sells - when "own" - type = "single" - when "any" - type = "full" - else - type = "profile" - end - distributor = sells != "none" - db.update("UPDATE enterprises SET type = #{db.quote(type)}, is_distributor = #{db.quote(distributor)} WHERE id = #{db.quote(enterprise_id)}") + Enterprise.all.each do |enterprise| + enterprise.update_attributes!({ + :type => type?(enterprise), + :is_distributor => distributes?(enterprise) + }) end remove_column :enterprises, :sells end - def db - ActiveRecord::Base.connection + def sells_what?(enterprise) + is_distributor = enterprise.read_attribute(:is_distributor) + is_primary_producer = enterprise.read_attribute(:is_primary_producer) + type = enterprise.read_attribute(:type) + return "own" if type == "single" && (is_distributor || is_primary_producer) + return "none" if !is_distributor || type == "profile" + return "any" + end + + def distributes?(enterprise) + enterprise.read_attribute(:sells) != "none" + end + + def type?(enterprise) + sells = enterprise.read_attribute(:sells) + return "profile" if sells == "none" + return "single" if sells == "own" + return "full" end end diff --git a/db/schema.rb b/db/schema.rb index 114dcd6b73..974dc8ac9b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -264,11 +264,11 @@ ActiveRecord::Schema.define(:version => 20141010043405) do t.string "instagram" t.string "linkedin" t.integer "owner_id", :null => false - t.string "sells", :default => "none", :null => false t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.string "unconfirmed_email" + t.string "sells", :default => "none", :null => false end add_index "enterprises", ["address_id"], :name => "index_enterprises_on_address_id" From b75af8d9fff0955c9f1f8fc0c18d22f12b278562 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Oct 2014 10:49:23 +1100 Subject: [PATCH 136/142] Fix sells column coming out all 'none' --- db/migrate/20140927005043_enterprise_config_refactor.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/db/migrate/20140927005043_enterprise_config_refactor.rb b/db/migrate/20140927005043_enterprise_config_refactor.rb index f9e8c936ce..6b51ac6e50 100644 --- a/db/migrate/20140927005043_enterprise_config_refactor.rb +++ b/db/migrate/20140927005043_enterprise_config_refactor.rb @@ -1,9 +1,15 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration + class Enterprise < ActiveRecord::Base + self.inheritance_column = nil + end + def up add_column :enterprises, :sells, :string, null: false, default: 'none' add_index :enterprises, :sells add_index :enterprises, [:is_primary_producer, :sells] + Enterprise.reset_column_information + Enterprise.all.each do |enterprise| enterprise.update_attributes!({:sells => sells_what?(enterprise)}) end @@ -17,6 +23,8 @@ class EnterpriseConfigRefactor < ActiveRecord::Migration add_column :enterprises, :type, :string, null: false, default: 'profile' add_column :enterprises, :is_distributor, :boolean + Enterprise.reset_column_information + Enterprise.all.each do |enterprise| enterprise.update_attributes!({ :type => type?(enterprise), From 175e430a2bedd47ea9b8f550eeb88c55f1937364 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Wed, 22 Oct 2014 14:51:17 +1100 Subject: [PATCH 137/142] uss oop for nav check --- .../directives/navigation_check.js.coffee | 2 +- .../utils/services/navigation_check.js.coffee | 67 +++++++++++-------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee b/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee index 6f5128d7bf..95f52505eb 100644 --- a/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee +++ b/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee @@ -3,7 +3,7 @@ angular.module("admin.utils").directive "navCheck", (NavigationCheck)-> scope: navCallback: '&' link: (scope,element,attributes) -> - # Define navigationCallback on a controller in $scope, otherwise this default will be used: + # Define navigationCallback on a controller in scope, otherwise this default will be used: scope.navCallback ||= -> "You will lose any unsaved work!" NavigationCheck.register(scope.navCallback) diff --git a/app/assets/javascripts/admin/utils/services/navigation_check.js.coffee b/app/assets/javascripts/admin/utils/services/navigation_check.js.coffee index 1aea4e087f..ff1041474c 100644 --- a/app/assets/javascripts/admin/utils/services/navigation_check.js.coffee +++ b/app/assets/javascripts/admin/utils/services/navigation_check.js.coffee @@ -1,37 +1,46 @@ angular.module("admin.utils") .factory "NavigationCheck", ($window, $rootScope) -> - callbacks = [] + new class NavigationCheck + callbacks = [] + constructor: -> + if $window.addEventListener + $window.addEventListener "beforeunload", @onBeforeUnloadHandler + else + $window.onbeforeunload = @onBeforeUnloadHandler - # Action for regular browser navigation. - onBeforeUnloadHandler = ($event) -> - message = getMessage() - if message - ($event or $window.event).preventDefault() + $rootScope.$on "$locationChangeStart", @locationChangeStartHandler + + + # Action for regular browser navigation. + onBeforeUnloadHandler: ($event) => + message = @getMessage() + if message + ($event or $window.event).preventDefault() + message + + # Action for angular navigation. + locationChangeStartHandler: ($event) => + message = @getMessage() + if message and not $window.confirm(message) + $event.stopPropagation() if $event.stopPropagation + $event.preventDefault() if $event.preventDefault + $event.cancelBubble = true + $event.returnValue = false + + # Runs callback functions to retreive most recently added non-empty message. + getMessage: -> + message = null + message = callback() ? message for callback in callbacks message - # Action for angular navigation. - locationChangeStartHandler = ($event) -> - message = getMessage() - if message and not $window.confirm(message) - $event.stopPropagation() if $event.stopPropagation - $event.preventDefault() if $event.preventDefault - $event.cancelBubble = true - $event.returnValue = false + register: (callback) => + callbacks.push callback - # Runs callback functions to retreive most recently added non-empty message. - getMessage = -> - message = null - message = callback() ? message for callback in callbacks - message + clear: => + if $window.addEventListener + $window.removeEventListener "beforeunload", @onBeforeUnloadHandler + else + $window.onbeforeunload = null - register = (callback) -> - callbacks.push callback + $rootScope.$on "$locationChangeStart", null - if $window.addEventListener - $window.addEventListener "beforeunload", onBeforeUnloadHandler - else - $window.onbeforeunload = onBeforeUnloadHandler - - $rootScope.$on "$locationChangeStart", locationChangeStartHandler - - return register: register From afa6119ec1aa6e9f8a3d38e2e0620574aa02345a Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Wed, 22 Oct 2014 14:53:20 +1100 Subject: [PATCH 138/142] better coverage for enterprise abilities, hide products from non producers --- spec/models/spree/ability_spec.rb | 43 +++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index c44601bb86..caf09853f1 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -12,30 +12,63 @@ module Spree let(:enterprise_any) { create(:enterprise, sells: 'any') } let(:enterprise_own) { create(:enterprise, sells: 'own') } let(:enterprise_none) { create(:enterprise, sells: 'none') } + let(:enterprise_any_producer) { create(:enterprise, sells: 'any', is_primary_producer: true) } + let(:enterprise_own_producer) { create(:enterprise, sells: 'own', is_primary_producer: true) } + let(:enterprise_none_producer) { create(:enterprise, sells: 'none', is_primary_producer: true) } - context "as manager of a 'any' type enterprise" do + context "as manager of an enterprise who sells 'any'" do before do user.enterprise_roles.create! enterprise: enterprise_any end - it { subject.can_manage_products?(user).should be_true } + it { subject.can_manage_products?(user).should be_false } it { subject.can_manage_enterprises?(user).should be_true } it { subject.can_manage_orders?(user).should be_true } end - context "as manager of a 'own' type enterprise" do + context "as manager of an enterprise who sell 'own'" do before do user.enterprise_roles.create! enterprise: enterprise_own end + it { subject.can_manage_products?(user).should be_false } + it { subject.can_manage_enterprises?(user).should be_true } + it { subject.can_manage_orders?(user).should be_true } + end + + context "as manager of an enterprise who sells 'none'" do + before do + user.enterprise_roles.create! enterprise: enterprise_none + end + + it { subject.can_manage_products?(user).should be_false } + it { subject.can_manage_enterprises?(user).should be_true } + it { subject.can_manage_orders?(user).should be_false } + end + + context "as manager of a producer enterprise who sells 'any'" do + before do + user.enterprise_roles.create! enterprise: enterprise_any_producer + end + it { subject.can_manage_products?(user).should be_true } it { subject.can_manage_enterprises?(user).should be_true } it { subject.can_manage_orders?(user).should be_true } end - context "as manager of a 'none' type enterprise" do + context "as manager of a producer enterprise who sell 'own'" do before do - user.enterprise_roles.create! enterprise: enterprise_none + user.enterprise_roles.create! enterprise: enterprise_own_producer + end + + it { subject.can_manage_products?(user).should be_true } + it { subject.can_manage_enterprises?(user).should be_true } + it { subject.can_manage_orders?(user).should be_true } + end + + context "as manager of a producer enterprise who sells 'none'" do + before do + user.enterprise_roles.create! enterprise: enterprise_none_producer end it { subject.can_manage_products?(user).should be_true } From a53cbb677d0b1537f4d9582e4ccd80cddd30918e Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Wed, 22 Oct 2014 14:55:01 +1100 Subject: [PATCH 139/142] fix report typos --- spec/models/spree/ability_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index caf09853f1..e523cce755 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -185,11 +185,11 @@ module Spree end it "should be able to read some reports" do - should have_ability([:admin, :index, :customers, :bulk_coop, :orders_and_fulfillment, :products_and_inventory], for: :reports) + should have_ability([:admin, :index, :customers, :bulk_coop, :orders_and_fulfillment, :products_and_inventory], for: :report) end it "should not be able to read other reports" do - should_not have_ability([:sales_total, :group_buys, :payments, :orders_and_distributors], for: :reports) + should_not have_ability([:sales_total, :group_buys, :payments, :orders_and_distributors], for: :report) end end @@ -280,16 +280,16 @@ module Spree end it "should be able to read some reports" do - should have_ability([:admin, :index, :customers, :group_buys, :bulk_coop, :payments, :orders_and_distributors, :orders_and_fulfillment, :products_and_inventory], for: :reports) + should have_ability([:admin, :index, :customers, :group_buys, :bulk_coop, :payments, :orders_and_distributors, :orders_and_fulfillment, :products_and_inventory], for: :report) end it "should not be able to read other reports" do - should_not have_ability([:sales_total], for: :reports) + should_not have_ability([:sales_total], for: :report) end end - context 'Order Cycle co-ordinator, distriutor enterprise manager' do + context 'Order Cycle co-ordinator, distributor enterprise manager' do let (:user) do user = create(:user) user.spree_roles = [] From 96ff387d1fa571b924e4cf7307e455e254f5bfe0 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Wed, 22 Oct 2014 15:34:09 +1100 Subject: [PATCH 140/142] fix navigation check on submission --- .../controllers/enterprise_controller.js.coffee | 8 ++++++-- app/views/admin/enterprises/edit.html.haml | 2 +- app/views/admin/enterprises/new.html.haml | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee index 0fa452a8d6..cfcf6319af 100644 --- a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee +++ b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee @@ -1,11 +1,15 @@ angular.module("admin.enterprises") - .controller "enterpriseCtrl", ($scope, longDescription, Enterprise, PaymentMethods, ShippingMethods) -> + .controller "enterpriseCtrl", ($scope, longDescription, NavigationCheck, Enterprise, PaymentMethods, ShippingMethods) -> $scope.Enterprise = Enterprise.enterprise $scope.PaymentMethods = PaymentMethods.paymentMethods $scope.ShippingMethods = ShippingMethods.shippingMethods + $scope.navClear = NavigationCheck.clear # htmlVariable is used by textAngular wysiwyg for the long descrtiption. $scope.htmlVariable = longDescription - # Provide a callback for a warning message displayed when leaving the page. + + # Provide a callback for generating warning messages displayed before leaving the page. This is passed in + # from a directive "nav-check" in the page - if we pass it here it will be called in the test suite, + # and on all new uses of this contoller, and we might not want that . $scope.enterpriseNavCallback = -> "You are editing an enterprise!" diff --git a/app/views/admin/enterprises/edit.html.haml b/app/views/admin/enterprises/edit.html.haml index 6a8d48b24b..3c132bf5e2 100644 --- a/app/views/admin/enterprises/edit.html.haml +++ b/app/views/admin/enterprises/edit.html.haml @@ -4,7 +4,7 @@ Editing: = @enterprise.name -= form_for [main_app, :admin, @enterprise] do |f| += form_for [main_app, :admin, @enterprise], html: { "ng-app" => 'admin.enterprises', "ng-submit" => "navClear()", "ng-controller" => 'enterpriseCtrl' , "nav-check" => '', "nav-callback" => 'enterpriseNavCallback()' } do |f| = render 'ng_form', 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 32f6ea0a8d..3df3551f47 100644 --- a/app/views/admin/enterprises/new.html.haml +++ b/app/views/admin/enterprises/new.html.haml @@ -3,7 +3,7 @@ - content_for :page_title do New Enterprise -= form_for [main_app, :admin, @enterprise] do |f| - = render partial: 'ng_form', :locals => { f: f } += form_for [main_app, :admin, @enterprise], html: { "ng-app" => 'admin.enterprises', "ng-submit" => "navClear()", "ng-controller" => 'enterpriseCtrl' , "nav-check" => '', "nav-callback" => 'enterpriseNavCallback()' } do |f| + = render 'ng_form', f: f .twelve.columns.alpha = render partial: 'spree/admin/shared/new_resource_links' From 69614d6cf149782c47a88e3e02a92210081fbef9 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Wed, 22 Oct 2014 17:23:06 +1100 Subject: [PATCH 141/142] fix accordion jumps --- app/views/checkout/_shipping.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/checkout/_shipping.html.haml b/app/views/checkout/_shipping.html.haml index 27089527a2..5ba5ed15e4 100644 --- a/app/views/checkout/_shipping.html.haml +++ b/app/views/checkout/_shipping.html.haml @@ -83,4 +83,4 @@ .row .small-12.columns.text-right - %button.primary{"ng-disabled" => "shipping.$invalid", "ng-click" => "next($event)", "ofn-focus" => "accordion['shipping']"} Next + %button.primary{"ng-disabled" => "shipping.$invalid", "ng-click" => "next($event)"} Next From 069b9ce91d89cf489488ca0950b8b69b7df4d656 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Wed, 22 Oct 2014 17:49:31 +1100 Subject: [PATCH 142/142] fix email length validation spec --- spec/models/enterprise_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 7adeb08d2d..206be1e131 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -105,7 +105,7 @@ describe Enterprise do subject { FactoryGirl.create(:distributor_enterprise, :address => FactoryGirl.create(:address)) } it { should validate_presence_of(:name) } it { should validate_presence_of(:email) } - it { should validate_length_of(:description, :maximum => 255) } + it { should ensure_length_of(:description).is_at_most(255) } it "requires an owner" do expect{