<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sergey Abakumoff</title>
    <description>The latest articles on DEV Community by Sergey Abakumoff (@sabakumoff).</description>
    <link>https://dev.to/sabakumoff</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2844%2F769109.jpeg</url>
      <title>DEV Community: Sergey Abakumoff</title>
      <link>https://dev.to/sabakumoff</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sabakumoff"/>
    <language>en</language>
    <item>
      <title>How to Use a Javascript Reporting Tool with Ruby on Rails</title>
      <dc:creator>Sergey Abakumoff</dc:creator>
      <pubDate>Thu, 28 Apr 2022 19:15:05 +0000</pubDate>
      <link>https://dev.to/mescius/how-to-use-a-javascript-reporting-tool-with-ruby-on-rails-5fae</link>
      <guid>https://dev.to/mescius/how-to-use-a-javascript-reporting-tool-with-ruby-on-rails-5fae</guid>
      <description>&lt;p&gt;ActiveReportsJS is a 100% client-side reporting tool with zero server dependencies. It means that you can use ActiveReportsJS together with any web server, including a Ruby on Rails application. This article contains a simple yet thorough tutorial on integrating ActiveReportsJS with a Ruby on Rails application. By the end, you will be able to do the following: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a Ruby on Rails application serving a JSON API
&lt;/li&gt;
&lt;li&gt;Create a data model for the JSON API
&lt;/li&gt;
&lt;li&gt;Initialize the data from a CSV file
&lt;/li&gt;
&lt;li&gt;Configure JSON API endpoints
&lt;/li&gt;
&lt;li&gt;Create an ActiveReportsJS report to visualize the data from the JSON API
&lt;/li&gt;
&lt;li&gt;Create a static HTML page to display the report in the report viewer
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Prerequisites&amp;nbsp;
&lt;/h4&gt;

&lt;p&gt;The following content assumes that you have Ruby on Rails installed on your machine. If you don't have it, you can obtain it from the&amp;nbsp;&lt;a href="http://rubyonrails.org/" rel="noopener noreferrer"&gt;Ruby on Rails website&lt;/a&gt;. It would be best if you also had ActiveReportsJS installed on your machine. If you don't have it, you can obtain it from the&amp;nbsp;&lt;a href="https://www.grapecity.com/activereportsjs/download" rel="noopener noreferrer"&gt;ActiveReportsJS website&lt;/a&gt;.  &lt;/p&gt;

&lt;h4&gt;
  
  
  Create a Ruby on Rails Application
&lt;/h4&gt;

&lt;p&gt;To create a new Ruby on Rails application, run the following command from a terminal or command prompt.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails new ReportingOnRails --api
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then open the newly created&amp;nbsp;ReportingOnRails&amp;nbsp;directory in your favorite code editor, such as Visual Studio Code.  &lt;/p&gt;

&lt;h4&gt;
  
  
  Create a Data Model for the JSON API
&lt;/h4&gt;

&lt;p&gt;We will use the Sales dataset that you can download from&amp;nbsp;&lt;a href="https://eforexcel.com/wp/downloads-18-sample-csv-files-data-sets-for-testing-sales/" rel="noopener noreferrer"&gt;E for Excel&lt;/a&gt;&amp;nbsp;website. It offers datasets of various sizes, starting from 100 records to 5M records. For simplicity, we will use the first dataset, which has 100 records.  &lt;/p&gt;

&lt;p&gt;There are many fields in the dataset, but we will only use several of them in this tutorial. To create a data model for the JSON API, run the following commands from the&amp;nbsp;ReportingOnRails&amp;nbsp;directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails g model Sale region:string country:string itemType:string unitsSold:float  
rake db:migrate

# or the following for Windows:  
# bin\rails g model Sale region:string country:string itemType:string unitsSold:float  
# ruby bin\rake db:migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Initialize the Data from a CSV File
&lt;/h4&gt;

