In the first part of the article, we created an ASP.Net Core application in which we implemented the following methods: displaying a report, displaying a report designer and saving the report changed in the designer to a server. But these are just the two features that we have stated. We need to implement the method of exporting the desired report in pdf or html format, followed by downloading this report. To let the user know which reports are available for download, we will implement a method for obtaining a list of reports.
Add the data structure for the report list to the model (Model folder) of the data:
Now we can create a list of reports with identifiers in our controller:
As mentioned above, we need a list of reports in the client application. It is useful for displaying a report, for editing a report in the designer and for downloading a report in pdf or html format.
Everything is simple here - a list of reports in json format. And now we are implementing a rather complicated method of obtaining report export:
This method receives two input parameters: id and query. The first is the report identifier from our list, and the second one is the set of report parameters that we specify in the url. We will have a look at this set below, but for now, let's continue with the Get method.
The SetParameterValue method sets the value of the parameter that we pass to the url, if necessary. This is just a demonstration of possibilities.
As you can see, from the format parameter we find out what the user selected. In our case, it can be pdf or html. Depending on the format, the report is exported. Each type of export has its own settings. As a result, the export is saved to the stream, and then is converted to a file for downloading.
Now back to the second parameter of the Get - query method. It has a type of ReportQuery. Create this class in the data model:
As you understand, Get methods are taken from WebAPI. This project is a hybrid; it has both a View part and a WebAPI interface.
Thus, in order to get a view that displays a report, you must form a url of the form:
In order to get a presentation with the report designer, the link needs to differ only in the name of the method:
But to get the name of the report, you need a list of available reports in the client application. You can get the list of reports in json format using url:
To download the report in the selected format, you will need to form a url of the form:
Where the report number corresponds to the id from the list of reports on the server, and the format may have values: pdf or html. In addition, you can specify a report parameter, if there is any in your report template. Then the url will look like this:
In this case, the parameter itself in the report should be called Parameter, and its value is taken from url. By analogy, you can think of as many parameters as you like in the url.
We have finished working with the server side. In the next part of the article, we will look at the way to use all this in a client application in PHP.