module RailsDb module ApplicationHelper include ::FontAwesome::Rails::IconHelper def rails_db_tables RailsDb::Database.accessible_tables end def sidebar_classes if show_sidebar? 'large-3 pull-9 columns' else 'large-3 pull-9 columns hide' end end def main_content_classes if show_sidebar? 'large-9 push-3 columns collapsed' else 'large-12 push-0 columns expanded' end end def show_sidebar? return true if controller_name == 'dashboard' && action_name == 'index' cookies['sidebar_visible'] == 'true' end def title(str) content_for :title do raw("#{str}"[0].upcase + "#{str}"[1..-1]) end end def paginate_table_entries(entries) params.delete(:id) return if entries.total_pages == 1 prev_page_text = "#{fa_icon('arrow-left')} Previous".html_safe next_page_text = "Next #{fa_icon('arrow-right')}".html_safe html = '' sanitize(html) end private def page_links_for_pagination(entries) pages = pages_for_pagination(entries) links = [] pages.each_with_index do |page,index| if page == entries.current_page links << content_tag(:b, page, { class: 'page current' }) else links << link_to(page, params.merge({ action: :data, page: page}), { remote: true, class: 'page' }) end links << ' ... ' if page != pages.last && (page + 1) != pages[index+1] end links.join(' ') end def pages_for_pagination(entries) last_page = entries.total_pages current_page = entries.current_page pages = if last_page > 10 [1, 2, 3] + (current_page-2..current_page+2).to_a + (last_page-2..last_page).to_a else (1..last_page).to_a end pages.uniq.select { |p| p > 0 && p <= last_page } end def db_hint_options result = {} RailsDb::Database.accessible_tables.each do |table_name| result[table_name] = RailsDb::Table.new(table_name).columns.inject({}) {|res, e| res[e.name] = nil; res } end result end end end