diff --git a/src/app/items/item-list/item-list.component.ts b/src/app/items/item-list/item-list.component.ts index a67f236..5888973 100644 --- a/src/app/items/item-list/item-list.component.ts +++ b/src/app/items/item-list/item-list.component.ts @@ -119,7 +119,7 @@ export class ItemListComponent implements OnInit{ if(val != null) { var item:Item = {_id: '', name: val.name, description: val.description, cost: val.cost, owner: this.owner.address}; this.itemService.addItem(item); - console.log('creando item y llamando a notifier >>>'); + //console.log('creando item y llamando a notifier >>>'); this.notifierService .showNotification(this.vE.itemlistItemAdded , this.vE.itemlistNotifClose, @@ -142,7 +142,7 @@ export class ItemListComponent implements OnInit{ dialogConfig.disableClose = true; dialogConfig.autoFocus = true; dialogConfig.data = item; - console.log('Entrando a dialogo de edicion') + //console.log('Entrando a dialogo de edicion') const dialogRef = this.dialog.open(ItemEditComponent, dialogConfig); dialogRef.afterClosed().subscribe((val) => { if (val != null) { @@ -153,8 +153,8 @@ export class ItemListComponent implements OnInit{ cost: val.cost, owner: this.owner.address }; - console.log('Edit:', editItem); - console.log('itemlistItemUpdated = ' + this.vE.itemlistItemUpdated); + //console.log('Edit:', editItem); + //console.log('itemlistItemUpdated = ' + this.vE.itemlistItemUpdated); this.itemService.addItem(editItem).subscribe((response) => { this.itemService.getItems(this.owner.address); }); @@ -213,7 +213,7 @@ export class ItemListComponent implements OnInit{ const dialogRef = this.dialog.open(ItemAddComponent, dialogConfig); dialogRef.afterClosed().subscribe((val) => { if (val != null) { - console.log('Adding to order', val); + //console.log('Adding to order', val); this.orderService.addToOrder(val); } this.itemService.getItems(this.owner.address); @@ -225,13 +225,13 @@ export class ItemListComponent implements OnInit{ } chgUILanguage(){ - console.log('ITEMLIST.chgUILanguage Called '); - this.languageService.getViewElements('itemlist').subscribe( + //console.log('ITEMLIST.chgUILanguage Called '); + this.languageService.getViewElements('itemlist').subscribe({next: response => { - console.log('Received >> ', response ); - console.log('Language Code : ', response.language); - console.log('Component Name : ',response.component); - console.log('Language data : ',response.data); + //console.log('Received >> ', response ); + //console.log('Language Code : ', response.language); + //console.log('Component Name : ',response.component); + //console.log('Language data : ',response.data); this.vE.itemlistListEmpty = response.data.itemlist_list_empty; this.vE.itemlistAvailItems = response.data.itemlist_avail_items; @@ -241,8 +241,9 @@ export class ItemListComponent implements OnInit{ this.vE.itemlistNotifClose = response.data.itemlist_notif_close; this.vE.itemlistNotifSuccess = response.data.itemlist_notif_success; }, + error: error => { console.log('Error >> ',error); } - ); + }); } } diff --git a/src/app/items/items.service.ts b/src/app/items/items.service.ts index c97e21f..8a20019 100644 --- a/src/app/items/items.service.ts +++ b/src/app/items/items.service.ts @@ -1,6 +1,6 @@ import { Item } from './item.model'; import { Injectable } from '@angular/core'; -import { Subject, BehaviorSubject, Observable } from 'rxjs'; +import { BehaviorSubject, Observable } from 'rxjs'; import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http'; import { ConfigData } from '../configdata'; @@ -10,27 +10,29 @@ var Buffer = require('buffer/').Buffer; @Injectable({providedIn: 'root'}) export class ItemService{ -// beUrl = 'https://test.zgo.cash/'; beUrl = ConfigData.Be_URL; -// console.log(ConfigData.Be_URL); private dataStore: { items: Item[] } = { items: [] } ; private _itemsUpdated: BehaviorSubject = new BehaviorSubject(this.dataStore.items); public readonly itemsUpdated: Observable = this._itemsUpdated.asObservable(); private address:string = ''; private reqHeaders: HttpHeaders; + private session: null|string; + private params: HttpParams; constructor(private http: HttpClient){ var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64'); this.reqHeaders = new HttpHeaders().set('Authorization', auth); + this.session = localStorage.getItem('s4z_token'); + this.params = new HttpParams().append('session', this.session!); } getItems(addr: string){ this.address = addr; - const params = new HttpParams().append('address', addr); - let obs = this.http.get<{message: string, items: any}>(this.beUrl+'api/items', { headers:this.reqHeaders, params: params, observe: 'response'}); + const newParams = this.params.append('address', addr); + let obs = this.http.get<{message: string, items: any}>(this.beUrl+'api/items', { headers:this.reqHeaders, params: newParams, observe: 'response'}); obs.subscribe((ItemDataResponse) => { if (ItemDataResponse.status == 200 ) { @@ -39,7 +41,6 @@ export class ItemService{ } else { this.dataStore.items = []; this._itemsUpdated.next(Object.assign({},this.dataStore).items); -// console.log('No items found'); } }); @@ -47,11 +48,9 @@ export class ItemService{ } addItem(item: Item) { - //const params = new HttpParams().append('item', JSON.stringify(item)); - let obs = this.http.post<{message: string}>(this.beUrl+'api/item', { payload: item }, { headers: this.reqHeaders }); + let obs = this.http.post<{message: string}>(this.beUrl+'api/item', { payload: item }, { headers: this.reqHeaders, params: this.params }); - obs.subscribe((ItemResponse) => { -// console.log('Item added'); + obs.subscribe(() => { this.getItems(this.address); }); @@ -59,10 +58,9 @@ export class ItemService{ } deleteItem(id: string) { - let obs = this.http.delete<{message: string}>(this.beUrl+'api/item/'+id, { headers: this.reqHeaders }); + let obs = this.http.delete<{message: string}>(this.beUrl+'api/item/'+id, { headers: this.reqHeaders, params: this.params }); - obs.subscribe((ItemResponse) => { -// console.log('Item deleted'); + obs.subscribe(() => { this.getItems(this.address); });