zgo/src/app/items/item-list/item-list.component.ts

250 lines
7.2 KiB
TypeScript
Raw Normal View History

2022-07-27 01:37:14 +00:00
import { Input, Inject, Component, OnInit } from '@angular/core';
import { MatDialog, MatDialogConfig} from '@angular/material/dialog';
import { faCartShopping } from '@fortawesome/free-solid-svg-icons';
2021-10-21 21:23:33 +00:00
import { Observable } from 'rxjs';
import { Item } from '../item.model';
import { Owner } from '../../owner.model';
import { FullnodeService } from '../../fullnode.service';
2021-10-21 21:23:33 +00:00
import { UserService } from '../../user.service';
import { ItemService } from '../items.service';
2021-10-27 12:59:43 +00:00
import { OrderService} from '../../order/order.service';
import { ItemCreateComponent } from '../item-create/item-create.component';
2022-07-27 01:37:14 +00:00
import { ItemEditComponent } from '../item-edit/item-edit.component';
2021-10-26 17:58:39 +00:00
import { ItemDeleteComponent } from '../item-delete/item-delete.component';
2021-10-26 20:07:51 +00:00
import { ItemAddComponent } from '../item-add/item-add.component';
2022-07-27 01:37:14 +00:00
import { NotifierService } from '../../notifier.service';
2021-10-21 21:23:33 +00:00
import { LanguageService } from '../../language.service';
import { LanguageData } from '../../language.model';
2021-10-21 21:23:33 +00:00
@Component({
selector: 'app-item-list',
templateUrl: './item-list.component.html',
styleUrls: ['./item-list.component.css']
2021-10-21 21:23:33 +00:00
})
export class ItemListComponent implements OnInit{
2022-07-20 14:25:51 +00:00
@Input() zecPrice: number;
2021-10-21 21:23:33 +00:00
public items: Item[] = [];
faCartShopping = faCartShopping;
2022-03-07 20:53:10 +00:00
owner: Owner = {
2021-11-22 20:37:45 +00:00
_id: '',
name: '',
address: '',
currency: 'usd',
tax: false,
taxValue: 0,
vat: false,
2022-01-17 20:49:08 +00:00
vatValue: 0,
2022-01-28 20:03:35 +00:00
first: '',
last: '',
2022-01-17 20:49:08 +00:00
email: '',
street: '',
city: '',
state: '',
postal: '',
phone: '',
2022-01-18 22:40:20 +00:00
paid: false,
2022-01-19 16:26:25 +00:00
website: '',
2022-03-07 17:14:29 +00:00
country: '',
2022-05-18 20:51:39 +00:00
zats: false,
invoices: false,
2022-07-14 16:11:04 +00:00
expiration: new Date(Date.now()).toISOString(),
2022-07-18 20:29:27 +00:00
payconf: false,
2022-08-31 13:56:06 +00:00
viewkey: '',
crmToken: ''
2021-11-22 20:37:45 +00:00
};
2021-10-21 21:23:33 +00:00
public ownerUpdate: Observable<Owner>;
public itemsUpdate: Observable<Item[]>;
//
// Language Support
//
vE = {
itemlistAvailItems : '',
itemlistListEmpty : '',
itemlistItemAdded : '',
itemlistItemUpdated : '',
itemlistItemDeleted : '',
itemlistNotifClose : '',
itemlistNotifSuccess : ''
}
//
// ------------------------------------------------------------
2021-10-21 21:23:33 +00:00
constructor(
public itemService: ItemService,
userService: UserService,
2021-10-27 12:59:43 +00:00
public orderService: OrderService,
public fullnodeService: FullnodeService,
2022-07-27 01:37:14 +00:00
private dialog: MatDialog,
private notifierService: NotifierService,
private languageService: LanguageService )
2022-07-27 01:37:14 +00:00
{
this.ownerUpdate = userService.ownerUpdate;
this.itemsUpdate = itemService.itemsUpdated;
this.ownerUpdate.subscribe((owner) => {
this.owner = owner;
itemService.getItems(this.owner.address);
this.itemsUpdate.subscribe((items) => {
this.items = items;
});
2021-10-21 21:23:33 +00:00
});
2022-07-27 01:37:14 +00:00
this.zecPrice = 1;
2021-10-21 21:23:33 +00:00
}
ngOnInit(){
this.chgUILanguage();
2021-10-28 18:22:54 +00:00
this.itemsUpdate.subscribe((items) => {
this.items = items;
});
2021-10-21 21:23:33 +00:00
}
openDialog(){
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
2021-10-26 15:09:34 +00:00
dialogConfig.data = {_id: '', name: '' , user: '', description: '', cost: 0}
const dialogRef = this.dialog.open(ItemCreateComponent, dialogConfig);
dialogRef.afterClosed().subscribe((val) => {
2021-10-26 15:09:34 +00:00
if(val != null) {
2022-05-18 20:51:39 +00:00
var item:Item = {_id: '', name: val.name, description: val.description, cost: val.cost, owner: this.owner.address};
2021-10-26 15:09:34 +00:00
this.itemService.addItem(item);
console.log('creando item y llamando a notifier >>>');
2022-07-27 01:37:14 +00:00
this.notifierService
.showNotification(this.vE.itemlistItemAdded ,
this.vE.itemlistNotifClose,
"success",
this.vE.itemlistNotifSuccess);
2021-10-26 15:09:34 +00:00
}
this.itemService.getItems(this.owner.address);
2021-10-28 18:22:54 +00:00
this.itemsUpdate.subscribe((items) => {
this.items = items;
});
2021-10-26 15:09:34 +00:00
});
}
edit(id: string) {
// console.log('Edit:', id);
2021-10-26 15:09:34 +00:00
const item = this.items.find(element => element._id == id);
// console.log(item);
2021-10-26 15:09:34 +00:00
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
dialogConfig.data = item;
console.log('Entrando a dialogo de edicion')
2022-07-27 01:37:14 +00:00
const dialogRef = this.dialog.open(ItemEditComponent, dialogConfig);
2021-10-26 15:09:34 +00:00
dialogRef.afterClosed().subscribe((val) => {
if (val != null) {
var editItem: Item = {
_id: val.id,
name: val.name,
description: val.description,
cost: val.cost,
2022-05-18 20:51:39 +00:00
owner: this.owner.address
2021-10-26 15:09:34 +00:00
};
console.log('Edit:', editItem);
console.log('itemlistItemUpdated = ' + this.vE.itemlistItemUpdated);
2021-10-26 15:09:34 +00:00
this.itemService.addItem(editItem).subscribe((response) => {
this.itemService.getItems(this.owner.address);
2022-07-27 01:37:14 +00:00
});
this.notifierService
.showNotification(this.vE.itemlistItemUpdated,
this.vE.itemlistNotifClose,
"success",
this.vE.itemlistNotifSuccess);
2021-10-26 15:09:34 +00:00
}
this.itemService.getItems(this.owner.address);
});
}
2021-10-26 17:58:39 +00:00
delete(id: string) {
//console.log('Edit:', id);
const item = this.items.find(element => element._id == id);
//console.log(item);
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
dialogConfig.data = item;
const dialogRef = this.dialog.open(ItemDeleteComponent, dialogConfig);
dialogRef.afterClosed().subscribe((val) => {
if (val != null) {
// console.log('Deleting', val);
2021-10-26 18:34:52 +00:00
this.itemService.deleteItem(val);
2021-10-28 18:22:54 +00:00
this.items = [];
this.notifierService
.showNotification(this.vE.itemlistItemDeleted,
this.vE.itemlistNotifClose,
"success",
this.vE.itemlistNotifSuccess);
2021-10-26 17:58:39 +00:00
}
this.itemService.getItems(this.owner.address);
2021-10-28 18:22:54 +00:00
this.itemsUpdate.subscribe((items) => {
this.items = items;
});
2021-10-26 17:58:39 +00:00
});
}
2021-10-26 20:07:51 +00:00
addToOrder(id: string) {
const item = this.items.find(element => element._id == id);
//console.log(item);
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
dialogConfig.data = {
qty: 1,
name: item!.name,
cost: item!.cost
};
const dialogRef = this.dialog.open(ItemAddComponent, dialogConfig);
dialogRef.afterClosed().subscribe((val) => {
if (val != null) {
console.log('Adding to order', val);
2021-10-27 12:59:43 +00:00
this.orderService.addToOrder(val);
2021-10-26 20:07:51 +00:00
}
this.itemService.getItems(this.owner.address);
});
}
2021-11-22 20:37:45 +00:00
getCurrency(){
return this.owner.currency.toUpperCase();
}
chgUILanguage(){
console.log('ITEMLIST.chgUILanguage Called ');
this.languageService.getViewElements('itemlist').subscribe(
response => {
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;
this.vE.itemlistItemAdded = response.data.itemlist_item_added;
this.vE.itemlistItemUpdated = response.data.itemlist_item_updated;
this.vE.itemlistItemDeleted = response.data.itemlist_item_deleted;
this.vE.itemlistNotifClose = response.data.itemlist_notif_close;
this.vE.itemlistNotifSuccess = response.data.itemlist_notif_success;
},
error => { console.log('Error >> ',error); }
);
}
2021-10-21 21:23:33 +00:00
}