import { Component, Injector, ViewEncapsulation, ViewChild, AfterViewInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { SupportTicketServiceProxy, SupportTicketStatusServiceProxy, SupportTicketTypeServiceProxy, TicketTypeList, TicketStatusList, TenantListDropDown, TicketKPI} from '@shared/service-proxies/service-proxies'; import { NotifyService } from '@abp/notify/notify.service'; import { AppComponentBase } from '@shared/common/app-component-base'; import { TokenAuthServiceProxy } from '@shared/service-proxies/service-proxies'; //import { CreateOrEditRouteTypeModalComponent } from './create-or-edit-routeType-modal.component'; //import { ViewRouteTypeModalComponent } from './view-routeType-modal.component'; import { appModuleAnimation } from '@shared/animations/routerTransition'; 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 { HttpClient, HttpEventType, } from '@angular/common/http'; import { Router } from '@angular/router'; //import { EntityTypeHistoryModalComponent } from '@app/shared/common/entityHistory/entity-type-history-modal.component'; import * as _ from 'lodash'; import * as moment from 'moment'; import { AppSessionService } from '@shared/common/session/app-session.service'; import { HttpHeaders } from '@angular/common/http'; import { map } from "rxjs/operators"; import { saveAs } from 'file-saver'; import { Observable } from 'rxjs'; import { Subject } from 'rxjs'; import { AppConsts } from '@shared/AppConsts'; import { TicketNotesModalComponent } from './ticket-notes-modal.component'; import { AssignModalComponent } from './assign-modal.component'; @Component({ templateUrl: './support-ticket.component.html', styleUrls: ['./support-ticket.component.less'], encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()] }) export class SupportTicketsComponent extends AppComponentBase { //@ViewChild('createOrEditRouteTypeModal', { static: true }) createOrEditRouteTypeModal: CreateOrEditRouteTypeModalComponent; //@ViewChild('viewRouteTypeModalComponent', { static: true }) viewRouteTypeModal: ViewRouteTypeModalComponent; //@ViewChild('entityTypeHistoryModal', { static: true }) entityTypeHistoryModal: EntityTypeHistoryModalComponent; @ViewChild('dataTable', { static: true }) dataTable: Table; @ViewChild('paginator', { static: true }) paginator: Paginator; @ViewChild('ticketNotesModal', {static: false}) ticketNotesModal: TicketNotesModalComponent; @ViewChild('assignModal', {static: false}) assignModal: AssignModalComponent; advancedFiltersAreShown = false; filterText = ''; assignedToFilter = ''; statusFilter = ''; typeFilter = ''; createdBy = ''; tenant: any; update: Array = []; ticketTypes: TicketTypeList[] = []; ticketStatuses: TicketStatusList[] = []; tenantList: TenantListDropDown[] = []; tenancy: boolean = false; totalTicket: any totalNewTicket: any; totalAssignedTicket: any; totalClosedTicket: any; totalTodayClosedTicket: any; totalFeatureChangeTicket: any; totalBugTicket: any; totalNewFeatureTicket: any; totalMyTicket: any; totalMyCreateTicket: any; dateFrom: any; dateTo: any; //public dateRange: moment.Moment[] = [moment().startOf('day'), moment().endOf('day')]; constructor( injector: Injector, private _supportTicketsServiceProxy: SupportTicketServiceProxy, private _notifyService: NotifyService, private _tokenAuth: TokenAuthServiceProxy, private _activatedRoute: ActivatedRoute, private _fileDownloadService: FileDownloadService, private _supportTicketStatusServiceProxy: SupportTicketStatusServiceProxy, private _supportTicketTypeServiceProxy: SupportTicketTypeServiceProxy, private _httpClient: HttpClient, private _router: Router, private _appSessionService: AppSessionService ) { super(injector); } ngOnInit(): void { var that = this; //this.entityHistoryEnabled = this.setIsEntityHistoryEnabled(); $('.kt-select2').select2(); this.showAllTypes(); this.showAllStatus(); this.showAllTenant(); /*$('#status').on('select2:select', function (e) { that.getSupportTickets(); }); $('#type').on('select2:select', function (e) { that.getSupportTickets(); }); $('#tenant').on('select2:select', function (e) { that.getSupportTickets(); });*/ if(this._appSessionService.tenant != undefined) { this.tenancy = true; } } ngAfterViewInit(): void { this.primengTableHelper.adjustScroll(this.dataTable); } getDate(event) : void { let from = new Date(event[0]).toLocaleDateString() let to = new Date(event[1]).toLocaleDateString() console.log(from); this.dateFrom = from; this.dateTo = to; //this.getSupportTickets(); } getKpi() : void { this._supportTicketsServiceProxy.getTicketForKPI( ).subscribe(result => { this.totalTicket = result.totalTicket; this.totalNewTicket = result.totalNewTicket; this.totalAssignedTicket = result.totalAssignedTicket; this.totalClosedTicket = result.totalCloseTicket; this.totalTodayClosedTicket = result.totalCloseTicketToday; this.totalFeatureChangeTicket = result.totalFeatureChangeTicket; this.totalBugTicket = result.totalIssueOrBugTicket; this.totalNewFeatureTicket = result.totalNewFeatureTicket; this.totalMyTicket = result.totalMyTicket; this.totalMyCreateTicket = result.totalMyCreateTicket; }); } getSupportTickets(event?: LazyLoadEvent) { //if (this.primengTableHelper.shouldResetPaging(event)) { //this.paginator.changePage(0); //return; //} this.getKpi(); //this.primengTableHelper.showLoadingIndicator(); this.statusFilter = (document.getElementById('status')).value; this.typeFilter = (document.getElementById('type')).value; this.tenant = (document.getElementById('tenant')).value; this.spinnerService.show(); this._supportTicketsServiceProxy.getTicket( this.filterText, this.assignedToFilter, this.statusFilter, this.typeFilter, this.dateFrom, this.dateTo, this.createdBy, this.tenant, this.primengTableHelper.getSorting(this.dataTable), this.primengTableHelper.getSkipCount(this.paginator, event), this.primengTableHelper.getMaxResultCount(this.paginator, event) ).subscribe(result => { this.primengTableHelper.totalRecordsCount = result.totalCount; this.primengTableHelper.records = result.items; //this.primengTableHelper.hideLoadingIndicator(); this.spinnerService.hide(); }); } reloadPage(): void { //this.paginator.changePage(this.paginator.getPage()); this.getSupportTickets(); } refresh(): void { this.dateFrom = undefined; this.dateTo = undefined; this.getSupportTickets(); } /* createRouteType(): void { this.createOrEditRouteTypeModal.show(); }*/ delete(id): void { this.message.confirm( '', '', (isConfirmed) => { if (isConfirmed) { this._supportTicketsServiceProxy.delete(id) .subscribe(() => { this.reloadPage(); this.notify.success(this.l('SuccessfullyDeleted')); }); } } ); } createOrEdit(url: any, id?: number){ if(id != null){ var myurl = `${url}/${id}`; }else{ var myurl = `${url}`; } console.log(myurl); this._router.navigateByUrl(myurl); } 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; }); } showAllTenant() : void { //this.active = true; this._supportTicketsServiceProxy.getTenantForDropDown().subscribe((result) => { this.tenantList = 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.download(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; } download(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 }); }) ); } ticketNotes(id): void { this.ticketNotesModal.show(id, true); } assign(id, assignId?): void { this.assignModal.show(id, assignId); } }