ExecutionButton.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div
  3. :id="`execution-${executionTrackingId}`"
  4. class="execution-button"
  5. >
  6. <button
  7. :title="`${ellapsed}s`"
  8. @click="show"
  9. >
  10. {{ buttonText }}
  11. </button>
  12. </div>
  13. </template>
  14. <script>
  15. //import { ExecutionFeedbackButton } from '../js/ExecutionFeedbackButton.js'
  16. export default {
  17. name: 'ExecutionButton',
  18. // mixins: [ExecutionFeedbackButton],
  19. props: {
  20. executionTrackingId: {
  21. type: String,
  22. required: true
  23. }
  24. },
  25. data() {
  26. return {
  27. ellapsed: 0,
  28. isWaiting: true
  29. }
  30. },
  31. computed: {
  32. buttonText() {
  33. if (this.isWaiting) {
  34. return 'Executing...'
  35. } else {
  36. return `${this.ellapsed}s`
  37. }
  38. }
  39. },
  40. mounted() {
  41. this.constructFromJson(this.executionTrackingId)
  42. },
  43. methods: {
  44. constructFromJson(json) {
  45. this.executionTrackingId = json
  46. this.ellapsed = 0
  47. this.isWaiting = true
  48. },
  49. show() {
  50. this.$emit('show')
  51. if (window.executionDialog) {
  52. window.executionDialog.reset()
  53. window.executionDialog.show()
  54. window.executionDialog.fetchExecutionResult(this.executionTrackingId)
  55. }
  56. },
  57. onExecStatusChanged() {
  58. this.isWaiting = false
  59. this.domTitle = this.ellapsed + 's'
  60. },
  61. // Override from ExecutionFeedbackButton
  62. onExecutionFinished(logEntry) {
  63. if (logEntry.timedOut) {
  64. this.renderExecutionResult('action-timeout', 'Timed out')
  65. } else if (logEntry.blocked) {
  66. this.renderExecutionResult('action-blocked', 'Blocked!')
  67. } else if (logEntry.exitCode !== 0) {
  68. this.renderExecutionResult('action-nonzero-exit', 'Exit code ' + logEntry.exitCode)
  69. } else {
  70. this.ellapsed = Math.ceil(new Date(logEntry.datetimeFinished) - new Date(logEntry.datetimeStarted)) / 1000
  71. this.renderExecutionResult('action-success', 'Success!')
  72. }
  73. },
  74. renderExecutionResult(resultCssClass, temporaryStatusMessage) {
  75. this.updateDom(resultCssClass, '[' + temporaryStatusMessage + ']')
  76. this.onExecStatusChanged()
  77. },
  78. updateDom(resultCssClass, title) {
  79. // For execution button, we don't need to update classes as much
  80. // since it's a simpler component
  81. if (resultCssClass) {
  82. this.$el.classList.add(resultCssClass)
  83. }
  84. }
  85. }
  86. }
  87. </script>
  88. <style scoped>
  89. .execution-button {
  90. display: inline-block;
  91. }
  92. .execution-button button {
  93. padding: 0.25em 0.5em;
  94. border: 1px solid #ccc;
  95. border-radius: 3px;
  96. background: #fff;
  97. cursor: pointer;
  98. font-size: 0.9em;
  99. transition: all 0.2s ease;
  100. }
  101. .execution-button button:hover {
  102. background: #f5f5f5;
  103. border-color: #999;
  104. }
  105. /* Animation classes */
  106. .execution-button button.action-timeout {
  107. background: #fff3cd;
  108. border-color: #ffeaa7;
  109. color: #856404;
  110. }
  111. .execution-button button.action-blocked {
  112. background: #f8d7da;
  113. border-color: #f5c6cb;
  114. color: #721c24;
  115. }
  116. .execution-button button.action-nonzero-exit {
  117. background: #f8d7da;
  118. border-color: #f5c6cb;
  119. color: #721c24;
  120. }
  121. .execution-button button.action-success {
  122. background: #d4edda;
  123. border-color: #c3e6cb;
  124. color: #155724;
  125. }
  126. </style>