Add category filter to admin index page.

This commit is contained in:
BOHUNG 2020-03-20 12:02:15 +08:00
parent 06ec0ff077
commit c2e3345228
6 changed files with 56 additions and 5 deletions

View File

@ -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

View File

@ -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')

View File

@ -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

View File

@ -0,0 +1,3 @@
<div class="filter-clear">
<%= 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" %>
</div>

View File

@ -0,0 +1,6 @@
<div class="accordion-inner pagination-right" data-toggle="buttons-checkbox">
<% @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'} %>
</div>

View File

@ -1,10 +1,29 @@
<% content_for :page_specific_css do -%>
<%= stylesheet_link_tag "lib/filter" %>
<% end -%>
<!-- filter -->
<div id="filter">
<ul class="nav nav-pills filter-nav pull-right">
<li class="accordion-group">
<div class="accordion-heading">
<a href="#collapse-category" data-toggle="collapse" data-parent="#filter" class="accordion-toggle"><%=t(:category)%></a>
</div>
</li>
</ul>
<div class="filter-group accordion-group">
<div class="accordion-body collapse" id="collapse-category">
<%= render :partial => "filter" %>
</div>
</div>
</div>
<!-- table -->
<table class="table main-list">
<thead>
<tr>
<th class="span1"><%= t(:category) %></th>
<th class="span1"><%= t('personal_writing.year') %></th>
<th class="span1"><%= t('personal_writing.month') %></th>
<th class="span3"><%= t('module_name.personal_writing') %></th>
<th class="span3"><%= t('personal_writing.writing_title') %></th>
<th class="span1"><%= t('users.name') %></th>
</tr>
</thead>