From 7f4816c9a5ec96e77d497de04b319cdb72df5776 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 19 Jun 2014 14:00:37 +1000 Subject: [PATCH] Adding new producer modal and dereferencing shopfront --- .../product_node_controller.js.coffee | 2 +- .../darkswarm/services/product.js.coffee | 7 ++- app/controllers/shop_controller.rb | 1 + app/views/modals/_producer.html.haml | 58 ++++++------------- app/views/shop/products.rabl | 9 +-- app/views/shop/products/_form.html.haml | 1 + .../darkswarm/services/product_spec.js.coffee | 15 ++++- 7 files changed, 43 insertions(+), 50 deletions(-) diff --git a/app/assets/javascripts/darkswarm/controllers/products/product_node_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/products/product_node_controller.js.coffee index f016d2e43f..73406e072b 100644 --- a/app/assets/javascripts/darkswarm/controllers/products/product_node_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/products/product_node_controller.js.coffee @@ -7,5 +7,5 @@ Darkswarm.controller "ProductNodeCtrl", ($scope) -> else $scope.product.price - $scope.producer = $scope.product.supplier + $scope.enterprise = $scope.product.supplier # For the modal, so it's consistent $scope.hasVariants = $scope.product.variants.length > 0 diff --git a/app/assets/javascripts/darkswarm/services/product.js.coffee b/app/assets/javascripts/darkswarm/services/product.js.coffee index 21c0921e41..2c57512bff 100644 --- a/app/assets/javascripts/darkswarm/services/product.js.coffee +++ b/app/assets/javascripts/darkswarm/services/product.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.factory 'Product', ($resource) -> +Darkswarm.factory 'Product', ($resource, Enterprises) -> new class Product constructor: -> @update() @@ -11,5 +11,10 @@ Darkswarm.factory 'Product', ($resource) -> update: => @loading = true @products = $resource("/shop/products").query => + @dereference() @loading = false @ + + dereference: -> + for product in @products + product.supplier = Enterprises.enterprises_by_id[product.supplier.id] diff --git a/app/controllers/shop_controller.rb b/app/controllers/shop_controller.rb index 8406a15951..b3e338e645 100644 --- a/app/controllers/shop_controller.rb +++ b/app/controllers/shop_controller.rb @@ -2,6 +2,7 @@ class ShopController < BaseController layout "darkswarm" before_filter :require_distributor_chosen before_filter :set_order_cycles + before_filter :load_active_distributors def show end diff --git a/app/views/modals/_producer.html.haml b/app/views/modals/_producer.html.haml index 51dc79ed72..22313fa0b8 100644 --- a/app/views/modals/_producer.html.haml +++ b/app/views/modals/_producer.html.haml @@ -1,43 +1,23 @@ -%ofn-modal{title: "{{producer.name}}"} - .row - .small-12.columns.producer-hero - %h3.producer-name +%ofn-modal{title: "{{enterprise.name}}"} + .highlight + .highlight-row + %p.right + {{ enterprise.address.city }} , {{enterprise.address.state}} + %h3 %i.ofn-i_036-producers - {{ producer.name }} - %img.producer-hero-img{"ng-src" => "{{producer.promo_image}}"} + {{ enterprise.name }} - .row + %img.producer-hero-img{"ng-src" => "{{enterprise.promo_image}}"} + + .row.pad-top{bindonce: true} .small-12.large-6.columns - %p{"ng-bind-html" => "producer.long_description"} - .small-8.large-4.columns - %a{"ng-href" => '/producers##{{producer.hash}}'} - Find my products - %img.producer-logo{"ng-src" => "{{producer.logo}}", "ng-if" => "producer.logo"} - .small-4.large-2.columns - %ul.small-block-grid-1{bindonce: true} - %li{"ng-if" => "producer.website"} - %a{"ng-href" => "http://{{producer.website | stripUrl}}", target: "_blank" } - %i.ofn-i_049-web - - %li{"ng-if" => "producer.email"} - %a{"ng-href" => "mailto:{{producer.email | stripUrl}}", target: "_blank" } - %i.ofn-i_050-mail-circle - - %li{"ng-if" => "producer.twitter"} - %a{"ng-href" => "http://twitter.com/{{producer.twitter}}", target: "_blank"} - %i.ofn-i_041-twitter - - %li{"ng-if" => "producer.facebook"} - %a{"ng-href" => "http://{{producer.facebook | stripUrl}}", target: "_blank"} - %i.ofn-i_044-facebook - - %li{"ng-if" => "producer.linkedin"} - %a{"ng-href" => "http://{{producer.linkedin | stripUrl}}", target: "_blank"} - %i.ofn-i_042-linkedin - - %li{"ng-if" => "producer.instagram"} - %a{"ng-href" => "http://instagram.com/{{producer.instagram}}", target: "_blank"} - %i.ofn-i_043-instagram - - %a.close-reveal-modal{"ng-click" => "$close()"} + %img.producer-logo{"bo-src" => "enterprise.logo", "bo-if" => "enterprise.logo"} + %h5.modal-header About + %p{"ng-bind-html" => "enterprise.long_description"} + + .small-12.large-6.columns + %ng-include{src: "'partials/contact.html'"} + %ng-include{src: "'partials/follow.html'"} + + %a.close-reveal-modal.outside{"ng-click" => "$close()"} %i.ofn-i_009-close diff --git a/app/views/shop/products.rabl b/app/views/shop/products.rabl index eb5d62644a..b934272b9a 100644 --- a/app/views/shop/products.rabl +++ b/app/views/shop/products.rabl @@ -10,14 +10,7 @@ node do |product| end child :supplier => :supplier do - attributes :id, :name, :description, :long_description, :website, :instagram, :facebook, :linkedin, :twitter - - node :logo do |supplier| - supplier.logo(:medium) if supplier.logo.exists? - end - node :promo_image do |supplier| - supplier.promo_image(:large) if supplier.promo_image.exists? - end + attributes :id end child :primary_taxon => :primary_taxon do diff --git a/app/views/shop/products/_form.html.haml b/app/views/shop/products/_form.html.haml index 724ec7b249..65a02cbaca 100644 --- a/app/views/shop/products/_form.html.haml +++ b/app/views/shop/products/_form.html.haml @@ -1,5 +1,6 @@ %products.small-12.columns{"ng-controller" => "ProductsCtrl", "ng-show" => "order_cycle.order_cycle_id != null", "infinite-scroll" => "incrementLimit()", "infinite-scroll-distance" => "1"} + = inject_enterprises = form_for :order, :url => populate_orders_path, html: {:class => "custom"} do diff --git a/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee index c053573565..bddd8168f6 100644 --- a/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee @@ -1,14 +1,27 @@ describe 'Product service', -> $httpBackend = null Product = null + Enterprises = null + product = + test: "cats" + supplier: + id: 9 beforeEach -> module 'Darkswarm' inject ($injector, _$httpBackend_)-> Product = $injector.get("Product") + Enterprises = $injector.get("Enterprises") $httpBackend = _$httpBackend_ it "Fetches products from the backend on init", -> - $httpBackend.expectGET("/shop/products").respond([{test : "cats"}]) + $httpBackend.expectGET("/shop/products").respond([product]) $httpBackend.flush() expect(Product.products[0].test).toEqual "cats" + + it "dereferences suppliers", -> + Enterprises.enterprises_by_id = + {id: 9, name: "test"} + $httpBackend.expectGET("/shop/products").respond([{supplier : {id: 9}}]) + $httpBackend.flush() + expect(Product.products[0].supplier).toBe Enterprises.enterprises_by_id["9"]