modified statuses and also now custom call to frontend controller is working.

This commit is contained in:
Harry Bomrah 2014-06-18 17:57:36 +08:00
parent 06df84df57
commit 201d0e61d8
2 changed files with 61 additions and 50 deletions

View File

@ -198,63 +198,66 @@ module ApplicationHelper
html = html.gsub("{{pagination_goes_here}}","");
end
html.html_safe
elsif params[:target_action] == "show"
file = File.open(File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "#{params[:target_action]}.html.erb"))
doc = Nokogiri::HTML(file, nil, "UTF-8")
file.close
controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new
data = controller.send("#{params[:target_action]}")
if data.blank? || data.empty?
file = File.open("#{Rails.root}/public/404.html")
else
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "#{params[:target_action]}.html.erb")
if File.exists?f
file = File.open(f)
doc = Nokogiri::HTML(file, nil, "UTF-8")
file.close
doc.to_html.html_safe
else
unless data['impressionist'].blank?
impression = data['impressionist'].impressions.create
impression.user_id = request.session['user_id']
impression.controller_name = params[:target_controller]
impression.action_name = params[:target_action]
impression.ip_address = request.remote_ip
impression.session_hash = request.session.id
impression.request_hash = @impressionist_hash
impression.referrer = request.referrer
impression.save
data['impressionist'].view_count = data['impressionist'].impressions.count
data['impressionist'].save
end
wrap_elements = doc.css("*[data-list][data-level='0']")
if wrap_elements.count == 0
wrap_element_html = doc.to_s
el = wrap_element_html
data.each do |key,value|
next if key.eql? 'impressionist'
value = value.nil? ? "" : value
el = el.gsub("{{#{key}}}",value.to_s)
el = el.gsub("%7B%7B#{key}%7D%7D",value.to_s)
end
el.html_safe
controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new
data = controller.send("#{params[:target_action]}")
if data.blank? || data.empty?
file = File.open("#{Rails.root}/public/404.html")
doc = Nokogiri::HTML(file, nil, "UTF-8")
file.close
doc.to_html.html_safe
else
keys = data.keys
not_array_key = nil
data.keys.each do |key|
not_array_key = key if data["#{key}"].kind_of?(Hash)
unless data['impressionist'].blank?
impression = data['impressionist'].impressions.create
impression.user_id = request.session['user_id']
impression.controller_name = params[:target_controller]
impression.action_name = params[:target_action]
impression.ip_address = request.remote_ip
impression.session_hash = request.session.id
impression.request_hash = @impressionist_hash
impression.referrer = request.referrer
impression.save
data['impressionist'].view_count = data['impressionist'].impressions.count
data['impressionist'].save
end
htmls = parsing_repeats_again(wrap_elements,data,1)
html = doc.to_s
htmls[0].each_with_index do |h,i|
html = html.gsub(h,htmls[1][i])
end
if data["#{not_array_key}"]
data["#{not_array_key}"].each do |key,value|
next if key.eql? 'impressionist'
wrap_elements = doc.css("*[data-list][data-level='0']")
if wrap_elements.count == 0
wrap_element_html = doc.to_s
el = wrap_element_html
data.each do |key,value|
next if key.eql? 'impressionist'
value = value.nil? ? "" : value
html = html.gsub("{{#{key}}}",value.to_s)
html = html.gsub("%7B%7B#{key}%7D%7D",value.to_s)
el = el.gsub("{{#{key}}}",value.to_s)
el = el.gsub("%7B%7B#{key}%7D%7D",value.to_s)
end
el.html_safe
else
keys = data.keys
not_array_key = nil
data.keys.each do |key|
not_array_key = key if data["#{key}"].kind_of?(Hash)
end
htmls = parsing_repeats_again(wrap_elements,data,1)
html = doc.to_s
htmls[0].each_with_index do |h,i|
html = html.gsub(h,htmls[1][i])
end
if data["#{not_array_key}"]
data["#{not_array_key}"].each do |key,value|
next if key.eql? 'impressionist'
value = value.nil? ? "" : value
html = html.gsub("{{#{key}}}",value.to_s)
html = html.gsub("%7B%7B#{key}%7D%7D",value.to_s)
end
end
html.html_safe
end
html.html_safe
end
end
end

View File

@ -27,6 +27,14 @@ module OrbitModel
statuses
end
def statuses_with_classname
statuses = []
statuses << {"name" => I18n.t(:top), "classname" => "top"} if is_top?
statuses << {"name" => I18n.t(:hot), "classname" => "hot"} if is_hot?
statuses << {"name" => I18n.t(:hidden), "classname" => "hidden"} if is_hidden?
statuses
end
def status_for_table
status = ""
status << "<span class='label label-success'>#{I18n.t(:top)}</span> " if self.is_top