RunJobDropdown.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <tippy
  3. class="runJobDropdown"
  4. :touch="true"
  5. :interactive="true"
  6. placement="bottom-end"
  7. theme="dropdown"
  8. ref="dropdown"
  9. trigger="click"
  10. append-to="parent"
  11. @show="
  12. () => {
  13. showJobDropdown = true;
  14. }
  15. "
  16. @hide="
  17. () => {
  18. showJobDropdown = false;
  19. }
  20. "
  21. >
  22. <div class="control has-addons" ref="trigger">
  23. <button class="button is-primary">Run Job</button>
  24. <button class="button dropdown-toggle">
  25. <i class="material-icons">
  26. {{ showJobDropdown ? "expand_more" : "expand_less" }}
  27. </i>
  28. </button>
  29. </div>
  30. <template #content>
  31. <div class="nav-dropdown-items" v-if="jobs.length > 0">
  32. <quick-confirm
  33. v-for="(job, index) in jobs"
  34. :key="`job-${index}`"
  35. placement="top"
  36. @confirm="runJob(job)"
  37. >
  38. <button class="nav-item button" :title="job.name">
  39. <i
  40. class="material-icons icon-with-button"
  41. content="Run Job"
  42. v-tippy
  43. >play_arrow</i
  44. >
  45. <p>{{ job.name }}</p>
  46. </button>
  47. </quick-confirm>
  48. </div>
  49. <p v-else class="no-jobs">No jobs available.</p>
  50. </template>
  51. </tippy>
  52. </template>
  53. <script>
  54. import { mapGetters } from "vuex";
  55. import Toast from "toasters";
  56. export default {
  57. props: {
  58. jobs: {
  59. type: Array,
  60. default: () => []
  61. }
  62. },
  63. data() {
  64. return {
  65. showJobDropdown: false
  66. };
  67. },
  68. computed: {
  69. ...mapGetters({
  70. socket: "websockets/getSocket"
  71. })
  72. },
  73. methods: {
  74. runJob(job) {
  75. new Toast(`Running job: ${job.name}`);
  76. this.socket.dispatch(job.socket, data => {
  77. if (data.status !== "success")
  78. new Toast({
  79. content: `Error: ${data.message}`,
  80. timeout: 8000
  81. });
  82. else new Toast({ content: data.message, timeout: 4000 });
  83. });
  84. }
  85. }
  86. };
  87. </script>
  88. <style lang="less" scoped>
  89. .nav-dropdown-items {
  90. & > span:not(:last-child) .nav-item.button {
  91. margin-bottom: 10px !important;
  92. }
  93. .nav-item.button .icon-with-button {
  94. font-size: 22px;
  95. color: var(--primary-color);
  96. }
  97. }
  98. .no-jobs {
  99. text-align: center;
  100. margin: 10px 0;
  101. }
  102. </style>