add the feature that let user can modify the show
order of categories for index and widget by themselves
This commit is contained in:
parent
526ceabda0
commit
7abd0b4e39
|
@ -7,7 +7,24 @@ class Admin::ArchiveFilesController < OrbitAdminController
|
|||
redirect_to '/' + I18n.locale.to_s + module_pages[0] + '?title=' + params['title'].to_s
|
||||
end
|
||||
end
|
||||
def save_categories_order
|
||||
keys = params['data_keys']
|
||||
values = params['data_values']
|
||||
keys.each do |key|
|
||||
key.slice! 'sort_number-'
|
||||
end
|
||||
keys.each_with_index do |key,index|
|
||||
archivecategory = ArchiveCategory.where(category_id: key)
|
||||
if !(values[index].empty?)
|
||||
archivecategory.first.update_attributes(sort_number: values[index].to_i)
|
||||
else
|
||||
archivecategory.first.update_attributes(sort_number: nil)
|
||||
end
|
||||
end
|
||||
render :json => {}.to_json
|
||||
end
|
||||
def index
|
||||
|
||||
if ArchiveSortOrder.count == 0
|
||||
ArchiveSortOrder.new('sort_order' => false).save
|
||||
end
|
||||
|
@ -48,7 +65,21 @@ class Admin::ArchiveFilesController < OrbitAdminController
|
|||
render_401
|
||||
end
|
||||
end
|
||||
|
||||
def categories_order
|
||||
categories = @module_app.categories
|
||||
categories.each do |category|
|
||||
archive_cat = ArchiveCategory.all.select{ |value| value.category_id.to_s == category.id.to_s}
|
||||
if archive_cat.length == 0
|
||||
ArchiveCategory.create(category_id: category.id.to_s)
|
||||
end
|
||||
end
|
||||
cats_with_nil = ArchiveCategory.all.in(sort_number: nil)
|
||||
cats_no_nil = ArchiveCategory.all.not_in(sort_number: nil).order_by(sort_number: 'desc')
|
||||
@cats = cats_no_nil.concat(cats_with_nil).collect do |cat|
|
||||
[categories.where(:_id => cat.category_id).first,cat.sort_number.to_s]
|
||||
end
|
||||
render :partial => "categories_order" if request.xhr?
|
||||
end
|
||||
def create
|
||||
@archive_file = ArchiveFile.new(archive_vars)
|
||||
@archive_file.create_user_id = current_user.id
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
class ArchivesController < ApplicationController
|
||||
def index
|
||||
#avoid the categories to be not in the ArchiveCategory
|
||||
check_cat_sort_data()
|
||||
if ArchiveSortOrder.count == 0
|
||||
ArchiveSortOrder.new('sort_order' => false).save
|
||||
end
|
||||
|
@ -7,8 +9,9 @@ class ArchivesController < ApplicationController
|
|||
if !params['title'].nil?
|
||||
files_by_cateogry = ArchiveFile.where(is_hidden: false).group_by(&:category)
|
||||
categories = files_by_cateogry.keys
|
||||
categories_sort = get_sorted_cat_with_filter(categories,'orm')
|
||||
cats_last = []
|
||||
categories.each do |category|
|
||||
categories_sort.each do |category|
|
||||
url_to_edit = ""
|
||||
flag = false
|
||||
archives = []
|
||||
|
@ -66,7 +69,8 @@ class ArchivesController < ApplicationController
|
|||
files_by_cateogry = ArchiveFile.where(is_hidden: false).filter_by_categories.filter_by_tags.group_by(&:category)
|
||||
each_data_count = []
|
||||
categories = files_by_cateogry.keys
|
||||
cats = categories.collect do |category|
|
||||
categories_sort = get_sorted_cat_with_filter(categories,'orm')
|
||||
cats = categories_sort.collect do |category|
|
||||
url_to_edit = OrbitHelper.user_has_cateogry?(category) ? "/admin/archive_files?filters[category][]=#{category.id.to_s}" : ""
|
||||
archives = files_by_cateogry[category].collect do |archive|
|
||||
statuses = archive.statuses_with_classname.collect do |status|
|
||||
|
@ -247,24 +251,31 @@ F cats = files_by_cateogry.keys.collect do |cat|
|
|||
end
|
||||
|
||||
def widget
|
||||
begin
|
||||
check_cat_sort_data()
|
||||
if ArchiveSortOrder.count == 0
|
||||
ArchiveSortOrder.new('sort_order' => false).save
|
||||
end
|
||||
page_data_count = OrbitHelper.widget_data_count
|
||||
categories = OrbitHelper.widget_categories
|
||||
categories = OrbitHelper.widget_categories #data are categories' ids or 'all'
|
||||
@categories = []
|
||||
if categories.first == "all"
|
||||
module_app = OrbitHelper.widget_module_app
|
||||
@categories = module_app.categories.collect do |cat|
|
||||
categories = OrbitHelper.widget_module_app.categories
|
||||
puts categories
|
||||
categories_sort = get_sorted_cat_with_filter(categories,'orm')
|
||||
@categories = categories_sort.collect do |cat|
|
||||
{
|
||||
"title" => cat.title,
|
||||
"id" => cat.id.to_s
|
||||
}
|
||||
end
|
||||
else
|
||||
categories.each do |cat|
|
||||
c = Category.find(cat)
|
||||
@categories << {"title" => c.title, "id" => c.id.to_s}
|
||||
categories_sort = get_sorted_cat_with_filter(categories,'id')
|
||||
@categories = categories_sort.collect do |cat|
|
||||
{
|
||||
"title" => cat.title,
|
||||
"id" => cat.id.to_s
|
||||
}
|
||||
end
|
||||
end
|
||||
cats = @categories.collect do |cat|
|
||||
|
@ -306,13 +317,44 @@ F cats = files_by_cateogry.keys.collect do |cat|
|
|||
"archives" => archives
|
||||
}
|
||||
end
|
||||
rescue => e
|
||||
puts e
|
||||
end
|
||||
{
|
||||
"categories" => cats,
|
||||
"extras" => {"widget-title" => "Archives","more_url" => (OrbitHelper.widget_more_url + '?data_count=' + page_data_count.to_s)}
|
||||
}
|
||||
end
|
||||
private
|
||||
def self.get_total_pages
|
||||
@@total_pages
|
||||
end
|
||||
def get_sorted_cat_with_filter(categories,cat_type)
|
||||
all_categories_with_nil = ArchiveCategory.all.in(sort_number: nil)
|
||||
all_categories_no_nil = ArchiveCategory.all.not_in(sort_number: nil).order_by(sort_number: 'desc')
|
||||
all_categories_id = all_categories_no_nil.concat(all_categories_with_nil).collect do |cat|
|
||||
cat.category_id.to_s
|
||||
end
|
||||
if cat_type=='id'
|
||||
categories_temp = ModuleApp.where(:key => "archive").first.categories
|
||||
categories = categories_temp.select{|cat| categories.include? cat.id.to_s}
|
||||
end
|
||||
categories_sort = []
|
||||
all_categories_id.each do |cat_id|
|
||||
category_selected = categories.select{|category| cat_id == category.id.to_s}
|
||||
if category_selected.length!=0
|
||||
categories_sort << category_selected[0]
|
||||
end
|
||||
end
|
||||
categories_sort
|
||||
end
|
||||
def self.get_total_pages
|
||||
@@total_pages
|
||||
end
|
||||
def check_cat_sort_data
|
||||
categories_temp = ModuleApp.where(:key => "archive").first.categories
|
||||
categories_temp.each do |category|
|
||||
archive_cat = ArchiveCategory.all.select{ |value| value.category_id.to_s == category.id.to_s}
|
||||
if archive_cat.length == 0
|
||||
ArchiveCategory.create(category_id: category.id.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class ArchiveCategory
|
||||
include Mongoid::Document
|
||||
field :category_id, type: String
|
||||
field :sort_number, type: Integer
|
||||
end
|
|
@ -0,0 +1,60 @@
|
|||
<% all_locales = I18n.available_locales %>
|
||||
<% count = all_locales.length %>
|
||||
<script type='text/javascript'>
|
||||
$('.category_sort_number_form').ready(function(){
|
||||
$('form[name="category_sort_number_form"]').submit(function(){
|
||||
var eles = $('form[name="category_sort_number_form"]').serialize().split('&')
|
||||
var keys=[],values=[]
|
||||
for (var i=0;i<eles.length;i++){
|
||||
var temp = eles[i].split('=')
|
||||
keys.push(temp[0])
|
||||
values.push(temp[1])
|
||||
}
|
||||
if (navigator.onLine) {
|
||||
$.ajax({
|
||||
url : "/admin/archive_files/categories_order",
|
||||
dataType : "json",
|
||||
type : "post",
|
||||
data:{data_keys: keys, data_values: values},
|
||||
success:function(data){
|
||||
location.reload();
|
||||
},
|
||||
error:function(){
|
||||
alert('Your server has some problem, please try again later!')
|
||||
}
|
||||
})
|
||||
} else {
|
||||
alert('Please connect the network and try again later!')
|
||||
}
|
||||
return false;
|
||||
})
|
||||
})
|
||||
</script>
|
||||
<div class='category_sort_number_form'>
|
||||
<form method="post" action="/admin/archive_files/categories_order?" name="category_sort_number_form" >
|
||||
<table>
|
||||
<thead style='line-height: 3;'>
|
||||
<tr style="text-align: center;">
|
||||
<td><%= t('archive.category') %></td>
|
||||
<td><%= t('archive.sort_number') %></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody style='line-height: 4;'>
|
||||
<% @cats.each do |cat| %>
|
||||
<tr>
|
||||
<td style='padding-right: 10px;'>
|
||||
<% all_locales.each_with_index do |locale,index| %>
|
||||
<%= "#{cat[0][:title][locale]}" %>
|
||||
<%= index!=(count-1) ? "/" : ":" %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<input style='margin: 0;' type="number" name="sort_number-<%= cat[0].id %>" value="<%= cat[1].to_s %>">
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<input type="submit" value="<%= t('archive.save') %>">
|
||||
</form>
|
||||
</div>
|
|
@ -1,12 +1,17 @@
|
|||
en:
|
||||
|
||||
restful_actions:
|
||||
categories_order: Categories Order
|
||||
archive:
|
||||
category: Category
|
||||
sort_number: Sort Order
|
||||
save: Save
|
||||
no_page: You have to create at least one page for archive module
|
||||
choose_order: Order with ascending
|
||||
"yes": "Yes"
|
||||
"no": "No"
|
||||
archive: Archive
|
||||
all: All
|
||||
categories_order: Categories Order
|
||||
new: New
|
||||
downloaded_times: Downloaded Times
|
||||
show_lang: Language
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
zh_tw:
|
||||
|
||||
restful_actions:
|
||||
categories_order: 類別排序
|
||||
archive:
|
||||
category: 類別
|
||||
sort_number: 排序號碼
|
||||
save: 儲存
|
||||
no_page: 請至少為檔案室模組新增一頁內容頁
|
||||
choose_order: 升序排列
|
||||
"yes": 是
|
||||
|
@ -8,6 +12,7 @@ zh_tw:
|
|||
show_lang: 呈現語系
|
||||
download: 檔案下載
|
||||
archive: 檔案室
|
||||
categories_order: 類別排序
|
||||
Title: 標題
|
||||
downloaded_times: 下載次數
|
||||
Files: 檔案
|
||||
|
|
|
@ -4,6 +4,8 @@ locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_l
|
|||
|
||||
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
||||
namespace :admin do
|
||||
get 'archive_files/categories_order' => 'archive_files#categories_order'
|
||||
post 'archive_files/categories_order' => 'archive_files#save_categories_order'
|
||||
resources :archive_files
|
||||
end
|
||||
get "/xhr/archive/download" => "archives#download_file"
|
||||
|
|
|
@ -43,6 +43,11 @@ module Archive
|
|||
:active_for_action=>{'admin/archive_files'=>'tags'},
|
||||
:active_for_tag => 'Archive',
|
||||
:available_for => 'managers'
|
||||
context_link 'archive.categories_order',
|
||||
:link_path=>"admin_archive_files_categories_order_path" ,
|
||||
:priority=>5,
|
||||
:active_for_action=>{'admin/archive_files'=>'categories_order'},
|
||||
:available_for => 'managers'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue