From 9dc8444979117500d41383096a63a83c97edd474 Mon Sep 17 00:00:00 2001 From: manuelinho96 Date: Fri, 5 Oct 2018 22:04:17 -0400 Subject: [PATCH 01/10] Added Clients Component. Now the client table retrieves the info from api. --- src/app/@core/data/smart-table.service.ts | 423 +----------------- .../catalog/clients/clients.component.html | 10 + .../catalog/clients/clients.component.scss | 0 .../catalog/clients/clients.component.ts | 70 +++ .../pages/catalog/clients/clients.model.ts | 6 + .../pages/catalog/clients/clients.service.ts | 33 ++ src/app/pages/pages-menu.ts | 4 + src/app/pages/pages-routing.module.ts | 6 +- src/app/pages/pages.module.ts | 4 + 9 files changed, 136 insertions(+), 420 deletions(-) create mode 100644 src/app/pages/catalog/clients/clients.component.html create mode 100644 src/app/pages/catalog/clients/clients.component.scss create mode 100644 src/app/pages/catalog/clients/clients.component.ts create mode 100644 src/app/pages/catalog/clients/clients.model.ts create mode 100644 src/app/pages/catalog/clients/clients.service.ts diff --git a/src/app/@core/data/smart-table.service.ts b/src/app/@core/data/smart-table.service.ts index 56f1087..1e48fef 100644 --- a/src/app/@core/data/smart-table.service.ts +++ b/src/app/@core/data/smart-table.service.ts @@ -4,425 +4,10 @@ import { Injectable } from '@angular/core'; export class SmartTableService { data = [{ - id: 1, - firstName: 'Mark', - lastName: 'Otto', - username: '@mdo', - email: 'mdo@gmail.com', - age: '28', - }, { - id: 2, - firstName: 'Jacob', - lastName: 'Thornton', - username: '@fat', - email: 'fat@yandex.ru', - age: '45', - }, { - id: 3, - firstName: 'Larry', - lastName: 'Bird', - username: '@twitter', - email: 'twitter@outlook.com', - age: '18', - }, { - id: 4, - firstName: 'John', - lastName: 'Snow', - username: '@snow', - email: 'snow@gmail.com', - age: '20', - }, { - id: 5, - firstName: 'Jack', - lastName: 'Sparrow', - username: '@jack', - email: 'jack@yandex.ru', - age: '30', - }, { - id: 6, - firstName: 'Ann', - lastName: 'Smith', - username: '@ann', - email: 'ann@gmail.com', - age: '21', - }, { - id: 7, - firstName: 'Barbara', - lastName: 'Black', - username: '@barbara', - email: 'barbara@yandex.ru', - age: '43', - }, { - id: 8, - firstName: 'Sevan', - lastName: 'Bagrat', - username: '@sevan', - email: 'sevan@outlook.com', - age: '13', - }, { - id: 9, - firstName: 'Ruben', - lastName: 'Vardan', - username: '@ruben', - email: 'ruben@gmail.com', - age: '22', - }, { - id: 10, - firstName: 'Karen', - lastName: 'Sevan', - username: '@karen', - email: 'karen@yandex.ru', - age: '33', - }, { - id: 11, - firstName: 'Mark', - lastName: 'Otto', - username: '@mark', - email: 'mark@gmail.com', - age: '38', - }, { - id: 12, - firstName: 'Jacob', - lastName: 'Thornton', - username: '@jacob', - email: 'jacob@yandex.ru', - age: '48', - }, { - id: 13, - firstName: 'Haik', - lastName: 'Hakob', - username: '@haik', - email: 'haik@outlook.com', - age: '48', - }, { - id: 14, - firstName: 'Garegin', - lastName: 'Jirair', - username: '@garegin', - email: 'garegin@gmail.com', - age: '40', - }, { - id: 15, - firstName: 'Krikor', - lastName: 'Bedros', - username: '@krikor', - email: 'krikor@yandex.ru', - age: '32', - }, { - 'id': 16, - 'firstName': 'Francisca', - 'lastName': 'Brady', - 'username': '@Gibson', - 'email': 'franciscagibson@comtours.com', - 'age': 11, - }, { - 'id': 17, - 'firstName': 'Tillman', - 'lastName': 'Figueroa', - 'username': '@Snow', - 'email': 'tillmansnow@comtours.com', - 'age': 34, - }, { - 'id': 18, - 'firstName': 'Jimenez', - 'lastName': 'Morris', - 'username': '@Bryant', - 'email': 'jimenezbryant@comtours.com', - 'age': 45, - }, { - 'id': 19, - 'firstName': 'Sandoval', - 'lastName': 'Jacobson', - 'username': '@Mcbride', - 'email': 'sandovalmcbride@comtours.com', - 'age': 32, - }, { - 'id': 20, - 'firstName': 'Griffin', - 'lastName': 'Torres', - 'username': '@Charles', - 'email': 'griffincharles@comtours.com', - 'age': 19, - }, { - 'id': 21, - 'firstName': 'Cora', - 'lastName': 'Parker', - 'username': '@Caldwell', - 'email': 'coracaldwell@comtours.com', - 'age': 27, - }, { - 'id': 22, - 'firstName': 'Cindy', - 'lastName': 'Bond', - 'username': '@Velez', - 'email': 'cindyvelez@comtours.com', - 'age': 24, - }, { - 'id': 23, - 'firstName': 'Frieda', - 'lastName': 'Tyson', - 'username': '@Craig', - 'email': 'friedacraig@comtours.com', - 'age': 45, - }, { - 'id': 24, - 'firstName': 'Cote', - 'lastName': 'Holcomb', - 'username': '@Rowe', - 'email': 'coterowe@comtours.com', - 'age': 20, - }, { - 'id': 25, - 'firstName': 'Trujillo', - 'lastName': 'Mejia', - 'username': '@Valenzuela', - 'email': 'trujillovalenzuela@comtours.com', - 'age': 16, - }, { - 'id': 26, - 'firstName': 'Pruitt', - 'lastName': 'Shepard', - 'username': '@Sloan', - 'email': 'pruittsloan@comtours.com', - 'age': 44, - }, { - 'id': 27, - 'firstName': 'Sutton', - 'lastName': 'Ortega', - 'username': '@Black', - 'email': 'suttonblack@comtours.com', - 'age': 42, - }, { - 'id': 28, - 'firstName': 'Marion', - 'lastName': 'Heath', - 'username': '@Espinoza', - 'email': 'marionespinoza@comtours.com', - 'age': 47, - }, { - 'id': 29, - 'firstName': 'Newman', - 'lastName': 'Hicks', - 'username': '@Keith', - 'email': 'newmankeith@comtours.com', - 'age': 15, - }, { - 'id': 30, - 'firstName': 'Boyle', - 'lastName': 'Larson', - 'username': '@Summers', - 'email': 'boylesummers@comtours.com', - 'age': 32, - }, { - 'id': 31, - 'firstName': 'Haynes', - 'lastName': 'Vinson', - 'username': '@Mckenzie', - 'email': 'haynesmckenzie@comtours.com', - 'age': 15, - }, { - 'id': 32, - 'firstName': 'Miller', - 'lastName': 'Acosta', - 'username': '@Young', - 'email': 'milleryoung@comtours.com', - 'age': 55, - }, { - 'id': 33, - 'firstName': 'Johnston', - 'lastName': 'Brown', - 'username': '@Knight', - 'email': 'johnstonknight@comtours.com', - 'age': 29, - }, { - 'id': 34, - 'firstName': 'Lena', - 'lastName': 'Pitts', - 'username': '@Forbes', - 'email': 'lenaforbes@comtours.com', - 'age': 25, - }, { - 'id': 35, - 'firstName': 'Terrie', - 'lastName': 'Kennedy', - 'username': '@Branch', - 'email': 'terriebranch@comtours.com', - 'age': 37, - }, { - 'id': 36, - 'firstName': 'Louise', - 'lastName': 'Aguirre', - 'username': '@Kirby', - 'email': 'louisekirby@comtours.com', - 'age': 44, - }, { - 'id': 37, - 'firstName': 'David', - 'lastName': 'Patton', - 'username': '@Sanders', - 'email': 'davidsanders@comtours.com', - 'age': 26, - }, { - 'id': 38, - 'firstName': 'Holden', - 'lastName': 'Barlow', - 'username': '@Mckinney', - 'email': 'holdenmckinney@comtours.com', - 'age': 11, - }, { - 'id': 39, - 'firstName': 'Baker', - 'lastName': 'Rivera', - 'username': '@Montoya', - 'email': 'bakermontoya@comtours.com', - 'age': 47, - }, { - 'id': 40, - 'firstName': 'Belinda', - 'lastName': 'Lloyd', - 'username': '@Calderon', - 'email': 'belindacalderon@comtours.com', - 'age': 21, - }, { - 'id': 41, - 'firstName': 'Pearson', - 'lastName': 'Patrick', - 'username': '@Clements', - 'email': 'pearsonclements@comtours.com', - 'age': 42, - }, { - 'id': 42, - 'firstName': 'Alyce', - 'lastName': 'Mckee', - 'username': '@Daugherty', - 'email': 'alycedaugherty@comtours.com', - 'age': 55, - }, { - 'id': 43, - 'firstName': 'Valencia', - 'lastName': 'Spence', - 'username': '@Olsen', - 'email': 'valenciaolsen@comtours.com', - 'age': 20, - }, { - 'id': 44, - 'firstName': 'Leach', - 'lastName': 'Holcomb', - 'username': '@Humphrey', - 'email': 'leachhumphrey@comtours.com', - 'age': 28, - }, { - 'id': 45, - 'firstName': 'Moss', - 'lastName': 'Baxter', - 'username': '@Fitzpatrick', - 'email': 'mossfitzpatrick@comtours.com', - 'age': 51, - }, { - 'id': 46, - 'firstName': 'Jeanne', - 'lastName': 'Cooke', - 'username': '@Ward', - 'email': 'jeanneward@comtours.com', - 'age': 59, - }, { - 'id': 47, - 'firstName': 'Wilma', - 'lastName': 'Briggs', - 'username': '@Kidd', - 'email': 'wilmakidd@comtours.com', - 'age': 53, - }, { - 'id': 48, - 'firstName': 'Beatrice', - 'lastName': 'Perry', - 'username': '@Gilbert', - 'email': 'beatricegilbert@comtours.com', - 'age': 39, - }, { - 'id': 49, - 'firstName': 'Whitaker', - 'lastName': 'Hyde', - 'username': '@Mcdonald', - 'email': 'whitakermcdonald@comtours.com', - 'age': 35, - }, { - 'id': 50, - 'firstName': 'Rebekah', - 'lastName': 'Duran', - 'username': '@Gross', - 'email': 'rebekahgross@comtours.com', - 'age': 40, - }, { - 'id': 51, - 'firstName': 'Earline', - 'lastName': 'Mayer', - 'username': '@Woodward', - 'email': 'earlinewoodward@comtours.com', - 'age': 52, - }, { - 'id': 52, - 'firstName': 'Moran', - 'lastName': 'Baxter', - 'username': '@Johns', - 'email': 'moranjohns@comtours.com', - 'age': 20, - }, { - 'id': 53, - 'firstName': 'Nanette', - 'lastName': 'Hubbard', - 'username': '@Cooke', - 'email': 'nanettecooke@comtours.com', - 'age': 55, - }, { - 'id': 54, - 'firstName': 'Dalton', - 'lastName': 'Walker', - 'username': '@Hendricks', - 'email': 'daltonhendricks@comtours.com', - 'age': 25, - }, { - 'id': 55, - 'firstName': 'Bennett', - 'lastName': 'Blake', - 'username': '@Pena', - 'email': 'bennettpena@comtours.com', - 'age': 13, - }, { - 'id': 56, - 'firstName': 'Kellie', - 'lastName': 'Horton', - 'username': '@Weiss', - 'email': 'kellieweiss@comtours.com', - 'age': 48, - }, { - 'id': 57, - 'firstName': 'Hobbs', - 'lastName': 'Talley', - 'username': '@Sanford', - 'email': 'hobbssanford@comtours.com', - 'age': 28, - }, { - 'id': 58, - 'firstName': 'Mcguire', - 'lastName': 'Donaldson', - 'username': '@Roman', - 'email': 'mcguireroman@comtours.com', - 'age': 38, - }, { - 'id': 59, - 'firstName': 'Rodriquez', - 'lastName': 'Saunders', - 'username': '@Harper', - 'email': 'rodriquezharper@comtours.com', - 'age': 20, - }, { - 'id': 60, - 'firstName': 'Lou', - 'lastName': 'Conner', - 'username': '@Sanchez', - 'email': 'lousanchez@comtours.com', - 'age': 16, + cedula: "25872062", + nombre: "Manuel", + apellido: "Rodriguez", + telefono: "04141633960" }]; getData() { diff --git a/src/app/pages/catalog/clients/clients.component.html b/src/app/pages/catalog/clients/clients.component.html new file mode 100644 index 0000000..05cd834 --- /dev/null +++ b/src/app/pages/catalog/clients/clients.component.html @@ -0,0 +1,10 @@ + + + Smart Table + + + + + + + diff --git a/src/app/pages/catalog/clients/clients.component.scss b/src/app/pages/catalog/clients/clients.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/pages/catalog/clients/clients.component.ts b/src/app/pages/catalog/clients/clients.component.ts new file mode 100644 index 0000000..9d8958c --- /dev/null +++ b/src/app/pages/catalog/clients/clients.component.ts @@ -0,0 +1,70 @@ +import { Component, OnInit } from '@angular/core'; +import { LocalDataSource } from 'ng2-smart-table'; +import { Clientmodel } from './clients.model'; +import { SmartTableService } from '../../../@core/data/smart-table.service'; +import { ClientService } from './clients.service'; + +@Component({ + selector: 'mac-clients', + templateUrl: './clients.component.html', + styles: ['./clients.component.scss'], + providers: [ClientService] +}) +export class ClientsComponent { + + settings = { + add: { + addButtonContent: '', + createButtonContent: '', + cancelButtonContent: '', + confirmCreate: true, + }, + edit: { + editButtonContent: '', + saveButtonContent: '', + cancelButtonContent: '', + }, + delete: { + deleteButtonContent: '', + confirmDelete: true, + }, + columns: { + cedula: { + title: 'Cédula', + type: 'string', + }, + nombre: { + title: 'Nombre', + type: 'string', + }, + apellido: { + title: 'Apellido', + type: 'string', + }, + telefono: { + title: 'Teléfono', + type: 'string', + }, + }, + }; + + source: LocalDataSource = new LocalDataSource(); + + constructor(private service: SmartTableService, + private clientService: ClientService) { + this.getClients() + } + + getClients(): void{ + this.clientService.getClients().subscribe(clients => + this.source.load(clients)) + } + + onDeleteConfirm(event): void { + if (window.confirm('Are you sure you want to delete?')) { + event.confirm.resolve(); + } else { + event.confirm.reject(); + } + } +} diff --git a/src/app/pages/catalog/clients/clients.model.ts b/src/app/pages/catalog/clients/clients.model.ts new file mode 100644 index 0000000..141849f --- /dev/null +++ b/src/app/pages/catalog/clients/clients.model.ts @@ -0,0 +1,6 @@ +export class Clientmodel { + cedula: number; + nombre: string; + apellido: string; + telefono: string +} \ No newline at end of file diff --git a/src/app/pages/catalog/clients/clients.service.ts b/src/app/pages/catalog/clients/clients.service.ts new file mode 100644 index 0000000..e4bdd73 --- /dev/null +++ b/src/app/pages/catalog/clients/clients.service.ts @@ -0,0 +1,33 @@ + +import { of, Observable } from 'rxjs'; +import { Injectable } from '@angular/core'; +import { Clientmodel } from './clients.model'; +import { catchError, tap } from 'rxjs/operators' +import { HttpHeaders, HttpClient } from '@angular/common/http' + +const httpOptions = { + headers: new HttpHeaders({'Content-Type': 'application/json'}) +} +@Injectable() +export class ClientService { + API_URL:string = "https://mactaquilla.herokuapp.com/taquilla-api" + + constructor( + private http: HttpClient + ){} + + getClients():Observable{ + let apiURL = `${this.API_URL}/cliente/` + return this.http.get(apiURL).pipe( + tap(clients => console.log("Fetched clients")), + catchError(this.handleError('getClients', [])) + ) + } + + private handleError(operation = 'operation', result?: T){ + return (error: any):Observable =>{ + console.log(error); + return of(result as T) + } + } +} diff --git a/src/app/pages/pages-menu.ts b/src/app/pages/pages-menu.ts index 34bd495..7f41816 100644 --- a/src/app/pages/pages-menu.ts +++ b/src/app/pages/pages-menu.ts @@ -48,6 +48,10 @@ export const MENU_ITEMS: NbMenuItem[] = [ title: 'Tabs', link: '/pages/ui-features/tabs', }, + { + title: 'Clients', + link: '/pages/clients' + } ], }, { diff --git a/src/app/pages/pages-routing.module.ts b/src/app/pages/pages-routing.module.ts index d714eca..c20591a 100644 --- a/src/app/pages/pages-routing.module.ts +++ b/src/app/pages/pages-routing.module.ts @@ -4,6 +4,7 @@ import { NgModule } from '@angular/core'; import { PagesComponent } from './pages.component'; import { DashboardComponent } from './dashboard/dashboard.component'; import { NotFoundComponent } from './miscellaneous/not-found/not-found.component'; +import { ClientsComponent } from './catalog/clients/clients.component'; const routes: Routes = [{ path: '', @@ -12,6 +13,9 @@ const routes: Routes = [{ path: 'dashboard', component: DashboardComponent, }, { + path: 'clients', + component: ClientsComponent + },{ path: 'ui-features', loadChildren: './ui-features/ui-features.module#UiFeaturesModule', }, { @@ -35,7 +39,7 @@ const routes: Routes = [{ }, { path: 'miscellaneous', loadChildren: './miscellaneous/miscellaneous.module#MiscellaneousModule', - }, { + },{ path: '', redirectTo: 'dashboard', pathMatch: 'full', diff --git a/src/app/pages/pages.module.ts b/src/app/pages/pages.module.ts index adcae4a..ea66507 100644 --- a/src/app/pages/pages.module.ts +++ b/src/app/pages/pages.module.ts @@ -5,9 +5,12 @@ import { DashboardModule } from './dashboard/dashboard.module'; import { PagesRoutingModule } from './pages-routing.module'; import { ThemeModule } from '../@theme/theme.module'; import { MiscellaneousModule } from './miscellaneous/miscellaneous.module'; +import { ClientsComponent } from './catalog/clients/clients.component'; +import { Ng2SmartTableModule } from 'ng2-smart-table' const PAGES_COMPONENTS = [ PagesComponent, + ClientsComponent ]; @NgModule({ @@ -16,6 +19,7 @@ const PAGES_COMPONENTS = [ ThemeModule, DashboardModule, MiscellaneousModule, + Ng2SmartTableModule ], declarations: [ ...PAGES_COMPONENTS, From d8a22f4444bda1a2509d6dcb08235043c4dde33a Mon Sep 17 00:00:00 2001 From: manuelinho96 Date: Fri, 5 Oct 2018 22:49:52 -0400 Subject: [PATCH 02/10] Added add clients. --- .../catalog/clients/clients.component.html | 3 ++- .../catalog/clients/clients.component.ts | 9 +++++++++ .../pages/catalog/clients/clients.service.ts | 19 +++++++++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/app/pages/catalog/clients/clients.component.html b/src/app/pages/catalog/clients/clients.component.html index 05cd834..411078a 100644 --- a/src/app/pages/catalog/clients/clients.component.html +++ b/src/app/pages/catalog/clients/clients.component.html @@ -4,7 +4,8 @@ - + diff --git a/src/app/pages/catalog/clients/clients.component.ts b/src/app/pages/catalog/clients/clients.component.ts index 9d8958c..4c4eeae 100644 --- a/src/app/pages/catalog/clients/clients.component.ts +++ b/src/app/pages/catalog/clients/clients.component.ts @@ -67,4 +67,13 @@ export class ClientsComponent { event.confirm.reject(); } } + + createClient(event): void{ + this.clientService.addClient(event.newData as Clientmodel).subscribe(client =>{ + if (client) { + event.confirm.resolve(event.newData) + } + } + ) + } } diff --git a/src/app/pages/catalog/clients/clients.service.ts b/src/app/pages/catalog/clients/clients.service.ts index e4bdd73..cab3383 100644 --- a/src/app/pages/catalog/clients/clients.service.ts +++ b/src/app/pages/catalog/clients/clients.service.ts @@ -24,9 +24,24 @@ export class ClientService { ) } + addClient(client: Clientmodel):Observable{ + let apiURL = `${this.API_URL}/cliente/` + return this.http.post(apiURL, client, httpOptions).pipe( + tap((client: Clientmodel) => console.log("Client added")), + catchError(this.handleError('addclient')) + ) + } + private handleError(operation = 'operation', result?: T){ - return (error: any):Observable =>{ - console.log(error); + return (error_object: any):Observable =>{ + console.log(error_object.error); + let error_message = "Your request return the following errors:\n" + for ( var key in error_object.error){ + if (error_object.error.hasOwnProperty(key)){ + error_message += key + ": " + error_object.error[key] + "\n" + } + } + alert(error_message) return of(result as T) } } From caeb90574e07afe2caf5b0b017d5cfdc711d7bec Mon Sep 17 00:00:00 2001 From: manuelinho96 Date: Fri, 5 Oct 2018 23:05:56 -0400 Subject: [PATCH 03/10] Added edit clients. But there's some problem with the edit endpoint. --- src/app/pages/catalog/clients/clients.component.html | 2 +- src/app/pages/catalog/clients/clients.component.ts | 12 ++++++++++++ src/app/pages/catalog/clients/clients.service.ts | 12 ++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/app/pages/catalog/clients/clients.component.html b/src/app/pages/catalog/clients/clients.component.html index 411078a..8a45d27 100644 --- a/src/app/pages/catalog/clients/clients.component.html +++ b/src/app/pages/catalog/clients/clients.component.html @@ -5,7 +5,7 @@ + (createConfirm)="createClient($event)" (editConfirm)="editClient($event)"> diff --git a/src/app/pages/catalog/clients/clients.component.ts b/src/app/pages/catalog/clients/clients.component.ts index 4c4eeae..735b1ed 100644 --- a/src/app/pages/catalog/clients/clients.component.ts +++ b/src/app/pages/catalog/clients/clients.component.ts @@ -23,6 +23,7 @@ export class ClientsComponent { editButtonContent: '', saveButtonContent: '', cancelButtonContent: '', + confirmSave: true }, delete: { deleteButtonContent: '', @@ -32,6 +33,7 @@ export class ClientsComponent { cedula: { title: 'Cédula', type: 'string', + editable: false }, nombre: { title: 'Nombre', @@ -68,6 +70,16 @@ export class ClientsComponent { } } + editClient(event):void { + console.log("alo") + this.clientService.updateClient(event.newData as Clientmodel).subscribe(client =>{ + if (client){ + event.confirm.resolve(event.newData) + } + } + ) + } + createClient(event): void{ this.clientService.addClient(event.newData as Clientmodel).subscribe(client =>{ if (client) { diff --git a/src/app/pages/catalog/clients/clients.service.ts b/src/app/pages/catalog/clients/clients.service.ts index cab3383..c44eda8 100644 --- a/src/app/pages/catalog/clients/clients.service.ts +++ b/src/app/pages/catalog/clients/clients.service.ts @@ -24,11 +24,19 @@ export class ClientService { ) } - addClient(client: Clientmodel):Observable{ + addClient(client: Clientmodel):Observable{ let apiURL = `${this.API_URL}/cliente/` return this.http.post(apiURL, client, httpOptions).pipe( tap((client: Clientmodel) => console.log("Client added")), - catchError(this.handleError('addclient')) + catchError(this.handleError('addClient')) + ) + } + + updateClient(client: Clientmodel):Observable{ + let apiURL = `${this.API_URL}/cliente/${client.cedula}/edit/` + return this.http.put(apiURL, client, httpOptions).pipe( + tap(_ => console.log(`update client ${client.cedula}`)), + catchError(this.handleError('updateClient')) ) } From f1d4a75df443ea74f1b6d6254400a393f540a4e1 Mon Sep 17 00:00:00 2001 From: manuelinho96 Date: Sat, 6 Oct 2018 10:07:06 -0400 Subject: [PATCH 04/10] Added delete client. --- src/app/pages/catalog/clients/clients.component.ts | 5 +++-- src/app/pages/catalog/clients/clients.service.ts | 10 +++++++++- src/app/pages/pages-routing.module.ts | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/app/pages/catalog/clients/clients.component.ts b/src/app/pages/catalog/clients/clients.component.ts index 735b1ed..3a40501 100644 --- a/src/app/pages/catalog/clients/clients.component.ts +++ b/src/app/pages/catalog/clients/clients.component.ts @@ -64,14 +64,15 @@ export class ClientsComponent { onDeleteConfirm(event): void { if (window.confirm('Are you sure you want to delete?')) { - event.confirm.resolve(); + this.clientService.deleteClient(event.data as Clientmodel).subscribe(client =>{ + this.getClients() + }) } else { event.confirm.reject(); } } editClient(event):void { - console.log("alo") this.clientService.updateClient(event.newData as Clientmodel).subscribe(client =>{ if (client){ event.confirm.resolve(event.newData) diff --git a/src/app/pages/catalog/clients/clients.service.ts b/src/app/pages/catalog/clients/clients.service.ts index c44eda8..1811db2 100644 --- a/src/app/pages/catalog/clients/clients.service.ts +++ b/src/app/pages/catalog/clients/clients.service.ts @@ -33,13 +33,21 @@ export class ClientService { } updateClient(client: Clientmodel):Observable{ - let apiURL = `${this.API_URL}/cliente/${client.cedula}/edit/` + let apiURL = `${this.API_URL}/cliente/${client.cedula}/edit` return this.http.put(apiURL, client, httpOptions).pipe( tap(_ => console.log(`update client ${client.cedula}`)), catchError(this.handleError('updateClient')) ) } + deleteClient(client: Clientmodel):Observable{ + let apiURL = `${this.API_URL}/cliente/${client.cedula}/delete` + return this.http.delete(apiURL, httpOptions).pipe( + tap(_ => console.log(`delete client ${client.cedula}`)), + catchError(this.handleError('deleteClient')) + ) + } + private handleError(operation = 'operation', result?: T){ return (error_object: any):Observable =>{ console.log(error_object.error); diff --git a/src/app/pages/pages-routing.module.ts b/src/app/pages/pages-routing.module.ts index c20591a..4deb75b 100644 --- a/src/app/pages/pages-routing.module.ts +++ b/src/app/pages/pages-routing.module.ts @@ -14,7 +14,7 @@ const routes: Routes = [{ component: DashboardComponent, }, { path: 'clients', - component: ClientsComponent + component: ClientsComponent, },{ path: 'ui-features', loadChildren: './ui-features/ui-features.module#UiFeaturesModule', From 6c3fc6870f8eda0f12c247ce25873d5144473232 Mon Sep 17 00:00:00 2001 From: manuelinho96 Date: Tue, 30 Oct 2018 18:13:10 -0400 Subject: [PATCH 05/10] Added modal form to add clients Now the form to add clients have all validation fields. Added toaster notification to pages.modules --- .../catalog/clients/clients.component.html | 91 ++++++++++++++++++- .../catalog/clients/clients.component.scss | 29 ++++++ .../catalog/clients/clients.component.ts | 70 ++++++++++---- .../pages/catalog/clients/clients.model.ts | 2 +- .../pages/catalog/clients/clients.service.ts | 18 +--- src/app/pages/pages-menu.ts | 13 ++- src/app/pages/pages.module.ts | 6 +- 7 files changed, 188 insertions(+), 41 deletions(-) diff --git a/src/app/pages/catalog/clients/clients.component.html b/src/app/pages/catalog/clients/clients.component.html index 8a45d27..7cd4148 100644 --- a/src/app/pages/catalog/clients/clients.component.html +++ b/src/app/pages/catalog/clients/clients.component.html @@ -4,8 +4,95 @@ - + + + + + + + +
+ + +
+
diff --git a/src/app/pages/catalog/clients/clients.component.scss b/src/app/pages/catalog/clients/clients.component.scss index e69de29..33a91ed 100644 --- a/src/app/pages/catalog/clients/clients.component.scss +++ b/src/app/pages/catalog/clients/clients.component.scss @@ -0,0 +1,29 @@ +@import '../../../@theme/styles/themes'; +@import '~bootstrap/scss/mixins/breakpoints'; +@import '~@nebular/theme/styles/global/bootstrap/breakpoints'; + +@include nb-install-component() { + + nb-card-footer { + padding-bottom: 0.25rem; + + button { + @include nb-ltr(margin, 0 1rem 1rem 0); + @include nb-rtl(margin, 0 0 1rem 1rem); + } + } + + /* stylelint-disable */ + toaster-container /deep/ { + #toast-container .toast-close-button { + right: 0; + } + } + /* stylelint-enable */ + + @include media-breakpoint-down(xs) { + .dropdown-toggle { + font-size: 0.75rem; + } + } +} \ No newline at end of file diff --git a/src/app/pages/catalog/clients/clients.component.ts b/src/app/pages/catalog/clients/clients.component.ts index 3a40501..ce2e7f3 100644 --- a/src/app/pages/catalog/clients/clients.component.ts +++ b/src/app/pages/catalog/clients/clients.component.ts @@ -3,6 +3,10 @@ import { LocalDataSource } from 'ng2-smart-table'; import { Clientmodel } from './clients.model'; import { SmartTableService } from '../../../@core/data/smart-table.service'; import { ClientService } from './clients.service'; +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { error } from '@angular/compiler/src/util'; +import { ToasterService, ToasterConfig, Toast, BodyOutputType } from 'angular2-toaster'; +import 'style-loader!angular2-toaster/toaster.css'; @Component({ selector: 'mac-clients', @@ -13,47 +17,55 @@ import { ClientService } from './clients.service'; export class ClientsComponent { settings = { + mode: 'external', + actions: { + position: 'right' + }, add: { - addButtonContent: '', - createButtonContent: '', - cancelButtonContent: '', - confirmCreate: true, + addButtonContent: '' }, edit: { - editButtonContent: '', - saveButtonContent: '', - cancelButtonContent: '', - confirmSave: true + editButtonContent: '' }, delete: { - deleteButtonContent: '', - confirmDelete: true, + deleteButtonContent: '' }, columns: { cedula: { - title: 'Cédula', + title: 'id', type: 'string', editable: false }, nombre: { - title: 'Nombre', + title: 'Name', type: 'string', }, apellido: { - title: 'Apellido', + title: 'Last name', type: 'string', }, telefono: { - title: 'Teléfono', + title: 'Phone', type: 'string', }, }, }; source: LocalDataSource = new LocalDataSource(); + clientemodel = new Clientmodel(); + activeModal: any; + config:ToasterConfig = new ToasterConfig({ + positionClass: 'toast-top-full-width', + timeout: 30000, + tapToDismiss: true, + showCloseButton: true + }); + constructor(private service: SmartTableService, - private clientService: ClientService) { + private clientService: ClientService, + private modalService: NgbModal, + private toasterService: ToasterService) { this.getClients() } @@ -81,12 +93,32 @@ export class ClientsComponent { ) } - createClient(event): void{ - this.clientService.addClient(event.newData as Clientmodel).subscribe(client =>{ - if (client) { - event.confirm.resolve(event.newData) + createClientModal(content): void{ + this.activeModal = this.modalService.open(content, { size: 'lg'}) + } + + createClient(): void{ + this.clientService.addClient(this.clientemodel).subscribe(client =>{ + if(client){ + if(!client.error){ + this.activeModal.dismiss() + this.getClients() + }else{ + this.toasterService.pop('warning', 'Your request has the following errors:\n', + this.getErrorMessage(client.error)) + } } } ) } + + getErrorMessage(object): string{ + let error_message = "" + for ( var key in object){ + if (object.hasOwnProperty(key)){ + error_message += object[key] + "\n" + } + } + return error_message + } } diff --git a/src/app/pages/catalog/clients/clients.model.ts b/src/app/pages/catalog/clients/clients.model.ts index 141849f..576f680 100644 --- a/src/app/pages/catalog/clients/clients.model.ts +++ b/src/app/pages/catalog/clients/clients.model.ts @@ -1,5 +1,5 @@ export class Clientmodel { - cedula: number; + cedula: string; nombre: string; apellido: string; telefono: string diff --git a/src/app/pages/catalog/clients/clients.service.ts b/src/app/pages/catalog/clients/clients.service.ts index 1811db2..eec7ff7 100644 --- a/src/app/pages/catalog/clients/clients.service.ts +++ b/src/app/pages/catalog/clients/clients.service.ts @@ -24,11 +24,11 @@ export class ClientService { ) } - addClient(client: Clientmodel):Observable{ + addClient(client: Clientmodel):Observable{ let apiURL = `${this.API_URL}/cliente/` return this.http.post(apiURL, client, httpOptions).pipe( tap((client: Clientmodel) => console.log("Client added")), - catchError(this.handleError('addClient')) + catchError(this.handleError('addClient')) ) } @@ -40,25 +40,17 @@ export class ClientService { ) } - deleteClient(client: Clientmodel):Observable{ + deleteClient(client: Clientmodel):Observable{ let apiURL = `${this.API_URL}/cliente/${client.cedula}/delete` return this.http.delete(apiURL, httpOptions).pipe( tap(_ => console.log(`delete client ${client.cedula}`)), - catchError(this.handleError('deleteClient')) + catchError(this.handleError('deleteClient')) ) } private handleError(operation = 'operation', result?: T){ return (error_object: any):Observable =>{ - console.log(error_object.error); - let error_message = "Your request return the following errors:\n" - for ( var key in error_object.error){ - if (error_object.error.hasOwnProperty(key)){ - error_message += key + ": " + error_object.error[key] + "\n" - } - } - alert(error_message) - return of(result as T) + return of(error_object) } } } diff --git a/src/app/pages/pages-menu.ts b/src/app/pages/pages-menu.ts index 7f41816..7d38bbd 100644 --- a/src/app/pages/pages-menu.ts +++ b/src/app/pages/pages-menu.ts @@ -11,6 +11,15 @@ export const MENU_ITEMS: NbMenuItem[] = [ title: 'FEATURES', group: true, }, + { + title: 'Catalog', + children: [ + { + title: 'Clients', + link: '/pages/clients' + } + ] + }, { title: 'UI Features', icon: 'nb-keypad', @@ -47,10 +56,6 @@ export const MENU_ITEMS: NbMenuItem[] = [ { title: 'Tabs', link: '/pages/ui-features/tabs', - }, - { - title: 'Clients', - link: '/pages/clients' } ], }, diff --git a/src/app/pages/pages.module.ts b/src/app/pages/pages.module.ts index ea66507..ea548eb 100644 --- a/src/app/pages/pages.module.ts +++ b/src/app/pages/pages.module.ts @@ -6,7 +6,8 @@ import { PagesRoutingModule } from './pages-routing.module'; import { ThemeModule } from '../@theme/theme.module'; import { MiscellaneousModule } from './miscellaneous/miscellaneous.module'; import { ClientsComponent } from './catalog/clients/clients.component'; -import { Ng2SmartTableModule } from 'ng2-smart-table' +import { Ng2SmartTableModule } from 'ng2-smart-table'; +import { ToasterModule } from 'angular2-toaster'; const PAGES_COMPONENTS = [ PagesComponent, @@ -19,7 +20,8 @@ const PAGES_COMPONENTS = [ ThemeModule, DashboardModule, MiscellaneousModule, - Ng2SmartTableModule + Ng2SmartTableModule, + ToasterModule.forRoot() ], declarations: [ ...PAGES_COMPONENTS, From f6b110b15038f82867b1358bf0cea771c7a4ef7d Mon Sep 17 00:00:00 2001 From: manuelinho96 Date: Tue, 30 Oct 2018 19:48:03 -0400 Subject: [PATCH 06/10] Added edit and delete client modals. --- .../catalog/clients/clients.component.html | 68 +++++++++++++------ .../catalog/clients/clients.component.ts | 65 +++++++++++++----- .../pages/catalog/clients/clients.service.ts | 4 +- 3 files changed, 96 insertions(+), 41 deletions(-) diff --git a/src/app/pages/catalog/clients/clients.component.html b/src/app/pages/catalog/clients/clients.component.html index 7cd4148..f4798d6 100644 --- a/src/app/pages/catalog/clients/clients.component.html +++ b/src/app/pages/catalog/clients/clients.component.html @@ -5,38 +5,43 @@ - + - - + + - -
+ +