import { Component, ViewChild, ElementRef, Renderer2, Input, OnInit, Inject, AfterViewInit } from '@angular/core'; import { GridComponent } from "./Controls" import { HttpClient } from '@angular/Common/http'; import { ModalComponent } from './Modal'; import { TaskComponent } from '../PageComponents/TaskComponent'; import { Subject } from 'rxjs'; import { DyTextComponent } from './Text'; import { ApplyPaymentComponent } from '../PageComponents/ApplyPayment'; import { ObjectNoteComponent } from '../Components/ObjectNoteComponent'; @Component({ selector: 'DyTasksPerModulControl' , templateUrl: '/templates/RelatedTaskGrid', }) export class TasksPerModulControlComponent implements OnInit,AfterViewInit { elementRef: ElementRef; @ViewChild("tasksGrid", { static: true }) tasksGrid: GridComponent; @ViewChild("addNewtaskforObject", { static: false }) addNewTaskModal: ModalComponent; @Input() id: string @Input() objectName: string; @Input() orderNumber: string; @Input() orderType: string; public renderer: Renderer2 public http: HttpClient; private ngUnsubscribe: Subject = new Subject(); ngOnDestroy(): any { this.ngUnsubscribe.next(); this.ngUnsubscribe.complete(); } constructor(@Inject(ElementRef) elementRef: ElementRef, @Inject(HttpClient) http: HttpClient, @Inject(Renderer2) renderer: Renderer2) { this.elementRef = elementRef; this.renderer = renderer; this.http = http; } ngOnInit() { this.tasksGrid.initDataSource(); } ngAfterViewInit() { this.tasksGrid.onLinkClicked.takeUntil(this.ngUnsubscribe).subscribe((result) => { this.tasksGrid.displayModal.Component = TaskComponent; var sub = this.tasksGrid.displayModal.componentLoaded.takeUntil(this.ngUnsubscribe).subscribe((Dcomp) => { // var comp: TaskComponent = Dcomp.instance; //grid.grid.displayModal.Buttons = saveButton(comp); // comp.dontListentoRoute = true; // var link = this.com.EvalExpression(result.item.linkFormat, result.options.data).split("/"); this.http.get(`api/Objects/Task/${result.options.data.id}`).takeUntil(this.ngUnsubscribe).subscribe(res => { var mod: any = res; comp.Model = mod; comp.OnNavigateRelated.takeUntil(this.ngUnsubscribe).subscribe(() => { this.tasksGrid.displayModal.dialogInstance.close(); }) //comp.documents.refreshDocuments(); sub.unsubscribe(); }); this.tasksGrid.displayModal.Buttons = [{ label: "Save", cssClass: "btn btn-success", action: (dialog) => { comp.Save().then((dta) => { dialog.close(); //this.parent.checkTasks(); this.tasksGrid.ReloadGird(); // this.checkTasks(); }); } }] }); this.tasksGrid.displayModal.childContentPlace.clear(); this.tasksGrid.displayModal.showDialog(); }); this.tasksGrid.addNewClicked.takeUntil(this.ngUnsubscribe).subscribe(() => { this.addNewTaskModal.Component = TaskComponent; this.addNewTaskModal.componentLoaded.takeUntil(this.ngUnsubscribe).subscribe((componenet) => { var tsk: TaskComponent = componenet.instance; tsk.Model.relatedObject = this.objectName; tsk.Model.relatedId = this.id; tsk.Model.name = this.getTaskName(); this.addNewTaskModal.Buttons = [{ label: "Save", cssClass: "btn btn-success", action: (dialog) => { tsk.Save().then((dta) => { dialog.close() this.tasksGrid.ReloadGird(); // this.checkTasks(); }); } }] }) this.addNewTaskModal.showDialog(); }); } public tasksView = (): UIGridView[] => { var ret = [{ addNewURL:" " , name: "Tasks", objectName: "task", isDefault: true, id: "Tasks", uiGridColumns: [ { name: "Id", visible: false }, { name: "Name", label: "Subject", openLinkInModal: true, openWithCommonEditor:true }, { name: "Status.Name", label: "Status" }, { name: "DueDate", specialFormat: "ShortDate", label: "Due Date" }, ], uiGridFilters: [ { field: "RelatedObject", data: this.objectName, operator: "=", type: "String" }, { field: "RelatedId", data: this.id, operator: "=", type: "Guid" }, ] }]; return ret; } private getTaskName() { return `${this.orderType.replace(this.orderType[0], this.orderType[0].toUpperCase())} ${this.orderNumber} - `; } }