log.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var num_lines = 0;
  2. Vue.component("log", {
  3. template: `<textarea v-bind:id="jp_props.id" :class="jp_props.classes" :style="jp_props.style" disabled></textarea>`,
  4. mounted() {
  5. comp_dict[this.$props.jp_props.id] = this;
  6. const sendConnectEvent = () => {
  7. if (websocket_id === "") return;
  8. const event = {
  9. event_type: "onConnect",
  10. vue_type: this.$props.jp_props.vue_type,
  11. id: this.$props.jp_props.id,
  12. page_id: page_id,
  13. websocket_id: websocket_id,
  14. };
  15. send_to_server(event, "event");
  16. clearInterval(connectInterval);
  17. };
  18. const connectInterval = setInterval(sendConnectEvent, 100);
  19. },
  20. methods: {
  21. push(line) {
  22. const decoded = decodeURIComponent(line);
  23. const textarea = document.getElementById(this.$props.jp_props.id);
  24. textarea.innerHTML += (num_lines ? "\n" : "") + decoded;
  25. textarea.scrollTop = textarea.scrollHeight;
  26. num_lines += decoded.split("\n").length;
  27. const max_lines = this.$props.jp_props.options.max_lines;
  28. while (max_lines != null && num_lines > max_lines) {
  29. const index = textarea.innerHTML.indexOf("\n");
  30. if (index == -1) break;
  31. textarea.innerHTML = textarea.innerHTML.slice(index + 1);
  32. num_lines -= 1;
  33. }
  34. },
  35. },
  36. props: {
  37. jp_props: Object,
  38. },
  39. });