mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(apps): more work on plugin dashboard sync
This commit is contained in:
parent
85be7dd902
commit
68a8d9bc91
@ -130,20 +130,6 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
|
||||
}
|
||||
}
|
||||
|
||||
if !cmd.Overwrite {
|
||||
if autoUpdate, exists := dash.Data.CheckGet("autoUpdate"); exists {
|
||||
message := "Dashboard marked as auto updated."
|
||||
|
||||
if pluginId, err := autoUpdate.Get("pluginId").String(); err == nil {
|
||||
if pluginDef, ok := plugins.Plugins[pluginId]; ok {
|
||||
message = "Dashboard updated automatically when plugin " + pluginDef.Name + " is updated."
|
||||
}
|
||||
}
|
||||
|
||||
return Json(412, util.DynMap{"status": "auto-update-dashboard", "message": message})
|
||||
}
|
||||
}
|
||||
|
||||
err := bus.Dispatch(&cmd)
|
||||
if err != nil {
|
||||
if err == m.ErrDashboardWithSameNameExists {
|
||||
@ -152,6 +138,14 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
|
||||
if err == m.ErrDashboardVersionMismatch {
|
||||
return Json(412, util.DynMap{"status": "version-mismatch", "message": err.Error()})
|
||||
}
|
||||
if pluginErr, ok := err.(m.UpdatePluginDashboardError); ok {
|
||||
message := "Dashboard is belongs to plugin " + pluginErr.PluginId + "."
|
||||
// look up plugin name
|
||||
if pluginDef, exist := plugins.Plugins[pluginErr.PluginId]; exist {
|
||||
message = "Dashboard is belongs to plugin " + pluginDef.Name + "."
|
||||
}
|
||||
return Json(412, util.DynMap{"status": "plugin-dashboard", "message": message})
|
||||
}
|
||||
if err == m.ErrDashboardNotFound {
|
||||
return Json(404, util.DynMap{"status": "not-found", "message": err.Error()})
|
||||
}
|
||||
|
@ -17,6 +17,14 @@ var (
|
||||
ErrDashboardVersionMismatch = errors.New("The dashboard has been changed by someone else")
|
||||
)
|
||||
|
||||
type UpdatePluginDashboardError struct {
|
||||
PluginId string
|
||||
}
|
||||
|
||||
func (d UpdatePluginDashboardError) Error() string {
|
||||
return "Dashboard belong to plugin"
|
||||
}
|
||||
|
||||
var (
|
||||
DashTypeJson = "file"
|
||||
DashTypeDB = "db"
|
||||
|
@ -46,6 +46,11 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
|
||||
return m.ErrDashboardVersionMismatch
|
||||
}
|
||||
}
|
||||
|
||||
// do not allow plugin dashboard updates without overwrite flag
|
||||
if existing.PluginId != "" && cmd.Overwrite == false {
|
||||
return m.UpdatePluginDashboardError{PluginId: existing.PluginId}
|
||||
}
|
||||
}
|
||||
|
||||
sameTitleExists, err := sess.Where("org_id=? AND slug=?", dash.OrgId, dash.Slug).Get(&sameTitle)
|
||||
|
@ -135,13 +135,13 @@ export class DashNavCtrl {
|
||||
});
|
||||
}
|
||||
|
||||
if (err.data && err.data.status === "auto-update-dashboard") {
|
||||
if (err.data && err.data.status === "plugin-dashboard") {
|
||||
err.isHandled = true;
|
||||
|
||||
$scope.appEvent('confirm-modal', {
|
||||
title: 'Auto Update Dashboard',
|
||||
title: 'Plugin Dashboard',
|
||||
text: err.data.message,
|
||||
text2: 'Use Save As... to create copy or ignore this warning.',
|
||||
text2: 'Your changes will be overwritten next time you update the plugin. Use Save As to create custom version.',
|
||||
yesText: "Save & Overwrite",
|
||||
icon: "fa-warning",
|
||||
onConfirm: function() {
|
||||
|
@ -105,7 +105,7 @@
|
||||
}
|
||||
|
||||
.confirm-modal-text2 {
|
||||
font-size: $font-size-h5;
|
||||
font-size: $font-size-root;
|
||||
padding-top: $spacer;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user