import { Component, Injector, ViewEncapsulation, ViewChild, OnInit, Injectable } 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 } 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 { TicketNotesModalComponent } from './ticket-notes-modal.component'; 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'; @Component({ templateUrl: './view-support-ticket.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], styleUrls: ['./support-ticket.component.less'], }) @Injectable() export class ViewSupportTicketComponent extends AppComponentBase implements OnInit { @ViewChild('dataTable', { static: true }) dataTable: Table; @ViewChild('paginator', { static: true }) paginator: Paginator; @ViewChild('ticketNotesModal', {static: false}) ticketNotesModal: TicketNotesModalComponent; bsConfig: Partial; id: any; defaultDate = new Date(); //users: UserListDto = new UserListDto(); //contacts: ContactListDto= new ContactListDto(); incidentDate: any; dueDate:any; startDate: any; effortHour: any; incidentType: any; typesId: number; content: string; notes: any[] = []; users: UserListDto[] = []; ticketTypes: TicketTypeList[] = []; ticketStatuses: TicketStatusList[] = []; filesDropDown: AttachmentList[] = []; noteList: NoteList[] = []; ticketForEdit: any; today: any; uploadUrl: string; url: 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; rootCause: string; solution: string; environment: any; parentId: any; ticketStatus: any; selectedType: any; selectedTypeCode: string; selectedStatusCode: string; selectedAssignedId: any; selectedStatusId: any; issueOrBugCode = "ISSUEORBUG" typeTrigger: any hasDownloads: boolean = false; files: File[] = []; notesCreate: Array = []; assignedStatusId: any; attachMents: Array = []; priority: any; ticketType: string; version: any; releasedDate: any; constructor( injector: Injector, private _notifyService: NotifyService, private _userServiceProxy: UserServiceProxy, private _supportTicketServiceProxy: SupportTicketServiceProxy, private _supportTicketStatusServiceProxy: SupportTicketStatusServiceProxy, private _supportTicketTypeServiceProxy: SupportTicketTypeServiceProxy, private _tokenAuth: TokenAuthServiceProxy, private _activatedRoute: ActivatedRoute, private _httpClient: HttpClient, private _router: Router, private _location:Location, private route: ActivatedRoute, private _fileDownloadService: FileDownloadService, //private _orderAppService: OrderServiceProxy, //private _incidentTypesService: IncidentTypesServiceProxy, //private _orderIncidentsService : OrderIncidentsServiceProxy, private _appSessionService: AppSessionService ) { super(injector); this.uploadUrl = AppConsts.remoteServiceBaseUrl + '/DemoUiComponents/UploadFiles'; this.url = AppConsts.appBaseUrl; } ngOnInit(): void { let maxcount = 1000; var that = this; var re = "sandbox"; var str = this.url; this.route.paramMap.subscribe(params => { this.id = params.get("id") }); this.spinnerService.show() this._supportTicketServiceProxy.getTicketForEdit(this.id).subscribe((result) => { //this.ticketForEdit = result; this.description = result.description; this.rootCause = result.rootCause; this.solution = result.solution; this.parentId = result.parentId; this.shortDescription = result.shortDescription; this.environment = result.environment; this.ticketStatus = result.ticketStatus; this.selectedType = result.ticketTypeId; this.typeTrigger = result.ticketTypeId; this.selectedTypeCode = result.ticketType; this.selectedAssignedId = result.assignedToId; this.selectedStatusId = result.ticketStatusId; this.priority = result.priority; this.startDate = result.startDate; this.dueDate = result.dueDate; this.effortHour = result.effortHour + " hours"; this.assignedTo = result.assigned; this.selectedStatusCode = result.ticketStatusCode; this.version = result.versionString; this.releasedDate = result.versionDate; if(result.environment != undefined) { $('#environmentEditInput').val(result.environment); $('#environmentEditInput').trigger('change'); } else { if(str.search(re) == -1){ $('#environmentEditInput').val('Production'); $('#environmentEditInput').trigger('change'); } else { $('#environmentEditInput').val('Sandbox'); $('#environmentEditInput').trigger('change'); } } if(this.priority != undefined) { $('#priorityEditInput').val(that.priority); $('#priorityEditInput').trigger('change'); } this.spinnerService.hide() }); // $('.kt-select2').select2(); this.showAllUsers(); this.showAllTypes(); this.showAllStatus(); this.showAllFiles(this.id); this.showAllNotes(this.id); $('.kt-select2').select2(); //this.getTicketForEdit(this.id); this.today = new Date(); this.noteCreator = this._appSessionService.user.name + ' ' + this._appSessionService.user.surname; if(this._appSessionService.tenant != undefined) { this.tenancy = true; this.hideNew = true; } $('#assigned').change(function() { //that.selectedStatusId = that.assignedStatusId; $('#statusInput').val(that.assignedStatusId); $('#statusInput').trigger('change'); }); $('#typeInput').change(function() { that.typeTrigger = $("#typeInput :selected").val(); // console.log(that.typeTrigger) //that.selectedStatusId = that.assignedStatusId; // $('#statusInput').val(that.assignedStatusId); // $('#statusInput').trigger('change'); }); } 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/SupportTicket/DownloadFile?id=' + id, { responseType: 'blob', observe: 'response' }).pipe( map((res: any) => { return new Blob([res.body], { type: fileExtension }); }) ); } showAllFiles(id) : void { this._supportTicketServiceProxy.getFiles(id).subscribe((result) => { this.filesDropDown = result.items; if(this.filesDropDown.length != 0) { this.hasDownloads = true; } }); } showAllNotes(id) : void { this._supportTicketServiceProxy.getNotes(id).subscribe((result) => { this.noteList = result.items; }); } showAllTypes() : void { //this.active = true; this._supportTicketTypeServiceProxy.getTicketTypeList().subscribe((result) => { this.ticketTypes = result.items; }); } showAllStatus() : void { //this.active = true; this._supportTicketStatusServiceProxy.getTicketStatusList().subscribe((result) => { this.ticketStatuses = result.items; for (var i = 0, len = result.items.length; i < len; i++) { if(result.items[i].code == 'ASSIGNED') { this.assignedStatusId = result.items[i].id; } } }); } save(): void { //console.log(this.createOrderIncident); //alert('yow'); let that = this; //that.typesId = Number($('#selectedIncidentTypeId').val()); this.assignedToId = Number($('#assigned').val())==0 ? null : Number($('#assigned').val()); this.assignedTo = $('#assigned option:selected').text(); this.ticketStatusId = Number($('#statusInput').val()); this.ticketTypeId = Number($('#typeInput').val()); this.environment = $('#environmentEditInput').val(); this.priority = Number($('#priorityEditInput').val()); for (let item of this.data) { let a = new CreateAttachments({ fileName: item.fileName, base64EncodedData: item.base64EncodedData, ticketId: null, }); this.attachMents.push(a); } // let input = new UpdateTicketDto({ // id: this.id, // assignedToId: this.assignedToId, // ticketTypeId: this.ticketTypeId, // ticketStatusId: this.ticketStatusId, // shortDescription: this.shortDescription, // assigned: this.assignedTo, // description: this.description, // rootCause: this.rootCause, // solution: this.solution, // environment: this.environment, // priority: this.priority, // createAttachments: this.attachMents, // }); // console.log(input) // this._supportTicketServiceProxy.updateTicket( // input // ).pipe().subscribe(result => { // this.attachMents = []; // this.files = []; // this.data = []; // this.goBack(); // 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; 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] }); }; 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._supportTicketServiceProxy.deleteAttachment(id) .subscribe(() => { this.reloadPage(); this.notify.success(this.l('SuccessfullyDeleted')); }); } } ); } }