<?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.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 
&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 &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 &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 ReportingOnRails 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 &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; 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 ReportingOnRails 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 &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; archive into the lib\seeds directory of the application.   &lt;/p&gt;

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

&lt;p&gt;Then open the &lt;strong&gt;db/seeds.rb&lt;/strong&gt; 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 'csv'

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

csv.each do |row|  
  #puts row.to_hash  
  Sale.create!(region: row['Region'],  
  country: row['Country'],  
  itemType: row['Item Type'],  
  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 config/routes.rb 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 do  
  get 'api/sales', to: 'application#sales'  
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now open app/controllers/application_controller.rb 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 ApplicationController &amp;lt; ActionController::API  
    def sales  
        @sales = Sale.all  

        render json: @sales  
      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 &lt;a href="http://localhost:3000/api/sales" rel="noopener noreferrer"&gt;http://localhost:3000/api/sales&lt;/a&gt; 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.   &lt;/p&gt;

&lt;p&gt;In the &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 File menu and select the Continuous Page Layout template for a newly created report.   &lt;/p&gt;

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

&lt;p&gt;In the Data Source editor dialog, type &lt;a href="http://localhost:3000/api/sales" rel="noopener noreferrer"&gt;http://localhost:3000/api/sales&lt;/a&gt; in the ENDPOINT field and click the Save Changes 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 + icon near DataSource in the Data panel.  &lt;/p&gt;

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

&lt;p&gt;Click the Validate button, ensure that the DataBase Fields section displays [7 items] text, and click the Save Changes 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 &lt;a href="https://www.grapecity.com/activereportsjs/docs/ReportAuthorGuide/Report-Designer-Interface#toolbox" rel="noopener noreferrer"&gt;toolbox&lt;/a&gt; using the Hamburger menu located on the toolbar’s left side.  &lt;/p&gt;

&lt;p&gt;Drag and drop the Chart item from the toolbox to the report page area's top-left corner. The Chart Wizard dialog appears. Select the Bar type and click the Next 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 Next 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 Finish 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 Orientation property to Horizontal and Position property to Bottom.  &lt;/p&gt;

&lt;p&gt;Click the File menu and save the newly created report in the public folder of the application under the name 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 application's public folder, create an index.html 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 lang="en"&amp;gt;  
&amp;lt;head&amp;gt;  
    &amp;lt;meta charset="UTF-8"&amp;gt;  
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;  
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;  
    &amp;lt;title&amp;gt;Sales Report&amp;lt;/title&amp;gt;  
    &amp;lt;link  
    rel="stylesheet"  
    href="https://cdn.grapecity.com/activereportsjs/3.latest/styles/ar-js-ui.css"  
    type="text/css"  
  /&amp;gt;  
  &amp;lt;link  
    rel="stylesheet"  
    href="https://cdn.grapecity.com/activereportsjs/3.latest/styles/ar-js-viewer.css"  
    type="text/css"  
  /&amp;gt;  
  &amp;lt;script src="https://cdn.grapecity.com/activereportsjs/3.latest/styles/ar-js-ui.css"&amp;gt;&amp;lt;/script&amp;gt;  
  &amp;lt;script src="https://cdn.grapecity.com/activereportsjs/3.latest/dist/ar-js-viewer.js"&amp;gt;&amp;lt;/script&amp;gt;  
  &amp;lt;script src="https://cdn.grapecity.com/activereportsjs/3.latest/dist/ar-js-pdf.js"&amp;gt;&amp;lt;/script&amp;gt;  
  &amp;lt;style&amp;gt;  
    #viewer-host {  
      width: 100%;  
      height: 100vh;  
    }  
  &amp;lt;/style&amp;gt;        
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;  
    &amp;lt;div id="viewer-host"&amp;gt;&amp;lt;/div&amp;gt;  
    &amp;lt;script&amp;gt;  
        var viewer = new ActiveReports.Viewer("#viewer-host");  
        viewer.open('/SalesReport.rdlx-json');  
      &amp;lt;/script&amp;gt;    
&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 &lt;a href="http://localhost:3000/index.html" rel="noopener noreferrer"&gt;http://localhost:3000/index.html&lt;/a&gt; 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>
