Sha256: b22104ea709162fc9cd971f9f77b8efa94846973b36e3ab710604ab75e84cdcd

Contents?: true

Size: 1.1 KB

Versions: 23

Compression:

Stored size: 1.1 KB

Contents

module MyDashboard
  class WidgetsController < ApplicationController

    before_filter :check_accessibility, only: :update
    before_filter :check_widget_name,   only: [:show, :update]
    before_filter :prepend_view_paths,  only: :show

    rescue_from ActionView::MissingTemplate, with: :template_not_found

    def show
      render file: widget_path, layout: false
    end

    def update
      data = params[:widget] || {}
      hash = data.merge(id: params[:name], updatedAt: Time.now.utc.to_i)
      MyDashboard.redis.publish("#{MyDashboard.config.redis_namespace}.create", hash.to_json)

      render nothing: true
    end

    private

    def check_widget_name
      raise 'bad widget name' unless params[:name] =~ /\A[a-zA-z0-9_\-]+\z/
    end

    def widget_path
      params[:name]
    end

    def prepend_view_paths
      prepend_view_path main_app_view_path
    end

    def main_app_view_path
      MyDashboard.config.widgets_views_path
    end

    def template_not_found
      raise "Count not find template for widget #{params[:name]}. Define your widget in #{main_app_view_path}"
    end

  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
my_dashboard-0.8.6 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.8.5 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.8.4 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.8.3 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.8.1 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.8.0 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.7.2 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.7.1 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.7.0 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.6.0 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.5.10 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.5.9 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.5.8 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.5.7 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.5.6 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.5.5 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.5.4 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.5.3 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.5.2 app/controllers/my_dashboard/widgets_controller.rb
my_dashboard-0.5.1 app/controllers/my_dashboard/widgets_controller.rb