import { Component, EventEmitter, ElementRef, Injector, Output, ViewChild, ViewContainerRef } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { AppSessionService } from '@shared/common/session/app-session.service'; import { SupportTicketServiceProxy, CreateNotes, SupportTicketStatusServiceProxy, TicketStatusList } from '@shared/service-proxies/service-proxies'; import { GeocodeServiceProxy, CreateGeocodeInput } from '@shared/service-proxies/service-proxies'; //import { AppSessionService } from '@shared/common/session/app-session.service'; import * as _ from 'lodash'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { AppConsts } from '@shared/AppConsts'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import {FormBuilder, FormGroup, Validators} from "@angular/forms"; import * as moment from 'moment'; @Component({ selector: 'ticketNotesModal', templateUrl: './ticket-notes-modal.component.html' }) export class TicketNotesModalComponent extends AppComponentBase { @ViewChild('createModal', {static: false}) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); note: any; notes: any[] = []; id: any; creator: string; today: any; resolve: boolean = false; active: boolean = false; saving: boolean = false; noteInput: CreateNotes = new CreateNotes(); ticketStatuses: TicketStatusList[] = []; ticketStatusId: number; selectedStatusId:number; constructor( injector: Injector, private viewContainerRef: ViewContainerRef, private _appSessionService: AppSessionService, private _supportTicketServiceProxy: SupportTicketServiceProxy, private _supportTicketStatusServiceProxy: SupportTicketStatusServiceProxy, ) { super(injector); } show(id?, resolve?, ticketStatuses?, statusId?) : void { this.today = new Date(); this.creator = this._appSessionService.user.name + ' ' + this._appSessionService.user.surname; this.id = id; this.note = null; this.resolve = resolve; this.ticketStatuses = ticketStatuses; this.selectedStatusId = statusId; this.active = true; this.init(); this.modal.show(); } onShown(): void { //document.getElementById('valueInput').focus(); $('.kt-select2').select2(); } init(): void { } save(): void { this.saving = true; if(this.id != undefined) { this.noteInput.ticketId = this.id; this.noteInput.notes = this.note; this.noteInput.creator = this.creator; this.noteInput.creationTime = this.today; this._supportTicketServiceProxy.createNote( this.noteInput ).pipe().subscribe(result => { if(this.resolve) { this.ticketStatusId = Number($('#statusNew').val()); this._supportTicketServiceProxy.closeTicket(this.id, this.ticketStatusId).pipe().subscribe(); this.saving = false; } this.notify.info(this.l('SavedSuccessfully')); this.saving = false; this.modalSave.emit(null); this.close(); }); } else { this.notes = this.note; this.getParentComponent().notes.push(this.notes); console.log(this.notes); //this.saving = true; this.close(); //this.modalSave.emit(null); } } getParentComponent() { return this.viewContainerRef[ '_data' ].componentView.component.viewContainerRef[ '_view' ].component } close(): void { this.active = false; this.saving = false; this.modal.hide(); } }