Browse Source

fix(playlist): move dashboard uri cration to Backend

bergquist 10 years ago
parent
commit
0918063c55

+ 11 - 1
pkg/api/playlist.go

@@ -63,7 +63,17 @@ func GetPlaylistDashboards(c *middleware.Context) Response {
 		return ApiError(500, "Playlist not found", err)
 	}
 
-	return Json(200, query.Result)
+	dtos := make([]m.PlaylistDashboardDto, 0)
+	for _, item := range *query.Result {
+		dtos = append(dtos, m.PlaylistDashboardDto{
+			Id:    item.Id,
+			Slug:  item.Slug,
+			Title: item.Title,
+			Uri:   "db/" + item.Slug,
+		})
+	}
+
+	return Json(200, dtos)
 }
 
 func DeletePlaylist(c *middleware.Context) Response {

+ 11 - 0
pkg/models/playlist.go

@@ -33,6 +33,17 @@ 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
 //

+ 1 - 0
pkg/services/sqlstore/playlist.go

@@ -105,6 +105,7 @@ func GetPlaylistDashboards(query *m.GetPlaylistDashboardsQuery) error {
 	var playlist = m.Playlist{}
 
 	hasPlaylist, err := x.Id(query.Id).Get(&playlist)
+
 	query.Result = &dashboards
 
 	if err != nil {

+ 0 - 3
public/app/features/playlist/playlist_routes.js

@@ -33,9 +33,6 @@ function (angular, config, _) {
               .then(function(playlist) {
                 return backendSrv.get('/api/playlists/' + playlistId + '/dashboards')
                   .then(function(dashboards) {
-                    _.each(dashboards, function(dashboard) {
-                      dashboard.uri = 'db/' + dashboard.slug;
-                    });
                     playlistSrv.start(dashboards, playlist.timespan);
                   });
               });