All files / src/components/navigation/annotation AnnotationTools.vue

95% Statements 38/40
88.88% Branches 16/18
94.44% Functions 17/18
94.59% Lines 35/37

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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166                                                  444x           2x               9x 5x                 1x         2x               8x 5x                 1x             2x       1x                             69x 69x 69x       69x   69x 69x 69x   69x   69x   69x                             69x           69x 17x 9x       69x 2x 1x       69x 60x       1x 1x       1x 1x     69x        
<template>
  <v-card
    v-bind="$attrs"
    color="background"
    flat
    tile
  >
    <DrawerTitle :title="t('labels.annotationTools')" />
    <v-card-text class="px-2 pb-4">
      <v-tabs
        :model-value="activeIndex"
        fixed-tabs
        :mandatory="false"
      >
        <v-tab
          v-for="item in tabs"
          width="45%"
          @click="item.click"
        >
          <v-icon :icon="item.icon" />
          <v-tooltip
            location="bottom"
            activator="parent"
            open-delay="1000"
          >
            {{ item.tooltip }}
            {{ translateTooltipShortcut(item.tooltipShortcut) }}
          </v-tooltip>
        </v-tab>
      </v-tabs>
      <v-snackbar
        v-model="s_create"
        variant="flat"
        transition="slide-y-reverse-transition"
        class="mb-3"
      >
        <v-icon
          class="minsk-500 pr-3"
          icon="arrow_selector_tool"
        />
        <span class="shark-950 text-center">{{
          t('texts.annotationMoveHelp')
        }}</span>
        <template #actions>
          <v-icon
            class="ml-auto mr-3 shark-400"
            icon="close"
            size="small"
            variant="flat"
            @click="s_create = false"
          />
        </template>
      </v-snackbar>
      <v-snackbar
        v-model="s_move"
        variant="flat"
        transition="slide-y-reverse-transition"
        class="mb-3"
      >
        <v-icon
          class="minsk-500 pr-3"
          icon="drag_pan"
        />
        <span class="shark-950 text-center">{{
          t('texts.annotationMoveHelp')
        }}</span>
        <template #actions>
          <v-icon
            class="ml-auto mr-3 shark-400"
            icon="close"
            size="small"
            variant="flat"
            @click="s_move = false"
          />
        </template>
      </v-snackbar>
    </v-card-text>
  </v-card>
  <AnnotationCreateModal
    v-model="m_annotationCreate"
    :annotation="annotation!"
    :return-to="returnTo"
  />
  <AnnotationDeleteSnackbar v-model="s_annotationDelete" />
</template>
 
<script setup lang="ts">
import { computed, onBeforeUnmount, ref, watch } from 'vue';
import { useToolStore } from '@/stores/tool.store';
import { storeToRefs } from 'pinia';
import { useI18n } from 'vue-i18n';
import {
  SHORTCUT_TEXT,
  translateTooltipShortcut,
} from '@/functions/translateTooltipShortcut';
import { useViewerStore } from '@/stores/viewer.store';
import { useToolGroup } from '@/composables/useToolGroup';
 
const { t } = useI18n();
const { annotationCreateTool, annotationMoveTool } = useToolStore();
const { activeTool, activeIndex, toggleTool } = useToolGroup(
  annotationCreateTool,
  annotationMoveTool,
);
const { s_annotationDelete } = storeToRefs(useViewerStore());
 
const m_annotationCreate = ref<boolean>(false);
const s_create = ref<boolean>(false);
const s_move = ref<boolean>(false);
 
const annotation = computed(() => annotationCreateTool.annotation.value);
 
const returnTo = computed(() => annotationCreateTool.returnTo.value);
 
const tabs = computed(() => [
  {
    icon: 'edit_square',
    click: create,
    tooltip: t('labels.create'),
    tooltipShortcut: SHORTCUT_TEXT.c,
  },
  {
    icon: 'drag_pan',
    click: move,
    tooltip: t('labels.move'),
    tooltipShortcut: SHORTCUT_TEXT.m,
  },
]);
 
watch(annotationCreateTool.annotation, (value) => {
  if (value) {
    m_annotationCreate.value = true;
  }
});
 
watch(annotationCreateTool.isActive, (value) => {
  if (!value) {
    m_annotationCreate.value = false;
  }
});
 
watch(m_annotationCreate, (isOpen) => {
  if (!isOpen) {
    annotationCreateTool.isActive.value = false;
  }
});
 
onBeforeUnmount(() => {
  activeTool.value = null;
});
 
function create(): void {
  s_create.value = toggleTool(annotationCreateTool);
  s_move.value = false;
}
 
function move(): void {
  s_create.value = false;
  s_move.value = toggleTool(annotationMoveTool);
}
 
defineExpose({ create, move });
 
defineOptions({ inheritAttrs: false });
</script>