ref: refs/heads/dmacvicar_log_viewer commit ddd705057629036254d35adb6b513832e380cc00 Author: Josef Reidinger <jreidinger@suse.cz> 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 %> - <table summary="<%= _("Table for settings timezone for target machine.") %>"> - <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, - :class=>'aligned-inputs' %> - </td> - - </tr> - <tr> - - - <td> - <label for="timezone"> - <%=_("Timezone:")%> - </label> - </td> - - <td id="timezones"> - <%= render(:partial => 'timezones', - :locals => {:region => @region, :default => @timezone, - :disabled => disabled}) %> - </td> - </tr> - - <% 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" - <%= "checked="checked"" if @utcstatus == "UTC"%> - <%= "disabled="disabled"" if disabled %> /> - </td> - </tr> - - <% end %> - </table> - <p> - <%= submit_tag _("Save timezone"), :onclick=>"Element.show('progress')", :disabled=> disabled, :class => 'button' -%> - </p> - <% 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 aligned-inputs', - :disabled=> disabled, :value => @date - %> - </td> - </tr> - - <tr> - <td> - <label for="currenttime"> - <%= _("Time:") %> - </label> - </td> - <td><%= text_field_tag "currenttime", @time, :disabled=> disabled, :class=>'aligned-inputs' %></td> - </tr> - </table> - <p> - <%= submit_tag _("Save time"), :onclick=>"return submitTime()", - :disabled=> disabled, :class => 'button' -%> - </p> - <% end %> - </div> - - <%= observe_field(:region, - :frequency => 0.25, - :update => :timezones, - :url => { :action => :timezones_for_region }, - :with => "'disabled=' + "+ (disabled ? "true":"false")+" + '&value=' +value") %> -<% end %> - diff --git a/plugins/systemtime/app/views/systemtime/_timezones.rhtml b/plugins/systemtime/app/views/systemtime/_timezones.rhtml new file mode 100644 index 0000000..bda39b0 --- /dev/null +++ b/plugins/systemtime/app/views/systemtime/_timezones.rhtml @@ -0,0 +1,12 @@ +<% +#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/systemtime/index.rhtml b/plugins/systemtime/app/views/systemtime/index.rhtml new file mode 100644 index 0000000..abf1cfa --- /dev/null +++ b/plugins/systemtime/app/views/systemtime/index.rhtml @@ -0,0 +1,128 @@ +<% 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 %> + <table summary="<%= _("Table for settings timezone for target machine.") %>"> + <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, + :class=>'aligned-inputs' %> + </td> + + </tr> + <tr> + + + <td> + <label for="timezone"> + <%=_("Timezone:")%> + </label> + </td> + + <td id="timezones"> + <%= render(:partial => 'timezones', + :locals => {:region => @region, :default => @timezone, + :disabled => disabled}) %> + </td> + </tr> + + <% 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" + <%= "checked="checked"" if @utcstatus == "UTC"%> + <%= "disabled="disabled"" if disabled %> /> + </td> + </tr> + + <% end %> + </table> + <p> + <%= submit_tag _("Save timezone"), :onclick=>"Element.show('progress')", :disabled=> disabled, :class => 'button' -%> + </p> + <% 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 aligned-inputs', + :disabled=> disabled, :value => @date + %> + </td> + </tr> + + <tr> + <td> + <label for="currenttime"> + <%= _("Time:") %> + </label> + </td> + <td><%= text_field_tag "currenttime", @time, :disabled=> disabled, :class=>'aligned-inputs' %></td> + </tr> + </table> + <p> + <%= submit_tag _("Save time"), :onclick=>"return submitTime()", + :disabled=> disabled, :class => 'button' -%> + </p> + <% end %> + </div> + + <%= observe_field(:region, + :frequency => 0.25, + :update => :timezones, + :url => { :action => :timezones_for_region }, + :with => "'disabled=' + "+ (disabled ? "true":"false")+" + '&value=' +value") %> +<% end %> + diff --git a/plugins/systemtime/config/routes.rb b/plugins/systemtime/config/routes.rb deleted file mode 100644 index 0be1d07..0000000 --- a/plugins/systemtime/config/routes.rb +++ /dev/null @@ -1,4 +0,0 @@ -ActionController::Routing::Routes.draw do |map| - map.connect "/systemtime", :controller => 'system_time', :action => 'index' -end - -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org