updates for changing user's role feature.

This commit is contained in:
kunw 2016-04-21 13:12:18 +08:00
parent ca2b71bd6d
commit fd9f7d0e64
8 changed files with 131 additions and 25 deletions

View File

@ -0,0 +1,6 @@
<ng-switch on="vm.editMode">
<span ng-switch-default>//vm.currentRole.name//</span>
<select ng-switch-when="true" >
<option value="//role.id//" ng-click="vm.selectRole(role)" ng-repeat="role in vm.roles">//role.name//</option>
</select>
</ng-switch>

View File

@ -0,0 +1,51 @@
(function() {
'use strict';
angular
.module('harbor.details')
.directive('switchRoles', switchRoles);
SwitchRolesController.$inject = [];
function SwitchRolesController() {
var vm = this;
vm.currentRole = getRoleById(vm.roleId);
vm.selectRole = selectRole;
function selectRole(role) {
vm.roleId = role.id;
vm.currentRole = getRoleById(vm.roleId);
}
function getRoleById(roleId) {
for(var i = 0; i < vm.roles.length; i++) {
var role = vm.roles[i];
if(role.id == roleId) {
return role;
}
}
}
}
function switchRoles() {
var directive = {
'restrict': 'E',
'templateUrl': '/static/ng/resources/js/components/details/switch-roles.directive.html',
'scope': {
'roles': '=',
'editMode': '=',
'userId': '=',
'roleId': '=',
},
'controller' : SwitchRolesController,
'controllerAs': 'vm',
'bindToController': true
};
return directive;
}
})();

View File

@ -1,15 +0,0 @@
(function() {
'use strict';
angular
.module('harbor.projectmember')
.controller('EditProjectMemberController', EditProjectMemberController);
EditProjectMemberController.$inject = ['EditProjectMemberService'];
function EditProjectMemberController(EditProjectMemberService) {
}
})();

View File

@ -0,0 +1,11 @@
<td>user1</td>
<td><switch-roles roles="vm.roles" edit-mode="vm.editMode" user-id="vm.userId" role-id="vm.roleId"></switch-roles></td>
<td>
<a href="javascript:;" ng-click="vm.update({roleId: vm.roleId})">
<ng-switch on="vm.editMode">
<span ng-switch-default class="glyphicon glyphicon-pencil"></span>&nbsp;&nbsp;
<span ng-switch-when="true" class="glyphicon glyphicon-ok"></span>
</ng-switch>
</a>
<a href="#"><span class="glyphicon glyphicon-trash"></span></a>
</td>

View File

@ -0,0 +1,52 @@
(function() {
'use strict';
angular
.module('harbor.projectmember')
.constant('roles', roles)
.directive('editProjectMember', editProjectMember);
function roles() {
return [
{'id': '1', 'name': 'Project Admin'},
{'id': '2', 'name': 'Developer'},
{'id': '3', 'name': 'Guest'}
];
}
EditProjectMemberController.$inject = ['roles', 'EditProjectMemberService'];
function EditProjectMemberController(roles, EditProjectMemberService) {
var vm = this;
vm.roles = roles();
vm.editMode = false;
vm.update = update;
function update(e) {
if(vm.editMode) {
vm.editMode = false;
}else {
vm.editMode = true;
}
vm.roleId = e.roleId;
}
}
function editProjectMember() {
var directive = {
'restrict': 'A',
'templateUrl': '/static/ng/resources/js/components/projectmember/edit-projectmember.directive.html',
'scope': {
'userId': '=',
'roleId': '='
},
'controller': EditProjectMemberController,
'controllerAs': 'vm',
'bindToController': true
};
return directive;
}
})();

View File

