Header in request some REST

Stimulsoft Reports.JS discussion
Mateus Garrido Kern
Posts: 29
Joined: Wed Sep 04, 2019 5:19 pm
Location: Curitiba/PR (Brazil)

Header in request some REST

Post by Mateus Garrido Kern » Wed Jun 17, 2020 2:26 pm

Hello,

I'm having trouble putting headers in my API requests using the report merge.
How I put headers in my requests using report merge?

My code is it:

Code: Select all

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

declare var Stimulsoft: any;

@Component({
  selector: 'app-livro-diario-relatorio',
  template: `<div id="viewerContent"></div>`
})

export class LivroDiarioRelatorioComponent implements OnInit {
  show: boolean;

  options: any = new Stimulsoft.Viewer.StiViewerOptions();
  viewer: any = new Stimulsoft.Viewer.StiViewer(this.options, 'StiViewer', false);

  constructor(private activatedRoute: ActivatedRoute) {}

  ngOnInit() {
    this.activatedRoute.queryParams.subscribe(params => {
      this.show = params['show'] === 'true' ? true : false;
    });

    let reportStart;
    let reportFinish;
    let dbJsonStart;
    let dbJsonFinish;

    const reportMiddle = new Stimulsoft.Report.StiReport.createNewReport();
    reportMiddle.loadFile('../../../../assets/ReportMiddle.mrt');
    reportMiddle.isAsync = true;

    const reportMerge = new Stimulsoft.Report.StiReport();
    reportMerge.reportUnit = reportMiddle.reportUnit;
    reportMerge.renderAsync();
    reportMerge.renderedPages.clear();

    const dbJsonMiddle = reportMiddle.dictionary.databases.getByName('JSON');
    dbJsonMiddle.pathData = 'https://api.test/middle';
    
    this.viewer.onBeginProcessData = function (event) {
      event.headers.push({key: 'Authorization', value: 'Bearer ' + localStorage.getItem('token')});
    };

    if (this.show) {
      reportStart = new Stimulsoft.Report.StiReport.createNewReport();
      reportStart.loadFile('../../../../assets/ReportStart.mrt');
      reportStart.isAsync = true;

      reportFinish = new Stimulsoft.Report.StiReport.createNewReport();
      reportFinish.loadFile('../../../../assets/ReportFinish.mrt');
      reportFinish.isAsync = true;
      
      dbJsonStart = reportStart.dictionary.databases.getByName('JSON');
      dbJsonStart.pathData = 'https://api.test/start';

      dbJsonFinish = reportFinish.dictionary.databases.getByName('JSON');
      dbJsonFinish.pathData = 'https://api.test/finish';

      reportStart.renderAsync(function () {
        for (let index = 0; index < reportStart.renderedPages.count; ++index) {
            reportMerge.renderedPages.add(reportStart.renderedPages.getByIndex(index));
        }
      });
    }
    
    reportMiddle.renderAsync(function () {
      for (let index = 0; index < reportMiddle.renderedPages.count; ++index) {
          reportMerge.renderedPages.add(reportMiddle.renderedPages.getByIndex(index));
      }
    });

    if (this.show) {
      reportFinish.renderAsync(function () {
        for (let index = 0; index < reportFinish.renderedPages.count; ++index) {
            reportMerge.renderedPages.add(reportFinish.renderedPages.getByIndex(index));
        }
      });
    }

    reportMerge.renderedPages.list.forEach(function(page, i, arr) {
      const pagination = page.components.getByName('Pagination');
      if (pagination) {
        pagination.text = 'Page ' + (i + 1) + ' of ' + reportMerge.renderedPages.count;
      }

      const centralText = page.components.getByName('CentralText');
      if (centralText) {
        centralText.text = centralText.text.replace(/{NumberPages}/gi, '' + reportMerge.renderedPages.count);
      }
    });

    this.viewer.report = reportMerge;
    this.viewer.renderHtml('viewerContent');
  }
}
And I have this problem, where show on console tab in my web page:

