mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
tech: ran pretttier on all typescript files
This commit is contained in:
@@ -1,20 +1,19 @@
|
||||
import angular from 'angular';
|
||||
import _ from 'lodash';
|
||||
import kbn from 'app/core/utils/kbn';
|
||||
import angular from "angular";
|
||||
import _ from "lodash";
|
||||
import kbn from "app/core/utils/kbn";
|
||||
|
||||
export class LinkSrv {
|
||||
|
||||
/** @ngInject */
|
||||
constructor(private templateSrv, private timeSrv) {}
|
||||
|
||||
getLinkUrl(link) {
|
||||
var url = this.templateSrv.replace(link.url || '');
|
||||
var url = this.templateSrv.replace(link.url || "");
|
||||
var params = {};
|
||||
|
||||
if (link.keepTime) {
|
||||
var range = this.timeSrv.timeRangeForUrl();
|
||||
params['from'] = range.from;
|
||||
params['to'] = range.to;
|
||||
params["from"] = range.from;
|
||||
params["to"] = range.to;
|
||||
}
|
||||
|
||||
if (link.includeVars) {
|
||||
@@ -35,10 +34,10 @@ export class LinkSrv {
|
||||
paramsArray.push(key);
|
||||
} else if (_.isArray(value)) {
|
||||
_.each(value, function(instance) {
|
||||
paramsArray.push(key + '=' + encodeURIComponent(instance));
|
||||
paramsArray.push(key + "=" + encodeURIComponent(instance));
|
||||
});
|
||||
} else {
|
||||
paramsArray.push(key + '=' + encodeURIComponent(value));
|
||||
paramsArray.push(key + "=" + encodeURIComponent(value));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -46,18 +45,22 @@ export class LinkSrv {
|
||||
return url;
|
||||
}
|
||||
|
||||
return this.appendToQueryString(url, paramsArray.join('&'));
|
||||
return this.appendToQueryString(url, paramsArray.join("&"));
|
||||
}
|
||||
|
||||
appendToQueryString(url, stringToAppend) {
|
||||
if (!_.isUndefined(stringToAppend) && stringToAppend !== null && stringToAppend !== '') {
|
||||
var pos = url.indexOf('?');
|
||||
if (
|
||||
!_.isUndefined(stringToAppend) &&
|
||||
stringToAppend !== null &&
|
||||
stringToAppend !== ""
|
||||
) {
|
||||
var pos = url.indexOf("?");
|
||||
if (pos !== -1) {
|
||||
if (url.length - pos > 1) {
|
||||
url += '&';
|
||||
url += "&";
|
||||
}
|
||||
} else {
|
||||
url += '?';
|
||||
url += "?";
|
||||
}
|
||||
url += stringToAppend;
|
||||
}
|
||||
@@ -68,32 +71,32 @@ export class LinkSrv {
|
||||
getAnchorInfo(link) {
|
||||
var info: any = {};
|
||||
info.href = this.getLinkUrl(link);
|
||||
info.title = this.templateSrv.replace(link.title || '');
|
||||
info.title = this.templateSrv.replace(link.title || "");
|
||||
return info;
|
||||
}
|
||||
|
||||
getPanelLinkAnchorInfo(link, scopedVars) {
|
||||
var info: any = {};
|
||||
if (link.type === 'absolute') {
|
||||
info.target = link.targetBlank ? '_blank' : '_self';
|
||||
info.href = this.templateSrv.replace(link.url || '', scopedVars);
|
||||
info.title = this.templateSrv.replace(link.title || '', scopedVars);
|
||||
if (link.type === "absolute") {
|
||||
info.target = link.targetBlank ? "_blank" : "_self";
|
||||
info.href = this.templateSrv.replace(link.url || "", scopedVars);
|
||||
info.title = this.templateSrv.replace(link.title || "", scopedVars);
|
||||
} else if (link.dashUri) {
|
||||
info.href = 'dashboard/' + link.dashUri + '?';
|
||||
info.title = this.templateSrv.replace(link.title || '', scopedVars);
|
||||
info.target = link.targetBlank ? '_blank' : '';
|
||||
info.href = "dashboard/" + link.dashUri + "?";
|
||||
info.title = this.templateSrv.replace(link.title || "", scopedVars);
|
||||
info.target = link.targetBlank ? "_blank" : "";
|
||||
} else {
|
||||
info.title = this.templateSrv.replace(link.title || '', scopedVars);
|
||||
var slug = kbn.slugifyForUrl(link.dashboard || '');
|
||||
info.href = 'dashboard/db/' + slug + '?';
|
||||
info.title = this.templateSrv.replace(link.title || "", scopedVars);
|
||||
var slug = kbn.slugifyForUrl(link.dashboard || "");
|
||||
info.href = "dashboard/db/" + slug + "?";
|
||||
}
|
||||
|
||||
var params = {};
|
||||
|
||||
if (link.keepTime) {
|
||||
var range = this.timeSrv.timeRangeForUrl();
|
||||
params['from'] = range.from;
|
||||
params['to'] = range.to;
|
||||
params["from"] = range.from;
|
||||
params["to"] = range.to;
|
||||
}
|
||||
|
||||
if (link.includeVars) {
|
||||
@@ -103,11 +106,14 @@ export class LinkSrv {
|
||||
info.href = this.addParamsToUrl(info.href, params);
|
||||
|
||||
if (link.params) {
|
||||
info.href = this.appendToQueryString(info.href, this.templateSrv.replace(link.params, scopedVars));
|
||||
info.href = this.appendToQueryString(
|
||||
info.href,
|
||||
this.templateSrv.replace(link.params, scopedVars)
|
||||
);
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
angular.module('grafana.services').service('linkSrv', LinkSrv);
|
||||
angular.module("grafana.services").service("linkSrv", LinkSrv);
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import angular from 'angular';
|
||||
import _ from 'lodash';
|
||||
import './link_srv';
|
||||
import angular from "angular";
|
||||
import _ from "lodash";
|
||||
import "./link_srv";
|
||||
|
||||
function panelLinksEditor() {
|
||||
return {
|
||||
scope: {
|
||||
panel: "="
|
||||
},
|
||||
restrict: 'E',
|
||||
controller: 'PanelLinksEditorCtrl',
|
||||
templateUrl: 'public/app/features/panellinks/module.html',
|
||||
link: function() {
|
||||
}
|
||||
restrict: "E",
|
||||
controller: "PanelLinksEditorCtrl",
|
||||
templateUrl: "public/app/features/panellinks/module.html",
|
||||
link: function() {}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,12 +21,12 @@ export class PanelLinksEditorCtrl {
|
||||
|
||||
$scope.addLink = function() {
|
||||
$scope.panel.links.push({
|
||||
type: 'dashboard',
|
||||
type: "dashboard"
|
||||
});
|
||||
};
|
||||
|
||||
$scope.searchDashboards = function(queryStr, callback) {
|
||||
backendSrv.search({query: queryStr}).then(function(hits) {
|
||||
backendSrv.search({ query: queryStr }).then(function(hits) {
|
||||
var dashboards = _.map(hits, function(dash) {
|
||||
return dash.title;
|
||||
});
|
||||
@@ -37,8 +36,8 @@ export class PanelLinksEditorCtrl {
|
||||
};
|
||||
|
||||
$scope.dashboardChanged = function(link) {
|
||||
backendSrv.search({query: link.dashboard}).then(function(hits) {
|
||||
var dashboard = _.find(hits, {title: link.dashboard});
|
||||
backendSrv.search({ query: link.dashboard }).then(function(hits) {
|
||||
var dashboard = _.find(hits, { title: link.dashboard });
|
||||
if (dashboard) {
|
||||
link.dashUri = dashboard.uri;
|
||||
link.title = dashboard.title;
|
||||
@@ -52,6 +51,7 @@ export class PanelLinksEditorCtrl {
|
||||
}
|
||||
}
|
||||
|
||||
angular.module('grafana.directives').directive('panelLinksEditor', panelLinksEditor)
|
||||
.controller('PanelLinksEditorCtrl', PanelLinksEditorCtrl);
|
||||
|
||||
angular
|
||||
.module("grafana.directives")
|
||||
.directive("panelLinksEditor", panelLinksEditor)
|
||||
.controller("PanelLinksEditorCtrl", PanelLinksEditorCtrl);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { LinkSrv } from '../link_srv';
|
||||
import _ from 'lodash';
|
||||
import { LinkSrv } from "../link_srv";
|
||||
import _ from "lodash";
|
||||
|
||||
jest.mock('angular', () => {
|
||||
let AngularJSMock = require('test/mocks/angular');
|
||||
jest.mock("angular", () => {
|
||||
let AngularJSMock = require("test/mocks/angular");
|
||||
return new AngularJSMock();
|
||||
});
|
||||
|
||||
describe('linkSrv', function() {
|
||||
describe("linkSrv", function() {
|
||||
var linkSrv;
|
||||
var templateSrvMock = {};
|
||||
var timeSrvMock = {};
|
||||
@@ -15,32 +15,38 @@ describe('linkSrv', function() {
|
||||
linkSrv = new LinkSrv(templateSrvMock, timeSrvMock);
|
||||
});
|
||||
|
||||
describe('when appending query strings', function() {
|
||||
it('add ? to URL if not present', function() {
|
||||
var url = linkSrv.appendToQueryString('http://example.com', 'foo=bar');
|
||||
expect(url).toBe('http://example.com?foo=bar');
|
||||
describe("when appending query strings", function() {
|
||||
it("add ? to URL if not present", function() {
|
||||
var url = linkSrv.appendToQueryString("http://example.com", "foo=bar");
|
||||
expect(url).toBe("http://example.com?foo=bar");
|
||||
});
|
||||
|
||||
it('do not add & to URL if ? is present but query string is empty', function() {
|
||||
var url = linkSrv.appendToQueryString('http://example.com?', 'foo=bar');
|
||||
expect(url).toBe('http://example.com?foo=bar');
|
||||
it("do not add & to URL if ? is present but query string is empty", function() {
|
||||
var url = linkSrv.appendToQueryString("http://example.com?", "foo=bar");
|
||||
expect(url).toBe("http://example.com?foo=bar");
|
||||
});
|
||||
|
||||
it('add & to URL if query string is present', function() {
|
||||
var url = linkSrv.appendToQueryString('http://example.com?foo=bar', 'hello=world');
|
||||
expect(url).toBe('http://example.com?foo=bar&hello=world');
|
||||
it("add & to URL if query string is present", function() {
|
||||
var url = linkSrv.appendToQueryString(
|
||||
"http://example.com?foo=bar",
|
||||
"hello=world"
|
||||
);
|
||||
expect(url).toBe("http://example.com?foo=bar&hello=world");
|
||||
});
|
||||
|
||||
it('do not change the URL if there is nothing to append', function() {
|
||||
_.each(['', undefined, null], function(toAppend) {
|
||||
var url1 = linkSrv.appendToQueryString('http://example.com', toAppend);
|
||||
expect(url1).toBe('http://example.com');
|
||||
it("do not change the URL if there is nothing to append", function() {
|
||||
_.each(["", undefined, null], function(toAppend) {
|
||||
var url1 = linkSrv.appendToQueryString("http://example.com", toAppend);
|
||||
expect(url1).toBe("http://example.com");
|
||||
|
||||
var url2 = linkSrv.appendToQueryString('http://example.com?', toAppend);
|
||||
expect(url2).toBe('http://example.com?');
|
||||
var url2 = linkSrv.appendToQueryString("http://example.com?", toAppend);
|
||||
expect(url2).toBe("http://example.com?");
|
||||
|
||||
var url3 = linkSrv.appendToQueryString('http://example.com?foo=bar', toAppend);
|
||||
expect(url3).toBe('http://example.com?foo=bar');
|
||||
var url3 = linkSrv.appendToQueryString(
|
||||
"http://example.com?foo=bar",
|
||||
toAppend
|
||||
);
|
||||
expect(url3).toBe("http://example.com?foo=bar");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user