Нет описания http://j1x-huginn.herokuapp.com

agent-show-page.js.coffee 2.6KB

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