From 68225d64aa91d324e3ed39d8b341127f1bbd44e8 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Sat, 13 Feb 2016 17:55:49 -0800 Subject: [PATCH 1/2] Converted org_users_ctrl to typescript --- public/app/core/routes/routes.ts | 1 + public/app/features/org/all.js | 2 +- public/app/features/org/orgUsersCtrl.js | 66 ----------------- public/app/features/org/org_users_ctrl.ts | 73 +++++++++++++++++++ .../app/features/org/partials/orgUsers.html | 18 ++--- 5 files changed, 84 insertions(+), 76 deletions(-) delete mode 100644 public/app/features/org/orgUsersCtrl.js create mode 100644 public/app/features/org/org_users_ctrl.ts diff --git a/public/app/core/routes/routes.ts b/public/app/core/routes/routes.ts index 82da84fbc56..4df007d7bd6 100644 --- a/public/app/core/routes/routes.ts +++ b/public/app/core/routes/routes.ts @@ -71,6 +71,7 @@ function setupAngularRoutes($routeProvider, $locationProvider) { .when('/org/users', { templateUrl: 'public/app/features/org/partials/orgUsers.html', controller : 'OrgUsersCtrl', + controllerAs: 'ctrl', resolve: loadOrgBundle, }) .when('/org/apikeys', { diff --git a/public/app/features/org/all.js b/public/app/features/org/all.js index d232b3bcd0a..cebd0dd1def 100644 --- a/public/app/features/org/all.js +++ b/public/app/features/org/all.js @@ -1,5 +1,5 @@ define([ - './orgUsersCtrl', + './org_users_ctrl', './newOrgCtrl', './userInviteCtrl', './orgApiKeysCtrl', diff --git a/public/app/features/org/orgUsersCtrl.js b/public/app/features/org/orgUsersCtrl.js deleted file mode 100644 index 0419e4d4a3b..00000000000 --- a/public/app/features/org/orgUsersCtrl.js +++ /dev/null @@ -1,66 +0,0 @@ -define([ - 'angular', -], -function (angular) { - 'use strict'; - - var module = angular.module('grafana.controllers'); - - module.controller('OrgUsersCtrl', function($scope, $http, backendSrv) { - - $scope.user = { - loginOrEmail: '', - role: 'Viewer', - }; - - $scope.users = []; - $scope.pendingInvites = []; - - $scope.init = function() { - $scope.get(); - $scope.editor = { index: 0 }; - }; - - $scope.get = function() { - backendSrv.get('/api/org/users').then(function(users) { - $scope.users = users; - }); - backendSrv.get('/api/org/invites').then(function(pendingInvites) { - $scope.pendingInvites = pendingInvites; - }); - }; - - $scope.updateOrgUser = function(user) { - backendSrv.patch('/api/org/users/' + user.userId, user); - }; - - $scope.removeUser = function(user) { - backendSrv.delete('/api/org/users/' + user.userId).then($scope.get); - }; - - $scope.revokeInvite = function(invite, evt) { - evt.stopPropagation(); - backendSrv.patch('/api/org/invites/' + invite.code + '/revoke').then($scope.get); - }; - - $scope.copyInviteToClipboard = function(evt) { - evt.stopPropagation(); - }; - - $scope.openInviteModal = function() { - var modalScope = $scope.$new(); - modalScope.invitesSent = function() { - $scope.get(); - }; - - $scope.appEvent('show-modal', { - src: 'public/app/features/org/partials/invite.html', - modalClass: 'modal-no-header invite-modal', - scope: modalScope - }); - }; - - $scope.init(); - - }); -}); diff --git a/public/app/features/org/org_users_ctrl.ts b/public/app/features/org/org_users_ctrl.ts new file mode 100644 index 00000000000..5738eff1f77 --- /dev/null +++ b/public/app/features/org/org_users_ctrl.ts @@ -0,0 +1,73 @@ +/// + +import angular from 'angular'; +import _ from 'lodash'; +import coreModule from '../../core/core_module'; + +export class OrgUsersCtrl { + + user: any; + users: any; + pendingInvites: any; + editor: any; + + /** @ngInject */ + constructor(private $scope, private $http, private backendSrv) { + this.user = { + loginOrEmail: '', + role: 'Viewer', + }; + this.get(); + this.editor = { index: 0 }; + } + + get() { + this.backendSrv.get('/api/org/users') + .then((users) => { + this.users = users; + }); + this.backendSrv.get('/api/org/invites') + .then((pendingInvites) => { + this.pendingInvites = pendingInvites; + }); + } + + updateOrgUser(user) { + this.backendSrv.patch('/api/org/users/' + user.userId, user); + } + + removeUser(user) { + this.backendSrv.delete('/api/org/users/' + user.userId) + .then(() => { + this.get(); + }); + } + + revokeInvite(invite, evt) { + evt.stopPropagation(); + this.backendSrv.patch('/api/org/invites/' + invite.code + '/revoke') + .then(() => { + this.get(); + }); + } + + copyInviteToClipboard(evt) { + evt.stopPropagation(); + } + + openInviteModal() { + var modalScope = this.$scope.$new(); + modalScope.invitesSent = function() { + this.get(); + }; + + this.$scope.appEvent('show-modal', { + src: 'public/app/features/org/partials/invite.html', + modalClass: 'modal-no-header invite-modal', + scope: modalScope + }); + } + +} + +coreModule.controller('OrgUsersCtrl', OrgUsersCtrl); diff --git a/public/app/features/org/partials/orgUsers.html b/public/app/features/org/partials/orgUsers.html index c029dff2955..94ac26c7b0a 100644 --- a/public/app/features/org/partials/orgUsers.html +++ b/public/app/features/org/partials/orgUsers.html @@ -7,7 +7,7 @@
- @@ -16,7 +16,7 @@
- + @@ -26,22 +26,22 @@ - +
{{user.login}} {{user.email}} - - +
- + @@ -50,12 +50,12 @@ - +
{{invite.email}} {{invite.name}} -   @@ -70,7 +70,7 @@ {{invite.url}}

  - From 47b6f01c8b70254d686ef237c03d677bc9ce3d54 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Sat, 13 Feb 2016 18:21:18 -0800 Subject: [PATCH 2/2] confirmation box added for user removal --- public/app/features/org/org_users_ctrl.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/public/app/features/org/org_users_ctrl.ts b/public/app/features/org/org_users_ctrl.ts index 5738eff1f77..9d77148e2ab 100644 --- a/public/app/features/org/org_users_ctrl.ts +++ b/public/app/features/org/org_users_ctrl.ts @@ -37,6 +37,18 @@ export class OrgUsersCtrl { } removeUser(user) { + this.$scope.appEvent('confirm-modal', { + title: 'Confirm delete user', + text: 'Are you sure you want to delete user ' + user.login + '?', + yesText: "Delete", + icon: "fa-warning", + onConfirm: () => { + this.removeUserConfirmed(user); + } + }); + } + + removeUserConfirmed(user) { this.backendSrv.delete('/api/org/users/' + user.userId) .then(() => { this.get();