OSDN Git Service

add user role navigation to navbar directive
authorhimetani_cafe <fumifumi@yasunaga-lab.bio.kyutech.ac.jp>
Fri, 31 Jul 2015 18:37:35 +0000 (03:37 +0900)
committerhimetani_cafe <fumifumi@yasunaga-lab.bio.kyutech.ac.jp>
Fri, 31 Jul 2015 18:37:35 +0000 (03:37 +0900)
client/app/app.js
client/app/components/login/login.html
client/app/components/signup/signup.controller.js
client/app/components/signup/signup.html
client/app/shared/navbar/navbar.controller.js
client/app/shared/navbar/navbar.html
client/app/shared/user/user.service.js
server/jb.js

index ed48dc2..7e19131 100644 (file)
@@ -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])
 })
index ba2895f..8822317 100644 (file)
@@ -7,11 +7,11 @@
     <label class="sr-only">Username</label>
     <input type="text" class="form-control" ng-model="email" placeholder="email" required autofocus>
     <label class="sr-only">Password</label>
-    <input type="password" name="password" class="form-control" ng-show="superuser" ng-disabled="!superuser" ng-model="password" placeholder="Password" required>
+    <input type="password" name="password" class="form-control" ng-show="admin" ng-disabled="!admin" ng-model="password" placeholder="Password" required>
     <div class="checkbox">
         <label>
             <input type="checkbox"
-                   ng-model="superuser">login as superuser
+                   ng-model="admin">login as admin 
         </label>
     </div>
     <button class="btn btn-lg btn-primary btn-block" type="submit">Signin</button>
index 117714f..8f2be35 100644 (file)
@@ -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) 
index cbe1632..0b5d7dd 100644 (file)
@@ -7,13 +7,13 @@
     <label class="sr-only">email</label>
     <input type="email"class="form-control" ng-model="email" placeholder="email" required autofocus>
     <label class="sr-only">password</label>
-    <input type="password" class="form-control" ng-model="password" placeholder="password" ng-show="role.superuser" ng-disabled="!role.superuser" required autofocus>
+    <input type="password" class="form-control" ng-model="password" placeholder="password" ng-show="role.admin" ng-disabled="!role.admin" required autofocus>
     <div class="text-center">
         <h4>role</h4>
         <div class="checkbox">
             <label>
                 <input type="checkbox" 
-                       ng-model="role.superuser">Superuser
+                       ng-model="role.admin">admin
             </label>
         </div>
         <div class="checkbox">
index 046825a..ac25a84 100644 (file)
@@ -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
+        }
+    })
+
+})
index e6a6ced..aa3e422 100644 (file)
@@ -1,12 +1,27 @@
 <nav class="nav navbar-default">
-    <div class="navbar-header">
-        <a class="navbar-brand" href="">Zephyr</a>
-    </div>
-    <div class="navbar-collapse collapse navbar-responsive-collapse">
-        <ul class="nav navbar-nav">
-            <li ng-class="{active: isBoard}"><a ng-href="{{boardRef}}">Board</a></li>
-            <li ng-class="{active: isWorkspace}"><a ng-href="{{workspaceRef}}">Workspace</a></li>
-            <li ng-class="{active: isNotes}"><a ng-href="{{notesRef}}">Notes</a></li>
-        </ul>
-    </div>
+<div class="navbar-header">
+    <a class="navbar-brand" href="">Zephyr</a>
+</div>
+<div class="navbar-collapse collapse navbar-responsive-collapse">
+    <ul class="nav navbar-nav">
+        <li ng-class="{active: isBoard}"><a ng-href="{{boardRef}}">Board</a></li>
+        <li ng-class="{active: isWorkspace}"><a ng-href="{{workspaceRef}}">Workspace</a></li>
+        <li ng-class="{active: isNotes}"><a ng-href="{{notesRef}}">Notes</a></li>
+        <li ng-class="{active: isAdmin}" ng-show="isAdminRole"><a ng-href="{{adminPath}}">Admin Page</a></li>
+    </ul>
+
+    <ul class="nav navbar-nav navbar-right">
+        <li dropdown>
+            <a href="#" class="btn-group" dropdown-toggle>
+                {{currentRole}}<span class="caret"></span>
+            </a>
+            <ul class="dropdown-menu" role="menu" aria-labelledby="simple-btn-keyboard-nav">
+                <li role="menuitem" ng-repeat="role in roles">
+                    <a href="#" ng-click="selectRole(role)">{{role}}</a>
+                </li>
+            </ul>
+        </li>
+        <li><a href="#">{{email}}</a></li>
+    </ul>
+</div>
 </nav>
index 0d462d6..7631a2c 100644 (file)
@@ -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
+       }
     }
 })
 
index a51fb3c..77e0e18 100644 (file)
@@ -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']
     }