From 62288a71ca8008fa2c2f94e6494a43edcbe0e221 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 16 Jul 2013 11:41:22 +0800 Subject: [PATCH 1/4] Fix category_id in forms Fix statuses list --- app/controllers/orbit_backend_controller.rb | 8 +++++--- lib/orbit_category/categorizable.rb | 6 +++++- .../panel/announcement/back_end/bulletins/_form.html.erb | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/orbit_backend_controller.rb b/app/controllers/orbit_backend_controller.rb index 510b09eb8..2d220cfab 100644 --- a/app/controllers/orbit_backend_controller.rb +++ b/app/controllers/orbit_backend_controller.rb @@ -21,9 +21,11 @@ class OrbitBackendController < ApplicationController status << 'is_top' status << 'is_hot' status << 'is_hidden' unless is_guest? - status << 'is_pending' if is_manager? - status << 'is_checked' if is_manager? - status << 'is_rejected' if is_manager? + if @module_app.is_approvable && is_manager? + status << 'is_pending' + status << 'is_checked' + status << 'is_rejected' + end status end diff --git a/lib/orbit_category/categorizable.rb b/lib/orbit_category/categorizable.rb index 3cd295447..1d23fba93 100644 --- a/lib/orbit_category/categorizable.rb +++ b/lib/orbit_category/categorizable.rb @@ -31,7 +31,11 @@ module OrbitCategory def category=(id) self.buffer_category.destroy if self.buffer_category self.build_buffer_category(category_id: id) - self.category_id = id + self.write_attribute(:category_id, id) + end + + def category_id=(id) + category = id end def disable? diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb index 80f80b60c..14bdb653f 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb @@ -51,7 +51,7 @@
- <%= f.select :category, @categories.collect{|t| [ t.title, t.id ]} %> + <%= f.select :category_id, @categories.collect{|t| [ t.title, t.id ]} %>
From 5190c1160a3ad9735a025c3d7dde76164a02d6ac Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 16 Jul 2013 14:43:56 +0800 Subject: [PATCH 2/4] Fix get_sorted_and_filtered, accepts 3 arguments and works for category --- app/controllers/application_controller.rb | 24 +++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7c02f1df7..053a2ec6a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -229,7 +229,7 @@ class ApplicationController < ActionController::Base redirect_to ret end - def get_sorted_and_filtered(object_class, query=nil) + def get_sorted_and_filtered(object_class, query = nil, objects = nil) if params[:filter] || params[:sort] || params[:new_filter] @filter = params[:filter] new_filter = params[:new_filter] @@ -248,11 +248,11 @@ class ApplicationController < ActionController::Base @filter = {new_filter[:type] => [new_filter[:id].to_s]} end - objects = get_objects(object_class, query) object_class = object_class.classify.constantize - if !params[:sort].blank? + objects ||= get_objects(object_class, query) + unless params[:sort].blank? options = params[:sort_options] - options = [options] if !options.class.eql?(Array) + options = [options] unless options.is_a?(Array) options.each do |option| if object_class.fields.include?(option) if object_class.fields[option].type.to_s.eql?('Object') && !object_class.relations[option].nil? @@ -272,6 +272,19 @@ class ApplicationController < ActionController::Base when :referenced_in objects = get_objects_from_referenced_objects(object_class.relations[option].class_name.constantize, objects, "#{option}_id") end + elsif option.eql?('category') + category_array = @module_app.categories.inject([]){ |result, value| + result << [value.title, value] + } + params[:direction].eql?('asc') ? category_array.sort! : category_array.sort!.reverse! + sorted_objects = Array.new + category_array.each do |x| + buffer_categories = x[1].buffer_categories + buffer_categories.each {|buffer_category| sorted_objects << buffer_category.categorizable } + end + sorted_objects.flatten! + sorted_objects.uniq! + objects = get_with_nil(objects, option, sorted_objects) elsif option.eql?('tags') tag_array = @module_app.tags.inject([]){ |result, value| result << [value.name, value] @@ -285,7 +298,7 @@ class ApplicationController < ActionController::Base sorted_objects.flatten! sorted_objects.uniq! objects = get_with_nil(objects, option, sorted_objects) - end + end end end if @filter @@ -381,7 +394,6 @@ class ApplicationController < ActionController::Base end def get_objects(object_class, query=nil) - object_class = object_class.classify.constantize if query objects = object_class.where(query) else From fc09ac3b68cbf87c67efeb40cc4389a9ac7f01fc Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 19 Jul 2013 17:09:17 +0800 Subject: [PATCH 3/4] Fix categorizable --- lib/orbit_category/categorizable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/orbit_category/categorizable.rb b/lib/orbit_category/categorizable.rb index 1d23fba93..4670dce05 100644 --- a/lib/orbit_category/categorizable.rb +++ b/lib/orbit_category/categorizable.rb @@ -35,7 +35,7 @@ module OrbitCategory end def category_id=(id) - category = id + self.category = id end def disable? From 1db324d1a29a37e5a077f4c0c28c256ca34dc207 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 19 Jul 2013 17:38:43 +0800 Subject: [PATCH 4/4] Fix get_sorted_and_filtered --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 053a2ec6a..bdb9059e3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -230,6 +230,7 @@ class ApplicationController < ActionController::Base end def get_sorted_and_filtered(object_class, query = nil, objects = nil) + object_class = object_class.classify.constantize if params[:filter] || params[:sort] || params[:new_filter] @filter = params[:filter] new_filter = params[:new_filter] @@ -248,7 +249,6 @@ class ApplicationController < ActionController::Base @filter = {new_filter[:type] => [new_filter[:id].to_s]} end - object_class = object_class.classify.constantize objects ||= get_objects(object_class, query) unless params[:sort].blank? options = params[:sort_options]