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

90.47% Statements 19/21
60% Branches 6/10
81.81% Functions 9/11
90.47% Lines 19/21

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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185                5x   2x                         1x                   1x                                               5x         5x                                                                                     23x   23x 23x 23x             23x         1x           1x               1x               1x             2x 2x       4x   23x                                                      
<template>
  <v-card
    color="background"
    flat
    tile
  >
    <DrawerTitle :title="t('labels.annotations')" />
    <v-card-text class="d-flex flex-column flex-grow-1 px-2 pb-4 pt-2">
      <div class="new-style pb-2">
        <v-text-field
          v-model="search"
          density="compact"
          variant="outlined"
          prepend-inner-icon="search"
          :placeholder="t('fields.search.placeholder')"
          hide-details
        >
          <template #append-inner>
            <v-btn
              variant="text"
              size="24"
              color="rgba(146, 147, 158, 1)"
              icon="close"
              @click="search = ''"
            />
          </template>
        </v-text-field>
      </div>
      <v-sheet
        class="overflow-auto"
        elevation="2"
      >
        <v-data-table-virtual
          v-model:expanded="expanded"
          :custom-filter="filter"
          density="compact"
          :headers="headers"
          hide-default-header
          :items="items"
          item-value="Id"
          must-sort
          :search="search"
          :sort-by="sortBy"
          :no-data-text="t('labels.noResults')"
        >
          <template
            #[`item.expand`]="{ internalItem, isExpanded, toggleExpand }"
          >
            <v-btn
              variant="text"
              size="24"
              :icon="isExpanded(internalItem) ? '$expand' : 'chevron_forward'"
              @click="toggleExpand(internalItem)"
              color="shark_400"
            />
          </template>
          <template #[`item.title`]="{ item }">
            <div class="d-flex align-center">
              <annotation-icon
                :annotation="item"
                class="ml-1"
              />
              <span class="ml-2 text-truncate text-caption">{{
                item.Title
              }}</span>
            </div>
          </template>
          <template #[`item.actions`]="{ item }">
            <annotation-menu :annotation="item" />
          </template>
          <template #[`item.visibility`]="{ isExpanded, internalItem }">
            <annotation-visibility-btn
              v-if="isExpanded(internalItem)"
              :annotation="internalItem.raw"
            />
          </template>
          <template #expanded-row="{ columns, item }">
            <tr>
              <td
                class="px-0"
                :colspan="columns.length"
              >
                <annotation-info :annotation="item" />
              </td>
            </tr>
          </template>
        </v-data-table-virtual>
      </v-sheet>
    </v-card-text>
  </v-card>
</template>
 
<script setup lang="ts">
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { DataOverlayAnnotation } from '@3cr/viewer-types-ts';
 
interface Props {
  items: DataOverlayAnnotation[];
}
 
withDefaults(defineProps<Props>(), {
  items: () => [],
});
 
const { t } = useI18n();
 
const search = ref<string>('');
const expanded = ref<string[]>([]);
const sortBy = ref([
  {
    key: 'title',
    order: 'asc' as 'asc' | 'desc',
  },
]);
 
const headers = ref([
  {
    key: 'expand',
    width: '24px',
    sortable: false,
    cellProps: (data: any) => ({
      class: ['px-0', 'pl-1', { 'bg-minsk_100': isExpanded(data.item.Id) }],
    }),
  },
  {
    key: 'title',
    cellProps: (data: any) => ({
      class: ['px-1', 'overflow', { 'bg-minsk_100': isExpanded(data.item.Id) }],
    }),
  },
  {
    key: 'visibility',
    width: '24px',
    sortable: false,
    cellProps: (data: any) => ({
      class: ['px-0', { 'bg-minsk_100': isExpanded(data.item.Id) }],
    }),
  },
  {
    key: 'actions',
    width: '24px',
    sortable: false,
    cellProps: (data: any) => ({
      class: ['px-0', 'px-1', { 'bg-minsk_100': isExpanded(data.item.Id) }],
    }),
  },
]);
 
function filter(value: string, query: string, item?: any): boolean {
  const annotation = item.raw as DataOverlayAnnotation;
  return annotation.Title.toLowerCase().includes(query.toLowerCase());
}
 
function isExpanded(id: string): boolean {
  return expanded.value.includes(id);
}
defineExpose({
  search,
  expanded,
  filter,
});
</script>
 
<style scoped lang="scss">
.v-data-table {
  height: 100%;
  width: 100%;
  .active {
    .v-btn__content {
      i.v-icon {
        color: #92939e !important;
      }
    }
  }
}
 
:deep(.overflow) {
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>