&lt;p&gt;Download and unzip the data from the&amp;nbsp;&lt;a href="https://global-cdn.grapecity.com/blogs/activereports/20220321-how-to-use-a-javascript-reporting-tool-with-ruby-on-rails/100-Sales-Records.zip" rel="noopener noreferrer"&gt;100-Sales-Records.zip&lt;/a&gt;&amp;nbsp;archive into the lib\seeds directory of the application.&amp;nbsp;  &lt;/p&gt;

&lt;p&gt;Install the&amp;nbsp;&lt;strong&gt;csv&lt;/strong&gt;&amp;nbsp;gem into the application.  &lt;/p&gt;

&lt;p&gt;Then open the&amp;nbsp;&lt;strong&gt;db/seeds.rb&lt;/strong&gt;&amp;nbsp;file and replace its content with the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require&amp;nbsp;'csv'

csv_text =&amp;nbsp;File.read(Rails.root.join('lib',&amp;nbsp;'seeds',&amp;nbsp;'100 Sales Records.csv'))  
csv =&amp;nbsp;CSV.parse(csv_text,&amp;nbsp;:headers&amp;nbsp;=&amp;gt;&amp;nbsp;true,&amp;nbsp;:encoding&amp;nbsp;=&amp;gt;&amp;nbsp;'ISO-8859-1')  
# puts csv

csv.each&amp;nbsp;do&amp;nbsp;|row|  
&amp;nbsp;&amp;nbsp;#puts row.to_hash  
&amp;nbsp;&amp;nbsp;Sale.create!(region: row['Region'],  
&amp;nbsp;&amp;nbsp;country: row['Country'],  
&amp;nbsp;&amp;nbsp;itemType: row['Item Type'],  
&amp;nbsp;&amp;nbsp;unitsSold: row['Units Sold'])  
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, run the following command from the terminal or command prompt.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rake db:seed  
# or ruby bin\rake db:seed in Windows
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Configure JSON API Endpoints
&lt;/h4&gt;

&lt;p&gt;Open the&amp;nbsp;config/routes.rb&amp;nbsp;file and replace its content with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Rails.application.routes.draw&amp;nbsp;do  
&amp;nbsp;&amp;nbsp;get&amp;nbsp;'api/sales', to:&amp;nbsp;'application#sales'  
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now open&amp;nbsp;app/controllers/application_controller.rb&amp;nbsp;and paste the following code snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class&amp;nbsp;ApplicationController &amp;lt; ActionController::API  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;def&amp;nbsp;sales  
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;@sales&amp;nbsp;= Sale.all  

&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;render json:&amp;nbsp;@sales  
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;end  
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run the application by using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails server  
# or ruby bin\rails server for Windows
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And open the browser to&amp;nbsp;&lt;a href="http://localhost:3000/api/sales" rel="noopener noreferrer"&gt;http://localhost:3000/api/sales&lt;/a&gt;&amp;nbsp;to see the data the JSON API returns.  &lt;/p&gt;

&lt;h4&gt;
  
  
  Create an ActiveReportsJS Report
&lt;/h4&gt;

&lt;p&gt;Let's now create a report that visualizes the data from the JSON API.&amp;nbsp;  &lt;/p&gt;

&lt;p&gt;In the&amp;nbsp;&lt;a href="https://www.grapecity.com/activereportsjs/docs/ReportAuthorGuide/QuickStart/Get-Started-With-Designer-App" rel="noopener noreferrer"&gt;Standalone Report Designer Application&lt;/a&gt;, click the&amp;nbsp;File&amp;nbsp;menu and select the&amp;nbsp;Continuous Page Layout&amp;nbsp;template for a newly created report.&amp;nbsp;  &lt;/p&gt;

&lt;p&gt;Open the&amp;nbsp;&lt;a href="https://www.grapecity.com/activereportsjs/docs/ReportAuthorGuide/Report-Designer-Interface#data-panel" rel="noopener noreferrer"&gt;Data panel&lt;/a&gt;&amp;nbsp;of the property inspector and click the&amp;nbsp;Add&amp;nbsp;button.  &lt;/p&gt;

