Add analysis and export.

This commit is contained in:
BoHung Chiu 2021-03-03 15:44:42 +08:00
parent fea246f017
commit 92eb18951c
25 changed files with 492 additions and 141 deletions

View File

@ -43,19 +43,18 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
cp_template_dir_path = "#{Rails.root}/tmp/#{@personal_plugin_field.module_name}/"
FileUtils.rm_rf(cp_template_dir_path)
FileUtils.cp_r(template_dir_path,cp_template_dir_path)
dirs = Dir.glob("#{cp_template_dir_path}*/")
files = Dir.glob("#{cp_template_dir_path}*").select { |fn| File.file?(fn) }
begin
in_use_locales = Site.first.in_use_locales
primary_modal_fields = @personal_plugin_field.primary_modal_fields.select{|f| (f[:field_name].present? rescue false)}
yml_files = Dir.glob("#{cp_template_dir_path}config/locales/*.yml")
yml_files.each do |yml_file|
locale = yml_file.split("/").last.split(".yml").first
yml_text = File.read(yml_file)
translate_hash = {}
@personal_plugin_field.primary_modal_fields.each do |field_value|
if field_value[:field_name] && (field_value[:translation_name][locale].present? rescue false)
primary_modal_fields.each do |field_value|
if (field_value[:translation_name][locale].present? rescue false)
translate_hash[field_value[:field_name]] = field_value[:translation_name][locale]
end
end
@ -88,10 +87,14 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
end
end
@blank_text = " "
slug_title = @personal_plugin_field.primary_modal_fields.select{|field_value| field_value[:slug_title] == "1" rescue false}.first[:field_name].to_s rescue ""
plugin_template_related_files = @personal_plugin_field.primary_modal_fields.select{|field_value| field_value[:field_type] == "file" rescue false}.map{|v| v[:field_name]}
slug_title = primary_modal_fields.select{|field_value| field_value[:slug_title] == "1" rescue false}.first[:field_name].to_s rescue ""
plugin_template_related_files = primary_modal_fields.select{|field_value| field_value[:field_type] == "file" rescue false}.map{|v| v[:field_name]}
plugin_template_related_links = primary_modal_fields.select{|field_value| field_value[:field_type] == "link" rescue false}.map{|v| v[:field_name]}
plugin_template_related_members = primary_modal_fields.select{|field_value| field_value[:field_type] == "member" rescue false}.map{|v| v[:field_name]}
plugin_template_related_files_text = plugin_template_related_files.to_s
plugin_template_related_files_fields = plugin_template_related_files.map{|field_name|
plugin_template_related_links_text = plugin_template_related_links.to_s
fields = plugin_template_related_files + plugin_template_related_links
plugin_template_related_files_fields = fields.map{|field_name|
"has_many :#{field_name.pluralize}, :dependent => :destroy, :autosave => true\r\n" +
"accepts_nested_attributes_for :#{field_name.pluralize}, :allow_destroy => true"
}.join("\r\n")
@ -99,15 +102,17 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
backend_index_fields = @personal_plugin_field.backend_fields["index"] rescue []
backend_index_fields_contents = backend_index_fields.map do |field_name|
if field_name == slug_title
"<%= link_to #{plugin_template}.#{field_name}, page_for_#{plugin_template}(#{plugin_template}), target: \"blank\" %>\r\n" +
"<div class=\"quick-edit\">"+
" <ul class=\"nav nav-pills hide\">"+
" <li><%= link_to t('edit'), edit_admin_#{plugin_template}_path(#{plugin_template},:page => params[:page]) %></li>"+
" <li><%= link_to t(:delete_), admin_#{plugin_template}_path(id: #{plugin_template}.id, :page => params[:page]), method: :delete, data: { confirm: 'Are you sure?' } %></li>"+
"</ul>"+
"</div>\r\n"
"\r\n <%= link_to #{plugin_template}.#{field_name}, page_for_#{plugin_template}(#{plugin_template}), target: \"blank\" %>\r\n" +
" <div class=\"quick-edit\">\r\n"+
" <ul class=\"nav nav-pills hide\">\r\n"+
" <li><%= link_to t('edit'), edit_admin_#{plugin_template}_path(#{plugin_template},:page => params[:page]) %></li>\r\n"+
" <li><%= link_to t(:delete_), admin_#{plugin_template}_path(id: #{plugin_template}.id, :page => params[:page]), method: :delete, data: { confirm: 'Are you sure?' } %></li>\r\n"+
" </ul>\r\n"+
" </div>\r\n "
elsif field_name.include?(".")
"<%= #{plugin_template}.#{field_name} rescue \"\" %>"
elsif fields.include?(field_name) || plugin_template_related_members.include?(field_name) #file or link or member
"<%= #{plugin_template}.display_field(\"#{field_name}\").html_safe rescue \"\" %>"
else
"<%= #{plugin_template}.#{field_name} %>"
end
@ -118,7 +123,7 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
extra_translate_title = col_name_to_show_in_index_page.map{|field_name| #在個人外掛前台index頁面的欄位翻譯名稱hash
["th-#{field_name}","I18n.t(\"#{@personal_plugin_field.module_name}.#{field_name}\")"]
}
col_fields = get_fields_text(@personal_plugin_field.primary_modal_fields)
col_fields = get_fields_text(primary_modal_fields)
col_related_fields = @personal_plugin_field.related_modal_fields.map{|field_values| get_fields_text(field_values)}
plugin_template_related = @personal_plugin_field.related_modal_name.select{|n| n.present?}
plugin_template_related_main_field = @personal_plugin_field.related_modal_fields.map{|field_values|
@ -128,7 +133,7 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
end
slug_titles.map{|field_value| field_value[:field_name]}.select{|t| t.present?}.first
}
locale_fields , none_locale_fields , locale_fields_input_fields,none_locale_fields_input_fields = get_input_fields(@personal_plugin_field.primary_modal_fields)
locale_fields , none_locale_fields , locale_fields_input_fields,none_locale_fields_input_fields = get_input_fields(primary_modal_fields)
related_locale_fields = []
related_none_locale_fields = []
related_locale_fields_input_fields = []
@ -144,7 +149,7 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
backend_profile_fields = backend_index_fields
backend_profile_fields_contents = backend_index_fields_contents
datetime_field_types_hash = {"year_month"=>"%Y/%m","date"=>"%Y/%m/%d","time"=>"%H:%M","date_time"=>"%Y/%m/%d %H:%M"}
datetime_fields = @personal_plugin_field.primary_modal_fields.select{|field_value| datetime_field_types_hash.keys.include?(field_value[:field_type])}.map{|field_value|
datetime_fields = primary_modal_fields.select{|field_value| datetime_field_types_hash.keys.include?(field_value[:field_type])}.map{|field_value|
[field_value[:field_name],datetime_field_types_hash[field_value[:field_type]]]
}.to_h
value_case_codes = ["value = #{plugin_template}.send(field) rescue \"\"",
@ -153,6 +158,8 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
"#{@blank_text}field.split(\".\").each{|f| value = value.send(f) rescue nil }",
"end",
"file_fields = #{plugin_template_related_files}",
"link_fields = #{plugin_template_related_links}",
"member_fields = #{plugin_template_related_members}",
"if file_fields.include?(field)",
"#{@blank_text}files = #{plugin_template}.send(field.pluralize)",
"#{@blank_text}value = files.map do |file|",
@ -161,6 +168,22 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
"#{@blank_text * 2}\"<li><a href='\#{url}'' target='_blank'>\#{title}</li>\"",
"#{@blank_text}end",
"#{@blank_text}value = value.join(\"\")",
"elsif link_fields.include?(field)",
"#{@blank_text}links = #{plugin_template}.send(field.pluralize)",
"#{@blank_text}value = links.map do |link|",
"#{@blank_text * 2}url = link.url",
"#{@blank_text * 2}title = (link.title.blank? ? url : link.title)",
"#{@blank_text * 2}\"<li><a href='\#{url}'' target='_blank'>\#{title}</li>\"",
"#{@blank_text}end",
"#{@blank_text}value = value.join(\"\")",
"elsif member_fields.include?(field)",
"#{@blank_text}members = #{plugin_template}.send(field.pluralize)",
"#{@blank_text}value = members.map{|m|",
"#{@blank_text*2}path = OrbitHelper.url_to_plugin_show(m.to_param, 'member') rescue '#'",
"#{@blank_text*2}((text_only rescue false) ? m.name : \"<a href='\#{path}'>\#{m.name}</a>\")",
"#{@blank_text}}",
"#{@blank_text}join_text = (text_only rescue false) ? \",\" : \"<br>\"",
"#{@blank_text}value = value.join(join_text)",
"end",
"strftime_hash = #{datetime_fields}",
"if strftime_hash.keys.include?(field)",
@ -178,12 +201,32 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
related_modal_name = @personal_plugin_field.related_modal_name[i]
field_names.map{|field_name| "<%= #{related_modal_name}.#{field_name} %>"}
}
member_methods_define = @personal_plugin_field.primary_modal_fields.select{|f| f[:field_type] == "member" && f[:field_name].present?}.map{|field_value|
member_methods_define = primary_modal_fields.select{|f| f[:field_type] == "member"}.map{|field_value|
["def #{field_value[:field_name].pluralize}",
" MemberProfile.find(self.#{field_value[:field_name].singularize}_ids) rescue []",
"end"]
}.flatten
@match_pattern = {"personal_plugin_template" => @personal_plugin_field.module_name,
analysis_field_name = @personal_plugin_field.backend_fields[:analysis][0] rescue ""
analysis_field_name = "year" if analysis_field_name.blank?
analysis_field_input_fields = ""
personal_plugin_template = @personal_plugin_field.module_name
iterate_step_text = "1.minute"
if analysis_field_name.present?
field_type = primary_modal_fields.select{|f| f[:field_name] == analysis_field_name}.first[:field_type] rescue "date_time"
analysis_field_input_fields = ["start","end"].map{|f|
"<span><%=t(\"#{personal_plugin_template}.extend_translate.#{f}_#{field_type}\")%></span>" +
generate_input_field(field_type,"#{analysis_field_name}_#{f}" ).gsub("<%= f.","<%= ").gsub(", :new_record => @#{plugin_template}.new_record?","")
}.join("")
if field_type == "date" || field_type == "date_time"
iterate_step_text = "1.day"
elsif field_type == "year"
iterate_step_text = "1"
end
end
time_fields = primary_modal_fields.select{|f| f[:field_type] == "time"}.map{|f| f[:field_name]}
before_save_codes = ""#time_fields.map{|f| "self.#{f} = parse_time(self.#{f}.strftime('%H:%M'))"}.join("\r\n")
@match_pattern = {"personal_plugin_template" => personal_plugin_template,
"plugin_template" => plugin_template,
"plugin_template_related" => plugin_template_related,
"plugin_template_related_files_fields" => plugin_template_related_files_fields,
@ -194,12 +237,14 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
"col_fields" => col_fields,
"col_related_fields" => col_related_fields,
"plugin_template_file" => plugin_template_related_files,
"plugin_template_link" => plugin_template_related_links,
"plugin_template_sort_hash" => "nil",
"col_name_to_show_in_index_page_arr" => col_name_to_show_in_index_page,
"related_backend_index_fields" => related_backend_index_fields,
"related_backend_index_fields_contents" => related_backend_index_fields_contents,
"backend_index_fields" => backend_index_fields,
"backend_index_fields_contents" => backend_index_fields_contents,
"plugin_template_related_links_text" => plugin_template_related_links_text,
"plugin_template_related_files_text" => plugin_template_related_files_text,
"locale_fields" => locale_fields,
"none_locale_fields" => none_locale_fields,
@ -214,7 +259,12 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
"backend_profile_fields_contents" => backend_profile_fields_contents,
"value_case_codes" => value_case_codes,
"display_field_code" => display_field_code,
"member_methods_define" => member_methods_define
"member_methods_define" => member_methods_define,
"analysis_field_name" => analysis_field_name,
"analysis_field_input_fields" => analysis_field_input_fields,
"before_save_codes" => before_save_codes,
"time_fields_text" => time_fields.to_s,
"iterate_step_text" => iterate_step_text
}
max_length = @match_pattern.keys.map{|k| k.length}.max
@match_pattern = @match_pattern.sort_by{|k,v| (v.class != Array) ? (max_length - k.length) : -k.length}
@ -225,6 +275,12 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
#end
copy_templates("#{cp_template_dir_path}modules/#{@personal_plugin_field.module_name}/")
render :html => @logs#@match_pattern#@logs.join("<br>").html_safe#@match_pattern
rescue => e
@match_pattern = {"parse_again_start"=>"","parse_again_end"=>"","col_name_translate_yaml"=>""}
replace_files(files)
replace_dirs(dirs,false)
render :html => e.backtrace.join("<br>")
end
end
def copy_templates(source)
templates = Dir.glob('app/templates/*/').select{|f| File.basename(f) != 'mobile'}
@ -242,7 +298,7 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
field_name = field_value[:field_name]
field_type = field_value[:field_type]
next if field_name.blank?
next if field_type == "file"
next if field_type == "file" || field_type == "link"
if (field_value[:localize] == "1" rescue false)
locale_fields << field_name
input_field = generate_input_field(field_type,field_name,true,extra_field_name,plugin_template)
@ -261,7 +317,7 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
plugin_template = @personal_plugin_field.primary_modal_name if plugin_template.nil?
input_field = ""
field_value_text = "@#{plugin_template}.#{field_name}"
field_name_text = ":#{field_name}"
field_name_text = "\"#{field_name}\""
field_name_text = "locale" if localize
placeholder = "#{personal_plugin_template}.#{field_name}"
placeholder = "#{personal_plugin_template}.#{extra_field_name}.#{field_name}" if extra_field_name
@ -298,17 +354,20 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
end
def get_fields_text(field_values)
fields_text = field_values.map do |field_value|
next if field_value[:field_type] == "file" || field_value[:field_name].blank?
next if field_value[:field_type] == "file" || field_value[:field_type] == "link" || field_value[:field_name].blank?
type = "String"
default = "\"\""
field_name = field_value[:field_name]
case field_value[:field_type]
when "year"
type = "Integer"
default = "DateTime.now.year"
when "date"
type = "Date"
default = "Date.parse(DateTime.now.to_s)"
when "time"
type = "Time"
default = "Time.now"
type = "String"
default = "\"\""
when "date_time"
type = "DateTime"
default = "DateTime.now"
@ -432,7 +491,7 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
break
end
end
new_text = new_text.gsub(/<% parse_again_start %>((?:(?!<% parse_again_start %>).)+)<% parse_again_end %>/m) do |ff|
new_text = new_text.gsub(/parse_again_start((?:(?!parse_again_start).)+)parse_again_end/m) do |ff|
parse_content = $1 #last match
result = ff
if include_key($1,k)

View File

@ -117,7 +117,7 @@
</div>
</div>
</div>
<% field_types = ["text_field","text_editor","file","select","year","year_month","date","time","date_time","member"].map{|field| [thead_field(field),field]}
<% field_types = ["text_field","text_editor","file","link","year","year_month","date","time","date_time","member"].map{|field| [thead_field(field),field]}
field_types1 = field_types.select{|a| a[1] != "file" && a[1] != "member"}
%>
<div class="tab-content language-area">
@ -228,7 +228,7 @@
}
})
}
$("form").submit(function(){
$(".main-forms").submit(function(){
if($("#primary_modal_plane .slug_title:checked").length == 0){
alert("<%=thead_field('please_choose_one_slug_title')%>");
}else if($("#primary_modal_plane .slug_title:checked").length > 1){

View File

@ -1,16 +1,22 @@
<div>
<% object = f.object
%>
<h5><%=thead_field(page_name)%></h5>
<table class="table table-bordered">
<button type="button" class="select_all btn"><%=t("select_all")%></button>
<button type="button" class="de_select_all btn"><%=t("de_select_all")%></button>
<table class="table table-bordered" id="<%="#{root_name}_#{page_name}"%>">
<thead>
<tr>
<% object.primary_modal_fields.each do |field_value| %>
<% next if (!access_field_types.include?(field_value[:field_type]) rescue false) %>
<th><%="#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}"%></th>
<% end %>
<% f.object.related_modal_name.each_with_index do |related_modal_name,i| %>
<% field_values = f.object.related_modal_fields[i].to_a %>
<% field_values.each do |field_value| %>
<th><%="#{related_modal_name}-#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}"%></th>
<% if page_name != "analysis" %>
<% f.object.related_modal_name.each_with_index do |related_modal_name,i| %>
<% field_values = f.object.related_modal_fields[i].to_a %>
<% field_values.each do |field_value| %>
<th><%="#{related_modal_name}-#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}"%></th>
<% end %>
<% end %>
<% end %>
</tr>
@ -20,20 +26,24 @@
<%= f.fields_for root_name do |f| %>
<%= f.fields_for page_name do |f| %>
<% object.primary_modal_fields.each do |field_value| %>
<% next if (!access_field_types.include?(field_value[:field_type]) rescue false) %>
<td>
<%= check_box_tag "#{f.object_name}[]", field_value[:field_name] , (object.send(root_name)[page_name].include?(field_value[:field_name]) rescue false),:id=>nil %>
</td>
<% end %>
<% object.related_modal_name.each_with_index do |related_modal_name,i| %>
<% field_values = object.related_modal_fields[i].to_a %>
<% field_values.each do |field_value| %>
<td>
<%= check_box_tag "#{f.object_name}[]", "#{related_modal_name+'.'+field_value[:field_name]}" , (object.send(root_name)[page_name].include?(related_modal_name+'.'+field_value[:field_name]) rescue false),:id=>nil %>
</td>
<% if page_name != "analysis" %>
<% object.related_modal_name.each_with_index do |related_modal_name,i| %>
<% field_values = object.related_modal_fields[i].to_a %>
<% field_values.each do |field_value| %>
<td>
<%= check_box_tag "#{f.object_name}[]", "#{related_modal_name+'.'+field_value[:field_name]}" , (object.send(root_name)[page_name].include?(related_modal_name+'.'+field_value[:field_name]) rescue false),:id=>nil %>
</td>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
</tr>
</tbody>
</table>
</table>
</div>

View File

@ -25,6 +25,7 @@
<h4><%= thead_field('backend_page') %></h4>
<div id="backend_page">
<%= render :partial => 'render_fields_check_table',locals: {:f=>f,:root_name=>'backend_fields',:page_name=>'index'} %>
<%= render :partial => 'render_fields_check_table',locals: {:f=>f,:root_name=>'backend_fields',:page_name=>'analysis',:access_field_types=>["date","date_time","year","year_month","time"]} %>
</div>
<h4><%= thead_field('frontend_page') %></h4>
<div id="frontend_page">
@ -41,4 +42,31 @@
<%= link_to t('cancel'), request.referer, :class=>"btn" %>
</div>
</fieldset>
<% end %>
<% end %>
<script type="text/javascript">
$(".select_all").click(function(){
$(this).parent().find("table input").prop("checked",true);
})
$(".de_select_all").click(function(){
$(this).parent().find("table input").prop("checked",false);
})
if($("#backend_fields_analysis input").length > 0){
$(".main-forms").submit(function(){
if($("#backend_fields_analysis input:checked").length == 0){
alert("<%=thead_field('please_choose_one_analysis_field')%>");
}else if($("#backend_fields_analysis input:checked").length > 1){
alert("<%=thead_field('analysis_field_can_only_choose_one')%>");
}else{
return true;
}
$('#backend_fields_analysis').css( 'border', '2px solid red');
window.location.href = "#backend_fields_analysis";
return false;
})
$('#backend_fields_analysis input').click(function(){
if($('#backend_fields_analysis input:checked').length == 1){
$('#backend_fields_analysis').css( 'border','');
}
})
}
</script>

View File

@ -35,5 +35,9 @@ en:
slug_title: Slug title
please_choose_one_slug_title: Please choose one Slug title!
slug_title_can_only_choose_one: Slug title can only choose one!
please_choose_one_analysis_field: Please choose one analysis field!
analysis_field_can_only_choose_one: Analysis field can only choose one!
generate_plugin: Generate plugin
member: Member
member: Member
link: Link
analysis: Analysis Page

View File

@ -35,5 +35,9 @@ zh_tw:
slug_title: 頭銜標題
please_choose_one_slug_title: 請至少選擇一個頭銜標題!
slug_title_can_only_choose_one: 頭銜標題只能選擇一個!
please_choose_one_analysis_field: 請至少選擇一個分析欄位!
analysis_field_can_only_choose_one: 分析欄位只能選擇一個!
generate_plugin: 生成個人外掛
member: 會員
member: 會員
link: 連結
analysis: 分析頁面

View File

@ -24,21 +24,25 @@ class Admin::PluginTemplatesController < OrbitMemberController
def show
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
analysis_field_name_start = params[:analysis_field_name_start]
analysis_field_name_end = params[:analysis_field_name_end]
graph_by = params[:graph_by]
@data = get_chart_data(year_start,year_end,role,params[:graph_by])
@data = get_chart_data(analysis_field_name_start,analysis_field_name_end,role,params[:graph_by],params[:time_zone])
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)
analysis_field_name_start = params[:analysis_field_name_start]
analysis_field_name_end = params[:analysis_field_name_end]
@data = get_data_for_excel(analysis_field_name_start,analysis_field_name_end,params[:time_zone])
@protocol = (request.referer.blank? ? "http" : URI(request.referer).scheme)
@host_url = "#{@protocol}://#{request.host_with_port}"
respond_to do |format|
format.xlsx {
response.headers['Content-Disposition'] = 'attachment; filename="plugin_templates.xlsx"'
@ -103,9 +107,9 @@ class Admin::PluginTemplatesController < OrbitMemberController
end
def get_settings
<% parse_again_start %>
parse_again_start
@plugin_template_relateds = PluginTemplateRelated.all
<% parse_again_end %>
parse_again_end
end
def set_plugin

View File

@ -1,28 +1,58 @@
module Admin::PluginTemplatesHelper
include OrbitFormHelper
alias :org_datetime_picker :datetime_picker
def datetime_picker(*arg,**args)
org_datetime_picker(arg,args)
end
def time_iterate(start_time, end_time, step, &block)
begin
yield(start_time)
end while (start_time += step) <= end_time
end
def parse_time(time_str,timezone="+08:00")
DateTime.parse("0000-01-01 " + time_str + timezone)
end
def page_for_plugin_template(plugin_template_object)
page = Page.where(:module=>"personal_plugin_template").first
("/#{I18n.locale}"+page.url+'/'+plugin_template_object.to_param).gsub('//','/') rescue "#"
end
def get_data_for_excel(year_start,year_end)
def get_data_for_excel(analysis_field_name_start,analysis_field_name_end,timezone)
analysis_field_name_start = parse_date_time_field("analysis_field_name",analysis_field_name_start,timezone)
analysis_field_name_end = parse_date_time_field("analysis_field_name",analysis_field_name_end,timezone)
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
d["data"] = PluginTemplate.where(:year.gte => year_start, :year.lte => year_end, :member_profile_id.in => mps) rescue []
d["data"] = PluginTemplate.where(:analysis_field_name.gte => analysis_field_name_start, :analysis_field_name.lte => analysis_field_name_end, :member_profile_id.in => mps) rescue []
data << d
end
return data
end
def get_chart_data(year_start,year_end,role,type)
def get_chart_data(analysis_field_name_start,analysis_field_name_end,role,type,timezone)
analysis_field_name_start = parse_date_time_field("analysis_field_name",analysis_field_name_start,timezone)
analysis_field_name_end = parse_date_time_field("analysis_field_name",analysis_field_name_end,timezone)
main_field_name = ""
time_fields = time_fields_text
max_iterate = 20
iterate_step = iterate_step_text
iterate_count = ((analysis_field_name_end - analysis_field_name_start) / iterate_step * 1.day.second).ceil
if iterate_count > max_iterate
iterate_step = (iterate_step * (iterate_count / max_iterate.to_f).ceil).second
end
case type
when "semester"
jls = CourseSemester.all
when "category"
jls = CourseCategory.all
when "default"
jls = []
parse_again_start
when "plugin_template_related"
jls = PluginTemplateRelated.all
main_field_name = "plugin_template_related_main_field"
parse_again_end
else
jls = []
end
finaldata = []
@ -33,31 +63,69 @@ module Admin::PluginTemplatesHelper
end
jls.each do |jl|
data = {}
data["name"] = jl.title
data["name"] = jl.send(main_field_name) rescue "N/A"
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.courses.where(:year.gte => year, :year.lte => year, :member_profile_id.in => mps).count rescue 0
data["data"][year.to_s] = t
time_iterate(analysis_field_name_start,analysis_field_name_end,iterate_step) do |analysis_field_name|
next_analysis_field_name = analysis_field_name + iterate_step
current_analysis_field_name = analysis_field_name
current_analysis_field_name = analysis_field_name.strftime("%H:%M") if time_fields.include?("analysis_field_name")
next_analysis_field_name = next_analysis_field_name.strftime("%H:%M") if time_fields.include?("analysis_field_name")
t = jl.plugin_templates.where(:analysis_field_name.gte => current_analysis_field_name, :analysis_field_name.lt => next_analysis_field_name, :member_profile_id.in => mps).count rescue 0
if current_analysis_field_name.class == DateTime
current_analysis_field_name = display_date_time(current_analysis_field_name,timezone,iterate_step)
end
data["data"][current_analysis_field_name.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)
time_iterate(analysis_field_name_start,analysis_field_name_end,iterate_step) do |analysis_field_name|
next_analysis_field_name = analysis_field_name + iterate_step
current_analysis_field_name = analysis_field_name
current_analysis_field_name = analysis_field_name.strftime("%H:%M") if time_fields.include?("analysis_field_name")
next_analysis_field_name = next_analysis_field_name.strftime("%H:%M") if time_fields.include?("analysis_field_name")
case type
when "semester"
t = Course.where(:year.gte => year, :year.lte => year, :member_profile_id.in => mps, :course_semester_id => nil).count rescue 0
when "category"
t = Course.where(:year.gte => year, :year.lte => year, :member_profile_id.in => mps, :course_category_id => nil).count rescue 0
when "default"
t = PluginTemplate.where(:analysis_field_name.gte => current_analysis_field_name, :analysis_field_name.lt => next_analysis_field_name, :member_profile_id.in => mps).count rescue 0
parse_again_start
when "plugin_template_related"
t = PluginTemplate.where(:analysis_field_name.gte => current_analysis_field_name, :analysis_field_name.lt => next_analysis_field_name, :member_profile_id.in => mps, :plugin_template_related_id => nil).count rescue 0
parse_again_end
else
t = PluginTemplate.where(:analysis_field_name.gte => current_analysis_field_name, :analysis_field_name.lt => next_analysis_field_name, :member_profile_id.in => mps).count rescue 0
end
data["data"][year.to_s] = t
current_analysis_field_name = current_analysis_field_name.new_offset(timezone) if current_analysis_field_name.class == DateTime
if current_analysis_field_name.class == DateTime
current_analysis_field_name = display_date_time(current_analysis_field_name,timezone,iterate_step)
end
data["data"][current_analysis_field_name.to_s] = t
end
finaldata << data
finaldata
end
def parse_date_time_field(field,value,timezone="+08:00")
time_fields = time_fields_text
if time_fields.include?(field)
parse_time(value,timezone)
elsif PluginTemplate.fields[field].type == Integer
value.to_i
elsif PluginTemplate.fields[field].type == Date
Date.parse(value)
else
DateTime.parse(value+timezone).utc
end
end
def display_date_time(date_time,timezone,iterate_step)
date_time = date_time.new_offset(timezone)
if iterate_step > 1.year
date_time = date_time.strftime("%Y")
elsif iterate_step > 1.month
date_time = date_time.strftime("%Y/%m")
elsif iterate_step > 1.day
date_time = date_time.strftime("%Y/%m/%d")
else
date_time = date_time.strftime("%Y/%m/%d %H:%M")
end
return date_time
end
end

View File

@ -10,17 +10,24 @@ class PluginTemplate
plugin_template_related_files_fields
<% parse_again_start %>
parse_again_start
belongs_to :plugin_template_related
<% parse_again_end %>
parse_again_end
field :rss2_id
belongs_to :member_profile
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(plugin_template_sort_hash) }
<% parse_again_start %>
parse_again_start
member_methods_define
<% parse_again_end %>
parse_again_end
before_save do
before_save_codes
end
def parse_time(time_str)
DateTime.parse("0000-01-01 " + time_str)
end
def self.get_plugin_datas_to_member(datas)
fields_to_show = col_name_to_show
@ -88,7 +95,7 @@ class PluginTemplate
}
end
def display_field(field)
def display_field(field,text_only=false)
plugin_template = self
display_field_code
end

View File

@ -0,0 +1,25 @@
# encoding: utf-8
require 'uri'
class PluginTemplateLink
include Mongoid::Document
include Mongoid::Timestamps
field :url
field :title, localize: true
belongs_to :plugin_template
before_validation :add_http
#validates :url, :presence => true, :format => /\A(http|https):\/\/(([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(:[0-9]{1,5})?(\/.*)?\Z/i
protected
def add_http
unless self.url[/^http:\/\//] || self.url[/^https:\/\//]
self.url = 'http://' + self.url
end
end
end

View File

@ -5,7 +5,7 @@
</div>
<div class="modal-body">
<% parse_again_start %>
parse_again_start
<div class="control-group">
<label class="control-label muted"><%= t("personal_plugin_template.plugin_template_related.related_locale_fields") %></label>
<div class="controls">
@ -23,8 +23,8 @@
</div>
</div>
</div>
<% parse_again_end %>
<% parse_again_start %>
parse_again_end
parse_again_start
<!-- related_none_locale_fields -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_plugin_template.plugin_template_related.related_none_locale_fields") %></label>
@ -32,7 +32,7 @@
related_none_locale_fields_input_fields
</div>
</div>
<% parse_again_end %>
parse_again_end
</div>
<div class="modal-footer">

View File

@ -40,7 +40,7 @@
<% @site_in_use_locales.each_with_index do |locale, i| %>
<div class="<%= locale %> tab-pane fade <%= ( i == 0 ) ? "in active" : '' %>">
<% parse_again_start %>
parse_again_start
<!-- locale_fields -->
<div class="control-group input-title">
<label class="control-label muted"><%= t("personal_plugin_template.locale_fields") %></label>
@ -48,10 +48,47 @@
locale_fields_input_fields
</div>
</div>
<% parse_again_end %>
parse_again_end
</div>
<% end %>
<!-- File -->
<!-- Link -->
<%
links_hash = {}
plugin_template_related_links_text.each do |link|
hash = {}
hash["html"] = add_attribute("form_link", f, link.pluralize.to_sym)
hash["count"] = @plugin_template.send(link.pluralize).count rescue 0
links_hash[link] = hash
%>
<div class="control-group">
<label class="control-label muted"><%= t("personal_plugin_template.#{link}") %></label>
<div class="controls">
<!-- Exist -->
<% if !@plugin_template.new_record? && hash["count"] > 0 %>
<div class="exist">
<% @plugin_template.send(link.pluralize).each_with_index do |obj, i| %>
<% if !obj.new_record? %>
<%= f.fields_for link.pluralize.to_sym, obj do |f| %>
<%= render :partial => "form_link", :object => obj, :locals => {:f => f, :i => i} %>
<% end %>
<% end %>
<% end %>
<hr>
</div>
<% end %>
<!-- Add -->
<div class="add-target" for="<%= link %>">
</div>
<p class="add-btn">
<a class="add_link trigger btn btn-small btn-primary" for="<%= link %>"><i class="icons-plus"></i> <%= t(:add) %></a>
</p>
</div>
</div>
<% end %>
<!-- File -->
<%
files_hash = {}
plugin_template_related_files_text.each do |file|
@ -127,7 +164,7 @@
</div>
<% end %>
<% parse_again_start %>
parse_again_start
<!-- none_locale_fields -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_plugin_template.none_locale_fields") %></label>
@ -135,16 +172,16 @@
none_locale_fields_input_fields
</div>
</div>
<% parse_again_end %>
<% parse_again_start %>
parse_again_end
parse_again_start
<!-- plugin_template_related -->
<div class="control-group big-group">
<label class="control-label muted"><%= t("personal_plugin_template.plugin_template_related.plugin_template_related_main_field") %></label>
<div class="controls">
<%= f.select :plugin_template_related_id, PluginTemplateRelated.all.collect {|t| [ t.plugin_template_related_main_field, t.id ]} %>
<%= f.select :plugin_template_related_id, PluginTemplateRelated.all.collect {|t| [ t.plugin_template_related_main_field, t.id ]}, { include_blank: true } %>
</div>
</div>
<% parse_again_end %>
parse_again_end
</div>
<!-- Status Module -->
<div class="tab-pane fade" id="status">
@ -180,6 +217,18 @@
return false;
})
var links = <%= links_hash.to_json.html_safe %>;
$("a.add_link").on("click",function(){
var type = $(this).attr("for"),
html = links[type].html,
count = parseInt(links[type].count),
replaceReg = new RegExp("new_" + type + "s","g");
html = html.replace(replaceReg,count);
$(".add-target[for=" + type + "]").append(html);
count++;
links[type].count = count;
return false;
})
$(document).on('click', '.delete_file', function(){
$(this).parents('.input-prepend').remove();
});

View File

@ -0,0 +1,26 @@
<div class="input-prepend input-append start-line">
<span class="add-on icons-link" title="<%= t(:url) %>"></span>
<%= f.text_field :url, class: "input-large", placeholder: t(:url) %>
<span class="add-on icons-pencil" title="<%= t(:url_alt) %>"></span>
<span class="tab-content">
<% @site_in_use_locales.each_with_index do |locale, i| %>
<span class="tab-pane fade <%= ( i == 0 ) ? "in active" : '' %> <%= locale %>">
<%= f.fields_for :title_translations do |f| %>
<%= f.text_field locale, :class => "input-large", placeholder: t(:url_alt), :value => (form_link.title_translations[locale] rescue nil) %>
<% end %>
</span>
<% end %>
</span>
<% if form_link.new_record? %>
<span class="delete_link add-on btn" title="<%= t(:delete_) %>">
<a class="icon-trash"></a>
</span>
<% else %>
<span class="remove_existing_record add-on btn" title="<%= t(:remove) %>">
<%= f.hidden_field :id %>
<a class="icon-remove"></a>
<%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
</span>
<% end %>
</div>

View File

@ -1,17 +1,17 @@
<thead>
<tr>
<% parse_again_start %>
parse_again_start
<th><%= t("personal_plugin_template.plugin_template_related.related_backend_index_fields") %></th>
<% parse_again_end %>
parse_again_end
<th><%= t(:action) %></th>
</tr>
</thead>
<tbody>
<% @plugin_template_relateds.each do |plugin_template_related| %>
<tr id="<%= dom_id plugin_template_related %>">
<% parse_again_start %>
parse_again_start
<td>related_backend_index_fields_contents</td>
<% parse_again_end %>
parse_again_end
<td class="span2">
<a href="<%= edit_admin_plugin_template_related_path(plugin_template_related) %>#plugin_template_related_modal" data-toggle="modal" data-remote="true" class="action"><%= t(:edit) %></a>
<%= link_to t(:delete_), admin_plugin_template_related_path(plugin_template_related), "data-confirm" => t('sure?'), :method => :delete, :remote => true,:class=>"archive_toggle action" %>

View File

@ -1,7 +1,7 @@
<% @plugin_templates.each do |plugin_template| %>
<tr id="<%= dom_id plugin_template %>" class="with_action">
<% parse_again_start %>
parse_again_start
<td> backend_index_fields_contents </td>
<% parse_again_end %>
parse_again_end
</tr>
<% end %>

View File

@ -32,24 +32,26 @@
<%= javascript_include_tag "justgage.1.0.1.min" %>
<%= javascript_include_tag "raphael.2.1.0.min" %>
<%= javascript_include_tag "validator" %>
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
<% end %>
<div id="analysis-area">
<div class="analysis-form">
<form id="analysis-form" action="" class="form-horizontal main-forms">
<div class="input-area">
<div class="control-group input-title">
<label class="control-label muted"><%= t("personal_course.year") %> : </label>
<label class="control-label muted"><%= t("personal_plugin_template.analysis_field_name") %> : </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"} ) %>
analysis_field_input_fields
</div>
</div>
<div class="control-group input-title">
<label class="control-label muted"><%= t("personal_course.graph_by") %> : </label>
<label class="control-label muted"><%= t("personal_plugin_template.graph_by") %> : </label>
<div class="controls">
<%= t("personal_course.course_semester") %> <input type="radio" name="graph_by" class="graph-type" value="semester">
<%= t("personal_course.course_category") %> <input data-fv-validation="required;" data-fv-messages="Please select atleast one.;" type="radio" name="graph_by" class="graph-type" value="category">
parse_again_start
<%= t("personal_plugin_template.plugin_template_related.plugin_template_related_main_field") %>
<input type="radio" name="graph_by" class="graph-type" value="plugin_template_related">
parse_again_end
</div>
</div>
</div>
@ -71,13 +73,19 @@
</div>
</div>
<script type="text/javascript">
var now = new Date();
var late_hour = -(Math.floor(now.getTimezoneOffset() / 60));
var minute = -(now.getTimezoneOffset() % 60);
var sign = (late_hour < 0) ? "-" : "+";
var time_zone_string = sign + ("00" + Math.abs(late_hour)).slice(-2) + ":"+ ("00" + Math.abs(minute)).slice(-2);
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/courses/download_excel.xlsx?" + "year_start=" + form.form.find("select[name=start_year]").val() + "&year_end=" + form.form.find("select[name=end_year]").val();
window.location.href = "/admin/plugin_templates/download_excel.xlsx?" + "analysis_field_name_start=" + form.form.find("[name=analysis_field_name_start]").val() + "&analysis_field_name_end=" + form.form.find("[name=analysis_field_name_end]").val() + "&time_zone=" +
time_zone_string;
return false;
})
@ -92,8 +100,8 @@
var generateCharts = function(index){
var role = roleArea.find(".role").eq(index);
$.ajax({
url : "/admin/courses/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()},
url : "/admin/plugin_templates/analysis_report",
data : {"role_id" : role.data("role-id"), "analysis_field_name_start" : form.form.find("[name=analysis_field_name_start]").val(), "analysis_field_name_end" : form.form.find("[name=analysis_field_name_end]").val(), "graph_by" : form.form.find("input[name=graph_by]:checked").val(),"time_zone": time_zone_string},
type : "get",
dataType : "html"
}).done(function(html){

View File

@ -1 +1 @@
<%= column_chart @data, :id => params[:role_id], :height => "350px", :xtitle => "Year", :ytitle => "Total number" %>
<%= column_chart @data, :id => params[:role_id], :height => "350px", :xtitle => "#{I18n.t("personal_plugin_template.analysis_field_name")}", :ytitle => "#{I18n.t("personal_plugin_template.extend_translate.total_number")}" %>

View File

@ -7,32 +7,65 @@ wb = xlsx_package.workbook
heading = sheet.styles.add_style(:b => true, :locked => true)
row = ["Name"]
row = [t("personal_plugin_template.author_name_translation")]
parse_again_start
@site_in_use_locales.each do |locale|
row << t("personal_course.title") + " - " + t(locale.to_s)
row << t("personal_plugin_template.locale_fields") + " - " + t(locale.to_s)
end
parse_again_end
parse_again_start
row << t("personal_plugin_template.none_locale_fields")
parse_again_end
parse_again_start
row << t("personal_plugin_template.plugin_template_related.plugin_template_related_main_field")
parse_again_end
parse_again_start
row << t("personal_plugin_template.plugin_template_file")
@site_in_use_locales.each do |locale|
row << t("personal_plugin_template.plugin_template_file") + " " + t("description") + " - " + t(locale.to_s)
end
@site_in_use_locales.each do |locale|
row << t("personal_course.objective") + " - " + t(locale.to_s)
row << t("personal_plugin_template.plugin_template_file") + " " + t("alternative") + " - " + t(locale.to_s)
end
row << t("personal_course.year")
row << t("personal_course.course_semester")
row << t("personal_course.course_category")
parse_again_end
parse_again_start
row << t("personal_plugin_template.plugin_template_link")
@site_in_use_locales.each do |locale|
row << t("personal_plugin_template.plugin_template_link") + " " + t("url_alt") + " - " + t(locale.to_s)
end
parse_again_end
sheet.add_row row, :style => heading
data.each do |course|
row = [course.member_profile.name]
data.each do |plugin_template|
row = [(plugin_template.member_profile.name rescue "")]
parse_again_start
@site_in_use_locales.each do |locale|
row << course.title_translations[locale.to_s]
row << plugin_template.locale_fields_translations[locale.to_s]
end
parse_again_end
parse_again_start
row << plugin_template.display_field("none_locale_fields",true)
parse_again_end
parse_again_start
row << (plugin_template.plugin_template_related.plugin_template_related_main_field rescue "")
parse_again_end
parse_again_start
plugin_template_files = plugin_template.plugin_template_files.asc(:created_at)
row << plugin_template_files.collect{|f| (@host_url + f.file.url rescue nil)}.join(";")
@site_in_use_locales.each do |locale|
row << plugin_template_files.collect{|l| l.description_translations[locale]}.join(";")
end
@site_in_use_locales.each do |locale|
row << course.objective_translations[locale.to_s]
row << plugin_template_files.collect{|l| l.title_translations[locale]}.join(";")
end
row << course.year
row << course.course_semester.title rescue ""
row << course.course_category.title rescue ""
parse_again_end
parse_again_start
plugin_template_links = plugin_template.plugin_template_links.asc(:created_at)
row << plugin_template_links.collect{|l| l.url}.join(";")
@site_in_use_locales.each do |locale|
row << plugin_template_links.collect{|l| l.title_translations[locale]}.join(";")
end
parse_again_end
sheet.add_row row
end
end

View File

@ -1,9 +1,9 @@
<table class="table main-list">
<thead>
<tr>
<% parse_again_start %>
parse_again_start
<th><%= t('personal_plugin_template.backend_index_fields') %></th>
<% parse_again_end %>
parse_again_end
</tr>
</thead>
<tbody id="tbody_writing_journals" class="sort-holder">

View File

@ -21,7 +21,7 @@
</style>
<div class="row">
<% parse_again_start %>
parse_again_start
<div class="element span4">
<div class="detail w-a h-a">
<p class="totle">
@ -46,10 +46,10 @@
</div>
</div>
</div>
<% parse_again_end %>
parse_again_end
</div>
<% parse_again_start %>
parse_again_start
<div>
<div style="display:none;" class="modal" id="plugin_template_related_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
</div>
@ -69,4 +69,4 @@
}
});
</script>
<% parse_again_end %>
parse_again_end

