import { Component, EventEmitter, ElementRef, Injector, Output, ViewChild, ViewContainerRef } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { IncidentServiceProxy, CreateIncidentInput, IncidentImageServiceProxy, CreateNoteIncidentInput } from '@shared/service-proxies/service-proxies'; import { GeocodeServiceProxy, CreateGeocodeInput } from '@shared/service-proxies/service-proxies'; 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'; import { AppSessionService } from '@shared/common/session/app-session.service'; @Component({ selector: 'createIncidentNotesModal', templateUrl: './create-incidentnote-modal.html' }) export class CreateIncidentNotesModalComponent extends AppComponentBase { @ViewChild('createModal', {static: false}) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); note: any; notes: any[] = []; creator: string; today: any; incidentInput: { id: number; geocodeId: number; content: string; incidentDate: string; }; incidentDate: Date; incidentTime: any; active: boolean = false; saving: boolean = false; incident: CreateIncidentInput = new CreateIncidentInput(); constructor( injector: Injector, private _incidentService: IncidentServiceProxy, private viewContainerRef: ViewContainerRef, private _appSessionService: AppSessionService, ) { super(injector); } show() { this.today = new Date(); this.creator = this._appSessionService.user.name + ' ' + this._appSessionService.user.surname; this.note = null; this.active = true; this.init(); this.modal.show(); } onShown(): void { //document.getElementById('valueInput').focus(); } init(): void { } save(): void { this.saving = true let input = new CreateNoteIncidentInput(); input.content = this.note; input.incidentId = this.getParentComponent().incidentId; // console.log("testonly") // this.getParentComponent().refreshNote(); this._incidentService.createIncidentNote(input).subscribe(result=>{ this.getParentComponent().refreshNote(); this.spinnerService.hide(); this.saving = false this.close(); }, error=> { this.saving=false }) } getParentComponent() { return this.viewContainerRef[ '_data' ].componentView.component.viewContainerRef[ '_view' ].component } close(): void { this.active = false; this.modal.hide(); } }