Image
(If the image didnt work, you can see this image access this url: https://prnt.sc/t1hcnt or see the attachment named CONSOLE_LOG_ERRO.png)

Thank you
Attachments
CONSOLE_LOG_ERRO.png
Console error in my web page (Press F12 in Chrome to access the console)
CONSOLE_LOG_ERRO.png (20.06 KiB) Viewed 1173 times
Mateus Garrido Kern
Email: desenv5.digibyte@outlook.com
Lech Kulikowski
Posts: 3225
Joined: Tue Mar 20, 2018 5:34 am

Re: Header in request some REST

Post by Lech Kulikowski » Mon Jun 22, 2020 8:34 am

Hello,

We need some additional time to investigate the issue, we will let you know about the result.

Thank you.
#2301
Vardenis
Posts: 7
Joined: Mon Feb 03, 2020 1:27 pm

Re: Header in request some REST

Post by Vardenis » Mon Jun 29, 2020 9:31 am

Hello,

Are there any news ? I'm looking for this answer too
Lech Kulikowski
Posts: 3225
Joined: Tue Mar 20, 2018 5:34 am

Re: Header in request some REST

Post by Lech Kulikowski » Tue Jun 30, 2020 10:24 am

Hello,

We are working on the problem. We will let you know when the solution is available.

Thank you.
Lech Kulikowski
Posts: 3225
Joined: Tue Mar 20, 2018 5:34 am

Re: Header in request some REST

Post by Lech Kulikowski » Thu Jul 02, 2020 8:45 am

Hello,

Please send us a sample report with test data that reproduces the issue for analysis.

Thank you.
Mateus Garrido Kern
Posts: 29
Joined: Wed Sep 04, 2019 5:19 pm
Location: Curitiba/PR (Brazil)

Re: Header in request some REST

Post by Mateus Garrido Kern » Fri Jul 03, 2020 9:14 pm

Lech Kulikowski wrote:
Thu Jul 02, 2020 8:45 am
Hello,

Please send us a sample report with test data that reproduces the issue for analysis.

Thank you.
Hello,

You have some e-mail adress to send the test project?

Thank You
Mateus Garrido Kern
Email: desenv5.digibyte@outlook.com
Andrew
Posts: 4024
Joined: Fri Jun 09, 2006 3:58 am

Re: Header in request some REST

Post by Andrew » Sat Jul 04, 2020 6:28 am

Hello,

Please send it to support@stimulsoft.com and refer to this forum thread.

Thank you.
Mateus Garrido Kern
Posts: 29
Joined: Wed Sep 04, 2019 5:19 pm
Location: Curitiba/PR (Brazil)

Re: Header in request some REST

Post by Mateus Garrido Kern » Mon Jul 06, 2020 6:21 pm

Hi Andrew, I sent a email to this address with the subject
Files about the topic "Header in request some REST", by Mateus Kern
, and this generate a request number 3164931.

I'm waiting for an answer, thank you.
Mateus Garrido Kern
Email: desenv5.digibyte@outlook.com
Lech Kulikowski
Posts: 3225
Joined: Tue Mar 20, 2018 5:34 am

Re: Header in request some REST

Post by Lech Kulikowski » Mon Jul 06, 2020 10:02 pm

Hello,

We need some additional time to investigate the issue, we will let you know about the result.

Thank you.
Mateus Garrido Kern
Posts: 29
Joined: Wed Sep 04, 2019 5:19 pm
Location: Curitiba/PR (Brazil)

Re: Header in request some REST

Post by Mateus Garrido Kern » Fri Jul 10, 2020 4:20 pm

I solved this problem putting onBeginProcessData in each report

Code: Select all

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

declare var Stimulsoft: any;

@Component({
  selector: 'app-livro-diario-relatorio',
  template: `<div id="viewerContent"></div>`
})

export class LivroDiarioRelatorioComponent implements OnInit {
  show: boolean;

  options: any = new Stimulsoft.Viewer.StiViewerOptions();
  viewer: any = new Stimulsoft.Viewer.StiViewer(this.options, 'StiViewer', false);

  constructor(private activatedRoute: ActivatedRoute) {}

  ngOnInit() {
    this.activatedRoute.queryParams.subscribe(params => {
      this.show = params['show'] === 'true' ? true : false;
    });

    let reportStart;
    let reportFinish;
    let dbJsonStart;
    let dbJsonFinish;

    const reportMiddle = new Stimulsoft.Report.StiReport.createNewReport();
    reportMiddle.loadFile('../../../../assets/ReportMiddle.mrt');
    reportMiddle.isAsync = true;

    const reportMerge = new Stimulsoft.Report.StiReport();
    reportMerge.reportUnit = reportMiddle.reportUnit;
    reportMerge.renderAsync();
    reportMerge.renderedPages.clear();

    const dbJsonMiddle = reportMiddle.dictionary.databases.getByName('JSON');
    dbJsonMiddle.pathData = 'https://api.test/middle';
    
    reportMiddle.onBeginProcessData = function (event) {
      event.headers.push({key: 'Authorization', value: 'Bearer ' + localStorage.getItem('token')});
    };

    if (this.show) {
      reportStart = new Stimulsoft.Report.StiReport.createNewReport();
      reportStart.loadFile('../../../../assets/ReportStart.mrt');
      reportStart.isAsync = true;

      reportFinish = new Stimulsoft.Report.StiReport.createNewReport();
      reportFinish.loadFile('../../../../assets/ReportFinish.mrt');
      reportFinish.isAsync = true;
      
      dbJsonStart = reportStart.dictionary.databases.getByName('JSON');
      dbJsonStart.pathData = 'https://api.test/start';

      dbJsonFinish = reportFinish.dictionary.databases.getByName('JSON');
      dbJsonFinish.pathData = 'https://api.test/finish';
      
      reportStart.onBeginProcessData = function (event) {
        event.headers.push({key: 'Authorization', value: 'Bearer ' + localStorage.getItem('token')});
      };
      
      reportStart.renderAsync(function () {
        for (let index = 0; index < reportStart.renderedPages.count; ++index) {
            reportMerge.renderedPages.add(reportStart.renderedPages.getByIndex(index));
        }
      });
    }
    
    reportMiddle.renderAsync(function () {
      for (let index = 0; index < reportMiddle.renderedPages.count; ++index) {
          reportMerge.renderedPages.add(reportMiddle.renderedPages.getByIndex(index));
      }
    });

    if (this.show) {
      reportFinish.onBeginProcessData = function (event) {
        event.headers.push({key: 'Authorization', value: 'Bearer ' + localStorage.getItem('token')});
      };
      
      reportFinish.renderAsync(function () {
        for (let index = 0; index < reportFinish.renderedPages.count; ++index) {
            reportMerge.renderedPages.add(reportFinish.renderedPages.getByIndex(index));
        }
      });
    }

    reportMerge.renderedPages.list.forEach(function(page, i, arr) {
      const pagination = page.components.getByName('Pagination');
      if (pagination) {
        pagination.text = 'Page ' + (i + 1) + ' of ' + reportMerge.renderedPages.count;
      }

      const centralText = page.components.getByName('CentralText');
      if (centralText) {
        centralText.text = centralText.text.replace(/{NumberPages}/gi, '' + reportMerge.renderedPages.count);
      }
    });

    this.viewer.report = reportMerge;
    this.viewer.renderHtml('viewerContent');
  }
}
Thank you guys for your attention, both here and by support@stimulsoft.com
Mateus Garrido Kern
Email: desenv5.digibyte@outlook.com
Post Reply