Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
9aa6a6b4
Commit
9aa6a6b4
authored
Oct 31, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'linkSrv-js-to-ts'
parents
948a5259
ec94dfa8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
162 deletions
+111
-162
public/app/features/dashboard/specs/share_modal_ctrl_specs.ts
+1
-1
public/app/features/panellinks/link_srv.ts
+108
-113
public/app/features/panellinks/module.js
+1
-1
public/app/features/panellinks/specs/link_srv_specs.ts
+0
-46
public/app/plugins/panel/singlestat/module.ts
+1
-1
No files found.
public/app/features/dashboard/specs/share_modal_ctrl_specs.ts
View file @
9aa6a6b4
...
...
@@ -2,7 +2,7 @@ import {describe, beforeEach, it, expect, sinon, angularMocks} from 'test/lib/co
import
helpers
from
'test/specs/helpers'
;
import
'../shareModalCtrl'
;
import
config
from
'app/core/config'
;
import
'app/features/panellinks/link
S
rv'
;
import
'app/features/panellinks/link
_s
rv'
;
describe
(
'ShareModalCtrl'
,
function
()
{
var
ctx
=
new
helpers
.
ControllerTestContext
();
...
...
public/app/features/panellinks/link
Srv.j
s
→
public/app/features/panellinks/link
_srv.t
s
View file @
9aa6a6b4
define
([
'angular'
,
'lodash'
,
'app/core/utils/kbn'
,
],
function
(
angular
,
_
,
kbn
)
{
'use strict'
;
kbn
=
kbn
.
default
;
angular
.
module
(
'grafana.services'
)
.
service
(
'linkSrv'
,
function
(
templateSrv
,
timeSrv
)
{
this
.
getLinkUrl
=
function
(
link
)
{
var
url
=
templateSrv
.
replace
(
link
.
url
||
''
);
var
params
=
{};
if
(
link
.
keepTime
)
{
var
range
=
timeSrv
.
timeRangeForUrl
();
params
[
'from'
]
=
range
.
from
;
params
[
'to'
]
=
range
.
to
;
}
if
(
link
.
includeVars
)
{
templateSrv
.
fillVariableValuesForUrl
(
params
);
}
return
this
.
addParamsToUrl
(
url
,
params
);
};
this
.
addParamsToUrl
=
function
(
url
,
params
)
{
var
paramsArray
=
[];
_
.
each
(
params
,
function
(
value
,
key
)
{
if
(
value
===
null
)
{
return
;
}
if
(
value
===
true
)
{
paramsArray
.
push
(
key
);
}
else
if
(
_
.
isArray
(
value
))
{
_
.
each
(
value
,
function
(
instance
)
{
paramsArray
.
push
(
key
+
'='
+
encodeURIComponent
(
instance
));
});
}
else
{
paramsArray
.
push
(
key
+
'='
+
encodeURIComponent
(
value
));
}
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
params
=
{};
if
(
link
.
keepTime
)
{
var
range
=
this
.
timeSrv
.
timeRangeForUrl
();
params
[
'from'
]
=
range
.
from
;
params
[
'to'
]
=
range
.
to
;
}
if
(
link
.
includeVars
)
{
this
.
templateSrv
.
fillVariableValuesForUrl
(
params
);
}
return
this
.
addParamsToUrl
(
url
,
params
);
}
addParamsToUrl
(
url
,
params
)
{
var
paramsArray
=
[];
_
.
each
(
params
,
function
(
value
,
key
)
{
if
(
value
===
null
)
{
return
;
}
if
(
value
===
true
)
{
paramsArray
.
push
(
key
);
}
else
if
(
_
.
isArray
(
value
))
{
_
.
each
(
value
,
function
(
instance
)
{
paramsArray
.
push
(
key
+
'='
+
encodeURIComponent
(
instance
));
});
}
else
{
paramsArray
.
push
(
key
+
'='
+
encodeURIComponent
(
value
));
}
});
if
(
paramsArray
.
length
===
0
)
{
return
url
;
}
return
this
.
appendToQueryString
(
url
,
paramsArray
.
join
(
'&'
));
};
this
.
appendToQueryString
=
function
(
url
,
stringToAppend
)
{
if
(
!
_
.
isUndefined
(
stringToAppend
)
&&
stringToAppend
!==
null
&&
stringToAppend
!==
''
)
{
var
pos
=
url
.
indexOf
(
'?'
);
if
(
pos
!==
-
1
)
{
if
(
url
.
length
-
pos
>
1
)
{
url
+=
'&'
;
}
}
else
{
url
+=
'?'
;
}
url
+=
stringToAppend
;
}
return
url
;
};
this
.
getAnchorInfo
=
function
(
link
)
{
var
info
=
{};
info
.
href
=
this
.
getLinkUrl
(
link
);
info
.
title
=
templateSrv
.
replace
(
link
.
title
||
''
);
return
info
;
};
this
.
getPanelLinkAnchorInfo
=
function
(
link
,
scopedVars
)
{
var
info
=
{};
if
(
link
.
type
===
'absolute'
)
{
info
.
target
=
link
.
targetBlank
?
'_blank'
:
'_self'
;
info
.
href
=
templateSrv
.
replace
(
link
.
url
||
''
,
scopedVars
);
info
.
title
=
templateSrv
.
replace
(
link
.
title
||
''
,
scopedVars
);
}
else
if
(
link
.
dashUri
)
{
info
.
href
=
'dashboard/'
+
link
.
dashUri
+
'?'
;
info
.
title
=
templateSrv
.
replace
(
link
.
title
||
''
,
scopedVars
);
info
.
target
=
link
.
targetBlank
?
'_blank'
:
''
;
}
else
{
info
.
title
=
templateSrv
.
replace
(
link
.
title
||
''
,
scopedVars
);
var
slug
=
kbn
.
slugifyForUrl
(
link
.
dashboard
||
''
);
info
.
href
=
'dashboard/db/'
+
slug
+
'?'
;
}
var
params
=
{};
if
(
paramsArray
.
length
===
0
)
{
return
url
;
}
if
(
link
.
keepTime
)
{
var
range
=
timeSrv
.
timeRangeForUrl
();
params
[
'from'
]
=
range
.
from
;
params
[
'to'
]
=
range
.
to
;
}
return
this
.
appendToQueryString
(
url
,
paramsArray
.
join
(
'&'
));
}
if
(
link
.
includeVars
)
{
templateSrv
.
fillVariableValuesForUrl
(
params
,
scopedVars
);
appendToQueryString
(
url
,
stringToAppend
)
{
if
(
!
_
.
isUndefined
(
stringToAppend
)
&&
stringToAppend
!==
null
&&
stringToAppend
!==
''
)
{
var
pos
=
url
.
indexOf
(
'?'
);
if
(
pos
!==
-
1
)
{
if
(
url
.
length
-
pos
>
1
)
{
url
+=
'&'
;
}
info
.
href
=
this
.
addParamsToUrl
(
info
.
href
,
params
);
if
(
link
.
params
)
{
info
.
href
=
this
.
appendToQueryString
(
info
.
href
,
templateSrv
.
replace
(
link
.
params
,
scopedVars
));
}
return
info
;
};
});
});
}
else
{
url
+=
'?'
;
}
url
+=
stringToAppend
;
}
return
url
;
}
getAnchorInfo
(
link
)
{
var
info
:
any
=
{};
info
.
href
=
this
.
getLinkUrl
(
link
);
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
);
}
else
if
(
link
.
dashUri
)
{
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
+
'?'
;
}
var
params
=
{};
if
(
link
.
keepTime
)
{
var
range
=
this
.
timeSrv
.
timeRangeForUrl
();
params
[
'from'
]
=
range
.
from
;
params
[
'to'
]
=
range
.
to
;
}
if
(
link
.
includeVars
)
{
this
.
templateSrv
.
fillVariableValuesForUrl
(
params
,
scopedVars
);
}
info
.
href
=
this
.
addParamsToUrl
(
info
.
href
,
params
);
if
(
link
.
params
)
{
info
.
href
=
this
.
appendToQueryString
(
info
.
href
,
this
.
templateSrv
.
replace
(
link
.
params
,
scopedVars
));
}
return
info
;
}
}
angular
.
module
(
'grafana.services'
).
service
(
'linkSrv'
,
LinkSrv
);
public/app/features/panellinks/module.js
View file @
9aa6a6b4
define
([
'angular'
,
'lodash'
,
'./link
S
rv'
,
'./link
_s
rv'
,
],
function
(
angular
,
_
)
{
'use strict'
;
...
...
public/app/features/panellinks/specs/link_srv_specs.ts
deleted
100644 → 0
View file @
948a5259
import
{
describe
,
beforeEach
,
it
,
expect
,
angularMocks
}
from
'test/lib/common'
;
import
'app/features/panellinks/linkSrv'
;
import
_
from
'lodash'
;
describe
(
'linkSrv'
,
function
()
{
var
_linkSrv
;
beforeEach
(
angularMocks
.
module
(
'grafana.core'
));
beforeEach
(
angularMocks
.
module
(
'grafana.services'
));
beforeEach
(
angularMocks
.
inject
(
function
(
linkSrv
)
{
_linkSrv
=
linkSrv
;
}));
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
).
to
.
be
(
'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
).
to
.
be
(
'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
).
to
.
be
(
'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
).
to
.
be
(
'http://example.com'
);
var
url2
=
_linkSrv
.
appendToQueryString
(
'http://example.com?'
,
toAppend
);
expect
(
url2
).
to
.
be
(
'http://example.com?'
);
var
url3
=
_linkSrv
.
appendToQueryString
(
'http://example.com?foo=bar'
,
toAppend
);
expect
(
url3
).
to
.
be
(
'http://example.com?foo=bar'
);
});
});
});
});
public/app/plugins/panel/singlestat/module.ts
View file @
9aa6a6b4
...
...
@@ -2,7 +2,7 @@ import _ from 'lodash';
import
$
from
'jquery'
;
import
'vendor/flot/jquery.flot'
;
import
'vendor/flot/jquery.flot.gauge'
;
import
'app/features/panellinks/link
S
rv'
;
import
'app/features/panellinks/link
_s
rv'
;
import
kbn
from
'app/core/utils/kbn'
;
import
config
from
'app/core/config'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment