mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-23 05:28:53 +00:00
Adding new producer modal and dereferencing shopfront
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user