From 39af588a94051eab253ef52fae06598ac62f5f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 22 Sep 2016 10:00:09 +0200 Subject: [PATCH] fix(playlist): fixed sorting issue with playlist playback, fixes #5467 --- CHANGELOG.md | 3 ++ pkg/api/dtos/playlist.go | 23 +++++++++++++++ pkg/api/playlist_play.go | 29 ++++++++++++------- pkg/models/playlist.go | 11 ------- .../features/playlist/partials/playlist.html | 4 +-- .../app/features/playlist/playlist_search.ts | 2 +- 6 files changed, 48 insertions(+), 24 deletions(-) create mode 100644 pkg/api/dtos/playlist.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 92f4ddfc586..d2609d8f7be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * **Influxdb**: Add support for elapsed(), closes [#5827](https://github.com/grafana/grafana/pull/5827) * **OAuth**: Add support for generic oauth, closes [#4718](https://github.com/grafana/grafana/pull/4718) * **Cloudwatch**: Add support to expand multi select template variable, closes [#5003](https://github.com/grafana/grafana/pull/5003) +* **Graph Panel**: Now supports flexible lower/upper bounds on Y-Max and Y-Min, PR [#5720](https://github.com/grafana/grafana/pull/5720) ### Breaking changes * **SystemD**: Change systemd description, closes [#5971](https://github.com/grafana/grafana/pull/5971) @@ -20,6 +21,8 @@ ### Bugfixes * **Table Panel**: Fixed problem when switching to Mixed datasource in metrics tab, fixes [#5999](https://github.com/grafana/grafana/pull/5999) +* **Playlist**: Fixed problem with play order not matching order defined in playlist, fixes [#5467](https://github.com/grafana/grafana/pull/5467) +* **Graph panel**: Fixed problem with auto decimals on y axis when datamin=datamax, fixes [#6070](https://github.com/grafana/grafana/pull/6070) # 3.1.2 (unreleased) * **Templating**: Fixed issue when combining row & panel repeats, fixes [#5790](https://github.com/grafana/grafana/issues/5790) diff --git a/pkg/api/dtos/playlist.go b/pkg/api/dtos/playlist.go new file mode 100644 index 00000000000..317ff83339a --- /dev/null +++ b/pkg/api/dtos/playlist.go @@ -0,0 +1,23 @@ +package dtos + +type PlaylistDashboard struct { + Id int64 `json:"id"` + Slug string `json:"slug"` + Title string `json:"title"` + Uri string `json:"uri"` + Order int `json:"order"` +} + +type PlaylistDashboardsSlice []PlaylistDashboard + +func (slice PlaylistDashboardsSlice) Len() int { + return len(slice) +} + +func (slice PlaylistDashboardsSlice) Less(i, j int) bool { + return slice[i].Order < slice[j].Order +} + +func (slice PlaylistDashboardsSlice) Swap(i, j int) { + slice[i], slice[j] = slice[j], slice[i] +} diff --git a/pkg/api/playlist_play.go b/pkg/api/playlist_play.go index e4feb3442fb..780767531a8 100644 --- a/pkg/api/playlist_play.go +++ b/pkg/api/playlist_play.go @@ -1,16 +1,18 @@ package api import ( + "sort" "strconv" + "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/bus" _ "github.com/grafana/grafana/pkg/log" m "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/search" ) -func populateDashboardsById(dashboardByIds []int64) ([]m.PlaylistDashboardDto, error) { - result := make([]m.PlaylistDashboardDto, 0) +func populateDashboardsById(dashboardByIds []int64, dashboardIdOrder map[int64]int) (dtos.PlaylistDashboardsSlice, error) { + result := make(dtos.PlaylistDashboardsSlice, 0) if len(dashboardByIds) > 0 { dashboardQuery := m.GetDashboardsQuery{DashboardIds: dashboardByIds} @@ -19,11 +21,12 @@ func populateDashboardsById(dashboardByIds []int64) ([]m.PlaylistDashboardDto, e } for _, item := range dashboardQuery.Result { - result = append(result, m.PlaylistDashboardDto{ + result = append(result, dtos.PlaylistDashboard{ Id: item.Id, Slug: item.Slug, Title: item.Title, Uri: "db/" + item.Slug, + Order: dashboardIdOrder[item.Id], }) } } @@ -31,8 +34,8 @@ func populateDashboardsById(dashboardByIds []int64) ([]m.PlaylistDashboardDto, e return result, nil } -func populateDashboardsByTag(orgId, userId int64, dashboardByTag []string) []m.PlaylistDashboardDto { - result := make([]m.PlaylistDashboardDto, 0) +func populateDashboardsByTag(orgId, userId int64, dashboardByTag []string, dashboardTagOrder map[string]int) dtos.PlaylistDashboardsSlice { + result := make(dtos.PlaylistDashboardsSlice, 0) if len(dashboardByTag) > 0 { for _, tag := range dashboardByTag { @@ -47,10 +50,11 @@ func populateDashboardsByTag(orgId, userId int64, dashboardByTag []string) []m.P if err := bus.Dispatch(&searchQuery); err == nil { for _, item := range searchQuery.Result { - result = append(result, m.PlaylistDashboardDto{ + result = append(result, dtos.PlaylistDashboard{ Id: item.Id, Title: item.Title, Uri: item.Uri, + Order: dashboardTagOrder[tag], }) } } @@ -60,28 +64,33 @@ func populateDashboardsByTag(orgId, userId int64, dashboardByTag []string) []m.P return result } -func LoadPlaylistDashboards(orgId, userId, playlistId int64) ([]m.PlaylistDashboardDto, error) { +func LoadPlaylistDashboards(orgId, userId, playlistId int64) (dtos.PlaylistDashboardsSlice, error) { playlistItems, _ := LoadPlaylistItems(playlistId) 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) dashboardByIds = append(dashboardByIds, dashboardId) + dashboardIdOrder[dashboardId] = i.Order } if i.Type == "dashboard_by_tag" { dashboardByTag = append(dashboardByTag, i.Value) + dashboardTagOrder[i.Value] = i.Order } } - result := make([]m.PlaylistDashboardDto, 0) + result := make(dtos.PlaylistDashboardsSlice, 0) - var k, _ = populateDashboardsById(dashboardByIds) + var k, _ = populateDashboardsById(dashboardByIds, dashboardIdOrder) result = append(result, k...) - result = append(result, populateDashboardsByTag(orgId, userId, dashboardByTag)...) + result = append(result, populateDashboardsByTag(orgId, userId, dashboardByTag, dashboardTagOrder)...) + sort.Sort(sort.Reverse(result)) return result, nil } diff --git a/pkg/models/playlist.go b/pkg/models/playlist.go index 4c6eacbb6a6..5c49bb9256c 100644 --- a/pkg/models/playlist.go +++ b/pkg/models/playlist.go @@ -57,17 +57,6 @@ func (this PlaylistDashboard) TableName() string { type Playlists []*Playlist type PlaylistDashboards []*PlaylistDashboard -// -// DTOS -// - -type PlaylistDashboardDto struct { - Id int64 `json:"id"` - Slug string `json:"slug"` - Title string `json:"title"` - Uri string `json:"uri"` -} - // // COMMANDS // diff --git a/public/app/features/playlist/partials/playlist.html b/public/app/features/playlist/partials/playlist.html index 08c31522b7f..6dfb8b2f8e0 100644 --- a/public/app/features/playlist/partials/playlist.html +++ b/public/app/features/playlist/partials/playlist.html @@ -25,7 +25,7 @@
-
+
Available
@@ -72,7 +72,7 @@
-
+
Selected
diff --git a/public/app/features/playlist/playlist_search.ts b/public/app/features/playlist/playlist_search.ts index e00c2cb3a36..b0ccd58eaeb 100644 --- a/public/app/features/playlist/playlist_search.ts +++ b/public/app/features/playlist/playlist_search.ts @@ -14,7 +14,7 @@ export class PlaylistSearchCtrl { /** @ngInject */ constructor(private $scope, private $location, private $timeout, private backendSrv, private contextSrv) { - this.query = { query: '', tag: [], starred: false }; + this.query = {query: '', tag: [], starred: false, limit: 30}; $timeout(() => { this.query.query = '';