You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.4 KiB

  1. import { computed, reactive, ref, useContext } from '@nuxtjs/composition-api'
  2. import { LabelDTO } from '@/services/application/label/labelData'
  3. import { CreateLabelCommand , UpdateLabelCommand } from '@/services/application/label/labelCommand'
  4. export const useLabelList = () => {
  5. const state = reactive({
  6. labels: [] as LabelDTO[]
  7. })
  8. const { app } = useContext()
  9. const $services = app.$services
  10. const getLabelList = async(
  11. projectId: string
  12. ) => {
  13. state.labels = await $services.label.list(projectId)
  14. }
  15. const createLabel = async(
  16. projectId: string,
  17. command: CreateLabelCommand
  18. ) => {
  19. await $services.label.create(projectId, command)
  20. await getLabelList(projectId)
  21. }
  22. const updateLabel = async(
  23. projectId: string,
  24. command: UpdateLabelCommand
  25. ) => {
  26. await $services.label.update(projectId, command)
  27. }
  28. const deleteLabelList = async(
  29. projectId: string,
  30. items: LabelDTO[]
  31. ) => {
  32. await $services.label.bulkDelete(projectId, items)
  33. await getLabelList(projectId)
  34. }
  35. const findLabelById = (labelId: number) => {
  36. return state.labels.find(item => item.id === labelId)
  37. }
  38. const shortKeys = computed(() => {
  39. return Object.fromEntries(state.labels.map(item => [item.id, [item.suffixKey]]))
  40. })
  41. return {
  42. state,
  43. getLabelList,
  44. findLabelById,
  45. createLabel,
  46. updateLabel,
  47. deleteLabelList,
  48. shortKeys,
  49. }
  50. }