[yast-commit] <web-client> master : parse datetime info on backend side

ref: refs/heads/master commit f8680d91879275b55bc4fd0ef1292dfe986ad7e6 Author: Josef Reidinger <jreidinger@suse.cz> Date: Fri Jul 17 13:55:56 2009 +0200 parse datetime info on backend side --- .../app/controllers/system_time_controller.rb | 46 +++--- .../systemtime/app/views/system_time/index.rhtml | 192 ++++++++++---------- plugins/systemtime/lib/systemtime.rb | 7 +- .../test/functional/systemtime_controller_test.rb | 10 +- 4 files changed, 131 insertions(+), 124 deletions(-) diff --git a/plugins/systemtime/app/controllers/system_time_controller.rb b/plugins/systemtime/app/controllers/system_time_controller.rb index 9f0136e..2f5f9df 100644 --- a/plugins/systemtime/app/controllers/system_time_controller.rb +++ b/plugins/systemtime/app/controllers/system_time_controller.rb @@ -18,22 +18,15 @@ class SystemTimeController < ApplicationController end def fill_current_region - # FIXME: @region can remain unset @timezones.each do |region| region.entries.each do |entry| - if entry.id == @systemtime.timezone + if entry.id == @timezone @region = region + return end end end - end - - def fill_date_and_time (timedate) - # FIXME: such conversions should be in a model - @time = timedate[timedate.index(" - ")+3,8] - @date = timedate[0..timedate.index(" - ")-1] - #convert date to format for datepicker - @date.sub!(/^(\d+)-(\d+)-(\d+)/,'\3/\2/\1') + raise _("Unknown timezone #{@timezone} on host") end public @@ -48,9 +41,9 @@ class SystemTimeController < ApplicationController end def index - @systemtime = load_proxy 'org.opensuse.yast.modules.yapi.time' + systemtime = load_proxy 'org.opensuse.yast.modules.yapi.time' - unless @systemtime + unless systemtime return false end @@ -61,10 +54,19 @@ class SystemTimeController < ApplicationController end - @timezones = @systemtime.timezones + @timezones = systemtime.timezones + @timezone = systemtime.timezone + @utcstatus = systemtime.utcstatus + @time = systemtime.time + @date = systemtime.date fill_valid_timezones - fill_current_region - fill_date_and_time(@systemtime.time) + begin + fill_current_region + rescue Exception => e + flash[:warning] = e.message + ExceptionLogger.log_exception e + redirect_to root_path + end end def update_time @@ -78,17 +80,17 @@ class SystemTimeController < ApplicationController fill_proxy_with_time t,params begin - response = t.save + 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 + ExceptionLogger.log_exception e rescue Exception => e flash[:error] = e.message - log_exception e + ExceptionLogger.log_exception e end redirect_to :action => :index @@ -102,17 +104,17 @@ class SystemTimeController < ApplicationController return false end - fill_proxy_with_time t,params,@@systemtime + fill_proxy_with_timezone t,params, t.timezones begin - response = t.save + t.save flash[:notice] = _('Settings have been written.') rescue ActiveResource::ClientError => e flash[:error] = YaST::ServiceResource.error(e) - log_exception e + ExceptionLogger.log_exception e rescue Exception => e flash[:error] = e.message - log_exception e + ExceptionLogger.log_exception e end redirect_to :action => :index diff --git a/plugins/systemtime/app/views/system_time/index.rhtml b/plugins/systemtime/app/views/system_time/index.rhtml index 8324f2a..431ec96 100644 --- a/plugins/systemtime/app/views/system_time/index.rhtml +++ b/plugins/systemtime/app/views/system_time/index.rhtml @@ -1,116 +1,118 @@ <% if @permissions %> -<%= javascript_include_tag "nogray_time_picker" %> -<% javascript_tag do -%> - $(document).ready( function() { - $(".datepicker").datepicker( { dateFormat: 'dd/mm/yy'} ); - }); -<% end -%> + <%= javascript_include_tag "nogray_time_picker" %> + <% javascript_tag do -%> + $(document).ready( function() { + $(".datepicker").datepicker( { dateFormat: 'dd/mm/yy'} ); + }); + <% end -%> -<%= javascript_include_tag :defaults %> -<% disabled = ! @permissions[:write] %> + <%= javascript_include_tag :defaults %> + <% disabled = ! @permissions[:write] %> -<h2><%=_("Configure timezone")%></h2> -<% form_tag '/system_time/update_timezone', :class => 'container' do %> - <table summary="<%= _("Table for settings timezone for target machine.") %>"> - <tr> + <h2><%=_("Configure timezone")%></h2> + <% form_tag '/system_time/update_timezone', :class => 'container' do %> + <table summary="<%= _("Table for settings timezone for target machine.") %>"> + <tr> - <td> - <label for="region"> - <%=_("Region:")%> - </label> - </td> - <% name = @region.name rescue "" - @valid = Array.new unless @valid -%> - <td><%= select_tag "region", options_for_select(@valid, name), :disabled => disabled %></td> - - </tr> - <tr> + <td> + <label for="region"> + <%=_("Region:")%> + </label> + </td> + <% #region is always non-nil as it is prerequisites which throws exception + %> + <td> + <%= select_tag "region", options_for_select(@valid, @region.name), :disabled => disabled %> + </td> + </tr> + <tr> - <td> - <label for="timezone"> - <%=_("Timezone:")%> - </label> - </td> - <td id="timezones"> - <%= render(:partial => 'timezones', - :locals => {:region => @region, :default => @systemtime.timezone, - :disabled => disabled}) %> - </td> - </tr> + <td> + <label for="timezone"> + <%=_("Timezone:")%> + </label> + </td> + + <td id="timezones"> + <%= render(:partial => 'timezones', + :locals => {:region => @region, :default => @timezone, + :disabled => disabled}) %> + </td> + </tr> - <% if @systemtime.utcstatus != "UTConly" %> + <% if @utcstatus != "UTConly" %> + + <tr> + <td> + <label for="utc"> + <%=_("Hardware clock is set to UTC")%> + </label> + </td> + <td> + <% #don't use check_box helper as it generate also hidden opposite value + %> + <input type="checkbox" name="utc" id="utc" value="true" + <%= @utcstatus == "UTC" ? "checked" : "" %> + <%= "disabled=\"disabled\"" if disabled %> /> + </td> + </tr> + + <% end %> <tr> + <td/> <td> - <label for="utc"> - <%=_("Hardware clock is set to UTC")%> + <%= submit_tag _("Save"), :onclick=>"Element.show('progress')", :disabled=> disabled, :class => 'button' -%> + </td> + </tr> + </table> + <% end %> + <h2><%=_("Manually configure time")%></h2> + <% form_tag '/system_time/update_time', :class => 'container' do %> + <table summary="<%= _("Manual time configuration table, where user selects data and time for target machine") %>"> + <tr> + <td> + <label for="date_date"> + <%= _("Date") %> </label> </td> <td> - <% #don't use check_box helper as it generate also hidden opposite value - %> - <input type="checkbox" name="utc" id="utc" value="true" - <%= @systemtime.utcstatus == "UTC" ? "checked" : "" %> - <%= "disabled=\"disabled\"" if disabled %> /> + <%= text_field "date","date", :class => :datepicker, + :disabled=> disabled, :value => @date + %> </td> </tr> - <% end %> - - <tr> - <td/> - <td> - <%= submit_tag _("Save"), :onclick=>"Element.show('progress')", :disabled=> disabled, :class => 'button' -%> - </td> - </tr> - </table> -<% end %> -<h2><%=_("Manually configure time")%></h2> -<% form_tag '/system_time/update_time', :class => 'container' do %> - <table summary="<%= _("Manual time configuration table, where user selects data and time for target machine") %>"> - <tr> - <td> - <label for="date_date"> - <%= _("Date") %> - </label> - </td> - <td> - <%= text_field "date","date", :class => :datepicker, - :disabled=> disabled, :value => @date - %> - </td> - </tr> - - <tr> - <td> - <label for="currenttime"> - <%= _("Time") %> - </label> - </td> - <td><%= text_field_tag "currenttime", @time, :disabled=> disabled %></td> - </tr> - - <tr> - <td></td> - <td> - - <%= submit_tag _("Save"), :onclick=>"Element.show('progress')", - :disabled=> disabled, :class => 'button' -%> - - </td> - </tr> - </table> -<% end %> - -<%= observe_field(:region, - :frequency => 0.25, - :update => :timezones, - :url => { :action => :timezones_for_region }, - :with => "'disabled=' + "+ (disabled ? "true":"false")+" + '&value=' +value") %> - <% end %> \ No newline at end of file + <tr> + <td> + <label for="currenttime"> + <%= _("Time") %> + </label> + </td> + <td><%= text_field_tag "currenttime", @time, :disabled=> disabled %></td> + </tr> + + <tr> + <td></td> + <td> + + <%= submit_tag _("Save"), :onclick=>"Element.show('progress')", + :disabled=> disabled, :class => 'button' -%> + + </td> + </tr> + </table> + <% end %> + + <%= observe_field(:region, + :frequency => 0.25, + :update => :timezones, + :url => { :action => :timezones_for_region }, + :with => "'disabled=' + "+ (disabled ? "true":"false")+" + '&value=' +value") %> +<% end %> \ No newline at end of file diff --git a/plugins/systemtime/lib/systemtime.rb b/plugins/systemtime/lib/systemtime.rb index 6df26ea..4b61e52 100644 --- a/plugins/systemtime/lib/systemtime.rb +++ b/plugins/systemtime/lib/systemtime.rb @@ -1,8 +1,8 @@ # Systemtime def fill_proxy_with_time(proxy,params) - arr = params[:date][:date].split("/") - proxy.time = "#{arr[2]}-#{arr[0]}-#{arr[1]} - "+params[:currenttime] + proxy.date = params[:date][:date] + proxy.time = params[:currenttime] proxy.timezones = [] #not needed anymore proxy.utcstatus = "" proxy.timezone = "" @@ -19,7 +19,7 @@ def fill_proxy_with_timezone(proxy,params,timezones) region.entries.each do |e| if (e.name == params[:timezone]) - t.timezone = e.id + proxy.timezone = e.id break end end @@ -33,5 +33,6 @@ def fill_proxy_with_timezone(proxy,params,timezones) end proxy.time = "" + proxy.date = "" proxy.timezones = [] #not needed anymore end \ No newline at end of file diff --git a/plugins/systemtime/test/functional/systemtime_controller_test.rb b/plugins/systemtime/test/functional/systemtime_controller_test.rb index f1bc5cc..77977db 100644 --- a/plugins/systemtime/test/functional/systemtime_controller_test.rb +++ b/plugins/systemtime/test/functional/systemtime_controller_test.rb @@ -33,13 +33,14 @@ class SystemTimeControllerTest < ActionController::TestCase class Result - attr_accessor :time, :timezone, :utcstatus, :timezones, :saved + attr_accessor :time, :date, :timezone, :utcstatus, :timezones, :saved def fill @timezones = [ Region.new("Europe","Europe/Prague",[ Entry.new("Europe/Prague","Czech Republic" )]) ] - @time = "2009-07-02 - 12:18:00" + @time = "12:18:00" + @date = "07/02/2009" @utcstatus = "true" @timezone = "Europe/Prague" # @available = [Lang.new("cs_CZ","cestina"), @@ -79,8 +80,9 @@ class SystemTimeControllerTest < ActionController::TestCase assert assigns(:permissions)[:read] assert assigns(:permissions)[:write] assert assigns(:time) - # assert assigns(:timezone), "Europe/Prague" - # assert assigns(:utcstatus) + assert assigns(:date) + assert_equal assigns(:timezone), "Europe/Prague" + assert assigns(:utcstatus) end def test_access_without_write_permissions -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
Josef Reidinger