diff --git a/src/app/app.component.html b/src/app/app.component.html index f348a5a..c34ed49 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -4,27 +4,3 @@
- -
-
-
-
- - - - -
-
-
- Valido {{profileForm.valid}} - -
- Touched {{profileForm.touched}} -
-
diff --git a/src/app/model/todo-item.ts b/src/app/model/todo-item.ts index bdb4f8b..e0a551c 100644 --- a/src/app/model/todo-item.ts +++ b/src/app/model/todo-item.ts @@ -2,6 +2,7 @@ export class TodoItem { id: number; description: string; isCompleted: boolean = false; + url:string; toggleCompleted() { this.isCompleted = !this.isCompleted; diff --git a/src/app/todo-app/todo-app.component.html b/src/app/todo-app/todo-app.component.html index 786cc57..4a7e408 100644 --- a/src/app/todo-app/todo-app.component.html +++ b/src/app/todo-app/todo-app.component.html @@ -1,8 +1,9 @@ - + - - +
+ + +
+ * No ha ingresado descripcion +
+ +
+ * No ha ingresado una URL vĂ¡lida +
+ +
+ +{{taskGroup.controls.description.value}} +
+{{taskGroup.controls.url.value}} diff --git a/src/app/todo-form/todo-form.component.ts b/src/app/todo-form/todo-form.component.ts index 3366020..3d62526 100644 --- a/src/app/todo-form/todo-form.component.ts +++ b/src/app/todo-form/todo-form.component.ts @@ -1,5 +1,8 @@ -import { Component, OnInit, Output, EventEmitter} from '@angular/core'; +import { Component, OnInit, Output, EventEmitter, Input} from '@angular/core'; import { TodoItem } from '../model/todo-item'; +import { FormGroup, FormControl, Validators } from '@angular/forms'; +import { TodoService } from '../todo.service'; +const urlRegex = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/; @Component({ selector: 'app-todo-form', @@ -7,18 +10,62 @@ import { TodoItem } from '../model/todo-item'; styleUrls: ['./todo-form.component.scss'] }) export class TodoFormComponent { - + @Input() selectedTask:TodoItem; @Output() add = new EventEmitter(); + taskGroup: FormGroup; + + constructor(private service:TodoService) { + this.taskGroup = new FormGroup({ + description: new FormControl('',[Validators.required]), + url: new FormControl('',[Validators.required,Validators.pattern(urlRegex)]), + id: new FormControl('') + }) - save(description){ - if(!description.value || description.value === '') { + } + ngOnChanges(){ + if (!this.selectedTask) { + this.taskGroup.patchValue({ + description: '', + url: '', + id: '' + }) + } + else{ + this.taskGroup.patchValue({ + description: this.selectedTask.description, + url: this.selectedTask.url, + id: this.selectedTask.id + }) + + } + } + save(){ + if(!this.taskGroup.controls.description.value || this.taskGroup.controls.description.value === '') { return; } - let task = new TodoItem(); - task.description = description.value; - task.isCompleted = false; - this.add.emit(task); - description.value = ''; + if (this.taskGroup.controls.id.value) { + let task = new TodoItem(); + task.description = this.taskGroup.controls.description.value; + task.isCompleted = false; + task.url = this.taskGroup.controls.url.value; + task.id = this.taskGroup.controls.id.value; + this.service.remove(task.id); + this.add.emit(task); + this.taskGroup.reset(); + console.log(this.taskGroup.controls.id.value) + } + else{ + let task = new TodoItem(); + task.description = this.taskGroup.controls.description.value; + task.isCompleted = false; + task.url = this.taskGroup.controls.url.value; + this.add.emit(task); + this.taskGroup.reset(); + console.log(this.selectedTask) + } + } + + } diff --git a/src/app/todo-list/todo-list.component.html b/src/app/todo-list/todo-list.component.html index 127ec76..788486f 100644 --- a/src/app/todo-list/todo-list.component.html +++ b/src/app/todo-list/todo-list.component.html @@ -2,10 +2,12 @@
  • - {{task.description}} +

    {{task.description}}

    + {{task.url}} +
  • diff --git a/src/app/todo-list/todo-list.component.ts b/src/app/todo-list/todo-list.component.ts index fc5d8f0..1281034 100644 --- a/src/app/todo-list/todo-list.component.ts +++ b/src/app/todo-list/todo-list.component.ts @@ -10,6 +10,7 @@ export class TodoListComponent implements OnInit { @Input() list: any[]; @Output() itemRemoved = new EventEmitter(); @Output() itemStateChanged = new EventEmitter(); + @Output() taskSelected = new EventEmitter(); constructor() { } ngOnInit() { @@ -23,4 +24,8 @@ export class TodoListComponent implements OnInit { } + editTask(task){ + this.taskSelected.emit(task); + } + } \ No newline at end of file diff --git a/src/app/todo.service.ts b/src/app/todo.service.ts index 9bba8cc..8c846c1 100644 --- a/src/app/todo.service.ts +++ b/src/app/todo.service.ts @@ -1,5 +1,6 @@ import { Injectable } from '@angular/core'; import { LocalStorageService } from './local-storage.service'; +import { TodoItem } from './model/todo-item'; @Injectable({ providedIn: 'root' @@ -7,9 +8,10 @@ import { LocalStorageService } from './local-storage.service'; export class TodoService { list = []; - lastItemId = 0; + lastItemId = 1; - constructor(private storage: LocalStorageService) { } + constructor(private storage: LocalStorageService) {; + } add(task) { const id = this.lastItemId; diff --git a/src/index.html b/src/index.html index 62a7817..b09794c 100644 --- a/src/index.html +++ b/src/index.html @@ -6,6 +6,9 @@ + + +