mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Adding handling of 'current hub'
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
Darkswarm.controller "CurrentHubCtrl", ($scope, CurrentHub) ->
|
||||
$scope.CurrentHub = CurrentHub
|
||||
@@ -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()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
Darkswarm.controller "HubsCtrl", ($scope, Hubs) ->
|
||||
console.log Hubs.hubs[0]
|
||||
$scope.Hubs = Hubs
|
||||
$scope.hubs = Hubs.hubs
|
||||
|
||||
7
app/assets/javascripts/darkswarm/services/hub.js.coffee
Normal file
7
app/assets/javascripts/darkswarm/services/hub.js.coffee
Normal 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
|
||||
|
||||
@@ -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'])
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
2
app/views/json/_current_hub.rabl
Normal file
2
app/views/json/_current_hub.rabl
Normal file
@@ -0,0 +1,2 @@
|
||||
object current_distributor
|
||||
attributes :name, :id
|
||||
@@ -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
|
||||
|
||||
2
app/views/shared/_current_hub.haml
Normal file
2
app/views/shared/_current_hub.haml
Normal file
@@ -0,0 +1,2 @@
|
||||
:javascript
|
||||
angular.module('Darkswarm').value('currentHub', #{render "json/current_hub"})
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user