Skip to content
Shubham Patel edited this page Feb 4, 2017 · 2 revisions

Admin panel charts

Controller code

There are 2 pages on admin panel which are full of charts for location based and nooks based statistics respectively. The page and the data is served through location_statistics_controller.rb and nook_statistics_controller.rb resp. Each page has a filter on top of it. On it's update the charts also get updated.

Both the controllers have a filter function which fetch the records according to the filter parameters sent from the user through page. This filter is applied before_filter to fetch and download function.

The controllers have following functions:

  1. Index - to render the initial page
  2. Fetch - send the data as JSON to the page. Note that the records have already been fetched from the DB according to the filter parameters by filter funciton.
  3. Download - send a CSV file with the records.

Rendering charts

The charts are rendered using scripts from app/javascripts/administrate/charts. The canvas_heatmap.js renders all the charts on HTML canvas instead of in the SVG formats. This gives better performance in terms of rendering time.

The rest of the files render different type of charts - please check the comments on the top of the file for more info on what they render and the interpretation of the axes.

Implementing Google User

GoogleUser is the model which corresponds to the user who register through GoogleAuth2. We use omniauth-google-oauth2 gem for this strategy. The GoogleUser model inherits from User model. User table contains an attribute called type - which is set to GoogleUser in case of registration through GoogleAuth2. This is called Single Table Inheritance (STI). In future, if a student user is to be implemented, please use the same.

Clone this wiki locally