Skip to content

Commit f2ecd3a

Browse files
author
Manuela Paula Ritter
committed
update task model, update reactive form for task
1 parent 207a7a0 commit f2ecd3a

11 files changed

+116
-103
lines changed

src/app/matrix/canvas/canvas.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<app-task-dot
66
*ngFor="let task of tasks[topic.id]"
77
[style.top]="task.importance | yPosition"
8-
[style.left]="task.dueDate | xPosition: maxDate"
8+
[style.left]="task.dueDay | xPosition: task.dueMonth:task.dueYear:maxDate"
99
[task]="task"
1010
[topic]="topic"
1111
(selectTask)="onSelectTask($event)"

src/app/matrix/detail/detail.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ <h2>Settings</h2>
44
<app-task-card
55
[task]="task"
66
[position]="i"
7-
[topic]="topics[task.topic]"
7+
[topicsForSelect]="topics"
88
(changeTask)="changeTask($event)"
99
></app-task-card>
1010
</p>

src/app/matrix/detail/detail.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, OnInit } from '@angular/core';
22
import { map } from 'rxjs/operators';
3-
import { Task, Topic } from '../matrix.interfaces';
3+
import { Task, TopicDictionary } from '../matrix.interfaces';
44
import { MatrixService } from '../matrix.service';
55

