-
Notifications
You must be signed in to change notification settings - Fork 37
Services #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
giulitruant
wants to merge
5
commits into
utnfrrottads:services
Choose a base branch
from
giulitruant:services
base: services
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Services #33
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,57 @@ | ||
| import { Injectable } from '@angular/core'; | ||
| import { TodoItem } from './model/todo-item'; | ||
|
|
||
| @Injectable({ | ||
| providedIn: 'root' | ||
| }) | ||
| export class LocalStorageService { | ||
| // https://developer.mozilla.org/es/docs/Web/API/Window/localStorage | ||
|
|
||
| myStorage = localStorage; | ||
| constructor() { } | ||
| getName() { | ||
| return 'LocalStorageService' | ||
| return 'LocalStorageService'; | ||
| } | ||
| cargarLocalStorage(){ | ||
| const list = []; | ||
| Object.values(this.myStorage).forEach(p => { | ||
| list.push(JSON.parse(p)); | ||
|
|
||
| }); | ||
| return list; | ||
|
|
||
| } | ||
|
|
||
| grabarLocalStorage(item: TodoItem){ | ||
| item.id = this.myStorage.length; | ||
| localStorage.setItem(item.id.toString(), JSON.stringify(item)); | ||
|
|
||
| } | ||
|
|
||
| updateLocalStorage(item: TodoItem){ | ||
| this.myStorage.removeItem(item.id.toString()); | ||
| this.myStorage.setItem(item.id.toString(), JSON.stringify(item)); | ||
|
|
||
| } | ||
|
|
||
| deleteItem(key){ | ||
| const value = this.myStorage.getItem(key); | ||
| console.dir(value); | ||
| if(value !== undefined && value){ | ||
| this.myStorage.removeItem(key); | ||
| } | ||
| } | ||
|
|
||
| Save(list: any[]){ | ||
| this.Clean(); | ||
| list.forEach(x => { | ||
| this.myStorage.setItem(x.id.toString(), JSON.stringify(x)); | ||
|
|
||
| }); | ||
| } | ||
|
|
||
| Clean(){ | ||
| this.myStorage.clear(); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| <app-todo-form (add)="onTodoItemCreated($event)"></app-todo-form> | ||
| <app-todo-list | ||
| [list]="getList()" | ||
| (itemRemoved)="onTodoItemRemoved($event)" | ||
| (itemStateChanged)="onItemStateChanged($event)" | ||
| > | ||
| <app-todo-list [list]="getList()" (itemRemoved)="onTodoItemRemoved($event)" | ||
| (itemStateChanged)="onItemStateChanged($event)"> | ||
| </app-todo-list> | ||
| <app-todo-footer | ||
| [list]="getList()" | ||
| > | ||
| <div class="buttons"> | ||
| <button class="btn btn-primary" type="button" (click)="save()" >Guardar</button> | ||
| <button class="btn btn-danger" type="button" (click)="clear()" >Limpiar</button> | ||
| </div> | ||
| <app-todo-footer [list]="getList()"> | ||
| </app-todo-footer> | ||
| <app-stats></app-stats> | ||
| <app-stats [list]="getList()"> | ||
| </app-stats> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .buttons { | ||
| justify-content: space-between; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,56 @@ | ||
| import { Component, OnInit } from '@angular/core'; | ||
| import {TodoItem} from '../model/todo-item'; | ||
| import { element } from 'protractor'; | ||
| import { TodoItem } from '../model/todo-item'; | ||
| import { TodoService } from '../todo.service'; | ||
| /** */ | ||
| @Component({ | ||
| selector: 'app-todo', | ||
| templateUrl: './todo-app.component.html', | ||
| styleUrls: ['./todo-app.component.scss'], | ||
| }) | ||
| export class TodoAppComponent { | ||
| export class TodoAppComponent implements OnInit { | ||
|
|
||
| cant: number = 0; | ||
| list: any[]; | ||
| constructor( | ||
| private service: TodoService | ||
| ) {} | ||
| ) { } | ||
|
|
||
| ngOnInit() { | ||
| this.service.getList(); | ||
|
|
||
| } | ||
|
|
||
| getList() { | ||
| this.list = this.service.list; | ||
| return this.list; | ||
|
|
||
| getList() { | ||
| return this.service.list; | ||
| } | ||
|
|
||
| onTodoItemRemoved(id) { | ||
| this.service.remove(id); | ||
| var items = this.list.find(x => x.id === id); | ||
| this.list.splice(items.id); | ||
|
|
||
| } | ||
| onItemStateChanged(item: TodoItem) { | ||
| item.toggleCompleted(); | ||
| onItemStateChanged(item: TodoItem) { | ||
| if (item.isCompleted) { | ||
| item.isCompleted = false; | ||
| } else { | ||
| item.isCompleted = true; | ||
| } | ||
|
|
||
| } | ||
| onTodoItemCreated(task: TodoItem) { | ||
| let lastId = this.list.length; | ||
| task.id = lastId; | ||
| this.list.push(task); | ||
| } | ||
|
|
||
| save() { | ||
| this.service.save(this.list); | ||
|
|
||
| } | ||
| onTodoItemCreated(task) { | ||
| this.service.add(task) | ||
|
|
||
| clear() { | ||
| this.service.clear(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,33 @@ | ||
| import { Component, OnInit, Input } from '@angular/core'; | ||
| import { TodoItem } from '../model/todo-item'; | ||
| import { TodoService } from '../todo.service'; | ||
| // import { TodoItem } from '../model/todo-item'; | ||
| // import { TodoService } from '../todo.service'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-todo-footer', | ||
| templateUrl: './todo-footer.component.html', | ||
| styleUrls: ['./todo-footer.component.scss'] | ||
| }) | ||
| export class TodoFooterComponent implements OnInit { | ||
| countTodo = 0; | ||
| countCompleted = 0; | ||
| @Input() list; | ||
| constructor( | ||
| private service: TodoService | ||
| ) { } | ||
| export class TodoFooterComponent implements OnInit { | ||
| @Input() list: any = []; | ||
| constructor( ) { } | ||
|
|
||
| ngOnInit() { | ||
|
|
||
| } | ||
| incompletedSize() { | ||
| this.countTodo = this.service.incompletedSize() | ||
| return this.countTodo; | ||
| if(this.list && this.list !== undefined){ | ||
| return this.list.filter(item => !item.isCompleted).length; | ||
| } else { | ||
| return 0; | ||
| } | ||
|
|
||
| } | ||
| completedSize() { | ||
| this.countCompleted =this.service.completedSize() | ||
| return this.countCompleted; | ||
| completedSize() { | ||
| if(this.list && this.list !== undefined){ | ||
| return this.list.filter(item => item.isCompleted).length;; | ||
| }else { | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,57 @@ | ||
| import { Injectable } from '@angular/core'; | ||
| import { LocalStorageService } from './local-storage.service'; | ||
| import { TodoItem } from './model/todo-item'; | ||
|
|
||
|
|
||
| @Injectable({ | ||
| providedIn: 'root' | ||
| }) | ||
| export class TodoService { | ||
|
|
||
| list = []; | ||
| lastItemId = 0; | ||
|
|
||
| list: any = []; | ||
|
|
||
| constructor(private storage: LocalStorageService) { } | ||
|
|
||
| add(task) { | ||
| const id = this.lastItemId; | ||
| task.id = id; | ||
| this.list.push(task); | ||
| this.lastItemId += 10; | ||
|
|
||
| getList(){ | ||
| this.list = this.storage.cargarLocalStorage(); | ||
|
|
||
| } | ||
|
|
||
| add(task: TodoItem) { | ||
| this.storage.grabarLocalStorage(task); | ||
|
|
||
| } | ||
|
|
||
| remove(id) { | ||
| const index = this.list.findIndex((element) => element.id === id); | ||
| this.list.splice(index, 1); | ||
| this.storage.deleteItem(id); | ||
| } | ||
|
|
||
| incompletedSize() { | ||
| return this.list.filter(item => !item.isCompleted).length; | ||
| save(lstItems: any[]){ | ||
| this.storage.Save(lstItems); | ||
| } | ||
|
|
||
| clear(){ | ||
| this.storage.Clean(); | ||
| this.list = []; | ||
| } | ||
| completedSize() { | ||
| return this.list.filter(item => item.isCompleted).length ; | ||
|
|
||
| // incompletedSize() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eliminar codigo comentado |
||
| // return this.list.filter(item => !item.isCompleted).length; | ||
| // // this.items = this.storage.cargarLocalStorage(); | ||
| // // return this.items.filter(item => !item.isCompleted).length; | ||
|
|
||
| // } | ||
|
|
||
| // completedSize() { | ||
| // return this.list.filter(item => item.isCompleted).length; | ||
| // // this.items = this.storage.cargarLocalStorage(); | ||
| // // return this.items.filter(item => item.isCompleted).length; | ||
|
|
||
| // } | ||
|
|
||
| update(item: TodoItem){ | ||
| this.storage.updateLocalStorage(item); | ||
|
|
||
| } | ||
|
|
||
| getName() { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
en ts/js los metodos van con minusculas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leete la guia de airbnb que pub licamos en la catedra