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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | 1x 96x 2x 6x 3x 5x 2x 1x 6x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 138x 59x 60x 81x 59x 96x 96x 1x 96x 96x 96x 59x 59x 50x 4x 2x 318x 302x 2x 2x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 4x 1x 1x 4x 3x 2x 2x 2x 5x 5x 3x 3x 2x 59x | <template>
<v-data-table-virtual
v-model="selected"
density="compact"
:headers="headers"
hide-default-header
:items="tableItems"
@click:row="selectRow"
item-value="Id"
hover
must-sort
:custom-filter="customFilter"
:row-props="
(item) => ({
class: { 'drag-drop': true, 'group-container': isGroup(item.item.Key) },
id: `item-${item.item.Id}`,
})
"
:search="search"
:sort-by="sortBy"
:no-data-text="t('labels.noResults')"
>
<template
#[`item.data-table-expand`]="{ internalItem, isExpanded, toggleExpand }"
>
<v-btn
v-if="isGroup(internalItem.raw.Key)"
class="pl-3 mr-2"
variant="text"
size="25"
data-testid="expand-btn"
style="z-index: 10"
color="shark_600"
:icon="isExpanded(internalItem) ? '$expand' : 'chevron_forward'"
@click="toggleExpand(internalItem)"
/>
</template>
<template #[`item.lock`]="{ item, isSelected, internalItem }">
<McadLockBtn
style="color: rgba(146, 147, 158, 1)"
:mcad="item"
class="hover-btn"
:class="[isSelected(internalItem) && 'hover-btn-selected']"
/>
</template>
<template #[`item.visibility`]="{ item, isSelected, internalItem }">
<McadVisibilityBtn
style="color: rgba(146, 147, 158, 1)"
:mcad="item"
class="hover-btn"
:class="[isSelected(internalItem) && 'hover-btn-selected']"
/>
</template>
<template #[`item.title`]="{ item }">
<div class="d-flex align-center">
<McadIcon
class="pl-2"
:mcad="item"
/>
<span
v-if="!isGroup(item.Key)"
class="ml-2 text-sm-regular text-truncate"
>
{{ item.Title }}
</span>
<v-text-field
v-else
data-testid="focus-item"
:model-value="focusedGroup?.Id === item.Id ? newTitle : item.Title"
@update:model-value="newTitle = $event"
variant="plain"
density="compact"
hide-details
:class="{ 'background-white': focusedGroup?.Id === item.Id }"
@focus="handleFocus(item)"
@blur="handleBlur(item)"
@keydown.enter="handleBlur(item)"
class="custom-text-field ml-2"
:style="{
backgroundColor: focusedGroup?.Id === item.Id ? 'white' : '',
borderWidth: focusedGroup?.Id === item.Id ? '1px' : '0',
boxShadow:
focusedGroup?.Id === item.Id ? '0 0 0 1px #6875EC' : 'none',
}"
/>
</div>
</template>
<template #[`item.actions`]="{ item }">
<div class="d-inline-flex align-center justify-end">
<McadMenu :mcad="item" />
</div>
</template>
<template v-slot:expanded-row="{ item }">
<tr>
<td
class="pr-0 pl-0"
:colspan="headers.length"
>
<!-- /* v8 ignore next 7 */-->
<McadDataTableItems
v-if="item.Children"
class="pl-4"
:items="item.Children"
:search="search"
style="background-color: #e1eafe"
/>
</td>
</tr>
</template>
</v-data-table-virtual>
</template>
<script setup lang="ts">
import { ref, onMounted, computed } from 'vue';
import { useViewer3cr } from '@/composables/useViewer3cr';
import { useMcadStore } from '@/stores/mcad.store';
import interact from 'interactjs';
import { storeToRefs } from 'pinia';
import { useToolStore } from '@/stores/tool.store';
import { DataOverlayMcad } from '@3cr/viewer-types-ts';
import { useI18n } from 'vue-i18n';
interface Props {
items?: string[];
isPrimary?: boolean;
search?: string;
}
const props = withDefaults(defineProps<Props>(), {
items: () => [],
isPrimary: false,
search: '',
});
const { t } = useI18n();
const { mcads, sortBy } = storeToRefs(useMcadStore());
const { mcadSelectTool } = useToolStore();
const viewer3cr = useViewer3cr();
const groupDataCache = ref<
Record<string, { title: string; children: string[] }>
>({});
const groupNames = ref<Record<string, { name: string; children: string[] }>>(
{},
);
const newTitle = ref<string>('');
const focusedGroup = ref<DataOverlayMcad | null>(null);
const groups = computed(() =>
mcads.value.filter((x) => props.items.filter(isGroup).includes(x.Key)),
);
const selected = computed(() => [mcadSelectTool.selected.value?.Id]);
const tableItems = computed(() => {
return mcads.value.filter(
(mcad) => props.items.findIndex((childId) => childId === mcad.Key) > -1,
);
});
const headers = ref([
{
key: 'data-table-expand',
cellProps: (data: any) => ({
class: [
'px-1',
'overflow',
{ active: mcadSelectTool.isSelected(data.item) },
],
}),
},
{
key: 'title',
sortable: true,
cellProps: (data: any) => ({
class: [
'px-1',
'overflow',
{ active: mcadSelectTool.isSelected(data.item) },
],
}),
sortRaw: (a: DataOverlayMcad, b: DataOverlayMcad) => {
return a.Title.localeCompare(b.Title);
},
},
{
key: 'lock',
width: '24px',
sortable: false,
cellProps: (data: any) => ({
class: ['px-0', 'pl-1', { active: mcadSelectTool.isSelected(data.item) }],
}),
},
{
key: 'visibility',
width: '24px',
sortable: false,
cellProps: (data: any) => ({
class: ['px-0', 'pl-1', { active: mcadSelectTool.isSelected(data.item) }],
}),
},
{
key: 'actions',
width: '32px',
sortable: false,
cellProps: (data: any) => ({
class: ['px-1', { active: mcadSelectTool.isSelected(data.item) }],
}),
},
]);
onMounted(() => {
if (props.isPrimary) {
interact(`.drag-drop`)
.draggable({
inertia: true,
listeners: {
start: onDragStart,
move: onDragMove,
end: onDragEnd,
},
})
.dropzone({
accept: '.drag-drop',
overlap: 0.5,
ondrop: onDrop,
});
}
});
function customFilter(value: string, query: string, item?: { value: any }) {
const foundItem = mcads.value.find((mcad) => mcad.Key === item?.value);
return foundItem?.Title.toLowerCase().includes(query.toLowerCase()) || false;
}
async function addToGroup(droppedId: string, groupId: string): Promise<void> {
const targetGroup = groups.value.find((g) => g.Id === groupId);
if (targetGroup && targetGroup.Children) {
if (!targetGroup.Children.includes(droppedId)) {
await ungroup(targetGroup.Children);
await removeMcad(targetGroup.Id);
await group([...targetGroup.Children, droppedId]);
/* v8 ignore next 3 */
const newGroup = groups.value.find((g) => {
return g.Children?.every(
(c) => targetGroup.Children?.includes(c) || c === droppedId,
);
});
if (newGroup) {
/* v8 ignore next 1 */
const previousName = groupNames.value[groupId]?.name || '';
const cachedData = groupDataCache.value[groupId];
const titleToRetain = cachedData ? cachedData.title : previousName;
await updateMcadTitle(newGroup?.Id, titleToRetain);
}
}
}
}
function isGroup(key: string) {
const node = mcads.value.find((x) => x.Key === key);
return node && node.Children && node.Children.length > 0;
}
function getChildren(key: string): Array<string> | undefined {
const node = mcads.value.find((x) => x.Key === key);
return node && node.Children;
}
function onDragStart(event: any) {
const target = event.target;
const rect = target.getBoundingClientRect();
target.dataset.originalX = rect.left;
target.dataset.originalY = rect.top;
}
function onDragMove(event: any) {
const target = event.target;
const x = (parseFloat(target.getAttribute('data-x')) || 0) + event.delta.x;
const y = (parseFloat(target.getAttribute('data-y')) || 0) + event.delta.y;
target.style.transform = `translate(${x}px, ${y}px)`;
target.setAttribute('data-x', x);
target.setAttribute('data-y', y);
}
function onDragEnd(event: any) {
const target = event.target;
const wasDroppedOnValidTarget = event.dropzone && event.relatedTarget;
if (!wasDroppedOnValidTarget) {
target.style.transform = '';
target.removeAttribute('data-x');
target.removeAttribute('data-y');
}
}
function onDrop(event: any) {
const droppedId = event.relatedTarget.id.replace('item-', '');
const targetId = event.target.id.replace('item-', '');
Iif (event.target.classList.contains('group-container')) {
addToGroup(droppedId, targetId);
} else {
const idsToGroup = [droppedId, targetId];
group(idsToGroup);
}
}
function selectRow(
_$event: MouseEvent,
{ item }: { item: DataOverlayMcad },
): void {
mcadSelectTool.toggle(item);
}
async function group(idsToGroup: string[]): Promise<void> {
const message = { Version: '0.0.0', Parent: '', Children: idsToGroup };
await viewer3cr.groupMcad({ message });
}
async function ungroup(idsToGroup: string[]): Promise<void> {
const message = { Version: '0.0.0', Children: idsToGroup };
await viewer3cr.ungroupMcad({ message });
}
async function removeMcad(id: string): Promise<void> {
const message = { Version: '0.0.0', Id: id };
await viewer3cr.removeMcadObject({ message });
}
async function updateMcadTitle(id: string, newTitle: string): Promise<void> {
const mcad = mcads.value.find((x) => x.Id === id);
if (mcad && isGroup(mcad.Key)) {
const titleMessage = { Version: '0.0.0', Id: id, Value: newTitle };
groupDataCache.value[id] = {
title: newTitle,
children: getChildren(mcad.Key)!!,
};
await viewer3cr.setMcadObjectTitle({ message: titleMessage });
}
}
function handleFocus(item: DataOverlayMcad) {
focusedGroup.value = item;
newTitle.value = item.Title;
}
async function handleBlur(item: DataOverlayMcad) {
focusedGroup.value = null;
if (item.Title !== newTitle.value) {
await updateMcadTitle(item.Id, newTitle.value);
}
}
defineExpose({
onDragEnd,
onDragStart,
onDrop,
onDragMove,
updateMcadTitle,
customFilter,
});
</script>
<style scoped lang="scss">
.v-data-table {
height: 100%;
width: 100%;
}
:deep(.overflow) {
max-width: 0;
text-overflow: ellipsis;
white-space: nowrap;
}
.custom-text-field {
padding: 0 !important;
:deep(input) {
padding: 0 !important;
}
}
</style>
<style lang="scss">
.v-data-table {
background-color: var(--v-background-color);
height: 100%;
.active {
background-color: rgb(var(--v-theme-minsk_050)) !important;
}
}
.drag-drop {
cursor: grab !important;
}
.drag-drop:active {
cursor: grabbing !important;
}
.background-white {
background-color: white !important;
border-radius: 8px !important;
margin: 4px !important;
padding: 0 !important;
}
tr {
.hover-btn {
display: none !important;
}
&:hover .hover-btn,
.hover-btn-selected {
display: inline-flex !important;
}
}
</style>
|