RunJobDropdown.vue 2.0 KB

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