/*! grafana - v4.5.1 - 2017-09-19
 * Copyright (c) 2017 Torkel Ödegaard; Licensed Apache-2.0 */

System.register(["lodash","../../core/core_module"],function(a,b){"use strict";var c,d,e;b&&b.id;return{setters:[function(a){c=a},function(a){d=a}],execute:function(){e=function(){function a(a,b,c,d,e,f){var g=this;if(this.$scope=a,this.playlistSrv=b,this.backendSrv=c,this.$location=d,this.$route=e,this.navModelSrv=f,this.filteredDashboards=[],this.filteredTags=[],this.searchQuery="",this.loading=!1,this.playlist={interval:"5m"},this.playlistItems=[],this.dashboardresult=[],this.tagresult=[],this.navModel=f.getPlaylistsNav(0),e.current.params.id){var h=e.current.params.id;c.get("/api/playlists/"+h).then(function(a){g.playlist=a}),c.get("/api/playlists/"+h+"/items").then(function(a){g.playlistItems=a})}}return a.$inject=["$scope","playlistSrv","backendSrv","$location","$route","navModelSrv"],a.prototype.filterFoundPlaylistItems=function(){var a=this;this.filteredDashboards=c.default.reject(this.dashboardresult,function(b){return c.default.find(a.playlistItems,function(a){return parseInt(a.value)===b.id})}),this.filteredTags=c.default.reject(this.tagresult,function(b){return c.default.find(a.playlistItems,function(a){return a.value===b.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){c.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",e),d.default.controller("PlaylistEditCtrl",e)}}});