1 line
10 KiB
JavaScript
1 line
10 KiB
JavaScript
!function(){var e;e=angular.module("adminApp",["ngCookies"]),e.config(["$locationProvider",function(e){return e.html5Mode(!0),e.hashPrefix("!")}]),e.controller("AdminIndexCtrl",["$scope","$location","$q","$cookieStore",function(e,t,n,r){return e.host=t.search().host||r.get("host")||t.host(),e.port=t.search().port||r.get("port"),e.database=t.search().database||r.get("database"),e.username=t.search().username||r.get("username"),e.password=t.search().password||r.get("password"),e.ssl=r.get("ssl")||!1,e.authenticated=!1,e.isClusterAdmin=!1,e.databases=[],e.admins=[],e.data=[],e.readQuery=null,e.writeSeriesName=null,e.writeValues=null,e.successMessage="OK",e.alertMessage="Error",e.authMessage="",e.queryMessage="",e.selectedPane="databases",e.selectedSubPane="users",e.newDbUser={},e.interfaces=[],e.databaseUsers=[],e.databaseUser=null,e.successMessage="",e.failureMessage="",e.shardSpaces=[],e.shardSpaceDurations=["15m","30m","1h","4h","12h","1d","7d","30d","180d"],e.shardSpaceRetentionPolicies=["1h","4h","12h","1d","7d","30d","60d","90d","180d","365d","730d","inf"],e.shardSpaceReplicationFactors=[1,3,4,5,6],e.shardSpaceSplits=[1,2,3,4,5,6,7,8,9,10],e.newAdminUsername=null,e.newAdminPassword=null,e.newUserPassword=null,e.newUserPasswordConfirmation=null,window.influxdb=null,e.alertSuccess=function(t){return e.successMessage=t,$("#alert-success").show().delay(2500).fadeOut(500)},e.alertFailure=function(t){return e.failureMessage=t,$("#alert-failure").show().delay(2500).fadeOut(500)},e.getHashParams=function(){return t.search()},e.setHashParams=function(e){return t.search(e)},e.humanize=function(e){return e.replace(/_/g," ").replace(/(\w+)/g,function(e){return e.charAt(0).toUpperCase()+e.slice(1)})},e.setCurrentInterface=function(t){return $("iframe").prop("src","/interfaces/"+t),e.selectedPane="data"},e.showDefaultInterface=function(t){return window.influxdb.database=t,$("iframe").prop("src","/interfaces/default"),e.selectedPane="data"},e.authenticateUser=function(){return e.database?e.authenticateAsDatabaseAdmin():e.authenticateAsClusterAdmin()},e.authenticateAsClusterAdmin=function(){return window.influxdb=new InfluxDB({hosts:[e.host],port:e.port,username:e.username,password:e.password,ssl:e.ssl}),n.when(window.influxdb.authenticateClusterAdmin()).then(function(){return e.authenticated=!0,e.isClusterAdmin=!0,e.isDatabaseAdmin=!1,e.selectedPane="databases",e.selectedSubPane="users",e.storeAuthenticatedCredentials(),e.getDatabases(),e.getClusterAdmins(),e.database&&(e.selectedDatabase=e.database,e.getDatabaseUsers()),t.search({})},function(t){return e.alertFailure("Couldn't authenticate user: "+t.responseText)})},e.authenticateAsDatabaseAdmin=function(){return window.influxdb=new InfluxDB({host:e.host,port:e.port,username:e.username,password:e.password,database:e.database,ssl:e.ssl}),n.when(window.influxdb.authenticateDatabaseUser(e.database)).then(function(){return e.authenticated=!0,e.isDatabaseAdmin=!0,e.isClusterAdmin=!1,e.selectedPane="databases",e.selectedSubPane="users",e.selectedDatabase=e.database,t.search({}),e.storeAuthenticatedCredentials(),e.getDatabaseUsers()},function(){return e.authenticateAsClusterAdmin()})},e.storeAuthenticatedCredentials=function(){return r.put("username",e.username),r.put("password",e.password),r.put("database",e.database),r.put("host",e.host),r.put("port",e.port),r.put("ssl",e.ssl)},e.getDatabases=function(){return n.when(window.influxdb.getDatabases()).then(function(t){return e.databases=t,e.shardSpaces=[],e.addShardSpace()})},e.getClusterAdmins=function(){return n.when(window.influxdb.getClusterAdmins()).then(function(t){return e.admins=t})},e.deleteClusterAdmin=function(t){return e.username===t?e.alertFailure("You can't delete the cluster admin you're currently logged in as."):n.when(window.influxdb.deleteClusterAdmin(t)).then(function(){return e.alertSuccess("Successfully deleted cluster admin: "+t),e.getClusterAdmins()},function(t){return e.alertFailure("Failed to deleted cluster admin: "+t.responseText)})},e.createClusterAdmin=function(){return n.when(window.influxdb.createClusterAdmin(e.newAdminUsername,e.newAdminPassword)).then(function(){return e.alertSuccess("Successfully created user: "+e.newAdminUsername),e.newAdminUsername=null,e.newAdminPassword=null,e.getClusterAdmins()},function(t){return e.alertFailure("Failed to create user: "+t.responseText)})},e.addShardSpace=function(){return e.shardSpaces.push({name:"default",regEx:"/.*/",retentionPolicy:"inf",shardDuration:"7d",replicationFactor:1,split:1})},e.removeShardSpace=function(t){return e.shardSpaces.splice(t,1),0===e.shardSpaces.length?e.addShardSpace():void 0},e.createDatabase=function(){var t;return t={spaces:e.shardSpaces},n.when(window.influxdb.createDatabaseConfig(e.newDatabaseName,t)).then(function(){return e.alertSuccess("Successfully created database: "+e.newDatabaseName),e.newDatabaseName=null,e.getDatabases()},function(t){return e.alertFailure("Failed to create database: "+t.responseText)})},e.createDatabaseUser=function(){return n.when(window.influxdb.createUser(e.selectedDatabase,e.newDbUser.username,e.newDbUser.password)).then(function(){var t;return e.alertSuccess("Successfully created user: "+e.newDbUser.username),t={admin:e.newDbUser.isAdmin},window.influxdb.updateDatabaseUser(e.selectedDatabase,e.newDbUser.username,t),e.newDbUser={},e.getDatabaseUsers()},function(t){return e.alertFailure("Failed to create user: "+t.responseText)})},e.deleteDatabase=function(t){return n.when(window.influxdb.deleteDatabase(t)).then(function(){return e.alertSuccess("Successfully removed database: "+t),e.getDatabases()},function(t){return e.alertFailure("Failed to remove database: "+t.responseText)})},e.authError=function(t){return e.authMessage=t,$("span#authFailure").show().delay(1500).fadeOut(500)},e.error=function(t){return e.alertMessage=t,$("span#writeFailure").show().delay(1500).fadeOut(500)},e.success=function(t){return e.successMessage=t,$("span#writeSuccess").show().delay(1500).fadeOut(500)},e.filteredColumns=function(e){return e.columns.filter(function(e){return"time"!==e&&"sequence_number"!==e})},e.columnPoints=function(e,t){var n;return n=e.columns.indexOf(t),e.points.map(function(e){return{time:new Date(e[0]),value:e[n]}})},e.getDatabaseUsers=function(){return n.when(window.influxdb.getDatabaseUsers(e.selectedDatabase)).then(function(t){return e.databaseUsers=t})},e.getDatabaseUser=function(){return n.when(window.influxdb.getDatabaseUser(e.selectedDatabase,e.selectedDatabaseUser)).then(function(t){return e.databaseUser=t})},e.showSelectedDatabase=function(){return e.selectedPane="databases",e.selectedSubPane="users",e.selectedDatabaseUser=null,e.getDatabaseUsers()},e.showDatabases=function(){return e.getDatabases(),e.selectedPane="databases",e.selectedSubPane="users",e.selectedDatabase=null,e.selectedDatabaseUser=null},e.showDatabase=function(t){return e.selectedDatabase=t.name,e.selectedDatabaseUser=null,e.getDatabaseUsers()},e.showDatabaseUsers=function(){return e.selectedDatabaseUser=null,e.selectedSubPane="users",e.getDatabaseUsers()},e.getContinuousQueries=function(){return n.when(window.influxdb.getClusterConfiguration()).then(function(t){return e.continuousQueries=t.ContinuousQueries[e.selectedDatabase]})},e.showContinuousQueries=function(){return e.selectedDatabaseUser=null,e.selectedSubPane="continuousQueries",e.getContinuousQueries()},e.showDbSettings=function(){return e.selectedDatabaseUser=null,e.selectedSubPane="settings",e.getDatabaseUsers(),e.getContinuousQueries()},e.showClusterAdmins=function(){return e.getClusterAdmins(),e.selectedPane="admins",e.selectedClusterAdmin=null},e.showClusterConfiguration=function(){return e.getClusterServers(),e.getClusterShards(),e.getClusterShardSpaces(),e.selectedPane="cluster"},e.getClusterServers=function(){return n.when(window.influxdb.getClusterServers()).then(function(t){return e.clusterServers=t})},e.getClusterShards=function(){return n.when(window.influxdb.getClusterShards()).then(function(t){return e.clusterShards=t})},e.getClusterShardSpaces=function(){return n.when(window.influxdb.getClusterShardSpaces()).then(function(t){return e.clusterShardSpaces=t})},e.deleteClusterShard=function(t){return n.when(window.influxdb.deleteClusterShard(t.id,t.serverIds)).then(function(){return e.alertSuccess("Successfully deleted shard: '"+t.id+"'"),e.getClusterShards()},function(t){return e.alertFailure("Failed to delete shard: "+t.responseText)})},e.showClusterAdmin=function(t){return e.selectedClusterAdmin=t.name},e.showDatabaseUser=function(t){return e.selectedDatabaseUser=t.name,e.getDatabaseUser()},e.changeDbUserPassword=function(){var t;return e.dbUserPassword!==e.dbUserPasswordConfirmation?e.alertFailure("Sorry, the passwords don't match."):null===e.dbUserPassword||""===e.dbUserPassword?e.alertFailure("Sorry, passwords cannot be blank."):(t={password:e.dbUserPassword},n.when(window.influxdb.updateDatabaseUser(e.selectedDatabase,e.selectedDatabaseUser,t)).then(function(){return e.alertSuccess("Successfully changed password for '"+e.selectedDatabaseUser+"'"),e.dbUserPassword=null,e.dbUserPasswordConfirmation=null},function(t){return e.alertFailure("Failed to change password for user: "+t.responseText)}))},e.changeClusterAdminPassword=function(){var t;return e.clusterAdminPassword!==e.clusterAdminPasswordConfirmation?e.alertFailure("Sorry, the passwords don't match."):null===e.clusterAdminPassword||""===e.clusterAdminPassword?e.alertFailure("Sorry, passwords cannot be blank."):(t={password:e.clusterAdminPassword},n.when(window.influxdb.updateClusterAdmin(e.selectedClusterAdmin,t)).then(function(){return e.alertSuccess("Successfully changed password for '"+e.selectedClusterAdmin+"'"),e.clusterAdminPassword=null,e.clusterAdminPasswordConfirmation=null},function(t){return e.alertFailure("Failed to change password for cluster admin: "+t.responseText)}))},e.updateDatabaseUser=function(){var t;return t={admin:e.databaseUser.isAdmin},n.when(window.influxdb.updateDatabaseUser(e.selectedDatabase,e.selectedDatabaseUser,t)).then(function(){return e.alertSuccess("Successfully updated database user '"+e.selectedDatabaseUser+"'"),e.getDatabaseUsers()},function(t){return e.alertFailure("Failed to update database user: "+t.responseText)})},e.deleteDatabaseUser=function(t){return n.when(window.influxdb.deleteDatabaseUser(e.selectedDatabase,t)).then(function(){return e.alertSuccess("Successfully delete user: "+t),e.getDatabaseUsers()},function(t){return e.alertFailure("Failed to delete user: "+t.responseText)})}}]),e.directive("ngConfirmClick",[function(){return{priority:-1,restrict:"A",link:function(e,t,n){return t.bind("click",function(e){var t;return t=n.ngConfirmClick,t&&!confirm(t)?(e.stopImmediatePropagation(),e.preventDefault()):void 0})}}}])}.call(this); |