require_dependency 'underworld/dashboard/helpers/box_helpers' module Underworld module DashboardHelper include Underworld::Dashboard::Helpers::BoxHelpers include ::ActionView::Helpers::TranslationHelper def form_label(resource, name) key = "forms.#{@resource.class.name.underscore.to_s.gsub('/', '.')}.#{name}" t(key) end def localized_time(time) # Fixme: Setup and use Rails l10n time.strftime("%Y-%m-%d %H:%M") end def link_button(title, **options) classes = "btn pull-right btn-sm #{options.fetch(:classes, '')}" icon_class = options[:icon_class] href = options.fetch(:href, '#') remote = options.fetch(:remote, false).to_s button = "" if icon_class button += "" end button += "#{title}" + '' button.html_safe end def action_buttons(buttons) buttons_html = '' buttons.each do |button| href = button.fetch(:href, '#') klass = button.fetch(:class, 'btn-success') remote = button.fetch(:remote, false).to_s icons = button.fetch(:icon_class, "") label = button.fetch(:name, '') model = button.fetch(:model, nil) action = button.fetch(:policy, nil) with_policy(model, action) do buttons_html += "\n" + "" + label + '' end end buttons_html.html_safe end # Translate route name to url dynamically def get_url(route_name, id = nil, engine = Rails.application) return route_name.call if id.nil? return route_name.call(id) unless id.nil? end def draw_menu(menu) klass = menu.class || '' klass += 'treeview' if sidebar.children? href = menu.url || '#' result = "