RunJobDropdown.vue 2.0 KB

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