mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix(playlist): move backend code to ctrl
data loading should be done in the ctrl
This commit is contained in:
parent
01a910fedc
commit
d15b0bf4c4
@ -8,14 +8,29 @@ function (angular, config, _) {
|
||||
|
||||
var module = angular.module('grafana.controllers');
|
||||
|
||||
module.controller('PlaylistEditCtrl', function(
|
||||
playlist,
|
||||
dashboards,
|
||||
$scope,
|
||||
playlistSrv,
|
||||
backendSrv,
|
||||
$location
|
||||
) {
|
||||
module.controller('PlaylistEditCtrl', function($scope, playlistSrv, backendSrv, $location, $route) {
|
||||
$scope.timespan = config.playlist_timespan;
|
||||
$scope.filteredDashboards = [];
|
||||
$scope.foundDashboards = [];
|
||||
$scope.searchQuery = '';
|
||||
$scope.loading = false;
|
||||
$scope.playlist = {};
|
||||
$scope.dashboards = [];
|
||||
|
||||
if ($route.current.params.id) {
|
||||
var playlistId = $route.current.params.id;
|
||||
|
||||
backendSrv.get('/api/playlists/' + playlistId)
|
||||
.then(function(result) {
|
||||
$scope.playlist = result;
|
||||
});
|
||||
|
||||
backendSrv.get('/api/playlists/' + playlistId + '/dashboards')
|
||||
.then(function(result) {
|
||||
$scope.dashboards = result;
|
||||
});
|
||||
}
|
||||
|
||||
$scope.search = function() {
|
||||
var query = {starred: true, limit: 10};
|
||||
|
||||
@ -38,19 +53,19 @@ function (angular, config, _) {
|
||||
|
||||
$scope.filterFoundDashboards = function() {
|
||||
$scope.filteredDashboards = _.reject($scope.foundDashboards, function(dashboard) {
|
||||
return _.findWhere(dashboards, function(listDashboard) {
|
||||
return _.findWhere($scope.dashboards, function(listDashboard) {
|
||||
return listDashboard.id === dashboard.id;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.addDashboard = function(dashboard) {
|
||||
dashboards.push(dashboard);
|
||||
$scope.dashboards.push(dashboard);
|
||||
$scope.filterFoundDashboards();
|
||||
};
|
||||
|
||||
$scope.removeDashboard = function(dashboard) {
|
||||
_.remove(dashboards, function(listedDashboard) {
|
||||
_.remove($scope.dashboards, function(listedDashboard) {
|
||||
return dashboard === listedDashboard;
|
||||
});
|
||||
$scope.filterFoundDashboards();
|
||||
@ -80,7 +95,7 @@ function (angular, config, _) {
|
||||
};
|
||||
|
||||
$scope.isNew = function() {
|
||||
return !playlist.id;
|
||||
return !$scope.playlist.id;
|
||||
};
|
||||
|
||||
$scope.startPlaylist = function(playlist, dashboards) {
|
||||
@ -88,7 +103,7 @@ function (angular, config, _) {
|
||||
};
|
||||
|
||||
$scope.isPlaylistEmpty = function() {
|
||||
return !dashboards.length;
|
||||
return !$scope.dashboards.length;
|
||||
};
|
||||
|
||||
$scope.isSearchResultsEmpty = function() {
|
||||
@ -108,12 +123,12 @@ function (angular, config, _) {
|
||||
};
|
||||
|
||||
$scope.moveDashboard = function(dashboard, offset) {
|
||||
var currentPosition = dashboards.indexOf(dashboard);
|
||||
var currentPosition = $scope.dashboards.indexOf(dashboard);
|
||||
var newPosition = currentPosition + offset;
|
||||
|
||||
if (newPosition >= 0 && newPosition < dashboards.length) {
|
||||
dashboards.splice(currentPosition, 1);
|
||||
dashboards.splice(newPosition, 0, dashboard);
|
||||
if (newPosition >= 0 && newPosition < $scope.dashboards.length) {
|
||||
$scope.dashboards.splice(currentPosition, 1);
|
||||
$scope.dashboards.splice(newPosition, 0, dashboard);
|
||||
}
|
||||
};
|
||||
|
||||
@ -125,13 +140,6 @@ function (angular, config, _) {
|
||||
$scope.moveDashboard(dashboard, 1);
|
||||
};
|
||||
|
||||
$scope.playlist = playlist;
|
||||
$scope.dashboards = dashboards;
|
||||
$scope.timespan = config.playlist_timespan;
|
||||
$scope.filteredDashboards = [];
|
||||
$scope.foundDashboards = [];
|
||||
$scope.searchQuery = '';
|
||||
$scope.loading = false;
|
||||
$scope.search();
|
||||
});
|
||||
});
|
||||
|
@ -16,31 +16,11 @@ function (angular, config, _) {
|
||||
})
|
||||
.when('/playlists/create', {
|
||||
templateUrl: 'app/features/playlist/partials/playlist.html',
|
||||
controller : 'PlaylistEditCtrl',
|
||||
resolve: {
|
||||
playlist: function() {
|
||||
return {};
|
||||
},
|
||||
dashboards: function() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
controller : 'PlaylistEditCtrl'
|
||||
})
|
||||
.when('/playlists/edit/:id', {
|
||||
templateUrl: 'app/features/playlist/partials/playlist.html',
|
||||
controller : 'PlaylistEditCtrl',
|
||||
resolve: {
|
||||
playlist: function(backendSrv, $route) {
|
||||
var playlistId = $route.current.params.id;
|
||||
|
||||
return backendSrv.get('/api/playlists/' + playlistId);
|
||||
},
|
||||
dashboards: function(backendSrv, $route) {
|
||||
var playlistId = $route.current.params.id;
|
||||
|
||||
return backendSrv.get('/api/playlists/' + playlistId + '/dashboards');
|
||||
}
|
||||
}
|
||||
controller : 'PlaylistEditCtrl'
|
||||
})
|
||||
.when('/playlists/play/:id', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
|
@ -12,7 +12,10 @@ function (angular, _) {
|
||||
$location,
|
||||
backendSrv
|
||||
) {
|
||||
$scope.playlists = backendSrv.get('/api/playlists');
|
||||
backendSrv.get('/api/playlists')
|
||||
.then(function(result) {
|
||||
$scope.playlists = result;
|
||||
});
|
||||
|
||||
$scope.playlistUrl = function(playlist) {
|
||||
return '/playlists/play/' + playlist.id;
|
||||
|
Loading…
Reference in New Issue
Block a user