/*! grafana - v4.2.0 - 2017-03-24
 * Copyright (c) 2017 Torkel Ödegaard; Licensed Apache-2.0 */

System.register(["lodash","app/plugins/sdk","app/features/dashboard/impression_store"],function(a,b){"use strict";var c,d,e,f,g=this&&this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)};b&&b.id;return{setters:[function(a){c=a},function(a){d=a},function(a){e=a}],execute:function(){f=function(a){function b(b,d,e){var f=a.call(this,b,d)||this;return f.backendSrv=e,f.panelDefaults={query:"",limit:10,tags:[],recent:!1,search:!1,starred:!0,headings:!0},c.default.defaults(f.panel,f.panelDefaults),f.panel.tag&&(f.panel.tags=[f.panel.tag],delete f.panel.tag),f.events.on("refresh",f.onRefresh.bind(f)),f.events.on("init-edit-mode",f.onInitEditMode.bind(f)),f.groups=[{list:[],show:!1,header:"Starred dashboards"},{list:[],show:!1,header:"Recently viewed dashboards"},{list:[],show:!1,header:"Search"}],f.panel.mode&&("starred"===f.panel.mode&&(f.panel.starred=!0,f.panel.headings=!1),"recently viewed"===f.panel.mode&&(f.panel.recent=!0,f.panel.starred=!1,f.panel.headings=!1),"search"===f.panel.mode&&(f.panel.search=!0,f.panel.starred=!1,f.panel.headings=!1),delete f.panel.mode),f}return g(b,a),b.$inject=["$scope","$injector","backendSrv"],b.prototype.onInitEditMode=function(){this.editorTabIndex=1,this.modes=["starred","search","recently viewed"],this.addEditorTab("Options","public/app/plugins/panel/dashlist/editor.html")},b.prototype.onRefresh=function(){var a=[];return a.push(this.getRecentDashboards()),a.push(this.getStarred()),a.push(this.getSearch()),Promise.all(a).then(this.renderingCompleted.bind(this))},b.prototype.getSearch=function(){var a=this;if(this.groups[2].show=this.panel.search,!this.panel.search)return Promise.resolve();var b={limit:this.panel.limit,query:this.panel.query,tag:this.panel.tags};return this.backendSrv.search(b).then(function(b){a.groups[2].list=b})},b.prototype.getStarred=function(){var a=this;if(this.groups[0].show=this.panel.starred,!this.panel.starred)return Promise.resolve();var b={limit:this.panel.limit,starred:"true"};return this.backendSrv.search(b).then(function(b){a.groups[0].list=b})},b.prototype.getRecentDashboards=function(){var a=this;if(this.groups[1].show=this.panel.recent,!this.panel.recent)return Promise.resolve();var b=c.default.take(e.impressions.getDashboardOpened(),this.panel.limit);return this.backendSrv.search({dashboardIds:b,limit:this.panel.limit}).then(function(d){a.groups[1].list=b.map(function(a){return c.default.find(d,function(b){return b.id===a})}).filter(function(a){return void 0!==a})})},b}(d.PanelCtrl),f.templateUrl="module.html",a("DashListCtrl",f),a("PanelCtrl",f)}}});