From 959ef733a1c34ac9a2e91d9bb829eeced7dab264 Mon Sep 17 00:00:00 2001 From: jdbranham Date: Wed, 31 May 2017 22:42:03 -0500 Subject: [PATCH] refs #199 call-to-action and nav-panel are snapshot compatible --- dist/panels/call-to-action/module.js | 85 +++++++++++++++--------- dist/panels/call-to-action/module.js.map | 2 +- dist/panels/nav-panel/module.js | 16 ++++- dist/panels/nav-panel/module.js.map | 2 +- src/panels/call-to-action/module.js | 83 ++++++++++++++--------- src/panels/nav-panel/module.js | 15 ++++- 6 files changed, 135 insertions(+), 68 deletions(-) diff --git a/dist/panels/call-to-action/module.js b/dist/panels/call-to-action/module.js index 4098dff..0482c57 100644 --- a/dist/panels/call-to-action/module.js +++ b/dist/panels/call-to-action/module.js @@ -92,6 +92,7 @@ System.register(['lodash', 'app/plugins/sdk', '../../components/config/dsUpgrade _this.getOrgDetails(); _this.datasourceUpgrader = new DatasourceUpgrader(contextSrv, backendSrv, $q, datasourceSrv); + _this.panel.snapshotData = _this.panel.snapshotData || {}; return _this; } @@ -135,26 +136,37 @@ System.register(['lodash', 'app/plugins/sdk', '../../components/config/dsUpgrade key: 'getOrgDetails', value: function getOrgDetails() { var self = this; - var p = this.backendSrv.get('api/plugin-proxy/raintank-worldping-app/api/grafana-net/profile/org'); - p.then(function (resp) { - self.org = resp; - - var millionChecksPerMonth = Math.ceil(parseInt(self.org.checksPerMonth, 10) / 100000) / 10; - if (millionChecksPerMonth > 1000) { - self.org.strChecksPerMonth = 'using ' + Math.ceil(millionChecksPerMonth / 1000) + ' Billion checks/mo'; - } else if (millionChecksPerMonth > 0) { - self.org.strChecksPerMonth = 'using ' + millionChecksPerMonth + ' Million checks/mo'; - } else { - self.org.strChecksPerMonth = 'not using any checks yet'; - } - - self.requiresUpgrade = self._requiresUpgrade(); - self.currentlyTrial = self._currentlyTrial(); - self.aboveFreeTier = self._aboveFreeTier(); - }, function (resp) { - self.alertSrv.set("failed to get Org Details", resp.statusText, 'error', 10000); - }); - return p; + if (self.dashboard.snapshot) { + return this.onOrgDetails(self.panel.snapshotData.org); + } else { + var p = this.backendSrv.get('api/plugin-proxy/raintank-worldping-app/api/grafana-net/profile/org'); + p.then(function (resp) { + self.panel.snapshotData.org = resp; + self.onOrgDetails(resp); + }, function (resp) { + self.alertSrv.set("failed to get Org Details", resp.statusText, 'error', 10000); + }); + return p; + } + } + }, { + key: 'onOrgDetails', + value: function onOrgDetails(resp) { + var self = this; + self.org = resp; + + var millionChecksPerMonth = Math.ceil(parseInt(self.org.checksPerMonth, 10) / 100000) / 10; + if (millionChecksPerMonth > 1000) { + self.org.strChecksPerMonth = 'using ' + Math.ceil(millionChecksPerMonth / 1000) + ' Billion checks/mo'; + } else if (millionChecksPerMonth > 0) { + self.org.strChecksPerMonth = 'using ' + millionChecksPerMonth + ' Million checks/mo'; + } else { + self.org.strChecksPerMonth = 'not using any checks yet'; + } + + self.requiresUpgrade = self._requiresUpgrade(); + self.currentlyTrial = self._currentlyTrial(); + self.aboveFreeTier = self._aboveFreeTier(); } }, { key: '_currentlyTrial', @@ -218,19 +230,30 @@ System.register(['lodash', 'app/plugins/sdk', '../../components/config/dsUpgrade key: 'refresh', value: function refresh() { var self = this; - return this.backendSrv.get('api/plugin-proxy/raintank-worldping-app/api/v2/quotas').then(function (resp) { - if (resp.meta.code !== 200) { - self.alertSrv.set("failed to get quotas.", resp.meta.message, 'error', 10000); - return self.$q.reject(resp.meta.message); - } - var quotaHash = {}; - _.forEach(resp.body, function (q) { - quotaHash[q.target] = q; + if (self.dashboard.snapshot) { + return this.onQuotas(self.panel.snapshotData.quotas); + } else { + return this.backendSrv.get('api/plugin-proxy/raintank-worldping-app/api/v2/quotas').then(function (resp) { + self.panel.snapshotData.quotas = resp; + self.onQuotas(resp); }); - self.quotas = quotaHash; - self.setEndpointStatus(); - self.setCollectorStatus(); + } + } + }, { + key: 'onQuotas', + value: function onQuotas(resp) { + var self = this; + if (resp.meta.code !== 200) { + self.alertSrv.set("failed to get quotas.", resp.meta.message, 'error', 10000); + return self.$q.reject(resp.meta.message); + } + var quotaHash = {}; + _.forEach(resp.body, function (q) { + quotaHash[q.target] = q; }); + self.quotas = quotaHash; + self.setEndpointStatus(); + self.setCollectorStatus(); } }]); diff --git a/dist/panels/call-to-action/module.js.map b/dist/panels/call-to-action/module.js.map index 3326907..81884bc 100644 --- a/dist/panels/call-to-action/module.js.map +++ b/dist/panels/call-to-action/module.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../../src/panels/call-to-action/module.js"],"names":["_","PanelCtrl","loadPluginCss","DatasourceUpgrader","dark","light","CallToActionCtrl","$scope","$injector","$location","$q","backendSrv","alertSrv","contextSrv","datasourceSrv","quotas","endpointStatus","collectorStatus","requiresUpgrade","currentlyTrial","aboveFreeTier","getOrgDetails","datasourceUpgrader","endpoint","used","probe","self","p","get","then","resp","org","millionChecksPerMonth","Math","ceil","parseInt","checksPerMonth","strChecksPerMonth","_requiresUpgrade","_currentlyTrial","_aboveFreeTier","set","statusText","wpPlan","meta","code","message","reject","quotaHash","forEach","body","q","target","setEndpointStatus","setCollectorStatus","templateUrl"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAOA,O;;AACCC,e,kBAAAA,S;AACAC,mB,kBAAAA,a;;AACDC,wB;;;;;;;;;;;;;;;;;;;;;AAEPD,oBAAc;AACZE,cAAM,uDADM;AAEZC,eAAO;AAFK,OAAd;;2BAKMC,gB;;;AAEJ;AACA,kCAAYC,MAAZ,EAAoBC,SAApB,EAA+BC,SAA/B,EAA0CC,EAA1C,EAA8CC,UAA9C,EAA0DC,QAA1D,EAAoEC,UAApE,EAAgFC,aAAhF,EAA+F;AAAA;;AAAA,0IACvFP,MADuF,EAC/EC,SAD+E;;AAE7F,gBAAKG,UAAL,GAAkBA,UAAlB;AACA,gBAAKC,QAAL,GAAgBA,QAAhB;AACA,gBAAKH,SAAL,GAAiBA,SAAjB;AACA,gBAAKC,EAAL,GAAUA,EAAV;AACA,gBAAKI,aAAL,GA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BAAKX,MAAL,GAAciC,SAAd;AACAtB,mBAAK2B,iBAAL;AACA3B,mBAAK4B,kBAAL;AACD,aAZM,CAAP;AAaD;;;;QArJ4BrD,S;;AAwJ/BK,uBAAiBiD,WAAjB,GAA+B,yEAA/B;;2BAGEjD,gB","file":"module.js","sourcesContent":["import _ from 'lodash';\nimport {PanelCtrl} from 'app/plugins/sdk';\nimport {loadPluginCss} from 'app/plugins/sdk';\nimport DatasourceUpgrader from '../../components/config/dsUpgrade';\n\nloadPluginCss({\n dark: 'plugins/raintank-worldping-app/css/worldping.dark.css',\n light: 'plugins/raintank-worldping-app/css/worldping.light.css'\n});\n\nclass CallToActionCtrl extends PanelCtrl {\n\n /** @ngInject */\n constructor($scope, $injector, $location, $q, backendSrv, alertSrv, contextSrv, datasourceSrv) {\n super($scope, $injector);\n this.backendSrv = backendSrv;\n this.alertSrv = alertSrv;\n this.$location = $location;\n this.$q = $q;\n this.datasourceSrv = datasourceSrv;\n\n this.quotas = null;\n this.endpointStatus = \"scopeEndpoints\";\n this.collectorStatus = \"scopeCollectors\";\n this.requiresUpgrade = null;\n this.currentlyTrial = null;\n this.aboveFreeTier = null;\n\n this.getOrgDetails();\n this.datasourceUpgrader = new DatasourceUpgrader(contextSrv, backendSrv, $q, datasourceSrv);\n }\n\n setEndpointStatus() {\n if (! this.quotas) {\n return;\n }\n if (this.quotas.endpoint.used === 0) {\n this.endpointStatus = \"noEndpoints\";\n return;\n }\n if (this.quotas.endpoint.used >= 1) {\n this.endpointStatus = \"hasEndpoints\";\n return;\n }\n //default.\n this.endpointStatus = \"hasEndpoints\";\n return;\n }\n\n setCollectorStatus() {\n if (! this.quotas) {\n return;\n }\n if (this.quotas.probe.used === 0) {\n this.collectorStatus = \"noCollectors\";\n return;\n }\n if (this.quotas.probe.used >= 1) {\n this.collectorStatus = \"hasCollectors\";\n return;\n }\n //default.\n this.collectorStatus = \"hasCollectors\";\n return;\n }\n\n getOrgDetails() {\n var self = this;\n var p = this.backendSrv.get('api/plugin-proxy/raintank-worldping-app/api/grafana-net/profile/org');\n p.then((resp) => {\n self.org = resp;\n\n const millionChecksPerMonth = Math.ceil(parseInt(self.org.checksPerMonth, 10) / 100000) / 10;\n if (millionChecksPerMonth > 1000) {\n self.org.strChecksPerMonth = 'using ' + Math.ceil(millionChecksPerMonth / 1000) + ' Billion checks/mo';\n } else if (millionChecksPerMonth > 0) {\n self.org.strChecksPerMonth = 'using ' + millionChecksPerMonth + ' Million checks/mo';\n } else {\n self.org.strChecksPerMonth = 'not using any checks yet';\n }\n\n self.requiresUpgrade = self._requiresUpgrade();\n self.currentlyTrial = self._currentlyTrial();\n self.aboveFreeTier = self._aboveFreeTier();\n }, (resp) => {\n self.alertSrv.set(\"failed to get Org Details\", resp.statusText, 'error', 10000);\n });\n return p;\n }\n\n _currentlyTrial() {\n if (!this.org) {\n return false;\n }\n\n if (this.org.wpPlan === 'trial') {\n return true;\n }\n\n return false;\n }\n\n _requiresUpgrade() {\n if (!this.org) {\n return true;\n }\n\n if (this.org.wpPlan !== '' && this.org.wpPlan !== 'free' && this.org.wpPlan !== 'trial') {\n return false;\n }\n\n return true;\n }\n\n _aboveFreeTier() {\n if (!this.org) {\n return false;\n }\n\n if (this.org.wpPlan !== '' && this.org.wpPlan !== 'free') {\n return false;\n }\n\n if (this.org.checksPerMonth / 1000000 > 1) {\n return true;\n }\n\n return false;\n }\n\n allDone() {\n if (! this.quotas) {\n return false;\n }\n if (this.quotas.probe.used === 0) {\n return false;\n }\n if (this.quotas.endpoint.used === 0) {\n return false;\n }\n //default.\n return true;\n }\n\n refresh() {\n var self = this;\n return this.backendSrv.get('api/plugin-proxy/raintank-worldping-app/api/v2/quotas').then(function(resp) {\n if (resp.meta.code !== 200) {\n self.alertSrv.set(\"failed to get quotas.\", resp.meta.message, 'error', 10000);\n return self.$q.reject(resp.meta.message);\n }\n var quotaHash = {};\n _.forEach(resp.body, function(q) {\n quotaHash[q.target] = q;\n });\n self.quotas = quotaHash;\n self.setEndpointStatus();\n self.setCollectorStatus();\n });\n }\n}\n\nCallToActionCtrl.templateUrl = 'public/plugins/raintank-worldping-app/panels/call-to-action/module.html';\n\nexport {\n CallToActionCtrl as PanelCtrl\n};\n"]} \ No newline at end of file +{"version":3,"sources":["../../../src/panels/call-to-action/module.js"],"names":["_","PanelCtrl","loadPluginCss","DatasourceUpgrader","dark","light","CallToActionCtrl","$scope","$injector","$location","$q","backendSrv","alertSrv","contextSrv","datasourceSrv","quotas","endpointStatus","collectorStatus","requiresUpgrade","currentlyTrial","aboveFreeTier","getOrgDetails","datasourceUpgrader","panel","snapshotData","endpoint","used","probe","self","dashboard","snapshot","onOrgDetails","org","p","get","then","resp","set","statusText","millionChecksPerMonth","Math","ceil","parseInt","checksPerMonth","strChecksPerMonth","_requiresUpgrade","_currentlyTrial","_aboveFreeTier","wpPlan","onQuotas","meta","code","message","reject","quotaHash","forEach","body","q","target","setEndpointStatus","setCollectorStatus","templateUrl"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAOA,O;;AACCC,e,kBAAAA,S;AACAC,mB,kBAAAA,a;;AACDC,wB;;;;;;;;;;;;;;;;;;;;;AAEPD,oBAAc;AACZE,cAAM,uDADM;AAEZC,eAAO;AAFK,OAAd;;2BAKMC,gB;;;AAEJ;AACA,kCAAYC,MAAZ,EAAoBC,SAApB,EAA+BC,SAA/B,EAA0CC,EAA1C,EAA8CC,UAA9C,EAA0DC,QAA1D,EAAoEC,UAApE,EAAgFC,aAAhF,EAA+F;AAAA;;AAAA,0IACvFP,MADuF,EAC/EC,SAD+E;;AAE7F,gBAAKG,UAAL,GAAkBA,UAAlB;AACA,gBAAKC,QAAL,GAAgBA,QAAhB;AACA,gBAAKH,SAAL,GAAiBA,SAAjB;AACA,gBAAKC,EAAL,GAAUA,EAAV;AACA,gBAAKI,aAAL,GAAqBA,aAArB;;AAEA,gBAAKC,MAAL,GAAc,IAAd;AACA,gBAAKC,cAAL,GAAsB,gBAAtB;AACA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CAAkF,UAASC,IAAT,EAAe;AACtGR,qBAAKL,KAAL,CAAWC,YAAX,CAAwBT,MAAxB,GAAiCqB,IAAjC;AACAR,qBAAKqB,QAAL,CAAcb,IAAd;AACD,eAHM,CAAP;AAID;AACF;;;mCAEQA,I,EAAM;AACb,gBAAIR,OAAO,IAAX;AACA,gBAAIQ,KAAKc,IAAL,CAAUC,IAAV,KAAmB,GAAvB,EAA4B;AAC1BvB,mBAAKhB,QAAL,CAAcyB,GAAd,CAAkB,uBAAlB,EAA2CD,KAAKc,IAAL,CAAUE,OAArD,EAA8D,OAA9D,EAAuE,KAAvE;AACA,qBAAOxB,KAAKlB,EAAL,CAAQ2C,MAAR,CAAejB,KAAKc,IAAL,CAAUE,OAAzB,CAAP;AACD;AACD,gBAAIE,YAAY,EAAhB;AACAtD,cAAEuD,OAAF,CAAUnB,KAAKoB,IAAf,EAAqB,UAASC,CAAT,EAAY;AAC/BH,wBAAUG,EAAEC,MAAZ,IAAsBD,CAAtB;AACD,aAFD;AAGA7B,iBAAKb,MAAL,GAAcuC,SAAd;AACA1B,iBAAK+B,iBAAL;AACA/B,iBAAKgC,kBAAL;AACD;;;;QA1K4B3D,S;;AA6K/BK,uBAAiBuD,WAAjB,GAA+B,yEAA/B;;2BAGEvD,gB","file":"module.js","sourcesContent":["import _ from 'lodash';\nimport {PanelCtrl} from 'app/plugins/sdk';\nimport {loadPluginCss} from 'app/plugins/sdk';\nimport DatasourceUpgrader from '../../components/config/dsUpgrade';\n\nloadPluginCss({\n dark: 'plugins/raintank-worldping-app/css/worldping.dark.css',\n light: 'plugins/raintank-worldping-app/css/worldping.light.css'\n});\n\nclass CallToActionCtrl extends PanelCtrl {\n\n /** @ngInject */\n constructor($scope, $injector, $location, $q, backendSrv, alertSrv, contextSrv, datasourceSrv) {\n super($scope, $injector);\n this.backendSrv = backendSrv;\n this.alertSrv = alertSrv;\n this.$location = $location;\n this.$q = $q;\n this.datasourceSrv = datasourceSrv;\n\n this.quotas = null;\n this.endpointStatus = \"scopeEndpoints\";\n this.collectorStatus = \"scopeCollectors\";\n this.requiresUpgrade = null;\n this.currentlyTrial = null;\n this.aboveFreeTier = null;\n\n this.getOrgDetails();\n this.datasourceUpgrader = new DatasourceUpgrader(contextSrv, backendSrv, $q, datasourceSrv);\n this.panel.snapshotData = this.panel.snapshotData || {};\n }\n\n setEndpointStatus() {\n if (! this.quotas) {\n return;\n }\n if (this.quotas.endpoint.used === 0) {\n this.endpointStatus = \"noEndpoints\";\n return;\n }\n if (this.quotas.endpoint.used >= 1) {\n this.endpointStatus = \"hasEndpoints\";\n return;\n }\n //default.\n this.endpointStatus = \"hasEndpoints\";\n return;\n }\n\n setCollectorStatus() {\n if (! this.quotas) {\n return;\n }\n if (this.quotas.probe.used === 0) {\n this.collectorStatus = \"noCollectors\";\n return;\n }\n if (this.quotas.probe.used >= 1) {\n this.collectorStatus = \"hasCollectors\";\n return;\n }\n //default.\n this.collectorStatus = \"hasCollectors\";\n return;\n }\n\n getOrgDetails() {\n var self = this;\n if(self.dashboard.snapshot){\n return this.onOrgDetails(self.panel.snapshotData.org);\n } else {\n var p = this.backendSrv.get('api/plugin-proxy/raintank-worldping-app/api/grafana-net/profile/org');\n p.then((resp) => {\n self.panel.snapshotData.org = resp;\n self.onOrgDetails(resp);\n }, (resp) => {\n self.alertSrv.set(\"failed to get Org Details\", resp.statusText, 'error', 10000);\n });\n return p;\n }\n }\n\n onOrgDetails(resp) {\n var self = this;\n self.org = resp;\n\n const millionChecksPerMonth = Math.ceil(parseInt(self.org.checksPerMonth, 10) / 100000) / 10;\n if (millionChecksPerMonth > 1000) {\n self.org.strChecksPerMonth = 'using ' + Math.ceil(millionChecksPerMonth / 1000) + ' Billion checks/mo';\n } else if (millionChecksPerMonth > 0) {\n self.org.strChecksPerMonth = 'using ' + millionChecksPerMonth + ' Million checks/mo';\n } else {\n self.org.strChecksPerMonth = 'not using any checks yet';\n }\n\n self.requiresUpgrade = self._requiresUpgrade();\n self.currentlyTrial = self._currentlyTrial();\n self.aboveFreeTier = self._aboveFreeTier();\n }\n\n _currentlyTrial() {\n if (!this.org) {\n return false;\n }\n\n if (this.org.wpPlan === 'trial') {\n return true;\n }\n\n return false;\n }\n\n _requiresUpgrade() {\n if (!this.org) {\n return true;\n }\n\n if (this.org.wpPlan !== '' && this.org.wpPlan !== 'free' && this.org.wpPlan !== 'trial') {\n return false;\n }\n\n return true;\n }\n\n _aboveFreeTier() {\n if (!this.org) {\n return false;\n }\n\n if (this.org.wpPlan !== '' && this.org.wpPlan !== 'free') {\n return false;\n }\n\n if (this.org.checksPerMonth / 1000000 > 1) {\n return true;\n }\n\n return false;\n }\n\n allDone() {\n if (! this.quotas) {\n return false;\n }\n if (this.quotas.probe.used === 0) {\n return false;\n }\n if (this.quotas.endpoint.used === 0) {\n return false;\n }\n //default.\n return true;\n }\n\n refresh() {\n var self = this;\n if(self.dashboard.snapshot){\n return this.onQuotas(self.panel.snapshotData.quotas);\n } else {\n return this.backendSrv.get('api/plugin-proxy/raintank-worldping-app/api/v2/quotas').then(function(resp) {\n self.panel.snapshotData.quotas = resp;\n self.onQuotas(resp);\n });\n }\n }\n\n onQuotas(resp) {\n var self = this;\n if (resp.meta.code !== 200) {\n self.alertSrv.set(\"failed to get quotas.\", resp.meta.message, 'error', 10000);\n return self.$q.reject(resp.meta.message);\n }\n var quotaHash = {};\n _.forEach(resp.body, function(q) {\n quotaHash[q.target] = q;\n });\n self.quotas = quotaHash;\n self.setEndpointStatus();\n self.setCollectorStatus();\n }\n}\n\nCallToActionCtrl.templateUrl = 'public/plugins/raintank-worldping-app/panels/call-to-action/module.html';\n\nexport {\n CallToActionCtrl as PanelCtrl\n};\n"]} \ No newline at end of file diff --git a/dist/panels/nav-panel/module.js b/dist/panels/nav-panel/module.js index 261dac7..31e69d0 100644 --- a/dist/panels/nav-panel/module.js +++ b/dist/panels/nav-panel/module.js @@ -126,8 +126,19 @@ System.register(['lodash', '../../filters/all', '../../directives/all', 'app/plu }, { key: 'refresh', value: function refresh() { - var endpointSlugs = this.getEndpointSlugs(); - this.getEndpoints(endpointSlugs); + if (this.dashboard.snapshot) { + this.getEndpointsFromSnapshot(); + } else { + var endpointSlugs = this.getEndpointSlugs(); + this.getEndpoints(endpointSlugs); + } + } + }, { + key: 'getEndpointsFromSnapshot', + value: function getEndpointsFromSnapshot() { + var self = this; + self.panel.snapshotData = self.endpoints; + self.pageReady = true; } }, { key: 'getEndpoints', @@ -145,6 +156,7 @@ System.register(['lodash', '../../filters/all', '../../directives/all', 'app/plu self.endpoints.push(endpoint); } }); + self.panel.snapshotData = self.endpoints; self.pageReady = true; }); } diff --git a/dist/panels/nav-panel/module.js.map b/dist/panels/nav-panel/module.js.map index b0a2299..c981a45 100644 --- a/dist/panels/nav-panel/module.js.map +++ b/dist/panels/nav-panel/module.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../../src/panels/nav-panel/module.js"],"names":["_","PanelCtrl","loadPluginCss","DatasourceUpgrader","dark","light","EndpointNavCtrl","$scope","$injector","$location","$q","backendSrv","templateSrv","alertSrv","contextSrv","datasourceSrv","endpointSlugs","ctrl","panel","title","transparent","pageReady","statuses","label","value","endpoints","endpointState","datasourceUpgrader","values","forEach","variables","tmplVar","name","current","isArray","getEndpointSlugs","getEndpoints","self","get","then","resp","meta","code","set","message","reject","isGoogleDemo","length","body","endpoint","indexOf","slug","push","type","check","checks","c","toLowerCase","enabled","state","states","duration","Date","getTime","stateChange","secs","Math","floor","mins","hours","days","search","path","id","templateUrl"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAOA,O;;AAGCC,e,kBAAAA,S;AACAC,mB,kBAAAA,a;;AACDC,wB;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEPD,oBAAc;AACZE,cAAM,uDADM;AAEZC,eAAO;AAFK,OAAd;;2BAKMC,e;;;AAEJ;AACA,iCAAYC,MAAZ,EAAoBC,SAApB,EAA+BC,SAA/B,EAA0CC,EAA1C,EAA8CC,UAA9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q,EAAU;AACxB,iBAAKxC,SAAL,CAAe+D,IAAf,CAAoB,mEAAkEvB,SAASwB,EAA/F;AACD;;;;QA3J2BxE,S;;AA8J9BK,sBAAgBoE,WAAhB,GAA8B,oEAA9B;;2BAEEpE,e","file":"module.js","sourcesContent":["import _ from 'lodash';\nimport '../../filters/all';\nimport '../../directives/all';\nimport {PanelCtrl} from 'app/plugins/sdk';\nimport {loadPluginCss} from 'app/plugins/sdk';\nimport DatasourceUpgrader from '../../components/config/dsUpgrade';\n\nloadPluginCss({\n dark: 'plugins/raintank-worldping-app/css/worldping.dark.css',\n light: 'plugins/raintank-worldping-app/css/worldping.light.css'\n});\n\nclass EndpointNavCtrl extends PanelCtrl {\n\n /** @ngInject */\n constructor($scope, $injector, $location, $q, backendSrv, templateSrv, alertSrv, contextSrv, datasourceSrv) {\n super($scope, $injector);\n this.$location = $location;\n this.$q = $q;\n this.backendSrv = backendSrv;\n this.templateSrv = templateSrv;\n this.datasourceSrv = datasourceSrv;\n this.alertSrv = alertSrv;\n this.endpointSlugs = [];\n\n $scope.ctrl.panel.title = \"\";\n $scope.ctrl.panel.transparent = true;\n\n this.pageReady = false;\n this.statuses = [\n {label: \"Ok\", value: 0},\n {label: \"Warning\", value: 1},\n {label: \"Error\", value: 2},\n {label: \"Unknown\", value: -1},\n ];\n this.endpoints = [];\n this.endpointState = {\n \"0\": 0,\n \"1\": 0,\n \"2\": 0,\n \"-1\": 0,\n };\n this.datasourceUpgrader = new DatasourceUpgrader(contextSrv, backendSrv, $q, datasourceSrv);\n }\n\n getEndpointSlugs() {\n var values = null;\n _.forEach(this.templateSrv.variables, function(tmplVar) {\n if (tmplVar.name === 'endpoint') {\n values = tmplVar.current.value;\n if (!_.isArray(values)) {\n values = [values];\n }\n values;\n }\n });\n this.endpointSlugs = values;\n return values;\n }\n\n refresh() {\n var endpointSlugs = this.getEndpointSlugs();\n this.getEndpoints(endpointSlugs);\n }\n\n getEndpoints(endpointSlugs) {\n var self = this;\n this.backendSrv.get('api/plugin-proxy/raintank-worldping-app/api/v2/endpoints').then((resp) => {\n if (resp.meta.code !== 200) {\n self.alertSrv.set(\"failed to get endpoint list.\", resp.meta.message, 'error', 10000);\n return self.$q.reject(resp.meta.message);\n }\n self.endpoints = [];\n self.isGoogleDemo = endpointSlugs.length === 1 && endpointSlugs[0] === '~google_com_demo';\n _.forEach(resp.body, function(endpoint) {\n if (_.indexOf(endpointSlugs, endpoint.slug) >= 0) {\n self.endpoints.push(endpoint);\n }\n });\n self.pageReady = true;\n });\n }\n\n monitorStateTxt(endpoint, type) {\n var check;\n _.forEach(endpoint.checks, function(c) {\n if (c.type.toLowerCase() === type.toLowerCase()) {\n check = c;\n }\n });\n if (typeof(check) !== \"object\") {\n return \"disabled\";\n }\n if (!check.enabled) {\n return \"disabled\";\n }\n if (check.state < 0 || check.state > 2) {\n return 'nodata';\n }\n var states = [\"online\", \"warn\", \"critical\"];\n return states[check.state];\n }\n\n monitorStateChangeStr(endpoint, type) {\n var check;\n _.forEach(endpoint.checks, function(c) {\n if (c.type.toLowerCase() === type.toLowerCase()) {\n check = c;\n }\n });\n if (typeof(check) !== \"object\") {\n return \"\";\n }\n var duration = new Date().getTime() - new Date(check.stateChange).getTime();\n if (duration < 10000) {\n return \"for a few seconds ago\";\n }\n if (duration < 60000) {\n var secs = Math.floor(duration/1000);\n return \"for \" + secs + \" seconds\";\n }\n if (duration < 3600000) {\n var mins = Math.floor(duration/1000/60);\n return \"for \" + mins + \" minutes\";\n }\n if (duration < 86400000) {\n var hours = Math.floor(duration/1000/60/60);\n return \"for \" + hours + \" hours\";\n }\n var days = Math.floor(duration/1000/60/60/24);\n return \"for \" + days + \" days\";\n }\n\n gotoDashboard(endpoint, type) {\n if (!type) {\n type = 'summary';\n }\n var search = {\n \"var-collector\": \"All\",\n \"var-endpoint\": endpoint.slug\n };\n switch(type) {\n case \"summary\":\n this.$location.path(\"/dashboard/db/worldping-endpoint-summary\").search(search);\n break;\n case \"ping\":\n this.$location.path(\"/dashboard/db/worldping-endpoint-ping\").search(search);\n break;\n case \"dns\":\n this.$location.path(\"/dashboard/db/worldping-endpoint-dns\").search(search);\n break;\n case \"http\":\n search['var-protocol'] = \"http\";\n this.$location.path(\"/dashboard/db/worldping-endpoint-web\").search(search);\n break;\n case \"https\":\n search['var-protocol'] = \"https\";\n this.$location.path(\"/dashboard/db/worldping-endpoint-web\").search(search);\n break;\n default:\n this.$location.path(\"/dashboard/db/worldping-endpoint-summary\").search(search);\n break;\n }\n }\n\n gotoEndpointURL(endpoint) {\n this.$location.path('plugins/raintank-worldping-app/page/endpoint-details?endpoint='+ endpoint.id);\n }\n}\n\nEndpointNavCtrl.templateUrl = 'public/plugins/raintank-worldping-app/panels/nav-panel/module.html';\nexport {\n EndpointNavCtrl as PanelCtrl\n};\n"]} \ No newline at end of file +{"version":3,"sources":["../../../src/panels/nav-panel/module.js"],"names":["_","PanelCtrl","loadPluginCss","DatasourceUpgrader","dark","light","EndpointNavCtrl","$scope","$injector","$location","$q","backendSrv","templateSrv","alertSrv","contextSrv","datasourceSrv","endpointSlugs","ctrl","panel","title","transparent","pageReady","statuses","label","value","endpoints","endpointState","datasourceUpgrader","values","forEach","variables","tmplVar","name","current","isArray","dashboard","snapshot","getEndpointsFromSnapshot","getEndpointSlugs","getEndpoints","self","snapshotData","get","then","resp","meta","code","set","message","reject","isGoogleDemo","length","body","endpoint","indexOf","slug","push","type","check","checks","c","toLowerCase","enabled","state","states","duration","Date","getTime","stateChange","secs","Math","floor","mins","hours","days","search","path","id","templateUrl"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAOA,O;;AAGCC,e,kBAAAA,S;AACAC,mB,kBAAAA,a;;AACDC,wB;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEPD,oBAAc;AACZE,cAAM,uDADM;AAEZC,eAAO;AAFK,OAAd;;2BAKMC,e;;;AAEJ;AACA,iCAAYC,MAAZ,EAAoBC,SAApB,EAA+BC,SAA/B,EAA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AAoB,sCAApB,EAA4DD,MAA5D,CAAmEA,MAAnE;AACA;AACF,mBAAK,OAAL;AACEA,uBAAO,cAAP,IAAyB,OAAzB;AACA,qBAAKlE,SAAL,CAAemE,IAAf,CAAoB,sCAApB,EAA4DD,MAA5D,CAAmEA,MAAnE;AACA;AACF;AACE,qBAAKlE,SAAL,CAAemE,IAAf,CAAoB,0CAApB,EAAgED,MAAhE,CAAuEA,MAAvE;AACA;AApBJ;AAsBD;;;0CAEetB,Q,EAAU;AACxB,iBAAK5C,SAAL,CAAemE,IAAf,CAAoB,mEAAkEvB,SAASwB,EAA/F;AACD;;;;QAtK2B5E,S;;AAyK9BK,sBAAgBwE,WAAhB,GAA8B,oEAA9B;;2BAEExE,e","file":"module.js","sourcesContent":["import _ from 'lodash';\nimport '../../filters/all';\nimport '../../directives/all';\nimport {PanelCtrl} from 'app/plugins/sdk';\nimport {loadPluginCss} from 'app/plugins/sdk';\nimport DatasourceUpgrader from '../../components/config/dsUpgrade';\n\nloadPluginCss({\n dark: 'plugins/raintank-worldping-app/css/worldping.dark.css',\n light: 'plugins/raintank-worldping-app/css/worldping.light.css'\n});\n\nclass EndpointNavCtrl extends PanelCtrl {\n\n /** @ngInject */\n constructor($scope, $injector, $location, $q, backendSrv, templateSrv, alertSrv, contextSrv, datasourceSrv) {\n super($scope, $injector);\n this.$location = $location;\n this.$q = $q;\n this.backendSrv = backendSrv;\n this.templateSrv = templateSrv;\n this.datasourceSrv = datasourceSrv;\n this.alertSrv = alertSrv;\n this.endpointSlugs = [];\n\n $scope.ctrl.panel.title = \"\";\n $scope.ctrl.panel.transparent = true;\n\n this.pageReady = false;\n this.statuses = [\n {label: \"Ok\", value: 0},\n {label: \"Warning\", value: 1},\n {label: \"Error\", value: 2},\n {label: \"Unknown\", value: -1},\n ];\n this.endpoints = [];\n this.endpointState = {\n \"0\": 0,\n \"1\": 0,\n \"2\": 0,\n \"-1\": 0,\n };\n this.datasourceUpgrader = new DatasourceUpgrader(contextSrv, backendSrv, $q, datasourceSrv);\n }\n\n getEndpointSlugs() {\n var values = null;\n _.forEach(this.templateSrv.variables, function(tmplVar) {\n if (tmplVar.name === 'endpoint') {\n values = tmplVar.current.value;\n if (!_.isArray(values)) {\n values = [values];\n }\n values;\n }\n });\n this.endpointSlugs = values;\n return values;\n }\n\n refresh() {\n if(this.dashboard.snapshot){\n this.getEndpointsFromSnapshot();\n } else {\n var endpointSlugs = this.getEndpointSlugs();\n this.getEndpoints(endpointSlugs);\n }\n }\n\n getEndpointsFromSnapshot() {\n var self = this;\n self.panel.snapshotData = self.endpoints;\n self.pageReady = true;\n }\n\n getEndpoints(endpointSlugs) {\n var self = this;\n this.backendSrv.get('api/plugin-proxy/raintank-worldping-app/api/v2/endpoints').then((resp) => {\n if (resp.meta.code !== 200) {\n self.alertSrv.set(\"failed to get endpoint list.\", resp.meta.message, 'error', 10000);\n return self.$q.reject(resp.meta.message);\n }\n self.endpoints = [];\n self.isGoogleDemo = endpointSlugs.length === 1 && endpointSlugs[0] === '~google_com_demo';\n _.forEach(resp.body, function(endpoint) {\n if (_.indexOf(endpointSlugs, endpoint.slug) >= 0) {\n self.endpoints.push(endpoint);\n }\n });\n self.panel.snapshotData = self.endpoints;\n self.pageReady = true;\n });\n }\n\n monitorStateTxt(endpoint, type) {\n var check;\n _.forEach(endpoint.checks, function(c) {\n if (c.type.toLowerCase() === type.toLowerCase()) {\n check = c;\n }\n });\n if (typeof(check) !== \"object\") {\n return \"disabled\";\n }\n if (!check.enabled) {\n return \"disabled\";\n }\n if (check.state < 0 || check.state > 2) {\n return 'nodata';\n }\n var states = [\"online\", \"warn\", \"critical\"];\n return states[check.state];\n }\n\n monitorStateChangeStr(endpoint, type) {\n var check;\n _.forEach(endpoint.checks, function(c) {\n if (c.type.toLowerCase() === type.toLowerCase()) {\n check = c;\n }\n });\n if (typeof(check) !== \"object\") {\n return \"\";\n }\n var duration = new Date().getTime() - new Date(check.stateChange).getTime();\n if (duration < 10000) {\n return \"for a few seconds ago\";\n }\n if (duration < 60000) {\n var secs = Math.floor(duration/1000);\n return \"for \" + secs + \" seconds\";\n }\n if (duration < 3600000) {\n var mins = Math.floor(duration/1000/60);\n return \"for \" + mins + \" minutes\";\n }\n if (duration < 86400000) {\n var hours = Math.floor(duration/1000/60/60);\n return \"for \" + hours + \" hours\";\n }\n var days = Math.floor(duration/1000/60/60/24);\n return \"for \" + days + \" days\";\n }\n\n gotoDashboard(endpoint, type) {\n if (!type) {\n type = 'summary';\n }\n var search = {\n \"var-collector\": \"All\",\n \"var-endpoint\": endpoint.slug\n };\n switch(type) {\n case \"summary\":\n this.$location.path(\"/dashboard/db/worldping-endpoint-summary\").search(search);\n break;\n case \"ping\":\n this.$location.path(\"/dashboard/db/worldping-endpoint-ping\").search(search);\n break;\n case \"dns\":\n this.$location.path(\"/dashboard/db/worldping-endpoint-dns\").search(search);\n break;\n case \"http\":\n search['var-protocol'] = \"http\";\n this.$location.path(\"/dashboard/db/worldping-endpoint-web\").search(search);\n break;\n case \"https\":\n search['var-protocol'] = \"https\";\n this.$location.path(\"/dashboard/db/worldping-endpoint-web\").search(search);\n break;\n default:\n this.$location.path(\"/dashboard/db/worldping-endpoint-summary\").search(search);\n break;\n }\n }\n\n gotoEndpointURL(endpoint) {\n this.$location.path('plugins/raintank-worldping-app/page/endpoint-details?endpoint='+ endpoint.id);\n }\n}\n\nEndpointNavCtrl.templateUrl = 'public/plugins/raintank-worldping-app/panels/nav-panel/module.html';\nexport {\n EndpointNavCtrl as PanelCtrl\n};\n"]} \ No newline at end of file diff --git a/src/panels/call-to-action/module.js b/src/panels/call-to-action/module.js index 4f9f71c..7b8ac78 100644 --- a/src/panels/call-to-action/module.js +++ b/src/panels/call-to-action/module.js @@ -28,6 +28,7 @@ class CallToActionCtrl extends PanelCtrl { this.getOrgDetails(); this.datasourceUpgrader = new DatasourceUpgrader(contextSrv, backendSrv, $q, datasourceSrv); + this.panel.snapshotData = this.panel.snapshotData || {}; } setEndpointStatus() { @@ -66,26 +67,36 @@ class CallToActionCtrl extends PanelCtrl { getOrgDetails() { var self = this; - var p = this.backendSrv.get('api/plugin-proxy/raintank-worldping-app/api/grafana-net/profile/org'); - p.then((resp) => { - self.org = resp; - - const millionChecksPerMonth = Math.ceil(parseInt(self.org.checksPerMonth, 10) / 100000) / 10; - if (millionChecksPerMonth > 1000) { - self.org.strChecksPerMonth = 'using ' + Math.ceil(millionChecksPerMonth / 1000) + ' Billion checks/mo'; - } else if (millionChecksPerMonth > 0) { - self.org.strChecksPerMonth = 'using ' + millionChecksPerMonth + ' Million checks/mo'; - } else { - self.org.strChecksPerMonth = 'not using any checks yet'; - } - - self.requiresUpgrade = self._requiresUpgrade(); - self.currentlyTrial = self._currentlyTrial(); - self.aboveFreeTier = self._aboveFreeTier(); - }, (resp) => { - self.alertSrv.set("failed to get Org Details", resp.statusText, 'error', 10000); - }); - return p; + if(self.dashboard.snapshot){ + return this.onOrgDetails(self.panel.snapshotData.org); + } else { + var p = this.backendSrv.get('api/plugin-proxy/raintank-worldping-app/api/grafana-net/profile/org'); + p.then((resp) => { + self.panel.snapshotData.org = resp; + self.onOrgDetails(resp); + }, (resp) => { + self.alertSrv.set("failed to get Org Details", resp.statusText, 'error', 10000); + }); + return p; + } + } + + onOrgDetails(resp) { + var self = this; + self.org = resp; + + const millionChecksPerMonth = Math.ceil(parseInt(self.org.checksPerMonth, 10) / 100000) / 10; + if (millionChecksPerMonth > 1000) { + self.org.strChecksPerMonth = 'using ' + Math.ceil(millionChecksPerMonth / 1000) + ' Billion checks/mo'; + } else if (millionChecksPerMonth > 0) { + self.org.strChecksPerMonth = 'using ' + millionChecksPerMonth + ' Million checks/mo'; + } else { + self.org.strChecksPerMonth = 'not using any checks yet'; + } + + self.requiresUpgrade = self._requiresUpgrade(); + self.currentlyTrial = self._currentlyTrial(); + self.aboveFreeTier = self._aboveFreeTier(); } _currentlyTrial() { @@ -144,19 +155,29 @@ class CallToActionCtrl extends PanelCtrl { refresh() { var self = this; - return this.backendSrv.get('api/plugin-proxy/raintank-worldping-app/api/v2/quotas').then(function(resp) { - if (resp.meta.code !== 200) { - self.alertSrv.set("failed to get quotas.", resp.meta.message, 'error', 10000); - return self.$q.reject(resp.meta.message); - } - var quotaHash = {}; - _.forEach(resp.body, function(q) { - quotaHash[q.target] = q; + if(self.dashboard.snapshot){ + return this.onQuotas(self.panel.snapshotData.quotas); + } else { + return this.backendSrv.get('api/plugin-proxy/raintank-worldping-app/api/v2/quotas').then(function(resp) { + self.panel.snapshotData.quotas = resp; + self.onQuotas(resp); }); - self.quotas = quotaHash; - self.setEndpointStatus(); - self.setCollectorStatus(); + } + } + + onQuotas(resp) { + var self = this; + if (resp.meta.code !== 200) { + self.alertSrv.set("failed to get quotas.", resp.meta.message, 'error', 10000); + return self.$q.reject(resp.meta.message); + } + var quotaHash = {}; + _.forEach(resp.body, function(q) { + quotaHash[q.target] = q; }); + self.quotas = quotaHash; + self.setEndpointStatus(); + self.setCollectorStatus(); } } diff --git a/src/panels/nav-panel/module.js b/src/panels/nav-panel/module.js index c42e2a7..6612e0f 100644 --- a/src/panels/nav-panel/module.js +++ b/src/panels/nav-panel/module.js @@ -59,8 +59,18 @@ class EndpointNavCtrl extends PanelCtrl { } refresh() { - var endpointSlugs = this.getEndpointSlugs(); - this.getEndpoints(endpointSlugs); + if(this.dashboard.snapshot){ + this.getEndpointsFromSnapshot(); + } else { + var endpointSlugs = this.getEndpointSlugs(); + this.getEndpoints(endpointSlugs); + } + } + + getEndpointsFromSnapshot() { + var self = this; + self.panel.snapshotData = self.endpoints; + self.pageReady = true; } getEndpoints(endpointSlugs) { @@ -77,6 +87,7 @@ class EndpointNavCtrl extends PanelCtrl { self.endpoints.push(endpoint); } }); + self.panel.snapshotData = self.endpoints; self.pageReady = true; }); }