From 2212156f00ce7185b9fbebc0a35b6fb623cab8a1 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 25 Apr 2014 11:32:02 +1000 Subject: [PATCH] Adding handling of 'current hub' --- .../controllers/current_hub_controller.js.coffee | 2 ++ .../darkswarm/controllers/hub_node_controller.js.coffee | 5 ++++- .../darkswarm/controllers/hubs_controller.js.coffee | 1 - app/assets/javascripts/darkswarm/services/hub.js.coffee | 7 +++++++ app/assets/javascripts/darkswarm/services/hubs.js.coffee | 2 +- app/views/home/_fat.html.haml | 8 ++------ app/views/home/_hubs.html.haml | 2 +- app/views/json/_current_hub.rabl | 2 ++ app/views/layouts/darkswarm.html.haml | 1 + app/views/shared/_current_hub.haml | 2 ++ app/views/shared/_menu.html.haml | 3 +++ 11 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 app/assets/javascripts/darkswarm/controllers/current_hub_controller.js.coffee create mode 100644 app/assets/javascripts/darkswarm/services/hub.js.coffee create mode 100644 app/views/json/_current_hub.rabl create mode 100644 app/views/shared/_current_hub.haml diff --git a/app/assets/javascripts/darkswarm/controllers/current_hub_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/current_hub_controller.js.coffee new file mode 100644 index 0000000000..80a2af33fe --- /dev/null +++ b/app/assets/javascripts/darkswarm/controllers/current_hub_controller.js.coffee @@ -0,0 +1,2 @@ +Darkswarm.controller "CurrentHubCtrl", ($scope, CurrentHub) -> + $scope.CurrentHub = CurrentHub diff --git a/app/assets/javascripts/darkswarm/controllers/hub_node_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/hub_node_controller.js.coffee index 13c5dfc536..6be80295ef 100644 --- a/app/assets/javascripts/darkswarm/controllers/hub_node_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/hub_node_controller.js.coffee @@ -1,9 +1,12 @@ -Darkswarm.controller "HubNodeCtrl", ($scope, Navigation, $location, $anchorScroll, $templateCache) -> +Darkswarm.controller "HubNodeCtrl", ($scope, Navigation, $location, $anchorScroll, $templateCache, CurrentHub) -> $scope.toggle = -> Navigation.navigate $scope.hub.path $scope.open = -> $location.path() == $scope.hub.path + + $scope.current = -> + $scope.hub.id is CurrentHub.id if $scope.open() $anchorScroll() diff --git a/app/assets/javascripts/darkswarm/controllers/hubs_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/hubs_controller.js.coffee index 8d2ea7df50..0be4166dcb 100644 --- a/app/assets/javascripts/darkswarm/controllers/hubs_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/hubs_controller.js.coffee @@ -1,4 +1,3 @@ Darkswarm.controller "HubsCtrl", ($scope, Hubs) -> - console.log Hubs.hubs[0] $scope.Hubs = Hubs $scope.hubs = Hubs.hubs diff --git a/app/assets/javascripts/darkswarm/services/hub.js.coffee b/app/assets/javascripts/darkswarm/services/hub.js.coffee new file mode 100644 index 0000000000..9af5a1cddf --- /dev/null +++ b/app/assets/javascripts/darkswarm/services/hub.js.coffee @@ -0,0 +1,7 @@ +Darkswarm.factory 'CurrentHub', ($location, hubs, $filter, currentHub) -> + new class CurrentHub + hasHub: false + constructor: -> + @[k] = v for k, v of currentHub + @hasHub = true + diff --git a/app/assets/javascripts/darkswarm/services/hubs.js.coffee b/app/assets/javascripts/darkswarm/services/hubs.js.coffee index 9574654fe2..a3f2b03f23 100644 --- a/app/assets/javascripts/darkswarm/services/hubs.js.coffee +++ b/app/assets/javascripts/darkswarm/services/hubs.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.factory 'Hubs', ($location, hubs, $filter) -> +Darkswarm.factory 'Hubs', ($location, hubs, $filter, CurrentHub) -> new class Hubs constructor: -> @hubs = $filter('orderBy')(hubs, ['-active', '+orders_close_at']) diff --git a/app/views/home/_fat.html.haml b/app/views/home/_fat.html.haml index c139cedab7..046a98b5d4 100644 --- a/app/views/home/_fat.html.haml +++ b/app/views/home/_fat.html.haml @@ -1,4 +1,3 @@ - .row.active_table_row{"ng-show" => "open()"} .columns.small-4 %strong Shop for @@ -12,11 +11,8 @@ %li.delivery{"bo-if" => "hub.delivery"} Delivery .columns.small-4 %strong Our producers - %ol - %li Fake Name Forever - %li The Constant Gardener - %li Shiny Olives - %li Love in the Time of Cholera + %p + Go to our shop to see our current producers .row.active_table_row.link{"ng-show" => "open()", "ng-if" => "hub.active"} .columns.small-11 diff --git a/app/views/home/_hubs.html.haml b/app/views/home/_hubs.html.haml index 3d21e2a7ad..a3a1d75334 100644 --- a/app/views/home/_hubs.html.haml +++ b/app/views/home/_hubs.html.haml @@ -23,7 +23,7 @@ .small-12.columns .active_table %hub.row{"ng-repeat" => "hub in filteredHubs = (hubs | filterHubs:query)", - "ng-class" => "{'closed' : !open(), 'open' : open(), 'inactive' : !hub.active}", + "ng-class" => "{'closed' : !open(), 'open' : open(), 'inactive' : !hub.active, 'current' : current()}", "ng-controller" => "HubNodeCtrl", id: "{{hub.path}}"} .small-12.columns diff --git a/app/views/json/_current_hub.rabl b/app/views/json/_current_hub.rabl new file mode 100644 index 0000000000..ab67cce3cc --- /dev/null +++ b/app/views/json/_current_hub.rabl @@ -0,0 +1,2 @@ +object current_distributor +attributes :name, :id diff --git a/app/views/layouts/darkswarm.html.haml b/app/views/layouts/darkswarm.html.haml index 8b2f1ac41b..2fc6d9165d 100644 --- a/app/views/layouts/darkswarm.html.haml +++ b/app/views/layouts/darkswarm.html.haml @@ -14,6 +14,7 @@ = csrf_meta_tags %body.off-canvas{"ng-app" => "Darkswarm"} + = render partial: "shared/current_hub" = render partial: "shared/menu" = display_flash_messages %ofn-flash diff --git a/app/views/shared/_current_hub.haml b/app/views/shared/_current_hub.haml new file mode 100644 index 0000000000..5a0ff7c564 --- /dev/null +++ b/app/views/shared/_current_hub.haml @@ -0,0 +1,2 @@ +:javascript + angular.module('Darkswarm').value('currentHub', #{render "json/current_hub"}) diff --git a/app/views/shared/_menu.html.haml b/app/views/shared/_menu.html.haml index f5aee8cc17..66102a80ac 100644 --- a/app/views/shared/_menu.html.haml +++ b/app/views/shared/_menu.html.haml @@ -13,6 +13,9 @@ %section.top-bar-section %ul.right + %li.current_hub{"ng-controller" => "CurrentHubCtrl", "ng-show" => "CurrentHub.id"} + %a{href: shop_path} + {{ CurrentHub.name }} %li.cart %a.icon{href: cart_url} %i.fi-shopping-cart