Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
<app-todo></app-todo>

<app-todo></app-todo>

<app-todo></app-todo>
<app-todo></app-todo>
1 change: 1 addition & 0 deletions src/app/app.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 5 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { TodoAppComponent } from './todo-app/todo-app.component';
import { TodoFormComponent } from './todo-form/todo-form.component';
import { TodoListComponent } from './todo-list/todo-list.component';
import { TodoFooterComponent } from './todo-footer/todo-footer.component';

@NgModule({
declarations: [
AppComponent,
TodoAppComponent,
TodoFormComponent
TodoFormComponent,
TodoListComponent,
TodoFooterComponent
],
imports: [
BrowserModule,
Expand Down
21 changes: 20 additions & 1 deletion src/app/model/todo-item.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
export class TodoItem {
id: number;
static idCounter: number = 0;

id: number = 0;
description: string;
isCompleted: boolean = false;

constructor(description){
this.id = TodoItem.getIdCount();
this.description = description;

TodoItem.increaseIdCount()
}

static increaseIdCount() {
this.idCounter += 1;
}

static getIdCount() {
return this.idCounter;
}

toggleCompleted() {
this.isCompleted = !this.isCompleted;
}

}

31 changes: 23 additions & 8 deletions src/app/todo-app/todo-app.component.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
<app-todo-form (add)="onTodoItemCreated($event)"></app-todo-form>
<app-todo-list
[list]="list"
(itemRemoved)="onTodoItemRemoved($event)"
(itemStateChanged)="onItemStateChanged($event)"
>
</app-todo-list>
<app-todo-footer [list]="list"></app-todo-footer>
<div class="content">
<div class="padding">
<div class="row container d-flex justify-content-center">
<div class="col-lg-12">
<div class="card px-3">
<div class="card-body">
<h4 class="card-title">¡Mi lista de tareas!</h4>
<app-todo-form (add)="onTodoItemCreated($event)"></app-todo-form>
<br>
<app-todo-list
[list]="list"
(itemRemoved)="onTodoItemRemoved($event)"
(itemStateChanged)="onItemStateChanged($event)"
>
</app-todo-list>
</div>
<app-todo-footer [list]="list"></app-todo-footer>
</div>
</div>
</div>
</div>
</div>

6 changes: 6 additions & 0 deletions src/app/todo-app/todo-app.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.content{
margin-top: 10px;
margin-left: auto;
margin-right: auto;
width: 60%;
}
25 changes: 17 additions & 8 deletions src/app/todo-app/todo-app.component.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';
import {TodoItem} from '../model/todo-item';

@Component({
selector: 'app-todo',
templateUrl: './todo-app.component.html',
styleUrls: ['./todo-app.component.scss']
})
export class TodoAppComponent implements OnInit {
list = [];
lastItemId = 0;
constructor() { }

ngOnInit(): void {
}
export class TodoAppComponent {
list : TodoItem[] = [];
// lastItemId = 0;

onItemStateChanged(item: TodoItem) {
item.toggleCompleted();
}

onTodoItemCreated(newItem : TodoItem){
this.list.push(newItem);
}

onTodoItemRemoved(item : TodoItem){
const index = this.list.findIndex(each => each.id === item.id);
this.list.splice(index,1);
}

// onItemEdited(item : TodoItem){

// }
}
4 changes: 4 additions & 0 deletions src/app/todo-footer/todo-footer.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class ="breadcrumb">
Tareas completadas:&nbsp; <b> {{ Completeditems() }} </b> &nbsp;
Tareas pendientes: &nbsp; <b> {{ UnCompleteditems() }} </b>
</div>
Empty file.
25 changes: 25 additions & 0 deletions src/app/todo-footer/todo-footer.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { TodoFooterComponent } from './todo-footer.component';

describe('TodoFooterComponent', () => {
let component: TodoFooterComponent;
let fixture: ComponentFixture<TodoFooterComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TodoFooterComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(TodoFooterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
24 changes: 24 additions & 0 deletions src/app/todo-footer/todo-footer.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Component, Input } from '@angular/core';

import { TodoItem } from '../model/todo-item';

@Component({
selector: 'app-todo-footer',
templateUrl: './todo-footer.component.html',
styleUrls: ['./todo-footer.component.scss']
})
export class TodoFooterComponent {

@Input() list : TodoItem[] = [];

Completeditems(){
return this.list.filter(each => each.isCompleted === true).length;
}

UnCompleteditems(){
// return this.list.filter(each => each.isCompleted === true).length;
// Other form:
return this.list.length - this.Completeditems()
}

}
6 changes: 5 additions & 1 deletion src/app/todo-form/todo-form.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<p>todo-form works!</p>
<div class="add-items d-flex">
<input type="text" class="form-control todo-list-input" placeholder="ingresa una nueva tarea" #item>
<button class="add btn btn-primary font-weight-bold todo-list-add-btn" (click)="addItem(item)">+</button>
</div>

7 changes: 7 additions & 0 deletions src/app/todo-form/todo-form.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
body {
background-color: #f9f9fa
}

ul{
list-style-type: none;
}
18 changes: 12 additions & 6 deletions src/app/todo-form/todo-form.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { Component, OnInit, Output, EventEmitter} from '@angular/core';
import { Component, Output, EventEmitter} from '@angular/core';

import { TodoItem } from 'src/app/model/todo-item';

@Component({
selector: 'app-todo-form',
templateUrl: './todo-form.component.html',
styleUrls: ['./todo-form.component.scss']
})
export class TodoFormComponent implements OnInit {
export class TodoFormComponent {

@Output() add = new EventEmitter();
constructor() { }
@Output() add = new EventEmitter<TodoItem>();

ngOnInit(): void {
}
addItem(item){
if (item.value === '') return;

const newItem = new TodoItem(item.value);
item.value = '';
item.focus();
this.add.emit(newItem);
}
}
49 changes: 49 additions & 0 deletions src/app/todo-list/todo-list.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<div class="list-wrapper">
<ul class="d-flex flex-column-reverse todo-list">
<li *ngFor="let item of list">
<div [ngClass]="{completed: item.isCompleted === true, uncompleted: item.isCompleted === false}">
<button type="button" class="remove btn btn-danger" (click)="itemRemovedClick(item)">X</button>
<!-- <button type="button" class="edit btn btn-info" (click)="itemEditClick(item)">Edit</button> -->
<button type="button" class="done btn btn-success" (click)="itemStateChangedClick(item)">Done</button>
{{ item.description }} <span class="atenuar">(ID {{ item.id }}: {{ getEstado(item) }})</span>
</div>
</li>
</ul>
</div>












<!--
<div class="card uncompleted" style="width: 18rem;" *ngFor="let item of list">
<div class="card-body">
<h6 class="card-subtitle mb-2 text-muted">ID {{ item.id }} </h6>
<h5 class="card-title"> {{ item.description }} </h5>
<a href="#" class="card-link" (click)="itemStateChangedClick(item)">Completed</a>
<a href="#" class="card-link" (click)="itemRemovedClick(item)">Remove</a>
</div>
</div> -->





<!-- <ul class="list-group list-group-flush" *ngFor="let item of list">
<li class="list-group-item">
<h6 class="card-subtitle mb-2 text-muted ">ID {{ item.id }} </h6>
<h5 class="card-title">{{ item.description }}</h5>
<a href="#" class="card-link card-body" (click)="itemStateChangedClick(item)">Completed</a>
<a href="#" class="card-link card-body" (click)="itemRemovedClick(item)">Remove</a>
</li>
</ul> -->


<!-- <input type="checkbox"> -->
44 changes: 44 additions & 0 deletions src/app/todo-list/todo-list.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.completed {
background-color: #cbff7b;
text-decoration: line-through;
}

.uncompleted {
background-color: lemonchiffon;
}

li {
border-radius: 2em;
margin-bottom: 0.5em;
}

ul{
list-style-type: none;
}

.btn {
margin-right: 10px;
font-weight: bold;
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-size: small;
border-radius: 6em;
}

.done{
background-color: #77dd77;
border-color: #77dd77;
}

.remove{
background-color: #c23b22;
border-color: #c23b22;
}

.edit{
background-color: #a2cadf;
border-color: #a2cadf;
}

.atenuar{
color: gray;
}
25 changes: 25 additions & 0 deletions src/app/todo-list/todo-list.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { TodoListComponent } from './todo-list.component';

describe('TodoListComponent', () => {
let component: TodoListComponent;
let fixture: ComponentFixture<TodoListComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TodoListComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(TodoListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
40 changes: 40 additions & 0 deletions src/app/todo-list/todo-list.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Component, Input, Output, EventEmitter } from '@angular/core';

import { TodoItem } from '../model/todo-item';

@Component({
selector: 'app-todo-list',
templateUrl: './todo-list.component.html',
styleUrls: ['./todo-list.component.scss']
})


export class TodoListComponent {

@Input() list = [];
@Output() itemRemoved = new EventEmitter<TodoItem>();
@Output() itemStateChanged = new EventEmitter<TodoItem>();
@Output() itemEdited = new EventEmitter<TodoItem>();

constructor() { }

itemRemovedClick(item : TodoItem){
this.itemRemoved.emit(item);
}

itemStateChangedClick(item : TodoItem){
this.itemStateChanged.emit(item);
}

// itemEditClick(item : TodoItem){
// this.itemEdited.emit(item);
// }

getEstado(item : TodoItem){
if (item.isCompleted)
return 'Completada';
else
return 'Incompleta';

}
}
Binary file added src/img-of-app/toDoList.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading