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, OrderIncidentsServiceProxy, IncidentStatusServiceProxy, WillCallServiceServiceProxy, IncidentServiceProxy, OrderIncidentNotesForUpdate, OrderIncidentAttachmentForUpdate, CreateAttachmentIncidentInput, UpdateOrderIncidentInput, OrderIncidentAttachment, GetAllForLookupTableInput } 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 } 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 { FeatureCheckerService } from 'abp-ng2-module/dist/src/features/feature-checker.service'; import { CommonLookupModalComponent } from '@app/shared/common/lookup/common-lookup-modal.component'; @Component({ templateUrl: './update-incident.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], styleUrls: ['./incident.less'], }) @Injectable() export class UpdateOrderIncidentComponent extends AppComponentBase implements AfterViewInit { @ViewChild('dataTable', { static: true }) dataTable: Table; @ViewChild('paginator', { static: true }) paginator: Paginator; @ViewChild('createIncidentNotesModal', {static: false}) createIncidentNotesModal: CreateIncidentNotesModalComponent; @ViewChild('incidentTypesList', { static: true}) incidentTypesList: CommonLookupModalComponent; @ViewChild('managerList', { static: true}) managerList: CommonLookupModalComponent; @ViewChild('statusList', { static: true}) statusList: CommonLookupModalComponent; @ViewChild('sourceList', { static: true}) sourceList: CommonLookupModalComponent; bsConfig: Partial; id: any; defaultDate = new Date(); //users: UserListDto = new UserListDto(); //contacts: ContactListDto= new ContactListDto(); incidentDate: any; incidentType: any; 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; getManager:string; 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; complaint:string; resolution:string; investigation:string; //sourceId:any; source:any; accountDetails: any; phone: any = ""; lab: boolean; rows: number; incidentId: any; txtIncidentTypeFilter: any; selectedIncidentType: any; incidentTypeId: any; txtManagerFilter: any; selectedManager: any; managerId: any; txtIncidentStatusFilter: any; selectedIncidentStatus: any; statusId: any; txtSourceFilter: any; selectedSource: any; sourceId: any; deleted:boolean = false; constructor( injector: Injector, private _notifyService: NotifyService, private _tokenAuth: TokenAuthServiceProxy, private route: ActivatedRoute, private router: Router, private _httpClient: HttpClient, 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 _featureCheckerService: FeatureCheckerService, ) { super(injector); this.uploadUrl = AppConsts.remoteServiceBaseUrl + '/DemoUiComponents/UploadFiles'; } ngOnInit(): void { this.lab = abp.features.isEnabled('App.RouteManagementFeauture.ClinicManagement'); this.route.paramMap.subscribe(params => { this.id = params.get("id"); }); this.getAllData(); // 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; // }); this.rows = this.lab ? 40 : 30; this.timeId = localStorage.getItem('timeZoneId'); moment.tz.setDefault(this.timeId); $(".kt-select2").select2(); } ngAfterViewInit(): void { let maxcount = 1000; this.today = new Date(); this.noteCreator = this._appSessionService.user.name + ' ' + this._appSessionService.user.surname; } refreshNote(){ this._incidentAppService.getOrderIncidentForUpdate(this.id,undefined,undefined,undefined,undefined,undefined).subscribe((result) => { this.notes = result.notes; }); } 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 }); }) ); } private validateNum(event: KeyboardEvent): void { const pattern = /[0-9\+\-\(\)\ ]/; let inputChar = String.fromCharCode(event.charCode); if (event.keyCode != 8 && !pattern.test(inputChar)) { event.preventDefault(); } } save(): void { let that = this; let update = new UpdateOrderIncidentInput(); update.typeId = this.incidentTypeId; update.content = that.content; update.date = moment.tz(this.defaultDate, this.timeId); update.managerId = this.managerId; update.statusId= this.statusId; update.incidentId = that.id; update.email = that.email; update.complaint = that.complaint; update.resolution = that.resolution; update.investigation = that.investigation; update.incidentSourceId = this.sourceId; update.phone = that.phone; this._incidentAppService.updateOrderIncident(update).pipe().subscribe(result => { this.getAllData() this.notify.info(this.l('SavedSuccessfully')); this.spinnerService.hide(); this.goBack(); }); } updateMyDate(newDate) { this.defaultDate = newDate; } ticketNotes(id): void { // this.ticketNotesModal.show(id, false); } onBeforeSend(event): void { event.xhr.setRequestHeader('Authorization', 'Bearer ' + abp.auth.getToken()); } getAttachmentsRefresh(){ this.spinnerService.show(); this._incidentAppService.getOrderIncidentForUpdate(this.id,undefined,undefined,undefined,undefined,undefined).subscribe((result) => { this.statusId = result.statusId; this.orderId = result.orderId; this.idate = result.incidentDate.tz(this.timeId); this.notes = result.notes; this.filesDropDown = result.attachments; this.sourceId = result.incidentSourceId; this.spinnerService.hide(); this._orderAppService.getRouteCodeDriver( result.orderId ).pipe().subscribe(result => { this.routedriverString = result; }); this._orderIncidentsService.getManagerByOrder( result.orderId ).pipe().subscribe(result => { this.getManager = result; }); }); } getAllData(){ this.spinnerService.show(); this._incidentAppService.getOrderIncidentForUpdate(this.id,undefined,undefined,undefined,undefined,undefined).subscribe((result) => { let that = this; if(result == undefined || result == null || result.incidentId == undefined){ this.message.error('','Incident is not found').then(function(){ that.router.navigateByUrl('/'); }) } if(result.incidentId != undefined){ this.incidentId = result.incidentId this.incidentTypeId = result.typeId; this.statusId = result.statusId; this.managerId = (result.managerId == 0)? null: result.managerId; this.content = result.content; this.orderId = result.orderId; this.idate = result.incidentDate.tz(this.timeId); 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.deleted = result.isDeleted; this.phone = result.phone; this.spinnerService.hide(); if(this.deleted){ var url = "/app/sprintship/view-incidents"; if(this.id != null){ var myurl = `${url}/${this.id}`; this.router.navigateByUrl(myurl); } } this._orderAppService.getRouteCodeDriver( result.orderId ).pipe().subscribe(result => { this.routedriverString = result; }); this._orderAppService.getAccountDetails( this.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( result.orderId ).pipe().subscribe(result => { this.getManager = result; }); this.getIncidentTypesInit(); this.getManagersInit(); this.getSourceInit(); this.getIncidentStatusInit(); } }); } getData(file) { var reader:any; let me = this; let data = new CreateAttachmentIncidentInput(); reader = new FileReader(); reader.readAsDataURL(file); reader.onload = function() { 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.incidentId; me._incidentAppService.createAttachement(data).subscribe(result=>{ me.getAttachmentsRefresh(); }); }; reader.onerror = function (error) { console.log('Error: ', error); }; } attach(){ $('#FileDrop').click(); this.getData('#FileDrop'); } 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.getAttachmentsRefresh(); this.notify.success(this.l('SuccessfullyDeleted')); }); } } ); } getIncidentTypesInit() { if (this.incidentTypeId != null) { let input = new GetAllForLookupTableInput(); input.id = this.incidentTypeId; var incidentTpyes = this._incidentTypesService.incidentTypePagedList(input); incidentTpyes.subscribe(result => { var selectedIncidentTypes = result.items[0]; this.selectIncidentType(selectedIncidentTypes); }); } this.incidentTypesList.configure({ title: this.l('Select Incident Type'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?: number) => { let input = new GetAllForLookupTableInput(); input.filter = filter; input.skipCount = skipCount; input.maxResultCount = maxResultCount; return this._incidentTypesService.incidentTypePagedList(input); } }); } getIncidentTypesList(filter : any) { this.incidentTypesList.show(); this.incidentTypesList.filterText = filter; } clearIncidentTypesList() { this.txtIncidentTypeFilter = ''; this.incidentTypeId = null; } selectIncidentType(item: any) { this.incidentTypeId = item.value; this.txtIncidentTypeFilter = item.name; } getManagersInit() { if (this.managerId != null) { let input = new GetAllForLookupTableInput(); input.id = this.managerId; var managers = this._orderIncidentsService.managersPagedList(input); managers.subscribe(result => { var selectedManager = result.items[0]; this.selectManager(selectedManager); }); } this.managerList.configure({ title: this.l('Select Assignee'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?: number) => { let input = new GetAllForLookupTableInput(); input.filter = filter; input.skipCount = skipCount; input.maxResultCount = maxResultCount; return this._orderIncidentsService.managersPagedList(input); } }); } getManagerList(filter : any) { this.managerList.show(); this.managerList.filterText = filter; } clearManagerList(){ this.txtManagerFilter = ''; this.managerId = null; } selectManager(item) { this.managerId = item.value; this.txtManagerFilter = item.name; } getIncidentStatusInit() { if (this.statusId != null) { let input = new GetAllForLookupTableInput(); input.id = this.statusId; var statuses = this._incidentStatus.incidentStatusPagedList(input); statuses.subscribe(result => { var selectedStatus = result.items[0]; this.selectIncidentStatus(selectedStatus); }); } this.statusList.configure({ title: this.l('Select Status'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?: number) => { let input = new GetAllForLookupTableInput(); input.filter = filter; input.skipCount = skipCount; input.maxResultCount = maxResultCount; return this._incidentStatus.incidentStatusPagedList(input); } }); } getIncidentStatusList(filter : any) { this.statusList.show(); this.statusList.filterText = filter; } clearIncidentStatusList(){ this.txtIncidentStatusFilter = ''; this.statusId = null; } selectIncidentStatus(item) { this.statusId = item.value; this.txtIncidentStatusFilter = item.name; } getSourceInit() { if (this.sourceId != null) { let input = new GetAllForLookupTableInput(); input.id = this.sourceId var sources = this._orderIncidentsService.incidentSourcePagedList(input); sources.subscribe(result => { var selectedSource = result.items[0]; this.selectSource(selectedSource); }); } this.sourceList.configure({ title: this.l('Select Fault Type'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?: number) => { let input = new GetAllForLookupTableInput(); input.filter = filter; input.skipCount = skipCount; input.maxResultCount = maxResultCount; return this._orderIncidentsService.incidentSourcePagedList(input); } }); } getSourceList(filter : any) { this.sourceList.show(); this.sourceList.filterText = filter; } clearSourceList(){ this.txtSourceFilter = ''; this.sourceId = null; } selectSource(item) { this.sourceId = item.value; this.txtSourceFilter = item.name; } }