diff --git a/app/controllers/admin/writings_controller.rb b/app/controllers/admin/writings_controller.rb index 9ed489d..1eaea07 100644 --- a/app/controllers/admin/writings_controller.rb +++ b/app/controllers/admin/writings_controller.rb @@ -10,7 +10,27 @@ class Admin::WritingsController < OrbitMemberController before_action :allow_admin_only, :only => [:index, :setting] def index - @writings = Writing.order_by(:year=>'desc').page(params[:page]).per(10) + @filter = params[:filter] + @mq = params[:mq] + @new_filter = params[:new_filter] + @filter = {} if @filter.nil? + @filter['category'] = [] if @filter['category'].nil? + if @new_filter.present? + if @filter['category'].include? @new_filter[:id] + @filter['category'].delete(@new_filter[:id]) + else + @filter['category'] << @new_filter[:id] + end + end + if params[:clear] != 'true' + if(params[:new_filter] != nil && params[:new_filter][:type] == 'category') + @writings = Writing.where(:category_id.in=> @filter['category']).order_by(:year=>'desc').page(params[:page]).per(10) + else + @writings = Writing.order_by(:year=>'desc').page(params[:page]).per(10) + end + else + redirect_to admin_writings_url + end end def new @@ -179,6 +199,9 @@ class Admin::WritingsController < OrbitMemberController def set_plugin @plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'Writing'}.first + @module_app = ModuleApp.where(:key=>'personal_writing').first + @module_app = ModuleApp.create(:key=>'personal_writing',:title=>'PersonalWriting','frontend_enable'=>true) if @module_app.nil? + @categories = @module_app.categories end private diff --git a/app/controllers/personal_writings_controller.rb b/app/controllers/personal_writings_controller.rb index 735274a..c6aeeb1 100644 --- a/app/controllers/personal_writings_controller.rb +++ b/app/controllers/personal_writings_controller.rb @@ -17,7 +17,7 @@ class PersonalWritingsController < ApplicationController "widget-title" => t("module_name.personal_writing"), "th_year" => t('personal_writing.year'), "th_month" => t('personal_writing.month'), - "th_writing_title" => t('module_name.personal_writing'), + "th_writing_title" => t('personal_writing.writing_title'), "th_other" => t('personal_writing.other'), "th_member" => t('users.name'), "th_detail" => t('detail') diff --git a/app/helpers/admin/personal_writings_helper.rb b/app/helpers/admin/personal_writings_helper.rb index 974c912..a1571ec 100644 --- a/app/helpers/admin/personal_writings_helper.rb +++ b/app/helpers/admin/personal_writings_helper.rb @@ -80,7 +80,7 @@ module Admin::PersonalWritingsHelper def get_chart_data(year_start,year_end,role,type) case type when "category" - jls = ResearchCategory.all + jls = @module_app.categories end finaldata = [] @@ -96,7 +96,7 @@ module Admin::PersonalWritingsHelper (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 + t = Writing.where(:year => year.to_s, :member_profile_id.in => mps,:category_id=>jl.id).count rescue 0 data["data"][year.to_s] = t end finaldata << data diff --git a/app/views/admin/writings/_clear_filters.html.erb b/app/views/admin/writings/_clear_filters.html.erb new file mode 100644 index 0000000..d8ff178 --- /dev/null +++ b/app/views/admin/writings/_clear_filters.html.erb @@ -0,0 +1,3 @@ +
+ <%= link_to content_tag(:i, nil, :class => 'icons-cycle') + t(:clear), url_for(:filter => @filter, :sort => params[:sort], :direction => params[:direction], :clear => true, :type => type), :class => "btn btn-link btn-small" %> +
\ No newline at end of file diff --git a/app/views/admin/writings/_filter.html.erb b/app/views/admin/writings/_filter.html.erb new file mode 100644 index 0000000..3cce19f --- /dev/null +++ b/app/views/admin/writings/_filter.html.erb @@ -0,0 +1,6 @@ +
+ <% @categories.each do |category| %> + <%= link_to category.title, url_for(:at=>params[:at],:filter => @filter, :new_filter => {:type => 'category', :id => category.id}, :sort => params[:sort], :direction => params[:direction], :sort_options => params[:sort_options]), :class => "btn btn-small #{' active' if (@filter['category'].include?(category.id.to_s) rescue nil)}" %> + <% end %> + <%= render :partial => 'clear_filters', :locals => {:type => 'category'} %> +
\ No newline at end of file diff --git a/app/views/admin/writings/index.html.erb b/app/views/admin/writings/index.html.erb index 2ba486c..ac89feb 100644 --- a/app/views/admin/writings/index.html.erb +++ b/app/views/admin/writings/index.html.erb @@ -1,10 +1,29 @@ +<% content_for :page_specific_css do -%> + <%= stylesheet_link_tag "lib/filter" %> +<% end -%> + +
+ +
+
+ <%= render :partial => "filter" %> +
+
+
+ - +
<%= t(:category) %> <%= t('personal_writing.year') %> <%= t('personal_writing.month') %><%= t('module_name.personal_writing') %><%= t('personal_writing.writing_title') %> <%= t('users.name') %>