From 43a14b5c9ec4ece21e75b1099b3b15aa0611b819 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 2 Dec 2015 18:29:00 +0800 Subject: [PATCH] sorting and dates fixed --- .../admin/honor_types_controller.rb | 9 ++++++++ app/models/honor.rb | 12 +++++++--- app/models/honor_type.rb | 1 + .../admin/honors/_list_honor_type.html.erb | 2 +- app/views/admin/honors/setting.html.erb | 22 +++++++++++++++++-- config/routes.rb | 1 + 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/honor_types_controller.rb b/app/controllers/admin/honor_types_controller.rb index 0685185..3126836 100644 --- a/app/controllers/admin/honor_types_controller.rb +++ b/app/controllers/admin/honor_types_controller.rb @@ -14,6 +14,15 @@ class Admin::HonorTypesController < OrbitMemberController render :partial=>'list', :layout=>false end + def update_order + orders = params["order"] + HonorType.each do |ht| + ht.sort_position = orders["#{ht.id}"] + ht.save + end + render :json => {"success" => true}.to_json + end + def edit @honor_type = HonorType.find(params[:id]) @url = admin_honor_type_path(@honor_type) diff --git a/app/models/honor.rb b/app/models/honor.rb index 51e718a..1c26e11 100644 --- a/app/models/honor.rb +++ b/app/models/honor.rb @@ -22,6 +22,8 @@ class Honor before_validation :add_http + scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc") } + def slug_title self.award_name+' '+self.awarding_unit rescue "" end @@ -39,6 +41,7 @@ class Honor def self.get_plugin_datas_to_member(datas) fields_to_show = [ + "honor_type", "year", "award_name", "awarding_unit" @@ -50,23 +53,26 @@ class Honor } end - plugin_datas = datas.where(:is_hidden=>false).order_by(:year=>'desc').collect do |p| + plugin_datas = datas.sort_for_frontend.collect do |p| pd_data = [] fields_to_show.collect do |t| if t == "award_name" pd_data << { "data_title" => "#{p.send(t)}" } + elsif t == "honor_type" + pd_data << {"data_title" => (p.honor_type.title rescue "")} else pd_data << { "data_title" => p.send(t) } end end { - "pd_datas" => pd_data + "pd_datas" => pd_data, + "type-sort" => (p.honor_type.sort_position rescue 1000) } end - + plugin_datas = plugin_datas.sort{|k,v| k["type-sort"] <=> v["type-sort"]} return [pd_title,plugin_datas] end diff --git a/app/models/honor_type.rb b/app/models/honor_type.rb index 543ddad..4d7a51d 100644 --- a/app/models/honor_type.rb +++ b/app/models/honor_type.rb @@ -3,6 +3,7 @@ class HonorType include Mongoid::Timestamps field :title, localize: true + field :sort_position, :type => Integer, :default => 0 has_many :honors end \ No newline at end of file diff --git a/app/views/admin/honors/_list_honor_type.html.erb b/app/views/admin/honors/_list_honor_type.html.erb index 269de0e..214e0db 100644 --- a/app/views/admin/honors/_list_honor_type.html.erb +++ b/app/views/admin/honors/_list_honor_type.html.erb @@ -1,4 +1,4 @@ - + <%= list_honor_type.title %> diff --git a/app/views/admin/honors/setting.html.erb b/app/views/admin/honors/setting.html.erb index 768d8c6..4b6e5d2 100644 --- a/app/views/admin/honors/setting.html.erb +++ b/app/views/admin/honors/setting.html.erb @@ -1,3 +1,6 @@ +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/jquery-ui-sortable.min" %> +<% end %>