added graphs and excel export
This commit is contained in:
parent
8f92bb92ba
commit
052dc17430
|
@ -21,6 +21,28 @@ class Admin::ResearchsController < OrbitMemberController
|
||||||
end
|
end
|
||||||
end
|
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
|
||||||
|
|
||||||
|
def download_excel
|
||||||
|
year_start = params[:year_start].to_i
|
||||||
|
year_end = params[:year_end].to_i
|
||||||
|
@data = get_data_for_excel(year_start,year_end)
|
||||||
|
respond_to do |format|
|
||||||
|
format.xlsx {
|
||||||
|
response.headers['Content-Disposition'] = 'attachment; filename="research_papers.xlsx"'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
||||||
if !research_params['member_profile_id'].blank?
|
if !research_params['member_profile_id'].blank?
|
||||||
|
|
|
@ -79,4 +79,57 @@ module Admin::PersonalResearchesHelper
|
||||||
research.member_profile = mp
|
research.member_profile = mp
|
||||||
research.save
|
research.save
|
||||||
end
|
end
|
||||||
|
def get_data_for_excel(year_start,year_end)
|
||||||
|
data = []
|
||||||
|
roles = Role.where(:disabled => false, :title.ne => "", :title.ne => nil).asc(:key)
|
||||||
|
roles.each do |role|
|
||||||
|
d = {}
|
||||||
|
d["name"] = role.title
|
||||||
|
mps = role.member_profile_ids
|
||||||
|
# d1 = DateTime.new(year_start,1,1,0,0)
|
||||||
|
# d2 = DateTime.new(year_end,12,31,23,59)
|
||||||
|
d["data"] = Research.where(:year.gte => year_start, :year.lte => year_end, :member_profile_id.in => mps) rescue []
|
||||||
|
data << d
|
||||||
|
end
|
||||||
|
return data
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_chart_data(year_start,year_end,role,type)
|
||||||
|
case type
|
||||||
|
when "category"
|
||||||
|
jls = ResearchCategory.all
|
||||||
|
end
|
||||||
|
|
||||||
|
finaldata = []
|
||||||
|
role = Role.find(role) rescue nil
|
||||||
|
mps = []
|
||||||
|
if !role.nil?
|
||||||
|
mps = role.member_profile_ids
|
||||||
|
end
|
||||||
|
jls.each do |jl|
|
||||||
|
data = {}
|
||||||
|
data["name"] = jl.title
|
||||||
|
data["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 = jl.researches.where(:year => year.to_s, :member_profile_id.in => mps).count rescue 0
|
||||||
|
data["data"][year.to_s] = t
|
||||||
|
end
|
||||||
|
finaldata << data
|
||||||
|
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)
|
||||||
|
case type
|
||||||
|
when "category"
|
||||||
|
t = Research.where(:year => year, :member_profile_id.in => mps, :project_type_id => nil).count rescue 0
|
||||||
|
end
|
||||||
|
|
||||||
|
data["data"][year.to_s] = t
|
||||||
|
end
|
||||||
|
finaldata << data
|
||||||
|
finaldata
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -0,0 +1,114 @@
|
||||||
|
<% # 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/journal_papers/analysis_report" class="form-horizontal main-forms">
|
||||||
|
<div class="input-area">
|
||||||
|
<div class="control-group input-title">
|
||||||
|
<label class="control-label muted"><%= t("personal_research.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 class="control-group input-title">
|
||||||
|
<label class="control-label muted"><%= t("personal_research.graph_by") %> : </label>
|
||||||
|
<div class="controls">
|
||||||
|
<%= t("personal_research.project_category") %> <input data-fv-validation="required;" data-fv-messages="Please select atleast one.;" type="radio" name="graph_by" class="graph-type" value="category" checked="checked">
|
||||||
|
</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/researchs/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/researchs/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" %>
|
|
@ -0,0 +1,63 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
wb = xlsx_package.workbook
|
||||||
|
@data.each_with_index do |role,idx|
|
||||||
|
data = role["data"]
|
||||||
|
wb.add_worksheet(name: role["name"] + "-" + idx.to_s) do |sheet|
|
||||||
|
|
||||||
|
heading = sheet.styles.add_style(:b => true, :locked => true)
|
||||||
|
|
||||||
|
row = ["Name"]
|
||||||
|
|
||||||
|
@site_in_use_locales.each do |locale|
|
||||||
|
row << t("personal_research.research_title") + " - " + t(locale.to_s)
|
||||||
|
end
|
||||||
|
|
||||||
|
@site_in_use_locales.each do |locale|
|
||||||
|
row << t("personal_research.extracted_chapters") + " - " + t(locale.to_s)
|
||||||
|
end
|
||||||
|
|
||||||
|
@site_in_use_locales.each do |locale|
|
||||||
|
row << t("personal_research.authors") + " - " + t(locale.to_s)
|
||||||
|
end
|
||||||
|
|
||||||
|
row << t("personal_research.year")
|
||||||
|
|
||||||
|
row << t("personal_research.language")
|
||||||
|
|
||||||
|
row << t("personal_research.publication_date")
|
||||||
|
|
||||||
|
row << t("personal_research.url")
|
||||||
|
|
||||||
|
row << t("personal_research.keywords")
|
||||||
|
|
||||||
|
row << t("personal_research.note")
|
||||||
|
|
||||||
|
|
||||||
|
sheet.add_row row, :style => heading
|
||||||
|
|
||||||
|
data.each do |proj|
|
||||||
|
row = [proj.member_profile.name]
|
||||||
|
@site_in_use_locales.each do |locale|
|
||||||
|
row << proj.research_title_translations[locale.to_s]
|
||||||
|
end
|
||||||
|
|
||||||
|
@site_in_use_locales.each do |locale|
|
||||||
|
row << proj.extracted_chapters_translations[locale.to_s]
|
||||||
|
end
|
||||||
|
|
||||||
|
@site_in_use_locales.each do |locale|
|
||||||
|
row << proj.authors_translations[locale.to_s]
|
||||||
|
end
|
||||||
|
|
||||||
|
row << proj.year
|
||||||
|
row << proj.language
|
||||||
|
row << proj.publication_date.strftime("%Y-%m-%d") rescue ""
|
||||||
|
row << proj.url
|
||||||
|
row << proj.keywords
|
||||||
|
row << proj.note
|
||||||
|
|
||||||
|
sheet.add_row row
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -32,6 +32,7 @@ en:
|
||||||
description : "File Description"
|
description : "File Description"
|
||||||
pages : "Pages"
|
pages : "Pages"
|
||||||
book_paper_type : "Book Paper Type"
|
book_paper_type : "Book Paper Type"
|
||||||
|
graph_by : "Graph By"
|
||||||
frontend:
|
frontend:
|
||||||
researchs: "Research Front-end"
|
researchs: "Research Front-end"
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ zh_tw:
|
||||||
description : "描述"
|
description : "描述"
|
||||||
pages : "Pages"
|
pages : "Pages"
|
||||||
book_paper_type : "Book Paper Type"
|
book_paper_type : "Book Paper Type"
|
||||||
|
graph_by : "Graph By"
|
||||||
frontend:
|
frontend:
|
||||||
researchs: "研究前台"
|
researchs: "研究前台"
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,9 @@ Rails.application.routes.draw do
|
||||||
resources :researchs do
|
resources :researchs do
|
||||||
collection do
|
collection do
|
||||||
get 'toggle_hide' => 'researchs#toggle_hide'
|
get 'toggle_hide' => 'researchs#toggle_hide'
|
||||||
|
get 'analysis'
|
||||||
|
get 'analysis_report'
|
||||||
|
get "download_excel"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ module PersonalResearch
|
||||||
OrbitApp.registration "PersonalResearch",:type=> 'ModuleApp' do
|
OrbitApp.registration "PersonalResearch",:type=> 'ModuleApp' do
|
||||||
module_label 'module_name.personal_research'
|
module_label 'module_name.personal_research'
|
||||||
base_url File.expand_path File.dirname(__FILE__)
|
base_url File.expand_path File.dirname(__FILE__)
|
||||||
personal_plugin :enable => true, :sort_number => '20', :app_name=>"Research", :intro_app_name=>"PersonalResearchIntro",:path=>"/plugin/personal_research/profile",:front_path=>"/profile",:admin_path=>"/admin/researchs",:i18n=>'module_name.personal_research', :module_app_name=>"PersonalResearch"
|
personal_plugin :enable => true, :sort_number => '20', :app_name=>"Research", :intro_app_name=>"PersonalResearchIntro",:path=>"/plugin/personal_research/profile",:front_path=>"/profile",:admin_path=>"/admin/researchs",:i18n=>'module_name.personal_research', :module_app_name=>"PersonalResearch", :analysis => true, :analysis_path => "/admin/researchs/analysis"
|
||||||
version "0.1"
|
version "0.1"
|
||||||
desktop_enabled true
|
desktop_enabled true
|
||||||
organization "Rulingcom"
|
organization "Rulingcom"
|
||||||
|
|
Loading…
Reference in New Issue