All files / src/views TestHomePage.vue

0% Statements 0/45
0% Branches 0/20
0% Functions 0/26
0% Lines 0/45

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97                                                                                                                                                                                                 
<template>
  <v-container :fluid="true" class="pa-2 d-flex flex-column h-100">
    <v-tabs v-model="activeTab" class="mx-2">
      <v-tab v-for="tab in tabs" :key="tab.value" :value="tab.value"> {{ tab.title }}</v-tab>
    </v-tabs>
    <v-tabs-window v-model="activeTab">
      <!-- Вкладка назначенные -->
      <v-tabs-window-item class="my-2 w-75 mx-auto h-100">
        <CatalogTest :activeTab="activeTab" :testingCard="getAllTests" title="Назначенные">
          <template #buttons>
            <v-btn class="mr-2 text-teal-darken-1" color="#00897B1F" elevation="0">
              Тренироваться
            </v-btn>
            <v-btn color="teal-darken-1" elevation="0"> Пройти</v-btn>
          </template>
        </CatalogTest>
      </v-tabs-window-item>
      <!-- Вкладка завершенных -->
      <v-tabs-window-item class="w-75 mx-auto">
        <CatalogTest :activeTab="activeTab" :testingCard="getAllTests" title="Завершенные">
          <!-- Здесь отобразить результат теста после того как будет готов БЭК и УМТ -->
          <template #results></template>
          <template #buttons>
            <v-btn class="mr-2 text-teal-darken-1" color="#00897B1F" elevation="0">
              Результаты
            </v-btn>
          </template>
        </CatalogTest>
      </v-tabs-window-item>
      <!-- Вкладка каталога -->
      <v-tabs-window-item class="w-75 mx-auto h-100">
        <CatalogTest :activeTab="activeTab" :testingCard="getAllTests" title="Каталог">
          <template #buttons>
            <v-btn class="mr-2 text-teal-darken-1" color="#00897B1F" elevation="0">
              Тренироваться
            </v-btn>
          </template>
        </CatalogTest>
      </v-tabs-window-item>
    </v-tabs-window>
  </v-container>
</template>
 
<script>
import CatalogTest from '@/components/testing/CatalogTest.vue';
import { axiosApiInstance } from '@/utils/axios-api';
 
import { computed, ref, watch } from 'vue';
 
export default {
  components: {
    CatalogTest,
  },
  setup() {
    const activeTab = ref(0);
    const currentTest = ref('');
 
    const getAllTests = ref([]);
 
    const getTestById = () => {
      let status =
        activeTab.value === 0 ? '?status=active' : activeTab.value === 1 ? '?status=completed' : '';
      axiosApiInstance
        .get(`/api/tests/gettests/${status}`)
        .then((resp) => (getAllTests.value = resp.data))
        .finally(() => {
          if (activeTab.value === 0) {
            currentTest.value = getAllTests.value.length;
          }
        });
    };

    getTestById();

    watch(
      () => activeTab.value,
      () => {
        getTestById();
        console.log(getAllTests);
      },
    );
 
    const tabs = computed(() => [
      { value: 0, title: `Назначенные (${currentTest.value})` },
      { value: 1, title: 'Завершенные' },
      { value: 2, title: 'Каталог' },
    ]);

    return {
      activeTab,
      tabs,
      getAllTests,
    };
  },
};
</script>