From 51c8a43e9f87be8113bd2e5b2c13bcbd34ac5ea0 Mon Sep 17 00:00:00 2001 From: himetani_cafe Date: Sat, 1 Aug 2015 03:37:35 +0900 Subject: [PATCH] add user role navigation to navbar directive --- client/app/app.js | 3 +- client/app/components/login/login.html | 4 +-- client/app/components/signup/signup.controller.js | 6 ++-- client/app/components/signup/signup.html | 4 +-- client/app/shared/navbar/navbar.controller.js | 35 +++++++++++++++++------ client/app/shared/navbar/navbar.html | 35 ++++++++++++++++------- client/app/shared/user/user.service.js | 26 +++++++++++++---- server/jb.js | 2 +- 8 files changed, 82 insertions(+), 33 deletions(-) diff --git a/client/app/app.js b/client/app/app.js index ed48dc2..7e19131 100644 --- a/client/app/app.js +++ b/client/app/app.js @@ -26,11 +26,12 @@ angular.module('zephyrApp', ['ui.bootstrap', 'ui.router', 'restangular','ngRoute // send signal to SignupController $rootScope.$broadcast('conflict') } - return false }) // Debug user.setEmail('fumifumi@yasunaga-lab.bio.kyutech.ac.jp') user.setID('504d41f91d2f81f02561b93a0e9ccde4') + user.setRoles(['admin', 'expert', 'amature']) + user.setCurrentRole(user.getRoles()[0]) }) diff --git a/client/app/components/login/login.html b/client/app/components/login/login.html index ba2895f..8822317 100644 --- a/client/app/components/login/login.html +++ b/client/app/components/login/login.html @@ -7,11 +7,11 @@ - +
diff --git a/client/app/components/signup/signup.controller.js b/client/app/components/signup/signup.controller.js index 117714f..8f2be35 100644 --- a/client/app/components/signup/signup.controller.js +++ b/client/app/components/signup/signup.controller.js @@ -17,13 +17,13 @@ angular.module('zephyrApp') email: $scope.email, roles: [] } - if($scope.superuser) + if($scope.admin) params.password = $scope.password else params.password = "secret" - if($scope.role.superuser) - params.roles.push('superuser') + if($scope.role.admin) + params.roles.push('admin') if($scope.role.expert) params.roles.push('expert') if($scope.role.amature) diff --git a/client/app/components/signup/signup.html b/client/app/components/signup/signup.html index cbe1632..0b5d7dd 100644 --- a/client/app/components/signup/signup.html +++ b/client/app/components/signup/signup.html @@ -7,13 +7,13 @@ - +

role

diff --git a/client/app/shared/navbar/navbar.controller.js b/client/app/shared/navbar/navbar.controller.js index 046825a..ac25a84 100644 --- a/client/app/shared/navbar/navbar.controller.js +++ b/client/app/shared/navbar/navbar.controller.js @@ -1,16 +1,35 @@ 'use strict'; angular.module('zephyrApp') -.controller('NavbarController', function($scope, $state) { - function activate(name) { - $scope.isBoard = name === 'board' - $scope.isWorkspace = name === 'workspace' - $scope.isNotes = name === 'notes' - } - activate($state.current.name) +.controller('NavbarController', function($scope, $state, user) { + $scope.email = user.getEmail() + + var route = $state.current.name + $scope.isBoard = route === 'board' + $scope.isWorkspace = route=== 'workspace' + $scope.isNotes = route === 'notes' + $scope.isAdmin = route === 'admin' + $scope.boardRef = "/board/"+$state.params.userID $scope.workspaceRef = "/workspace/"+$state.params.userID $scope.notesRef = "/notes/"+$state.params.userID -}) + $scope.roles = user.getRoles() + $scope.currentRole = user.getCurrentRole() + $scope.selectRole = function(role) { + $scope.currentRole = role + user.setCurrentRole(role) + } + + $scope.$watch('currentRole', function(role) { + if(role === 'admin') { + $scope.adminPath = '/admin/'+user.getID() + $scope.isAdminRole = true + } else { + $scope.adminPath = '#' + $scope.isAdminRole = false + } + }) + +}) diff --git a/client/app/shared/navbar/navbar.html b/client/app/shared/navbar/navbar.html index e6a6ced..aa3e422 100644 --- a/client/app/shared/navbar/navbar.html +++ b/client/app/shared/navbar/navbar.html @@ -1,12 +1,27 @@ diff --git a/client/app/shared/user/user.service.js b/client/app/shared/user/user.service.js index 0d462d6..7631a2c 100644 --- a/client/app/shared/user/user.service.js +++ b/client/app/shared/user/user.service.js @@ -3,20 +3,34 @@ angular.module('zephyrApp') .service('user', function() { var userID, - email + email, + roles, + currentRole return { + getID: function() { + return userID + }, setID: function(id) { userID = id }, - getID: function() { - return userID + getEmail: function() { + return email }, setEmail: function(addr) { email = addr }, - getEmail: function() { - return email - } + getRoles: function() { + return roles + }, + setRoles: function(r) { + roles = r + }, + getCurrentRole: function() { + return currentRole + }, + setCurrentRole: function(r) { + currentRole = r + } } }) diff --git a/server/jb.js b/server/jb.js index a51fb3c..77e0e18 100644 --- a/server/jb.js +++ b/server/jb.js @@ -11,7 +11,7 @@ if(process.env.DB_ZEPHYR === 'drop') { var user1 = { email: 'fumifumi@yasunaga-lab.bio.kyutech.ac.jp', password: 'secret', - role: ['expert'], + role: ['expert','amature'], // admin | expert | amature notes: ['namae.json', 'sample_1.json'] } -- 2.11.0