async ngOnInit()

in front-end/src/app/shared/common-view/viewer-report/viewer-report.component.ts [35:80]


  async ngOnInit() {
    this.viewerInitSubscription = this.viewerService.getInitialized().subscribe(async init => {
      if (init) {
        try {
        this.oneReport = this.viewerService.reports.length === 1;
        this.sub = this.route.params.subscribe(params => {
          this.reportID = params['reportID'];
        });
        this.selectedOrgID = this.route.snapshot.queryParamMap.get('selectedOrg');
        this.report = await this.reportService.getReport(this.reportID, this.selectedOrgID);
        this.selectedOrg = this.report.organizations.find(org => {
          return org._id === this.selectedOrgID;
        });
        /*
        this.reportsCount = await this.viewerService.reportsCount();
        const patt = new RegExp('/c/(.)+/reporting');
        const replaceLink = this.report.link.replace(patt, '/embed/reporting');
        this.embedLink = this.sanitizer.bypassSecurityTrustResourceUrl(replaceLink);
        */
        const patt = new RegExp('google\.com(.)*\/reporting');
        const replaceLink = this.report.link.replace(patt, 'google.com/embed/reporting');
        this.embedLink = this.sanitizer.bypassSecurityTrustResourceUrl(replaceLink);

        if (!this.viewerService.currentOrganization) {
          const org = this.viewerService.getOrganization(this.selectedOrgID);
          let status;
          if (this.viewerService.adminUser) {
            status = await (<any>this.viewerService.initializeGhost(org, this.viewerService.adminUser));
          } else {
            status = await (<any>this.viewerService.initializeGhost(org, this.viewerService.getUser()));
          }
          // delete this after
          this.initialized = true;
          if (status.status === '200') {
            this.initialized = true;
          }
        } else {
          this.initialized = true;
        }
      } catch (e) {
        this.error = true;
        this.errorMessage = e.message;
      }
      }
    });
  }