Merge branch 'development' of https://github.com/Rulingcom/orbit into development

This commit is contained in:
saurabhbhatia 2013-07-19 17:39:55 +08:00
commit 109b891b27
4 changed files with 30 additions and 12 deletions

View File

@ -229,7 +229,8 @@ class ApplicationController < ActionController::Base
redirect_to ret redirect_to ret
end end
def get_sorted_and_filtered(object_class, query=nil) 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] if params[:filter] || params[:sort] || params[:new_filter]
@filter = params[:filter] @filter = params[:filter]
new_filter = params[:new_filter] new_filter = params[:new_filter]
@ -248,11 +249,10 @@ class ApplicationController < ActionController::Base
@filter = {new_filter[:type] => [new_filter[:id].to_s]} @filter = {new_filter[:type] => [new_filter[:id].to_s]}
end end
objects = get_objects(object_class, query) objects ||= get_objects(object_class, query)
object_class = object_class.classify.constantize unless params[:sort].blank?
if !params[:sort].blank?
options = params[:sort_options] options = params[:sort_options]
options = [options] if !options.class.eql?(Array) options = [options] unless options.is_a?(Array)
options.each do |option| options.each do |option|
if object_class.fields.include?(option) if object_class.fields.include?(option)
if object_class.fields[option].type.to_s.eql?('Object') && !object_class.relations[option].nil? 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 when :referenced_in
objects = get_objects_from_referenced_objects(object_class.relations[option].class_name.constantize, objects, "#{option}_id") objects = get_objects_from_referenced_objects(object_class.relations[option].class_name.constantize, objects, "#{option}_id")
end 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') elsif option.eql?('tags')
tag_array = @module_app.tags.inject([]){ |result, value| tag_array = @module_app.tags.inject([]){ |result, value|
result << [value.name, value] result << [value.name, value]
@ -381,7 +394,6 @@ class ApplicationController < ActionController::Base
end end
def get_objects(object_class, query=nil) def get_objects(object_class, query=nil)
object_class = object_class.classify.constantize
if query if query
objects = object_class.where(query) objects = object_class.where(query)
else else

View File

@ -21,9 +21,11 @@ class OrbitBackendController < ApplicationController
status << 'is_top' status << 'is_top'
status << 'is_hot' status << 'is_hot'
status << 'is_hidden' unless is_guest? status << 'is_hidden' unless is_guest?
status << 'is_pending' if is_manager? if @module_app.is_approvable && is_manager?
status << 'is_checked' if is_manager? status << 'is_pending'
status << 'is_rejected' if is_manager? status << 'is_checked'
status << 'is_rejected'
end
status status
end end

View File

@ -31,7 +31,11 @@ module OrbitCategory
def category=(id) def category=(id)
self.buffer_category.destroy if self.buffer_category self.buffer_category.destroy if self.buffer_category
self.build_buffer_category(category_id: id) self.build_buffer_category(category_id: id)
self.category_id = id self.write_attribute(:category_id, id)
end
def category_id=(id)
self.category = id
end end
def disable? def disable?

View File

@ -51,7 +51,7 @@
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t(:category) %></label> <label class="control-label muted"><%= t(:category) %></label>
<div class="controls"> <div class="controls">
<%= f.select :category, @categories.collect{|t| [ t.title, t.id ]} %> <%= f.select :category_id, @categories.collect{|t| [ t.title, t.id ]} %>
</div> </div>
</div> </div>