All files / src/components/navigation/measurement MeasurementDataTable.vue

95.23% Statements 20/21
60% Branches 6/10
90.9% Functions 10/11
95.23% Lines 20/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 186 187 188 189 190                5x   2x                         1x                   1x                                               5x         5x                                                                                                 26x   26x 26x 26x             26x         1x               1x       1x             1x               1x             4x       2x 2x     26x                                        
<template>
  <v-card
    color="background"
    flat
    tile
  >
    <DrawerTitle :title="t('labels.measurements')" />
    <v-card-text class="d-flex flex-column px-2 pb-4 pt-2">
      <div class="new-style pb-2">
        <v-text-field
          v-model="search"
          density="compact"
          prepend-inner-icon="search"
          :placeholder="t('fields.search.placeholder')"
          variant="outlined"
          hide-details
        >
          <template #append-inner>
            <v-btn
              variant="text"
              color="rgba(146, 147, 158, 1)"
              size=""
              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">
              <measurement-icon
                :measurement="item"
                class="ml-1"
              />
              <span class="ml-2 text-truncate text-caption">{{
                item.Title
              }}</span>
            </div>
          </template>
          <template #[`item.actions`]="{ item }">
            <div>
              <measurement-menu :measurement="item" />
            </div>
          </template>
          <template #[`item.visibility`]="{ isExpanded, internalItem }">
            <measurement-visibility-btn
              v-if="isExpanded(internalItem)"
              :measurement="internalItem.raw"
              color="shark_400"
            />
          </template>
          <template #expanded-row="{ columns, item }">
            <tr>
              <td
                class="px-0"
                :colspan="columns.length"
              >
                <measurement-info
                  :measurement="item"
                  :is-modal="false"
                />
              </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 { DataOverlayMeasurement } from '@3cr/viewer-types-ts';
 
interface Props {
  items: DataOverlayMeasurement[];
}
 
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',
    sortable: true,
    cellProps: (data: any) => ({
      class: ['px-1', 'overflow', { 'bg-minsk_100': isExpanded(data.item.Id) }],
    }),
    sortRaw: (a: DataOverlayMeasurement, b: DataOverlayMeasurement) => {
      return a.Title.localeCompare(b.Title);
    },
  },
  {
    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', 'pr-1', { 'bg-minsk_100': isExpanded(data.item.Id) }],
    }),
  },
]);
 
function isExpanded(id: string): boolean {
  return expanded.value.includes(id);
}
 
function filter(value: string, query: string, item?: any): boolean {
  const measurement = item.raw as DataOverlayMeasurement;
  return measurement.Title.toLowerCase().includes(query.toLowerCase());
}
 
defineExpose({
  search,
  expanded,
  filter,
});
</script>
 
<style scoped lang="scss">
.v-data-table {
  height: 100%;
  width: 100%;
}
 
:deep(.overflow) {
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>