organization.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <div class="d-flex flex-column align-center">
  3. <h2 class="ma-4">{{ $t('cmf_structure_licence')}}</h2>
  4. <a
  5. href="https://www.cmf-musique.org/services/tarifs-preferentiels/"
  6. target="_blank"
  7. >
  8. {{ $t('cmf_licence_details_url')}}
  9. </a>
  10. <v-form
  11. ref="form"
  12. lazy-validation
  13. >
  14. <div class="ma-12">
  15. <v-btn
  16. v-if="!pending && fileUrl === null"
  17. @click="submit"
  18. >
  19. {{ $t('generate') }}
  20. </v-btn>
  21. <v-btn
  22. v-else
  23. color="primary"
  24. :loading="pending"
  25. :disabled="pending"
  26. :href="fileUrl">
  27. {{ $t('download') }}
  28. </v-btn>
  29. </div>
  30. </v-form>
  31. </div>
  32. </template>
  33. <script lang="ts">
  34. import {defineComponent, Ref, ref, useContext} from "@nuxtjs/composition-api";
  35. import {HTTP_METHOD, QUERY_TYPE} from "~/types/enums";
  36. import DataPersister from "~/services/data/dataPersister";
  37. import {DataPersisterArgs} from "~/types/interfaces";
  38. export default defineComponent({
  39. name: 'OrganizationCmfLicence',
  40. setup() {
  41. const { $config } = useContext()
  42. let pending: Ref<boolean> = ref(false)
  43. let fileUrl: Ref<string | null> = ref(null)
  44. const submit = async () => {
  45. const url = new URL($config.baseUrl_mercure)
  46. url.searchParams.append('topic', "files")
  47. // const eventSource = new EventSource(url.toString(), { withCredentials: true });
  48. const eventSource = new EventSource(url.toString());
  49. eventSource.onmessage = event => {
  50. // Will be called every time an update is published by the server
  51. const data = JSON.parse(event.data)
  52. fileUrl.value = data.url
  53. pending.value = false
  54. }
  55. await DataPersister.request(
  56. '/api/export/cmf-licence/organization',
  57. HTTP_METHOD.POST,
  58. { type: QUERY_TYPE.DEFAULT, data: { format: 'pdf', async: true } } as DataPersisterArgs
  59. )
  60. pending.value = true
  61. }
  62. return {
  63. submit,
  64. pending,
  65. fileUrl
  66. }
  67. }
  68. })
  69. </script>