Browse Source

fix(playlist): fixed sorting issue with playlist playback, fixes #5467

Torkel Ödegaard 9 years ago
parent
commit
39af588a94

+ 3 - 0
CHANGELOG.md

@@ -13,6 +13,7 @@
 * **Influxdb**: Add support for elapsed(), closes [#5827](https://github.com/grafana/grafana/pull/5827)
 * **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)
 * **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)
 * **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
 ### Breaking changes
 * **SystemD**: Change systemd description, closes [#5971](https://github.com/grafana/grafana/pull/5971)
 * **SystemD**: Change systemd description, closes [#5971](https://github.com/grafana/grafana/pull/5971)
@@ -20,6 +21,8 @@
 
 
 ### Bugfixes
 ### Bugfixes
 * **Table Panel**: Fixed problem when switching to Mixed datasource in metrics tab, fixes [#5999](https://github.com/grafana/grafana/pull/5999)
 * **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)
 # 3.1.2 (unreleased)
 * **Templating**: Fixed issue when combining row & panel repeats, fixes [#5790](https://github.com/grafana/grafana/issues/5790)
 * **Templating**: Fixed issue when combining row & panel repeats, fixes [#5790](https://github.com/grafana/grafana/issues/5790)

+ 23 - 0
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]
+}

+ 19 - 10
pkg/api/playlist_play.go

@@ -1,16 +1,18 @@
 package api
 package api
 
 
 import (
 import (
+	"sort"
 	"strconv"
 	"strconv"
 
 
+	"github.com/grafana/grafana/pkg/api/dtos"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	_ "github.com/grafana/grafana/pkg/log"
 	_ "github.com/grafana/grafana/pkg/log"
 	m "github.com/grafana/grafana/pkg/models"
 	m "github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/search"
 	"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 {
 	if len(dashboardByIds) > 0 {
 		dashboardQuery := m.GetDashboardsQuery{DashboardIds: dashboardByIds}
 		dashboardQuery := m.GetDashboardsQuery{DashboardIds: dashboardByIds}
@@ -19,11 +21,12 @@ func populateDashboardsById(dashboardByIds []int64) ([]m.PlaylistDashboardDto, e
 		}
 		}
 
 
 		for _, item := range dashboardQuery.Result {
 		for _, item := range dashboardQuery.Result {
-			result = append(result, m.PlaylistDashboardDto{
+			result = append(result, dtos.PlaylistDashboard{
 				Id:    item.Id,
 				Id:    item.Id,
 				Slug:  item.Slug,
 				Slug:  item.Slug,
 				Title: item.Title,
 				Title: item.Title,
 				Uri:   "db/" + item.Slug,
 				Uri:   "db/" + item.Slug,
+				Order: dashboardIdOrder[item.Id],
 			})
 			})
 		}
 		}
 	}
 	}
@@ -31,8 +34,8 @@ func populateDashboardsById(dashboardByIds []int64) ([]m.PlaylistDashboardDto, e
 	return result, nil
 	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 {
 	if len(dashboardByTag) > 0 {
 		for _, tag := range dashboardByTag {
 		for _, tag := range dashboardByTag {
@@ -47,10 +50,11 @@ func populateDashboardsByTag(orgId, userId int64, dashboardByTag []string) []m.P
 
 
 			if err := bus.Dispatch(&searchQuery); err == nil {
 			if err := bus.Dispatch(&searchQuery); err == nil {
 				for _, item := range searchQuery.Result {
 				for _, item := range searchQuery.Result {
-					result = append(result, m.PlaylistDashboardDto{
+					result = append(result, dtos.PlaylistDashboard{
 						Id:    item.Id,
 						Id:    item.Id,
 						Title: item.Title,
 						Title: item.Title,
 						Uri:   item.Uri,
 						Uri:   item.Uri,
+						Order: dashboardTagOrder[tag],
 					})
 					})
 				}
 				}
 			}
 			}
@@ -60,28 +64,33 @@ func populateDashboardsByTag(orgId, userId int64, dashboardByTag []string) []m.P
 	return result
 	return result
 }
 }
 
 
-func LoadPlaylistDashboards(orgId, userId, playlistId int64) ([]m.PlaylistDashboardDto, error) {
+func LoadPlaylistDashboards(orgId, userId, playlistId int64) (dtos.PlaylistDashboardsSlice, error) {
 	playlistItems, _ := LoadPlaylistItems(playlistId)
 	playlistItems, _ := LoadPlaylistItems(playlistId)
 
 
 	dashboardByIds := make([]int64, 0)
 	dashboardByIds := make([]int64, 0)
 	dashboardByTag := make([]string, 0)
 	dashboardByTag := make([]string, 0)
+	dashboardIdOrder := make(map[int64]int)
+	dashboardTagOrder := make(map[string]int)
 
 
 	for _, i := range playlistItems {
 	for _, i := range playlistItems {
 		if i.Type == "dashboard_by_id" {
 		if i.Type == "dashboard_by_id" {
 			dashboardId, _ := strconv.ParseInt(i.Value, 10, 64)
 			dashboardId, _ := strconv.ParseInt(i.Value, 10, 64)
 			dashboardByIds = append(dashboardByIds, dashboardId)
 			dashboardByIds = append(dashboardByIds, dashboardId)
+			dashboardIdOrder[dashboardId] = i.Order
 		}
 		}
 
 
 		if i.Type == "dashboard_by_tag" {
 		if i.Type == "dashboard_by_tag" {
 			dashboardByTag = append(dashboardByTag, i.Value)
 			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, k...)
-	result = append(result, populateDashboardsByTag(orgId, userId, dashboardByTag)...)
+	result = append(result, populateDashboardsByTag(orgId, userId, dashboardByTag, dashboardTagOrder)...)
 
 
+	sort.Sort(sort.Reverse(result))
 	return result, nil
 	return result, nil
 }
 }

+ 0 - 11
pkg/models/playlist.go

@@ -57,17 +57,6 @@ func (this PlaylistDashboard) TableName() string {
 type Playlists []*Playlist
 type Playlists []*Playlist
 type PlaylistDashboards []*PlaylistDashboard
 type PlaylistDashboards []*PlaylistDashboard
 
 
-//
-// DTOS
-//
-
-type PlaylistDashboardDto struct {
-	Id    int64  `json:"id"`
-	Slug  string `json:"slug"`
-	Title string `json:"title"`
-	Uri   string `json:"uri"`
-}
-
 //
 //
 // COMMANDS
 // COMMANDS
 //
 //

+ 2 - 2
public/app/features/playlist/partials/playlist.html

@@ -25,7 +25,7 @@
 	</div>
 	</div>
 
 
 	<div class="row">
 	<div class="row">
-		<div class="col-md-6">
+		<div class="col-lg-6">
 			<div class="playlist-search-containerwrapper">
 			<div class="playlist-search-containerwrapper">
 				<div class="max-width-32">
 				<div class="max-width-32">
 					<h5 class="page-headering playlist-column-header">Available</h5>
 					<h5 class="page-headering playlist-column-header">Available</h5>
@@ -72,7 +72,7 @@
 			</div>
 			</div>
 		</div>
 		</div>
 
 
-		<div class="col-md-6">
+		<div class="col-lg-6">
 			<h5 class="page headering playlist-column-header">Selected</h5>
 			<h5 class="page headering playlist-column-header">Selected</h5>
 			<table class="grafana-options-table playlist-available-list">
 			<table class="grafana-options-table playlist-available-list">
 				<tr ng-repeat="playlistItem in ctrl.playlistItems">
 				<tr ng-repeat="playlistItem in ctrl.playlistItems">

+ 1 - 1
public/app/features/playlist/playlist_search.ts

@@ -14,7 +14,7 @@ export class PlaylistSearchCtrl {
 
 
   /** @ngInject */
   /** @ngInject */
   constructor(private $scope, private $location, private $timeout, private backendSrv, private contextSrv) {
   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(() => {
     $timeout(() => {
       this.query.query = '';
       this.query.query = '';