Commit 68225d64 by utkarshcmu

Converted org_users_ctrl to typescript

parent 14952de2
...@@ -71,6 +71,7 @@ function setupAngularRoutes($routeProvider, $locationProvider) { ...@@ -71,6 +71,7 @@ function setupAngularRoutes($routeProvider, $locationProvider) {
.when('/org/users', { .when('/org/users', {
templateUrl: 'public/app/features/org/partials/orgUsers.html', templateUrl: 'public/app/features/org/partials/orgUsers.html',
controller : 'OrgUsersCtrl', controller : 'OrgUsersCtrl',
controllerAs: 'ctrl',
resolve: loadOrgBundle, resolve: loadOrgBundle,
}) })
.when('/org/apikeys', { .when('/org/apikeys', {
......
define([ define([
'./orgUsersCtrl', './org_users_ctrl',
'./newOrgCtrl', './newOrgCtrl',
'./userInviteCtrl', './userInviteCtrl',
'./orgApiKeysCtrl', './orgApiKeysCtrl',
......
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();
});
});
///<reference path="../../headers/common.d.ts" />
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);
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<div class="page-container"> <div class="page-container">
<div class="page-wide"> <div class="page-wide">
<button class="btn btn-inverse pull-right" ng-click="openInviteModal()"> <button class="btn btn-inverse pull-right" ng-click="ctrl.openInviteModal()">
<i class="fa fa-plus"></i> <i class="fa fa-plus"></i>
Add or Invite Add or Invite
</button> </button>
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<br> <br>
<tabset> <tabset>
<tab heading="Users ({{users.length}})"> <tab heading="Users ({{ctrl.users.length}})">
<table class="filter-table form-inline"> <table class="filter-table form-inline">
<thead> <thead>
<tr> <tr>
...@@ -26,22 +26,22 @@ ...@@ -26,22 +26,22 @@
<th style="width: 34px;"></th> <th style="width: 34px;"></th>
</tr> </tr>
</thead> </thead>
<tr ng-repeat="user in users"> <tr ng-repeat="user in ctrl.users">
<td>{{user.login}}</td> <td>{{user.login}}</td>
<td><span class="ellipsis">{{user.email}}</span></td> <td><span class="ellipsis">{{user.email}}</span></td>
<td> <td>
<select type="text" ng-model="user.role" class="input-medium" ng-options="f for f in ['Viewer', 'Editor', 'Read Only Editor', 'Admin']" ng-change="updateOrgUser(user)"> <select type="text" ng-model="user.role" class="input-medium" ng-options="f for f in ['Viewer', 'Editor', 'Read Only Editor', 'Admin']" ng-change="ctrl.updateOrgUser(user)">
</select> </select>
</td> </td>
<td> <td>
<a ng-click="removeUser(user)" class="btn btn-danger btn-mini"> <a ng-click="ctrl.removeUser(user)" class="btn btn-danger btn-mini">
<i class="fa fa-remove"></i> <i class="fa fa-remove"></i>
</a> </a>
</td> </td>
</tr> </tr>
</table> </table>
</tab> </tab>
<tab heading="Pending Invitations ({{pendingInvites.length}})"> <tab heading="Pending Invitations ({{ctrl.pendingInvites.length}})">
<table class="filter-table form-inline"> <table class="filter-table form-inline">
<thead> <thead>
<tr> <tr>
...@@ -50,12 +50,12 @@ ...@@ -50,12 +50,12 @@
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
<tbody ng-repeat="invite in pendingInvites"> <tbody ng-repeat="invite in ctrl.pendingInvites">
<tr ng-click="invite.expanded = !invite.expanded" ng-class="{'expanded': invite.expanded}"> <tr ng-click="invite.expanded = !invite.expanded" ng-class="{'expanded': invite.expanded}">
<td>{{invite.email}}</td> <td>{{invite.email}}</td>
<td>{{invite.name}}</td> <td>{{invite.name}}</td>
<td class="text-right"> <td class="text-right">
<button class="btn btn-inverse btn-mini " data-clipboard-text="{{invite.url}}" clipboard-button ng-click="copyInviteToClipboard($event)"> <button class="btn btn-inverse btn-mini " data-clipboard-text="{{invite.url}}" clipboard-button ng-click="ctrl.copyInviteToClipboard($event)">
<i class="fa fa-clipboard"></i> Copy Invite <i class="fa fa-clipboard"></i> Copy Invite
</button> </button>
&nbsp; &nbsp;
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
<td colspan="3"> <td colspan="3">
<a href="{{invite.url}}">{{invite.url}}</a><br><br> <a href="{{invite.url}}">{{invite.url}}</a><br><br>
&nbsp; &nbsp;
<button class="btn btn-inverse btn-mini" ng-click="revokeInvite(invite, $event)"> <button class="btn btn-inverse btn-mini" ng-click="ctrl.revokeInvite(invite, $event)">
<i class="fa fa-remove" style="color: red"></i> Revoke invite <i class="fa fa-remove" style="color: red"></i> Revoke invite
</button> </button>
<span style="padding-left: 15px"> <span style="padding-left: 15px">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment