import { Component, OnInit } from '@angular/core'; import { DialogService, DynamicDialogConfig } from 'primeng/api'; import { DashboardServicesService } from '../../../shared/services/dashboard-services.service'; import { IDocumentStatus } from '../../../shared/core/IDocumentStatus'; import { IDocuments } from '../../../shared/core/IDocuments'; import { ActivityServicesService } from '../../../shared/services/activity-services.service'; @Component({ selector: 'app-add-document', templateUrl: './add-document.component.html', styleUrls: ['./add-document.component.css'], providers: [DashboardServicesService] }) export class AddDocumentComponent implements OnInit { // Document Types documentStatusLists: IDocumentStatus[] = []; // Selected Document Type selectedDocumentStatus: IDocumentStatus; // Attributes documentName: string = ''; additionalInformation: string = ''; // Upload document ulpoadDocument: string; // Upload File name uploadedFileName: string; // Documents documentsList: IDocuments[] = []; // Jobplanid JobPlanId: number; constructor(public dialogService: DialogService, public config: DynamicDialogConfig, private dashboardServicesService: DashboardServicesService, private activitiesService: ActivityServicesService ) { } ngOnInit() { // Get Document Types this.activitiesService.GetAllDocumentStatus().subscribe( data => { this.documentStatusLists = data; this.selectedDocumentStatus = this.documentStatusLists[0]; } ); // Assign Job plan id this.JobPlanId = this.config.data.JobPlanId; } // Popup Close closePopUp() { this.dialogService.dialogComponentRef.instance.close(); } // Save Document Save() { const selectedStaffID = 14; // Form data const frmData = new FormData(); if (this.ulpoadDocument != null && this.ulpoadDocument !== undefined) { frmData.append('fileUpload', this.ulpoadDocument); } const newDocument: IDocuments = { JobPlanId: this.JobPlanId, DocumentsTypeId: this.selectedDocumentStatus.DocumentsTypeId, StaffId: selectedStaffID, Name: this.documentName, Description: this.additionalInformation, DocumentId: 0, FileName: '', FilePath: '' }; this.activitiesService.InsertDocument(frmData, newDocument.JobPlanId, newDocument.DocumentsTypeId, newDocument.StaffId , newDocument.Name, newDocument.Description).subscribe( data => { this.closePopUp(); } ); } CloseDocument() { this.closePopUp(); } // Upload Image or document onChange(event: any): void { // console.log('Upload image') let files = event.target.files; if (files) { for (let file of files) { let reader = new FileReader(); reader.onload = (e: any) => { } reader.readAsDataURL(file); } } this.ulpoadDocument = event.target.files[0]; this.uploadedFileName = this.ulpoadDocument['name']; } }