agent-show-page.js.coffee 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. class @AgentShowPage
  2. constructor: ->
  3. $(".agent-show #show-tabs a[href='#logs'], #logs .refresh").on "click", @fetchLogs
  4. $(".agent-show #logs .clear").on "click", @clearLogs
  5. # Trigger tabs when navigated to.
  6. if tab = window.location.href.match(/tab=(\w+)\b/i)?[1]
  7. if tab in ["details", "logs"]
  8. $(".agent-show .nav-pills li a[href='##{tab}']").click()
  9. fetchLogs: (e) ->
  10. agentId = $(e.target).closest("[data-agent-id]").data("agent-id")
  11. e.preventDefault()
  12. $("#logs .spinner").show()
  13. $("#logs .refresh, #logs .clear").hide()
  14. $.get "/agents/#{agentId}/logs", (html) =>
  15. $("#logs .logs").html html
  16. $("#logs .spinner").stop(true, true).fadeOut ->
  17. $("#logs .refresh, #logs .clear").show()
  18. clearLogs: (e) ->
  19. if confirm("Are you sure you want to clear all logs for this Agent?")
  20. agentId = $(e.target).closest("[data-agent-id]").data("agent-id")
  21. e.preventDefault()
  22. $("#logs .spinner").show()
  23. $("#logs .refresh, #logs .clear").hide()
  24. $.post "/agents/#{agentId}/logs/clear", { "_method": "DELETE" }, (html) =>
  25. $("#logs .logs").html html
  26. $("#show-tabs li a.recent-errors").removeClass 'recent-errors'
  27. $("#logs .spinner").stop(true, true).fadeOut ->
  28. $("#logs .refresh, #logs .clear").show()
  29. $ ->
  30. Utils.registerPage(AgentShowPage, forPathsMatching: /^agents\/\d+/)