Module: RailsDbAdmin::Extensions::Railties::ActionView::Helpers::ReportHelper
- Defined in:
- lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb
Instance Method Summary collapse
- #bootstrap_load ⇒ Object
- #jquery_load ⇒ Object
- #name_and_path_from_source(source, base_directory) ⇒ Object
- #render_template(template, locals = nil) ⇒ Object
- #report_download_link(report_iid, format, display = nil) ⇒ Object
- #report_download_url(report_iid, format) ⇒ Object
- #report_expand_javascript_sources(report, sources, recursive = false) ⇒ Object
- #report_expand_stylesheet_sources(report, sources, recursive = false) ⇒ Object
- #report_image_path(report, source) ⇒ Object
- #report_image_tag(report_id, source, options = {}) ⇒ Object
- #report_javascript_include_tag(report_id, *sources) ⇒ Object
- #report_javascript_path(report, source) ⇒ Object
- #report_javascript_src_tag(report, source, options) ⇒ Object
- #report_stylesheet_link_tag(report_id, *sources) ⇒ Object
- #report_stylesheet_path(report, source) ⇒ Object
- #report_stylesheet_tag(report, source, options) ⇒ Object
Instance Method Details
#bootstrap_load ⇒ Object
174 175 176 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 174 def bootstrap_load stylesheet_link_tag "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" end |
#jquery_load ⇒ Object
178 179 180 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 178 def jquery_load javascript_include_tag "https://code.jquery.com/jquery-1.10.0.min.js" end |
#name_and_path_from_source(source, base_directory) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 93 def name_and_path_from_source(source, base_directory) path = source.split('/') name = path.last directory = if path.length > 1 #remove last element path.pop "#{base_directory}/#{path.join('/')}" else base_directory end return name, directory end |
#render_template(template, locals = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 19 def render_template(template, locals=nil) if request && request.format.symbol == :html locals.nil? ? (render :partial => "/#{template}") : (render :partial => "/#{template}",:locals => locals[:locals]) elsif request && request.format.symbol == :pdf locals.nil? ? (render :partial => "/#{template}.html.erb") : (render :partial => "/#{template}.html.erb" , :locals => locals[:locals]) else locals.nil? ? (render :partial => "/#{template}.html.erb") : (render :partial => "/#{template}.html.erb" , :locals => locals[:locals]) end end |
#report_download_link(report_iid, format, display = nil) ⇒ Object
14 15 16 17 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 14 def report_download_link(report_iid, format, display=nil) display = display || "Download #{format.to_s.humanize}" raw "<a target='_blank' href='#{report_download_url(report_iid, format)}'>#{display}</a>" end |
#report_download_url(report_iid, format) ⇒ Object
10 11 12 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 10 def report_download_url(report_iid, format) raw "/reports/display/#{report_iid}.#{format}" end |
#report_expand_javascript_sources(report, sources, recursive = false) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 117 def (report, sources, recursive = false) if sources.include?(:all) collect_asset_files(report.base_dir + '/javascripts', ('**' if recursive), '*.js').uniq else sources.flatten end end |
#report_expand_stylesheet_sources(report, sources, recursive = false) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 109 def (report, sources, recursive = false) if sources.include?(:all) all_stylesheet_files = collect_asset_files(report.base_dir + '/stylesheets', ('**' if recursive), '*.css').uniq else sources.flatten end end |
#report_image_path(report, source) ⇒ Object
164 165 166 167 168 169 170 171 172 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 164 def report_image_path(report, source) report = Report.iid(report) unless report.is_a?(Report) name, directory = name_and_path_from_source(source, "#{report.url}/images") file = report.files.where('name = ? and directory = ?', name, directory).first file.nil? ? '' : file.fully_qualified_url end |
#report_image_tag(report_id, source, options = {}) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 136 def report_image_tag(report_id, source, = {}) report = Report.iid(report_id) return("could not find report with the id #{report_id}") unless report if request && request.format.symbol == :pdf img_path = report.image_path(source) file_support = ErpTechSvcs::FileSupport::Base.new(:storage => ErpTechSvcs::Config.file_storage) image_tag "data:image/png;base64,#{Base64.encode64(file_support.get_contents(img_path).first)}" else .symbolize_keys! [:src] = report_image_path(report, source) [:alt] ||= File.basename([:src], '.*').split('.').first.to_s.capitalize if size = .delete(:size) [:width], [:height] = size.split("x") if size =~ %r{^\d+x\d+$} end if mouseover = .delete(:mouseover) [:onmouseover] = "this.src='#{report_image_path(report, mouseover)}'" [:onmouseout] = "this.src='#{report_image_path(report, [:src])}'" end tag("img", ) end end |
#report_javascript_include_tag(report_id, *sources) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 51 def report_javascript_include_tag(report_id, *sources) report = Report.iid(report_id) return("could not find report with the id #{report_id}") unless report if request && request.format.symbol == :pdf file_support = ErpTechSvcs::FileSupport::Base.new(:storage => ErpTechSvcs::Config.file_storage) js = sources.collect do |source| js_path = report.javascript_path(source) js_text = "<script>#{file_support.get_contents(js_path).first}</script>" js_text.respond_to?(:html_safe) ? js_text.html_safe : js_text end.join("\n") raw js else = sources..stringify_keys cache = .delete("cache") recursive = .delete("recursive") sources = (report, sources, recursive).collect do |source| report_javascript_src_tag(report, source, ) end.join("\n") raw sources end end |
#report_javascript_path(report, source) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 83 def report_javascript_path(report, source) report = Report.iid(report) unless report.is_a?(Report) name, directory = name_and_path_from_source(source, "#{report.url}/javascripts") file = report.files.where('name = ? and directory = ?', name, directory).first file.nil? ? '' : file.fully_qualified_url end |
#report_javascript_src_tag(report, source, options) ⇒ Object
131 132 133 134 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 131 def report_javascript_src_tag(report, source, ) = {"type" => Mime::JS, "src" => report_javascript_path(report, source)}.merge() content_tag("script", "", ) end |
#report_stylesheet_link_tag(report_id, *sources) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 29 def report_stylesheet_link_tag(report_id, *sources) report = Report.iid(report_id) return("could not find report with the id #{report_id}") unless report if request && request.format.symbol == :pdf file_support = ErpTechSvcs::FileSupport::Base.new(:storage => ErpTechSvcs::Config.file_storage) css = sources.collect do |source| css_path = report.stylesheet_path(source) css_text = "<style type='text/css'>#{file_support.get_contents(css_path).first}</style>" css_text.respond_to?(:html_safe) ? css_text.html_safe : css_text end.join("\n") raw css else = sources..stringify_keys cache = .delete("cache") recursive = .delete("recursive") sources = (report, sources, recursive).collect do |source| report_stylesheet_tag(report, source, ) end.join("\n") raw sources end end |
#report_stylesheet_path(report, source) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 73 def report_stylesheet_path(report, source) report = Report.iid(report) unless report.is_a?(Report) name, directory = name_and_path_from_source(source, "#{report.url}/stylesheets") file = report.files.where('name = ? and directory = ?', name, directory).first file.nil? ? '' : file.fully_qualified_url end |
#report_stylesheet_tag(report, source, options) ⇒ Object
125 126 127 128 129 |
# File 'lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb', line 125 def report_stylesheet_tag(report, source, ) = {"rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => html_escape(report_stylesheet_path(report, source))}.merge() tag("link", , false, false) end |