&lt;p&gt;In the Data Source editor dialog, type&amp;nbsp;&lt;a href="http://localhost:3000/api/sales" rel="noopener noreferrer"&gt;http://localhost:3000/api/sales&lt;/a&gt;&amp;nbsp;in the&amp;nbsp;ENDPOINT&amp;nbsp;field and click the&amp;nbsp;Save Changes&amp;nbsp;button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fglobal-cdn.grapecity.com%2Fblogs%2Factivereports%2F20220321-how-to-use-a-javascript-reporting-tool-with-ruby-on-rails%2F01-datasource.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fglobal-cdn.grapecity.com%2Fblogs%2Factivereports%2F20220321-how-to-use-a-javascript-reporting-tool-with-ruby-on-rails%2F01-datasource.png" alt="ruby"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Click the&amp;nbsp;+&amp;nbsp;icon near&amp;nbsp;DataSource&amp;nbsp;in the Data panel.  &lt;/p&gt;

&lt;p&gt;In the&amp;nbsp;Data Set Editor&amp;nbsp;dialog, type&amp;nbsp;Sales&amp;nbsp;in the NAME field and $.* in the&amp;nbsp;JSON Path&amp;nbsp;field.  &lt;/p&gt;

&lt;p&gt;Click the&amp;nbsp;Validate&amp;nbsp;button, ensure that the&amp;nbsp;DataBase Fields&amp;nbsp;section displays&amp;nbsp;[7 items]&amp;nbsp;text, and click the&amp;nbsp;Save Changes&amp;nbsp;button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fglobal-cdn.grapecity.com%2Fblogs%2Factivereports%2F20220321-how-to-use-a-javascript-reporting-tool-with-ruby-on-rails%2F02-dataset.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fglobal-cdn.grapecity.com%2Fblogs%2Factivereports%2F20220321-how-to-use-a-javascript-reporting-tool-with-ruby-on-rails%2F02-dataset.png" alt="ruby"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Expand the&amp;nbsp;&lt;a href="https://www.grapecity.com/activereportsjs/docs/ReportAuthorGuide/Report-Designer-Interface#toolbox" rel="noopener noreferrer"&gt;toolbox&lt;/a&gt;&amp;nbsp;using the&amp;nbsp;Hamburger&amp;nbsp;menu located on the toolbar’s left side.  &lt;/p&gt;

&lt;p&gt;Drag and drop the&amp;nbsp;Chart&amp;nbsp;item from the toolbox to the report page area's top-left corner. The&amp;nbsp;Chart Wizard&amp;nbsp;dialog appears. Select the&amp;nbsp;Bar&amp;nbsp;type and click the&amp;nbsp;Next&amp;nbsp;button on the first screen.  &lt;/p&gt;

&lt;p&gt;On the second screen of the dialog, configure the data as shown in the following image and click the&amp;nbsp;Next&amp;nbsp;button.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fglobal-cdn.grapecity.com%2Fblogs%2Factivereports%2F20220321-how-to-use-a-javascript-reporting-tool-with-ruby-on-rails%2F03-chartwizard.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fglobal-cdn.grapecity.com%2Fblogs%2Factivereports%2F20220321-how-to-use-a-javascript-reporting-tool-with-ruby-on-rails%2F03-chartwizard.png" alt="ruby"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;On the third screen, click the&amp;nbsp;Finish&amp;nbsp;button.  &lt;/p&gt;

&lt;p&gt;Resize the chart report item to fill the entire width of the report page. Click the chart legend to load its properties into the properties panel, and set the&amp;nbsp;Orientation&amp;nbsp;property to&amp;nbsp;Horizontal&amp;nbsp;and&amp;nbsp;Position&amp;nbsp;property to&amp;nbsp;Bottom.  &lt;/p&gt;

&lt;p&gt;Click the&amp;nbsp;File&amp;nbsp;menu and save the newly created report in the&amp;nbsp;public&amp;nbsp;folder of the application under the name&amp;nbsp;SalesReport.rdlx-json.  &lt;/p&gt;

&lt;h4&gt;
  
  
  Create a Static HTML Page to Display the Report
&lt;/h4&gt;

