import { Component, Injector, ViewEncapsulation, ViewChild, OnInit } 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 { OrderServiceProxy, OrderListDto, OrderRouteListDto, RouteVehicleListDto, UserListDto, OrderIncidentsServiceProxy, CreateOrderIncidentDto, RouteTemplateListDto, ContactListDto, IncidentTypesServiceProxy, ListResultDtoOfIncidentTypeDto } from '@shared/service-proxies/service-proxies'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { IncidentNotesModalComponent } from './incident-notes-modal.component'; 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 { HttpClient } from '@angular/common/http'; import { FormControl, FormGroup } from '@angular/forms'; @Component({ templateUrl: './create-incident.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()] }) export class CreateIncidentComponent extends AppComponentBase implements OnInit { @ViewChild('dataTable', { static: true }) dataTable: Table; @ViewChild('paginator', { static: true }) paginator: Paginator; @ViewChild('incidentNotesModal', {static: false}) incidentNotesModal: IncidentNotesModalComponent; bsConfig: Partial; id: any; defaultDate = new Date(); orderDetails: OrderRouteListDto = new OrderRouteListDto(); vehicle: RouteVehicleListDto = new RouteVehicleListDto(); users: UserListDto = new UserListDto(); routeTemplate: RouteTemplateListDto = new RouteTemplateListDto(); contacts: ContactListDto= new ContactListDto(); incidentTypes : ListResultDtoOfIncidentTypeDto = new ListResultDtoOfIncidentTypeDto(); createOrderIncident: CreateOrderIncidentDto = new CreateOrderIncidentDto(); incidentDate: any; incidentType: any; typesId: number; content: string; notes: any[] = []; 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 ) { super(injector); } ngOnInit(): void { this.route.paramMap.subscribe(params => { this.id = params.get("id") }) $('.kt-select2').select2(); this._orderAppService.getOrderDriver( this.id ).pipe().subscribe(result => { this.orderDetails = result; this.vehicle = this.orderDetails.route.vehicle; this.users = this.orderDetails.route.vehicle.user; this.routeTemplate = this.orderDetails.route.routeTemplate; this.contacts = this.orderDetails.deliveryDetail.contact; //console.log(this.orderDetails.deliveryDetail.contact); }); this._incidentTypesService.getAllIncidentType().subscribe(result=>{ this.incidentTypes = result; //console.log(result); }); } getIncident(event?: LazyLoadEvent) { if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } } reloadPage(): void { this.paginator.changePage(this.paginator.getPage()); } save(): void { //console.log(this.createOrderIncident); //alert('yow'); let that = this; that.typesId = Number($('#selectedIncidentTypeId').val()); let createOrderIncidents = new CreateOrderIncidentDto({ orderId: this.id, incidentTypeId: that.typesId, geocodeId: 0, content: that.content, incidentDate: moment.utc(moment(this.defaultDate).format('YYYY-MM-DD')), id: undefined }); this._orderIncidentsService.createOrderIncident(createOrderIncidents).subscribe(result=>{ this.notify.info(this.l('SavedSuccessfully')); }); } updateMyDate(newDate) { this.defaultDate = newDate; } incidentNotes(): void { this.incidentNotesModal.show(); } }