Finalised UI for sharing permissions

This commit is contained in:
Tatyana Tychshenko 2016-06-10 15:48:02 +10:00 committed by Arik Fraimovich
parent 91a46ea1bb
commit 95dca53b1e
5 changed files with 89 additions and 116 deletions

View File

@ -156,9 +156,76 @@
$scope.recentDashboards = Dashboard.recent();
};
// Controller for modal window share_permissions, works for both query and dashboards, needs api_access set in scope
var SharePermissionsCtrl = function ($scope, $http, $modalInstance, User) {
$scope.grantees = [];
$scope.newGrantees = {};
// List users that are granted permissions
var loadGrantees = function() {
$http.get($scope.api_access).success(function(result) {
$scope.grantees = [];
for(var access_type in result) {
result[access_type].forEach(function(grantee) {
var item = grantee;
item['access_type'] = access_type;
$scope.grantees.push(item);
})
}
});
};
loadGrantees();
// Search for user
$scope.findUser = function(search) {
if (search == "") {
return;
}
if ($scope.foundUsers === undefined) {
User.query(function(users) {
var existingIds = _.map($scope.grantees, function(m) { return m.id; });
_.each(users, function(user) { user.alreadyGrantee = _.contains(existingIds, user.id); });
$scope.foundUsers = users;
});
}
};
// Add new user to grantees list
$scope.addGrantee = function(user) {
$scope.newGrantees.selected = undefined;
var body = {'access_type': 'modify', 'user_id': user.id};
$http.post($scope.api_access, body).success(function() {
user.alreadyGrantee = true;
loadGrantees();
});
};
// Remove user from grantees list
$scope.removeGrantee = function(user) {
var body = {'access_type': 'modify', 'user_id': user.id};
$http({ url: $scope.api_access, method: 'DELETE',
data: body, headers: {"Content-Type": "application/json"}
}).success(function() {
$scope.grantees = _.filter($scope.grantees, function(m) { return m != user });
if ($scope.foundUsers) {
_.each($scope.foundUsers, function(u) { if (u.id == user.id) { u.alreadyGrantee = false }; });
}
});
};
$scope.close = function() {
$modalInstance.close();
}
};
angular.module('redash.controllers', [])
.controller('QueriesCtrl', ['$scope', '$http', '$location', '$filter', 'Query', QueriesCtrl])
.controller('IndexCtrl', ['$scope', 'Events', 'Dashboard', 'Query', IndexCtrl])
.controller('MainCtrl', ['$scope', '$location', 'Dashboard', MainCtrl])
.controller('QuerySearchCtrl', ['$scope', '$location', '$filter', 'Events', 'Query', QuerySearchCtrl]);
.controller('QuerySearchCtrl', ['$scope', '$location', '$filter', 'Events', 'Query', QuerySearchCtrl])
.controller('SharePermissionsCtrl', ['$scope', '$http', '$modalInstance', 'User', SharePermissionsCtrl]);
})();

View File

