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

System.register(["lodash","moment","angular","app/core/core"],function(a,b){"use strict";function c(){return{restrict:"E",templateUrl:"public/app/features/dashboard/dashnav/dashnav.html",controller:h,bindToController:!0,controllerAs:"ctrl",transclude:!0,scope:{dashboard:"="}}}b&&b.id;a("dashNavDirective",c);var d,e,f,g,h;return{setters:[function(a){d=a},function(a){e=a},function(a){f=a},function(a){g=a}],execute:function(){h=function(){function a(a,b,c,d,f,h,i,j,k,l){if(this.$scope=a,this.$rootScope=b,this.dashboardSrv=c,this.$location=d,this.playlistSrv=f,this.backendSrv=h,this.$timeout=i,this.datasourceSrv=j,this.navModelSrv=k,this.contextSrv=l,this.navModel=k.getDashboardNav(this.dashboard,this),g.appEvents.on("save-dashboard",this.saveDashboard.bind(this),a),g.appEvents.on("delete-dashboard",this.deleteDashboard.bind(this),a),this.dashboard.meta.isSnapshot){var m=this.dashboard.meta;this.titleTooltip="Created: &nbsp;"+e.default(m.created).calendar(),m.expires&&(this.titleTooltip+="<br>Expires: &nbsp;"+e.default(m.expires).fromNow()+"<br>")}}return a.$inject=["$scope","$rootScope","dashboardSrv","$location","playlistSrv","backendSrv","$timeout","datasourceSrv","navModelSrv","contextSrv"],a.prototype.toggleSideMenu=function(){this.contextSrv.toggleSideMenu()},a.prototype.openEditView=function(a){var b=d.default.extend(this.$location.search(),{editview:a});this.$location.search(b)},a.prototype.showHelpModal=function(){g.appEvents.emit("show-modal",{templateHtml:"<help-modal></help-modal>"})},a.prototype.starDashboard=function(){var a=this;return this.dashboard.meta.isStarred?this.backendSrv.delete("/api/user/stars/dashboard/"+this.dashboard.id).then(function(){a.dashboard.meta.isStarred=!1}):void this.backendSrv.post("/api/user/stars/dashboard/"+this.dashboard.id).then(function(){a.dashboard.meta.isStarred=!0})},a.prototype.shareDashboard=function(a){var b=this.$scope.$new();b.tabIndex=a,b.dashboard=this.dashboard,g.appEvents.emit("show-modal",{src:"public/app/features/dashboard/partials/shareModal.html",scope:b})},a.prototype.hideTooltip=function(a){f.default.element(a.currentTarget).tooltip("hide")},a.prototype.makeEditable=function(){return this.dashboard.editable=!0,this.dashboardSrv.saveDashboard({makeEditable:!0,overwrite:!1}).then(function(){window.location.href=window.location.href})},a.prototype.exitFullscreen=function(){this.$rootScope.appEvent("panel-change-view",{fullscreen:!1,edit:!1})},a.prototype.saveDashboard=function(){return this.dashboardSrv.saveDashboard()},a.prototype.deleteDashboard=function(){var a=this,b="",c=this.dashboard.title,d=this.dashboard.rows.reduce(function(a,b){return a+=b.panels.filter(function(a){return a.alert}).length},0);d>0&&(b="DELETE",c="This dashboad contains "+d+" alerts. Deleting this dashboad will also delete those alerts"),g.appEvents.emit("confirm-modal",{title:"Delete",text:"Do you want to delete this dashboard?",text2:c,icon:"fa-trash",confirmText:b,yesText:"Delete",onConfirm:function(){a.dashboard.meta.canSave=!1,a.deleteDashboardConfirmed()}})},a.prototype.deleteDashboardConfirmed=function(){var a=this;this.backendSrv.delete("/api/dashboards/db/"+this.dashboard.meta.slug).then(function(){g.appEvents.emit("alert-success",["Dashboard Deleted",a.dashboard.title+" has been deleted"]),a.$location.url("/")})},a.prototype.saveDashboardAs=function(){return this.dashboardSrv.showSaveAsModal()},a.prototype.viewJson=function(){var a=this.dashboard.getSaveModelClone();this.$rootScope.appEvent("show-json-editor",{object:a})},a.prototype.showSearch=function(){this.$rootScope.appEvent("show-dash-search")},a.prototype.navItemClicked=function(a,b){a.clickHandler&&(a.clickHandler(),b.preventDefault())},a}(),a("DashNavCtrl",h),f.default.module("grafana.directives").directive("dashnav",c)}}});