Skip to content

Commit

Permalink
Feature: Report builder - allow replace by drop
Browse files Browse the repository at this point in the history
  • Loading branch information
karelcallens committed Sep 6, 2024
1 parent 103f637 commit da782d1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
<div class="mb-4">
<div class="mb-1">{{ slot.formattedName }}</div>
@for (slotContent of slot.content; track slotContent) {
<div class="flex items-center border border-violet-300 rounded-md text-violet-700 text-sm p-2 mb-1 bg-violet-50 select-none">
<div class="flex items-center border border-violet-300 rounded-md text-violet-700 text-sm p-2 mb-1 bg-violet-50 select-none"
id="data-replace-{{slot.name}}-{{$index}}"
cdkDropList
(cdkDropListDropped)="replace($event, $index)"
cdkDropListConnectedTo="column-list">
<div class="flex items-center grow truncate">
<mat-icon fontSet="material-symbols-outlined" class="icon-20 mr-2 flex-shrink-0">
{{ columnTypeIcons[slotContent.type] }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ export class SlotsDisplayComponent {
}
}

replace(event: CdkDragDrop<string[]>, index: number) {
const column = event.item.data;
const slotNameTemp = event.container.id.replace('data-replace-', '');
const slotName = slotNameTemp.substring(0, slotNameTemp.lastIndexOf('-')) as Slot['name'];

const slotContent: Slot['content'][number] = {
label: column.name,
set: column.securable_id,
column: column.id,
type: column.type,
subtype: column.subtype,
format: column.format
};

const slot = this.chartService.slots().find(slot => slot.name === slotName);

if (slot?.content?.[index]) {
slot.content[index] = slotContent;
this.chartService.updateSlots((this.chartService.slots() ?? []));
}
}

removeColumnFromSlot(slotName: string, indexToRemove: number): void {
const slot = this.chartService.slots().find(slot => slot.name === slotName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
CdkDrag,
CdkDropList,
CdkDropListGroup,
moveItemInArray,
transferArrayItem,
CdkDragPlaceholder,
} from '@angular/cdk/drag-drop';
import { DataService } from '../shared/services/data.service';
Expand Down Expand Up @@ -75,17 +73,6 @@ export class DataPanelComponent implements OnInit {
},
] satisfies Dataset[];

/*datasets = [
{
name: 'Team Stats',
datasetId: '30ee4df6-b311-4774-bbbd-3bdc52753f4a',
},
{
name: 'Player Stats',
datasetId: '97fb82d0-e7aa-4221-8f6e-a410014291b7',
}
] satisfies Dataset[];*/

panelOpenState = false;
collapsed = false;
columnTypeIcons = COLUMN_TYPE_ICONS;
Expand All @@ -107,8 +94,15 @@ export class DataPanelComponent implements OnInit {
constructor() {
effect(() => {
// Update names of CDK drop fields, based on slot names
this.cdkDropLists = CHARTS().find((chart) => chart.type === this.chartService.type())?.slots?.map((slot) => `data-drop-${slot.name}`) ?? [];
this.cdkDropLists.push('data-drop-filter');
this.cdkDropLists = []
for (const slot of this.chartService.slots()) {
this.cdkDropLists.push(`data-drop-${slot.name}`);
if ((slot?.content ?? []).length > 0) {
for (let i = 0; i < slot.content.length; i++) {
this.cdkDropLists.push(`data-replace-${slot.name}-${i}`);
}
}
}
});
}

Expand Down

0 comments on commit da782d1

Please sign in to comment.