feat(apps): plugin dashboard sync is starting to work
This commit is contained in:
@@ -14,6 +14,7 @@ type PluginDashboardInfoDTO struct {
|
|||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Imported bool `json:"imported"`
|
Imported bool `json:"imported"`
|
||||||
ImportedUri string `json:"importedUri"`
|
ImportedUri string `json:"importedUri"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
ImportedRevision int64 `json:"importedRevision"`
|
ImportedRevision int64 `json:"importedRevision"`
|
||||||
Revision int64 `json:"revision"`
|
Revision int64 `json:"revision"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
@@ -36,6 +37,8 @@ func GetPluginDashboards(orgId int64, pluginId string) ([]*PluginDashboardInfoDT
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
existingMatches := make(map[int64]bool)
|
||||||
|
|
||||||
for _, include := range plugin.Includes {
|
for _, include := range plugin.Includes {
|
||||||
if include.Type != PluginTypeDashboard {
|
if include.Type != PluginTypeDashboard {
|
||||||
continue
|
continue
|
||||||
@@ -60,12 +63,23 @@ func GetPluginDashboards(orgId int64, pluginId string) ([]*PluginDashboardInfoDT
|
|||||||
res.Imported = true
|
res.Imported = true
|
||||||
res.ImportedUri = "db/" + existingDash.Slug
|
res.ImportedUri = "db/" + existingDash.Slug
|
||||||
res.ImportedRevision = existingDash.Data.Get("revision").MustInt64(1)
|
res.ImportedRevision = existingDash.Data.Get("revision").MustInt64(1)
|
||||||
|
existingMatches[existingDash.Id] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = append(result, res)
|
result = append(result, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// find deleted dashboards
|
||||||
|
for _, dash := range query.Result {
|
||||||
|
if _, exists := existingMatches[dash.Id]; !exists {
|
||||||
|
result = append(result, &PluginDashboardInfoDTO{
|
||||||
|
Slug: dash.Slug,
|
||||||
|
Removed: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,17 +62,33 @@ func syncPluginDashboards(pluginDef *PluginBase, orgId int64) {
|
|||||||
plog.Info("Syncing plugin dashboards to DB", "pluginId", pluginDef.Id)
|
plog.Info("Syncing plugin dashboards to DB", "pluginId", pluginDef.Id)
|
||||||
|
|
||||||
// Get plugin dashboards
|
// Get plugin dashboards
|
||||||
if dashboards, err := GetPluginDashboards(orgId, pluginDef.Id); err != nil {
|
dashboards, err := GetPluginDashboards(orgId, pluginDef.Id)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
plog.Error("Failed to load app dashboards", "error", err)
|
plog.Error("Failed to load app dashboards", "error", err)
|
||||||
return
|
return
|
||||||
} else {
|
}
|
||||||
// Update dashboards with updated revisions
|
|
||||||
for _, dash := range dashboards {
|
// Update dashboards with updated revisions
|
||||||
if dash.ImportedRevision != dash.Revision {
|
for _, dash := range dashboards {
|
||||||
if err := autoUpdateAppDashboard(dash, orgId); err != nil {
|
// remove removed ones
|
||||||
plog.Error("Failed to auto update app dashboard", "pluginId", pluginDef.Id, "error", err)
|
if dash.Removed {
|
||||||
return
|
plog.Info("Deleting plugin dashboard", "pluginId", pluginDef.Id, "dashboard", dash.Slug)
|
||||||
}
|
|
||||||
|
deleteCmd := m.DeleteDashboardCommand{OrgId: orgId, Slug: dash.Slug}
|
||||||
|
if err := bus.Dispatch(&deleteCmd); err != nil {
|
||||||
|
plog.Error("Failed to auto update app dashboard", "pluginId", pluginDef.Id, "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// update updated ones
|
||||||
|
if dash.ImportedRevision != dash.Revision {
|
||||||
|
if err := autoUpdateAppDashboard(dash, orgId); err != nil {
|
||||||
|
plog.Error("Failed to auto update app dashboard", "pluginId", pluginDef.Id, "error", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user