&lt;p&gt;In the&amp;nbsp;application's public folder, create an&amp;nbsp;index.html&amp;nbsp;file and replace its content with the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;  
&amp;lt;html&amp;nbsp;lang="en"&amp;gt;  
&amp;lt;head&amp;gt;  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;meta&amp;nbsp;charset="UTF-8"&amp;gt;  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;meta&amp;nbsp;http-equiv="X-UA-Compatible"&amp;nbsp;content="IE=edge"&amp;gt;  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;meta&amp;nbsp;name="viewport"&amp;nbsp;content="width=device-width, initial-scale=1.0"&amp;gt;  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;title&amp;gt;Sales Report&amp;lt;/title&amp;gt;  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;link  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rel="stylesheet"  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;href="https://cdn.grapecity.com/activereportsjs/3.latest/styles/ar-js-ui.css"  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;type="text/css"  
&amp;nbsp;&amp;nbsp;/&amp;gt;  
&amp;nbsp;&amp;nbsp;&amp;lt;link  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rel="stylesheet"  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;href="https://cdn.grapecity.com/activereportsjs/3.latest/styles/ar-js-viewer.css"  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;type="text/css"  
&amp;nbsp;&amp;nbsp;/&amp;gt;  
&amp;nbsp;&amp;nbsp;&amp;lt;script&amp;nbsp;src="https://cdn.grapecity.com/activereportsjs/3.latest/styles/ar-js-ui.css"&amp;gt;&amp;lt;/script&amp;gt;  
&amp;nbsp;&amp;nbsp;&amp;lt;script&amp;nbsp;src="https://cdn.grapecity.com/activereportsjs/3.latest/dist/ar-js-viewer.js"&amp;gt;&amp;lt;/script&amp;gt;  
&amp;nbsp;&amp;nbsp;&amp;lt;script&amp;nbsp;src="https://cdn.grapecity.com/activereportsjs/3.latest/dist/ar-js-pdf.js"&amp;gt;&amp;lt;/script&amp;gt;  
&amp;nbsp;&amp;nbsp;&amp;lt;style&amp;gt;  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#viewer-host {  
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;width: 100%;  
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;height: 100vh;  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}  
&amp;nbsp;&amp;nbsp;&amp;lt;/style&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;  
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div&amp;nbsp;id="viewer-host"&amp;gt;&amp;lt;/div&amp;gt;  
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&amp;gt;  
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;var viewer = new ActiveReports.Viewer("#viewer-host");  
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;viewer.open('/SalesReport.rdlx-json');  
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;lt;/script&amp;gt; &amp;nbsp;  
&amp;lt;/body&amp;gt;  
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure that the application runs and visit the browser to&amp;nbsp;&lt;a href="http://localhost:3000/index.html" rel="noopener noreferrer"&gt;http://localhost:3000/index.html&lt;/a&gt;&amp;nbsp;to see the report. If you followed the steps correctly, you should see a report that displays the data from the JSON API.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fglobal-cdn.grapecity.com%2Fblogs%2Factivereports%2F20220321-how-to-use-a-javascript-reporting-tool-with-ruby-on-rails%2F04-report.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fglobal-cdn.grapecity.com%2Fblogs%2Factivereports%2F20220321-how-to-use-a-javascript-reporting-tool-with-ruby-on-rails%2F04-report.png" alt="ruby"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Hi, I'm Sergey Abakumoff</title>
      <dc:creator>Sergey Abakumoff</dc:creator>
      <pubDate>Tue, 07 Feb 2017 04:19:32 +0000</pubDate>
      <link>https://dev.to/sabakumoff/hi-im-sergey-abakumoff</link>
      <guid>https://dev.to/sabakumoff/hi-im-sergey-abakumoff</guid>
      <description>&lt;p&gt;I have been coding for 12 years.&lt;/p&gt;

&lt;p&gt;You can find me on GitHub as &lt;a href="https://github.com/sAbakumoff" rel="noopener noreferrer"&gt;sAbakumoff&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I live in Amsterdam.&lt;/p&gt;

&lt;p&gt;I mostly program in these languages: Javascript, Golang.&lt;/p&gt;

&lt;p&gt;I am currently learning more about texas holdem&lt;/p&gt;

&lt;p&gt;Nice to meet you.&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
