|
|
@@ -49,7 +49,7 @@ func GetDashboard(c *middleware.Context) {
|
|
|
|
|
|
dash := query.Result
|
|
|
|
|
|
- // Finding the last creator and updater of the dashboard
|
|
|
+ // Finding creator and last updater of the dashboard
|
|
|
updater, creator := "Anonymous", "Anonymous"
|
|
|
if dash.UpdatedBy > 0 {
|
|
|
updater = getUserLogin(dash.UpdatedBy)
|
|
|
@@ -58,19 +58,26 @@ func GetDashboard(c *middleware.Context) {
|
|
|
creator = getUserLogin(dash.CreatedBy)
|
|
|
}
|
|
|
|
|
|
+ // Finding total panels and queries on the dashboard
|
|
|
+ totalRows, totalPanels, totalQueries := getTotalRowsPanelsAndQueries(dash.Data)
|
|
|
+
|
|
|
dto := dtos.DashboardFullWithMeta{
|
|
|
Dashboard: dash.Data,
|
|
|
Meta: dtos.DashboardMeta{
|
|
|
- IsStarred: isStarred,
|
|
|
- Slug: slug,
|
|
|
- Type: m.DashTypeDB,
|
|
|
- CanStar: c.IsSignedIn,
|
|
|
- CanSave: c.OrgRole == m.ROLE_ADMIN || c.OrgRole == m.ROLE_EDITOR,
|
|
|
- CanEdit: canEditDashboard(c.OrgRole),
|
|
|
- Created: dash.Created,
|
|
|
- Updated: dash.Updated,
|
|
|
- UpdatedBy: updater,
|
|
|
- CreatedBy: creator,
|
|
|
+ IsStarred: isStarred,
|
|
|
+ Slug: slug,
|
|
|
+ Type: m.DashTypeDB,
|
|
|
+ CanStar: c.IsSignedIn,
|
|
|
+ CanSave: c.OrgRole == m.ROLE_ADMIN || c.OrgRole == m.ROLE_EDITOR,
|
|
|
+ CanEdit: canEditDashboard(c.OrgRole),
|
|
|
+ Created: dash.Created,
|
|
|
+ Updated: dash.Updated,
|
|
|
+ UpdatedBy: updater,
|
|
|
+ CreatedBy: creator,
|
|
|
+ TotalRows: totalRows,
|
|
|
+ TotalPanels: totalPanels,
|
|
|
+ TotalQueries: totalQueries,
|
|
|
+ Version: dash.Version,
|
|
|
},
|
|
|
}
|
|
|
|
|
|
@@ -88,6 +95,26 @@ func getUserLogin(userId int64) string {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func getTotalRowsPanelsAndQueries(data map[string]interface{}) (int, int, int) {
|
|
|
+ totalRows, totalPanels, totalQueries := 0, 0, 0
|
|
|
+ if rows, rowsOk := data["rows"]; rowsOk {
|
|
|
+ totalRows = len(rows.([]interface{}))
|
|
|
+ if totalRows > 0 {
|
|
|
+ for _, rowElement := range rows.([]interface{}) {
|
|
|
+ if panels, panelsOk := rowElement.(map[string]interface{})["panels"]; panelsOk {
|
|
|
+ totalPanels += len(panels.([]interface{}))
|
|
|
+ for _, panelElement := range panels.([]interface{}) {
|
|
|
+ if targets, targetsOk := panelElement.(map[string]interface{})["targets"]; targetsOk {
|
|
|
+ totalQueries += len(targets.([]interface{}))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return totalRows, totalPanels, totalQueries
|
|
|
+}
|
|
|
+
|
|
|
func DeleteDashboard(c *middleware.Context) {
|
|
|
slug := c.Params(":slug")
|
|
|
|