mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Playlist: update service so it supports both read+write (#55959)
This commit is contained in:
@@ -2,12 +2,14 @@ package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
_ "github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/playlist"
|
||||
"github.com/grafana/grafana/pkg/services/search"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
)
|
||||
@@ -68,28 +70,37 @@ func (hs *HTTPServer) populateDashboardsByTag(ctx context.Context, orgID int64,
|
||||
|
||||
// Deprecated -- the frontend can do this better
|
||||
func (hs *HTTPServer) LoadPlaylistDashboards(ctx context.Context, orgID int64, signedInUser *user.SignedInUser, playlistUID string) (dtos.PlaylistDashboardsSlice, error) {
|
||||
playlistItems, _ := hs.LoadPlaylistItems(ctx, playlistUID, orgID)
|
||||
result := make(dtos.PlaylistDashboardsSlice, 0)
|
||||
dto, err := hs.playlistService.Get(ctx,
|
||||
&playlist.GetPlaylistByUidQuery{UID: playlistUID, OrgId: orgID})
|
||||
if err != nil || dto == nil || dto.Items == nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
playlistItems := *dto.Items
|
||||
|
||||
dashboardByIDs := make([]int64, 0)
|
||||
dashboardByTag := make([]string, 0)
|
||||
dashboardIDOrder := make(map[int64]int)
|
||||
dashboardTagOrder := make(map[string]int)
|
||||
|
||||
for _, i := range playlistItems {
|
||||
if i.Type == "dashboard_by_id" {
|
||||
dashboardID, _ := strconv.ParseInt(i.Value, 10, 64)
|
||||
for i, item := range playlistItems {
|
||||
if item.Type == "dashboard_by_id" {
|
||||
dashboardID, _ := strconv.ParseInt(item.Value, 10, 64)
|
||||
dashboardByIDs = append(dashboardByIDs, dashboardID)
|
||||
dashboardIDOrder[dashboardID] = i.Order
|
||||
dashboardIDOrder[dashboardID] = i
|
||||
}
|
||||
|
||||
if i.Type == "dashboard_by_tag" {
|
||||
dashboardByTag = append(dashboardByTag, i.Value)
|
||||
dashboardTagOrder[i.Value] = i.Order
|
||||
if item.Type == "dashboard_by_tag" {
|
||||
dashboardByTag = append(dashboardByTag, item.Value)
|
||||
dashboardTagOrder[item.Value] = i
|
||||
}
|
||||
|
||||
if item.Type == "dashboard_by_uid" {
|
||||
return nil, fmt.Errorf("dashboard_by_uid not supported by this deprecated API")
|
||||
}
|
||||
}
|
||||
|
||||
result := make(dtos.PlaylistDashboardsSlice, 0)
|
||||
|
||||
var k, _ = hs.populateDashboardsByID(ctx, dashboardByIDs, dashboardIDOrder)
|
||||
result = append(result, k...)
|
||||
result = append(result, hs.populateDashboardsByTag(ctx, orgID, signedInUser, dashboardByTag, dashboardTagOrder)...)
|
||||
|
||||
Reference in New Issue
Block a user