Skip to content

Commit 9701bdd

Browse files
committed
Add project's actions
Add actions to project card
1 parent 05620dc commit 9701bdd

File tree

5 files changed

+74
-11
lines changed

5 files changed

+74
-11
lines changed

task-manager/src/app/projects/components/project-list-item/project-list-item.component.css

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
transition: 0.4s ease-in-out;
1616
}
1717

18+
.project-title {
19+
border-bottom: 1px solid black;
20+
}
21+
1822
.project-title,
1923
.project-description,
2024
.project-dates {
@@ -61,12 +65,7 @@
6165
gap: 1em;
6266
}
6367

64-
:host:hover {
65-
transform: scale(1.02);
66-
background-color: var(--accent);
67-
}
68-
69-
:host:active {
68+
:host:active:not(:has(.button:active)) {
7069
transform: scale(0.98);
7170
background-color: var(--accent);
7271
}
@@ -75,3 +74,34 @@
7574
transform: scale(0.98);
7675
background-color: var(--accent);
7776
}
77+
78+
.project-actions {
79+
width: 100%;
80+
height: 100%;
81+
display: inline-flex;
82+
flex-direction: row;
83+
justify-content: space-between;
84+
align-items: center;
85+
gap: 0.5em;
86+
border-top: 1px solid black;
87+
padding: 1em 0em;
88+
box-sizing: border-box;
89+
}
90+
91+
.project-actions .button {
92+
width: 100%;
93+
}
94+
95+
.project-actions .update-button {
96+
background-color: rgba(from var(--info) r g b / 0.5);
97+
}
98+
99+
.project-actions .delete-button {
100+
background-color: rgba(from var(--error) r g b / 0.5);
101+
}
102+
103+
.button {
104+
display: inline-flex;
105+
justify-content: space-around;
106+
align-items: center;
107+
}

task-manager/src/app/projects/components/project-list-item/project-list-item.component.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ <h2 class="project-title">{{ title }}</h2>
44
<tm-tag [label]="startingAt" type="info" [icon]="clock"></tm-tag>
55
<tm-tag [label]="endingAt" type="info" [icon]="clock"></tm-tag>
66
</div>
7+
<div class="project-actions">
8+
<button tmButton class="button update-button" (click)="onUpdate($event)">
9+
Update <fa-icon class="icon" [icon]="pencil"></fa-icon>
10+
</button>
11+
<button tmButton class="button delete-button" (click)="onDelete($event)">
12+
Delete <fa-icon class="icon" [icon]="trash"></fa-icon>
13+
</button>
14+
</div>

task-manager/src/app/projects/components/project-list-item/project-list-item.component.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
import { Component, HostBinding, Input } from '@angular/core';
1+
import { Component, HostBinding, inject, Input } from '@angular/core';
22
import { CommonModule } from '@angular/common';
3-
import { Project, TagComponent } from 'src/app/shared';
3+
import { ButtonComponent, Project, StoreProjectService, TagComponent } from 'src/app/shared';
44
import * as moment from 'moment';
5-
import { faClock } from '@fortawesome/free-solid-svg-icons';
5+
import { faClock, faPencilAlt, faTrash } from '@fortawesome/free-solid-svg-icons';
6+
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
67

78
@Component({
89
standalone: true,
910
selector: 'tm-project-list-item',
10-
imports: [CommonModule, TagComponent],
1111
templateUrl: './project-list-item.component.html',
1212
styleUrls: ['./project-list-item.component.css'],
13+
imports: [CommonModule, TagComponent, ButtonComponent, FontAwesomeModule],
1314
})
1415
export class ProjectListItemComponent {
16+
private readonly storeProjectService: StoreProjectService;
17+
18+
public constructor() {
19+
this.storeProjectService = inject(StoreProjectService);
20+
}
21+
1522
@Input() public project!: Project;
1623

1724
@HostBinding('attr.draggable')
@@ -31,11 +38,28 @@ export class ProjectListItemComponent {
3138
return faClock;
3239
}
3340

41+
public get pencil() {
42+
return faPencilAlt;
43+
}
44+
45+
public get trash() {
46+
return faTrash;
47+
}
48+
3449
public get startingAt() {
3550
return `Starting at: ${moment(this.project.startingAt).format('DD/MM/YYYY')}`;
3651
}
3752

3853
public get endingAt() {
3954
return `Ending at: ${moment(this.project.endingAt).format('DD/MM/YYYY')}`;
4055
}
56+
57+
public onUpdate(event: MouseEvent) {
58+
event.stopImmediatePropagation();
59+
}
60+
61+
public onDelete(event: MouseEvent) {
62+
event.stopImmediatePropagation();
63+
this.storeProjectService.delete(this.project, 'id');
64+
}
4165
}

task-manager/src/app/projects/components/project-list/project-list.component.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
grid-template-columns: repeat(4, 1fr);
99
gap: 1em;
1010
padding: 1em 2em;
11+
box-sizing: border-box;
1112
}

task-manager/src/app/shared/services/store-collection.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ export abstract class StoreCollectionService<T> extends StoreService<T[]> {
2323
}
2424

2525
public delete(item: T, keyName: keyof T): void {
26-
this.value = this.value.filter((anItem) => anItem[keyName] === item[keyName]);
26+
this.value = this.value.filter((anItem) => anItem[keyName] !== item[keyName]);
2727
}
2828
}

0 commit comments

Comments
 (0)