diff --git a/app/controllers/admin/project_types_controller.rb b/app/controllers/admin/project_types_controller.rb index 75a8d77..8e6d4a2 100644 --- a/app/controllers/admin/project_types_controller.rb +++ b/app/controllers/admin/project_types_controller.rb @@ -14,6 +14,15 @@ class Admin::ProjectTypesController < OrbitMemberController render :partial=>'list', :layout=>false end + def update_order + orders = params["order"] + ProjectType.each do |pt| + pt.sort_position = orders["#{pt.id}"] + pt.save + end + render :json => {"success" => true}.to_json + end + def edit @project_type = ProjectType.find(params[:id]) @url = admin_project_type_path(@project_type) diff --git a/app/models/project.rb b/app/models/project.rb index fc7e8e2..671542b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -34,6 +34,8 @@ class Project before_validation :add_http + scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year=>'desc', :period_start_date=>'desc') } + def duration "#{self.period_start_date.strftime("%Y.%m") rescue ""} ~ #{self.period_end_date.strftime("%Y.%m") rescue ""}" end @@ -41,6 +43,7 @@ class Project def self.get_plugin_datas_to_member(datas) fields_to_show = [ + "project_type", "year", "project_title", "participator", @@ -55,7 +58,7 @@ class Project } end - plugin_datas = datas.where(:is_hidden=>false).order_by(:period_start_date=>'desc',:year=>'desc').collect do |p| + plugin_datas = datas.sort_for_frontend.collect do |p| pd_data = [] fields_to_show.collect do |t| @@ -70,17 +73,20 @@ class Project end pd_data << { "data_title" => date } + elsif t == "project_type" + pd_data << {"data_title" => (p.project_type.title rescue "")} else pd_data << { "data_title" => p.send(t) } end end { - "pd_datas" => pd_data + "pd_datas" => pd_data, + "type-sort" => (p.project_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/project_type.rb b/app/models/project_type.rb index d2811fb..9dbf0a8 100644 --- a/app/models/project_type.rb +++ b/app/models/project_type.rb @@ -3,6 +3,7 @@ class ProjectType include Mongoid::Timestamps field :title, localize: true + field :sort_position, type: Integer, default: 0 has_many :projects diff --git a/app/views/admin/projects/_form.html.erb b/app/views/admin/projects/_form.html.erb index 01e62e6..e4e0d17 100644 --- a/app/views/admin/projects/_form.html.erb +++ b/app/views/admin/projects/_form.html.erb @@ -181,7 +181,7 @@
- <%= f.datetime_picker :period_start_date, :no_label => true, :format=>"yyyy/MM" %> + <%= f.datetime_picker :period_start_date, :format=>"yyyy/MM", :value=> @project.period_start_date, :new_record => @project.new_record? %>
@@ -189,7 +189,7 @@
- <%= f.datetime_picker :period_end_date, :no_label => true, :format=>"yyyy/MM" %> + <%= f.datetime_picker :period_end_date, :no_label => true, :format=>"yyyy/MM", :value=> @project.period_end_date, :new_record => @project.new_record? %>
diff --git a/app/views/admin/projects/_list_project_type.html.erb b/app/views/admin/projects/_list_project_type.html.erb index 3a916cd..5eacad0 100644 --- a/app/views/admin/projects/_list_project_type.html.erb +++ b/app/views/admin/projects/_list_project_type.html.erb @@ -1,4 +1,4 @@ - + <%= list_project_type.title %> diff --git a/app/views/admin/projects/setting.html.erb b/app/views/admin/projects/setting.html.erb index f7252ef..3ad76ca 100644 --- a/app/views/admin/projects/setting.html.erb +++ b/app/views/admin/projects/setting.html.erb @@ -1,3 +1,6 @@ +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/jquery-ui-sortable.min" %> +<% end %>