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
7cd663bb
Commit
7cd663bb
authored
May 14, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(import): more import work
parent
d9d46096
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
92 additions
and
59 deletions
+92
-59
pkg/api/dtos/plugins.go
+5
-1
pkg/api/plugins.go
+2
-1
pkg/plugins/dashboard_importer.go
+14
-15
pkg/plugins/dashboards.go
+19
-14
public/app/core/components/search/search.html
+1
-1
public/app/core/components/search/search.ts
+0
-5
public/app/core/directives/dash_edit_link.js
+16
-1
public/app/core/services/datasource_srv.js
+5
-5
public/app/core/services/util_srv.ts
+2
-1
public/app/features/dashboard/import/import.html
+1
-1
public/app/features/dashboard/import/import.ts
+18
-5
public/app/features/plugins/import_list/import_list.html
+6
-6
public/app/features/plugins/import_list/import_list.ts
+3
-3
No files found.
pkg/api/dtos/plugins.go
View file @
7cd663bb
package
dtos
package
dtos
import
"github.com/grafana/grafana/pkg/plugins"
import
(
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/plugins"
)
type
PluginSetting
struct
{
type
PluginSetting
struct
{
Name
string
`json:"name"`
Name
string
`json:"name"`
...
@@ -50,5 +53,6 @@ type ImportDashboardCommand struct {
...
@@ -50,5 +53,6 @@ type ImportDashboardCommand struct {
PluginId
string
`json:"pluginId"`
PluginId
string
`json:"pluginId"`
Path
string
`json:"path"`
Path
string
`json:"path"`
Overwrite
bool
`json:"overwrite"`
Overwrite
bool
`json:"overwrite"`
Dashboard
*
simplejson
.
Json
`json:"dashboard"`
Inputs
[]
plugins
.
ImportDashboardInput
`json:"inputs"`
Inputs
[]
plugins
.
ImportDashboardInput
`json:"inputs"`
}
}
pkg/api/plugins.go
View file @
7cd663bb
...
@@ -168,10 +168,11 @@ func ImportDashboard(c *middleware.Context, apiCmd dtos.ImportDashboardCommand)
...
@@ -168,10 +168,11 @@ func ImportDashboard(c *middleware.Context, apiCmd dtos.ImportDashboardCommand)
Path
:
apiCmd
.
Path
,
Path
:
apiCmd
.
Path
,
Inputs
:
apiCmd
.
Inputs
,
Inputs
:
apiCmd
.
Inputs
,
Overwrite
:
apiCmd
.
Overwrite
,
Overwrite
:
apiCmd
.
Overwrite
,
Dashboard
:
apiCmd
.
Dashboard
,
}
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to i
nstall
dashboard"
,
err
)
return
ApiError
(
500
,
"Failed to i
mport
dashboard"
,
err
)
}
}
return
Json
(
200
,
cmd
.
Result
)
return
Json
(
200
,
cmd
.
Result
)
...
...
pkg/plugins/dashboard_importer.go
View file @
7cd663bb
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
)
)
type
ImportDashboardCommand
struct
{
type
ImportDashboardCommand
struct
{
Dashboard
*
simplejson
.
Json
Path
string
Path
string
Inputs
[]
ImportDashboardInput
Inputs
[]
ImportDashboardInput
Overwrite
bool
Overwrite
bool
...
@@ -41,17 +42,15 @@ func init() {
...
@@ -41,17 +42,15 @@ func init() {
}
}
func
ImportDashboard
(
cmd
*
ImportDashboardCommand
)
error
{
func
ImportDashboard
(
cmd
*
ImportDashboardCommand
)
error
{
plugin
,
exists
:=
Plugins
[
cmd
.
PluginId
]
if
!
exists
{
return
PluginNotFoundError
{
cmd
.
PluginId
}
}
var
dashboard
*
m
.
Dashboard
var
dashboard
*
m
.
Dashboard
var
err
error
var
err
error
if
dashboard
,
err
=
loadPluginDashboard
(
plugin
,
cmd
.
Path
);
err
!=
nil
{
if
cmd
.
PluginId
!=
""
{
return
err
if
dashboard
,
err
=
loadPluginDashboard
(
cmd
.
PluginId
,
cmd
.
Path
);
err
!=
nil
{
return
err
}
}
else
{
dashboard
=
m
.
NewDashboardFromJson
(
cmd
.
Dashboard
)
}
}
evaluator
:=
&
DashTemplateEvaluator
{
evaluator
:=
&
DashTemplateEvaluator
{
...
@@ -76,13 +75,13 @@ func ImportDashboard(cmd *ImportDashboardCommand) error {
...
@@ -76,13 +75,13 @@ func ImportDashboard(cmd *ImportDashboardCommand) error {
}
}
cmd
.
Result
=
&
PluginDashboardInfoDTO
{
cmd
.
Result
=
&
PluginDashboardInfoDTO
{
PluginId
:
cmd
.
PluginId
,
PluginId
:
cmd
.
PluginId
,
Title
:
dashboard
.
Title
,
Title
:
dashboard
.
Title
,
Path
:
cmd
.
Path
,
Path
:
cmd
.
Path
,
Revision
:
dashboard
.
GetString
(
"revision"
,
"1.0"
),
Revision
:
dashboard
.
Data
.
Get
(
"revision"
)
.
MustInt64
(
1
),
I
nstall
edUri
:
"db/"
+
saveCmd
.
Result
.
Slug
,
I
mport
edUri
:
"db/"
+
saveCmd
.
Result
.
Slug
,
I
nstalledRevision
:
dashboard
.
GetString
(
"revision"
,
"1.0"
),
I
mportedRevision
:
dashboard
.
Data
.
Get
(
"revision"
)
.
MustInt64
(
1
),
I
nstall
ed
:
true
,
I
mport
ed
:
true
,
}
}
return
nil
return
nil
...
...
pkg/plugins/dashboards.go
View file @
7cd663bb
...
@@ -10,14 +10,14 @@ import (
...
@@ -10,14 +10,14 @@ import (
)
)
type
PluginDashboardInfoDTO
struct
{
type
PluginDashboardInfoDTO
struct
{
PluginId
string
`json:"pluginId"`
PluginId
string
`json:"pluginId"`
Title
string
`json:"title"`
Title
string
`json:"title"`
I
nstalled
bool
`json:"install
ed"`
I
mported
bool
`json:"import
ed"`
I
nstalledUri
string
`json:"install
edUri"`
I
mportedUri
string
`json:"import
edUri"`
I
nstalledRevision
string
`json:"install
edRevision"`
I
mportedRevision
int64
`json:"import
edRevision"`
Revision
string
`json:"revision"`
Revision
int64
`json:"revision"`
Description
string
`json:"description"`
Description
string
`json:"description"`
Path
string
`json:"path"`
Path
string
`json:"path"`
}
}
func
GetPluginDashboards
(
orgId
int64
,
pluginId
string
)
([]
*
PluginDashboardInfoDTO
,
error
)
{
func
GetPluginDashboards
(
orgId
int64
,
pluginId
string
)
([]
*
PluginDashboardInfoDTO
,
error
)
{
...
@@ -42,7 +42,12 @@ func GetPluginDashboards(orgId int64, pluginId string) ([]*PluginDashboardInfoDT
...
@@ -42,7 +42,12 @@ func GetPluginDashboards(orgId int64, pluginId string) ([]*PluginDashboardInfoDT
return
result
,
nil
return
result
,
nil
}
}
func
loadPluginDashboard
(
plugin
*
PluginBase
,
path
string
)
(
*
m
.
Dashboard
,
error
)
{
func
loadPluginDashboard
(
pluginId
,
path
string
)
(
*
m
.
Dashboard
,
error
)
{
plugin
,
exists
:=
Plugins
[
pluginId
]
if
!
exists
{
return
nil
,
PluginNotFoundError
{
pluginId
}
}
dashboardFilePath
:=
filepath
.
Join
(
plugin
.
PluginDir
,
path
)
dashboardFilePath
:=
filepath
.
Join
(
plugin
.
PluginDir
,
path
)
reader
,
err
:=
os
.
Open
(
dashboardFilePath
)
reader
,
err
:=
os
.
Open
(
dashboardFilePath
)
...
@@ -66,14 +71,14 @@ func getDashboardImportStatus(orgId int64, plugin *PluginBase, path string) (*Pl
...
@@ -66,14 +71,14 @@ func getDashboardImportStatus(orgId int64, plugin *PluginBase, path string) (*Pl
var
dashboard
*
m
.
Dashboard
var
dashboard
*
m
.
Dashboard
var
err
error
var
err
error
if
dashboard
,
err
=
loadPluginDashboard
(
plugin
,
path
);
err
!=
nil
{
if
dashboard
,
err
=
loadPluginDashboard
(
plugin
.
Id
,
path
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
res
.
Path
=
path
res
.
Path
=
path
res
.
PluginId
=
plugin
.
Id
res
.
PluginId
=
plugin
.
Id
res
.
Title
=
dashboard
.
Title
res
.
Title
=
dashboard
.
Title
res
.
Revision
=
dashboard
.
GetString
(
"revision"
,
"1.0"
)
res
.
Revision
=
dashboard
.
Data
.
Get
(
"revision"
)
.
MustInt64
(
1
)
query
:=
m
.
GetDashboardQuery
{
OrgId
:
orgId
,
Slug
:
dashboard
.
Slug
}
query
:=
m
.
GetDashboardQuery
{
OrgId
:
orgId
,
Slug
:
dashboard
.
Slug
}
...
@@ -82,9 +87,9 @@ func getDashboardImportStatus(orgId int64, plugin *PluginBase, path string) (*Pl
...
@@ -82,9 +87,9 @@ func getDashboardImportStatus(orgId int64, plugin *PluginBase, path string) (*Pl
return
nil
,
err
return
nil
,
err
}
}
}
else
{
}
else
{
res
.
I
nstall
ed
=
true
res
.
I
mport
ed
=
true
res
.
I
nstall
edUri
=
"db/"
+
query
.
Result
.
Slug
res
.
I
mport
edUri
=
"db/"
+
query
.
Result
.
Slug
res
.
I
nstalledRevision
=
query
.
Result
.
GetString
(
"revision"
,
"1.0"
)
res
.
I
mportedRevision
=
query
.
Result
.
Data
.
Get
(
"revision"
)
.
MustInt64
(
1
)
}
}
return
res
,
nil
return
res
,
nil
...
...
public/app/core/components/search/search.html
View file @
7cd663bb
...
@@ -67,7 +67,7 @@
...
@@ -67,7 +67,7 @@
Create New
Create New
</a>
</a>
<a
class=
"btn btn-inverse pull-left"
ng-click=
"ctrl.import()
"
ng-show=
"ctrl.contextSrv.isEditor"
ng-click=
"ctrl.isOpen = false;"
>
<a
class=
"btn btn-inverse pull-left"
href=
"dashboard/new/?editview=import
"
ng-show=
"ctrl.contextSrv.isEditor"
ng-click=
"ctrl.isOpen = false;"
>
<i
class=
"fa fa-upload"
></i>
<i
class=
"fa fa-upload"
></i>
Import
Import
</a>
</a>
...
...
public/app/core/components/search/search.ts
View file @
7cd663bb
...
@@ -149,11 +149,6 @@ export class SearchCtrl {
...
@@ -149,11 +149,6 @@ export class SearchCtrl {
this
.
searchDashboards
();
this
.
searchDashboards
();
};
};
import
()
{
appEvents
.
emit
(
'show-modal'
,
{
templateHtml
:
'<dash-import></dash-import>'
,
});
}
}
}
export
function
searchDirective
()
{
export
function
searchDirective
()
{
...
...
public/app/core/directives/dash_edit_link.js
View file @
7cd663bb
...
@@ -12,7 +12,7 @@ function ($, coreModule) {
...
@@ -12,7 +12,7 @@ function ($, coreModule) {
'import'
:
{
src
:
'<dash-import></dash-import>'
}
'import'
:
{
src
:
'<dash-import></dash-import>'
}
};
};
coreModule
.
default
.
directive
(
'dashEditorView'
,
function
(
$compile
,
$location
)
{
coreModule
.
default
.
directive
(
'dashEditorView'
,
function
(
$compile
,
$location
,
$rootScope
)
{
return
{
return
{
restrict
:
'A'
,
restrict
:
'A'
,
link
:
function
(
scope
,
elem
)
{
link
:
function
(
scope
,
elem
)
{
...
@@ -57,6 +57,21 @@ function ($, coreModule) {
...
@@ -57,6 +57,21 @@ function ($, coreModule) {
}
}
};
};
if
(
editview
===
'import'
)
{
var
modalScope
=
$rootScope
.
$new
();
modalScope
.
$on
(
"$destroy"
,
function
()
{
editorScope
.
dismiss
();
});
$rootScope
.
appEvent
(
'show-modal'
,
{
templateHtml
:
'<dash-import></dash-import>'
,
scope
:
modalScope
,
backdrop
:
'static'
});
return
;
}
var
view
=
payload
.
src
;
var
view
=
payload
.
src
;
if
(
view
.
indexOf
(
'.html'
)
>
0
)
{
if
(
view
.
indexOf
(
'.html'
)
>
0
)
{
view
=
$
(
'<div class="tabbed-view" ng-include="'
+
"'"
+
view
+
"'"
+
'"></div>'
);
view
=
$
(
'<div class="tabbed-view" ng-include="'
+
"'"
+
view
+
"'"
+
'"></div>'
);
...
...
public/app/core/services/datasource_srv.js
View file @
7cd663bb
...
@@ -81,11 +81,11 @@ function (angular, _, coreModule, config) {
...
@@ -81,11 +81,11 @@ function (angular, _, coreModule, config) {
_
.
each
(
config
.
datasources
,
function
(
value
,
key
)
{
_
.
each
(
config
.
datasources
,
function
(
value
,
key
)
{
if
(
value
.
meta
&&
value
.
meta
.
metrics
)
{
if
(
value
.
meta
&&
value
.
meta
.
metrics
)
{
metricSources
.
push
({
metricSources
.
push
({
value
:
key
,
name
:
key
,
meta
:
value
.
meta
});
value
:
key
===
config
.
defaultDatasource
?
null
:
key
,
name
:
key
,
if
(
key
===
config
.
defaultDatasource
)
{
met
a
:
value
.
meta
,
met
ricSources
.
push
({
value
:
null
,
name
:
'default'
,
meta
:
value
.
meta
});
}
);
}
}
}
});
});
...
...
public/app/core/services/util_srv.ts
View file @
7cd663bb
...
@@ -30,7 +30,8 @@ export class UtilSrv {
...
@@ -30,7 +30,8 @@ export class UtilSrv {
persist
:
false
,
persist
:
false
,
show
:
false
,
show
:
false
,
scope
:
options
.
scope
,
scope
:
options
.
scope
,
keyboard
:
false
keyboard
:
false
,
backdrop
:
options
.
backdrop
});
});
Promise
.
resolve
(
modal
).
then
(
function
(
modalEl
)
{
Promise
.
resolve
(
modal
).
then
(
function
(
modalEl
)
{
...
...
public/app/features/dashboard/import/import.html
View file @
7cd663bb
...
@@ -84,7 +84,7 @@
...
@@ -84,7 +84,7 @@
</div>
</div>
<div
class=
"gf-form-button-row"
>
<div
class=
"gf-form-button-row"
>
<button
type=
"button"
class=
"btn gf-form-btn width-10"
ng-click=
"ctrl.saveDashboard()"
ng-class=
"{'btn-danger': ctrl.nameExists, 'btn-success': !ctrl.nameExists}"
ng-disable
=
"!ctrl.inputsOk
"
>
<button
type=
"button"
class=
"btn gf-form-btn width-10"
ng-click=
"ctrl.saveDashboard()"
ng-class=
"{'btn-danger': ctrl.nameExists, 'btn-success': !ctrl.nameExists}"
ng-disable
d=
"!ctrl.inputsValid
"
>
<i
class=
"fa fa-save"
></i>
Save
&
Open
<i
class=
"fa fa-save"
></i>
Save
&
Open
</button>
</button>
<a
class=
"btn btn-link"
ng-click=
"dismiss()"
>
Cancel
</a>
<a
class=
"btn btn-link"
ng-click=
"dismiss()"
>
Cancel
</a>
...
...
public/app/features/dashboard/import/import.ts
View file @
7cd663bb
...
@@ -12,7 +12,6 @@ export class DashImportCtrl {
...
@@ -12,7 +12,6 @@ export class DashImportCtrl {
parseError
:
string
;
parseError
:
string
;
nameExists
:
boolean
;
nameExists
:
boolean
;
dash
:
any
;
dash
:
any
;
dismiss
:
any
;
inputs
:
any
[];
inputs
:
any
[];
inputsValid
:
boolean
;
inputsValid
:
boolean
;
...
@@ -33,6 +32,7 @@ export class DashImportCtrl {
...
@@ -33,6 +32,7 @@ export class DashImportCtrl {
var
inputModel
=
{
var
inputModel
=
{
name
:
input
.
name
,
name
:
input
.
name
,
type
:
input
.
type
,
type
:
input
.
type
,
pluginId
:
input
.
pluginId
,
options
:
[]
options
:
[]
};
};
...
@@ -64,7 +64,7 @@ export class DashImportCtrl {
...
@@ -64,7 +64,7 @@ export class DashImportCtrl {
});
});
}
}
input
Option
Changed
()
{
input
Value
Changed
()
{
this
.
inputsValid
=
true
;
this
.
inputsValid
=
true
;
for
(
let
input
of
this
.
inputs
)
{
for
(
let
input
of
this
.
inputs
)
{
if
(
!
input
.
value
)
{
if
(
!
input
.
value
)
{
...
@@ -86,9 +86,22 @@ export class DashImportCtrl {
...
@@ -86,9 +86,22 @@ export class DashImportCtrl {
}
}
saveDashboard
()
{
saveDashboard
()
{
return
this
.
backendSrv
.
saveDashboard
(
this
.
dash
,
{
overwrite
:
true
}).
then
(
res
=>
{
var
inputs
=
this
.
inputs
.
map
(
input
=>
{
this
.
$location
.
url
(
'dashboard/db/'
+
res
.
slug
);
return
{
this
.
dismiss
();
name
:
input
.
name
,
type
:
input
.
type
,
pluginId
:
input
.
pluginId
,
value
:
input
.
value
};
});
return
this
.
backendSrv
.
post
(
'api/dashboards/import'
,
{
dashboard
:
this
.
dash
,
overwrite
:
true
,
inputs
:
inputs
}).
then
(
res
=>
{
this
.
$location
.
url
(
'dashboard/'
+
res
.
importedUri
);
this
.
$scope
.
dismiss
();
});
});
}
}
...
...
public/app/features/plugins/import_list/import_list.html
View file @
7cd663bb
...
@@ -6,27 +6,27 @@
...
@@ -6,27 +6,27 @@
<i
class=
"icon-gf icon-gf-dashboard"
></i>
<i
class=
"icon-gf icon-gf-dashboard"
></i>
</td>
</td>
<td>
<td>
<a
href=
"dashboard/{{dash.i
nstalledUri}}"
ng-show=
"dash.install
ed"
>
<a
href=
"dashboard/{{dash.i
mportedUri}}"
ng-show=
"dash.import
ed"
>
{{dash.title}}
{{dash.title}}
</a>
</a>
<span
ng-show=
"!dash.i
nstall
ed"
>
<span
ng-show=
"!dash.i
mport
ed"
>
{{dash.title}}
{{dash.title}}
</span>
</span>
</td>
</td>
<td>
<td>
v{{dash.revision}}
v{{dash.revision}}
<span
ng-if=
"dash.installed"
>
<span
ng-if=
"dash.installed"
>
(Imported v{{dash.i
nstall
edRevision}})
(Imported v{{dash.i
mport
edRevision}})
<span>
<span>
</td>
</td>
<td
style=
"text-align: right"
>
<td
style=
"text-align: right"
>
<button
class=
"btn btn-secondary"
ng-click=
"ctrl.import(dash, false)"
ng-show=
"!dash.i
nstall
ed"
>
<button
class=
"btn btn-secondary"
ng-click=
"ctrl.import(dash, false)"
ng-show=
"!dash.i
mport
ed"
>
Import
Import
</button>
</button>
<button
class=
"btn btn-secondary"
ng-click=
"ctrl.import(dash, true)"
ng-show=
"dash.i
nstall
ed"
>
<button
class=
"btn btn-secondary"
ng-click=
"ctrl.import(dash, true)"
ng-show=
"dash.i
mport
ed"
>
Update
Update
</button>
</button>
<button
class=
"btn btn-danger"
ng-click=
"ctrl.remove(dash)"
ng-show=
"dash.i
nstall
ed"
>
<button
class=
"btn btn-danger"
ng-click=
"ctrl.remove(dash)"
ng-show=
"dash.i
mport
ed"
>
Delete
Delete
</button>
</button>
</td>
</td>
...
...
public/app/features/plugins/import_list/import_list.ts
View file @
7cd663bb
...
@@ -61,15 +61,15 @@ export class DashImportListCtrl {
...
@@ -61,15 +61,15 @@ export class DashImportListCtrl {
}
}
return
this
.
backendSrv
.
post
(
`/api/dashboards/import`
,
installCmd
).
then
(
res
=>
{
return
this
.
backendSrv
.
post
(
`/api/dashboards/import`
,
installCmd
).
then
(
res
=>
{
this
.
$rootScope
.
appEvent
(
'alert-success'
,
[
'Dashboard I
nstall
ed'
,
dash
.
title
]);
this
.
$rootScope
.
appEvent
(
'alert-success'
,
[
'Dashboard I
mport
ed'
,
dash
.
title
]);
_
.
extend
(
dash
,
res
);
_
.
extend
(
dash
,
res
);
});
});
}
}
remove
(
dash
)
{
remove
(
dash
)
{
this
.
backendSrv
.
delete
(
'/api/dashboards/'
+
dash
.
i
nstall
edUri
).
then
(()
=>
{
this
.
backendSrv
.
delete
(
'/api/dashboards/'
+
dash
.
i
mport
edUri
).
then
(()
=>
{
this
.
$rootScope
.
appEvent
(
'alert-success'
,
[
'Dashboard Deleted'
,
dash
.
title
]);
this
.
$rootScope
.
appEvent
(
'alert-success'
,
[
'Dashboard Deleted'
,
dash
.
title
]);
dash
.
i
nstall
ed
=
false
;
dash
.
i
mport
ed
=
false
;
});
});
}
}
}
}
...
...
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