diff --git a/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee index d48e488c16..c3984f9d54 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.controller "CheckoutCtrl", ($scope, Order, storage, CheckoutFormState) -> +Darkswarm.controller "CheckoutCtrl", ($scope, Order, storage, CheckoutFormState, User) -> # We put Order.order into the scope for convenience # However, storage.bind replaces Order.order @@ -9,12 +9,22 @@ Darkswarm.controller "CheckoutCtrl", ($scope, Order, storage, CheckoutFormState) $scope.CheckoutFormState = CheckoutFormState #$scope.order = Order.order - $scope.accordion = {user: true} + if User + $scope.accordion = {details: true} + else + $scope.accordion = {user: true} + $scope.show = (name)-> $scope.accordion[name] = true storage.bind $scope, "accordion", {storeName: "accordion_#{$scope.order.id}"} + + # If we are logged in, but the cached accordion panel is user, move to details + if User and $scope.accordion.user + $scope.accordion.user = false + $scope.accordion.details = true + storage.bind $scope, "CheckoutFormState.ship_address_same_as_billing", { defaultValue: true} $scope.purchase = (event)-> diff --git a/app/assets/javascripts/darkswarm/services/hub.js.coffee b/app/assets/javascripts/darkswarm/services/hub.js.coffee index 9fd20c6285..68fcd6e3f6 100644 --- a/app/assets/javascripts/darkswarm/services/hub.js.coffee +++ b/app/assets/javascripts/darkswarm/services/hub.js.coffee @@ -1,7 +1,5 @@ Darkswarm.factory 'CurrentHub', ($location, $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/spree_user.js.coffee b/app/assets/javascripts/darkswarm/services/spree_user.js.coffee index f57a6e183b..f16ede8a46 100644 --- a/app/assets/javascripts/darkswarm/services/spree_user.js.coffee +++ b/app/assets/javascripts/darkswarm/services/spree_user.js.coffee @@ -1,6 +1,7 @@ -Darkswarm.factory 'SpreeUser', ($resource) -> +Darkswarm.factory 'SpreeUser', () -> + # This is for storing Login/Signup/Forgot data to send to server + # This does NOT represent our current user new class SpreeUser - spree_user: { + spree_user: remember_me: 0 email: null - } diff --git a/app/assets/javascripts/darkswarm/services/user.js.coffee b/app/assets/javascripts/darkswarm/services/user.js.coffee new file mode 100644 index 0000000000..2a71d6c7b8 --- /dev/null +++ b/app/assets/javascripts/darkswarm/services/user.js.coffee @@ -0,0 +1,8 @@ +Darkswarm.factory 'User', (user)-> + # This is for the current user + if user and !$.isEmptyObject(user) + new class User + constructor: -> + @[k] = v for k, v of user + else + undefined diff --git a/app/views/json/_current_user.rabl b/app/views/json/_current_user.rabl new file mode 100644 index 0000000000..b07ae07b66 --- /dev/null +++ b/app/views/json/_current_user.rabl @@ -0,0 +1,2 @@ +object spree_current_user +attributes :email, :id diff --git a/app/views/layouts/darkswarm.html.haml b/app/views/layouts/darkswarm.html.haml index 2fc6d9165d..e44c0600af 100644 --- a/app/views/layouts/darkswarm.html.haml +++ b/app/views/layouts/darkswarm.html.haml @@ -15,6 +15,7 @@ %body.off-canvas{"ng-app" => "Darkswarm"} = render partial: "shared/current_hub" + = render partial: "shared/current_user" = render partial: "shared/menu" = display_flash_messages %ofn-flash diff --git a/app/views/shared/_current_user.haml b/app/views/shared/_current_user.haml new file mode 100644 index 0000000000..9745a71313 --- /dev/null +++ b/app/views/shared/_current_user.haml @@ -0,0 +1,2 @@ +:javascript + angular.module('Darkswarm').value('user', #{render "json/current_user"}) diff --git a/app/views/shared/_menu.html.haml b/app/views/shared/_menu.html.haml index d4c0030f2c..dcd3897195 100644 --- a/app/views/shared/_menu.html.haml +++ b/app/views/shared/_menu.html.haml @@ -15,7 +15,7 @@ %section.top-bar-section %ul.right %li.current_hub{"ng-controller" => "CurrentHubCtrl", "ng-show" => "CurrentHub.id"} - %a{href: shop_path} + %a{href: main_app.shop_path} {{ CurrentHub.name }} %li.cart %a.icon{href: cart_url} diff --git a/spec/javascripts/unit/darkswarm/controllers/checkout_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/checkout_controller_spec.js.coffee index f5d5ac6a58..11cb4b7f3c 100644 --- a/spec/javascripts/unit/darkswarm/controllers/checkout_controller_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/controllers/checkout_controller_spec.js.coffee @@ -5,6 +5,7 @@ describe "CheckoutCtrl", -> beforeEach -> module("Darkswarm") + angular.module('Darkswarm').value('user', {}) Order = { submit: -> navigate: -> diff --git a/spec/javascripts/unit/darkswarm/controllers/sidebar_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/sidebar_controller_spec.js.coffee index 0d051a8cfa..c1b4095564 100644 --- a/spec/javascripts/unit/darkswarm/controllers/sidebar_controller_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/controllers/sidebar_controller_spec.js.coffee @@ -12,11 +12,3 @@ describe "SidebarCtrl", -> scope = $rootScope ctrl = $controller 'SidebarCtrl', {$scope: scope, $location: location} scope.$apply() - - it 'is active when a location is set', -> - expect(scope.active()).toEqual true - - it 'is inactive no location is set', -> - location.path = -> - null - expect(scope.active()).toEqual false diff --git a/spec/javascripts/unit/darkswarm/services/sidebar_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/sidebar_spec.js.coffee new file mode 100644 index 0000000000..8551113280 --- /dev/null +++ b/spec/javascripts/unit/darkswarm/services/sidebar_spec.js.coffee @@ -0,0 +1,37 @@ +describe "Sidebar", -> + location = null + Sidebar = null + Navigation = null + + beforeEach -> + module("Darkswarm") + inject (_Sidebar_, $location, _Navigation_) -> + Sidebar = _Sidebar_ + Navigation = _Navigation_ + location = $location + Sidebar.paths = ["/test", "/frogs"] + + + it 'is active when a location in paths is set', -> + spyOn(location, "path").andReturn "/test" + expect(Sidebar.active()).toEqual true + + it 'is inactive if location is set', -> + spyOn(location, "path").andReturn null + expect(Sidebar.active()).toEqual false + + describe "Toggling on/off", -> + it 'toggles the current sidebar path', -> + expect(Sidebar.active()).toEqual false + Navigation.path = "/frogs" + Sidebar.toggle() + expect(Sidebar.active()).toEqual true + + it 'If current navigation path is not in the sidebar, it toggles the first sidebar path', -> + Navigation.path = "/donkeys" + spyOn(Navigation, 'navigate') + Sidebar.toggle() + expect(Navigation.navigate).toHaveBeenCalledWith("/test") + + +