View File

@ -28,9 +28,9 @@
<% if has_access? %>
<th><input type="checkbox" /></th>
<% end -%>
<% parse_again_start %>
parse_again_start
<th><%= t('personal_plugin_template.backend_profile_fields') %></th>
<% parse_again_end %>
parse_again_end
</tr>
</thead>
<tbody>
@ -41,9 +41,9 @@
<%= check_box_tag 'to_change[]', plugin_template.id.to_s, false, :class => "list-check" %>
</td>
<% end %>
<% parse_again_start %>
parse_again_start
<td>backend_profile_fields_contents</td>
<% parse_again_end %>
parse_again_end
</tr>
<% end %>
</tbody>

View File

@ -4,4 +4,17 @@ en:
plugin_templates: personal_plugin_template_translate
plugin_template: personal_plugin_template_translate
personal_plugin_template:
extend_translate:
start_time: Start time
end_time: End time
start_date: Start date
end_date: End date
start_date_time: Start date & time
end_date_time: End date & time
start_year: Start year
end_year: End year
start_year_month: Start year/month
end_year_month: End year/month
total_number: Total number
graph_by: "Graph By"
col_name_translate_yaml

View File

@ -4,4 +4,17 @@ zh_tw:
plugin_templates: personal_plugin_template_translate
plugin_template: personal_plugin_template_translate
personal_plugin_template:
extend_translate:
start_time: 開始時間
end_time: 結束時間
start_date: 開始日期
end_date: 結束日期
start_date_time: 開始日期時間
end_date_time: 結束日期時間
start_year: 開始年分
end_year: 結束年分
start_year_month: 開始年月
end_year_month: 結束年月
total_number: 總數量
graph_by: "Graph By"
col_name_translate_yaml

View File

@ -24,9 +24,9 @@ Rails.application.routes.draw do
end
end
end
<% parse_again_start %>
parse_again_start
resources :plugin_template_relateds
<% parse_again_end %>
parse_again_end
end
end
end

View File

@ -2,16 +2,16 @@
<caption><h3>{{widget-title}}</h3></caption>
<thead>
<tr>
<% parse_again_start %>
parse_again_start
<th class="col-md-1">{{th-col_name_to_show_in_index_page_arr}}</th>
<% parse_again_end %>
parse_again_end
</tr>
</thead>
<tbody data-level="0" data-list="plugin_templates">
<tr>
<% parse_again_start %>
parse_again_start
<td>{{col_name_to_show_in_index_page_arr}}</td>
<% parse_again_end %>
parse_again_end
</tr>
</tbody>
</table>