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.

59 lines
1.4 KiB

  1. import { computed, reactive, useContext } from '@nuxtjs/composition-api'
  2. import { LabelDTO } from '@/services/application/label/labelData'
  3. import { CreateLabelCommand , UpdateLabelCommand } from '@/services/application/label/labelCommand'
  4. import { LabelApplicationService } from '@/services/application/label/labelApplicationService'
  5. export const useLabelList = (service: LabelApplicationService) => {
  6. const state = reactive({
  7. labels: [] as LabelDTO[]
  8. })
  9. const { app } = useContext()
  10. const getLabelList = async(
  11. projectId: string
  12. ) => {
  13. state.labels = await service.list(projectId)
  14. }
  15. const createLabel = async(
  16. projectId: string,
  17. command: CreateLabelCommand
  18. ) => {
  19. await service.create(projectId, command)
  20. await getLabelList(projectId)
  21. }
  22. const updateLabel = async(
  23. projectId: string,
  24. command: UpdateLabelCommand
  25. ) => {
  26. await service.update(projectId, command)
  27. }
  28. const deleteLabelList = async(
  29. projectId: string,
  30. items: LabelDTO[]
  31. ) => {
  32. await service.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. }