LongJobs.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <script setup lang="ts">
  2. import { defineAsyncComponent, ref, onMounted } from "vue";
  3. import { storeToRefs } from "pinia";
  4. import { useWebsocketsStore } from "@/stores/websockets";
  5. import { useLongJobsStore } from "@/stores/longJobs";
  6. import { useUserAuthStore } from "@/stores/userAuth";
  7. const FloatingBox = defineAsyncComponent(
  8. () => import("@/components/FloatingBox.vue")
  9. );
  10. const body = ref(document.body);
  11. const userAuthStore = useUserAuthStore();
  12. const { loggedIn } = storeToRefs(userAuthStore);
  13. const { socket } = useWebsocketsStore();
  14. const longJobsStore = useLongJobsStore();
  15. const { activeJobs } = storeToRefs(longJobsStore);
  16. const { setJob, setJobs, removeJob } = longJobsStore;
  17. const remove = job => {
  18. if (job.status === "success" || job.status === "error") {
  19. socket.dispatch("users.removeLongJob", job.id, res => {
  20. if (res.status === "success") {
  21. removeJob(job.id);
  22. } else console.log(res.message);
  23. });
  24. }
  25. };
  26. onMounted(() => {
  27. socket.onConnect(() => {
  28. if (loggedIn.value) {
  29. socket.dispatch("users.getLongJobs", {
  30. cb: res => {
  31. if (res.status === "success") {
  32. setJobs(res.data.longJobs);
  33. } else console.log(res.message);
  34. },
  35. onProgress: res => {
  36. setJob(res);
  37. }
  38. });
  39. }
  40. });
  41. socket.on("keep.event:longJob.removed", ({ data }) => {
  42. removeJob(data.jobId);
  43. });
  44. socket.on("keep.event:longJob.added", ({ data }) => {
  45. if (!activeJobs.value.find(activeJob => activeJob.id === data.jobId))
  46. socket.dispatch("users.getLongJob", data.jobId, {
  47. cb: res => {
  48. if (res.status === "success") {
  49. setJob(res.data.longJob);
  50. } else console.log(res.message);
  51. },
  52. onProgress: res => {
  53. setJob(res);
  54. }
  55. });
  56. });
  57. });
  58. </script>
  59. <template>
  60. <floating-box
  61. v-if="activeJobs.length > 0"
  62. title="Jobs"
  63. id="longJobs"
  64. ref="longJobs"
  65. :persist="true"
  66. initial="align-bottom"
  67. :min-width="200"
  68. :max-width="400"
  69. :min-height="200"
  70. >
  71. <template #body>
  72. <div class="active-jobs">
  73. <div
  74. v-for="job in activeJobs"
  75. :key="`activeJob-${job.id}`"
  76. class="active-job"
  77. >
  78. <i
  79. v-if="
  80. job.status === 'started' || job.status === 'update'
  81. "
  82. class="material-icons"
  83. content="In Progress"
  84. v-tippy="{ theme: 'info', placement: 'right' }"
  85. >
  86. pending
  87. </i>
  88. <i
  89. v-else-if="job.status === 'success'"
  90. class="material-icons success"
  91. content="Complete"
  92. v-tippy="{ theme: 'info', placement: 'right' }"
  93. >
  94. check_circle
  95. </i>
  96. <i
  97. v-else
  98. class="material-icons error"
  99. content="Failed"
  100. v-tippy="{ theme: 'info', placement: 'right' }"
  101. >
  102. error
  103. </i>
  104. <div class="name" :title="job.name">{{ job.name }}</div>
  105. <div class="actions">
  106. <i
  107. class="material-icons clear"
  108. :class="{
  109. disabled: !(
  110. job.status === 'success' ||
  111. job.status === 'error'
  112. )
  113. }"
  114. content="Clear"
  115. v-tippy="{ placement: 'left' }"
  116. @click="remove(job)"
  117. >
  118. remove_circle
  119. </i>
  120. <tippy
  121. :touch="true"
  122. :interactive="true"
  123. placement="left"
  124. ref="longJobMessage"
  125. :append-to="body"
  126. >
  127. <i class="material-icons message">chat</i>
  128. <template #content>
  129. <div class="long-job-message">
  130. <strong>Latest Update:</strong>
  131. <span :title="job.message">{{
  132. job.message
  133. }}</span>
  134. </div>
  135. </template>
  136. </tippy>
  137. </div>
  138. </div>
  139. </div>
  140. </template>
  141. </floating-box>
  142. </template>
  143. <style lang="less" scoped>
  144. .night-mode {
  145. #longJobs {
  146. .active-jobs {
  147. .active-job {
  148. background-color: var(--dark-grey);
  149. border: 0;
  150. }
  151. }
  152. }
  153. .long-job-message {
  154. color: var(--black);
  155. }
  156. }
  157. #longJobs {
  158. z-index: 5000 !important;
  159. .active-jobs {
  160. .active-job {
  161. display: flex;
  162. padding: 5px;
  163. margin: 5px 0;
  164. border: 1px solid var(--light-grey-3);
  165. border-radius: @border-radius;
  166. &:first-child {
  167. margin-top: 0;
  168. }
  169. &:last-child {
  170. margin-bottom: 0;
  171. }
  172. .name {
  173. line-height: 24px;
  174. font-weight: 600;
  175. text-transform: capitalize;
  176. text-overflow: ellipsis;
  177. white-space: nowrap;
  178. overflow: hidden;
  179. margin-right: auto;
  180. }
  181. .material-icons {
  182. font-size: 20px;
  183. color: var(--primary-color);
  184. margin: auto 5px auto 0;
  185. cursor: pointer;
  186. &.success {
  187. color: var(--green);
  188. }
  189. &.error,
  190. &.clear {
  191. color: var(--red);
  192. }
  193. &.disabled {
  194. color: var(--light-grey-3);
  195. cursor: not-allowed;
  196. }
  197. }
  198. .actions {
  199. display: flex;
  200. .material-icons {
  201. margin: auto 0 auto 5px;
  202. }
  203. & > span {
  204. display: flex;
  205. padding: 0;
  206. }
  207. }
  208. }
  209. }
  210. }
  211. .long-job-message {
  212. display: flex;
  213. flex-direction: column;
  214. strong {
  215. font-size: 12px;
  216. }
  217. span {
  218. display: -webkit-inline-box;
  219. text-overflow: ellipsis;
  220. white-space: normal;
  221. -webkit-box-orient: vertical;
  222. -webkit-line-clamp: 3;
  223. overflow: hidden;
  224. max-width: 200px;
  225. font-size: 12px;
  226. }
  227. }
  228. </style>