You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2018/05/17 02:25:55 UTC
[incubator-trafficcontrol] 09/17: manage capabilities for a role
This is an automated email from the ASF dual-hosted git repository.
mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git
commit d2bb9372753a77678e314e99a470da7e33092c0d
Author: Jeremy Mitchell <mi...@gmail.com>
AuthorDate: Tue May 1 12:48:39 2018 -0600
manage capabilities for a role
---
traffic_portal/app/src/app.js | 2 +
.../common/modules/form/role/FormRoleController.js | 14 +--
.../form/role/edit/FormEditRoleController.js | 14 ++-
.../common/modules/form/role/form.role.tpl.html | 4 +-
.../TableAssignCapabilitiesController.js | 106 +++++++++++++++++++++
.../TableRoleCapabilitiesController.js | 106 +++++++++++++++++++++
.../roleCapabilities/index.js} | 28 +-----
.../table.assignCapabilities.tpl.html | 43 +++++++++
.../table.roleCapabilities.tpl.html | 53 +++++++++++
.../private/roles/capabilities/index.js} | 44 ++++-----
10 files changed, 350 insertions(+), 64 deletions(-)
diff --git a/traffic_portal/app/src/app.js b/traffic_portal/app/src/app.js
index ee6f617..f3c9e44 100644
--- a/traffic_portal/app/src/app.js
+++ b/traffic_portal/app/src/app.js
@@ -146,6 +146,7 @@ var trafficPortal = angular.module('trafficPortal', [
require('./modules/private/regions/physLocations').name,
require('./modules/private/regions/new').name,
require('./modules/private/roles').name,
+ require('./modules/private/roles/capabilities').name,
require('./modules/private/roles/edit').name,
require('./modules/private/roles/list').name,
require('./modules/private/roles/new').name,
@@ -315,6 +316,7 @@ var trafficPortal = angular.module('trafficPortal', [
require('./common/modules/table/regions').name,
require('./common/modules/table/regionPhysLocations').name,
require('./common/modules/table/roles').name,
+ require('./common/modules/table/roleCapabilities').name,
require('./common/modules/table/servers').name,
require('./common/modules/table/serverConfigFiles').name,
require('./common/modules/table/serverDeliveryServices').name,
diff --git a/traffic_portal/app/src/common/modules/form/role/FormRoleController.js b/traffic_portal/app/src/common/modules/form/role/FormRoleController.js
index 2223a76..757c5f9 100644
--- a/traffic_portal/app/src/common/modules/form/role/FormRoleController.js
+++ b/traffic_portal/app/src/common/modules/form/role/FormRoleController.js
@@ -17,20 +17,10 @@
* under the License.
*/
-var FormRoleController = function(roles, $scope, $location, formUtils, locationUtils) {
+var FormRoleController = function(roles, $scope, formUtils, locationUtils) {
$scope.role = roles[0];
- $scope.viewCapabilities = function() {
- return; // todo: need to implement this view
- $location.path($location.path() + '/capabilities');
- };
-
- $scope.viewUsers = function() {
- return; // todo: need to implement this view
- $location.path($location.path() + '/users');
- };
-
$scope.navigateToPath = locationUtils.navigateToPath;
$scope.hasError = formUtils.hasError;
@@ -39,5 +29,5 @@ var FormRoleController = function(roles, $scope, $location, formUtils, locationU
};
-FormRoleController.$inject = ['roles', '$scope', '$location', 'formUtils', 'locationUtils'];
+FormRoleController.$inject = ['roles', '$scope', 'formUtils', 'locationUtils'];
module.exports = FormRoleController;
diff --git a/traffic_portal/app/src/common/modules/form/role/edit/FormEditRoleController.js b/traffic_portal/app/src/common/modules/form/role/edit/FormEditRoleController.js
index 08223e5..e5fd847 100644
--- a/traffic_portal/app/src/common/modules/form/role/edit/FormEditRoleController.js
+++ b/traffic_portal/app/src/common/modules/form/role/edit/FormEditRoleController.js
@@ -17,7 +17,7 @@
* under the License.
*/
-var FormEditRoleController = function(roles, $scope, $controller, $uibModal, $anchorScroll, locationUtils, roleService, messageModel) {
+var FormEditRoleController = function(roles, $scope, $controller, $uibModal, $anchorScroll, $location, locationUtils, roleService, messageModel) {
// extends the FormRoleController to inherit common methods
angular.extend(this, $controller('FormRoleController', { roles: roles, $scope: $scope }));
@@ -46,6 +46,16 @@ var FormEditRoleController = function(roles, $scope, $controller, $uibModal, $an
saveLabel: 'Update'
};
+ $scope.viewCapabilities = function() {
+ $location.path($location.path() + '/capabilities');
+ };
+
+ $scope.viewUsers = function() {
+ alert('viewUsers');
+ return; // todo: need to implement this view
+ $location.path($location.path() + '/users');
+ };
+
$scope.confirmSave = function(role) {
var params = {
title: 'Update Role?',
@@ -93,5 +103,5 @@ var FormEditRoleController = function(roles, $scope, $controller, $uibModal, $an
};
-FormEditRoleController.$inject = ['roles', '$scope', '$controller', '$uibModal', '$anchorScroll', 'locationUtils', 'roleService', 'messageModel'];
+FormEditRoleController.$inject = ['roles', '$scope', '$controller', '$uibModal', '$anchorScroll', '$location', 'locationUtils', 'roleService', 'messageModel'];
module.exports = FormEditRoleController;
diff --git a/traffic_portal/app/src/common/modules/form/role/form.role.tpl.html b/traffic_portal/app/src/common/modules/form/role/form.role.tpl.html
index 5f03d24..c451a19 100644
--- a/traffic_portal/app/src/common/modules/form/role/form.role.tpl.html
+++ b/traffic_portal/app/src/common/modules/form/role/form.role.tpl.html
@@ -24,8 +24,8 @@ under the License.
<li class="active">{{roleName}}</li>
</ol>
<div class="pull-right" role="group" ng-show="!settings.isNew">
- <!--<button class="btn btn-primary" title="View Capabilities" ng-click="viewCapabilities()">View Capabilities</button>-->
- <!--<button class="btn btn-primary" title="View Users" ng-click="viewUsers()">View Users</button>-->
+ <button class="btn btn-primary" title="View Capabilities" ng-click="viewCapabilities()">View Capabilities</button>
+ <button class="btn btn-primary" title="View Users" ng-click="viewUsers()">View Users</button>
</div>
<div class="clearfix"></div>
</div>
diff --git a/traffic_portal/app/src/common/modules/table/roleCapabilities/TableAssignCapabilitiesController.js b/traffic_portal/app/src/common/modules/table/roleCapabilities/TableAssignCapabilitiesController.js
new file mode 100644
index 0000000..66f6e7e
--- /dev/null
+++ b/traffic_portal/app/src/common/modules/table/roleCapabilities/TableAssignCapabilitiesController.js
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+var TableAssignCapabilitiesController = function(role, capabilities, assignedCapabilities, $scope, $uibModalInstance) {
+
+ var selectedCapabilities = [];
+
+ var addAll = function() {
+ markVisibleCapabilities(true);
+ };
+
+ var removeAll = function() {
+ markVisibleCapabilities(false);
+ };
+
+ var markVisibleCapabilities = function(selected) {
+ var visibleCapabilityNames = $('#assignCapabilitiesTable tr.cap-row').map(
+ function() {
+ return $(this).attr('id'); // the cap name is being stored as the id on the row
+ }).get();
+ $scope.selectedCapabilities = _.map(capabilities, function(c) {
+ if (visibleCapabilityNames.includes(c.name)) {
+ c['selected'] = selected;
+ }
+ return c;
+ });
+ updateSelectedCount();
+ };
+
+ var updateSelectedCount = function() {
+ selectedCapabilities = _.filter($scope.selectedCapabilities, function(c) { return c['selected'] == true; } );
+ $('div.selected-count').html('<b>' + selectedCapabilities.length + ' capabilities selected</b>');
+ };
+
+ $scope.role = role;
+
+ $scope.selectedCapabilities = _.map(capabilities, function(c) {
+ var isAssigned = _.find(assignedCapabilities, function(assignedCap) {
+ return assignedCap == c.name
+ });
+ if (isAssigned) {
+ c['selected'] = true;
+ }
+ return c;
+ });
+
+ $scope.selectAll = function($event) {
+ var checkbox = $event.target;
+ if (checkbox.checked) {
+ addAll();
+ } else {
+ removeAll();
+ }
+ };
+
+ $scope.onChange = function() {
+ updateSelectedCount();
+ };
+
+ $scope.submit = function() {
+ var selectedCapabilityNames = _.pluck(selectedCapabilities, 'name');
+ $uibModalInstance.close(selectedCapabilityNames);
+ };
+
+ $scope.cancel = function () {
+ $uibModalInstance.dismiss('cancel');
+ };
+
+ angular.element(document).ready(function () {
+ var assignCapabilitiesTable = $('#assignCapabilitiesTable').dataTable({
+ "scrollY": "60vh",
+ "paging": false,
+ "order": [[ 1, 'asc' ]],
+ "dom": '<"selected-count">frtip',
+ "columnDefs": [
+ { 'orderable': false, 'targets': 0 },
+ { "width": "5%", "targets": 0 }
+ ],
+ "stateSave": false
+ });
+ assignCapabilitiesTable.on( 'search.dt', function () {
+ $("#selectAllCB").removeAttr("checked"); // uncheck the all box when filtering
+ } );
+ updateSelectedCount();
+ });
+
+};
+
+TableAssignCapabilitiesController.$inject = ['role', 'capabilities', 'assignedCapabilities', '$scope', '$uibModalInstance'];
+module.exports = TableAssignCapabilitiesController;
diff --git a/traffic_portal/app/src/common/modules/table/roleCapabilities/TableRoleCapabilitiesController.js b/traffic_portal/app/src/common/modules/table/roleCapabilities/TableRoleCapabilitiesController.js
new file mode 100644
index 0000000..3e7623c
--- /dev/null
+++ b/traffic_portal/app/src/common/modules/table/roleCapabilities/TableRoleCapabilitiesController.js
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+var TableRoleCapabilitiesController = function(roles, $scope, $state, $uibModal, locationUtils, capabilityService, roleService, messageModel) {
+
+ $scope.role = roles[0];
+
+ $scope.selectCapabilities = function() {
+ var modalInstance = $uibModal.open({
+ templateUrl: 'common/modules/table/roleCapabilities/table.assignCapabilities.tpl.html',
+ controller: 'TableAssignCapabilitiesController',
+ size: 'lg',
+ resolve: {
+ role: function() {
+ return $scope.role;
+ },
+ capabilities: function(capabilityService) {
+ return capabilityService.getCapabilities();
+ },
+ assignedCapabilities: function() {
+ return $scope.role.capabilities;
+ }
+ }
+ });
+ modalInstance.result.then(function(selectedCapabilities) {
+ $scope.role.capabilities = selectedCapabilities;
+ roleService.updateRole($scope.role)
+ .then(
+ function(result) {
+ messageModel.setMessages(result.alerts, false);
+ $scope.refresh();
+ }
+ );
+ }, function () {
+ // do nothing
+ });
+ };
+
+ $scope.confirmRemoveCapability = function(capToRemove, $event) {
+ $event.stopPropagation(); // this kills the click event so it doesn't trigger anything else
+
+ var params = {
+ title: 'Remove Capabilty from Role?',
+ message: 'Are you sure you want to remove ' + capToRemove + ' from this role?'
+ };
+ var modalInstance = $uibModal.open({
+ templateUrl: 'common/modules/dialog/confirm/dialog.confirm.tpl.html',
+ controller: 'DialogConfirmController',
+ size: 'md',
+ resolve: {
+ params: function () {
+ return params;
+ }
+ }
+ });
+ modalInstance.result.then(function() {
+ $scope.role.capabilities = _.filter($scope.role.capabilities, function(cap) { return cap != capToRemove; });
+ roleService.updateRole($scope.role)
+ .then(
+ function(result) {
+ messageModel.setMessages(result.alerts, false);
+ $scope.refresh();
+ }
+ );
+ }, function () {
+ // do nothing
+ });
+ };
+
+ $scope.refresh = function() {
+ $state.reload(); // reloads all the resolves for the view
+ };
+
+ $scope.navigateToPath = locationUtils.navigateToPath;
+
+ angular.element(document).ready(function () {
+ $('#capabilitiesTable').dataTable({
+ "aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
+ "iDisplayLength": 25,
+ "columnDefs": [
+ { 'orderable': false, 'targets': 1 }
+ ],
+ "aaSorting": []
+ });
+ });
+
+};
+
+TableRoleCapabilitiesController.$inject = ['roles', '$scope', '$state', '$uibModal', 'locationUtils', 'capabilityService', 'roleService', 'messageModel'];
+module.exports = TableRoleCapabilitiesController;
diff --git a/traffic_portal/app/src/common/modules/form/role/FormRoleController.js b/traffic_portal/app/src/common/modules/table/roleCapabilities/index.js
similarity index 54%
copy from traffic_portal/app/src/common/modules/form/role/FormRoleController.js
copy to traffic_portal/app/src/common/modules/table/roleCapabilities/index.js
index 2223a76..e8455b2 100644
--- a/traffic_portal/app/src/common/modules/form/role/FormRoleController.js
+++ b/traffic_portal/app/src/common/modules/table/roleCapabilities/index.js
@@ -1,3 +1,4 @@
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -17,27 +18,6 @@
* under the License.
*/
-var FormRoleController = function(roles, $scope, $location, formUtils, locationUtils) {
-
- $scope.role = roles[0];
-
- $scope.viewCapabilities = function() {
- return; // todo: need to implement this view
- $location.path($location.path() + '/capabilities');
- };
-
- $scope.viewUsers = function() {
- return; // todo: need to implement this view
- $location.path($location.path() + '/users');
- };
-
- $scope.navigateToPath = locationUtils.navigateToPath;
-
- $scope.hasError = formUtils.hasError;
-
- $scope.hasPropertyError = formUtils.hasPropertyError;
-
-};
-
-FormRoleController.$inject = ['roles', '$scope', '$location', 'formUtils', 'locationUtils'];
-module.exports = FormRoleController;
+module.exports = angular.module('trafficPortal.table.roleCapabilities', [])
+ .controller('TableRoleCapabilitiesController', require('./TableRoleCapabilitiesController'))
+ .controller('TableAssignCapabilitiesController', require('./TableAssignCapabilitiesController'));
diff --git a/traffic_portal/app/src/common/modules/table/roleCapabilities/table.assignCapabilities.tpl.html b/traffic_portal/app/src/common/modules/table/roleCapabilities/table.assignCapabilities.tpl.html
new file mode 100644
index 0000000..4b0648b
--- /dev/null
+++ b/traffic_portal/app/src/common/modules/table/roleCapabilities/table.assignCapabilities.tpl.html
@@ -0,0 +1,43 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<div class="modal-header">
+ <button type="button" class="close" ng-click="cancel()"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
+ <h3 class="modal-title">Assign Capabilities to {{::role.name}}</h3>
+</div>
+<div class="modal-body">
+ <table id="assignCapabilitiesTable" class="table responsive-utilities jambo_table" style="table-layout:fixed; width:100%;">
+ <thead>
+ <tr class="headings">
+ <th style="padding-left: 10px;"><input id="selectAllCB" type="checkbox" ng-click="selectAll($event)"></th>
+ <th>Name</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr id="{{::c.name}}" class="cap-row" ng-repeat="c in ::selectedCapabilities">
+ <td><input type="checkbox" ng-checked="c.selected" ng-model="c.selected" ng-change="onChange()"></td>
+ <td data-search="^{{::c.name}}$">{{::c.name}}</td>
+ </tr>
+ </tbody>
+ </table>
+</div>
+<div class="modal-footer">
+ <button class="btn btn-link" ng-click="cancel()">cancel</button>
+ <button class="btn btn-primary" ng-click="submit()">Submit</button>
+</div>
diff --git a/traffic_portal/app/src/common/modules/table/roleCapabilities/table.roleCapabilities.tpl.html b/traffic_portal/app/src/common/modules/table/roleCapabilities/table.roleCapabilities.tpl.html
new file mode 100644
index 0000000..1269f57
--- /dev/null
+++ b/traffic_portal/app/src/common/modules/table/roleCapabilities/table.roleCapabilities.tpl.html
@@ -0,0 +1,53 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<div class="x_panel">
+ <div class="x_title">
+ <ol class="breadcrumb pull-left">
+ <li><a ng-click="navigateToPath('/roles')">Roles</a></li>
+ <li><a ng-click="navigateToPath('/roles/' + role.id)">{{::role.name}}</a></li>
+ <li class="active">Capabilities</li>
+ </ol>
+ <div class="pull-right" role="group">
+ <button class="btn btn-primary" title="Link Capabilties to Role" ng-click="selectCapabilities()"><i class="fa fa-link"></i></button>
+ <button class="btn btn-default" title="Refresh" ng-click="refresh()"><i class="fa fa-refresh"></i></button>
+ </div>
+ <div class="clearfix"></div>
+ </div>
+ <div class="x_content">
+ <br>
+ <table id="capabilitiesTable" class="table responsive-utilities jambo_table">
+ <thead>
+ <tr class="headings">
+ <th>Name</th>
+ <th style="text-align: right;">Actions</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr ng-repeat="c in ::role.capabilities">
+ <td data-search="^{{::c}}$">{{::c}}</td>
+ <td style="text-align: right;">
+ <a class="link action-link" title="Remove Capability from Role" ng-click="confirmRemoveCapability(c, $event)"><i class="fa fa-sm fa-chain-broken"></i></a>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+</div>
+
diff --git a/traffic_portal/app/src/common/modules/form/role/FormRoleController.js b/traffic_portal/app/src/modules/private/roles/capabilities/index.js
similarity index 54%
copy from traffic_portal/app/src/common/modules/form/role/FormRoleController.js
copy to traffic_portal/app/src/modules/private/roles/capabilities/index.js
index 2223a76..bc012bf 100644
--- a/traffic_portal/app/src/common/modules/form/role/FormRoleController.js
+++ b/traffic_portal/app/src/modules/private/roles/capabilities/index.js
@@ -17,27 +17,23 @@
* under the License.
*/
-var FormRoleController = function(roles, $scope, $location, formUtils, locationUtils) {
-
- $scope.role = roles[0];
-
- $scope.viewCapabilities = function() {
- return; // todo: need to implement this view
- $location.path($location.path() + '/capabilities');
- };
-
- $scope.viewUsers = function() {
- return; // todo: need to implement this view
- $location.path($location.path() + '/users');
- };
-
- $scope.navigateToPath = locationUtils.navigateToPath;
-
- $scope.hasError = formUtils.hasError;
-
- $scope.hasPropertyError = formUtils.hasPropertyError;
-
-};
-
-FormRoleController.$inject = ['roles', '$scope', '$location', 'formUtils', 'locationUtils'];
-module.exports = FormRoleController;
+module.exports = angular.module('trafficPortal.private.roles.capabilities', [])
+ .config(function($stateProvider, $urlRouterProvider) {
+ $stateProvider
+ .state('trafficPortal.private.roles.capabilities', {
+ url: '/{roleId}/capabilities',
+ views: {
+ rolesContent: {
+ templateUrl: 'common/modules/table/roleCapabilities/table.roleCapabilities.tpl.html',
+ controller: 'TableRoleCapabilitiesController',
+ resolve: {
+ roles: function($stateParams, roleService) {
+ return roleService.getRoles({ id: $stateParams.roleId });
+ }
+ }
+ }
+ }
+ })
+ ;
+ $urlRouterProvider.otherwise('/');
+ });
--
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.