Enhance item service for new API
This commit is contained in:
parent
3810900036
commit
c99908807f
2 changed files with 24 additions and 25 deletions
|
@ -119,7 +119,7 @@ export class ItemListComponent implements OnInit{
|
||||||
if(val != null) {
|
if(val != null) {
|
||||||
var item:Item = {_id: '', name: val.name, description: val.description, cost: val.cost, owner: this.owner.address};
|
var item:Item = {_id: '', name: val.name, description: val.description, cost: val.cost, owner: this.owner.address};
|
||||||
this.itemService.addItem(item);
|
this.itemService.addItem(item);
|
||||||
console.log('creando item y llamando a notifier >>>');
|
//console.log('creando item y llamando a notifier >>>');
|
||||||
this.notifierService
|
this.notifierService
|
||||||
.showNotification(this.vE.itemlistItemAdded ,
|
.showNotification(this.vE.itemlistItemAdded ,
|
||||||
this.vE.itemlistNotifClose,
|
this.vE.itemlistNotifClose,
|
||||||
|
@ -142,7 +142,7 @@ export class ItemListComponent implements OnInit{
|
||||||
dialogConfig.disableClose = true;
|
dialogConfig.disableClose = true;
|
||||||
dialogConfig.autoFocus = true;
|
dialogConfig.autoFocus = true;
|
||||||
dialogConfig.data = item;
|
dialogConfig.data = item;
|
||||||
console.log('Entrando a dialogo de edicion')
|
//console.log('Entrando a dialogo de edicion')
|
||||||
const dialogRef = this.dialog.open(ItemEditComponent, dialogConfig);
|
const dialogRef = this.dialog.open(ItemEditComponent, dialogConfig);
|
||||||
dialogRef.afterClosed().subscribe((val) => {
|
dialogRef.afterClosed().subscribe((val) => {
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
|
@ -153,8 +153,8 @@ export class ItemListComponent implements OnInit{
|
||||||
cost: val.cost,
|
cost: val.cost,
|
||||||
owner: this.owner.address
|
owner: this.owner.address
|
||||||
};
|
};
|
||||||
console.log('Edit:', editItem);
|
//console.log('Edit:', editItem);
|
||||||
console.log('itemlistItemUpdated = ' + this.vE.itemlistItemUpdated);
|
//console.log('itemlistItemUpdated = ' + this.vE.itemlistItemUpdated);
|
||||||
this.itemService.addItem(editItem).subscribe((response) => {
|
this.itemService.addItem(editItem).subscribe((response) => {
|
||||||
this.itemService.getItems(this.owner.address);
|
this.itemService.getItems(this.owner.address);
|
||||||
});
|
});
|
||||||
|
@ -213,7 +213,7 @@ export class ItemListComponent implements OnInit{
|
||||||
const dialogRef = this.dialog.open(ItemAddComponent, dialogConfig);
|
const dialogRef = this.dialog.open(ItemAddComponent, dialogConfig);
|
||||||
dialogRef.afterClosed().subscribe((val) => {
|
dialogRef.afterClosed().subscribe((val) => {
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
console.log('Adding to order', val);
|
//console.log('Adding to order', val);
|
||||||
this.orderService.addToOrder(val);
|
this.orderService.addToOrder(val);
|
||||||
}
|
}
|
||||||
this.itemService.getItems(this.owner.address);
|
this.itemService.getItems(this.owner.address);
|
||||||
|
@ -225,13 +225,13 @@ export class ItemListComponent implements OnInit{
|
||||||
}
|
}
|
||||||
|
|
||||||
chgUILanguage(){
|
chgUILanguage(){
|
||||||
console.log('ITEMLIST.chgUILanguage Called ');
|
//console.log('ITEMLIST.chgUILanguage Called ');
|
||||||
this.languageService.getViewElements('itemlist').subscribe(
|
this.languageService.getViewElements('itemlist').subscribe({next:
|
||||||
response => {
|
response => {
|
||||||
console.log('Received >> ', response );
|
//console.log('Received >> ', response );
|
||||||
console.log('Language Code : ', response.language);
|
//console.log('Language Code : ', response.language);
|
||||||
console.log('Component Name : ',response.component);
|
//console.log('Component Name : ',response.component);
|
||||||
console.log('Language data : ',response.data);
|
//console.log('Language data : ',response.data);
|
||||||
|
|
||||||
this.vE.itemlistListEmpty = response.data.itemlist_list_empty;
|
this.vE.itemlistListEmpty = response.data.itemlist_list_empty;
|
||||||
this.vE.itemlistAvailItems = response.data.itemlist_avail_items;
|
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.itemlistNotifClose = response.data.itemlist_notif_close;
|
||||||
this.vE.itemlistNotifSuccess = response.data.itemlist_notif_success;
|
this.vE.itemlistNotifSuccess = response.data.itemlist_notif_success;
|
||||||
},
|
},
|
||||||
|
error:
|
||||||
error => { console.log('Error >> ',error); }
|
error => { console.log('Error >> ',error); }
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Item } from './item.model';
|
import { Item } from './item.model';
|
||||||
import { Injectable } from '@angular/core';
|
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 { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
|
||||||
|
|
||||||
import { ConfigData } from '../configdata';
|
import { ConfigData } from '../configdata';
|
||||||
|
@ -10,27 +10,29 @@ var Buffer = require('buffer/').Buffer;
|
||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
|
|
||||||
export class ItemService{
|
export class ItemService{
|
||||||
// beUrl = 'https://test.zgo.cash/';
|
|
||||||
|
|
||||||
beUrl = ConfigData.Be_URL;
|
beUrl = ConfigData.Be_URL;
|
||||||
|
|
||||||
// console.log(ConfigData.Be_URL);
|
|
||||||
|
|
||||||
private dataStore: { items: Item[] } = { items: [] } ;
|
private dataStore: { items: Item[] } = { items: [] } ;
|
||||||
private _itemsUpdated: BehaviorSubject<Item[]> = new BehaviorSubject(this.dataStore.items);
|
private _itemsUpdated: BehaviorSubject<Item[]> = new BehaviorSubject(this.dataStore.items);
|
||||||
public readonly itemsUpdated: Observable<Item[]> = this._itemsUpdated.asObservable();
|
public readonly itemsUpdated: Observable<Item[]> = this._itemsUpdated.asObservable();
|
||||||
private address:string = '';
|
private address:string = '';
|
||||||
private reqHeaders: HttpHeaders;
|
private reqHeaders: HttpHeaders;
|
||||||
|
private session: null|string;
|
||||||
|
private params: HttpParams;
|
||||||
|
|
||||||
constructor(private http: HttpClient){
|
constructor(private http: HttpClient){
|
||||||
var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64');
|
var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64');
|
||||||
this.reqHeaders = new HttpHeaders().set('Authorization', auth);
|
this.reqHeaders = new HttpHeaders().set('Authorization', auth);
|
||||||
|
this.session = localStorage.getItem('s4z_token');
|
||||||
|
this.params = new HttpParams().append('session', this.session!);
|
||||||
}
|
}
|
||||||
|
|
||||||
getItems(addr: string){
|
getItems(addr: string){
|
||||||
this.address = addr;
|
this.address = addr;
|
||||||
const params = new HttpParams().append('address', addr);
|
const newParams = this.params.append('address', addr);
|
||||||
let obs = this.http.get<{message: string, items: any}>(this.beUrl+'api/items', { headers:this.reqHeaders, params: params, observe: 'response'});
|
let obs = this.http.get<{message: string, items: any}>(this.beUrl+'api/items', { headers:this.reqHeaders, params: newParams, observe: 'response'});
|
||||||
|
|
||||||
obs.subscribe((ItemDataResponse) => {
|
obs.subscribe((ItemDataResponse) => {
|
||||||
if (ItemDataResponse.status == 200 ) {
|
if (ItemDataResponse.status == 200 ) {
|
||||||
|
@ -39,7 +41,6 @@ export class ItemService{
|
||||||
} else {
|
} else {
|
||||||
this.dataStore.items = [];
|
this.dataStore.items = [];
|
||||||
this._itemsUpdated.next(Object.assign({},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) {
|
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, params: this.params });
|
||||||
let obs = this.http.post<{message: string}>(this.beUrl+'api/item', { payload: item }, { headers: this.reqHeaders });
|
|
||||||
|
|
||||||
obs.subscribe((ItemResponse) => {
|
obs.subscribe(() => {
|
||||||
// console.log('Item added');
|
|
||||||
this.getItems(this.address);
|
this.getItems(this.address);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -59,10 +58,9 @@ export class ItemService{
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteItem(id: string) {
|
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) => {
|
obs.subscribe(() => {
|
||||||
// console.log('Item deleted');
|
|
||||||
this.getItems(this.address);
|
this.getItems(this.address);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue