index.html 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <html>
  2. <head>
  3. <title>etcd Web Interface</title>
  4. <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
  5. <script type="text/javascript">
  6. $(function() {
  7. var conn;
  8. var content = $("#content");
  9. function update(response) {
  10. // if set
  11. if (response.action == "SET") {
  12. if (response.expiration > "1970") {
  13. t = response.key + "=" + response.value
  14. + " " + response.expiration
  15. } else {
  16. t = response.key + "=" + response.value
  17. }
  18. id = response.key.replace(new RegExp("/", 'g'), "\\/");
  19. if ($("#store_" + id).length == 0) {
  20. if (response.expiration > "1970") {
  21. t = response.key + "=" + response.value
  22. + " " + response.expiration
  23. } else {
  24. t = response.key + "=" + response.value
  25. }
  26. var e = $('<div id="store_' + response.key + '"/>')
  27. .text(t)
  28. e.appendTo(content)
  29. }
  30. else {
  31. $("#store_" + id)
  32. .text(t)
  33. }
  34. }
  35. // if delete
  36. else if (response.action == "DELETE") {
  37. id = response.key.replace(new RegExp("/", 'g'), "\\/");
  38. $("#store_" + id).remove()
  39. }
  40. }
  41. if (window["WebSocket"]) {
  42. conn = new WebSocket("ws://{{.Address}}/ws");
  43. conn.onclose = function(evt) {
  44. }
  45. conn.onmessage = function(evt) {
  46. var response = JSON.parse(evt.data)
  47. update(response)
  48. }
  49. } else {
  50. appendLog($("<div><b>Your browser does not support WebSockets.</b></div>"))
  51. }
  52. });
  53. </script>
  54. </head>
  55. <body>
  56. <div id="leader">Leader: {{.Leader}}</div>
  57. <div id="content"></div>
  58. </body>
  59. </html>