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
05fabc73
Commit
05fabc73
authored
Sep 09, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dashboard: elasticsearch dashboard storage now slugifies urls, #781
parent
e9497611
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
16 deletions
+40
-16
src/app/components/kbn.js
+7
-0
src/app/services/elasticsearch/es-datasource.js
+33
-16
No files found.
src/app/components/kbn.js
View file @
05fabc73
...
...
@@ -655,6 +655,13 @@ function($, _, moment) {
}
};
kbn
.
slugifyForUrl
=
function
(
str
)
{
return
str
.
toLowerCase
()
.
replace
(
/
[^\w
]
+/g
,
''
)
.
replace
(
/ +/g
,
'-'
);
};
kbn
.
stringToJsRegex
=
function
(
str
)
{
if
(
str
[
0
]
!==
'/'
)
{
return
new
RegExp
(
str
);
...
...
src/app/services/elasticsearch/es-datasource.js
View file @
05fabc73
define
([
'angular'
,
'lodash'
,
'jquery'
,
'config'
,
'kbn'
,
'moment'
],
function
(
angular
,
_
,
$
,
config
,
kbn
,
moment
)
{
function
(
angular
,
_
,
config
,
kbn
,
moment
)
{
'use strict'
;
var
module
=
angular
.
module
(
'grafana.services'
);
...
...
@@ -119,25 +118,29 @@ function (angular, _, $, config, kbn, moment) {
});
};
ElasticDatasource
.
prototype
.
_getDashboardWithSlug
=
function
(
id
)
{
return
this
.
_get
(
'/dashboard/'
+
kbn
.
slugifyForUrl
(
id
))
.
then
(
function
(
result
)
{
return
angular
.
fromJson
(
result
.
_source
.
dashboard
);
},
function
()
{
throw
"Dashboard not found"
;
});
};
ElasticDatasource
.
prototype
.
getDashboard
=
function
(
id
,
isTemp
)
{
var
url
=
'/dashboard/'
+
id
;
if
(
isTemp
)
{
url
=
'/temp/'
+
id
;
}
if
(
isTemp
)
{
url
=
'/temp/'
+
id
;
}
var
self
=
this
;
return
this
.
_get
(
url
)
.
then
(
function
(
result
)
{
if
(
result
.
_source
&&
result
.
_source
.
dashboard
)
{
return
angular
.
fromJson
(
result
.
_source
.
dashboard
);
}
else
{
return
false
;
}
return
angular
.
fromJson
(
result
.
_source
.
dashboard
);
},
function
(
data
)
{
if
(
data
.
status
===
0
)
{
throw
"Could not contact Elasticsearch. Please ensure that Elasticsearch is reachable from your browser."
;
}
else
{
throw
"Could not find dashboard "
+
id
;
// backward compatible fallback
return
self
.
_getDashboardWithSlug
(
id
);
}
});
};
...
...
@@ -159,15 +162,29 @@ function (angular, _, $, config, kbn, moment) {
return
this
.
_saveTempDashboard
(
data
);
}
else
{
return
this
.
_request
(
'PUT'
,
'/dashboard/'
+
encodeURIComponent
(
title
),
this
.
index
,
data
)
.
then
(
function
()
{
return
{
title
:
title
,
url
:
'/dashboard/db/'
+
title
};
var
id
=
encodeURIComponent
(
kbn
.
slugifyForUrl
(
title
));
var
self
=
this
;
return
this
.
_request
(
'PUT'
,
'/dashboard/'
+
id
,
this
.
index
,
data
)
.
then
(
function
(
results
)
{
self
.
_removeUnslugifiedDashboard
(
results
,
title
);
return
{
title
:
title
,
url
:
'/dashboard/db/'
+
id
};
},
function
(
err
)
{
throw
'Failed to save to elasticsearch '
+
err
.
data
;
});
}
};
ElasticDatasource
.
prototype
.
_removeUnslugifiedDashboard
=
function
(
saveResult
,
title
)
{
if
(
saveResult
.
statusText
!==
'Created'
)
{
return
;
}
var
self
=
this
;
this
.
_get
(
'/dashboard/'
+
title
).
then
(
function
()
{
self
.
deleteDashboard
(
title
);
});
};
ElasticDatasource
.
prototype
.
_saveTempDashboard
=
function
(
data
)
{
return
this
.
_request
(
'POST'
,
'/temp/?ttl='
+
this
.
saveTempTTL
,
this
.
index
,
data
)
.
then
(
function
(
result
)
{
...
...
@@ -227,7 +244,7 @@ function (angular, _, $, config, kbn, moment) {
for
(
var
i
=
0
;
i
<
results
.
hits
.
hits
.
length
;
i
++
)
{
hits
.
dashboards
.
push
({
id
:
results
.
hits
.
hits
[
i
].
_id
,
title
:
results
.
hits
.
hits
[
i
].
_
id
,
title
:
results
.
hits
.
hits
[
i
].
_
source
.
title
,
tags
:
results
.
hits
.
hits
[
i
].
_source
.
tags
});
}
...
...
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