amahi/platform

View on GitHub
app/views/server/_status.html.slim

Summary

Maintainability
Test Coverage
- uid = server.id.to_s
- is_running = ! pids.empty?
- running = server_status('running')
- stopped = server_status('stopped')
- status_msg = is_running ? running : stopped
- processes = pids.empty? ? '-' : pids.join(', ')
- start_icon = theme_image_tag("server/start")
- stop_icon = theme_image_tag("server/stop")
- restart_icon = theme_image_tag("server/restart")
- refresh_icon = theme_image_tag("server/refresh")
- spin_show = spinner_show uid
- spin_hide = spinner_hide uid

.server-manage
  fieldset
    legend
      |   #{server.comment}  
    .settings-fields
      table
        tr
          td
              |  
          td
              |  
        tr
          td
            = t 'status'
            | \:
          td
            = status_msg
            = spinner uid
            - javascript_tag do
              = render :update do |page| page["server_status_#{uid}"].replace_html status_msg end
        tr
          td
              |  
          td
              |  
        tr
          td
            = t 'control'
            | \:
          td
            = link_to_remote(refresh_icon,                                           \
              :update => "server_info_#{uid}",                                       \
              :before => spin_show,                                                  \
              :success => spin_hide,                                                 \
              :url => { :controller => 'server', :action => 'refresh', :id => uid }) 
            |   —  
            = t 'refresh_status'
            p
            - if is_running
              = link_to_remote(stop_icon,    \
                :update => "server_info_#{uid}",  \
                :confirm => [t('are_you_sure_you_want_to_stop_the_server',\
                    :name => server.comment), "", \
                    server.monitored ? t('the_watchdog_is_running_and_will_restart_it_in_a_few_seconds') : t('this_will_stop_the_server_permanently', :name => server.comment) \
                ].join("\n"), \
                :before => spin_show, \
                :success => spin_hide, \
                :url => { :controller => 'server', :action => 'stop', :id => uid }) 
              |   —    
              =  t 'stop_it' 
              |   
              = server.monitored ? t('it_will_be_restarted_by_the_watchdog') : t('permanently')}
              p
              = link_to_remote(restart_icon,  \
                  :update => "server_info_#{uid}", \
                  :confirm => t('are_you_sure_you_want_to_restart_the_server', :name => server.comment), \
                  :before => spin_show, \
                  :success => spin_hide, \
                  :url => { :controller => 'server', :action => 'restart', :id => uid })                 |:
              |   —  
              = t 'restart'
            - else
              = link_to_remote(start_icon, \
                  :update => "server_info_#{uid}", \
                  :confirm => t('are_you_sure_you_want_to_start_the_server', :name => server.comment), \
                  :before => spin_show, \
                  :success => spin_hide, \
                  :url => { :controller => 'server', :action => 'start', :id => uid })  
              |   —   Start
        tr
          td
              |  
          td
              |  
        tr
          td 
              | Settings:
          td
            = checkbox_to_remote server.monitored,                                            \
              :url => { :controller => 'server', :action => 'toggle_monitored', :id => uid }, \
              :confirm => server.monitored ? t('the_watchdog_is_a_critical_setting') : nil,   \
              :before => spin_show,                                                           \
              :success => spin_hide,                                                          \
              :update => "server_info_#{uid}"                                                 
            | -   —  
            = t 'watchdog'
            | .
            = server.comment 
            = server.monitored ? t('is_being_monitored_24x7') : t('is_not_being_monitored_24x7')
            p
            = checkbox_to_remote (server.monitored or server.start_at_boot), {                     \
              :url => { :controller => 'server', :action => 'toggle_start_at_boot', :id => uid },  \
              :confirm => server.start_at_boot ? t('the_boot_option_is_a_critical_setting') : nil, \
              :before => spin_show,                                                                \
              :success => spin_hide,                                                               \
              :update => "server_info_#{uid}" },                                                   \
              :disabled => server.monitored
            |   —  
            = t 'start_at_boot_time'}
            | . 
            = server.comment
            = server.start_at_boot ? t('will_start_at_boot_time') : t('will_not_start_at_boot_time')