import { Component, Injector, ViewEncapsulation, ViewChild, OnInit, Injectable, AfterViewInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { NotifyService } from '@abp/notify/notify.service'; import { AppComponentBase } from '@shared/common/app-component-base'; import { TokenAuthServiceProxy, OrderServiceProxy, IncidentTypesServiceProxy,OrderStatusAttachmentServiceProxy, OrderIncidentsServiceProxy, IncidentStatusServiceProxy, WillCallServiceServiceProxy, IncidentServiceProxy, OrderIncidentNotesForUpdate, OrderIncidentAttachmentForUpdate, CreateAttachmentIncidentInput, UpdateOrderIncidentInput, DriverIncidentsServiceProxy, EmployeeIncidentsServiceProxy } from '@shared/service-proxies/service-proxies'; import { UserServiceProxy, UserListDto, SupportTicketServiceProxy, SupportTicketStatusServiceProxy, SupportTicketTypeServiceProxy, TicketTypeList, TicketStatusList, CreateTicketDto, CreateAttachments, CreateNotes, AttachmentList, NoteList, GetTicketForEdit, UpdateTicketDto } from '@shared/service-proxies/service-proxies'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppSessionService } from '@shared/common/session/app-session.service'; import { Table } from 'primeng/components/table/table'; import { Paginator } from 'primeng/components/paginator/paginator'; import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'; import { FileDownloadService } from '@shared/utils/file-download.service'; import { EntityTypeHistoryModalComponent } from '@app/shared/common/entityHistory/entity-type-history-modal.component'; import * as _ from 'lodash'; import * as moment from 'moment'; import { Router } from '@angular/router'; import { BsDatepickerConfig } from 'ngx-bootstrap/datepicker'; import { HttpEventType, HttpClient } from '@angular/common/http'; import { FormControl } from '@angular/forms'; import {Location} from '@angular/common'; import { AppConsts } from '@shared/AppConsts'; import {FormBuilder, FormGroup, Validators} from "@angular/forms"; import { HttpHeaders } from '@angular/common/http'; import { map, finalize } from "rxjs/operators"; import { NgxDropzoneModule } from 'ngx-dropzone'; import { saveAs } from 'file-saver'; import { Observable } from 'rxjs'; import { Subject } from 'rxjs'; import { OrderAttachment } from '@app/sprintship/controller/order-detail/order-attachments.component'; import { CreateIncidentNotesModalComponent } from '@app/sprintship/incident/create-incidentnote-modal'; @Component({ templateUrl: './view-employee-incident.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], styleUrls: ['./employee-incident.component.less'], }) @Injectable() export class ViewEmployeeIncidentComponent extends AppComponentBase implements AfterViewInit { image: Array<{ src: string, caption: any, thumb: string }> = new Array(); @ViewChild('orderAttachment', { static: true }) orderAttachment: OrderAttachment; @ViewChild('dataTable', { static: true }) dataTable: Table; @ViewChild('paginator', { static: true }) paginator: Paginator; @ViewChild('createIncidentNotesModal', {static: false}) createIncidentNotesModal: CreateIncidentNotesModalComponent; bsConfig: Partial; id: any; defaultDate = new Date(); //users: UserListDto = new UserListDto(); //contacts: ContactListDto= new ContactListDto(); incidentDate: any; incidentType: any; dateIncident: string; typesId: number; content: string; notes: OrderIncidentNotesForUpdate[] = []; users: UserListDto[] = []; ticketTypes: TicketTypeList[] = []; ticketStatuses: TicketStatusList[] = []; filesDropDown: OrderIncidentAttachmentForUpdate[] = []; noteList: NoteList[] = []; ticketForEdit: any; today: any; uploadUrl: string; downloadUrl: string; uploadedFiles: any[] = []; data: any[] = []; noteCreator: string; tenancy: boolean = false; hideNew: boolean = false; showAlert: boolean = false; assignedToId: any; assignedTo: any; ticketTypeId: any; ticketStatusId: any; shortDescription: any; description: any; parentId: any; ticketStatus: any; selectedType: any; selectedAssignedId: any; selectedStatusId: any; hasDownloads: boolean = false; files: File[] = []; notesCreate: Array = []; attachMents: Array = []; incidentTypes: any; managers: any; statuses: any; typeId: any; statusId: any; managerId: any; routedriverString: any; orderId: any; idate: any; email:string; timeId: any; driverName: string; managerName: string; incidentTypeName: string; incidentStatusName: string; constructor( injector: Injector, private _httpClient: HttpClient, private route: ActivatedRoute, private _orderAppService: OrderServiceProxy, private _incidentTypesService: IncidentTypesServiceProxy, private _orderIncidentsService : OrderIncidentsServiceProxy, private _incidentStatus : IncidentStatusServiceProxy, private _appSessionService: AppSessionService, private _incidentAppService: IncidentServiceProxy, private _location: Location, private _driverIncidentsServiceSproxy: DriverIncidentsServiceProxy, private _employeeIncidentsServiceSproxy: EmployeeIncidentsServiceProxy ) { super(injector); this.uploadUrl = AppConsts.remoteServiceBaseUrl + '/DemoUiComponents/UploadFiles'; } ngOnInit(): void { $('.kt-select2').select2(); this.route.paramMap.subscribe(params => { this.id = params.get("id"); }); this.getAllData(); this.timeId = localStorage.getItem('timeZoneId'); moment.tz.setDefault(this.timeId); this._orderIncidentsService.getManagers() .subscribe(result=>{ this.managers = result; }) this._incidentTypesService.getAllIncidentType() .subscribe(result=>{ this.incidentTypes = result.items; }); this._incidentStatus.getAllIncidentStatus(undefined,undefined) .subscribe(result=>{ this.statuses = result; }) } ngAfterViewInit(): void { let maxcount = 1000; this.today = new Date(); this.noteCreator = this._appSessionService.user.name + ' ' + this._appSessionService.user.surname; } getAllData(){ this.spinnerService.show(); this._employeeIncidentsServiceSproxy.getEmployeeIncidentForEdit(this.id).subscribe((result) => { this.typeId = result.incidentTypeName; this.statusId = result.statusId; this.managerId = result.managerId; this.content = result.incidentContent; this.idate = result.incidentDate.tz(this.timeId); this.notes = result.notes; this.filesDropDown = result.attachments; this.email = result.email; this.driverName = result.employeeName; this.managerName = result.managerName; this.incidentStatusName = result.incidenStatusName; this.incidentTypeName = result.incidentTypeName; this.spinnerService.hide(); }); } showAllFilters(){ } incidentNotes(): void { this.createIncidentNotesModal.show(); } onSelect(event) { console.log(event); if(event.rejectedFiles.length != 0) { this.showAlert = true; } this.files.push(...event.addedFiles); let f = event.addedFiles; for (const file of f) { this.getData(file); } } closeAlert() { this.showAlert = false; } onRemove(event) { console.log(event.name); this.files.splice(this.files.indexOf(event), 1); //this.data.splice(this.data.indexOf(event), 1); _.remove(this.data, function (el) { return el.fileName === event.name; }); } goBack(){ this._location.back(); } showAllUsers() : void { //this.active = true; // this._supportTicketServiceProxy.getUsersForDropDown().subscribe((result) => { // this.users = result.items; // }); } downloadFile(id: number, fileName: string) { let checkFileType = fileName.split('.').pop(); var fileType; if (checkFileType == ".txt") { fileType = "text/plain"; } if (checkFileType == ".pdf") { fileType = "application/pdf"; } if (checkFileType == ".doc") { fileType = "application/vnd.ms-word"; } if (checkFileType == ".docx") { fileType = "application/vnd.ms-word"; } if (checkFileType == ".xls") { fileType = "application/vnd.ms-excel"; } if (checkFileType == ".png") { fileType = "image/png"; } if (checkFileType == ".jpg") { fileType = "image/jpeg"; } if (checkFileType == ".jpeg") { fileType = "image/jpeg"; } if (checkFileType == ".gif") { fileType = "image/gif"; } if (checkFileType == ".csv") { fileType = "text/csv"; } this.DownloadFile(fileName, fileType, id) .subscribe( success => { saveAs(success, fileName); }, err => { alert("Server error while downloading file."); } ); //console.log(this.downloadUrl); //return this._httpClient.get(`${AppConsts.remoteServiceBaseUrl}/api/services/app/SupportTicket/DownloadFile?id= ${id}`, { observe: 'response', responseType: 'blob' as 'json' }); //location.href = this.downloadUrl; //this.notify.success(`Downloaded successfully.`); //window.location = this.downloadUrl; } DownloadFile(filePath: string, fileType: string, id: number): Observable { let fileExtension = fileType; let input = filePath; return this._httpClient.get(AppConsts.remoteServiceBaseUrl + '/api/services/app/Incident/DownloadFile?id=' + id, { responseType: 'blob', observe: 'response' }).pipe( map((res: any) => { return new Blob([res.body], { type: fileExtension }); }) ); } save(): void { let that = this; that.typesId = Number($('#selectedIncidentTypeId').val()); let update = new UpdateOrderIncidentInput(); update.typeId = that.typesId; update.content = that.content; update.date = moment.tz(this.defaultDate, this.timeId); update.managerId = Number($('#Manager').val()); update.statusId= Number($('#Status').val()); update.incidentId = that.id; update.email = that.email; this._incidentAppService.updateOrderIncident(update).pipe().subscribe(result => { this.getAllData() this.notify.info(this.l('SavedSuccessfully')); }); } updateMyDate(newDate) { this.defaultDate = newDate; } ticketNotes(id): void { // this.ticketNotesModal.show(id, false); } onBeforeSend(event): void { event.xhr.setRequestHeader('Authorization', 'Bearer ' + abp.auth.getToken()); } getData(file) { var reader:any; let me = this; let data = new CreateAttachmentIncidentInput(); reader = new FileReader(); reader.readAsDataURL(file); //reader.onload = function () { //me.modelvalue = reader.result; //console.log(reader.result.toString().split(',')[1]); //}; reader.onload = function() { //me.modelvalue = reader.result.toString().split(',')[1]; //me.image.fileName = file.name; //me.image.base64EncodedData = me.modelvalue; me.data.push( { fileName: file.name, base64EncodedData: reader.result.toString().split(',')[1] }); data.base64EncodedData = reader.result.toString().split(',')[1]; data.fileName = file.name; data.incidentId = me.id; me._incidentAppService.createAttachement(data).subscribe(result=>{ me.getAllData(); }); }; reader.onerror = function (error) { console.log('Error: ', error); }; } reloadPage(): void { //this.paginator.changePage(this.paginator.getPage()); this.ngOnInit(); } deleteRow(id){ //this.notes.splice(index,1); this.message.confirm( '', '', (isConfirmed) => { if (isConfirmed) { // this._supportTicketServiceProxy.deleteNote(id) // .subscribe(() => { // this.reloadPage(); // this.notify.success(this.l('SuccessfullyDeleted')); // }); } } ); } deleteFile(id) { this.message.confirm( '', '', (isConfirmed) => { if (isConfirmed) { this._incidentAppService.deleteAttachment(id) .subscribe(() => { this.getAllData(); this.notify.success(this.l('SuccessfullyDeleted')); }); } } ); } attach(){ $('#FileDrop').click(); } }