All files / src/components/modal/menus AutoAnnotateMenu.vue

100% Statements 26/26
92.85% Branches 13/14
100% Functions 8/8
100% Lines 25/25

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      5x           5x                 74x                             2x     1x 1x                     30x 30x   30x 30x 30x 30x 30x     5x 4x   1x         1x 1x 1x 1x 1x 1x 1x 1x       30x                    
<template>
  <v-menu
    v-bind="$attrs"
    v-model="menuOpen"
    :close-on-content-click="false"
    width="492"
    data-testid="menu"
  >
    <template #activator="{ props, isActive }">
      <div class="d-flex">
        <v-btn
          class="rounded-e-0"
          color="primary"
          prepend-icon="auto_awesome"
          variant="outlined"
          @click="checkAndOpenMenu"
          data-testid="openBtn"
        >
          <span class="minsk-900">{{ t('labels.runAiModels') }}</span>
        </v-btn>
        <v-btn
          v-bind="props"
          class="border-s-0 rounded-s-0"
          color="primary"
          size="40"
          variant="outlined"
        >
          <v-icon :icon="isActive ? 'close' : 'arrow_drop_down'" />
        </v-btn>
      </div>
    </template>
    <ai-model-list
      data-testid="modelList"
      v-model:selected="selectedModels"
    />
  </v-menu>
  <AutoAnnotateModal v-model="loading" />
  <AnnotationGeneratedSnackbar v-model="s_annotate" />
</template>
 
<script setup lang="ts">
import { storeToRefs } from 'pinia';
import { ref } from 'vue';
import { useViewerStore } from '@/stores/viewer.store';
import { useI18n } from 'vue-i18n';
 
defineOptions({ inheritAttrs: false });
 
const { t } = useI18n();
const { options } = storeToRefs(useViewerStore());
 
const selectedModels = ref<string[]>([]);
const loading = ref<boolean>(false);
const s_annotate = ref<boolean>(false);
const done = ref<boolean>(false);
const menuOpen = ref(false);
 
async function checkAndOpenMenu(): Promise<void> {
  if (selectedModels.value.length === 0) {
    menuOpen.value = true;
  } else {
    await runAiModels();
  }
}
 
async function runAiModels(): Promise<void> {
  Eif (options.value.onRunAIModel) {
    loading.value = true;
    await options.value.onRunAIModel(selectedModels.value);
    setTimeout(() => {
      loading.value = false;
      done.value = true;
      s_annotate.value = true;
      selectedModels.value = [];
    }, 4000);
  }
}
defineExpose({
  menuOpen,
  selectedModels,
  runAiModels,
  done,
  loading,
  s_annotate,
  checkAndOpenMenu,
});
</script>