Browse Source

ds ui++

master
Coin de Gamma 6 years ago
parent
commit
82875bb7c0
  1. 11
      src/datasource/module.ts
  2. 4
      src/datasource/partials/config.html
  3. 17
      src/utlis.ts

11
src/datasource/module.ts

@ -8,7 +8,7 @@ import configTemplate from './partials/config.html';
class HasticConfigCtrl { class HasticConfigCtrl {
public static template = configTemplate; public static template = configTemplate;
public ACCESS_OPTIONS: any[] = [ public ACCESS_OPTIONS = [
{ key: 'proxy', value: 'Server (Default)' }, { key: 'proxy', value: 'Server (Default)' },
{ key: 'direct', value: 'Browser'} { key: 'direct', value: 'Browser'}
]; ];
@ -16,13 +16,14 @@ class HasticConfigCtrl {
public current: any; public current: any;
private showAccessHelp: boolean = false; private showAccessHelp: boolean = false;
constructor($scope) { constructor(private $scope) {
this.current.access = 'proxy';
console.log($scope);
} }
normalizeUrl() { normalizeUrl() {
this.current.url = normalizeUrl(this.current.url); if(this.$scope.current.url === "") {
return;
}
this.$scope.current.url = normalizeUrl(this.$scope.current.url);
} }
toggleAccessHelp() { toggleAccessHelp() {

4
src/datasource/partials/config.html

@ -14,7 +14,7 @@
ng-blur="ctrl.normalizeUrl()" ng-blur="ctrl.normalizeUrl()"
/> />
<info-popover mode="right-absolute"> <info-popover mode="right-absolute">
<p>Specify a complete Hastic Server HTTP URL (for example http://your_hastic_server:8080)</p> <p>Specify a complete Hastic Server HTTP URL (for example http://your_hastic_server:8000)</p>
<span ng-show="current.access === 'direct'"> <span ng-show="current.access === 'direct'">
Your access method is <em>Browser</em>, this means the URL Your access method is <em>Browser</em>, this means the URL
needs to be accessible from the browser. needs to be accessible from the browser.
@ -34,7 +34,7 @@
<select <select
class="gf-form-input" class="gf-form-input"
ng-model="current.access" ng-model="current.access"
ng-options="f.key as f.value for f in ctrl.accessOptions" ng-options="f.key as f.value for f in ctrl.ACCESS_OPTIONS"
/> />
</div> </div>
</div> </div>

17
src/utlis.ts

@ -1,14 +1,15 @@
import url from 'url-parse'; import url from 'url-parse';
export function normalizeUrl(grafanaUrl: string) {
if(!grafanaUrl) { export function normalizeUrl(inputUrl: string) {
return grafanaUrl; if(!inputUrl) {
return inputUrl;
} }
let urlObj = new url(grafanaUrl, {}); let urlObj = new url(inputUrl, {});
if(urlObj.protocol !== 'http:' && urlObj.protocol !== 'https:') { if(urlObj.protocol !== 'http:' && urlObj.protocol !== 'https:') {
grafanaUrl = `http://${grafanaUrl}`; inputUrl = `http://${inputUrl}`;
urlObj = new url(grafanaUrl, {}); urlObj = new url(inputUrl, {});
console.log('No protocol provided in GRAFANA_URL -> inserting "http://"'); console.log('No protocol provided in inputUrl -> inserting "http://"');
} }
if(urlObj.slashes === false) { if(urlObj.slashes === false) {
urlObj = new url(`${urlObj.protocol}//${urlObj.pathname}`, {}); urlObj = new url(`${urlObj.protocol}//${urlObj.pathname}`, {});
@ -16,7 +17,7 @@ export function normalizeUrl(grafanaUrl: string) {
} }
if(urlObj.pathname.slice(-1) === '/') { if(urlObj.pathname.slice(-1) === '/') {
urlObj.pathname = urlObj.pathname.slice(0, -1); urlObj.pathname = urlObj.pathname.slice(0, -1);
console.log('Removing the slash at the end of GRAFANA_URL'); console.log('Removing the slash at the end of inputUrl');
} }
let finalUrl = `${urlObj.protocol}//${urlObj.hostname}`; let finalUrl = `${urlObj.protocol}//${urlObj.hostname}`;
if(urlObj.port !== '') { if(urlObj.port !== '') {

Loading…
Cancel
Save