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

System.register(["app/core/config","lodash","angular","jquery","app/core/profiler","app/core/core"],function(a){var b,c,d,e,f,g,h,i,j,k,l;return{setters:[function(a){b=a},function(a){c=a},function(a){d=a},function(a){e=a},function(a){f=a},function(a){g=a}],execute:function(){h=25,i=9,j=5,k=2,l=function(){function a(a,c){var d=this;this.$injector=c,this.$scope=a,this.$timeout=c.get("$timeout"),this.editorTabIndex=0,this.events=new g.Emitter,this.timing={};var e=b["default"].panels[this.panel.type];e&&(this.pluginId=e.id,this.pluginName=e.name),a.$on("refresh",function(){return d.refresh()}),a.$on("render",function(){return d.render()}),a.$on("$destroy",function(){return d.events.emit("panel-teardown")})}return a.prototype.init=function(){this.calculatePanelHeight(),this.publishAppEvent("panel-initialized",{scope:this.$scope}),this.events.emit("panel-initialized")},a.prototype.renderingCompleted=function(){f.profiler.renderingCompleted(this.panel.id,this.timing)},a.prototype.refresh=function(){this.events.emit("refresh",null)},a.prototype.publishAppEvent=function(a,b){this.$scope.$root.appEvent(a,b)},a.prototype.changeView=function(a,b){this.publishAppEvent("panel-change-view",{fullscreen:a,edit:b,panelId:this.panel.id})},a.prototype.viewPanel=function(){this.changeView(!0,!1)},a.prototype.editPanel=function(){this.changeView(!0,!0)},a.prototype.exitFullscreen=function(){this.changeView(!1,!1)},a.prototype.initEditMode=function(){var a=this;this.editorTabs=[],this.addEditorTab("General","public/app/partials/panelgeneral.html"),this.editModeInitiated=!0,this.events.emit("init-edit-mode",null);var b=this.$injector.get("$routeParams");b.editorTab&&this.editorTabs.forEach(function(c,d){c.title===b.editorTab&&(a.editorTabIndex=d)})},a.prototype.changeTab=function(a){this.editorTabIndex=a;var b=this.$injector.get("$route");b.current.params.editorTab=this.editorTabs[a].title,b.updateParams()},a.prototype.addEditorTab=function(a,b,d){var e={title:a,directiveFn:b};c["default"].isString(b)&&(e.directiveFn=function(){return{templateUrl:b}}),d?this.editorTabs.splice(d,0,e):this.editorTabs.push(e)},a.prototype.getMenu=function(){var a=[];return a.push({text:"View",click:"ctrl.viewPanel(); dismiss();"}),a.push({text:"Edit",click:"ctrl.editPanel(); dismiss();",role:"Editor"}),this.fullscreen||a.push({text:"Duplicate",click:"ctrl.duplicate()",role:"Editor"}),a.push({text:"Share",click:"ctrl.sharePanel(); dismiss();"}),a},a.prototype.getExtendedMenu=function(){var a=[{text:"Panel JSON",click:"ctrl.editPanelJson(); dismiss();"}];return this.events.emit("init-panel-actions",a),a},a.prototype.otherPanelInFullscreenMode=function(){return this.dashboard.meta.fullscreen&&!this.fullscreen},a.prototype.calculatePanelHeight=function(){if(this.fullscreen){var a=e["default"](window).height(),b=Math.floor(.3*a),d=Math.floor(.7*a);this.containerHeight=this.editMode?b:d}else this.containerHeight=this.panel.height||this.row.height,c["default"].isString(this.containerHeight)&&(this.containerHeight=parseInt(this.containerHeight.replace("px",""),10));this.height=this.containerHeight-(k+j+(this.panel.title?h:i))},a.prototype.render=function(a){this.otherPanelInFullscreenMode()||(this.calculatePanelHeight(),this.timing.renderStart=(new Date).getTime(),this.events.emit("render",a))},a.prototype.toggleEditorHelp=function(a){return this.editorHelpIndex===a?void(this.editorHelpIndex=null):void(this.editorHelpIndex=a)},a.prototype.duplicate=function(){this.dashboard.duplicatePanel(this.panel,this.row)},a.prototype.updateColumnSpan=function(a){var b=this;this.panel.span=Math.min(Math.max(Math.floor(this.panel.span+a),1),12),this.$timeout(function(){b.render()})},a.prototype.removePanel=function(){var a=this;this.publishAppEvent("confirm-modal",{title:"Remove Panel",text:"Are you sure you want to remove this panel?",icon:"fa-trash",yesText:"Remove",onConfirm:function(){a.row.panels=c["default"].without(a.row.panels,a.panel)}})},a.prototype.editPanelJson=function(){this.publishAppEvent("show-json-editor",{object:this.panel,updateHandler:this.replacePanel.bind(this)})},a.prototype.replacePanel=function(a,b){var d=this,e=(this.row,c["default"].indexOf(this.row.panels,b));this.row.panels.splice(e,1),this.$timeout(function(){a.id=b.id,a.span=b.span,d.row.panels.splice(e,0,a)})},a.prototype.sharePanel=function(){var a=this.$scope.$new();a.panel=this.panel,a.dashboard=this.dashboard,this.publishAppEvent("show-modal",{src:"public/app/features/dashboard/partials/shareModal.html",scope:a})},a.prototype.openInspector=function(){var a=this.$scope.$new();a.panel=this.panel,a.dashboard=this.dashboard,a.inspector=d["default"].copy(this.inspector),this.publishAppEvent("show-modal",{src:"public/app/partials/inspector.html",scope:a})},a}(),a("PanelCtrl",l)}}});