Adding 'Add Task' feature. Create a task-content model for better understanding.
All checks were successful
Deploying Website / build (push) Successful in 1m6s
All checks were successful
Deploying Website / build (push) Successful in 1m6s
This commit is contained in:
parent
f91561db26
commit
97d8a8ebc3
@ -1,20 +1,20 @@
|
|||||||
<div class="backdrop" (click)="onCancel()"></div>
|
<div class="backdrop" (click)="onCancel()"></div>
|
||||||
<dialog open>
|
<dialog open>
|
||||||
<h2>Add Task</h2>
|
<h2>Add Task</h2>
|
||||||
<form>
|
<form (ngSubmit)="onSubmit()">
|
||||||
<p>
|
<p>
|
||||||
<label for="title">Title</label>
|
<label for="title">Title</label>
|
||||||
<input type="text" id="title" name="title" />
|
<input type="text" id="title" name="title" [(ngModel)]="enteredTitle" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<label for="summary">Summary</label>
|
<label for="summary">Summary</label>
|
||||||
<textarea id="summary" rows="5" name="summary"></textarea>
|
<textarea id="summary" rows="5" name="summary" [(ngModel)]="enteredSummary"></textarea>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<label for="due-date">Due Date</label>
|
<label for="due-date">Due Date</label>
|
||||||
<input type="date" id="due-date" name="due-date" />
|
<input type="date" id="due-date" name="due-date" [(ngModel)]="enteredDate" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class="actions">
|
<p class="actions">
|
||||||
|
@ -1,15 +1,33 @@
|
|||||||
import {Component, EventEmitter, Output} from '@angular/core';
|
import {Component, EventEmitter, Output} from '@angular/core';
|
||||||
|
import {FormsModule} from '@angular/forms';
|
||||||
|
import {Task} from '../../task/task.model';
|
||||||
|
import {TaskContent} from './task-content.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-new-task',
|
selector: 'app-new-task',
|
||||||
imports: [],
|
imports: [
|
||||||
|
FormsModule
|
||||||
|
],
|
||||||
templateUrl: './new-task.component.html',
|
templateUrl: './new-task.component.html',
|
||||||
styleUrl: './new-task.component.css'
|
styleUrl: './new-task.component.css'
|
||||||
})
|
})
|
||||||
export class NewTaskComponent {
|
export class NewTaskComponent {
|
||||||
@Output() cancel = new EventEmitter<void>();
|
@Output() cancel = new EventEmitter<void>();
|
||||||
|
@Output() add = new EventEmitter<TaskContent>();
|
||||||
|
enteredTitle = '';
|
||||||
|
enteredSummary = '';
|
||||||
|
enteredDate = '';
|
||||||
|
|
||||||
onCancel() {
|
onCancel() {
|
||||||
this.cancel.emit();
|
this.cancel.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSubmit() {
|
||||||
|
let taskContent: TaskContent = {
|
||||||
|
title: this.enteredTitle,
|
||||||
|
summary: this.enteredSummary,
|
||||||
|
date: this.enteredDate,
|
||||||
|
};
|
||||||
|
this.add.emit(taskContent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
5
src/app/tasks/new-task/task-content.model.ts
Normal file
5
src/app/tasks/new-task/task-content.model.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export interface TaskContent {
|
||||||
|
title: string;
|
||||||
|
summary: string;
|
||||||
|
date: string;
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
@if (isAddingTask) {
|
@if (isAddingTask) {
|
||||||
<app-new-task (cancel)="onCancelAddTask()" />
|
<app-new-task
|
||||||
|
(cancel)="onCancelAddTask()"
|
||||||
|
(add)="onAddTask($event)"
|
||||||
|
/>
|
||||||
}
|
}
|
||||||
|
|
||||||
<section id="tasks">
|
<section id="tasks">
|
||||||
|
@ -3,6 +3,7 @@ import {User} from '../user/user.model';
|
|||||||
import {Task} from '../task/task.model';
|
import {Task} from '../task/task.model';
|
||||||
import {TaskComponent} from '../task/task.component';
|
import {TaskComponent} from '../task/task.component';
|
||||||
import {NewTaskComponent} from './new-task/new-task.component';
|
import {NewTaskComponent} from './new-task/new-task.component';
|
||||||
|
import {TaskContent} from './new-task/task-content.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-tasks',
|
selector: 'app-tasks',
|
||||||
@ -54,4 +55,20 @@ export class TasksComponent {
|
|||||||
onCancelAddTask() {
|
onCancelAddTask() {
|
||||||
this.isAddingTask = false;
|
this.isAddingTask = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onAddTask(taskContent: TaskContent) {
|
||||||
|
let nextTaskId = this.tasks.length + 1;
|
||||||
|
let taskId = 't' + (nextTaskId).toString();
|
||||||
|
|
||||||
|
let task: Task = {
|
||||||
|
id: taskId,
|
||||||
|
userId: this.user.id,
|
||||||
|
title: taskContent.title,
|
||||||
|
summary: taskContent.summary,
|
||||||
|
dueDate: taskContent.date,
|
||||||
|
};
|
||||||
|
this.tasks.push(task);
|
||||||
|
|
||||||
|
this.onCancelAddTask()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user