Changeset 1073

Show
Ignore:
Timestamp:
03/14/07 17:02:01 (3 years ago)
Author:
julians
Message:

Parse earth-config.yml as an ERB file; do not reload configuration file in user.rb and server.rb; do away with eval() statements and instead use ERB notation in configuration file; add configurable maximum breadcrumb trail size and replace parts of breadcrumb trail with ... if trail becomes too long; implements #71

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/controllers/application.rb

    r858 r1073  
    11# Filters added to this controller will be run for all controllers in the application. 
    22# Likewise, all the methods added will be available for all controllers. 
     3 
     4require 'erb' 
     5 
    36class ApplicationController < ActionController::Base 
    47 
    5   @@webapp_config = open(File.dirname(__FILE__) + "/../../config/earth-webapp.yml") { |f| YAML.load(f.read) } 
    6    
     8  @@webapp_config = YAML.load(ERB.new(File.read(File.join(File.dirname(__FILE__), "../../config/earth-webapp.yml"))).result) 
     9 
     10  def self.webapp_config 
     11    @@webapp_config 
     12  end 
    713end 
  • trunk/app/helpers/application_helper.rb

    r1007 r1073  
    5858      # Note: need to reverse ancestors with behavior compatible to nested_set 
    5959      # (as opposed to better_nested_set) 
    60       for dir in directory.ancestors.reverse 
     60      path_components = directory.ancestors.reverse 
     61 
     62      # Add top-most directory, if present 
     63      if not path_components.empty? 
     64        s += link_to(path_components[0][:name], :overwrite_params => {:path => path_components[0].path, :page => nil}) + '/' 
     65 
     66        # Remove top-most directory from component list 
     67        path_components = path_components[1..-1] 
     68      end 
     69 
     70      # Remove top-most directories from component list until breadcrumb size is acceptable 
     71      # Make sure that at least the parent directory is still in breadcrumb 
     72      stripped = false 
     73      while path_components.size > 1 \ 
     74        and path_components.inject(s.size) { |sum, dir| sum += dir.name.size+1 } > ApplicationController::webapp_config["max_breadcrumb_length"].to_i 
     75        path_components = path_components[1..-1] 
     76        stripped = true 
     77      end 
     78 
     79      s += ".../" if stripped 
     80 
     81      path_components.each do |dir| 
    6182        s += link_to(dir[:name], :overwrite_params => {:path => dir.path, :page => nil}) + '/' 
    6283      end 
  • trunk/app/models/earth/server.rb

    r1053 r1073  
    55  class Server < ActiveRecord::Base 
    66    has_many :directories, :dependent => :delete_cascade, :order => :lft 
    7    
    8     cattr_accessor :config 
    9     cattr_accessor :heartbeat_grace_period 
    10     self.config = YAML.load(::File.open(::File.dirname(__FILE__) + "/../../../config/earth-webapp.yml")) 
    11     self.heartbeat_grace_period = eval(self.config["heartbeat_grace_period"]) 
     7 
     8    @@config = nil     
     9    def self.config 
     10      @@config = ApplicationController::webapp_config unless @@config 
     11      @@config 
     12    end 
     13     
     14    def self.heartbeat_grace_period 
     15      self.config["heartbeat_grace_period"].to_i 
     16    end 
    1217 
    1318    def Server.this_server 
  • trunk/app/models/user.rb

    r978 r1073  
    22  cattr_accessor :config 
    33  attr_reader :uid, :name 
    4      
    5   self.config = YAML.load(File.open(File.dirname(__FILE__) + "/../../config/earth-webapp.yml")) 
     4 
     5  @@config = nil     
     6  def self.config 
     7    @@config = ApplicationController::webapp_config unless @@config 
     8    @@config 
     9  end 
    610   
    7   @@uid_to_name = ExpiringHash.new(eval(config["ldap_cache_time"])
     11  @@uid_to_name = ExpiringHash.new(config["ldap_cache_time"].to_i
    812 
    913  def User.reset_cache 
    10     @@uid_to_name = ExpiringHash.new(eval(config["ldap_cache_time"])
     14    @@uid_to_name = ExpiringHash.new(config["ldap_cache_time"].to_i
    1115  end 
    1216 
  • trunk/config/earth-webapp.yml

    r920 r1073  
    11# Any parameters here affect the Earth web application 
     2# 
     3# This file is parsed with ERB, so you can insert ruby code using <%= "..." %> constructs 
    24 
    35# Configuration for doing user and group name lookup from uid and gid 
     
    1012  id_field: "uidNumber" 
    1113  name_field: "uid" 
    12 ldap_cache_time: 1.days 
     14ldap_cache_time: <%= 1.days %> 
    1315 
    1416# 
     
    1719# be caused by database load etc.  
    1820# 
    19 heartbeat_grace_period: 10.seconds 
     21heartbeat_grace_period: <%= 10.seconds %> 
     22 
     23# ----- Misc ----- 
     24 
     25# Maximum length of breadcrumb trail in characters. The breadcrumb 
     26# trail will always contain (if applicable): a link to root, a link to 
     27# the current server, a link to the top-level directory on the server, 
     28# a link to the parent directory, and the name of the current 
     29# directory. Additional directories between the top-level directory 
     30# and the parent directory will only be shown if the total length of 
     31# the breadcrumb trail, in characters, is less or equal than the 
     32# number configured below.   
     33
     34# Note that ideally, this would take the width of individual 
     35# characters and the width of the browser window into account; at this 
     36# point however this level of precision is not provided by Earth. 
     37
     38max_breadcrumb_length: 20 
    2039 
    2140# ----- Graph Configuration -----