Adding handling of 'current hub'

This commit is contained in:
Will Marshall
2014-04-25 11:32:02 +10:00
parent f57020d190
commit 2212156f00
11 changed files with 25 additions and 10 deletions

View File

@@ -0,0 +1,2 @@
Darkswarm.controller "CurrentHubCtrl", ($scope, CurrentHub) ->
$scope.CurrentHub = CurrentHub

View File

@@ -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()

View File

@@ -1,4 +1,3 @@
Darkswarm.controller "HubsCtrl", ($scope, Hubs) ->
console.log Hubs.hubs[0]
$scope.Hubs = Hubs
$scope.hubs = Hubs.hubs

View File

@@ -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

View File

@@ -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'])

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,2 @@
object current_distributor
attributes :name, :id

View File

@@ -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

View File

@@ -0,0 +1,2 @@
:javascript
angular.module('Darkswarm').value('currentHub', #{render "json/current_hub"})

View File

@@ -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