agent-show-page.js.coffee 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. $(".agent-show #memory .clear").on "click", @clearMemory
  6. # Trigger tabs when navigated to.
  7. if tab = window.location.href.match(/tab=(\w+)\b/i)?[1]
  8. if tab in ["details", "logs"]
  9. $(".agent-show .nav-pills li a[href='##{tab}']").click()
  10. fetchLogs: (e) ->
  11. agentId = $(e.target).closest("[data-agent-id]").data("agent-id")
  12. e.preventDefault()
  13. $("#logs .spinner").show()
  14. $("#logs .refresh, #logs .clear").hide()
  15. $.get "/agents/#{agentId}/logs", (html) =>
  16. $("#logs .logs").html html
  17. $("#logs .logs .show-log-details").each ->
  18. $button = $(this)
  19. $button.on 'click', (e) ->
  20. e.preventDefault()
  21. Utils.showDynamicModal '<pre></pre>',
  22. title: $button.data('modal-title'),
  23. body: (body) ->
  24. $(body).find('pre').text $button.data('modal-content')
  25. $("#logs .spinner").stop(true, true).fadeOut ->
  26. $("#logs .refresh, #logs .clear").show()
  27. clearLogs: (e) ->
  28. if confirm("Are you sure you want to clear all logs for this Agent?")
  29. agentId = $(e.target).closest("[data-agent-id]").data("agent-id")
  30. e.preventDefault()
  31. $("#logs .spinner").show()
  32. $("#logs .refresh, #logs .clear").hide()
  33. $.post "/agents/#{agentId}/logs/clear", { "_method": "DELETE" }, (html) =>
  34. $("#logs .logs").html html
  35. $("#show-tabs li a.recent-errors").removeClass 'recent-errors'
  36. $("#logs .spinner").stop(true, true).fadeOut ->
  37. $("#logs .refresh, #logs .clear").show()
  38. clearMemory: (e) ->
  39. if confirm("Are you sure you want to clear memory of this Agent?")
  40. agentId = $(e.target).closest("[data-agent-id]").data("agent-id")
  41. e.preventDefault()
  42. $("#memory .spinner").css(display: 'inline-block')
  43. $("#memory .clear").hide()
  44. $.post "/agents/#{agentId}/memory", { "_method": "DELETE" }
  45. .done ->
  46. $("#memory .spinner").fadeOut ->
  47. $("#memory + .memory").text "{\n}\n"
  48. .fail ->
  49. $("#memory .spinner").fadeOut ->
  50. $("#memory .clear").css(display: 'inline-block')
  51. $ ->
  52. Utils.registerPage(AgentShowPage, forPathsMatching: /^agents\/\d+/)