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

System.register(["app/core/config","angular","app/core/core_module"],function(a,b){"use strict";var c,d,e,f;b&&b.id;return{setters:[function(a){c=a},function(a){d=a},function(a){e=a}],execute:function(){f=function(){function a(a,b,e,f,g,h,i,j,k,l,m,n,o){this.$scope=a,this.$rootScope=b,a.editor={index:0};var p;a.setupDashboard=function(b){try{a.setupDashboardInternal(b)}catch(b){a.onInitFailed(b,"Dashboard init failed",!0)}},a.setupDashboardInternal=function(b){var c=i.create(b.dashboard,b.meta);i.setCurrent(c),f.init(c),h.init(c,b.alerts),g.init(c).catch(a.onInitFailed.bind(this,"Templating init failed",!1)).finally(function(){k.init(c),k.process(),j.init(c,a),a.dashboard=c,a.dashboardMeta=c.meta,a.dashboardViewState=l.create(a),e.setupDashboardBindings(a,c),a.dashboard.updateSubmenuVisibility(),a.setWindowTitleAndTheme(),a.appEvent("dashboard-initialized",a.dashboard)}).catch(a.onInitFailed.bind(this,"Dashboard init failed",!0))},a.onInitFailed=function(b,c,d){console.log(b,d),d.data&&d.data.message?d.message=d.data.message:d.message||(d={message:d.toString()}),a.appEvent("alert-error",[b,d.message]),c&&!a.loadedFallbackDashboard&&(a.loadedFallbackDashboard=!0,a.setupDashboard({dashboard:{title:"Dashboard Init failed"}}))},a.templateVariableUpdated=function(){k.process()},a.setWindowTitleAndTheme=function(){window.document.title=c.default.window_title_prefix+a.dashboard.title},a.broadcastRefresh=function(){b.$broadcast("refresh")},a.addRowDefault=function(){a.dashboard.addEmptyRow()},a.showJsonEditor=function(c,d){var e=b.$new();e.object=d.object,e.updateHandler=d.updateHandler,a.appEvent("show-dash-editor",{src:"public/app/partials/edit_json.html",scope:e})},a.registerWindowResizeEvent=function(){d.default.element(window).bind("resize",function(){o.cancel(p),p=o(function(){a.$broadcast("render")},200)}),a.$on("$destroy",function(){d.default.element(window).unbind("resize"),a.dashboard.destroy()})},a.timezoneChanged=function(){b.$broadcast("refresh")}}return a.$inject=["$scope","$rootScope","keybindingSrv","timeSrv","variableSrv","alertingSrv","dashboardSrv","unsavedChangesSrv","dynamicDashboardSrv","dashboardViewStateSrv","contextSrv","alertSrv","$timeout"],a.prototype.init=function(a){this.$scope.onAppEvent("show-json-editor",this.$scope.showJsonEditor),this.$scope.onAppEvent("template-variable-value-updated",this.$scope.templateVariableUpdated),this.$scope.setupDashboard(a),this.$scope.registerWindowResizeEvent()},a}(),a("DashboardCtrl",f),e.default.controller("DashboardCtrl",f)}}});