diff --git a/assets/javascripts/models/overview.js.coffee b/assets/javascripts/models/overview.js.coffee index fc7599c..01a467a 100644 --- a/assets/javascripts/models/overview.js.coffee +++ b/assets/javascripts/models/overview.js.coffee @@ -1,14 +1,9 @@ class Nutcracker.Models.Overview extends Backbone.Model - initialize: -> - clientConnections = _(@get("clusters").pluck("client_connections")).sum() - - serverConnections = 0 - for nodesCollection in @get("clusters").pluck("nodes") - serverConnections += nodesCollection.serverConnections() - - @set "serverConnections", serverConnections - @set "clientConnections", clientConnections - + url: "/overview.json" + + initialize: => + @postInit() + nodes: => new Backbone.Collection(_(@get("clusters").pluck("nodes")).chain() .pluck("models") @@ -16,12 +11,33 @@ class Nutcracker.Models.Overview extends Backbone.Model .flatten() .value() ) + + fetch: => + super and @postInit() + # reload the app + if window.location.hash == "" + Nutcracker.router.navigate('/',trigger: true) + else + Nutcracker.router.navigate(window.location.hash,trigger: true) + clusters: => @get "clusters" + + postInit: => + clientConnections = _(@get("clusters").pluck("client_connections")).sum() + + serverConnections = 0 + for nodesCollection in @get("clusters").pluck("nodes") + serverConnections += nodesCollection.serverConnections() + + @set "serverConnections", serverConnections + @set "clientConnections", clientConnections + @set "initializeTime", new Date + set: ( attributes, options ) -> if attributes.clusters? and attributes.clusters not instanceof Nutcracker.Collections.Clusters attributes.clusters = new Nutcracker.Collections.Clusters attributes.clusters - Backbone.Model.prototype.set.call(@, attributes, options) + Backbone.Model.prototype.set.call(@, attributes, options) \ No newline at end of file diff --git a/assets/javascripts/views/cluster.js.coffee b/assets/javascripts/views/cluster.js.coffee index 59b06e0..ec01c86 100644 --- a/assets/javascripts/views/cluster.js.coffee +++ b/assets/javascripts/views/cluster.js.coffee @@ -1,6 +1,6 @@ class Nutcracker.Views.Cluster extends Backbone.View template: JST['cluster'] - + render: -> @curIndex = @collection.indexOf(@model) @nextCluster = @collection.at @curIndex+1 diff --git a/assets/javascripts/views/footer.js.coffee b/assets/javascripts/views/footer.js.coffee index c28339f..655a850 100644 --- a/assets/javascripts/views/footer.js.coffee +++ b/assets/javascripts/views/footer.js.coffee @@ -2,7 +2,10 @@ class Nutcracker.Views.Footer extends Backbone.View className: "container navbar navbar-fixed-bottom navbar-inverse" template: JST['footer'] - render: -> + render: => @$el.html @template({@model}) + @$el.find('#lastUpdate').html("Last updated: " + humanize.relativeTime(@model.get("initializeTime")/1000)) + setTimeout(@render,1000) this + diff --git a/assets/javascripts/views/navbar.js.coffee b/assets/javascripts/views/navbar.js.coffee index f90e5fa..ad8ccb3 100644 --- a/assets/javascripts/views/navbar.js.coffee +++ b/assets/javascripts/views/navbar.js.coffee @@ -1,28 +1,52 @@ class Nutcracker.Views.Navbar extends Backbone.View className: "navbar navbar-inverse navbar-fixed-top" template: JST['navbar'] - - initialize: => - Backbone.history.bind "all", @routeChange + events: 'click .auto-refresh-button' : 'autoRefresh' - render: -> - $(@el).html @template {@model} - this + initialize: => + Backbone.history.bind "all", @resetButtons + @listenTo(@model,'change', @render) + @autoRefreshInterval = null - resetButtons: -> - @$el.find("li").removeClass 'active' + resetButtons: => + @$el.find("li").removeClass('active') + + if @autoRefreshInterval + @$("#auto-refresh-drop-down").addClass('active') + @$("#auto-refresh-value-#{@autoRefreshInterval}").addClass('active') + else + @$("#auto-refresh-drop-down").removeClass("active") + @$("#auto-refresh-drop-down").find('.active').removeClass("active") + + url = window.location.href + if /#\/config$/.test url + @activate '#config' + else if /#\/clusters\//.test url + @activate '#clusters' + else if /#\/nodes\//.test url + @activate '#nodes' + else + @activate '#overview' + + autoRefresh: ( event ) => + interval = parseInt($(event.currentTarget).attr('value')) + @autoRefreshTimer and clearInterval @autoRefreshTimer + if interval == @autoRefreshInterval + @autoRefreshInterval = null + else + @autoRefreshInterval = interval + @autoRefreshTimer = setInterval => + @model.fetch() + ,@autoRefreshInterval*1000 + + @resetButtons() + event.preventDefault() + activate: ( id )=> @$(id).addClass 'active' - routeChange: (route, object, action, args) => + render: => + @$el.html @template {@model} @resetButtons() - if /showOverview/g.test action - @activate '#overview' - if /showConfig/.test action - @activate '#config' - else if /showCluster/ig.test action - @activate '#clusters' - else if /showNode/gi.test action - @activate '#nodes' - + this \ No newline at end of file diff --git a/assets/templates/footer.jst.eco b/assets/templates/footer.jst.eco index 8ab6088..ef3edc4 100644 --- a/assets/templates/footer.jst.eco +++ b/assets/templates/footer.jst.eco @@ -1 +1 @@ -Last Update <%=humanize.relativeTime(@model.get('timestamp'))%> +
diff --git a/assets/templates/navbar.jst.eco b/assets/templates/navbar.jst.eco index fbf6926..1877448 100644 --- a/assets/templates/navbar.jst.eco +++ b/assets/templates/navbar.jst.eco @@ -15,7 +15,7 @@