66
@Component({
@@ -10,7 +10,7 @@ import { MatrixService } from '../matrix.service';
1010
})
1111
export class DetailComponent implements OnInit {
1212
taskHistory: Task[] = [];
13-
topics: { [key: number]: Topic } = {};
13+
topics: TopicDictionary = {};
1414

1515
constructor(private readonly matrixService: MatrixService) {}
1616

src/app/matrix/matrix.effects.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import {
99
GetMatrixData,
1010
GetMatrixDataFailed,
1111
GetMatrixDataSuccess,
12+
UPDATE_TASK,
13+
UpdateTask,
14+
UpdateTaskFailed,
15+
UpdateTaskSuccess,
1216
} from './matrix.actions';
1317
import { MatrixData, Task, Topic } from './matrix.interfaces';
1418

@@ -20,22 +24,15 @@ export class MatrixEffects {
2024
new Topic(3, 'LongName Topic', Color.orange, true, false),
2125
];
2226
private tasks: Task[] = [
23-
new Task(1, 'Tast', 1, 60, new Date('2020-12-01T12:00:00.000Z')),
24-
new Task(2, 'Tast 2', 2, 20),
25-
new Task(3, 'Tast 3', 1, 33),
26-
new Task(4, 'Tast 4', 2, 99),
27-
new Task(5, 'Long Name Task', 3, 44),
28-
new Task(6, 'tttttt anen', 3, 55, new Date('2020-12-02T12:00:00.000Z')),
29-
new Task(7, 'Tast 2930', 1, 1, new Date('2020-11-20T12:00:00.000Z')),
30-
new Task(8, 'nenene', 2, 2, new Date('2020-11-28T12:00:00.000Z')),
31-
new Task(
32-
9,
33-
'nnn',
34-
3,
35-
90,
36-
new Date('2020-12-10T12:00:00.000Z'),
37-
'test description',
38-
),
27+
new Task(1, 'Tast', 1, 60, 1, 12, 20),
28+
new Task(2, 'Tast 2', 2, 20, 10, 12, 20),
29+
new Task(3, 'Tast 3', 1, 33, 30, 11, 20),
30+
new Task(4, 'Tast 4', 2, 99, 5, 12, 20),
31+
new Task(5, 'Long Name Task', 3, 44, 7, 12, 20),
32+
new Task(6, 'tttttt anen', 3, 55, 2, 12, 20),
33+
new Task(7, 'Tast 2930', 1, 1, 20, 11, 20),
34+
new Task(8, 'nenene', 2, 2, 28, 11, 20),
35+
new Task(9, 'nnn', 3, 90, 10, 12, 20, 'test description'),
3936
];
4037
private data: MatrixData = {
4138
topics: this.topics,
@@ -49,12 +46,20 @@ export class MatrixEffects {
4946
ofType<GetMatrixData>(GET_MATRIX_DATA),
5047
mergeMap(() =>
5148
of(this.data).pipe(
52-
map((data: MatrixData) => {
53-
console.log(data);
54-
return new GetMatrixDataSuccess(data);
55-
}),
49+
map((data: MatrixData) => new GetMatrixDataSuccess(data)),
5650
catchError((message) => of(new GetMatrixDataFailed(message))),
5751
),
5852
),
5953
);
54+
55+
@Effect()
56+
updateTask$: Observable<Action> = this.actions$.pipe(
57+
ofType<UpdateTask>(UPDATE_TASK),
58+
mergeMap((action) =>
59+
of(action.task).pipe(
60+
map((task: Task) => new UpdateTaskSuccess(task)),
61+
catchError((message) => of(new UpdateTaskFailed(message))),
62+
),
63+
),
64+
);
6065
}

src/app/matrix/matrix.interfaces.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export class Task {
2121
public name: string,
2222
public topic: number,
2323
public importance: number,
24-
public dueDate: Date = new Date(),
24+
public dueDay: number,
25+
public dueMonth: number,
26+
public dueYear: number,
2527
public description: string = '',
2628
public done: boolean = false,
2729
public deleted: boolean = false,

src/app/matrix/matrix.reducers.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ describe('MatrixReducers', () => {
5050
});
5151

5252
it('should set loading on UPDATE_TASK', () => {
53-
const action: MatrixAction = new UpdateTask(new Task(1, 'test', 1, 1));
53+
const action: MatrixAction = new UpdateTask(
54+
new Task(1, 'test', 1, 1, 1, 12, 2020),
55+
);
5456
const newState = matrixReducer(defaultState, action);
5557
expect(newState).toEqual(loadingState);
5658
});
@@ -143,7 +145,7 @@ describe('MatrixReducers', () => {
143145

144146
it('should set unloading on UPDATE_TASK_SUCCESS', () => {
145147
const action: MatrixAction = new UpdateTaskSuccess(
146-
new Task(1, 'test', 1, 1),
148+
new Task(1, 'test', 1, 1, 1, 12, 2020),
147149
);
148150
const newState = matrixReducer(defaultState, action);
149151
expect(newState.isLoading).toEqual(false);
@@ -201,9 +203,9 @@ describe('MatrixReducers', () => {
201203
it('should update task on UPDATE_TASK_SUCCESS', () => {
202204
defaultState = {
203205
...defaultState,
204-
tasks: { [1]: [new Task(1, 'test', 1, 1)] },
206+
tasks: [new Task(1, 'test', 1, 1, 1, 12, 2020)],
205207
};
206-
const updatedTask = new Task(1, 'test', 7, 1);
208+
const updatedTask = new Task(1, 'test', 7, 1, 1, 12, 2020);
207209
const action: MatrixAction = new UpdateTaskSuccess(updatedTask);
208210
const newState = matrixReducer(defaultState, action);
209211
expect(newState.tasks[1]).toContain(updatedTask);

src/app/matrix/matrix.service.mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
@Injectable()
1212
export class MatrixMockService implements MatrixService {
1313
testTopic = new Topic(1, 'Test', Color.orange, true, false);
14-
testTask = new Task(1, 'Test Task', 1, 23);
14+
testTask = new Task(1, 'Test Task', 1, 23, 1, 12, 20);
1515

1616
getData(): void {}
1717
updateTask(task: Task): void {}

src/app/matrix/task-card/task-card.component.html

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,29 @@
1-
<div [class]="topic.color">
1+
<div [class]="topicsForSelect[task.topic].color">
22
<div *ngIf="position <= 1" class="card-container">
3-
<label *ngIf="task.name === ''" class="name-label" for="name"
4-
>task name</label
5-
>
6-
<input
7-
type="text"
8-
class="name-input"
9-
id="name"
10-
required
11-
value="{{ task.name }}"
12-
/>
13-
<label for="description">description</label>
14-
<textarea id="description" value="{{ task.description }}"></textarea>
15-
<div class="row imp-due-date">
16-
<input
17-
type="number"
18-
id="importance"
19-
required
20-
value="{{ task.importance }}"
21-
/>
22-
<span class="separator">imp.</span>
23-
<input type="number" id="day" value="{{ task.dueDate.getDay() + 1 }}" />
24-
<span>.</span>
25-
<input
26-
type="number"
27-
id="month"
28-
value="{{ task.dueDate.getMonth() + 1 }}"
29-
/>
30-
<span>.</span>
31-
<span>20</span>
32-
<input
33-
type="number"
34-
id="year"
35-
value="{{ task.dueDate.getFullYear() - 2000 }}"
36-
/>
37-
</div>
38-
<div class="row topic-done">
39-
<p>{{ task.topic }}</p>
40-
<button class="done-btn">
41-
{{ task.done ? 'mark undone' : 'mark done' }}
42-
</button>
43-
</div>
3+
<form [formGroup]="taskForm">
4+
<input formControlName="name" class="name-input" type="text" />
5+
<textarea formControlName="description"></textarea>
6+
<div class="row imp-due-date">
7+
<input type="number" required formControlName="importance" />
8+
<span class="separator">imp.</span>
9+
<input type="number" formControlName="dueDay" />
10+
<span>.</span>
11+
<input type="number" formControlName="dueMonth" />
12+
<span>.</span>
13+
<span>20</span>
14+
<input type="number" formControlName="dueYear" />
15+
</div>
16+
<div class="row topic-done">
17+
<select formControlName="topic">
18+
<option *ngFor="let t of topicsForSelect | keyvalue" [ngValue]="t.value.id">
19+
{{ t.value.name }}
20+
</option>
21+
</select>
22+
<button class="done-btn">
23+
{{ task.done ? 'mark undone' : 'mark done' }}
24+
</button>
25+
</div>
26+
</form>
4427
</div>
4528

4629
<div *ngIf="position >= 2" class="card-small-container">

src/app/matrix/task-card/task-card.component.scss

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,27 @@
44
padding: 1rem;
55
background-color: green;
66
border-radius: 20px;
7-
display: flex;
8-
flex-direction: column;
97
color: #f3f3f3;
8+
9+
form {
10+
display: flex;
11+
flex-direction: column;
12+
}
13+
14+
input,
15+
textarea {
16+
color: #f3f3f3;
17+
border: none;
18+
background-color: transparent;
19+
}
20+
21+
input[type='text'] {
22+
font-size: 2rem;
23+
}
24+
25+
textarea {
26+
font-size: 1rem;
27+
}
1028
}
1129

1230
.separator {
@@ -54,16 +72,8 @@
5472
$color-secondary 83.94%
5573
);
5674

57-
input,
58-
textarea {
59-
color: #f3f3f3;
60-
border: none;
61-
background-color: transparent;
62-
}
63-
6475
input[type='text'],
6576
textarea {
66-
font-size: 2rem;
6777
font-family: Nunito;
6878
border-bottom: 1px solid $color-lighter;
6979
}

src/app/matrix/task-card/task-card.component.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
1-
import { Component, EventEmitter, Input, Output } from '@angular/core';
2-
import { FormControl, FormGroup } from '@angular/forms';
3-
import { Task, Topic } from '../matrix.interfaces';
1+
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2+
import { FormBuilder, FormGroup } from '@angular/forms';
3+
import { debounceTime, map, switchMap } from 'rxjs/operators';
4+
import { Task, TopicDictionary } from '../matrix.interfaces';
45

56
@Component({
67
selector: 'app-task-card',
78
templateUrl: './task-card.component.html',
89
styleUrls: ['./task-card.component.scss'],
910
})
10-
export class TaskCardComponent {
11+
export class TaskCardComponent implements OnInit {
1112
@Input() task!: Task;
12-
@Input() topic!: Topic;
13+
@Input() topicsForSelect: TopicDictionary = {};
1314
@Input() position = 0;
1415
@Output() changeTask = new EventEmitter<Task>();
15-
taskForm = new FormGroup({
16-
name: new FormControl(''),
17-
description: new FormControl(''),
18-
importance: new FormControl(''),
19-
dueDate: new FormGroup({
20-
day: new FormControl(''),
21-
month: new FormControl(''),
22-
year: new FormControl(''),
23-
}),
24-
topic: new FormControl(''),
25-
done: new FormControl(''),
26-
});
16+
taskForm!: FormGroup;
17+
18+
constructor(private fb: FormBuilder) {}
19+
20+
ngOnInit(): void {
21+
this.taskForm = this.fb.group(this.task);
22+
this.taskForm.valueChanges
23+
.pipe(
24+
debounceTime(500),
25+
map((change: Task) => {
26+
console.log(change);
27+
if (change) {
28+
this.changeTask.emit(change);
29+
return change;
30+
}
31+
}),
32+
)
33+
.subscribe();
34+
}
2735

2836
onChange(task: Task): void {
2937
this.changeTask.emit(task);

0 commit comments

Comments
 (0)