Skip to content

Commit d02a27d

Browse files
committed
up
1 parent b95e932 commit d02a27d

File tree

4 files changed

+29
-46
lines changed

4 files changed

+29
-46
lines changed

src/app/history/history.component.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
top: 0;
77
left: 0;
88
overflow-x: hidden;
9-
background-color: #d6d6d6;
109
border-right-style: solid;
1110
border-width: medium;
1211
overflow-y: auto;
@@ -39,7 +38,6 @@
3938
color: black;
4039
background-color: white;
4140
border-width: thin;
42-
font-family: 'Josefin Sans', sans-serif;
4341
font-size: 20px;
4442
}
4543

@@ -50,7 +48,6 @@
5048
color: black;
5149
background-color: white;
5250
border-width: thin;
53-
font-family: 'Josefin Sans', sans-serif;
5451
}
5552

5653
.history-button-inactive {
@@ -60,7 +57,6 @@
6057
color: lightgray;
6158
background-color: gray;
6259
border-width: thin;
63-
font-family: 'Josefin Sans', sans-serif;
6460
}
6561

6662
.header button:disabled {
@@ -70,6 +66,5 @@
7066
color: black;
7167
background-color: lightgray;
7268
border-width: thin;
73-
font-family: 'Josefin Sans', sans-serif;
7469
font-size: 20px;
7570
}

src/app/tab-cards/tab-cards.component.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
user-select: none; /* Non-prefixed version, currently supported by Chrome, Edge, Opera and Firefox */
1717
}
1818

19+
.card-elt {
20+
pointer-events: none;
21+
}
22+
1923
.cards-block {
2024
min-width: 33%;
2125
min-height: 50px;

src/app/tab-cards/tab-cards.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<div class="cards-block" #cards1>
44
<mat-card *ngFor="let card of dataService.cards1" class="cards">
5-
<mat-card-header>
5+
<mat-card-header class="card-elt">
66
<mat-card-title>{{card.title}}</mat-card-title>
77
<mat-card-subtitle>{{card.subTitle}}</mat-card-subtitle>
88
</mat-card-header>
9-
<mat-card-content>
9+
<mat-card-content class="card-elt">
1010
<p>
1111
{{card.text}}
1212
</p>
@@ -16,11 +16,11 @@
1616

1717
<div class="cards-block" #cards2>
1818
<mat-card *ngFor="let card of dataService.cards2" class="cards">
19-
<mat-card-header>
19+
<mat-card-header class="card-elt">
2020
<mat-card-title>{{card.title}}</mat-card-title>
2121
<mat-card-subtitle>{{card.subTitle}}</mat-card-subtitle>
2222
</mat-card-header>
23-
<mat-card-content>
23+
<mat-card-content class="card-elt">
2424
<p>
2525
{{card.text}}
2626
</p>

src/app/tab-cards/tab-cards.component.ts

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class TabCardsComponent extends TabContentComponent implements AfterViewI
3333
// it most of the time since this.bindings.undoHistory returns the same instance).
3434
}
3535

36-
ngAfterViewInit() {
36+
public ngAfterViewInit(): void {
3737
// This binder creates the command that allows the user to move a card from one list to another
3838
this.bindings.dndBinder(true)
3939
.on(window.document.body)
@@ -43,55 +43,35 @@ export class TabCardsComponent extends TabContentComponent implements AfterViewI
4343
return new TransferArrayItem<CardData>([], [], -1, 0, 'Drag card');
4444
})
4545
// Checks if the user picked a valid card, and a new list for the card as a destination
46-
.when(i => {
47-
// A valid card has to be selected in order to create the command
48-
const card = (i.src.target as Element).closest('mat-card');
49-
return card !== null;
50-
})
46+
.when(i => (i.src.target as Element).classList.contains('mat-card'))
5147
.first((_, i) => {
52-
this.card = (i.src.target as Element).closest('mat-card') as HTMLElement;
48+
this.card = (i.src.target as HTMLElement);
5349
this.sourceIndex = Array.prototype.indexOf.call(this.card!.parentNode?.children ?? [], this.card);
5450
// Saves the initial state of the card's style to be able to restore it if the command can't be executed
5551
this.mementoX = this.card.style.left;
5652
this.mementoY = this.card.style.top;
5753
this.mementoCSSPosition = this.card.style.position;
58-
// Edits the card's style to make it movable visually
59-
this.card.style.width = String(this.card.clientWidth - 32) + 'px';
60-
this.card.style.position = 'absolute';
54+
55+
this.card.style.position = 'relative';
6156
this.card.style.zIndex = '999';
57+
6258
})
6359
.then((c, i) => {
64-
// Retrieves the position of the mouse on the page (substract the sidebar size)
65-
let x = i.tgt.pageX - 220;
66-
let y = i.tgt.pageY;
67-
// Prevents parts of the card from going outside of the document
68-
if (i.tgt.pageX > window.innerWidth - this.card!.clientWidth - 10) {
69-
x = x - this.card!.clientWidth - 5;
70-
}
71-
if (i.tgt.pageY > window.innerHeight - this.card!.clientHeight - 15) {
72-
y = y - this.card!.clientHeight - 5;
73-
}
74-
75-
// Moves the card visually
76-
this.card!.style.left = String(x) + 'px';
77-
this.card!.style.top = String(y) + 'px';
60+
this.card!.style.left = `${i.diffClientX}px`;
61+
this.card!.style.top = `${i.diffClientY}px`;
62+
c.srcIndex = this.sourceIndex;
7863

79-
// Checks if the target selected is valid for the current card and makes the command executable if it is
80-
const isCardPositionValid = (this.card!.parentNode === this.cards1.nativeElement ?
81-
i.tgt.target === this.cards2.nativeElement : i.tgt.target === this.cards1.nativeElement);
82-
if (!isCardPositionValid) {
83-
c.srcIndex = -1;
64+
if (this.insideRectangle(this.cards2.nativeElement.getBoundingClientRect(), i.tgt.clientX, i.tgt.clientY) &&
65+
!this.insideRectangle(this.cards2.nativeElement.getBoundingClientRect(), i.src.clientX, i.src.clientY)) {
66+
c.srcArray = this.dataService.cards1;
67+
c.tgtArray = this.dataService.cards2;
8468
} else {
85-
c.srcIndex = this.sourceIndex;
86-
87-
// Defines which array is the source and which one is the target
88-
const fromSrcToTgt = i.tgt.target === this.cards2.nativeElement && i.src.target !== this.cards1.nativeElement;
89-
if (fromSrcToTgt) {
90-
c.srcArray = this.dataService.cards1;
91-
c.tgtArray = this.dataService.cards2;
92-
} else {
69+
if (this.insideRectangle(this.cards1.nativeElement.getBoundingClientRect(), i.tgt.clientX, i.tgt.clientY) &&
70+
!this.insideRectangle(this.cards1.nativeElement.getBoundingClientRect(), i.src.clientX, i.src.clientY)) {
9371
c.srcArray = this.dataService.cards2;
9472
c.tgtArray = this.dataService.cards1;
73+
} else {
74+
c.srcIndex = -1;
9575
}
9676
}
9777
})
@@ -108,4 +88,8 @@ export class TabCardsComponent extends TabContentComponent implements AfterViewI
10888
})
10989
.bind();
11090
}
91+
92+
private insideRectangle(rec: DOMRect, x: number, y: number): boolean {
93+
return x >= rec.x && y >= rec.y && x <= (rec.x + rec.width) && y <= (rec.y + rec.height);
94+
}
11195
}

0 commit comments

Comments
 (0)