[ranch] 55: Add the systems controller.

https://svn.lrde.epita.fr/svn/ranch/trunk Index: ChangeLog from Nicolas Despr�s <nicolas.despres@gmail.com> Add the systems controller. * web/ranch/app/views/layouts/_menubar.rhtml: Add the `Systems' menu item. * web/ranch/app/controllers/systems_controller.rb: New. Implement the index and list request. * web/ranch/app/views/layouts/systems.rhtml: New. Layout for the systems controller. * web/ranch/app/views/systems: New. * web/ranch/app/views/systems/list.rhtml: New. View for the list request. * web/ranch/app/views/systems/_menubar.rhtml: New. Menu bar part of the systems layout. * web/ranch/test/functional/systems_controller_test.rb, * web/ranch/app/helpers/systems_helper.rb: New. Generated by Rails. app/controllers/systems_controller.rb | 14 ++++++++++++++ app/helpers/systems_helper.rb | 2 ++ app/views/layouts/_menubar.rhtml | 1 + app/views/layouts/systems.rhtml | 24 ++++++++++++++++++++++++ app/views/systems/_menubar.rhtml | 10 ++++++++++ app/views/systems/list.rhtml | 24 ++++++++++++++++++++++++ test/functional/systems_controller_test.rb | 18 ++++++++++++++++++ 7 files changed, 93 insertions(+) Index: web/ranch/test/functional/systems_controller_test.rb --- web/ranch/test/functional/systems_controller_test.rb (revision 0) +++ web/ranch/test/functional/systems_controller_test.rb (revision 0) @@ -0,0 +1,18 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'systems_controller' + +# Re-raise errors caught by the controller. +class SystemsController; def rescue_action(e) raise e end; end + +class SystemsControllerTest < Test::Unit::TestCase + def setup + @controller = SystemsController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + # Replace this with your real tests. + def test_truth + assert true + end +end Index: web/ranch/app/helpers/systems_helper.rb --- web/ranch/app/helpers/systems_helper.rb (revision 0) +++ web/ranch/app/helpers/systems_helper.rb (revision 0) @@ -0,0 +1,2 @@ +module SystemsHelper +end Index: web/ranch/app/controllers/systems_controller.rb --- web/ranch/app/controllers/systems_controller.rb (revision 0) +++ web/ranch/app/controllers/systems_controller.rb (revision 0) @@ -0,0 +1,14 @@ +class SystemsController < ApplicationController + + layout 'systems' + + def index + list + render :action => 'list' + end + + def list + @systems = System.find :all, :order => "hostname" + end + +end Index: web/ranch/app/views/layouts/systems.rhtml --- web/ranch/app/views/layouts/systems.rhtml (revision 0) +++ web/ranch/app/views/layouts/systems.rhtml (revision 0) @@ -0,0 +1,24 @@ + <!-- -*- html -*- --> + +<html> + <%= render :partial => "layouts/head" %> + <body> + <%= render :partial => "layouts/top_banner" %> + <%= render :partial => "layouts/menubar" %> + + <p> + <table width="100%"> + <tr><td> + <%= render :partial => "systems/menubar" %> + </td></tr> + <tr><td> + <%= @content_for_layout %> + </td></tr> + </table> + </p> + + <%= render :partial => "layouts/bottom_banner" %> + </body> +</html> + + Index: web/ranch/app/views/layouts/_menubar.rhtml --- web/ranch/app/views/layouts/_menubar.rhtml (revision 54) +++ web/ranch/app/views/layouts/_menubar.rhtml (working copy) @@ -5,6 +5,7 @@ <tr> <td><%= link_to "Home", :controller => "ranch" %></td> <td><%= link_to "Projects", :controller => "projects" %></td> + <td><%= link_to "Systems", :controller => "systems" %></td> </tr> </table> <hr> Index: web/ranch/app/views/systems/list.rhtml --- web/ranch/app/views/systems/list.rhtml (revision 0) +++ web/ranch/app/views/systems/list.rhtml (revision 0) @@ -0,0 +1,24 @@ + <!-- -*- html -*- --> + +<p> +<table> + <% + rejected_col = [ "id", "info" ] + columns = System.columns.reject do |column| + rejected_col.include? column.name + end + %> + <tr> + <% for column in columns do %> + <%= content_tag "td", column.name %> + <% end %> + </tr> + <% for system in @systems do %> + <tr> + <% for column in columns do %> + <%= content_tag "td", system.send(column.name) %> + <% end %> + </tr> + <% end %> +</table> +</p> Index: web/ranch/app/views/systems/_menubar.rhtml --- web/ranch/app/views/systems/_menubar.rhtml (revision 0) +++ web/ranch/app/views/systems/_menubar.rhtml (revision 0) @@ -0,0 +1,10 @@ + <!-- -*- html -*- --> +<table> + <tr> + <td> + <%= link_to "List", :controller => "systems", + :action => "list" %> + </td> + </tr> +</table> +<hr>
participants (1)
-
Nicolas Despr�s