import { Component } from '@angular/core'; import { Router } from '@angular/router'; import { PolicyService } from '@core/services/policy.service'; import { SpinnerService } from '@core/services/spinner.service'; import { AdHocReportingService } from '@features/reporting/services/ad-hoc-reporting.service'; import { Tab } from '@yourcause/common'; import { ModalFactory } from '@yourcause/common/modals'; import { ManageAdHocReportModalComponent } from '../manage-ad-hoc-report-modal/manage-ad-hoc-report-modal.component'; @Component({ selector: 'gc-reporting-wrapper-page', templateUrl: './reporting-wrapper-page.component.html', styleUrls: ['./reporting-wrapper-page.component.scss'] }) export class ReportingWrapperPageComponent { canManageAdHoc = this.policyService.dataExport.canManageAdHoc(); tabs: Tab[] = [{ link: './ad-hoc', labelKey: 'GLOBAL:textAdHoc', label: 'Ad hoc' }, { link: './data-feeds', labelKey: 'GLOBAL:textDataFeeds', label: 'Data Feeds' }]; constructor ( private policyService: PolicyService, private spinnerService: SpinnerService, private adHocReportingService: AdHocReportingService, private modalFactory: ModalFactory, private router: Router ) { } get isAdHoc () { return location.pathname.includes('ad-hoc-data-feeds/ad-hoc'); } async showCreateModal () { this.spinnerService.startSpinner(); await this.adHocReportingService.resolveModalDeps(); this.spinnerService.stopSpinner(); const report = await this.modalFactory.open( ManageAdHocReportModalComponent, {} ); if (report) { let id: number; this.spinnerService.startSpinner(); if (!!report.startFromTemplate) { id = await this.adHocReportingService.handleCreateReportFromTemplate( report ); } else { id = await this.adHocReportingService.saveReportDetails(report); } this.spinnerService.stopSpinner(); if (id) { this.router.navigate([ `/management/reporting/ad-hoc-data-feeds/ad-hoc-edit/${id}` ]); } } } }