From 0a40e2cedd25187545044c2eba96f74779b69f66 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 9 May 2020 02:13:28 +0200 Subject: [PATCH 1/3] Support for headers both as function/object and replaced moment with dateTime --- src/module.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/module.ts b/src/module.ts index fb0fd79..b70221b 100644 --- a/src/module.ts +++ b/src/module.ts @@ -2,7 +2,7 @@ import { MetricsPanelCtrl } from 'grafana/app/plugins/sdk'; import $ from 'jquery'; import _ from 'lodash'; import appEvents from 'grafana/app/core/app_events'; -import moment from 'moment'; +import dateTime from '@grafana/data'; import './style.css'; import { DSInfo, RenderMode } from './types'; import { examples } from './examples'; @@ -473,6 +473,14 @@ class AjaxCtrl extends MetricsPanelCtrl { } process(rsp: any) { + const headers = (key: any) => { + if (typeof rsp.headers === 'function') { + return key != null ? rsp.headers(key) : rsp.headers(); + } + + return key != null ? rsp.headers[key] : rsp.headers; + }; + if (this.panel.showTime) { let txt: string = this.panel.showTimePrefix ? this.panel.showTimePrefix : ''; if (this.panel.showTimeValue) { @@ -483,20 +491,20 @@ class AjaxCtrl extends MetricsPanelCtrl { when = Date.now(); } else if (this.panel.showTimeValue.startsWith('header-')) { const h = this.panel.showTimeValue.substring('header-'.length); - const v = rsp.headers[h]; + const v = headers(h); if (v) { console.log('TODO, parse header', v, h); } else { const vals: any = {}; - for (const key in rsp.headers()) { - vals[key] = rsp.headers[key]; + for (const key in headers()) { + vals[key] = headers(key); } console.log('Header:', h, 'not found in:', vals, rsp); } } if (when) { - txt += moment(when).format(this.panel.showTimeFormat); + txt += dateTime(when).format(this.panel.showTimeFormat); } else { txt += 'missing: ' + this.panel.showTimeValue; } From 50618665ddf365ed843cb1854b368bb930e5960c Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Thu, 16 Sep 2021 12:03:42 -0700 Subject: [PATCH 2/3] update --- src/examples.ts | 6 +++++- src/module.ts | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/examples.ts b/src/examples.ts index 7d3663d..ed057b3 100644 --- a/src/examples.ts +++ b/src/examples.ts @@ -123,7 +123,11 @@ export const examples = [ url: 'https://httpbin.org/basic-auth/user/pass', withCredentials: true, params_js: '{}', - header_js: '{\n' + " Authorization: 'Basic ' + btoa('user' + ':' + 'pass')\n" + "// Authorization: 'Basic dXNlcjpwYXNz'\n" + '}', + header_js: + '{\n' + + " Authorization: 'Basic ' + btoa('user' + ':' + 'pass')\n" + + "// Authorization: 'Basic dXNlcjpwYXNz'\n" + + '}', }, }, { diff --git a/src/module.ts b/src/module.ts index b70221b..88a60a0 100644 --- a/src/module.ts +++ b/src/module.ts @@ -2,12 +2,11 @@ import { MetricsPanelCtrl } from 'grafana/app/plugins/sdk'; import $ from 'jquery'; import _ from 'lodash'; import appEvents from 'grafana/app/core/app_events'; -import dateTime from '@grafana/data'; import './style.css'; import { DSInfo, RenderMode } from './types'; import { examples } from './examples'; -import { DataQueryResponse, DataSourceApi } from '@grafana/data'; +import { DataQueryResponse, DataSourceApi, dateTime } from '@grafana/data'; class AjaxCtrl extends MetricsPanelCtrl { static templateUrl = 'partials/module.html'; From 964afd53104f4c9e3c03cfe1a99b3427c6620e20 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Thu, 16 Sep 2021 12:05:38 -0700 Subject: [PATCH 3/3] update --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d34513d --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Change Log + +## [0.0.7-dev] + +- Updating dependencies \ No newline at end of file