ref: refs/heads/dmacvicar_log_viewer
commit ddd705057629036254d35adb6b513832e380cc00
Author: Josef Reidinger
Date: Mon Aug 17 15:38:30 2009 +0200
remove private routing from systemtime plugin
---
.../app/controllers/system_time_controller.rb | 160 --------------------
.../app/controllers/systemtime_controller.rb | 160 ++++++++++++++++++++
.../app/views/system_time/_timezones.rhtml | 12 --
.../systemtime/app/views/system_time/index.rhtml | 128 ----------------
.../app/views/systemtime/_timezones.rhtml | 12 ++
.../systemtime/app/views/systemtime/index.rhtml | 128 ++++++++++++++++
plugins/systemtime/config/routes.rb | 4 -
7 files changed, 300 insertions(+), 304 deletions(-)
diff --git a/plugins/systemtime/app/controllers/system_time_controller.rb b/plugins/systemtime/app/controllers/system_time_controller.rb
deleted file mode 100644
index 04aa1c1..0000000
--- a/plugins/systemtime/app/controllers/system_time_controller.rb
+++ /dev/null
@@ -1,160 +0,0 @@
-require 'yast/service_resource'
-require 'systemtime'
-
-
-# = SystemTimeController
-# Provides all functionality, that handles time management module.
-# The most functionality around time handling is in rest-service and this
-# controller just provide handling of different exceptions and UI features.
-# Update time and timezone is separated as timezone update doesn't neccesarry
-# require also time update and that could set time to bad value.
-class SystemTimeController < ApplicationController
- before_filter :login_required
- layout 'main'
- include ProxyLoader
-
- #helpers
- private
- # Fills @+valid+ field that represents valid regions with informations from
- # @+timezone+ field.
- def fill_valid_timezones
- @valid = @@timezones.collect { |region| region.name }
- end
-
- # Fills current region name in field @+region+. Requires filled @+timezones+
- # and @+timezone+ fields
- # throws:: Exception if current timezone is not in any known region. @+region+
- # field in this case is +nil+.
- def fill_current_region
- @region = @@timezones.find { |region|
- region.entries.find { |entry| entry.id==@timezone } }
- raise _("Unknown timezone #{@timezone} on host") unless @region
- end
-
- public
-
- # cannot move to initialize, it is not finded - http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html#ApplicationCont...
- # Initialize GetText and Content-Type.
- init_gettext "yast_webclient_systemtime" # textdomain, options(:charset, :content_type)
-
- def initialize
- unless defined? @@timezones
- @@timezones = {}
- end
- @valid = []
- end
-
- # Index handler. Loads information from backend and if success all required
- # fields is filled. In case of errors redirect to help page, main page or just
- # show flash with partial problem.
- def index
- systemtime = load_proxy 'org.opensuse.yast.modules.yapi.time'
-
- unless systemtime
- return false
- end
-
- unless @permissions[:read]
- flash[:warning] = _("No permissions for time module")
- redirect_to root_path
- return false
- end
-
- @@timezones = systemtime.timezones
- @timezone = systemtime.timezone
- @utcstatus = systemtime.utcstatus
- @time = systemtime.time
- @date = systemtime.date
- fill_valid_timezones
- begin
- fill_current_region
- rescue Exception => e
- flash[:warning] = e.message
- ExceptionLogger.log_exception e
- redirect_to root_path
- end
- end
-
- # Update time handler. Sets to backend new time. If time is set to future it
- # still shows problems. Now it invalidate session for logged user.If
- # everything goes fine it redirect to index
- def update_time
- t = load_proxy 'org.opensuse.yast.modules.yapi.time'
-
- unless t
- return false
- end
-
- fill_proxy_with_time t,params
-
- begin
- t.save
- flash[:notice] = _('Settings have been written.')
- rescue Timeout::Error => e
- #do nothing as if you move time to future it throws this exception
- log.debug "Time moved to future"
- flash[:notice] = _('Settings have been written.')
- rescue ActiveResource::ClientError => e
- flash[:error] = YaST::ServiceResource.error(e)
- ExceptionLogger.log_exception e
- rescue Exception => e
- flash[:error] = e.message
- ExceptionLogger.log_exception e
- end
-
- redirect_to :action => :index
- end
-
- # Update time handler. Sets to backend new timezone. If everything goes fine
- # it redirect to index
- def update_timezone
- t = load_proxy 'org.opensuse.yast.modules.yapi.time'
-
- unless t
- return false
- end
-
- fill_proxy_with_timezone t,params, t.timezones
-
- begin
- t.save
- flash[:notice] = _('Settings have been written.')
- rescue ActiveResource::ClientError => e
- flash[:error] = YaST::ServiceResource.error(e)
- ExceptionLogger.log_exception e
- rescue Exception => e
- flash[:error] = e.message
- ExceptionLogger.log_exception e
- end
-
- redirect_to :action => :index
- end
-
-
- #AJAX function that renders new timezones for selected region. Expected
- # initialized values from index call.
- def timezones_for_region
- if @@timezones.empty?
- # since while calling this function there is different instance of the class
- # than when calling index, @@timezones were empty; reinitialize them
- # possible FIXME: how does it increase the amount of data transferred?
- systemtime = load_proxy 'org.opensuse.yast.modules.yapi.time'
-
- unless systemtime
- return false #possible FIXME: is returnign false for AJAX correct?
- end
-
- @@timezones = systemtime.timezones
- end
-
- region = @@timezones.find { |r| r.name == params[:value] } #possible FIXME later it gets class, not a string
-
- unless region
- return false; #possible FIXME: is returnign false for AJAX correct?
- end
-
- render(:partial => 'timezones',
- :locals => {:region => region, :default => region.central,
- :disabled => ! params[:disabled]=="true"})
- end
-end
diff --git a/plugins/systemtime/app/controllers/systemtime_controller.rb b/plugins/systemtime/app/controllers/systemtime_controller.rb
new file mode 100644
index 0000000..9c68f7a
--- /dev/null
+++ b/plugins/systemtime/app/controllers/systemtime_controller.rb
@@ -0,0 +1,160 @@
+require 'yast/service_resource'
+require 'systemtime'
+
+
+# = SystemTimeController
+# Provides all functionality, that handles time management module.
+# The most functionality around time handling is in rest-service and this
+# controller just provide handling of different exceptions and UI features.
+# Update time and timezone is separated as timezone update doesn't neccesarry
+# require also time update and that could set time to bad value.
+class SystemtimeController < ApplicationController
+ before_filter :login_required
+ layout 'main'
+ include ProxyLoader
+
+ #helpers
+ private
+ # Fills @+valid+ field that represents valid regions with informations from
+ # @+timezone+ field.
+ def fill_valid_timezones
+ @valid = @@timezones.collect { |region| region.name }
+ end
+
+ # Fills current region name in field @+region+. Requires filled @+timezones+
+ # and @+timezone+ fields
+ # throws:: Exception if current timezone is not in any known region. @+region+
+ # field in this case is +nil+.
+ def fill_current_region
+ @region = @@timezones.find { |region|
+ region.entries.find { |entry| entry.id==@timezone } }
+ raise _("Unknown timezone #{@timezone} on host") unless @region
+ end
+
+ public
+
+ # cannot move to initialize, it is not finded - http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html#ApplicationCont...
+ # Initialize GetText and Content-Type.
+ init_gettext "yast_webclient_systemtime" # textdomain, options(:charset, :content_type)
+
+ def initialize
+ unless defined? @@timezones
+ @@timezones = {}
+ end
+ @valid = []
+ end
+
+ # Index handler. Loads information from backend and if success all required
+ # fields is filled. In case of errors redirect to help page, main page or just
+ # show flash with partial problem.
+ def index
+ systemtime = load_proxy 'org.opensuse.yast.modules.yapi.time'
+
+ unless systemtime
+ return false
+ end
+
+ unless @permissions[:read]
+ flash[:warning] = _("No permissions for time module")
+ redirect_to root_path
+ return false
+ end
+
+ @@timezones = systemtime.timezones
+ @timezone = systemtime.timezone
+ @utcstatus = systemtime.utcstatus
+ @time = systemtime.time
+ @date = systemtime.date
+ fill_valid_timezones
+ begin
+ fill_current_region
+ rescue Exception => e
+ flash[:warning] = e.message
+ ExceptionLogger.log_exception e
+ redirect_to root_path
+ end
+ end
+
+ # Update time handler. Sets to backend new time. If time is set to future it
+ # still shows problems. Now it invalidate session for logged user.If
+ # everything goes fine it redirect to index
+ def update_time
+ t = load_proxy 'org.opensuse.yast.modules.yapi.time'
+
+ unless t
+ return false
+ end
+
+ fill_proxy_with_time t,params
+
+ begin
+ t.save
+ flash[:notice] = _('Settings have been written.')
+ rescue Timeout::Error => e
+ #do nothing as if you move time to future it throws this exception
+ log.debug "Time moved to future"
+ flash[:notice] = _('Settings have been written.')
+ rescue ActiveResource::ClientError => e
+ flash[:error] = YaST::ServiceResource.error(e)
+ ExceptionLogger.log_exception e
+ rescue Exception => e
+ flash[:error] = e.message
+ ExceptionLogger.log_exception e
+ end
+
+ redirect_to :action => :index
+ end
+
+ # Update time handler. Sets to backend new timezone. If everything goes fine
+ # it redirect to index
+ def update_timezone
+ t = load_proxy 'org.opensuse.yast.modules.yapi.time'
+
+ unless t
+ return false
+ end
+
+ fill_proxy_with_timezone t,params, t.timezones
+
+ begin
+ t.save
+ flash[:notice] = _('Settings have been written.')
+ rescue ActiveResource::ClientError => e
+ flash[:error] = YaST::ServiceResource.error(e)
+ ExceptionLogger.log_exception e
+ rescue Exception => e
+ flash[:error] = e.message
+ ExceptionLogger.log_exception e
+ end
+
+ redirect_to :action => :index
+ end
+
+
+ #AJAX function that renders new timezones for selected region. Expected
+ # initialized values from index call.
+ def timezones_for_region
+ if @@timezones.empty?
+ # since while calling this function there is different instance of the class
+ # than when calling index, @@timezones were empty; reinitialize them
+ # possible FIXME: how does it increase the amount of data transferred?
+ systemtime = load_proxy 'org.opensuse.yast.modules.yapi.time'
+
+ unless systemtime
+ return false #possible FIXME: is returnign false for AJAX correct?
+ end
+
+ @@timezones = systemtime.timezones
+ end
+
+ region = @@timezones.find { |r| r.name == params[:value] } #possible FIXME later it gets class, not a string
+
+ unless region
+ return false; #possible FIXME: is returnign false for AJAX correct?
+ end
+
+ render(:partial => 'timezones',
+ :locals => {:region => region, :default => region.central,
+ :disabled => ! params[:disabled]=="true"})
+ end
+end
diff --git a/plugins/systemtime/app/views/system_time/_timezones.rhtml b/plugins/systemtime/app/views/system_time/_timezones.rhtml
deleted file mode 100644
index bda39b0..0000000
--- a/plugins/systemtime/app/views/system_time/_timezones.rhtml
+++ /dev/null
@@ -1,12 +0,0 @@
-<%
-#prepare array for options, maybe add to controller?
-list = []
-central = ""
-region.entries.each() do |timezone|
- list.push timezone.name
- central = timezone.name if timezone.id == default
-end
-list.sort!
-%>
-<%= select_tag "timezone",
- options_for_select(list, central), :disabled=> disabled, :class=>'aligned-inputs' %>
diff --git a/plugins/systemtime/app/views/system_time/index.rhtml b/plugins/systemtime/app/views/system_time/index.rhtml
deleted file mode 100644
index abf1cfa..0000000
--- a/plugins/systemtime/app/views/system_time/index.rhtml
+++ /dev/null
@@ -1,128 +0,0 @@
-<% if @permissions %>
-
- <% content_for :head do %>
- <link rel="stylesheet" href="/inc/smoothness/jquery.ui.custom.css" type="text/css" media="screen" title="default" charset="utf-8" />
-
- <% javascript_tag do -%>
- $(document).ready( function() {
- $(".datepicker").datepicker( { dateFormat: 'dd/mm/yy'} );
- });
- <% end -%>
-
- <!-- FIXME move javascript function outside of index -->
- <% javascript_tag do -%>
- function submitTime() {
- if (!$("#date_date")[0].value.match( /^\d{2}\/\d{2}\/\d{4}$/)){
- alert ("<%= _("Invalid date format. Correct one is dd/mm/yyyy") %>");
- return false;
- }
- if (!$("#currenttime")[0].value.match( /^\d{2}:\d{2}:\d{2}$/)) {
- alert ("<%= _("Invalid time format. Correct one is hh:mm:ss") %>");
- return false;
- }
- Element.show('progress');
- return true;
- };
- <% end -%>
-
- <% end %>
- <% disabled = ! @permissions[:write] %>
-
- <div class='plugin-icon'><img src='/icons/yast-ntp-client.png' alt="time module"/></div>
- <div class='plugin-content'>
- <h2><%=_("Configure timezone")%></h2>
- <% form_tag '/system_time/update_timezone', :class => 'container' do %>
-