diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 61dcb3f..92831f8 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -17,6 +17,7 @@ import { AppComponent } from './app.component'; import { TaskFormComponent } from './task-form/task-form.component'; import { TodosListComponent } from './todos-list/todos-list.component'; import { TodoItemComponent } from './todo-item/todo-item.component'; +import { TodoEditComponent } from './todo-edit/todo-edit.component'; @NgModule({ @@ -24,7 +25,8 @@ import { TodoItemComponent } from './todo-item/todo-item.component'; AppComponent, TaskFormComponent, TodosListComponent, - TodoItemComponent + TodoItemComponent, + TodoEditComponent ], imports: [ BrowserModule, diff --git a/src/app/todo-edit/todo-edit.component.css b/src/app/todo-edit/todo-edit.component.css new file mode 100644 index 0000000..b736363 --- /dev/null +++ b/src/app/todo-edit/todo-edit.component.css @@ -0,0 +1,16 @@ +.textDeprecated { + color: grey; + text-decoration: line-through; +} + +.high { + background-color: red; +} + +.medium { + background-color: yellow; +} + +.low { + background-color: green; +} diff --git a/src/app/todo-edit/todo-edit.component.html b/src/app/todo-edit/todo-edit.component.html new file mode 100644 index 0000000..c88953e --- /dev/null +++ b/src/app/todo-edit/todo-edit.component.html @@ -0,0 +1,15 @@ +
+ + Edit Todo + + {{getErrorMessage()}} + +
diff --git a/src/app/todo-edit/todo-edit.component.spec.ts b/src/app/todo-edit/todo-edit.component.spec.ts new file mode 100644 index 0000000..ba0204c --- /dev/null +++ b/src/app/todo-edit/todo-edit.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { TodoEditComponent } from './todo-edit.component'; + +describe('TodoEditComponent', () => { + let component: TodoEditComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [TodoEditComponent] + }); + fixture = TestBed.createComponent(TodoEditComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/todo-edit/todo-edit.component.ts b/src/app/todo-edit/todo-edit.component.ts new file mode 100644 index 0000000..c3f78ce --- /dev/null +++ b/src/app/todo-edit/todo-edit.component.ts @@ -0,0 +1,60 @@ +import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; +import {Todo} from "../todo"; +import {FormControl, FormGroup, Validators} from "@angular/forms"; + +@Component({ + selector: 'app-todo-edit', + templateUrl: './todo-edit.component.html', + styleUrls: ['./todo-edit.component.css'] +}) +export class TodoEditComponent implements OnInit { + @Output() updateTodoChildEvent = new EventEmitter(); + + @Input() todoItemChild!: Todo; + + @Input() isDisabledChild!: true | null; + @Input() tasksStatusChild: string = 'low'; + @Input() isCheckedChild: boolean = false; + + formControlChild = new FormControl('', [Validators.required, Validators.minLength(3)]) + + ngOnInit() { + this.formControlChild.setValue(this.todoItemChild.name); + } + + onChildInputChange(todo: Todo, val: string) { + this.updateTodoChildEvent.emit({id: todo.id, name: val}); + } + + setInputBackground() { + switch(this.tasksStatusChild) { + case 'high': + return 'high'; + case 'medium': + return 'medium'; + case 'low': + return 'low'; + default: + return ''; + } + } + + setInputDecorations() { + return this.isCheckedChild ? 'textDeprecated' : ''; + } + + setClasses() { + return { + [this.setInputDecorations()]: true, + [this.setInputBackground()]: true + }; + } + + getErrorMessage() { + if (this.formControlChild.hasError('required')) { + return 'You must enter a value'; + } + + return this.formControlChild.hasError('minlength') ? 'Too short, should be at least 3 symbols' : ''; + } +} diff --git a/src/app/todo-item/todo-item.component.css b/src/app/todo-item/todo-item.component.css index 0719309..11c6f05 100644 --- a/src/app/todo-item/todo-item.component.css +++ b/src/app/todo-item/todo-item.component.css @@ -1,16 +1,7 @@ -.textDepricated { - color: grey; - text-decoration: line-through; +.formContainer { + display: flex; } -.high { - background-color: red; -} - -.medium { - background-color: yellow; -} - -.low { - background-color: green; +.wrapper { + display: flex; } diff --git a/src/app/todo-item/todo-item.component.html b/src/app/todo-item/todo-item.component.html index 93bd1b7..a9a0f0b 100644 --- a/src/app/todo-item/todo-item.component.html +++ b/src/app/todo-item/todo-item.component.html @@ -1,20 +1,14 @@ - - -
+
+ Done - - Input - - {{getErrorMessage()}} - + + Priorities - - +
diff --git a/src/app/todo-item/todo-item.component.ts b/src/app/todo-item/todo-item.component.ts index 1ed1acf..1af1202 100644 --- a/src/app/todo-item/todo-item.component.ts +++ b/src/app/todo-item/todo-item.component.ts @@ -8,7 +8,7 @@ import {TodoService} from "../todo.service"; templateUrl: './todo-item.component.html', styleUrls: ['./todo-item.component.css'] }) -export class TodoItemComponent implements OnInit { +export class TodoItemComponent { @Input() todoItemsList: Todo[] = []; @Input() todoItem!: Todo; @Output() deleteTodoEvent = new EventEmitter(); @@ -18,14 +18,6 @@ export class TodoItemComponent implements OnInit { isDisabled: true | null = null; taskStatus: string = 'low'; - todoForm: FormGroup = new FormGroup({ - todoItemForm: new FormControl('', [Validators.required, Validators.minLength(3)]) - }); - - ngOnInit() { - this.todoForm.setValue({todoItemForm: this.todoItem.name}); - } - constructor(private todoService: TodoService) { } @@ -33,32 +25,8 @@ export class TodoItemComponent implements OnInit { this.deleteTodoEvent.emit(todo); } - updateTodo(todo: Todo, val: string) { - this.updateTodoEvent.emit({id: todo.id, name: val}); - } - - setInputBackground() { - switch(this.taskStatus) { - case 'high': - return 'high'; - case 'medium': - return 'medium'; - case 'low': - return 'low'; - default: - return ''; - } - } - - setInputDecorations() { - return this.isChecked ? 'textDepricated' : ''; - } - - setClasses() { - return { - [this.setInputDecorations()]: true, - [this.setInputBackground()]: true - }; + updateTodo(todo: Todo) { + this.updateTodoEvent.emit(todo); } onCheckboxChange() { @@ -69,12 +37,4 @@ export class TodoItemComponent implements OnInit { onSelectChange(event: Event) { this.taskStatus = (event.target as unknown as HTMLInputElement).value; } - - getErrorMessage() { - if (this.todoForm.hasError('required')) { - return 'You must enter a value'; - } - - return this.todoForm.hasError('minlength') ? 'Too short, should be at least 3 symbols' : ''; - } } diff --git a/src/app/todo.service.ts b/src/app/todo.service.ts index a19ba27..c94ef31 100644 --- a/src/app/todo.service.ts +++ b/src/app/todo.service.ts @@ -29,9 +29,7 @@ export class TodoService { } updateTodo(todoItem: Todo): void { - // debugger this.todos = this.todos.map((todo) => { - console.log(todo.id === todoItem.id, todo.id, todoItem.id) if (todo.id === todoItem.id) { return todoItem; } diff --git a/src/app/todos-list/todos-list.component.html b/src/app/todos-list/todos-list.component.html index 93926ac..f72683a 100644 --- a/src/app/todos-list/todos-list.component.html +++ b/src/app/todos-list/todos-list.component.html @@ -1,5 +1,5 @@ - +