diff --git a/src/app/app.component.html b/src/app/app.component.html index f348a5a..662aecb 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,30 +1,6 @@
- -
-
-
-
- - - - -
-
-
- Valido {{profileForm.valid}} - -
- Touched {{profileForm.touched}} -
-
diff --git a/src/app/model/todo-item.ts b/src/app/model/todo-item.ts index bdb4f8b..7908b4f 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/stats/stats.component.html b/src/app/stats/stats.component.html index b599e29..6caedd9 100644 --- a/src/app/stats/stats.component.html +++ b/src/app/stats/stats.component.html @@ -1,6 +1,8 @@ -
-{{completedPercentage()}} % -
+
+
+ {{completedPercentage()}}% +
+
\ No newline at end of file diff --git a/src/app/stats/stats.component.scss b/src/app/stats/stats.component.scss index 3543841..ac66d87 100644 --- a/src/app/stats/stats.component.scss +++ b/src/app/stats/stats.component.scss @@ -1,6 +1,20 @@ .progressbar { - background-color: green; + background-color: rgb(1, 228, 1); + transition: width 0.4s; + height: inherit; + border-radius: inherit; + +} + +.progressbar-background{ height: 50px; font-size: x-large; - transition: width 0.3s; + border-radius: 30px; + background-color: lightgrey; +} + +.progressbar-percentage{ + position: relative; + left: 500px; + font-weight: bold; } diff --git a/src/app/todo-app/todo-app.component.html b/src/app/todo-app/todo-app.component.html index 786cc57..b170b97 100644 --- a/src/app/todo-app/todo-app.component.html +++ b/src/app/todo-app/todo-app.component.html @@ -1,12 +1,20 @@ - + + + (itemUpdated)="onItemUpdating($event)" + > + + > + \ No newline at end of file diff --git a/src/app/todo-app/todo-app.component.ts b/src/app/todo-app/todo-app.component.ts index cc42271..5adc493 100644 --- a/src/app/todo-app/todo-app.component.ts +++ b/src/app/todo-app/todo-app.component.ts @@ -10,6 +10,8 @@ import { TodoService } from '../todo.service'; }) export class TodoAppComponent { + taskToEdit:TodoItem = null; + constructor( private service: TodoService ) {} @@ -17,13 +19,26 @@ export class TodoAppComponent { getList() { return this.service.list; } + onTodoItemRemoved(id) { this.service.remove(id); } - onItemStateChanged(item: TodoItem) { - item.toggleCompleted(); + + onItemStateChanged(task:TodoItem) { + task.toggleCompleted(); } - onTodoItemCreated(task) { - this.service.add(task) + + onItemCreated(task:TodoItem) { + this.service.add(task); } + + onItemUpdating(task:TodoItem) { + this.taskToEdit = Object.assign({},task); + } + + onItemUpdated(task:TodoItem){ + this.service.update(task); + this.taskToEdit = null; + } + } diff --git a/src/app/todo-footer/todo-footer.component.html b/src/app/todo-footer/todo-footer.component.html index a0f7423..06be46a 100644 --- a/src/app/todo-footer/todo-footer.component.html +++ b/src/app/todo-footer/todo-footer.component.html @@ -1,2 +1,3 @@ -

Tasks Completed {{completedSize()}}

-

Tasks To do {{incompletedSize()}}

+ \ No newline at end of file diff --git a/src/app/todo-footer/todo-footer.component.scss b/src/app/todo-footer/todo-footer.component.scss index e69de29..9bb4e6b 100644 --- a/src/app/todo-footer/todo-footer.component.scss +++ b/src/app/todo-footer/todo-footer.component.scss @@ -0,0 +1,14 @@ +.footer{ + margin-bottom: 10px; + padding: 50px; + background-color: rgb(32, 44, 44); + border-radius: 5px; + text-align: center; +} + +.footer-description{ + font-weight: bold; + color: lightgray; + font-family: Arial, Helvetica, sans-serif; + font-size: xx-large; +} \ No newline at end of file diff --git a/src/app/todo-form/todo-form.component.html b/src/app/todo-form/todo-form.component.html index ec0ad47..be801f8 100644 --- a/src/app/todo-form/todo-form.component.html +++ b/src/app/todo-form/todo-form.component.html @@ -1,10 +1,16 @@ +
+ + + + +
- - diff --git a/src/app/todo-form/todo-form.component.scss b/src/app/todo-form/todo-form.component.scss index 213bb36..9891be5 100644 --- a/src/app/todo-form/todo-form.component.scss +++ b/src/app/todo-form/todo-form.component.scss @@ -1,3 +1,4 @@ .add-todo { - width: 80% + width: 45%; + margin-right: 5px; } diff --git a/src/app/todo-form/todo-form.component.ts b/src/app/todo-form/todo-form.component.ts index 3366020..e07e3f8 100644 --- a/src/app/todo-form/todo-form.component.ts +++ b/src/app/todo-form/todo-form.component.ts @@ -1,24 +1,69 @@ -import { Component, OnInit, Output, EventEmitter} from '@angular/core'; +import { Component, Output, EventEmitter, Input, OnChanges} from '@angular/core'; import { TodoItem } from '../model/todo-item'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { Subscription } from 'rxjs'; @Component({ selector: 'app-todo-form', templateUrl: './todo-form.component.html', styleUrls: ['./todo-form.component.scss'] }) -export class TodoFormComponent { +export class TodoFormComponent implements OnChanges { + + taskControl = new FormGroup({ + description: new FormControl('',Validators.required), //mismo nombre que atributos de TodoItem + url: new FormControl('',[ + Validators.required, + Validators.pattern('(https?://)?([\\da-z.-]+)\\.([a-z.]{2,6})[/\\w .-]*/?') + ]) + }); + + saveButtonText='Create'; + descriptionChangesSubscription:Subscription = null; @Output() add = new EventEmitter(); + @Output() update = new EventEmitter(); + @Input() taskToEdit; + + ngOnChanges(){ + if(!this.taskToEdit){ + this.saveButtonText = 'Create'; + } + else{ + this.saveButtonText = 'Update'; + this.descriptionChangesSubscription = this.taskControl.valueChanges.subscribe( + value => this.taskToEdit = Object.assign(this.taskToEdit, value) + ); + + this.taskControl.patchValue({description: this.taskToEdit.description, url: this.taskToEdit.url}) + } + } - save(description){ - if(!description.value || description.value === '') { + save(){ + if(!this.taskControl.value || this.taskControl.untouched) { return; } + + if(!this.taskToEdit){ + this.addTask(); + } + else{ + this.updateTask(); + } + } + + addTask(){ let task = new TodoItem(); - task.description = description.value; + task = Object.assign(task,this.taskControl.value); task.isCompleted = false; this.add.emit(task); - description.value = ''; + this.taskControl.reset(); + } + + updateTask(){ + this.descriptionChangesSubscription.unsubscribe(); + this.taskControl.reset(); + this.update.emit(this.taskToEdit); } } diff --git a/src/app/todo-list/todo-list.component.html b/src/app/todo-list/todo-list.component.html index 127ec76..04957ff 100644 --- a/src/app/todo-list/todo-list.component.html +++ b/src/app/todo-list/todo-list.component.html @@ -2,10 +2,11 @@
  • - {{task.description}} + {{task.description}} - {{task.url}} +
  • - + diff --git a/src/app/todo-list/todo-list.component.scss b/src/app/todo-list/todo-list.component.scss index 0096849..0657edd 100644 --- a/src/app/todo-list/todo-list.component.scss +++ b/src/app/todo-list/todo-list.component.scss @@ -3,13 +3,16 @@ } .list { padding: 0; + margin-top: 20px; } .list-item { margin: 0; list-style-type: none; - font-size: 2rem; + font-size: 1.5rem; border-bottom: 1px solid lightgrey; - width: 80%; + //width: 80%; display: flex; justify-content: space-between; + padding: 0px 30px 0px 30px; + border-radius: 5px; } diff --git a/src/app/todo-list/todo-list.component.ts b/src/app/todo-list/todo-list.component.ts index fc5d8f0..c2edbb6 100644 --- a/src/app/todo-list/todo-list.component.ts +++ b/src/app/todo-list/todo-list.component.ts @@ -10,17 +10,21 @@ export class TodoListComponent implements OnInit { @Input() list: any[]; @Output() itemRemoved = new EventEmitter(); @Output() itemStateChanged = new EventEmitter(); + @Output() itemUpdated = new EventEmitter(); constructor() { } ngOnInit() { } - removeItem(id) { + removeItem(id){ this.itemRemoved.emit(id); } - completeTask(item:TodoItem) { + completeTask(item:TodoItem){ this.itemStateChanged.emit(item); + } + updateTask(item:TodoItem){ + this.itemUpdated.emit(item); } } \ No newline at end of file diff --git a/src/app/todo.service.ts b/src/app/todo.service.ts index 9bba8cc..28eb1bb 100644 --- a/src/app/todo.service.ts +++ b/src/app/todo.service.ts @@ -1,21 +1,22 @@ import { Injectable } from '@angular/core'; import { LocalStorageService } from './local-storage.service'; +import { TodoItem } from './model/todo-item'; @Injectable({ providedIn: 'root' }) export class TodoService { - list = []; + list:TodoItem[] = []; lastItemId = 0; constructor(private storage: LocalStorageService) { } - add(task) { + add(task:TodoItem) { const id = this.lastItemId; task.id = id; this.list.push(task); - this.lastItemId += 10; + this.lastItemId += 1; } remove(id) { @@ -23,6 +24,13 @@ export class TodoService { this.list.splice(index, 1); } + update(task:TodoItem) { + const index = this.list.findIndex(element => element.id === task.id); + const t = this.list[index]; + t.description = task.description; + t.url = task.url; + } + incompletedSize() { return this.list.filter(item => !item.isCompleted).length;