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 } 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 { IncidentNotesModalComponent } from '../controller/create-incidents/incident-notes-modal.component'; import { CreateIncidentNotesModalComponent } from './create-incidentnote-modal'; import { OrderAttachment } from '../controller/order-detail/order-attachments.component'; @Component({ templateUrl: './view-incident.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], styleUrls: ['./incident.less'], }) @Injectable() export class ViewIncidentComponent 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; getManager:string; 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; complaint:string; investigation:string; resolution:string; source:any; sourceId:any; timeId: any; lab: boolean; accountDetails: any; phone: any; deleted:boolean = false; constructor( injector: Injector, private _notifyService: NotifyService, private _tokenAuth: TokenAuthServiceProxy, private _activatedRoute: ActivatedRoute, private _httpClient: HttpClient, private _router: Router, private route: ActivatedRoute, private _orderAppService: OrderServiceProxy, private _incidentTypesService: IncidentTypesServiceProxy, private _orderIncidentsService : OrderIncidentsServiceProxy, private _incidentStatus : IncidentStatusServiceProxy, private _willcallService: WillCallServiceServiceProxy, private _appSessionService: AppSessionService, private _incidentAppService: IncidentServiceProxy, private _location: Location, private _attachmentService: OrderStatusAttachmentServiceProxy ) { super(injector); this.uploadUrl = AppConsts.remoteServiceBaseUrl + '/DemoUiComponents/UploadFiles'; } ngOnInit(): void { this.lab = abp.features.isEnabled('App.RouteManagementFeauture.ClinicManagement'); $('.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; }) this._orderIncidentsService.getIncidentSource().pipe().subscribe(result => { this.source = 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._incidentAppService.getOrderIncidentForUpdate(this.id,undefined,undefined,undefined,undefined,undefined).subscribe((result) => { this.typeId = result.typeId; this.statusId = result.statusId; this.managerId = result.managerId; this.content = result.content; this.orderId = result.orderId; this.idate = result.incidentDate; this.notes = result.notes; this.filesDropDown = result.attachments; this.email = result.email this.complaint = result.complaint; this.resolution = result.resolution; this.investigation = result.investigation; this.sourceId = result.incidentSourceId; this.phone = result.phone; this.deleted = result.isDeleted; this.spinnerService.hide(); this._orderAppService.getRouteCodeDriver( result.orderId ).pipe().subscribe(result => { this.routedriverString = result; }); this._orderAppService.getAccountDetails( result.orderId ).pipe().subscribe(result => { if (this.lab) { if (result != null) { this.accountDetails = result.split("|")[0] + ' - ' + result.split("|")[1]; //this.phone = result.split("-")[2] == '' ? null : result.split("-")[2]; } } else { this.accountDetails = ''; //this.phone = '0'; } }); this._orderIncidentsService.getManagerByOrder( this.orderId ).pipe().subscribe(result => { this.getManager = result; console.log("getManager") console.log(this.getManager) }); }); } showAllFilters(){ } incidentNotes(): void { this.createIncidentNotesModal.show(); } onSelect(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) { 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(); } }