From 721b7cb9f853df7ffc79d216bb59a7251bb96cf9 Mon Sep 17 00:00:00 2001 From: Jonnie Spratley Date: Sat, 25 Jan 2014 16:30:53 -0800 Subject: [PATCH] fixed sidebar --- app/index.html | 1 + app/scripts/app.coffee | 2 +- app/scripts/config.coffee | 5 +++ app/scripts/controllers/login.coffee | 58 +++++++++++--------------- app/scripts/controllers/sidebar.coffee | 23 ++++++++++ app/views/navbar.html | 2 +- app/views/settings.html | 30 +++++++------ app/views/sidebar.html | 23 ++++++++-- test/spec/controllers/sidebar.coffee | 19 +++++++++ 9 files changed, 107 insertions(+), 56 deletions(-) create mode 100644 app/scripts/controllers/sidebar.coffee create mode 100644 test/spec/controllers/sidebar.coffee diff --git a/app/index.html b/app/index.html index da8a14b..7c31bcf 100755 --- a/app/index.html +++ b/app/index.html @@ -105,6 +105,7 @@ + \ No newline at end of file diff --git a/app/scripts/app.coffee b/app/scripts/app.coffee index 361c7d4..e39be88 100644 --- a/app/scripts/app.coffee +++ b/app/scripts/app.coffee @@ -86,7 +86,7 @@ angular.module('angularCmsApp', [ angular.module('angularCmsApp').controller 'AppCtrl', ['$scope', '$rootScope', '$http', '$log', '$route', '$location', '$routeParams', '$cookieStore', ($scope, $rootScope, $http, $log, $route, $location, $routeParams, $cookieStore) -> App = Config App.route = $routeParams; - App.session.user = $cookieStore.get('App.session.user') + App.session = $cookieStore.get('App.session') App.route = $route App.location = $location diff --git a/app/scripts/config.coffee b/app/scripts/config.coffee index 6cd0bae..864760e 100644 --- a/app/scripts/config.coffee +++ b/app/scripts/config.coffee @@ -106,6 +106,11 @@ window.Config = title: "Docs" icon: "book" href: "/docs" + , + id: 1 + title: "Login" + icon: "lock" + href: "/login" ] user: [ id: 1 diff --git a/app/scripts/controllers/login.coffee b/app/scripts/controllers/login.coffee index 07b4870..260ac22 100644 --- a/app/scripts/controllers/login.coffee +++ b/app/scripts/controllers/login.coffee @@ -1,42 +1,33 @@ 'use strict' #Login Controller - Handles the login.html view for authenticating a user. angular.module('angularCmsApp').controller 'LoginCtrl', ($scope, $rootScope, $cookieStore) -> - #Setup initial model $scope.user = username: null password: null remember: false - $scope.user = Parse.User.current() if Parse.User.current() + #$scope.user = Parse.User.current() if Parse.User.current() ### Login Method to set the session. @param {Object} user - A user model containing username and password ### $scope.login = (u) -> - + console.log(u) Parse.User.logIn u.username, u.password, - success: (user) -> - console.log user - + console.log user $scope.$apply(()-> - - $rootScope.alert = - type: 'success' - code: 'Authorized' - message: 'Welcome back....' - - #Set user cookie - $cookieStore.put('App.session.user', user) if user.remember - #Set user session - $rootScope.App.session.user = user.attributes - - #Set session authorized - $rootScope.App.session.authorized = true + session = + user: user.attributes + authorized: true + console.log('save sessin', session) + #Set user cookie + $cookieStore.put('App.session', session) if u.remember + $rootScope.App.session = session #Change location $rootScope.App.location.path('/dashboard') ) @@ -45,20 +36,19 @@ angular.module('angularCmsApp').controller 'LoginCtrl', ($scope, $rootScope, $co $scope.error = error; ) - ### - Logout method to clear the session. - @param {Object} user - A user model containing remember - ### - $scope.logout = (user) -> - #Clear cookie - $cookieStore.put('App.session.user', null) unless user.remember - - #Clear session - $rootScope.App.session.user = null - $rootScope.App.session.authorized = false - - #Change location - $rootScope.App.location.path($rootScope.App.logout.redirect) - + + + ### + Logout method to clear the session. + @param {Object} user - A user model containing remember + ### + $scope.logout = (user) -> + #Clear cookie + $cookieStore.put('App.session', null) unless App.session.user.remember + #Clear session + $rootScope.App.session = null + #Change location + $rootScope.App.location.path($rootScope.App.logout.redirect) + #Controller name $scope.name = 'login' diff --git a/app/scripts/controllers/sidebar.coffee b/app/scripts/controllers/sidebar.coffee new file mode 100644 index 0000000..f279868 --- /dev/null +++ b/app/scripts/controllers/sidebar.coffee @@ -0,0 +1,23 @@ +'use strict' + +angular.module('angularCmsApp') + .controller 'SidebarCtrl', ($scope, $rootScope) -> + $scope.awesomeThings = [ + 'HTML5 Boilerplate' + 'AngularJS' + 'Karma' + ] + + $scope.items = $rootScope.App.menu.user + $scope.selected = null + + $scope.select = (item) -> + angular.forEach $rootScope.App.menu.admin, (item) -> + item.selected = false + console.log item + angular.forEach $rootScope.App.menu.user, (item) -> + item.selected = false + console.log item + + item.selected = true + diff --git a/app/views/navbar.html b/app/views/navbar.html index 0453b04..8c10d7a 100755 --- a/app/views/navbar.html +++ b/app/views/navbar.html @@ -34,7 +34,7 @@
  • - Logout + Logout
  • diff --git a/app/views/settings.html b/app/views/settings.html index 5887ab3..065d3eb 100755 --- a/app/views/settings.html +++ b/app/views/settings.html @@ -7,22 +7,20 @@

    Settings

    -
    -
    - - - - - -
    - - -
    -
    -
    -
    - -
    +
    +
    + + + +
    + + +
    +
    +
    +
    + +
    App: {{App | json}}
    \ No newline at end of file diff --git a/app/views/sidebar.html b/app/views/sidebar.html index d662e07..cbf5c20 100644 --- a/app/views/sidebar.html +++ b/app/views/sidebar.html @@ -1,8 +1,23 @@ - + + \ No newline at end of file diff --git a/test/spec/controllers/sidebar.coffee b/test/spec/controllers/sidebar.coffee new file mode 100644 index 0000000..14f5aa9 --- /dev/null +++ b/test/spec/controllers/sidebar.coffee @@ -0,0 +1,19 @@ +'use strict' + +describe 'Controller: SidebarCtrl', () -> + + # load the controller's module + beforeEach module 'angularCmsApp' + + SidebarCtrl = {} + scope = {} + + # Initialize the controller and a mock scope + beforeEach inject ($controller, $rootScope) -> + scope = $rootScope.$new() + SidebarCtrl = $controller 'SidebarCtrl', { + $scope: scope + } + + it 'should attach a list of awesomeThings to the scope', () -> + expect(scope.awesomeThings.length).toBe 3