import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { StoreService } from '../store.services'; import { ItemDefiningViewModel, Attachments } from '../store-model'; import { NotificationService } from '../../../_services/notification.service'; import { LocalService } from '../../../_services/local.service'; @Component({ selector: 'app-item-dtl-view', templateUrl: './item-dtl-view.component.html', }) export class ItemDtlViewComponent implements OnInit { public itemDefining = new ItemDefiningViewModel(); public openDilogCat = false; public attachments = new Attachments(); public itemId: number; public attachmentList: any[]; public saving = false; public deletedDocId: number; public openDilogConfirmation = false; constructor(private activatedRoute: ActivatedRoute, public _notificationService: NotificationService, public _storeService: StoreService, private _localService: LocalService) { } ngOnInit() { this.activatedRoute.queryParams.subscribe(params => { const accId = params['id']; if (accId != null) this.itemId = accId; this.getItem(accId); }); this.attachments.FK_Item_Id = this.itemId; this.getAttachment(this.itemId) } public getItem(id: number) { this._storeService.getItemById(id).subscribe((res: any) => { if (res) { this.itemDefining = res.item; this.itemDefining.Exp_Date = new Date(res.item.Exp_Date) } }, err => { }); } public closeCat(status) { this.openDilogCat = false; this.openDilogConfirmation = false; } public saveCatlog() { if (this.attachments.file == null) { this._notificationService.notify("danger", "Select a file first!"); return; } this.saving = true; this._storeService.saveAttachment(this.attachments).subscribe((res: any) => { this._notificationService.notify("success", "Catlog Save Successfully"); this.attachments = new Attachments(); this.saving = false; this.getAttachment(this.itemId); this.closeCat('y'); }, err => { this._notificationService.notify("danger", err.error); this.saving = false; }) } public getFIle(event) { debugger; this.attachments.file = event.target.files[0]; } public getAttachment(e) { this._storeService.getAttachments(e, "item").subscribe((res: any) => { if (res) { this.attachmentList = res.res; console.log(res); } }, err => { }) } public RemoveDoc(r) { this.deletedDocId = r; this.openDilogConfirmation = true; } public ConfirmDelete() { this._storeService.RemoveDoc(this.deletedDocId).subscribe((res: any) => { this.deletedDocId = null; this.openDilogConfirmation = false; this._notificationService.notify("success", "Remove Successfully!"); this.getAttachment(this.itemId) }, err => { this._notificationService.notify("danger", err.error); }); } }