@ -116,54 +116,17 @@
}
}
$scope.showSharePermissionsModal = function(dashboard) {
$modal.open({
templateUrl: '/views/dialogs/share_permissions.html',
controller: ['$scope', '$modalInstance', function($scope, $modalInstance) {
$scope.showSharePermissionsModal = function() {
// Create scope for share permissions dialog and pass api path to it
var scope = $scope.$new();
$scope.api_access = 'api/access/Dashboard/' + $scope.dashboard.id;
scope.params = {api_access: $scope.api_access};
// $scope.can_edit_group = Group.get({id: $routeParams.groupId});
$scope.members = [];
$scope.newMember = {};
$scope.findUser = function(search) {
if (search == "") {
return;
}
if ($scope.foundUsers === undefined) {
User.query(function(users) {
var existingIds = _.map($scope.members, function(m) { return m.id; });
_.each(users, function(user) { user.alreadyMember = _.contains(existingIds, user.id); });
$scope.foundUsers = users;
});
}
};
$scope.addMember = function(user) {
// Clear selection, to clear up the input control.
$scope.newMember.selected = undefined;
//$http.post('api/access/' + $routeParams.groupId + '/members', {'user_id': user.id}).success(function() {
$scope.members.unshift(user);
user.alreadyMember = true;
// });
};
$scope.removeMember = function(member) {
// $http.delete('api/access/' + $routeParams.groupId + '/members/' + member.id).success(function() {
$scope.members = _.filter($scope.members, function(m) { return m != member });
if ($scope.foundUsers) {
_.each($scope.foundUsers, function(user) { if (user.id == member.id) { user.alreadyMember = false }; });
}
// });
};
$scope.close = function() {
$modalInstance.close();
}
}]
})
$modal.open({
scope: scope,
templateUrl: '/views/dialogs/share_permissions.html',
controller: 'SharePermissionsCtrl'
})
}
$scope.toggleFullscreen = function() {

View File

@ -340,76 +340,19 @@
$scope.selectedTab = hash || DEFAULT_TAB;
});
$scope.showSharePermissionsModal = function(query) {
$scope.showSharePermissionsModal = function() {
// Create scope for share permissions dialog and pass api path to it
var scope = $scope.$new();
$scope.api_access = 'api/access/Query/' + $routeParams.queryId;
scope.params = {api_access: $scope.api_access};
$modal.open({
scope: scope,
templateUrl: '/views/dialogs/share_permissions.html',
controller: ['$scope', '$modalInstance', function($scope, $modalInstance) {
/* list of users that are granted access to this query */
$scope.grantees = [];
$scope.newGrantees = {};
var loadGrantees = function() {
$http.get('api/access/Query/' + $routeParams.queryId).success(function(result) {
$scope.grantees = [];
for(var access_type in result) {
result[access_type].forEach(function(grantee) {
var item = grantee;
item['access_type'] = access_type;
$scope.grantees.push(item);
})
}
});
};
loadGrantees();
$scope.findUser = function(search) {
if (search == "") {
return;
}
if ($scope.foundUsers === undefined) {
User.query(function(users) {
var existingIds = _.map($scope.grantees, function(m) { return m.id; });
_.each(users, function(user) { user.alreadyGrantee = _.contains(existingIds, user.id); });
$scope.foundUsers = users;
});
}
};
$scope.addGrantee = function(user) {
// Clear selection, to clear up the input control.
$scope.newGrantees.selected = undefined;
var body = {'access_type': 'modify', 'user_id': user.id};
$http.post('api/access/Query/' + $routeParams.queryId, body).success(function() {
$scope.grantees.unshift(user);
user.alreadyGrantee = true;
});
};
$scope.removeGrantee = function(user) {
var body = {'access_type': 'modify', 'user_id': user.id};
$http({ url: 'api/access/Query/' + $routeParams.queryId, method: 'DELETE',
data: body, headers: {"Content-Type": "application/json"}
}).success(function() {
$scope.grantees = _.filter($scope.grantees, function(m) { return m != user });
if ($scope.foundUsers) {
_.each($scope.foundUsers, function(u) { if (u.id == user.id) { u.alreadyMember = false }; });
}
});
};
$scope.close = function() {
$modalInstance.close();
}
}]
controller: 'SharePermissionsCtrl'
})
}
};
angular.module('redash.controllers')
.controller('QueryViewCtrl',
['$scope', 'Events', '$route', '$routeParams', '$http', '$location', 'notifications', 'growl', '$modal', 'Query', 'DataSource', 'User', QueryViewCtrl]);
.controller('QueryViewCtrl', ['$scope', 'Events', '$route', '$routeParams', '$http', '$location', 'notifications', 'growl', '$modal', 'Query', 'DataSource', 'User', QueryViewCtrl]);
})();

View File

@ -20,7 +20,7 @@
</button>
<ul class="dropdown-menu pull-right" dropdown-menu>
<li><a data-toggle="modal" hash-link hash="edit_dashboard_dialog">Edit Dashboard</a></li>
<li><a ng-click="showSharePermissionsModal(dashboard)">Share Edit Permissions</a></li>
<li><a ng-click="showSharePermissionsModal()">Share Edit Permissions</a></li>
<li><a data-toggle="modal" hash-link hash="add_query_dialog">Add Widget</a></li>
<li ng-if="!dashboard.is_archived"><a ng-click="archiveDashboard()">Archive Dashboard</a></li>
</ul>

View File

@ -125,7 +125,7 @@
</button>
<ul class="dropdown-menu pull-right" dropdown-menu>
<li ng-if="!query.is_archived && query.id != undefined && (isQueryOwner || currentUser.hasPermission('admin'))"><a hash-link hash="archive-confirmation-modal" data-toggle="modal">Archive Query</a></li>
<li ng-if="!query.is_archived && query.id != undefined && (isQueryOwner || currentUser.hasPermission('admin'))"><a ng-click="showSharePermissionsModal(query)">Share Edit Permissions</a></li>
<li ng-if="!query.is_archived && query.id != undefined && (isQueryOwner || currentUser.hasPermission('admin'))"><a ng-click="showSharePermissionsModal()">Share Edit Permissions</a></li>
<li ng-if="query.id != undefined"><a ng-click="showApiKey()">Show API Key</a></li>
</ul>
</div>