From e26ebf423946cd39241614852d8d60f3f8f040a3 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 9 Apr 2015 17:15:57 +1000 Subject: [PATCH 1/5] Serialize only activated hubs and producers of an enterprise --- app/serializers/api/enterprise_serializer.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index 95ef4cec60..532887ae01 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -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 = { From 1e168afd711073ffe0c04d05aad3f616fbc98b5e Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 10 Apr 2015 12:55:20 +1000 Subject: [PATCH 2/5] giving the enterprise serializer the active_distributors --- app/views/groups/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml index dfa780f688..0459b2fc52 100644 --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -22,7 +22,7 @@ %tab{heading: 'Map', active: "active(\'\')", select: "select(\'\')"} - = inject_json_ams "enterprises", @group.enterprises, Api::EnterpriseSerializer + = inject_json_ams "enterprises", @group.enterprises, Api::EnterpriseSerializer, active_distributors: @active_distributors .map-container %map{"ng-controller" => "MapCtrl", "ng-if" => "(active(\'\') && (mapShowed = true)) || mapShowed"} %google-map{options: "map.additional_options", center: "map.center", zoom: "map.zoom", styles: "map.styles", draggable: "true"} From 2fd25f6cc43735a18d6abf8613213f1281ab33bb Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 10 Apr 2015 17:42:54 +1000 Subject: [PATCH 3/5] Injecting all enterprises into group page The enterprises have related producers and hubs that need to be dereferenced. Therefore, we need a bigger set of enterprises to be loaded. Injecting all enterprises is simple and doesn't require changes if the set of needed enterprise data is growing in future. --- .../group_enterprises_controller.js.coffee | 3 +-- .../group_page_controller.js.coffee | 14 ++++++++++++++ .../darkswarm/services/map.js.coffee | 8 +++++--- app/views/groups/show.html.haml | 19 +++++++++++++------ 4 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 app/assets/javascripts/darkswarm/controllers/group_page_controller.js.coffee diff --git a/app/assets/javascripts/darkswarm/controllers/group_enterprises_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/group_enterprises_controller.js.coffee index ab8336116f..db1a9a1d8b 100644 --- a/app/assets/javascripts/darkswarm/controllers/group_enterprises_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/group_enterprises_controller.js.coffee @@ -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 diff --git a/app/assets/javascripts/darkswarm/controllers/group_page_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/group_page_controller.js.coffee new file mode 100644 index 0000000000..b30d409b97 --- /dev/null +++ b/app/assets/javascripts/darkswarm/controllers/group_page_controller.js.coffee @@ -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 + diff --git a/app/assets/javascripts/darkswarm/services/map.js.coffee b/app/assets/javascripts/darkswarm/services/map.js.coffee index 703c3c54bf..7ff9f553f2 100644 --- a/app/assets/javascripts/darkswarm/services/map.js.coffee +++ b/app/assets/javascripts/darkswarm/services/map.js.coffee @@ -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 diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml index 0459b2fc52..625d4f0d6d 100644 --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -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,11 +30,10 @@ %tab{heading: 'Map', active: "active(\'\')", select: "select(\'\')"} - = inject_json_ams "enterprises", @group.enterprises, Api::EnterpriseSerializer, active_distributors: @active_distributors .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', @@ -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}}"} @@ -77,7 +84,7 @@ .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 From 201bcb133af2278dc9e85117ba18cc661e8c0fb7 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 15 Apr 2015 16:15:21 +1000 Subject: [PATCH 4/5] show profiles checkbox on groups hubs page --- app/views/groups/show.html.haml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml index 625d4f0d6d..9bc40337a9 100644 --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -79,6 +79,9 @@ = render partial: "shared/components/enterprise_search" -# TODO: find out why this is not working -#= render partial: "home/filters" + .small-12.medium-6.columns + %span   + = render partial: 'shared/components/show_profiles' .row{bindonce: true} .small-12.columns From 548e3576b9623c4ffba52186d963ec0c11a8578e Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 15 Apr 2015 17:13:10 +1000 Subject: [PATCH 5/5] textAngular editor for group description --- .../admin/enterprise_groups/enterprise_groups.js.coffee | 2 +- app/views/admin/enterprise_groups/_form_about.html.haml | 6 +++--- app/views/groups/show.html.haml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/admin/enterprise_groups/enterprise_groups.js.coffee b/app/assets/javascripts/admin/enterprise_groups/enterprise_groups.js.coffee index e8e462d998..0ff8e4f515 100644 --- a/app/assets/javascripts/admin/enterprise_groups/enterprise_groups.js.coffee +++ b/app/assets/javascripts/admin/enterprise_groups/enterprise_groups.js.coffee @@ -1 +1 @@ -angular.module("admin.enterprise_groups", ["admin.side_menu", "admin.users"]) +angular.module("admin.enterprise_groups", ["admin.side_menu", "admin.users", "textAngular"]) diff --git a/app/views/admin/enterprise_groups/_form_about.html.haml b/app/views/admin/enterprise_groups/_form_about.html.haml index 60d7276094..a29fde22cd 100644 --- a/app/views/admin/enterprise_groups/_form_about.html.haml +++ b/app/views/admin/enterprise_groups/_form_about.html.haml @@ -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] diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml index 9bc40337a9..1bc965dfb3 100644 --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -40,7 +40,7 @@ active: "active(\'about\')", select: "select(\'about\')"} %h1 About Us - %p= @group.long_description + %p!= @group.long_description %tab{heading: 'Our producers', active: "active(\'producers\')",