Skip to content

Commit 39a2325

Browse files
trslatergithub-actions[bot]
authored andcommittedMar 11, 2025·
Replace condition that kept orders sane
1 parent 30112ce commit 39a2325

File tree

1 file changed

+55
-57
lines changed

1 file changed

+55
-57
lines changed
 

‎alcs-frontend/src/app/features/application/decision/decision-v2/decision-input/decision-conditions/decision-condition-order-dialog/decision-condition-order-dialog.component.ts

+55-57
Original file line numberDiff line numberDiff line change
@@ -48,63 +48,61 @@ export class DecisionConditionOrderDialogComponent implements OnInit {
4848
}
4949

5050
async openMenu($event: MouseEvent, record: ApplicationDecisionConditionDto) {
51-
this.overlayRef?.detach();
52-
$event.preventDefault();
53-
this.selectedRecord = record.uuid;
54-
const positionStrategy = this.overlay
55-
.position()
56-
.flexibleConnectedTo({ x: $event.x, y: $event.y })
57-
.withPositions([
58-
{
59-
originX: 'end',
60-
originY: 'bottom',
61-
overlayX: 'start',
62-
overlayY: 'top',
63-
},
64-
]);
65-
66-
this.overlayRef = this.overlay.create({
67-
positionStrategy,
68-
scrollStrategy: this.overlay.scrollStrategies.close(),
69-
});
70-
71-
this.overlayRef.attach(
72-
new TemplatePortal(this.orderMenu, this.viewContainerRef, {
73-
$implicit: record,
74-
}),
75-
);
76-
}
77-
78-
sendToBottom(record: ApplicationDecisionConditionDto) {
79-
const currentIndex = this.conditionsToOrder.findIndex((item) => item.uuid === record.uuid);
80-
this.conditionsToOrder.sort((a,b) => a.order - b.order).forEach((item) => {
81-
if (item.order > currentIndex) {
82-
item.order--;
83-
}
84-
});
85-
this.conditionsToOrder[currentIndex].order = this.conditionsToOrder.length;
86-
this.dataSource.data = this.conditionsToOrder.sort((a,b) => a.order - b.order);
87-
this.overlayRef?.detach();
88-
this.selectedRecord = undefined;
89-
}
90-
91-
sendToTop(record: ApplicationDecisionConditionDto) {
92-
const currentIndex = this.conditionsToOrder.findIndex((item) => item.uuid === record.uuid);
93-
this.conditionsToOrder.sort((a,b) => a.order - b.order).forEach((item) => {
94-
if (item.order < currentIndex) {
95-
item.order++;
96-
}
97-
});
98-
this.conditionsToOrder[currentIndex].order = 0;
99-
this.dataSource.data = this.conditionsToOrder.sort((a,b) => a.order - b.order);
100-
this.overlayRef?.detach();
101-
this.selectedRecord = undefined;
102-
}
103-
104-
clearMenu() {
105-
this.overlayRef?.detach();
106-
this.selectedRecord = undefined;
107-
}
51+
this.overlayRef?.detach();
52+
$event.preventDefault();
53+
this.selectedRecord = record.uuid;
54+
const positionStrategy = this.overlay
55+
.position()
56+
.flexibleConnectedTo({ x: $event.x, y: $event.y })
57+
.withPositions([
58+
{
59+
originX: 'end',
60+
originY: 'bottom',
61+
overlayX: 'start',
62+
overlayY: 'top',
63+
},
64+
]);
65+
66+
this.overlayRef = this.overlay.create({
67+
positionStrategy,
68+
scrollStrategy: this.overlay.scrollStrategies.close(),
69+
});
70+
71+
this.overlayRef.attach(
72+
new TemplatePortal(this.orderMenu, this.viewContainerRef, {
73+
$implicit: record,
74+
}),
75+
);
76+
}
77+
78+
sendToBottom(record: ApplicationDecisionConditionDto) {
79+
this.conditionsToOrder.forEach((item) => {
80+
if (item.order > record.order) {
81+
item.order--;
82+
}
83+
});
84+
record.order = this.conditionsToOrder.length - 1;
85+
this.dataSource.data = this.conditionsToOrder.sort((a, b) => a.order - b.order);
86+
this.overlayRef?.detach();
87+
this.selectedRecord = undefined;
88+
}
89+
90+
sendToTop(record: ApplicationDecisionConditionDto) {
91+
this.conditionsToOrder.forEach((item) => {
92+
if (item.order < record.order) {
93+
item.order++;
94+
}
95+
});
96+
record.order = 0;
97+
this.dataSource.data = this.conditionsToOrder.sort((a, b) => a.order - b.order);
98+
this.overlayRef?.detach();
99+
this.selectedRecord = undefined;
100+
}
101+
102+
clearMenu() {
103+
this.overlayRef?.detach();
104+
this.selectedRecord = undefined;
105+
}
108106

109107
private moveItem(currentIndex: number, targetIndex: number) {
110108
this.conditionsToOrder.sort((a,b) => a.order - b.order).forEach((item) => {

0 commit comments

Comments
 (0)
Please sign in to comment.