mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Dereferencing groups and adding modals to page
This commit is contained in:
@@ -6,7 +6,7 @@ Darkswarm.directive "activeTableHubLink", (CurrentHub, CurrentOrder) ->
|
||||
link: (scope, elm, attr)->
|
||||
# Swap out the text of the hub link depending on whether it'll change current hub
|
||||
# To be used with ofnEmptiesCart
|
||||
if CurrentHub.hub.id and CurrentHub.hub.id isnt scope.hub.id
|
||||
if CurrentHub.hub?.id and CurrentHub.hub.id isnt scope.hub.id
|
||||
scope.action = attr.change
|
||||
else
|
||||
scope.action = attr.shop
|
||||
|
||||
@@ -3,7 +3,7 @@ Darkswarm.directive "ofnEmptiesCart", (CurrentHub, CurrentOrder, Navigation, sto
|
||||
link: (scope, elm, attr)->
|
||||
hub = scope.$eval(attr.ofnEmptiesCart)
|
||||
# A hub is selected, we're changing to a different hub, and the cart isn't empty
|
||||
if CurrentHub.hub.id and CurrentHub.hub.id isnt hub.id
|
||||
if CurrentHub.hub?.id and CurrentHub.hub.id isnt hub.id
|
||||
unless CurrentOrder.empty()
|
||||
elm.bind 'click', (ev)->
|
||||
ev.preventDefault()
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
Darkswarm.directive "hubModal", ($modal)->
|
||||
restrict: 'E'
|
||||
replace: true
|
||||
template: "<a>{{enterprise.name}}</a>"
|
||||
link: (scope, elem, attrs, ctrl)->
|
||||
elem.on "click", =>
|
||||
scope.modalInstance = $modal.open(controller: ctrl, templateUrl: 'hub_modal.html', scope: scope)
|
||||
@@ -0,0 +1,6 @@
|
||||
Darkswarm.factory 'Dereferencer', ->
|
||||
new class Dereferencer
|
||||
dereference: (array, data)->
|
||||
if array
|
||||
for object, i in array
|
||||
array[i] = data[object.id]
|
||||
@@ -1,4 +1,4 @@
|
||||
Darkswarm.factory 'Enterprises', (enterprises, CurrentHub)->
|
||||
Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Dereferencer)->
|
||||
new class Enterprises
|
||||
enterprises_by_id: {} # id/object pairs for lookup
|
||||
constructor: ->
|
||||
@@ -10,12 +10,6 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub)->
|
||||
dereference: ->
|
||||
if CurrentHub.hub?.id
|
||||
CurrentHub.hub = @enterprises_by_id[CurrentHub.hub.id]
|
||||
|
||||
for enterprise in @enterprises
|
||||
if enterprise.hubs
|
||||
for hub, i in enterprise.hubs
|
||||
enterprise.hubs[i] = @enterprises_by_id[hub.id]
|
||||
|
||||
if enterprise.producers
|
||||
for producer, i in enterprise.producers
|
||||
enterprise.producers[i] = @enterprises_by_id[producer.id]
|
||||
Dereferencer.dereference enterprise.hubs, @enterprises_by_id
|
||||
Dereferencer.dereference enterprise.producers, @enterprises_by_id
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
Darkswarm.factory 'Groups', (groups) ->
|
||||
Darkswarm.factory 'Groups', (groups, Enterprises, Dereferencer) ->
|
||||
new class Groups
|
||||
groups: groups
|
||||
groups_by_id: {}
|
||||
constructor: ->
|
||||
@groups = groups
|
||||
for group in @groups
|
||||
@groups_by_id[group.id] = group
|
||||
@dereference()
|
||||
dereference: ->
|
||||
for group in @groups
|
||||
Dereferencer.dereference group.enterprises, Enterprises.enterprises_by_id
|
||||
for enterprise in Enterprises.enterprises
|
||||
Dereferencer.dereference enterprise.groups, @groups_by_id
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ Darkswarm.factory "MapModal", ($modal, $rootScope)->
|
||||
scope.enterprise = enterprise
|
||||
if enterprise.is_distributor
|
||||
scope.hub = enterprise
|
||||
$modal.open(templateUrl: "map_modal_hub.html", scope: scope)
|
||||
$modal.open(templateUrl: "hub_modal.html", scope: scope)
|
||||
else
|
||||
scope.producer = enterprise
|
||||
$modal.open(templateUrl: "map_modal_producer.html", scope: scope)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
%p.right
|
||||
{{ [enterprise.address.city, enterprise.address.state] | printArray}}
|
||||
%h3
|
||||
%i.ofn-i_036-producers
|
||||
%i.ofn-i_036-producers{"ng-show" => "!enterprise.is_distributor"}
|
||||
%i.ofn-i_040-hub{"ng-show" => "enterprise.is_distributor"}
|
||||
{{ enterprise.name }}
|
||||
%img.hero-img{"ng-src" => "{{enterprise.promo_image}}"}
|
||||
|
||||
@@ -36,10 +36,11 @@
|
||||
.small-6.columns
|
||||
%p {{ group.long_description }}
|
||||
.small-6.columns
|
||||
%h5 Our hubs & producers
|
||||
%h5 Our hubs & producers
|
||||
%ul.small-block-grid-2
|
||||
%li{"ng-repeat" => "enterprise in group.enterprises"}
|
||||
%a{"bo-href" => "enterprise.path"} {{ enterprise.name }}
|
||||
%hub-modal{"ng-if" => "enterprise.is_distributor"}
|
||||
%producer-modal{"ng-if" => "!enterprise.is_distributor"}
|
||||
|
||||
.row.group_footer
|
||||
.small-12.columns
|
||||
|
||||
@@ -2,7 +2,7 @@ collection @groups
|
||||
attributes :id, :name, :position, :description, :long_description
|
||||
|
||||
child enterprises: :enterprises do
|
||||
extends 'json/enterprises'
|
||||
attributes :id
|
||||
end
|
||||
|
||||
node :logo do |group|
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe GroupsController do
|
||||
render_views
|
||||
let(:enterprise) { create(:distributor_enterprise) }
|
||||
let!(:group) { create(:enterprise_group, enterprises: [enterprise], on_front_page: true) }
|
||||
it "gets all visible groups" do
|
||||
EnterpriseGroup.stub_chain :on_front_page, :by_position
|
||||
EnterpriseGroup.should_receive :on_front_page
|
||||
get :index
|
||||
end
|
||||
|
||||
it "loads all enterprises for group" do
|
||||
get :index
|
||||
response.body.should have_text enterprise.id
|
||||
end
|
||||
end
|
||||
|
||||
21
spec/features/consumer/groups_spec.rb
Normal file
21
spec/features/consumer/groups_spec.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature 'Groups', js: true do
|
||||
include AuthenticationWorkflow
|
||||
include UIComponentHelper
|
||||
|
||||
let(:enterprise) { create(:distributor_enterprise) }
|
||||
let!(:group) { create(:enterprise_group, enterprises: [enterprise], on_front_page: true) }
|
||||
|
||||
it "renders groups" do
|
||||
visit groups_path
|
||||
page.should have_content group.name
|
||||
end
|
||||
|
||||
it "renders enterprise modals for groups" do
|
||||
visit groups_path
|
||||
page.should have_content enterprise.name
|
||||
open_enterprise_modal enterprise
|
||||
modal_should_be_open_for enterprise
|
||||
end
|
||||
end
|
||||
@@ -36,9 +36,7 @@ feature 'Home', js: true do
|
||||
it "should show hub producer modals" do
|
||||
expand_active_table_node distributor.name
|
||||
page.should have_content producer.name
|
||||
find("a", text: producer.name).click
|
||||
within ".reveal-modal" do
|
||||
page.should have_content producer.name
|
||||
end
|
||||
open_enterprise_modal producer
|
||||
modal_should_be_open_for producer
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
describe "Groups service", ->
|
||||
Groups = null
|
||||
Enterprises = null
|
||||
CurrentHubMock = {}
|
||||
groups = [{
|
||||
id: 1
|
||||
name: "Test Group"
|
||||
enterprises: [
|
||||
{id: 1},
|
||||
{id: 2}
|
||||
]
|
||||
}]
|
||||
enterprises = [
|
||||
{id: 1, name: "Test 1", groups: [{id: 1}]},
|
||||
{id: 2, name: "Test 2", groups: [{id: 1}]}
|
||||
]
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
angular.module('Darkswarm').value('groups', groups)
|
||||
angular.module('Darkswarm').value('enterprises', enterprises)
|
||||
module ($provide)->
|
||||
$provide.value "CurrentHub", CurrentHubMock
|
||||
null
|
||||
inject (_Groups_, _Enterprises_)->
|
||||
Groups = _Groups_
|
||||
Enterprises = _Enterprises_
|
||||
|
||||
it "dereferences group enterprises", ->
|
||||
expect(Groups.groups[0].enterprises[0]).toBe enterprises[0]
|
||||
|
||||
it "dereferences enterprise groups", ->
|
||||
expect(Enterprises.enterprises[0].groups[0]).toBe groups[0]
|
||||
@@ -38,6 +38,16 @@ module UIComponentHelper
|
||||
have_selector ".login-modal"
|
||||
end
|
||||
|
||||
def open_enterprise_modal(enterprise)
|
||||
find("a", text: enterprise.name).click
|
||||
end
|
||||
|
||||
def modal_should_be_open_for(enterprise)
|
||||
within ".reveal-modal" do
|
||||
page.should have_content enterprise.name
|
||||
end
|
||||
end
|
||||
|
||||
def have_reset_password
|
||||
have_content "An email with instructions on resetting your password has been sent!"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user