import { Component, OnInit } from '@angular/core'; import { AutomationService } from '../../../shared/service/automation.service'; import { CookieService } from 'ngx-cookie-service'; import { IAutomation } from '../../../shared/core/automation/IAutomation'; @Component({ selector: 'app-automation-list', templateUrl: './automation-list.component.html', styleUrls: ['./automation-list.component.css'] }) export class AutomationListComponent implements OnInit { showNewAutomation: boolean = false; companyId: number; siteType: string = 'CRM' // for CRM contact automationList: IAutomation[] = []; newAutomationId: number; constructor(private automationService: AutomationService, private cookieService: CookieService) { } ngOnInit() { //Temparory setting the companyId //Have to set the actual value when subscription done this.companyId = +this.cookieService.get('CompanyId'); // get automation list this.getAutomations(this.companyId, this.siteType, 0, 0); } // Get automation list getAutomations(companyId: number, siteType: string, automationId: number, automationType: number) { this.automationService.GetAutomations(companyId, siteType, automationId, automationType).subscribe(list => { // bind automation list this.automationList = list; }) } // Pin automation pinAutomation(automation: IAutomation) { automation.IsPin = !automation.IsPin; this.automationService.PinAutomations(this.companyId, automation.Id, this.siteType, automation.IsPin).subscribe(list => { // bind automation list this.automationList = list; }) } applyForAll(automation: IAutomation) { this.automationService.ApplyForAll(this.companyId, automation.Id, automation.IsApplyAll).subscribe(data => { }) } // close add new / edit popup rebindCloseAddNew(event: boolean) { // hide new automation component this.showNewAutomation = false; // get automation list this.getAutomations(this.companyId, this.siteType, 0, 0); } // edit/view automation function editAutomation(automationId: number) { // show new automation component this.showNewAutomation = true; this.newAutomationId = automationId; } // add automation button click addAutomation() { // show new automation component this.showNewAutomation = true; this.newAutomationId = 0; } }