@ -44,16 +44,8 @@
<th>Username</th><th>Role</th><th>Operation</th> <th>Username</th><th>Role</th><th>Operation</th>
</thead> </thead>
<tbody> <tbody>
<tr> <tr edit-project-member user-id="1" role-id="2"></tr>
<td>user1</td><td>3</td><td>Project Admin</td><td><a href="#"><span class="glyphicon glyphicon-pencil"></span></a><a href="#"><span class="glyphicon glyphicon-trash"></span></a></td> </tbody>
</tr>
<tr>
<td>tester1</td><td>3</td><td>Project Admin</td><td><a href="#"><span class="glyphicon glyphicon-pencil"></span></a><a href="#"><span class="glyphicon glyphicon-trash"></span></a></td>
</tr>
<tr>
<td>user1</td><td>3</td><td>Project Admin</td><td><a href="#"><span class="glyphicon glyphicon-pencil"></span></a><a href="#"><span class="glyphicon glyphicon-trash"></span></a></td>
</tr>
</tbody>
</table> </table>
</div> </div>
</div> </div>

View File

@ -9,10 +9,12 @@
'harbor.layout.log', 'harbor.layout.log',
'harbor.services.user', 'harbor.services.user',
'harbor.services.repository', 'harbor.services.repository',
'harbor.services.projectmember',
'harbor.session', 'harbor.session',
'harbor.header', 'harbor.header',
'harbor.details', 'harbor.details',
'harbor.repository', 'harbor.repository',
'harbor.projectmember',
'harbor.user', 'harbor.user',
'harbor.log' 'harbor.log'
]); ]);

View File

@ -55,6 +55,9 @@
<script src="/static/ng/resources/js/services/repository/services.repository.module.js"></script> <script src="/static/ng/resources/js/services/repository/services.repository.module.js"></script>
<script src="/static/ng/resources/js/services/repository/services.list-repository.js"></script> <script src="/static/ng/resources/js/services/repository/services.list-repository.js"></script>
<script src="/static/ng/resources/js/services/projectmember/services.projectmember.module.js"></script>
<script src="/static/ng/resources/js/services/projectmember/services.edit-projectmember.js"></script>
<script src="/static/ng/resources/js/services/log/services.log.module.js"></script> <script src="/static/ng/resources/js/services/log/services.log.module.js"></script>
<script src="/static/ng/resources/js/services/log/services.list-log.js"></script> <script src="/static/ng/resources/js/services/log/services.list-log.js"></script>
@ -66,6 +69,7 @@
<script src="/static/ng/resources/js/components/details/switch-pane-projects.directive.js"></script> <script src="/static/ng/resources/js/components/details/switch-pane-projects.directive.js"></script>
<script src="/static/ng/resources/js/components/details/retrieve-projects.directive.js"></script> <script src="/static/ng/resources/js/components/details/retrieve-projects.directive.js"></script>
<script src="/static/ng/resources/js/components/details/switch-roles.directive.js"></script>
<script src="/static/ng/resources/js/components/repository/repository.module.js"></script> <script src="/static/ng/resources/js/components/repository/repository.module.js"></script>
<script src="/static/ng/resources/js/components/repository/list-repository.directive.js"></script> <script src="/static/ng/resources/js/components/repository/list-repository.directive.js"></script>
@ -73,6 +77,9 @@
<script src="/static/ng/resources/js/components/user/user.module.js"></script> <script src="/static/ng/resources/js/components/user/user.module.js"></script>
<script src="/static/ng/resources/js/components/user/list-user.directive.js"></script> <script src="/static/ng/resources/js/components/user/list-user.directive.js"></script>
<script src="/static/ng/resources/js/components/projectmember/projectmember.module.js"></script>
<script src="/static/ng/resources/js/components/projectmember/edit-projectmember.directive.js"></script>
<script src="/static/ng/resources/js/components/log/log.module.js"></script> <script src="/static/ng/resources/js/components/log/log.module.js"></script>
<script src="/static/ng/resources/js/components/log/list-log.directive.js"></script> <script src="/static/ng/resources/js/components/log/list-log.directive.js"></script>