You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.2 KiB

  1. <template lang='pug'>
  2. v-dialog(v-model='isShown', width='90vw', max-width='1200')
  3. .dialog-header
  4. span Live Console
  5. v-spacer
  6. .caption.blue--text.text--lighten-3.mr-3 Streaming...
  7. v-progress-circular(
  8. indeterminate
  9. color='blue lighten-3'
  10. :size='20'
  11. :width='2'
  12. )
  13. .consoleTerm(ref='consoleContainer')
  14. v-toolbar(flat, color='grey darken-3', dark)
  15. v-spacer
  16. v-btn(outline, @click='clear')
  17. v-icon(left) cancel_presentation
  18. span Clear
  19. v-btn(outline, @click='close')
  20. v-icon(left) close
  21. span Close
  22. </template>
  23. <script>
  24. import _ from 'lodash'
  25. import { Terminal } from 'xterm'
  26. import * as fit from 'xterm/lib/addons/fit/fit'
  27. import livetrailSubscription from 'gql/admin/logging/logging-subscription-livetrail.gql'
  28. Terminal.applyAddon(fit)
  29. export default {
  30. term: null,
  31. props: {
  32. value: {
  33. type: Boolean,
  34. default: false
  35. }
  36. },
  37. computed: {
  38. isShown: {
  39. get() { return this.value },
  40. set(val) { this.$emit('input', val) }
  41. }
  42. },
  43. watch: {
  44. value(newValue, oldValue) {
  45. if (newValue) {
  46. _.delay(() => {
  47. this.term = new Terminal()
  48. this.term.open(this.$refs.consoleContainer)
  49. this.term.writeln('Connecting to \x1B[1;3;31mconsole output\x1B[0m...')
  50. this.attach()
  51. }, 100)
  52. } else {
  53. this.term.dispose()
  54. this.term = null
  55. }
  56. }
  57. },
  58. mounted() {
  59. },
  60. methods: {
  61. clear() {
  62. this.term.clear()
  63. },
  64. close() {
  65. this.isShown = false
  66. },
  67. attach() {
  68. const self = this
  69. const observer = this.$apollo.subscribe({
  70. query: livetrailSubscription
  71. })
  72. observer.subscribe({
  73. next(data) {
  74. const item = _.get(data, `data.loggingLiveTrail`, {})
  75. console.info(item)
  76. self.term.writeln(`${item.level}: ${item.output}`)
  77. },
  78. error(error) {
  79. self.$store.commit('showNotification', {
  80. style: 'red',
  81. message: error.message,
  82. icon: 'warning'
  83. })
  84. }
  85. })
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang='scss'>
  91. .consoleTerm {
  92. background-color: #000;
  93. padding: 16px;
  94. width: 100%;
  95. height: 415px;
  96. }
  97. </style>