add admin :analysis & :analysis_resport
This commit is contained in:
parent
2ce3a4d5b6
commit
048c9bc563
|
@ -1,6 +1,6 @@
|
|||
class Admin::ActivitiesController < OrbitMemberController
|
||||
layout "member_plugin"
|
||||
#include Admin::PersonalActivitiesHelper
|
||||
include Admin::PersonalActivitiesHelper
|
||||
|
||||
before_action :set_activity, only: [:edit, :update, :destroy]
|
||||
#before_action :set_plugin
|
||||
|
@ -50,6 +50,20 @@ class Admin::ActivitiesController < OrbitMemberController
|
|||
end
|
||||
end
|
||||
|
||||
def analysis
|
||||
end
|
||||
|
||||
def analysis_report
|
||||
role = params[:role_id]
|
||||
year_start = params[:year_start].to_i
|
||||
year_end = params[:year_end].to_i
|
||||
graph_by = params[:graph_by]
|
||||
|
||||
@data = get_chart_data(year_start,year_end,role,params[:graph_by])
|
||||
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_activity
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
module Admin::PersonalActivitiesHelper
|
||||
def get_chart_data(year_start,year_end,role,type)
|
||||
type = nil
|
||||
|
||||
finaldata = []
|
||||
role = Role.find(role) rescue nil
|
||||
mps = []
|
||||
if !role.nil?
|
||||
mps = role.member_profile_ids
|
||||
end
|
||||
data = {"name" => "N/A", "data" => {}}
|
||||
(year_start..year_end).each do |year|
|
||||
d1 = DateTime.new(year,1,1,0,0)
|
||||
d2 = DateTime.new(year,12,31,23,59)
|
||||
t = Activity.where(:year.gte => year, :year.lte => year, :member_profile_id.in => mps).count rescue 0
|
||||
data["data"][year.to_s] = t
|
||||
end
|
||||
finaldata << data
|
||||
finaldata
|
||||
end
|
||||
end
|
|
@ -0,0 +1,108 @@
|
|||
<% # encoding: utf-8 %>
|
||||
<% content_for :page_specific_css do %>
|
||||
<%= stylesheet_link_tag "lib/main-forms" %>
|
||||
<%= stylesheet_link_tag "lib/fileupload" %>
|
||||
<%= stylesheet_link_tag "lib/main-list" %>
|
||||
<%= stylesheet_link_tag "lib/main-form-col2" %>
|
||||
<style>
|
||||
.graph-type {
|
||||
margin-right: 10px !important;
|
||||
}
|
||||
.analysis-show-area{
|
||||
margin-top: 25px;
|
||||
}
|
||||
.role {
|
||||
margin: 15px auto;
|
||||
width: 90%;
|
||||
height: 400px;
|
||||
}
|
||||
.role h3{
|
||||
border-bottom: 1px solid #000;
|
||||
}
|
||||
.role .graph-area{
|
||||
text-align: center;
|
||||
}
|
||||
.role .graph-area .loader {
|
||||
margin-top: 170px;
|
||||
}
|
||||
</style>
|
||||
<% end %>
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "//www.google.com/jsapi", "chartkick"%>
|
||||
<%= javascript_include_tag "justgage.1.0.1.min" %>
|
||||
<%= javascript_include_tag "raphael.2.1.0.min" %>
|
||||
<%= javascript_include_tag "validator" %>
|
||||
<% end %>
|
||||
<div id="analysis-area">
|
||||
<div class="analysis-form">
|
||||
<form id="analysis-form" action="/admin/activities/analysis_report" class="form-horizontal main-forms">
|
||||
<div class="input-area">
|
||||
<div class="control-group input-title">
|
||||
<label class="control-label muted"><%= t("personal_activity.year") %> : </label>
|
||||
<div class="controls">
|
||||
<%= select_year(DateTime.now.year - 5, {:start_year => DateTime.now.year, :end_year => 1950}, {:name => 'start_year', :class => "span1"} ) %>
|
||||
-
|
||||
<%= select_year(DateTime.now.year, {:start_year => DateTime.now.year, :end_year => 1950}, {:name => 'end_year', :class => "span1"} ) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button id="generate_graph" class="btn btn-info">Graphs</button>
|
||||
<a href="" id="generate_excel" class="btn btn-primary">Export</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="analysis-show-area hide in">
|
||||
<% Role.where(:disabled => false, :title.ne => "", :title.ne => nil).asc(:key).each do |role| %>
|
||||
<div class="role muted" data-role-id="<%= role.id.to_s %>">
|
||||
<h3><%= role.title %></h3>
|
||||
<div class="graph-area">
|
||||
<img class="loader" src="/assets/preloader.gif" alt="loading" width="70" height="70">
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var form = new FormValidator($("#analysis-form")),
|
||||
roleArea = $("#analysis-area .analysis-show-area"),
|
||||
totalRoles = roleArea.find(".role").length;
|
||||
form.form.on("submit",function(){return false;})
|
||||
|
||||
$("#generate_excel").on("click",function(){
|
||||
window.location.href = "/admin/activities/download_excel.xlsx?" + "year_start=" + form.form.find("select[name=start_year]").val() + "&year_end=" + form.form.find("select[name=end_year]").val();
|
||||
return false;
|
||||
})
|
||||
|
||||
$("#generate_graph").on("click",function(){
|
||||
if(form.isFormValidated()){
|
||||
generateCharts(0);
|
||||
roleArea.removeClass("hide");
|
||||
}
|
||||
return false;
|
||||
})
|
||||
|
||||
var generateCharts = function(index){
|
||||
var role = roleArea.find(".role").eq(index);
|
||||
$.ajax({
|
||||
url : "/admin/activities/analysis_report",
|
||||
data : {"role_id" : role.data("role-id"), "year_start" : form.form.find("select[name=start_year]").val(), "year_end" : form.form.find("select[name=end_year]").val(), "graph_by" : form.form.find("input[name=graph_by]:checked").val()},
|
||||
type : "get",
|
||||
dataType : "html"
|
||||
}).done(function(html){
|
||||
role.find(".graph-area").html(html);
|
||||
if(index < totalRoles){
|
||||
generateCharts(index + 1);
|
||||
}
|
||||
}).error(function(){
|
||||
role.find(".graph-area").html("There was an error loading this graph.");
|
||||
if(index < totalRoles){
|
||||
generateCharts(index + 1);
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
<%= column_chart @data, :id => params[:role_id], :height => "350px", :xtitle => "Year", :ytitle => "Total number" %>
|
|
@ -11,3 +11,4 @@ en:
|
|||
activity_start_date: "Start Date"
|
||||
activity_end_date: "End Date"
|
||||
note: "Note"
|
||||
graph_by: "Graphy By"
|
||||
|
|
|
@ -3,14 +3,14 @@ Rails.application.routes.draw do
|
|||
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
||||
namespace :admin do
|
||||
resources :activities do
|
||||
#collection do
|
||||
collection do
|
||||
# post 'merge_process' => 'books#merge_process'
|
||||
# get 'merge' => 'books#merge'
|
||||
# get 'toggle_hide' => 'books#toggle_hide'
|
||||
# get 'analysis'
|
||||
# get 'analysis_report'
|
||||
get 'analysis'
|
||||
get 'analysis_report'
|
||||
# get "download_excel"
|
||||
#end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue