Put sorting in web_link, page_context and design

This commit is contained in:
Christophe Vilayphiou 2012-05-05 21:20:20 +08:00
parent b48099d752
commit f190ce18ee
23 changed files with 130 additions and 259 deletions

View File

@ -1,4 +1,4 @@
class Admin::DesignsController < ApplicationController class Admin::DesignsController < OrbitBackendController
require "net/http" require "net/http"
require "uri" require "uri"
require 'zip/zip' require 'zip/zip'
@ -25,7 +25,7 @@ class Admin::DesignsController < ApplicationController
end end
def index def index
@designs = Design.all.entries @designs = params[:sort] ? get_sorted_and_filtered("designs") : Design.all
end end
def new def new
@ -84,6 +84,13 @@ class Admin::DesignsController < ApplicationController
render :action => 'new' render :action => 'new'
end end
end end
def delete
if params[:to_delete]
designs = Design.any_in(:_id => params[:to_delete]).delete_all
end
redirect_to admin_designs_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options])
end
protected protected

View File

@ -27,9 +27,13 @@ class OrbitBackendController< ApplicationController
end end
end end
def get_sorted_and_filtered(object_class) def get_sorted_and_filtered(object_class, query=nil)
object_class = object_class.classify.constantize object_class = object_class.classify.constantize
objects = object_class.all if query
objects = object_class.all.where(query)
else
objects = object_class.all
end
if !params[:sort].blank? if !params[:sort].blank?
options = params[:sort_options] options = params[:sort_options]

View File

@ -27,7 +27,7 @@ module OrbitBackendHelper
concat (content_tag :th, :class => "span1 strong" do concat (content_tag :th, :class => "span1 strong" do
concat check_box_tag :check_all concat check_box_tag :check_all
concat link_to content_tag(:i, nil, :class => "icon-trash"), '#', :class => "list-remove" concat link_to content_tag(:i, nil, :class => "icon-trash"), '#', :class => "list-remove"
end) if delete_all && is_manager? end) if (delete_all && (is_admin? || (is_manager? rescue nil)))
titles.each do |title| titles.each do |title|
concat render_title(title[0], title[1], title[2], title[3]) concat render_title(title[0], title[1], title[2], title[3])
end end

View File

@ -3,10 +3,10 @@ class Design
include Mongoid::Timestamps include Mongoid::Timestamps
include ParserLayout include ParserLayout
field :title field :title, :type => String
field :author field :author, :type => String
field :intro field :intro, :type => String
field :version field :version, :type => String
has_many :pages has_many :pages

View File

@ -0,0 +1,14 @@
<tr class="with_action">
<td><%= check_box_tag 'to_delete[]', design.id, false, :class => "checkbox_in_list" %></td>
<td>
<%= design.title %>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<li><%= link_to t(:edit), edit_admin_design_path(design), :class => 'edit' %></li>
<li class="dropdown"><%= link_to t(:delete), admin_design_path(design), :confirm => t('sure?'), :method => :delete, :class => 'delete' %></li>
</ul>
</div>
</td>
<td><%= design.author %></td>
<td><%= design.intro %></td>
</tr>

View File

@ -0,0 +1,12 @@
<thead>
<tr>
<th class="span1 strong"></th>
<th class="span7"></th>
<th class="span2"></th>
<th class="span2"></th>
</tr>
</thead>
<tbody>
<tbody id="tbody_designs" class="sort-holder">
<%= render :partial => 'design', :collection => @designs %>
</tbody>

View File

@ -0,0 +1,11 @@
<div id='filter' class="subnav">
<div class="filters">
<div id="sort_headers" class="table-label">
<%= render 'sort_headers' %>
</div>
</div>
</div>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "sort_header" %>
<% end %>

View File

@ -0,0 +1,3 @@
<%= render_sort_bar(true, ['title', 'title','span7', 'admin.title'],
['author', 'author', 'span2', 'admin.author'],
['intro', 'intro', 'span2', 'admin.intro']).html_safe %>

View File

@ -1,52 +1,10 @@
<%= flash_messages %> <%= form_for :news_bulletins, :url => delete_admin_designs_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]), :html => {:id => 'delete_all'}, :remote => true do %>
<div id="filter" class="subnav"> <%= render 'filter' %>
<div class="filters"> <table class="table main-list">
<div id="sort_headers" class="table-label"> <%= render 'designs' %>
<table class="table main-list"> </table>
<thead> <% end %>
<tr>
<th class="span1 strong">
<input type="checkbox">
<a href class="list-remove"><i class="icon-trash"></i></a>
</th>
<th class="span7"><%= t('admin.title') %></th>
<th class="span2"><%= t('admin.author') %></th>
<th class="span2"><%= t('admin.intro') %></th>
</tr>
</thead>
</table>
</div>
</div>
</div>
<table class="table main-list">
<thead>
<tr>
<th class="span1 strong"></th>
<th class="span7"></th>
<th class="span2"></th>
<th class="span2"></th>
</tr>
</thead>
<tbody>
<% @designs.each do |design| %>
<tr class="with_action">
<td><input type="checkbox"></td>
<td>
<%= design.title %>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<li><%= link_to t(:edit), edit_admin_design_path(design), :class => 'edit' %></li>
<li class="dropdown"><%= link_to t(:delete), admin_design_path(design), :confirm => t('sure?'), :method => :delete, :class => 'delete' %></li>
</ul>
</div>
</td>
<td><%= design.author %></td>
<td><%= design.intro %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="form-actions form-fixed pagination-right"> <div class="form-actions form-fixed pagination-right">
<%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t('admin.add'), new_admin_design_path, :class => 'btn btn-primary' %> <%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t('admin.add'), new_admin_design_path, :class => 'btn btn-primary' %>
</div> </div>

View File

@ -0,0 +1,3 @@
$("#delete_all").attr("action", "<%= delete_admin_designs_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) %>");
$("#sort_headers").html("<%= j render 'sort_headers' %>");
$("#tbody_designs").html("<%= j render :partial => 'design', :collection => @designs %>");

View File

@ -37,6 +37,7 @@ Orbit::Application.routes.draw do
resources :designs do resources :designs do
collection do collection do
get 'upload_package' get 'upload_package'
post 'delete'
post 'upload_package' post 'upload_package'
end end
member do member do

View File

@ -331,87 +331,5 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
module_app = ModuleApp.first(:conditions => {:key => 'announcement'}) module_app = ModuleApp.first(:conditions => {:key => 'announcement'})
@tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc) @tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc)
end end
def get_sorted_and_filtered_bulletins
bulletins = Bulletin.all
case params[:sort]
when 'postdate', 'deadline'
bulletins = bulletins.order_by([params[:sort], params[:direction]])
when 'category'
category_ids = bulletins.distinct(:bulletin_category_id)
categories = BulletinCategory.find(category_ids) rescue nil
if categories
h = Hash.new
categories.each { |category| h[category.i18n_variable[I18n.locale]] = category.id }
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
sorted_categorys = sorted.collect {|a| bulletins.where(:bulletin_category_id => a[1]).entries }
bulletins = sorted_categorys.flatten!
end
when 'title'
h = Array.new
bulletins.each { |bulletin| h << [bulletin.title[I18n.locale].downcase, bulletin] }
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
bulletins = sorted.collect {|a| a[1] }
when 'status'
bulletins = bulletins.order_by(:is_top, params[:direction]).order_by(:is_hot, params[:direction]).order_by(:is_hidden, params[:direction]).order_by(:is_pending, params[:direction]).order_by(:is_checked, params[:direction]).order_by(:is_rejected, params[:direction])
when 'update_user_id'
user_ids = bulletins.distinct(:update_user_id)
users = User.find(user_ids) rescue nil
if users
h = Array.new
users.each { |user| h << [user.name, user.id] }
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
sorted_users = sorted.collect {|a| bulletins.where(:update_user_id => a[1]).entries }
bulletins = sorted_users.flatten
end
when 'tags'
a = Array.new
AnnouncementTag.all.order_by(I18n.locale, params[:direction]).each { |tag| a << tag.bulletins }
a.flatten!
a.uniq!
tmp = Array.new
bulletins.where(:tag_ids => []).each { |bulletin| tmp << [bulletin.title[I18n.locale].downcase, bulletin] }
sorted = params[:direction].eql?('asc') ? tmp.sort : tmp.sort.reverse!
sorted_titles = sorted.collect {|a| a[1] }
a = params[:direction].eql?('asc') ? (sorted_titles + a) : (a + sorted_titles)
bulletins = a.flatten
end
if @filter
@filter.each do |key, value|
case key
when 'status'
a = Array.new
bulletins.each do |bulletin|
value.each do |v|
case v
when 'pending'
a << bulletin if bulletin.is_checked.nil?
when 'rejected'
a << bulletin if bulletin.is_checked.eql?(false)
else
a << bulletin if bulletin[v]
end
end
end
bulletins = a.uniq
when 'categories'
a = Array.new
bulletins.each do |bulletin|
a << bulletin if value.include?(bulletin.bulletin_category.id.to_s)
end
bulletins = a.uniq
when 'tags'
a = Array.new
bulletins.each do |bulletin|
bulletin.tags.each do |tag|
a << bulletin if value.include?(tag.id.to_s)
end
end
bulletins = a.uniq
end if value.size > 0
end
end
Kaminari.paginate_array(bulletins).page(params[:page]).per(10)
end
end end

View File

@ -333,86 +333,4 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController
@tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc) @tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc)
end end
def get_sorted_and_filtered_news_bulletins
news_bulletins = NewsBulletin.all
case params[:sort]
when 'postdate', 'deadline'
news_bulletins = news_bulletins.order_by([params[:sort], params[:direction]])
when 'category'
category_ids = news_bulletins.distinct(:news_bulletin_category_id)
categories = NewsBulletinCategory.find(category_ids) rescue nil
if categories
h = Hash.new
categories.each { |category| h[category.i18n_variable[I18n.locale]] = category.id }
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
sorted_categorys = sorted.collect {|a| news_bulletins.where(:news_bulletin_category_id => a[1]).entries }
news_bulletins = sorted_categorys.flatten!
end
when 'title'
h = Array.new
news_bulletins.each { |news_bulletin| h << [news_bulletin.title[I18n.locale].downcase, news_bulletin] }
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
news_bulletins = sorted.collect {|a| a[1] }
when 'status'
news_bulletins = news_bulletins.order_by(:is_top, params[:direction]).order_by(:is_hot, params[:direction]).order_by(:is_hidden, params[:direction]).order_by(:is_pending, params[:direction]).order_by(:is_checked, params[:direction]).order_by(:is_rejected, params[:direction])
when 'update_user_id'
user_ids = news_bulletins.distinct(:update_user_id)
users = User.find(user_ids) rescue nil
if users
h = Array.new
users.each { |user| h << [user.name, user.id] }
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
sorted_users = sorted.collect {|a| news_bulletins.where(:update_user_id => a[1]).entries }
news_bulletins = sorted_users.flatten
end
when 'tags'
a = Array.new
NewsTag.all.order_by(I18n.locale, params[:direction]).each { |tag| a << tag.news_bulletins }
a.flatten!
a.uniq!
tmp = Array.new
news_bulletins.where(:tag_ids => []).each { |news_bulletin| tmp << [news_bulletin.title[I18n.locale].downcase, news_bulletin] }
sorted = params[:direction].eql?('asc') ? tmp.sort : tmp.sort.reverse!
sorted_titles = sorted.collect {|a| a[1] }
a = params[:direction].eql?('asc') ? (sorted_titles + a) : (a + sorted_titles)
news_bulletins = a.flatten
end
if @filter
@filter.each do |key, value|
case key
when 'status'
a = Array.new
news_bulletins.each do |news_bulletin|
value.each do |v|
case v
when 'pending'
a << news_bulletin if news_bulletin.is_checked.nil?
when 'rejected'
a << news_bulletin if news_bulletin.is_checked.eql?(false)
else
a << news_bulletin if news_bulletin[v]
end
end
end
news_bulletins = a.uniq
when 'categories'
a = Array.new
news_bulletins.each do |news_bulletin|
a << news_bulletin if value.include?(news_bulletin.news_bulletin_category.id.to_s)
end
news_bulletins = a.uniq
when 'tags'
a = Array.new
news_bulletins.each do |news_bulletin|
news_bulletin.tags.each do |tag|
a << news_bulletin if value.include?(tag.id.to_s)
end
end
news_bulletins = a.uniq
end if value.size > 0
end
end
Kaminari.paginate_array(news_bulletins).page(params[:page]).per(10)
end
end end

View File

@ -5,11 +5,12 @@ class Panel::PageContent::BackEnd::PageContextsController < OrbitBackendControll
def index def index
@page_contexts = PageContext.where(:archived => false).desc(:updated_at).page(params[:page]).per(10) @page_contexts = params[:sort] ? get_sorted_and_filtered("page_contexts", {:archived => false}) : PageContext.where(:archived => false).page(params[:page]).per(10)
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
format.xml { render :xml => @page_contexts } format.xml { render :xml => @page_contexts }
format.js {}
end end
end end

View File

@ -0,0 +1,11 @@
<div id='filter' class="subnav">
<div class="filters">
<div id="sort_headers" class="table-label">
<%= render 'sort_headers' %>
</div>
</div>
</div>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "sort_header" %>
<% end %>

View File

@ -0,0 +1,4 @@
<%= render_sort_bar(false, ['name', 'page','span7', 'page_context.name'],
['version', 'version', 'span2', 'page_context.version'],
['update_time', 'updated_at', 'span2', 'page_context.update_time'],
['last_modified', 'update_user_id', 'span2', 'page_context.last_modified']).html_safe %>

View File

@ -1,22 +1,6 @@
<%= flash_messages %> <%= flash_messages %>
<%= render 'filter' %>
<div id="filter" class="subnav">
<div class="filters">
<div id="sort_headers" class="table-label">
<table class="table main-list">
<thead>
<tr>
<th class="span7"><%= t('page_context.name') %></th>
<th class="span2"><%= t('page_context.version') %></th>
<th class="span2"><%= t('page_context.update_time') %></th>
<th class="span2"><%= t('page_context.last_modified') %></th>
</tr>
</thead>
</table>
</div>
</div>
</div>
<table class="table main-list"> <table class="table main-list">
<thead> <thead>
@ -27,13 +11,13 @@
<th class="span2"></th> <th class="span2"></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody id="tbody_page_contexts" class="sort-holder">
<%= render :partial => 'page_context', :collection => @page_contexts %> <%= render :partial => 'page_context', :collection => @page_contexts %>
</tbody> </tbody>
</table> </table>
<%= paginate @page_contexts %> <div id="page_context_pagination" class="paginationFixed">
<%= paginate @page_contexts, :params => {:direction => params[:direction], :sort => params[:sort]} %>
</div>

View File

@ -0,0 +1,3 @@
$("#sort_headers").html("<%= j render 'sort_headers' %>");
$("#tbody_page_contexts").html("<%= j render :partial => 'page_context', :collection => @page_contexts %>");
$("#page_context_pagination").html("<%= j paginate @page_contexts, :params => {:direction => params[:direction], :sort => params[:sort]} %>");

View File

@ -122,6 +122,13 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController
format.js format.js
end end
end end
def delete
if params[:to_delete]
web_links = WebLink.any_in(:_id => params[:to_delete]).delete_all
end
redirect_to panel_web_resource_back_end_web_links_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options])
end
protected protected

View File

@ -1,4 +1,4 @@
<%= render_sort_bar(false, ['status', ['is_top', 'is_hot', 'is_hidden', 'is_pending', 'is_checked', 'is_rejected'], 'span1', 'bulletin.status'], <%= render_sort_bar(true, ['status', ['is_top', 'is_hot', 'is_hidden', 'is_pending', 'is_checked', 'is_rejected'], 'span1', 'bulletin.status'],
['category', 'bulletin_category', 'span2', 'bulletin.category'], ['category', 'bulletin_category', 'span2', 'bulletin.category'],
['name', 'name','span3', 'bulletin.title'], ['name', 'name','span3', 'bulletin.title'],
['tags', 'tags', 'span2', 'bulletin.tags']).html_safe %> ['tags', 'tags', 'span2', 'bulletin.tags']).html_safe %>

View File

@ -1,4 +1,9 @@
<tr id="<%= dom_id web_link %>" class="with_action"> <tr id="<%= dom_id web_link %>" class="with_action">
<td>
<% if (web_link.create_user_id == current_user.id) || is_manager? %>
<%= check_box_tag 'to_delete[]', web_link.id, false, :class => "checkbox_in_list" %>
<% end -%>
</td>
<td> <td>
<div class="label-group"> <div class="label-group">
<div class="label-td"> <div class="label-td">

View File

@ -1,17 +1,20 @@
<%= render 'filter' %> <%= form_for :news_bulletins, :url => delete_panel_web_resource_back_end_web_links_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]), :html => {:id => 'delete_all'}, :remote => true do %>
<table class="table main-list"> <%= render 'filter' %>
<thead> <table class="table main-list">
<tr> <thead>
<th class="span1"></th> <tr>
<th class="span2"></th> <th class="span1"></th>
<th class="span3"></th> <th class="span1"></th>
<th class="span2"></th> <th class="span2"></th>
</tr> <th class="span3"></th>
</thead> <th class="span2"></th>
<tbody id="tbody_web_links" class="sort-holder"> </tr>
<%= render :partial => 'web_link', :collection => @web_links %> </thead>
</tbody> <tbody id="tbody_web_links" class="sort-holder">
</table> <%= render :partial => 'web_link', :collection => @web_links %>
</tbody>
</table>
<% end %>
<div id="web_link_pagination" class="paginationFixed"> <div id="web_link_pagination" class="paginationFixed">
<%= paginate @web_links, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil} %> <%= paginate @web_links, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil} %>

View File

@ -4,7 +4,11 @@ Rails.application.routes.draw do
namespace :web_resource do namespace :web_resource do
namespace :back_end do namespace :back_end do
root :to => "web_links#index" root :to => "web_links#index"
resources :web_links resources :web_links do
collection do
post 'delete'
end
end
resources :web_link_categorys resources :web_link_categorys
resources :tags resources :tags
end end