Skip to content

Commit

Permalink
fixed sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
jonniespratley committed Jan 26, 2014
1 parent 7d43c89 commit 721b7cb
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 56 deletions.
1 change: 1 addition & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<script src="scripts/services/cmsSessionService.js"></script>
<script src="scripts/directives/cmsWidgets.js"></script>
<script src="scripts/directives/cmsWidget.js"></script>
<script src="scripts/controllers/sidebar.js"></script>
<!-- endbuild -->
</body>
</html>
2 changes: 1 addition & 1 deletion app/scripts/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions app/scripts/config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ window.Config =
title: "Docs"
icon: "book"
href: "/docs"
,
id: 1
title: "Login"
icon: "lock"
href: "/login"
]
user: [
id: 1
Expand Down
58 changes: 24 additions & 34 deletions app/scripts/controllers/login.coffee
Original file line number Diff line number Diff line change
@@ -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')
)
Expand All @@ -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'
23 changes: 23 additions & 0 deletions app/scripts/controllers/sidebar.coffee
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion app/views/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</li>
<li class="divider"></li>
<li>
<a ng-click="logout()">Logout</a>
<a href="#" ng-click="logout(App.session.user)">Logout</a>
</li>
</ul>
</li>
Expand Down
30 changes: 14 additions & 16 deletions app/views/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ <h1><i class="fa fa-1x fa-cogs"></i> Settings</h1>
</div>

<div class="row">
<div class="col-sm-9 col-xs-7">
<form class="form-horizontal">
<cms-form-group label="App[key]" ng-repeat="(key, value) in App">
<input type="text" ng-model="App[key]"/>
</cms-form-group>


<div class="form-group tr">
<button class="btn btn-default">Cancel</button>
<button class="btn btn-primary" type="submit">Save</button>
</div>
</form>
</div>
<div class="col-sm-3 col-xs-5">
<aside class="well">Some help here</aside>
</div>
<div class="col-sm-9 col-xs-7">
<form class="form-horizontal" ng-submit="update(App)">
<cms-form-group label="{{key}}" ng-repeat="(key, value) in App">
<input type="text" ng-model="App[key]" value="{{ angular.isObject(App[key]) }}"/>
</cms-form-group>
<div class="form-group tr">
<button class="btn btn-default">Cancel</button>
<button class="btn btn-primary" type="submit">Save</button>
</div>
</form>
</div>
<div class="col-sm-3 col-xs-5">
<aside class="well">Some help here</aside>
</div>
</div>

<pre>App: {{App | json}}</pre>
23 changes: 19 additions & 4 deletions app/views/sidebar.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
<div class="well well-sm sidebar-nav">
<div class="well well-sm sidebar-nav" ng-controller="SidebarCtrl">
<nav class="nav nav-list">
<li class="nav-header">Menu</li>
<li ng-repeat="item in App.menu.user" ng-include src="'menu-item.html'"></li>
<li
ng-class="{active:item.selected}"
ng-repeat="item in App.menu.user"
ng-include src="'sidebar-item.html'"></li>
<li class="nav-header">Admin</li>
<li ng-repeat="item in App.menu.admin" ng-include src="'menu-item.html'"></li>
<li
ng-class="{active:item.selected}"
ng-repeat="item in App.menu.admin"
ng-include src="'sidebar-item.html'"></li>
</nav>
</div>
</div>

<script id="sidebar-item.html" type="text/ng-template">
<a
ng-click="select(item)"
ng-href="#{{item.href}}">
<i class="fa fa-1x fa-{{item.icon}}"></i>
{{item.title}}
</a>
</script>
19 changes: 19 additions & 0 deletions test/spec/controllers/sidebar.coffee
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 721b7cb

Please sign in to comment.