No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
Add (optional) gem description here
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Project Readme

SolidusAdminInsights

Dashboard for querying and viewing you solidus store's metrics. Use SolidusEventTracker to capture the metrics

Installation

Add solidus_admin_insights to your Gemfile:

gem 'solidus_admin_insights'

Bundle your dependencies and run the installation generator:

bundle
bundle exec rails g solidus_admin_insights:install
bundle exec rails g solidus_events_tracker:install

Adding new reports

Create a class that inherits from Spree::Report and define a report_query method. If the report is to be paginated. it should define also define a method called paginated and set it to return true alongwith defining paginated_report_query and record_count_query. the _query methods should return objects that respond to to_sql which returns sql string for reporting query.

All reports need to define the following constants:

  1. SORTABLE_ATTRIBUTES: Other attributes based on which reports can be sorted.
  2. DEFAULT_SORTABLE_ATTRIBUTE: The attribute which is used by default to sort the report results.
  3. HEADERS: The static header fields for report. Note time based fields are automatically added. Any field not declared here but available in observation will be ignored while displaying the report.
  4. SEARCH_ATTRIBUTES: A hash containing the attributes and their name on frontend based on which report result can be filtered.

Additionally they need to define two nested classes. Result and Result::Observation.

Result class can inherit from Spree::Report::Result if it is a basic report or from Spree::Report::TimedResult if the result can be time scaled(i.e. changing reporting period changes the scale of report).

Similarly Observation class needs to inherit either from Spree::Report::Observation or Spree::Report::TimedObservation. It defines a macro call observation_fields which can be passed an array or hash with default values of fields which form one report item. Create a method of same name in Observation class for virtual fields which are not returned by queries. ie. average or for formatting db results.

TimedResult has 2 lifecycle methods which can be overriden for customizing the report output.

  1. build_empty_observations: Generates empty observations which are later filled with datapoints returned by report query.
  2. populate_observations: Fill the empty observations with data returned via query.

TimedObservation defines a describes? method which can be overriden to change where the query results gets copied to.

You can add charts to reports by calling charts with a list of classes representing the chart. Each chart implementing class gets the results in it's initializer and need to implement to_h method returning the json representation of chart.

Finally, register the report in initializer solidus_admin_insights.rb in its appropriate category or make a new category to make it available in admin dashboard.

Testing

First bundle your dependencies, then run rake. rake will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using rake test_app.

bundle
bundle exec rake

When testing your applications integration with this extension you may use it's factories. Simply add this require statement to your spec_helper:

require 'solidus_admin_insights/factories'

Credits

vinsol.com: Ruby on Rails, iOS and Android developers

Copyright (c) 2017 vinsol.com, released under the New MIT License