From 201d0e61d85a32795eb3e6a3e5c96ca1ad4f3b9c Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 18 Jun 2014 17:57:36 +0800 Subject: [PATCH] modified statuses and also now custom call to frontend controller is working. --- app/helpers/application_helper.rb | 103 +++++++++++++++--------------- lib/orbit_model/status.rb | 8 +++ 2 files changed, 61 insertions(+), 50 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9f90814..36cdffd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/lib/orbit_model/status.rb b/lib/orbit_model/status.rb index 9d14470..25be802 100644 --- a/lib/orbit_model/status.rb +++ b/lib/orbit_model/status.rb @@ -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 << "#{I18n.t(:top)} " if self.is_top