class RestFtpDaemon::API::Dashboard

Public Instance Methods

build_dashboard(filter = '') click to toggle source
# File lib/rest-ftp-daemon/api/dashboard.rb, line 34
def build_dashboard filter = ''
  # Initialize Facter
  begin
    Facter.loadfacts
  rescue StandardError => exception
    log_error "dashboard/build: #{exception.inspect}"
  end

  # Detect QS filters
  @filter = filter.to_s
  @page = params["page"].to_i

  # Get jobs for this view, order jobs by their weights
  jobs_with_status = RestFtpDaemon::JobQueue.instance.jobs_with_status(filter).reverse

  # Provide queue only if no filtering set
  if filter.empty?
    @jobs_queued = RestFtpDaemon::JobQueue.instance.jobs_queued
  else
    @jobs_queued = []
  end

  # Build paginator
  @paginate = Paginate.new jobs_with_status
  @paginate.filter = filter
  @paginate.page = @page
  @paginate.all = params.keys.include? "all"

  # Compile haml template
  output = render :dashboard

  # Send response
  #env["api.format"] = :html
  # format "html"
  status 200
  content_type "html"
  body output
end
log_context() click to toggle source
# File lib/rest-ftp-daemon/api/dashboard.rb, line 16
def log_context
  {caller: "API::Dashboard"}
end
render(name, values={}) click to toggle source
# File lib/rest-ftp-daemon/api/dashboard.rb, line 20
def render name, values={}
  # Prepare template engine
  template = File.read("#{Conf.app_libs}/views/#{name}.haml")
  haml_engine = Haml::Engine.new(template, encoding: Encoding::UTF_8)

  # Inject helpers
  scope_object = eval("self", binding)
  scope_object.extend RestFtpDaemon::ViewsHelper
  scope_object.extend RestFtpDaemon::CommonHelpers

  # Do the rendering !
  haml_engine.render(scope_object, values)
end