auditories.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <div
  3. v-if="!(auditories && auditoriesFree)"
  4. class="w-full h-full flex items-center justify-center show"
  5. >
  6. <ILoader class="w-16 h-16 text-foreground" />
  7. </div>
  8. <div
  9. v-else
  10. class="flex flex-col p-4 gap-2 show"
  11. >
  12. <template v-if="busyAuditories.length > 0">
  13. <h1 class="text-2xl font-semibold">
  14. Сейчас заняты
  15. </h1>
  16. <div class="flex flex-wrap gap-2 mb-8">
  17. <span
  18. v-for="(auditory, index) in busyAuditories"
  19. :key="index"
  20. class="text-xl font-semibold rounded-md px-2 py-1 bg-primary text-background-100"
  21. @click="$router.push(`/timetable/auditory/${auditory}`)"
  22. >
  23. {{ auditory }}
  24. </span>
  25. </div>
  26. </template>
  27. <template v-if="auditoriesFree.length > 0">
  28. <h1 class="text-2xl font-semibold">
  29. Сейчас свободны
  30. </h1>
  31. <div class="flex flex-wrap gap-2">
  32. <span
  33. v-for="(auditory, index) in auditoriesFree"
  34. :key="index"
  35. class="text-xl font-semibold rounded-md px-2 py-1 bg-foreground text-background-100"
  36. @click="$router.push(`/timetable/auditory/${auditory}`)"
  37. >
  38. {{ auditory }}
  39. </span>
  40. </div>
  41. </template>
  42. </div>
  43. </template>
  44. <script setup lang="ts">
  45. definePageMeta({
  46. name: 'Выберите аудиторию',
  47. middleware: ['user-only'],
  48. })
  49. const { $api } = useNuxtApp()
  50. const date = new Date()
  51. const hours = date.getHours().toString().padStart(2, '0')
  52. const minutes = date.getMinutes().toString().padStart(2, '0')
  53. const auditories = ref<Array<string> | null>(null)
  54. const auditoriesFree = ref<Array<string> | null>(null)
  55. const busyAuditories = computed(() => {
  56. const result: Array<string> = []
  57. // TODO: write types
  58. for (const i of auditories.value!) {
  59. if (auditoriesFree.value?.indexOf(i) === -1) {
  60. result.push(i)
  61. }
  62. }
  63. return result
  64. })
  65. onMounted(async () => {
  66. auditories.value = await $api.timetable.getClassrooms()
  67. auditoriesFree.value = await $api.timetable.getFreeClassrooms(`${hours}:${minutes}`)
  68. })
  69. </script>