From b0ecadcb28932a6f467b1399b49aec5e3f6dc9d0 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 25 Apr 2014 13:49:44 +1000 Subject: [PATCH] Moving our sidebar to a service for maximum awesomesauce --- .../authentication_actions_controller.js.coffee | 14 ++------------ .../controllers/sidebar_controller.js.coffee | 7 ++----- .../darkswarm/services/sidebar.js.coffee | 13 +++++++++++++ app/views/home/_fat.html.haml | 1 + app/views/shared/_menu.html.haml | 3 ++- app/views/shared/_sidebar.html.haml | 2 +- 6 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 app/assets/javascripts/darkswarm/services/sidebar.js.coffee diff --git a/app/assets/javascripts/darkswarm/controllers/authentication_actions_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/authentication_actions_controller.js.coffee index 77c8b45d9d..ce5817bcf3 100644 --- a/app/assets/javascripts/darkswarm/controllers/authentication_actions_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/authentication_actions_controller.js.coffee @@ -1,12 +1,2 @@ -Darkswarm.controller "AuthenticationActionsCtrl", ($scope, Navigation, storage) -> - $scope.toggleLogin = -> - Navigation.navigate "/login" - - $scope.toggleSignup = -> - Navigation.navigate "/signup" - - $scope.toggleSignup = -> - Navigation.navigate "/signup" - - $scope.toggle = (path = null)-> - Navigation.navigate(path) +Darkswarm.controller "AuthenticationActionsCtrl", ($scope, Navigation, storage, Sidebar) -> + $scope.Sidebar = Sidebar diff --git a/app/assets/javascripts/darkswarm/controllers/sidebar_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/sidebar_controller.js.coffee index cd7ce8fe0b..da18067f36 100644 --- a/app/assets/javascripts/darkswarm/controllers/sidebar_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/sidebar_controller.js.coffee @@ -1,5 +1,2 @@ -Darkswarm.controller "SidebarCtrl", ($scope, $location) -> - $scope.sidebarPaths = ["/login", "/signup", "/forgot", "/account"] - - $scope.active = -> - $location.path() in $scope.sidebarPaths +Darkswarm.controller "SidebarCtrl", ($scope, $location, Sidebar) -> + $scope.Sidebar = Sidebar diff --git a/app/assets/javascripts/darkswarm/services/sidebar.js.coffee b/app/assets/javascripts/darkswarm/services/sidebar.js.coffee new file mode 100644 index 0000000000..c05f6659f2 --- /dev/null +++ b/app/assets/javascripts/darkswarm/services/sidebar.js.coffee @@ -0,0 +1,13 @@ +Darkswarm.factory "Sidebar", ($location, Navigation)-> + new class Sidebar + paths: ["/login", "/signup", "/forgot", "/account"] + + active: -> + $location.path() in @paths + + toggle: -> + if Navigation.path in @paths + Navigation.navigate(Navigation.path) + else + Navigation.navigate(@paths[0]) + diff --git a/app/views/home/_fat.html.haml b/app/views/home/_fat.html.haml index bb9015ca82..f29e6cdec5 100644 --- a/app/views/home/_fat.html.haml +++ b/app/views/home/_fat.html.haml @@ -17,6 +17,7 @@ .columns.small-11 %a{"bo-href" => "hub.path", "ng-show" => "!emptiesCart()"} Shop at + %strong {{ hub.name }} %a{"ng-click" => "changeHub()", "ng-show" => "emptiesCart()"} Change hub to diff --git a/app/views/shared/_menu.html.haml b/app/views/shared/_menu.html.haml index 66102a80ac..d4c0030f2c 100644 --- a/app/views/shared/_menu.html.haml +++ b/app/views/shared/_menu.html.haml @@ -2,8 +2,9 @@ %section.top-bar-section %ul.left{"ng-controller" => "AuthenticationActionsCtrl"} %li - %a.icon{"ng-click" => "toggle()"} + %a.icon{"ng-click" => "Sidebar.toggle()"} %i.fi-list + %li= link_to image_tag("ofn_logo_small.png"), root_path %li.divider - if spree_current_user.nil? diff --git a/app/views/shared/_sidebar.html.haml b/app/views/shared/_sidebar.html.haml index 04891a5c82..158083d584 100644 --- a/app/views/shared/_sidebar.html.haml +++ b/app/views/shared/_sidebar.html.haml @@ -1,5 +1,5 @@ %section#sidebar{ role: "complementary", "ng-controller" => "SidebarCtrl", -"ng-class" => "{'active' : active()}"} +"ng-class" => "{'active' : Sidebar.active()}"} - if spree_current_user.nil? %tabset