Commit 569a98e9faab563caa3ab019c0fa2047f5577119
Exists in
master
Merge branch 'master' of git.focasoftware.com:angular/autoservicio
Showing
9 changed files
Show diff stats
src/app/app-routing.module.ts
1 | import { NgModule } from '@angular/core'; | 1 | import { NgModule } from '@angular/core'; |
2 | import { Routes, RouterModule } from '@angular/router'; | 2 | import { Routes, RouterModule } from '@angular/router'; |
3 | import { HomeComponent } from './components/home/home.component'; | 3 | import { HomeComponent } from './components/home/home.component'; |
4 | import { InicioComponent } from './components/inicio/inicio.component'; | 4 | import { InicioComponent } from './components/inicio/inicio.component'; |
5 | import { BusquedaProductosComponent } from './components/busqueda-productos/busqueda-productos.component'; | 5 | import { BusquedaProductosComponent } from './components/busqueda-productos/busqueda-productos.component'; |
6 | import { ConfirmacionCarritoComponent } from './components/confirmacion-carrito/confirmacion-carrito.component'; | 6 | import { ConfirmacionCarritoComponent } from './components/confirmacion-carrito/confirmacion-carrito.component'; |
7 | import { MasterComponent } from './components/master/master.component'; | 7 | import { MasterComponent } from './components/master/master.component'; |
8 | import { CancelarCompraComponent } from './components/cancelar-compra/cancelar-compra.component'; | 8 | import { CancelarCompraComponent } from './components/cancelar-compra/cancelar-compra.component'; |
9 | import { MensajeFinalComponent } from './components/mensaje-final/mensaje-final.component'; | 9 | import { MensajeFinalComponent } from './components/mensaje-final/mensaje-final.component'; |
10 | import { ComandaComponent } from './components/comanda/comanda.component'; | 10 | import { ComandaComponent } from './components/comanda/comanda.component'; |
11 | import { PedidosSalientesComponent } from './components/pedidos-salientes/pedidos-salientes.component'; | ||
11 | 12 | ||
12 | const routes: Routes = [ | 13 | const routes: Routes = [ |
13 | { path: '', component: HomeComponent }, | 14 | { path: '', component: HomeComponent }, |
14 | { path: 'home', component: HomeComponent }, | 15 | { path: 'home', component: HomeComponent }, |
15 | { path: 'confirmacion-carrito', component: ConfirmacionCarritoComponent }, | 16 | { path: 'confirmacion-carrito', component: ConfirmacionCarritoComponent }, |
16 | { path: 'cancelar-compra', component: CancelarCompraComponent }, | 17 | { path: 'cancelar-compra', component: CancelarCompraComponent }, |
17 | { path: 'mensaje-final', component: MensajeFinalComponent }, | 18 | { path: 'mensaje-final', component: MensajeFinalComponent }, |
18 | { path: 'comanda', component: ComandaComponent }, | 19 | { path: 'comanda', component: ComandaComponent }, |
20 | { path: 'pedidos-salientes', component: PedidosSalientesComponent }, | ||
19 | { | 21 | { |
20 | path: '', | 22 | path: '', |
21 | component: MasterComponent, | 23 | component: MasterComponent, |
22 | children: [ | 24 | children: [ |
23 | { path: 'inicio', component: InicioComponent }, | 25 | { path: 'inicio', component: InicioComponent }, |
24 | { path: 'busqueda-productos', component: BusquedaProductosComponent } | 26 | { path: 'busqueda-productos', component: BusquedaProductosComponent } |
25 | ] | 27 | ] |
26 | }, | 28 | }, |
27 | { path: '**', redirectTo: '/home', pathMatch: 'full' }, | 29 | { path: '**', redirectTo: '/home', pathMatch: 'full' }, |
28 | ]; | 30 | ]; |
29 | 31 | ||
30 | @NgModule({ | 32 | @NgModule({ |
31 | imports: [RouterModule.forRoot(routes, {onSameUrlNavigation: 'reload'})], | 33 | imports: [RouterModule.forRoot(routes, {onSameUrlNavigation: 'reload'})], |
32 | exports: [RouterModule] | 34 | exports: [RouterModule] |
33 | }) | 35 | }) |
34 | 36 | ||
35 | export class AppRoutingModule { } | 37 | export class AppRoutingModule { } |
36 | 38 |
src/app/app.module.ts
1 | //#region MODULES | 1 | //#region MODULES |
2 | import { BrowserModule } from '@angular/platform-browser'; | 2 | import { BrowserModule } from '@angular/platform-browser'; |
3 | import { NgModule } from '@angular/core'; | 3 | import { NgModule } from '@angular/core'; |
4 | import { AppRoutingModule } from './app-routing.module'; | 4 | import { AppRoutingModule } from './app-routing.module'; |
5 | import { HttpClientModule } from '@angular/common/http'; | 5 | import { HttpClientModule } from '@angular/common/http'; |
6 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; | 6 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; |
7 | import { TooltipModule } from 'ngx-bootstrap/tooltip'; | 7 | import { TooltipModule } from 'ngx-bootstrap/tooltip'; |
8 | import { PopoverModule } from 'ngx-bootstrap/popover'; | 8 | import { PopoverModule } from 'ngx-bootstrap/popover'; |
9 | import { CarouselModule } from 'ngx-bootstrap/carousel'; | 9 | import { CarouselModule } from 'ngx-bootstrap/carousel'; |
10 | import { PaginationModule } from 'ngx-bootstrap/pagination'; | 10 | import { PaginationModule } from 'ngx-bootstrap/pagination'; |
11 | //#endregion | 11 | //#endregion |
12 | 12 | ||
13 | //#region Keyboard | 13 | //#region Keyboard |
14 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | 14 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
15 | import { MatButtonModule } from '@angular/material/button'; | 15 | import { MatButtonModule } from '@angular/material/button'; |
16 | import { MatKeyboardModule } from '@ngx-material-keyboard/core'; | 16 | import { MatKeyboardModule } from '@ngx-material-keyboard/core'; |
17 | //#endregion | 17 | //#endregion |
18 | 18 | ||
19 | //#region COMPONENTS | 19 | //#region COMPONENTS |
20 | import { AppComponent } from './app.component'; | 20 | import { AppComponent } from './app.component'; |
21 | import { HeaderComponent } from './components/header/header.component'; | 21 | import { HeaderComponent } from './components/header/header.component'; |
22 | import { SidebarComponent } from './components/sidebar/sidebar.component'; | 22 | import { SidebarComponent } from './components/sidebar/sidebar.component'; |
23 | import { HomeComponent } from './components/home/home.component'; | 23 | import { HomeComponent } from './components/home/home.component'; |
24 | import { InicioComponent } from './components/inicio/inicio.component'; | 24 | import { InicioComponent } from './components/inicio/inicio.component'; |
25 | import { BusquedaProductosComponent } from './components/busqueda-productos/busqueda-productos.component'; | 25 | import { BusquedaProductosComponent } from './components/busqueda-productos/busqueda-productos.component'; |
26 | import { ConfirmacionCarritoComponent } from './components/confirmacion-carrito/confirmacion-carrito.component'; | 26 | import { ConfirmacionCarritoComponent } from './components/confirmacion-carrito/confirmacion-carrito.component'; |
27 | import { MasterComponent } from './components/master/master.component'; | 27 | import { MasterComponent } from './components/master/master.component'; |
28 | import { PopoverPromosComponent } from './components/popover-promos/popover-promos.component'; | 28 | import { PopoverPromosComponent } from './components/popover-promos/popover-promos.component'; |
29 | import { PopoverSinonimosComponent } from './components/popover-sinonimos/popover-sinonimos.component'; | 29 | import { PopoverSinonimosComponent } from './components/popover-sinonimos/popover-sinonimos.component'; |
30 | import { CancelarCompraComponent } from './components/cancelar-compra/cancelar-compra.component'; | 30 | import { CancelarCompraComponent } from './components/cancelar-compra/cancelar-compra.component'; |
31 | import { MensajeFinalComponent } from './components/mensaje-final/mensaje-final.component'; | 31 | import { MensajeFinalComponent } from './components/mensaje-final/mensaje-final.component'; |
32 | import { ComandaComponent } from './components/comanda/comanda.component'; | 32 | import { ComandaComponent } from './components/comanda/comanda.component'; |
33 | import { PedidosSalientesComponent } from './components/pedidos-salientes/pedidos-salientes.component'; | ||
33 | //#endregion | 34 | //#endregion |
34 | 35 | ||
35 | @NgModule({ | 36 | @NgModule({ |
36 | declarations: [ | 37 | declarations: [ |
37 | AppComponent, | 38 | AppComponent, |
38 | HeaderComponent, | 39 | HeaderComponent, |
39 | SidebarComponent, | 40 | SidebarComponent, |
40 | HomeComponent, | 41 | HomeComponent, |
41 | InicioComponent, | 42 | InicioComponent, |
42 | BusquedaProductosComponent, | 43 | BusquedaProductosComponent, |
43 | ConfirmacionCarritoComponent, | 44 | ConfirmacionCarritoComponent, |
44 | MasterComponent, | 45 | MasterComponent, |
45 | PopoverPromosComponent, | 46 | PopoverPromosComponent, |
46 | PopoverSinonimosComponent, | 47 | PopoverSinonimosComponent, |
47 | CancelarCompraComponent, | 48 | CancelarCompraComponent, |
48 | MensajeFinalComponent, | 49 | MensajeFinalComponent, |
49 | ComandaComponent | 50 | ComandaComponent, |
51 | PedidosSalientesComponent | ||
50 | ], | 52 | ], |
51 | imports: [ | 53 | imports: [ |
52 | BrowserModule, | 54 | BrowserModule, |
53 | AppRoutingModule, | 55 | AppRoutingModule, |
54 | HttpClientModule, | 56 | HttpClientModule, |
55 | FormsModule, | 57 | FormsModule, |
56 | ReactiveFormsModule, | 58 | ReactiveFormsModule, |
57 | ReactiveFormsModule.withConfig({ warnOnNgModelWithFormControl: 'never' }), | 59 | ReactiveFormsModule.withConfig({ warnOnNgModelWithFormControl: 'never' }), |
58 | TooltipModule.forRoot(), | 60 | TooltipModule.forRoot(), |
59 | PopoverModule.forRoot(), | 61 | PopoverModule.forRoot(), |
60 | BrowserAnimationsModule, | 62 | BrowserAnimationsModule, |
61 | MatKeyboardModule, | 63 | MatKeyboardModule, |
62 | MatButtonModule, | 64 | MatButtonModule, |
63 | CarouselModule.forRoot(), | 65 | CarouselModule.forRoot(), |
64 | PaginationModule.forRoot() | 66 | PaginationModule.forRoot() |
65 | ], | 67 | ], |
66 | providers: [], | 68 | providers: [], |
67 | bootstrap: [AppComponent] | 69 | bootstrap: [AppComponent] |
68 | }) | 70 | }) |
69 | export class AppModule { } | 71 | export class AppModule { } |
70 | 72 |
src/app/components/busqueda-productos/busqueda-productos.component.html
1 | <div class="row m-0 fade-in"> | 1 | <div class="row m-0 fade-in"> |
2 | <div class="col-12 p-0"> | 2 | <div class="col-12 p-0"> |
3 | 3 | ||
4 | <!-- NOMBRE DE SECCION --> | 4 | <!-- NOMBRE DE SECCION --> |
5 | <div class="row m-0"> | 5 | <div class="row m-0"> |
6 | <div class="col-12 p-0"> | 6 | <div class="col-12 p-0"> |
7 | <p class="h5 py-1 bg-gray text-muted text-center"> | 7 | <p class="h5 py-1 bg-gray text-muted text-center"> |
8 | {{title}} | 8 | {{title}} |
9 | <i *ngIf="title === 'Búsqueda'" class="fa fa-search"></i> | 9 | <i *ngIf="title === 'Búsqueda'" class="fa fa-search"></i> |
10 | </p> | 10 | </p> |
11 | </div> | 11 | </div> |
12 | </div> | 12 | </div> |
13 | 13 | ||
14 | <div class="row m-3 disable-user-select"> | 14 | <div class="row m-3 disable-user-select"> |
15 | 15 | ||
16 | <!-- FILTROS --> | 16 | <!-- FILTROS --> |
17 | <div *ngIf="queMostrar != 'promociones'" class="col-sm-2 p-1"> | 17 | <div *ngIf="queMostrar != 'promociones'" class="col-sm-2 p-1"> |
18 | <div class="text-center"> | 18 | <div class="text-center"> |
19 | <p class="font-weight-bold text-muted border-bottom pb-2">Buscar por Categoría</p> | 19 | <p class="font-weight-bold text-muted border-bottom pb-2">Buscar por Categoría</p> |
20 | </div> | 20 | </div> |
21 | <ul class="list-group"> | 21 | <ul class="list-group"> |
22 | <li | 22 | <li |
23 | [ngClass]="{active: categoriaActive == 0}" | 23 | [ngClass]="{active: categoriaActive == 0}" |
24 | (click)="categoriaActive = 0; filterItems()" | 24 | (click)="categoriaActive = 0; filterItems()" |
25 | class="list-group-item list-group-item-action text-center my-1 p-2 h6"> | 25 | class="list-group-item list-group-item-action text-center my-1 p-2 h6"> |
26 | Todos | 26 | Todos |
27 | </li> | 27 | </li> |
28 | <li | 28 | <li |
29 | *ngFor="let categoria of categorias" | 29 | *ngFor="let categoria of categorias" |
30 | [ngClass]="{active: categoriaActive == categoria.id}" | 30 | [ngClass]="{active: categoriaActive == categoria.id}" |
31 | (click)="categoriaActive = categoria.id; filterItems()" | 31 | (click)="categoriaActive = categoria.id; filterItems()" |
32 | class="list-group-item list-group-item-action text-center my-1 p-2 h6"> | 32 | class="list-group-item list-group-item-action text-center my-1 p-2 h6"> |
33 | {{categoria.detalle}} | 33 | {{categoria.detalle}} |
34 | </li> | 34 | </li> |
35 | </ul> | 35 | </ul> |
36 | </div> | 36 | </div> |
37 | 37 | ||
38 | <!-- SEARCH INPUT --> | 38 | <!-- SEARCH INPUT --> |
39 | <div *ngIf="productos.length > 0" class="fade-in col"> | 39 | <div *ngIf="productos.length > 0" class="fade-in col"> |
40 | 40 | ||
41 | <div class="row search"> | 41 | <div class="row search"> |
42 | <div class="col-sm-10"> | 42 | <div class="col-sm-10"> |
43 | <span class="fa fa-search form-control-lg form-control-search pl-3"></span> | 43 | <span class="fa fa-search form-control-lg form-control-search pl-3"></span> |
44 | <input | 44 | <input |
45 | [matKeyboard]="'spanish'" | 45 | [matKeyboard]="'spanish'" |
46 | type="text" | 46 | type="text" |
47 | class="form-control form-control-lg shadow-sm rounded-pill px-5" | 47 | class="form-control form-control-lg shadow-sm rounded-pill px-5" |
48 | placeholder="Búsqueda productos" | 48 | placeholder="Búsqueda productos" |
49 | [(ngModel)]="searchTerm" | 49 | [(ngModel)]="searchTerm" |
50 | (ngModelChange)="filterItems()"> | 50 | (ngModelChange)="filterItems()"> |
51 | </div> | 51 | </div> |
52 | <!-- BOTON VOLVER --> | 52 | <!-- BOTON VOLVER --> |
53 | <div class="col-sm-2"> | 53 | <div class="col-sm-2"> |
54 | <button | 54 | <button |
55 | type="button" | 55 | type="button" |
56 | class="btn btn-light btn-lg shadow-sm" | 56 | class="btn btn-light btn-lg shadow-sm" |
57 | [routerLink]="['/inicio']"> | 57 | [routerLink]="['/inicio']"> |
58 | <span class="font-weight-normal h6 pr-2">Volver</span> | 58 | <span class="font-weight-normal h6 pr-2">Volver</span> |
59 | <i class="fa fa-undo text-warning" aria-hidden="true"></i> | 59 | <i class="fa fa-undo text-warning" aria-hidden="true"></i> |
60 | </button> | 60 | </button> |
61 | </div> | 61 | </div> |
62 | <div class="col-sm-12 my-2 h5"> | 62 | <div class="col-sm-12 my-2 h5"> |
63 | <button | 63 | <button |
64 | class="btn btn-outline-primary badge badge-light px-2 shadow-sm" | 64 | class="btn btn-outline-primary badge badge-light px-2 shadow-sm" |
65 | [ngClass]="{'active': ordenandoByVendidos}" | 65 | [ngClass]="{'active': ordenandoByVendidos}" |
66 | (click)="ordenandoByVendidos = !ordenandoByVendidos; ordenar()" | 66 | (click)="ordenandoByVendidos = !ordenandoByVendidos; filterItems()" |
67 | >Más vendidos</button> | 67 | >Más vendidos</button> |
68 | </div> | 68 | </div> |
69 | </div> | 69 | </div> |
70 | <!-- LISTA DE PRODUCTOS --> | 70 | <!-- LISTA DE PRODUCTOS --> |
71 | <div class="row align-items-start vh-70 overflow-scroll disable-user-select"> | 71 | <div class="row align-items-start vh-70 overflow-scroll disable-user-select"> |
72 | <div | 72 | <div |
73 | class="col-4 p-2" | 73 | class="col-4 p-2" |
74 | *ngFor="let producto of auxProductos"> | 74 | *ngFor="let producto of auxProductos"> |
75 | <div | 75 | <div |
76 | class="card-effect bg-white rounded-sm shadow border-0" | 76 | class="card-effect bg-white rounded-sm shadow border-0" |
77 | (click)="elegirProducto(producto)"> | 77 | (click)="elegirProducto(producto)"> |
78 | <img src="{{apiImagenes}}/imagenes/{{producto.imagenes[0].imagen}}" class="rounded-sm w-100 m-auto"> | 78 | <img src="{{apiImagenes}}/imagenes/{{producto.imagenes[0].imagen}}" class="rounded-sm w-100 m-auto"> |
79 | <div class="p-2"> | 79 | <div class="p-2"> |
80 | <p class="h6 min-h-40 text-left m-0"><small>{{producto.DET_LAR}}</small></p> | 80 | <p class="h6 min-h-40 text-left m-0"><small>{{producto.DET_LAR}}</small></p> |
81 | <div class="row m-0"> | 81 | <div class="row m-0"> |
82 | <div class="col-12 my-auto pt-2 pr-2 p-0"> | 82 | <div class="col-12 my-auto pt-2 pr-2 p-0"> |
83 | <p class="text-right m-0 h6">{{producto.PreVen | currency}}</p> | 83 | <p class="text-right m-0 h6">{{producto.PreVen | currency}}</p> |
84 | </div> | 84 | </div> |
85 | </div> | 85 | </div> |
86 | </div> | 86 | </div> |
87 | </div> | 87 | </div> |
88 | </div> | 88 | </div> |
89 | </div> | 89 | </div> |
90 | </div> | 90 | </div> |
91 | 91 | ||
92 | <!-- SPINNER --> | 92 | <!-- SPINNER --> |
93 | <div | 93 | <div |
94 | *ngIf="productos.length === 0 && showSpinner" | 94 | *ngIf="productos.length === 0 && showSpinner" |
95 | class="col-sm-10 p-0 align-self-center text-center"> | 95 | class="col-sm-10 p-0 align-self-center text-center"> |
96 | <div class="spinner-border spinner-lg text-secondary" role="status"></div> | 96 | <div class="spinner-border spinner-lg text-secondary" role="status"></div> |
97 | <span class="text-secondary m-2 h5">Cargando información.</span> | 97 | <span class="text-secondary m-2 h5">Cargando información.</span> |
98 | </div> | 98 | </div> |
99 | 99 | ||
100 | </div> | 100 | </div> |
101 | 101 | ||
102 | </div> | 102 | </div> |
103 | 103 | ||
104 | </div> | 104 | </div> |
105 | 105 |
src/app/components/busqueda-productos/busqueda-productos.component.ts
1 | import { Component, OnInit, EventEmitter } from '@angular/core'; | 1 | import { Component, OnInit, EventEmitter } from '@angular/core'; |
2 | import { ProductoService } from 'src/app/services/producto.service'; | 2 | import { ProductoService } from 'src/app/services/producto.service'; |
3 | import { Producto } from 'src/app/wrappers/producto'; | 3 | import { Producto } from 'src/app/wrappers/producto'; |
4 | import { Categoria } from 'src/app/wrappers/categoria'; | 4 | import { Categoria } from 'src/app/wrappers/categoria'; |
5 | import { appSettings } from 'src/etc/AppSettings'; | 5 | import { appSettings } from 'src/etc/AppSettings'; |
6 | import { Router } from '@angular/router'; | 6 | import { Router } from '@angular/router'; |
7 | 7 | ||
8 | @Component({ | 8 | @Component({ |
9 | selector: 'app-busqueda-productos', | 9 | selector: 'app-busqueda-productos', |
10 | templateUrl: './busqueda-productos.component.html', | 10 | templateUrl: './busqueda-productos.component.html', |
11 | styleUrls: ['./busqueda-productos.component.scss'] | 11 | styleUrls: ['./busqueda-productos.component.scss'] |
12 | }) | 12 | }) |
13 | export class BusquedaProductosComponent implements OnInit { | 13 | export class BusquedaProductosComponent implements OnInit { |
14 | 14 | ||
15 | private productos: Producto[] = []; | 15 | private productos: Producto[] = []; |
16 | private auxProductos: Producto[] = []; | 16 | private auxProductos: Producto[] = []; |
17 | private searchTerm: string = ''; | 17 | private searchTerm: string = ''; |
18 | private categoriaActive: number = null; | 18 | private categoriaActive: number = null; |
19 | private showSpinner: boolean = true; | 19 | private showSpinner: boolean = true; |
20 | private queMostrar: string = 'todos'; | 20 | private queMostrar: string = 'todos'; |
21 | private apiImagenes: string = appSettings.apiImagenes; | 21 | private apiImagenes: string = appSettings.apiImagenes; |
22 | private categorias: Categoria[] = []; | 22 | private categorias: Categoria[] = []; |
23 | private blurFocus = new EventEmitter(); | 23 | private blurFocus = new EventEmitter(); |
24 | private ordenandoByVendidos = true; | 24 | private ordenandoByVendidos = true; |
25 | private title: string = 'Búsqueda' | 25 | private title: string = 'Búsqueda' |
26 | 26 | ||
27 | constructor( | 27 | constructor( |
28 | private productoService: ProductoService, | 28 | private productoService: ProductoService, |
29 | private router: Router) { } | 29 | private router: Router) { } |
30 | 30 | ||
31 | ngOnInit() { | 31 | ngOnInit() { |
32 | 32 | ||
33 | this.queMostrar = this.productoService.mostrar; | 33 | this.queMostrar = this.productoService.mostrar; |
34 | 34 | ||
35 | this.productoService.getCategorias() | 35 | this.productoService.getCategorias() |
36 | .subscribe((categorias: Categoria[]) => { | 36 | .subscribe((categorias: Categoria[]) => { |
37 | 37 | ||
38 | switch (this.queMostrar) { | 38 | switch (this.queMostrar) { |
39 | case 'todos': | 39 | case 'todos': |
40 | this.categorias = categorias; | 40 | this.categorias = categorias; |
41 | this.categoriaActive = 0; | 41 | this.categoriaActive = 0; |
42 | this.title = 'Búsqueda'; | 42 | this.title = 'Búsqueda'; |
43 | break; | 43 | break; |
44 | case 'promociones': | 44 | case 'promociones': |
45 | this.categorias = categorias; | 45 | this.categorias = categorias; |
46 | this.categoriaActive = 1; | 46 | this.categoriaActive = 1; |
47 | this.title = 'Promociones'; | 47 | this.title = 'Promociones'; |
48 | break; | 48 | break; |
49 | case 'ordenar': | 49 | case 'ordenar': |
50 | this.categorias = categorias.filter((categoria: Categoria) => { | 50 | this.categorias = categorias.filter((categoria: Categoria) => { |
51 | return categoria.ES_PEDIDO; | 51 | return categoria.ES_PEDIDO; |
52 | }); | 52 | }); |
53 | this.categoriaActive = 0; | 53 | this.categoriaActive = 0; |
54 | this.title = 'Ordenar'; | 54 | this.title = 'Ordenar'; |
55 | break; | 55 | break; |
56 | default: | 56 | default: |
57 | this.categorias = categorias; | 57 | this.categorias = categorias; |
58 | this.categoriaActive = 0; | 58 | this.categoriaActive = 0; |
59 | this.title = 'Búsqueda'; | 59 | this.title = 'Búsqueda'; |
60 | break; | 60 | break; |
61 | } | 61 | } |
62 | }); | 62 | }); |
63 | 63 | ||
64 | this.productoService.productoAcargar = undefined; | 64 | this.productoService.productoAcargar = undefined; |
65 | this.productoService.getAll() | 65 | this.productoService.getAll() |
66 | .subscribe((data: Producto[]) => { | 66 | .subscribe((data: Producto[]) => { |
67 | 67 | ||
68 | this.setProductosSinImagen(data); | 68 | this.setProductosSinImagen(data); |
69 | 69 | ||
70 | if (this.queMostrar == 'ordenar') { | 70 | if (this.queMostrar == 'ordenar') { |
71 | 71 | ||
72 | this.categorias.forEach((categoria: Categoria) => { | 72 | this.categorias.forEach((categoria: Categoria) => { |
73 | 73 | ||
74 | let tempProductos = data.filter((producto: Producto) => { | 74 | let tempProductos = data.filter((producto: Producto) => { |
75 | return producto.categoria_selfservice == categoria.id; | 75 | return producto.categoria_selfservice == categoria.id; |
76 | }); | 76 | }); |
77 | 77 | ||
78 | this.productos = this.productos.concat(tempProductos); | 78 | this.productos = this.productos.concat(tempProductos); |
79 | 79 | ||
80 | }); | 80 | }); |
81 | } else { | 81 | } else { |
82 | this.productos = data; | 82 | this.productos = data; |
83 | } | 83 | } |
84 | this.filterItems(); | 84 | this.filterItems(); |
85 | this.ordenar(); | ||
86 | }, (error) => { | 85 | }, (error) => { |
87 | this.showSpinner = false; | 86 | this.showSpinner = false; |
88 | console.error(error); | 87 | console.error(error); |
89 | }); | 88 | }); |
90 | } | 89 | } |
91 | 90 | ||
92 | filterItems() { | 91 | filterItems() { |
93 | 92 | ||
94 | this.auxProductos = this.productos.filter(x => { | 93 | this.auxProductos = this.productos.filter(x => { |
95 | if (this.categoriaActive === 0) { | 94 | if (this.categoriaActive === 0) { |
96 | return x.DET_LAR.toLowerCase().includes(this.searchTerm.toLowerCase()); | 95 | return x.DET_LAR.toLowerCase().includes(this.searchTerm.toLowerCase()); |
97 | } | 96 | } |
98 | else { | 97 | else { |
99 | return x.DET_LAR.toLowerCase().includes(this.searchTerm.toLowerCase()) && | 98 | return x.DET_LAR.toLowerCase().includes(this.searchTerm.toLowerCase()) && |
100 | x.categoria_selfservice === this.categoriaActive; | 99 | x.categoria_selfservice === this.categoriaActive; |
101 | } | 100 | } |
102 | }); | 101 | }); |
103 | 102 | ||
103 | this.ordenar(); | ||
104 | |||
104 | } | 105 | } |
105 | 106 | ||
106 | agregarAlCarrito(producto: Producto) { | 107 | agregarAlCarrito(producto: Producto) { |
107 | 108 | ||
108 | producto.cantidad = 1; | 109 | producto.cantidad = 1; |
109 | this.productoService.productos.push(producto); | 110 | this.productoService.productos.push(producto); |
110 | } | 111 | } |
111 | 112 | ||
112 | ordenar() { | 113 | ordenar() { |
113 | 114 | ||
114 | if (this.ordenandoByVendidos) { | 115 | if (this.ordenandoByVendidos) { |
115 | 116 | ||
116 | this.auxProductos.sort((a, b) => { | 117 | this.auxProductos.sort((a, b) => { |
117 | return b.cantidadVendida - a.cantidadVendida; | 118 | return b.cantidadVendida - a.cantidadVendida; |
118 | }); | 119 | }); |
119 | } else { | ||
120 | this.filterItems(); | ||
121 | } | 120 | } |
122 | 121 | ||
123 | } | 122 | } |
124 | 123 | ||
125 | private elegirProducto(producto: Producto) { | 124 | private elegirProducto(producto: Producto) { |
126 | 125 | ||
127 | if (producto.PRO) { | 126 | if (producto.PRO) { |
128 | 127 | ||
129 | let imagenes = producto.imagenes; | 128 | let imagenes = producto.imagenes; |
130 | this.productoService.getPromocionByCodigos(producto.CodSec, producto.CodArt) | 129 | this.productoService.getPromocionByCodigos(producto.CodSec, producto.CodArt) |
131 | .subscribe(res => { | 130 | .subscribe(res => { |
132 | 131 | ||
133 | this.productoService.productoAcargar = res[0]; | 132 | this.productoService.productoAcargar = res[0]; |
134 | this.productoService.productoAcargar.imagenes = imagenes; | 133 | this.productoService.productoAcargar.imagenes = imagenes; |
135 | this.router.navigate(['inicio']); | 134 | this.router.navigate(['inicio']); |
136 | }, | 135 | }, |
137 | error => { console.error(error); } | 136 | error => { console.error(error); } |
138 | ); | 137 | ); |
139 | } else { | 138 | } else { |
140 | 139 | ||
141 | this.productoService.productoAcargar = producto; | 140 | this.productoService.productoAcargar = producto; |
142 | this.router.navigate(['inicio']); | 141 | this.router.navigate(['inicio']); |
143 | } | 142 | } |
144 | 143 | ||
145 | } | 144 | } |
146 | 145 | ||
147 | private setProductosSinImagen(productos: Producto[]) { | 146 | private setProductosSinImagen(productos: Producto[]) { |
148 | 147 | ||
149 | productos.forEach((producto: Producto) => { | 148 | productos.forEach((producto: Producto) => { |
150 | producto.imagenes = producto.imagenes.length == 0 ? | 149 | producto.imagenes = producto.imagenes.length == 0 ? |
151 | [{ imagen: 'noImage.jpg' }] : producto.imagenes; | 150 | [{ imagen: 'noImage.jpg' }] : producto.imagenes; |
152 | }) | 151 | }) |
153 | } | 152 | } |
src/app/components/pedidos-salientes/pedidos-salientes.component.html
File was created | 1 | <div class="bg-primary-gradient vh-100"> | |
2 | <div class="d-flex justify-content-center"> | ||
3 | <div class="row my-5 text-white text-center"> | ||
4 | <h1 class="col-12">Su pedido ya esta listo.</h1> | ||
5 | <h2 class="col-12 mt-3">Nº de Pedido</h2> | ||
6 | |||
7 | <h1 *ngIf="pedidosRecientes.length" class="col-12 border rounded"> | ||
8 | {{rellenar(pedidosRecientes[0].id, 2)}} | ||
9 | </h1> | ||
10 | |||
11 | <h2 *ngFor="let pedido of pedidosRecientes; let i = index" [hidden]="i == 0" class="col-4 border rounded mx-0"> | ||
12 | {{rellenar(pedido.id, 2)}} | ||
13 | </h2> | ||
14 | </div> | ||
15 | </div> | ||
16 | </div> | ||
17 |
src/app/components/pedidos-salientes/pedidos-salientes.component.scss
src/app/components/pedidos-salientes/pedidos-salientes.component.spec.ts
File was created | 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | |
2 | |||
3 | import { PedidosSalientesComponent } from './pedidos-salientes.component'; | ||
4 | |||
5 | describe('PedidosSalientesComponent', () => { | ||
6 | let component: PedidosSalientesComponent; | ||
7 | let fixture: ComponentFixture<PedidosSalientesComponent>; | ||
8 | |||
9 | beforeEach(async(() => { | ||
10 | TestBed.configureTestingModule({ | ||
11 | declarations: [ PedidosSalientesComponent ] | ||
12 | }) | ||
13 | .compileComponents(); | ||
14 | })); | ||
15 | |||
16 | beforeEach(() => { | ||
17 | fixture = TestBed.createComponent(PedidosSalientesComponent); | ||
18 | component = fixture.componentInstance; | ||
19 | fixture.detectChanges(); | ||
20 | }); | ||
21 | |||
22 | it('should create', () => { | ||
23 | expect(component).toBeTruthy(); | ||
24 | }); | ||
25 | }); | ||
26 |
src/app/components/pedidos-salientes/pedidos-salientes.component.ts
File was created | 1 | import { Component, OnInit } from '@angular/core'; | |
2 | import { ComandaService } from 'src/app/services/comanda.service'; | ||
3 | |||
4 | @Component({ | ||
5 | selector: 'app-pedidos-salientes', | ||
6 | templateUrl: './pedidos-salientes.component.html', | ||
7 | styleUrls: ['./pedidos-salientes.component.scss'] | ||
8 | }) | ||
9 | export class PedidosSalientesComponent implements OnInit { | ||
10 | |||
11 | private pedidosRecientes = []; | ||
12 | private ciclo; | ||
13 | |||
14 | constructor(private comandaService: ComandaService) { } | ||
15 | |||
16 | ngOnInit() { | ||
17 | this.buscar(); | ||
18 | |||
19 | this.ciclo = setTimeout(() => { | ||
20 | this.buscar(); | ||
21 | }, 5000) | ||
22 | } | ||
23 | |||
24 | ngOnDestroy() { | ||
25 | |||
26 | clearTimeout(this.ciclo); | ||
27 | } | ||
28 | |||
29 | buscar() { | ||
30 | |||
31 | this.comandaService | ||
32 | .getPendientesEntrega() | ||
33 | .subscribe((pedidos: []) => { | ||
34 | |||
35 | this.pedidosRecientes = pedidos; | ||
36 | }, console.log); | ||
37 | } | ||
38 | |||
39 | rellenar(relleno, longitud) { | ||
40 | relleno = '' + relleno; | ||
41 | while (relleno.length < longitud) { | ||
42 | relleno = '0' + relleno; | ||
43 | } | ||
44 | return relleno; | ||
45 | } | ||
46 | } | ||
47 |
src/app/services/comanda.service.ts
1 | import { Injectable } from "@angular/core"; | 1 | import { Injectable } from "@angular/core"; |
2 | import { HttpClient } from "@angular/common/http"; | 2 | import { HttpClient } from "@angular/common/http"; |
3 | import { appSettings } from "src/etc/AppSettings"; | 3 | import { appSettings } from "src/etc/AppSettings"; |
4 | import { Observable } from "rxjs"; | 4 | import { Observable } from "rxjs"; |
5 | import { Comanda } from '../wrappers/comanda'; | 5 | import { Comanda } from '../wrappers/comanda'; |
6 | 6 | ||
7 | @Injectable({ | 7 | @Injectable({ |
8 | providedIn: "root" | 8 | providedIn: "root" |
9 | }) | 9 | }) |
10 | export class ComandaService { | 10 | export class ComandaService { |
11 | private apiUrl: string = appSettings.apiUrl; | 11 | private apiUrl: string = appSettings.apiUrl; |
12 | 12 | ||
13 | constructor(private http: HttpClient) { } | 13 | constructor(private http: HttpClient) { } |
14 | 14 | ||
15 | getAll(): Observable<any> { | 15 | getAll(): Observable<any> { |
16 | 16 | ||
17 | return this.http.get(`${this.apiUrl}/comandas`); | 17 | return this.http.get(`${this.apiUrl}/comandas`); |
18 | } | 18 | } |
19 | 19 | ||
20 | updateComanda(id: number, estado: number, observacion: string): Observable<any> { | 20 | updateComanda(id: number, estado: number, observacion: string): Observable<any> { |
21 | 21 | ||
22 | return this.http.get(`${this.apiUrl}/comandas/update/${id}/${estado}/${observacion}`); | 22 | return this.http.get(`${this.apiUrl}/comandas/update/${id}/${estado}/${observacion}`); |
23 | } | 23 | } |
24 | |||
25 | getPendientesEntrega() { | ||
26 | return this.http.get(`${this.apiUrl}/comandas/pendientes-entrega`); | ||
27 | } | ||
24 | } | 28 | } |
25 | 29 |