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

4
src/datasource/partials/config.html

@ -14,7 +14,7 @@
ng-blur="ctrl.normalizeUrl()"
/>
<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'">
Your access method is <em>Browser</em>, this means the URL
needs to be accessible from the browser.
@ -34,7 +34,7 @@
<select
class="gf-form-input"
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>

17
src/utlis.ts

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

Loading…
Cancel
Save