Sha256: 2232210af80ed8a8c9eec90923ae244e58698bed5800bc0651aa38407b4cca92

Contents?: true

Size: 1016 Bytes

Versions: 6

Compression:

Stored size: 1016 Bytes

Contents

module Admin

  module DashboardHelper

    def applications
      apps = {}

      Typus.models.sort {|a,b| a.constantize.model_name.human <=> b.constantize.model_name.human}.each do |model|
        # Get the application name.
        app_name = model.constantize.typus_application
        # Initialize the application if needed.
        apps[app_name] = [] unless apps.keys.include?(app_name)
        # Add model to the application only if the @current_user has permission.
        apps[app_name] << model if @current_user.resources.include?(model)
      end

      render File.join(path, "applications"), :applications => apps.compact.sort
    end

    def resources
      available = Typus.resources.map do |resource|
                    resource if @current_user.resources.include?(resource)
                  end.compact

      return if available.empty?

      render File.join(path, "resources"), :resources => available
    end

    private

    def path
      "admin/helpers/dashboard"
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
typus-1.0.0.pre6 app/helpers/admin/dashboard_helper.rb
typus-1.0.0.pre5 app/helpers/admin/dashboard_helper.rb
typus-1.0.0.pre4 app/helpers/admin/dashboard_helper.rb
typus-1.0.0.pre3 app/helpers/admin/dashboard_helper.rb
typus-1.0.0.pre2 app/helpers/admin/dashboard_helper.rb
typus-1.0.0.pre app/helpers/admin/dashboard_helper.rb