Merge branch 'group-pages'

This commit is contained in:
Rohan Mitchell
2015-04-16 16:53:49 +10:00
7 changed files with 50 additions and 19 deletions

View File

@@ -1 +1 @@
angular.module("admin.enterprise_groups", ["admin.side_menu", "admin.users"])
angular.module("admin.enterprise_groups", ["admin.side_menu", "admin.users", "textAngular"])

View File

@@ -1,5 +1,4 @@
Darkswarm.controller "GroupEnterprisesCtrl", ($scope, Enterprises, Search, FilterSelectorsService) ->
$scope.Enterprises = Enterprises
Darkswarm.controller "GroupEnterprisesCtrl", ($scope, Search, FilterSelectorsService) ->
$scope.totalActive = FilterSelectorsService.totalActive
$scope.clearAll = FilterSelectorsService.clearAll
$scope.filterText = FilterSelectorsService.filterText

View File

@@ -0,0 +1,14 @@
Darkswarm.controller "GroupPageCtrl", ($scope, group_enterprises, Enterprises, MapConfiguration, OfnMap) ->
$scope.Enterprises = Enterprises
group_enterprises_ids = group_enterprises.map (enterprise) =>
enterprise.id
is_in_group = (enterprise) ->
group_enterprises_ids.indexOf(enterprise.id) != -1
$scope.group_producers = Enterprises.producers.filter is_in_group
$scope.group_hubs = Enterprises.hubs.filter is_in_group
$scope.map = angular.copy MapConfiguration.options
$scope.mapMarkers = OfnMap.enterprise_markers group_enterprises

View File

@@ -1,11 +1,13 @@
Darkswarm.factory "OfnMap", (Enterprises, EnterpriseModal, visibleFilter)->
Darkswarm.factory "OfnMap", (Enterprises, EnterpriseModal, visibleFilter) ->
new class OfnMap
constructor: ->
@enterprises = (@extend(enterprise) for enterprise in visibleFilter(Enterprises.enterprises))
@enterprises = @enterprise_markers(Enterprises.enterprises)
enterprise_markers: (enterprises) ->
@extend(enterprise) for enterprise in visibleFilter(enterprises)
# Adding methods to each enterprise
extend: (enterprise)->
extend: (enterprise) ->
new class MapMarker
# We're whitelisting attributes because GMaps tries to crawl
# our data, and our data is recursive, so it breaks

View File

@@ -36,12 +36,10 @@ 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, :category
:icon, :icon_font, :producer_icon_font, :category, :producers, :hubs
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
@@ -73,6 +71,14 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
enterprise_shop_path(object)
end
def producers
ActiveModel::ArraySerializer.new(object.suppliers.activated, {each_serializer: Api::IdSerializer})
end
def hubs
ActiveModel::ArraySerializer.new(object.distributors.activated, {each_serializer: Api::IdSerializer})
end
# Map svg icons.
def icon
icons = {

View File

@@ -1,6 +1,6 @@
%fieldset.alpha.no-border-bottom{ ng: { show: "menu.selected.name=='About'" } }
%legend About
= f.field_container :long_description do
= f.label :long_description
%br/
= f.text_area :long_description
%text-angular{'id' => 'enterprise_group_long_description', 'name' => 'enterprise_group[long_description]', 'class' => 'text-angular',
'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]"}
!= @enterprise_group[:long_description]

View File

@@ -1,4 +1,12 @@
#group-page.row.pad-top
-# inject all enterprises as "enterprises"
-# it could be more efficient to inject only the enterprises that are related to the group
= inject_enterprises
-# inject enterprises in this group
-# further hubs and producers of these enterprises can't be resoleved within this small subset
= inject_json_ams "group_enterprises", @group.enterprises, Api::EnterpriseSerializer, active_distributors: @active_distributors
#group-page.row.pad-top{"ng-controller" => "GroupPageCtrl"}
.small-12.columns.pad-top
%header
.row
@@ -22,18 +30,17 @@
%tab{heading: 'Map',
active: "active(\'\')",
select: "select(\'\')"}
= inject_json_ams "enterprises", @group.enterprises, Api::EnterpriseSerializer
.map-container
%map{"ng-controller" => "MapCtrl", "ng-if" => "(active(\'\') && (mapShowed = true)) || mapShowed"}
%map{"ng-if" => "(active(\'\') && (mapShowed = true)) || mapShowed"}
%google-map{options: "map.additional_options", center: "map.center", zoom: "map.zoom", styles: "map.styles", draggable: "true"}
%markers{models: "OfnMap.enterprises", fit: "true",
%markers{models: "mapMarkers", fit: "true",
coords: "'self'", icon: "'icon'", click: "'reveal'"}
%tab{heading: 'About us',
active: "active(\'about\')",
select: "select(\'about\')"}
%h1 About Us
%p= @group.long_description
%p!= @group.long_description
%tab{heading: 'Our producers',
active: "active(\'producers\')",
@@ -50,7 +57,7 @@
.small-12.columns
.active_table
%producer.active_table_node.row.animate-repeat{id: "{{producer.path}}",
"ng-repeat" => "producer in filteredEnterprises = (Enterprises.producers | visible | searchEnterprises:query | taxons:activeTaxons)",
"ng-repeat" => "producer in filteredEnterprises = (group_producers | visible | searchEnterprises:query | taxons:activeTaxons)",
"ng-controller" => "GroupEnterpriseNodeCtrl",
"ng-class" => "{'closed' : !open(), 'open' : open(), 'inactive' : !producer.active}",
id: "{{producer.hash}}"}
@@ -72,12 +79,15 @@
= render partial: "shared/components/enterprise_search"
-# TODO: find out why this is not working
-#= render partial: "home/filters"
.small-12.medium-6.columns
%span &nbsp;
= render partial: 'shared/components/show_profiles'
.row{bindonce: true}
.small-12.columns
.active_table
%hub.active_table_node.row.animate-repeat{id: "{{hub.hash}}",
"ng-repeat" => "hub in filteredEnterprises = (Enterprises.hubs | visible | searchEnterprises:query | taxons:activeTaxons | shipping:shippingTypes | showHubProfiles:show_profiles | orderBy:['-active', '+orders_close_at'])",
"ng-repeat" => "hub in filteredEnterprises = (group_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()}",
"ng-controller" => "GroupEnterpriseNodeCtrl"}
.small-12.columns