/*! grafana - v3.1.0 - 2016-07-18
 * Copyright (c) 2016 Torkel Ödegaard; Licensed Apache-2.0 */

System.register(["lodash","../../core/core_module"],function(a){var b,c,d;return{setters:[function(a){b=a},function(a){c=a}],execute:function(){d=function(){function a(a,b,c,d,e){var f=this;if(this.$scope=a,this.playlistSrv=b,this.backendSrv=c,this.$location=d,this.$route=e,this.filteredDashboards=[],this.filteredTags=[],this.searchQuery="",this.loading=!1,this.playlist={interval:"5m"},this.playlistItems=[],this.dashboardresult=[],this.tagresult=[],e.current.params.id){var g=e.current.params.id;c.get("/api/playlists/"+g).then(function(a){f.playlist=a}),c.get("/api/playlists/"+g+"/items").then(function(a){f.playlistItems=a})}}return a.$inject=["$scope","playlistSrv","backendSrv","$location","$route"],a.prototype.filterFoundPlaylistItems=function(){var a=this;this.filteredDashboards=b["default"].reject(this.dashboardresult,function(c){return b["default"].findWhere(a.playlistItems,function(a){return parseInt(a.value)===c.id})}),this.filteredTags=b["default"].reject(this.tagresult,function(c){return b["default"].findWhere(a.playlistItems,function(a){return a.value===c.term})})},a.prototype.addPlaylistItem=function(a){a.value=a.id.toString(),a.type="dashboard_by_id",a.order=this.playlistItems.length+1,this.playlistItems.push(a),this.filterFoundPlaylistItems()},a.prototype.addTagPlaylistItem=function(a){var b={value:a.term,type:"dashboard_by_tag",order:this.playlistItems.length+1,title:a.term};this.playlistItems.push(b),this.filterFoundPlaylistItems()},a.prototype.removePlaylistItem=function(a){b["default"].remove(this.playlistItems,function(b){return a===b}),this.filterFoundPlaylistItems()},a.prototype.savePlaylist=function(a,b){var c,d=this;a.items=b,c=a.id?this.backendSrv.put("/api/playlists/"+a.id,a):this.backendSrv.post("/api/playlists",a),c.then(function(){d.$scope.appEvent("alert-success",["Playlist saved",""]),d.$location.path("/playlists")},function(){d.$scope.appEvent("alert-error",["Unable to save playlist",""])})},a.prototype.isNew=function(){return!this.playlist.id},a.prototype.isPlaylistEmpty=function(){return!this.playlistItems.length},a.prototype.backToList=function(){this.$location.path("/playlists")},a.prototype.searchStarted=function(a){var b=this;a.then(function(a){b.dashboardresult=a.dashboardResult,b.tagresult=a.tagResult,b.filterFoundPlaylistItems()})},a.prototype.movePlaylistItem=function(a,b){var c=this.playlistItems.indexOf(a),d=c+b;d>=0&&d<this.playlistItems.length&&(this.playlistItems.splice(c,1),this.playlistItems.splice(d,0,a))},a.prototype.movePlaylistItemUp=function(a){this.movePlaylistItem(a,-1)},a.prototype.movePlaylistItemDown=function(a){this.movePlaylistItem(a,1)},a}(),a("PlaylistEditCtrl",d),c["default"].controller("PlaylistEditCtrl",d)}}});