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
2dd49e6e
Commit
2dd49e6e
authored
Oct 25, 2017
by
Patrick O'Carroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
converted linkSrv.js to linkSrv.ts
parent
c91a1e99
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
107 deletions
+103
-107
public/app/features/panellinks/linkSrv.ts
+103
-107
No files found.
public/app/features/panellinks/linkSrv.
j
s
→
public/app/features/panellinks/linkSrv.
t
s
View file @
2dd49e6e
define
([
import
angular
from
'angular'
;
'angular'
,
import
_
from
'lodash'
;
'lodash'
,
import
kbn
from
'app/core/utils/kbn'
;
'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
);
export
class
LinkSrv
{
};
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
));
}
});
if
(
paramsArray
.
length
===
0
)
{
/** @ngInject */
return
url
;
constructor
(
private
templateSrv
,
private
timeSrv
)
{
}
}
return
this
.
appendToQueryString
(
url
,
paramsArray
.
join
(
'&'
));
getLinkUrl
(
link
)
{
};
var
url
=
this
.
templateSrv
.
replace
(
link
.
url
||
''
);
var
params
=
{};
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
(
link
.
keepTime
)
{
var
range
=
this
.
timeSrv
.
timeRangeForUrl
();
params
[
'from'
]
=
range
.
from
;
params
[
'to'
]
=
range
.
to
;
}
if
(
link
.
keepTime
)
{
if
(
link
.
includeVars
)
{
var
range
=
timeSrv
.
timeRangeForUrl
();
this
.
templateSrv
.
fillVariableValuesForUrl
(
params
);
params
[
'from'
]
=
range
.
from
;
}
params
[
'to'
]
=
range
.
to
;
}
if
(
link
.
includeVars
)
{
return
this
.
addParamsToUrl
(
url
,
params
);
templateSrv
.
fillVariableValuesForUrl
(
params
,
scopedVars
);
}
}
info
.
href
=
this
.
addParamsToUrl
(
info
.
href
,
params
);
addParamsToUrl
(
url
,
params
)
{
var
paramsArray
=
[];
if
(
link
.
params
)
{
_
.
each
(
params
,
function
(
value
,
key
)
{
info
.
href
=
this
.
appendToQueryString
(
info
.
href
,
templateSrv
.
replace
(
link
.
params
,
scopedVars
));
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
));
}
});
return
info
;
if
(
paramsArray
.
length
===
0
)
{
};
return
url
;
}
});
return
this
.
appendToQueryString
(
url
,
paramsArray
.
join
(
'&'
));
});
}
appendToQueryString
(
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
;
}
getAnchorInfo
(
link
)
{
var
info
=
{};
(
<
any
>
info
).
href
=
this
.
getLinkUrl
(
link
);
(
<
any
>
info
).
title
=
this
.
templateSrv
.
replace
(
link
.
title
||
''
);
return
info
;
}
getPanelLinkAnchorInfo
(
link
,
scopedVars
)
{
var
info
=
{};
if
(
link
.
type
===
'absolute'
)
{
(
<
any
>
info
).
target
=
link
.
targetBlank
?
'_blank'
:
'_self'
;
(
<
any
>
info
).
href
=
this
.
templateSrv
.
replace
(
link
.
url
||
''
,
scopedVars
);
(
<
any
>
info
).
title
=
this
.
templateSrv
.
replace
(
link
.
title
||
''
,
scopedVars
);
}
else
if
(
link
.
dashUri
)
{
(
<
any
>
info
).
href
=
'dashboard/'
+
link
.
dashUri
+
'?'
;
(
<
any
>
info
).
title
=
this
.
templateSrv
.
replace
(
link
.
title
||
''
,
scopedVars
);
(
<
any
>
info
).
target
=
link
.
targetBlank
?
'_blank'
:
''
;
}
else
{
(
<
any
>
info
).
title
=
this
.
templateSrv
.
replace
(
link
.
title
||
''
,
scopedVars
);
var
slug
=
kbn
.
slugifyForUrl
(
link
.
dashboard
||
''
);
(
<
any
>
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
);
}
(
<
any
>
info
).
href
=
this
.
addParamsToUrl
((
<
any
>
info
).
href
,
params
);
if
(
link
.
params
)
{
(
<
any
>
info
).
href
=
this
.
appendToQueryString
((
<
any
>
info
).
href
,
this
.
templateSrv
.
replace
(
link
.
params
,
scopedVars
));
}
return
info
;
}
}
angular
.
module
(
'grafana.services'
).
service
(
'linkSrv'
,
LinkSrv
);
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