ref: refs/heads/master
commit d771a65b4c3df01b68b4e7e452da9578da7a9e05
Author: Josef Reidinger
Date: Tue Jul 14 10:08:47 2009 +0200
refactor time controller, move some functionality to lib
---
.../app/controllers/system_time_controller.rb | 52 ++++---------------
plugins/systemtime/lib/systemtime.rb | 36 ++++++++++++++
2 files changed, 47 insertions(+), 41 deletions(-)
diff --git a/plugins/systemtime/app/controllers/system_time_controller.rb b/plugins/systemtime/app/controllers/system_time_controller.rb
index 0e0450f..dbdda44 100644
--- a/plugins/systemtime/app/controllers/system_time_controller.rb
+++ b/plugins/systemtime/app/controllers/system_time_controller.rb
@@ -1,4 +1,5 @@
require 'yast/service_resource'
+require 'systemtime'
class SystemTimeController < ApplicationController
before_filter :login_required
@@ -29,6 +30,8 @@ class SystemTimeController < ApplicationController
@date.sub!(/^(\d+)-(\d+)-(\d+)/,'\3/\2/\1')
end
+
+
public
@@timezones = {}
@@ -56,22 +59,17 @@ class SystemTimeController < ApplicationController
return false
end
- arr = params[:date][:date].split("/")
- t.time = "#{arr[2]}-#{arr[0]}-#{arr[1]} - "+params[:currenttime]
- t.timezones = [] #not needed anymore
- t.utcstatus = ""
- t.timezone = ""
+ fill_proxy_with_time t,params
- response = true
begin
response = 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"
rescue ActiveResource::ClientError => e
flash[:error] = YaST::ServiceResource.error(e)
log_exception e
- response = false
end
redirect_to :action => :index
@@ -84,45 +82,17 @@ class SystemTimeController < ApplicationController
return false
end
- region = {}
- @@timezones.each do |reg|
- if reg.name == params[:region]
- region = reg
- break
- end
- end
-
- region.entries.each do |e|
- if (e.name == params[:timezone])
- t.timezone = e.id
- break
- end
- end
-
- if (t.utcstatus != "UTConly")
- if params[:utc] == "true"
- t.utcstatus = "UTC"
- else
- t.utcstatus = "localtime"
- end
- end
-
- t.time = ""
- t.timezones = [] #not needed anymore
-
- response = true
+ fill_proxy_with_time t,params,@@systemtime
+
begin
response = t.save
+ flash[:notice] = _('Settings have been written.')
rescue ActiveResource::ClientError => e
flash[:error] = YaST::ServiceResource.error(e)
- response = false
- end
- if !response
- redirect_to :action => :index
- else
- flash[:notice] = _('Settings have been written.')
- redirect_to :action => :index
+ log_exception e
end
+
+ redirect_to :action => :index
end
def timezones_for_region
diff --git a/plugins/systemtime/lib/systemtime.rb b/plugins/systemtime/lib/systemtime.rb
index 96e2db5..6df26ea 100644
--- a/plugins/systemtime/lib/systemtime.rb
+++ b/plugins/systemtime/lib/systemtime.rb
@@ -1 +1,37 @@
# Systemtime
+
+def fill_proxy_with_time(proxy,params)
+ arr = params[:date][:date].split("/")
+ proxy.time = "#{arr[2]}-#{arr[0]}-#{arr[1]} - "+params[:currenttime]
+ proxy.timezones = [] #not needed anymore
+ proxy.utcstatus = ""
+ proxy.timezone = ""
+end
+
+def fill_proxy_with_timezone(proxy,params,timezones)
+ region = {}
+ timezones.each do |reg|
+ if reg.name == params[:region]
+ region = reg
+ break
+ end
+ end
+
+ region.entries.each do |e|
+ if (e.name == params[:timezone])
+ t.timezone = e.id
+ break
+ end
+ end
+
+ if (proxy.utcstatus != "UTConly")
+ if params[:utc] == "true"
+ proxy.utcstatus = "UTC"
+ else
+ proxy.utcstatus = "localtime"
+ end
+ end
+
+ proxy.time = ""
+ proxy.timezones = [] #not needed anymore
+end
\ No newline at end of file
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org