-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64c46b6
commit a121e31
Showing
11 changed files
with
227 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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
9 changes: 9 additions & 0 deletions
9
workspace/04-pipesApp/src/app/ventas/interfaces/ventas.interface.ts
This file contains 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,9 @@ | ||
export enum Color { | ||
rojo, negro, azul, verde | ||
} | ||
|
||
export interface Heroe { | ||
nombre: string; | ||
vuela: boolean; | ||
color: Color; | ||
} |
71 changes: 70 additions & 1 deletion
71
workspace/04-pipesApp/src/app/ventas/pages/ordenar/ordenar.component.html
This file contains 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 +1,70 @@ | ||
<p>ordenar works!</p> | ||
<div class="text-layout"> | ||
|
||
<h1>Pipes personalizados</h1> | ||
<p>Pipes creados por {{ 'nosotros' | mayusculas:enMayusculas }}</p> | ||
|
||
</div> | ||
|
||
<p-toolbar> | ||
<div class="p-toolbar-group-left"> | ||
|
||
</div> | ||
|
||
<div class="p-toolbar-group-right"> | ||
<p-button label="En myúsculas" icon="pi pi-check" styleClass="p-button-md" (onClick)="cambiarTamanio()" | ||
class="mr-1"> | ||
</p-button> | ||
<button pButton icon="pi pi-sort" label="Por nombre" class="mr-1 p-button-warning" | ||
(click)="cambiarOrden('nombre')"></button> | ||
<button pButton icon="pi pi-sort" label="Vuela" class="mr-1 p-button-success " | ||
(click)="cambiarOrden('vuela')"></button> | ||
<button pButton icon="pi pi-sort" label="Por color" class="mr-1 p-button-help" | ||
(click)="cambiarOrden('color')"></button> | ||
</div> | ||
</p-toolbar> | ||
|
||
<div class="grid"> | ||
<div class="col mt-2"> | ||
<p-table [value]="heroes | ordenar: ordenarPor " responsiveLayout="scroll"> | ||
<ng-template pTemplate="header"> | ||
<tr> | ||
<th>Nombre</th> | ||
<th>Vuela</th> | ||
<th>Color</th> | ||
</tr> | ||
</ng-template> | ||
<ng-template pTemplate="body" let-heroe> | ||
<tr> | ||
<td>{{heroe.nombre | titlecase}}</td> | ||
<td>{{heroe.vuela | vuela | titlecase }}</td> | ||
<td>{{heroe.color }}</td> | ||
</tr> | ||
</ng-template> | ||
</p-table> | ||
</div> | ||
</div> | ||
|
||
|
||
<div class="grid"> | ||
<div class="col mt-2"> | ||
<p-table [value]="heroes | slice:0" responsiveLayout="scroll"> | ||
<ng-template pTemplate="header"> | ||
<tr> | ||
<th pSortableColumn="nombre">Nombre <p-sortIcon field="nombre"></p-sortIcon> | ||
</th> | ||
<th pSortableColumn="vuela">Vuela <p-sortIcon field="vuela"></p-sortIcon> | ||
</th> | ||
<th pSortableColumn="color">Color <p-sortIcon field="color"></p-sortIcon> | ||
</th> | ||
</tr> | ||
</ng-template> | ||
<ng-template pTemplate="body" let-heroe> | ||
<tr> | ||
<td>{{heroe.nombre | titlecase}}</td> | ||
<td>{{heroe.vuela | vuela | titlecase }}</td> | ||
<td>{{heroe.color }}</td> | ||
</tr> | ||
</ng-template> | ||
</p-table> | ||
</div> | ||
</div> |
44 changes: 40 additions & 4 deletions
44
workspace/04-pipesApp/src/app/ventas/pages/ordenar/ordenar.component.ts
This file contains 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,16 +1,52 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Component } from '@angular/core'; | ||
import { Color, Heroe } from '../../interfaces/ventas.interface'; | ||
|
||
@Component({ | ||
selector: 'app-ordenar', | ||
templateUrl: './ordenar.component.html', | ||
styles: [ | ||
] | ||
}) | ||
export class OrdenarComponent implements OnInit { | ||
export class OrdenarComponent { | ||
|
||
constructor() { } | ||
enMayusculas: boolean = false; | ||
|
||
ngOnInit(): void { | ||
ordenarPor: string = ''; | ||
|
||
heroes: Heroe[] = [ | ||
{ | ||
nombre: 'Superman', | ||
vuela: true, | ||
color: Color.azul | ||
}, | ||
{ | ||
nombre: 'Bataman', | ||
vuela: false, | ||
color: Color.negro | ||
}, | ||
{ | ||
nombre: 'Robin', | ||
vuela: false, | ||
color: Color.verde | ||
}, | ||
{ | ||
nombre: 'Dart Devil', | ||
vuela: false, | ||
color: Color.rojo | ||
}, | ||
{ | ||
nombre: 'Linterna Verde', | ||
vuela: true, | ||
color: Color.verde | ||
}, | ||
]; | ||
|
||
|
||
cambiarTamanio() { | ||
(this.enMayusculas) ? this.enMayusculas = false : this.enMayusculas = true; | ||
} | ||
|
||
cambiarOrden(valor: string){ | ||
this.ordenarPor = valor; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
workspace/04-pipesApp/src/app/ventas/pipes/mayusculas.pipe.ts
This file contains 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,13 @@ | ||
import { Pipe, PipeTransform } from "@angular/core"; | ||
|
||
@Pipe({ | ||
name: 'mayusculas' | ||
}) | ||
export class MayusculasPipe implements PipeTransform { | ||
|
||
transform(valor: string, enMayusculas: boolean = true): string { | ||
return (enMayusculas) ? valor.toUpperCase() : valor.toLowerCase(); | ||
} | ||
|
||
} | ||
|
25 changes: 25 additions & 0 deletions
25
workspace/04-pipesApp/src/app/ventas/pipes/ordenar.pipe.ts
This file contains 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,25 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
import { Heroe } from '../interfaces/ventas.interface'; | ||
|
||
@Pipe({ | ||
name: 'ordenar' | ||
}) | ||
export class OrdenarPipe implements PipeTransform { | ||
|
||
transform(heroes: Heroe[], ordenarPor: string = 'sin valor'): Heroe[] { | ||
|
||
switch (ordenarPor) { | ||
case 'nombre': | ||
return heroes = heroes.sort((a, b) => (a.nombre > b.nombre) ? 1 : -1); | ||
case 'vuela': | ||
return heroes = heroes.sort((a, b) => (a.vuela > b.vuela) ? -1 : 1); | ||
case 'color': | ||
return heroes = heroes.sort((a, b) => (a.color > b.color) ? 1 : -1); | ||
|
||
default: | ||
return heroes; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains 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,12 @@ | ||
import { Pipe, PipeTransform } from "@angular/core"; | ||
|
||
@Pipe({ | ||
name: 'vuela' | ||
}) | ||
export class VuelaPipe implements PipeTransform { | ||
|
||
transform(vuela: boolean): string { | ||
return (vuela) ? 'vuela' : 'no vuela'; | ||
} | ||
|
||
} |
This file contains 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