class ControlPanel

File

control_panel.rb

(C)

Hipposoft 2007

Purpose

Manage settings for individual User models. See below for more details.


24-Dec-2007 (ADH): Created.

Public Instance Methods

get_preference( key_str ) click to toggle source

Get a value from the instance’s preferences hash. The hash is nested in a similar manner to the I18n module’s translation hashes and is addressed in a similar way - pass a dot-separated key string, e.g. “foo.bar.baz”. Returns ‘nil’ for unset preferences, else the value at that location.

Currently defined preferences include (but may not be limited to - this list may be out of date) the following:

sorting => { <controller-name> => { <sort data> } }

  Most recently recorded value of params[:sort] by an index action for
  a controller identified by <controller_name>. For more information see
  "appctrl_apply_sorting_preferences".

per_page => { <controller-name> => { <pagination data> } }
# File app/models/control_panel.rb, line 62
def get_preference( key_str )
  keys = key_str.split( '.' )
  pref = self.preferences

  for key in keys
    return nil if pref.nil?
    pref = pref[ key ]
  end

  return pref
end
remove_inactive_tasks() click to toggle source

Remove inactive tasks from the control panel. The caller is responsible for saving the updated object.

# File app/models/control_panel.rb, line 40
def remove_inactive_tasks
  # See the User model's remove_inactive_tasks method for details.

  self.tasks = self.tasks.where( :active => true )
end
set_preference( key_str, value ) click to toggle source

Set the value of a preference identified as for “#get_preference” above. If any of the nested hashes identified by the key string are missing (e.g. in example “foo.bar.baz”, any of hashes “foo”, “bar” or “baz”) then relevant entries in the preferences will be made automatically.

The method saves ‘self’ back to database and returns the return value of the call made to “save”. Thus returns ‘false’ on failure, else ‘true’.

See also “#set_preference!”.

# File app/models/control_panel.rb, line 84
def set_preference( key_str, value )
  return set_preference_by_method!( key_str, value, :save )
end
set_preference!( key_str, value ) click to toggle source

As “#set_preference” but returns the result of a call to “save!”, so raises an exception on failure.

# File app/models/control_panel.rb, line 91
def set_preference!( key_str, value )
  return set_preference_by_method!( key_str, value, :save! )
end