bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/web/static/js/tokenList.ts (about) 1 /// <reference path="0-bosun.ts" /> 2 3 class TokenListController { 4 tokens: Array<Token>; 5 status: string ; 6 deleteTarget: string; 7 8 delete = () => { 9 this.status = "Deleting..." 10 this.$http.delete("/api/tokens?hash=" + encodeURIComponent(this.deleteTarget)) 11 .then(() => { 12 this.status = ""; 13 this.load(); 14 }, (err) => { 15 this.status = 'Unable to delete token: ' + err; 16 }) 17 } 18 19 load = () =>{ 20 this.status = "Loading..." 21 this.$http.get("/api/tokens").then( 22 (resp: ng.IHttpPromiseCallbackArg<Token[]>) => { 23 _(resp.data).forEach((tok) => { 24 tok.LastUsed = moment.utc(tok.LastUsed); 25 tok.Permissions = this.auth.PermissionsFor(tok.Role); 26 tok.RoleName = this.auth.RoleFor(tok.Role) || ("" + tok.Permissions.length+" Permissions"); 27 }) 28 this.tokens = resp.data; 29 this.status = ""; 30 }, (err) => { 31 this.status = 'Unable to fetch tokens: ' + err; 32 } 33 ) 34 } 35 36 permList = (tok: Token): string =>{ 37 //HACK: return html string for popover. angular-strap has bad api for this 38 var h = `<div class="popover" tabindex="-1"> 39 <div class="arrow"></div> 40 <div class="popover-content"><ul>` 41 var perms = this.auth.PermissionsFor(tok.Role); 42 for (var i = 0; i< perms.length; i++){ 43 var p = perms[i]; 44 var open = "<strong>"; 45 var close = "</strong>"; 46 h += "<li>"+open+p+close+"</li>"; 47 } 48 h += `</ul></div></div>` 49 return h; 50 } 51 52 static $inject = ['$http', "authService"]; 53 constructor(private $http: ng.IHttpService, private auth: IAuthService) { 54 this.load(); 55 } 56 } 57 58 bosunApp.component('tokenList', { 59 controller: TokenListController, 60 controllerAs: "ct", 61 templateUrl : '/static/partials/tokenList.html'});