Commit a8f00402eaf0e89dd72c98fe1c27190c6b7026cc

Authored by AntonioTerceiro
1 parent f037e407

ActionItem152: adding a login block


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1241 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/admin/environment_design_controller.rb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +class EnvironmentDesignController < BoxOrganizerController
  2 +
  3 + def available_blocks
  4 + @available_blocks ||= [ LoginBlock ]
  5 + end
  6 +
  7 +end
... ...
app/controllers/box_organizer_controller.rb
1 1 class BoxOrganizerController < ApplicationController
2 2  
  3 + def index
  4 + end
  5 +
3 6 def move_block
4 7 @block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, ''))
5 8  
... ...
app/controllers/my_profile/profile_design_controller.rb
... ... @@ -6,8 +6,4 @@ class ProfileDesignController &lt; BoxOrganizerController
6 6 @available_blocks ||= [ Block, ArticleBlock ]
7 7 end
8 8  
9   - def index
10   - end
11   -
12   -
13 9 end
... ...
app/controllers/public/account_controller.rb
... ... @@ -34,6 +34,14 @@ class AccountController &lt; PublicController
34 34 render :action => 'login', :layout => false
35 35 end
36 36  
  37 + def login_block
  38 + if logged_in?
  39 + render :action => 'user_info', :layout => 'block'
  40 + else
  41 + render :action => 'login_block', :layout => 'block'
  42 + end
  43 + end
  44 +
37 45 # action to register an user to the application
38 46 def signup
39 47 begin
... ...
app/helpers/application_helper.rb
... ... @@ -329,4 +329,8 @@ module ApplicationHelper
329 329 end
330 330 end
331 331  
  332 + def user
  333 + @controller.send(:user)
  334 + end
  335 +
332 336 end
... ...
app/helpers/boxes_helper.rb
... ... @@ -20,7 +20,7 @@ module BoxesHelper
20 20  
21 21 def display_boxes(holder, main_content)
22 22 boxes = holder.boxes.first(holder.boxes_limit)
23   - content = boxes.reverse.map { |item| display_box(item, main_content) }.join("\n")
  23 + content = boxes.map { |item| display_box(item, main_content) }.join("\n")
24 24 content = main_content if (content.blank?)
25 25 content_tag('div', content, :class => 'boxes', :id => 'boxes' )
26 26 end
... ... @@ -40,7 +40,7 @@ module BoxesHelper
40 40 end
41 41  
42 42 def display_block(block, main_content = nil)
43   - content = block.content(main_content)
  43 + content = block.main? ? main_content : block.content
44 44 result =
45 45 case content
46 46 when Hash
... ... @@ -53,7 +53,7 @@ module BoxesHelper
53 53 end
54 54 end
55 55  
56   - classes = 'block' # ['block', block.class.name.underscore.gsub('_', '-') ].uniq.join(' ')
  56 + classes = ['block', block.class.name.underscore.gsub('_', '-') ].uniq.join(' ')
57 57  
58 58 box_decorator.block_target(block.box, block) + content_tag('div', result + box_decorator.block_edit_buttons(block), :class => classes, :id => "block-#{block.id}") + box_decorator.block_handle(block)
59 59 end
... ...
app/models/block.rb
... ... @@ -19,4 +19,8 @@ class Block &lt; ActiveRecord::Base
19 19 nil
20 20 end
21 21  
  22 + def main?
  23 + false
  24 + end
  25 +
22 26 end
... ...
app/models/login_block.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class LoginBlock < Block
  2 +
  3 + def self.description
  4 + _('A login box for your users.')
  5 + end
  6 +
  7 + def content
  8 + { :controller => 'account', :action => 'login_block' }
  9 + end
  10 +
  11 +end
... ...
app/models/main_block.rb
... ... @@ -8,4 +8,8 @@ class MainBlock &lt; Block
8 8 main_content
9 9 end
10 10  
  11 + def main?
  12 + true
  13 + end
  14 +
11 15 end
... ...
app/views/account/login_block.rhtml 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +<div id="login-box">
  2 + <% unless logged_in? %>
  3 +
  4 + <h2><%= _('Login') %></h2>
  5 +
  6 + <% labelled_form_for :user, @user, :url => { :controller => 'account', :action => 'login' } do |f| %>
  7 + <%= display_form_field(_('Username'), text_field_tag(:login) ) %>
  8 + <%= display_form_field(_('Password'), password_field_tag(:password) ) %>
  9 + <div>
  10 + <%= submit_button( 'login', _('Log in') )%>
  11 + </div>
  12 + <% end %>
  13 +
  14 + <div>
  15 + <%= link_to _("New user"), :controller => 'account', :action => 'signup' %>
  16 + </div>
  17 + <% else %>
  18 + <h2><%= @profile.identifier %></h2>
  19 + <% end %>
  20 +
  21 +</div><!-- end id="login-box" -->
  22 +
... ...
app/views/account/user_info.rhtml 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +<h2><%= user.identifier %></h2>
  2 +
  3 +<ul>
  4 + <li><%= _('User since %d') % user.person_info.created_at.year %></li>
  5 + <li><%= link_to_homepage _('Homepage') %></li>
  6 +</ul>
... ...
app/views/environment_design 0 → 120000
... ... @@ -0,0 +1 @@
  1 +box_organizer/
0 2 \ No newline at end of file
... ...
app/views/home/index.rhtml
... ... @@ -2,9 +2,6 @@
2 2  
3 3 <h1><%= @environment.name %></h1>
4 4  
5   -<%# FIXME %>
6   -<%= render :file => 'account/login.rhtml' %>
7   -
8 5 <h2><%= _('Recent articles') %></h2>
9 6  
10 7 <% for article in @articles %>
... ...
app/views/layouts/application.rhtml
... ... @@ -30,7 +30,7 @@
30 30 <% end %>
31 31 </head>
32 32  
33   - <body class='category<%= category_color %>' onload='noosfero_init();'>
  33 + <body class='noosfero category<%= category_color %>' onload='noosfero_init();'>
34 34  
35 35 <% unless flash[:notice].nil? %>
36 36 <div id='notice' onclick="Element.hide('notice');">
... ...
app/views/layouts/block.rhtml 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +<html>
  2 + <head>
  3 + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  4 + <title>noosfero block</title>
  5 +
  6 + <%= stylesheet_link_tag 'common' %>
  7 + <%= stylesheet_link_tag 'button' %>
  8 + <%= stylesheet_link_tag 'search' %>
  9 + <%= stylesheet_link_tag 'block' %>
  10 +
  11 +
  12 + <%# FIXME %>
  13 + <%= stylesheet_link_tag '/designs/templates/default/stylesheets/style.css' %>
  14 + <%= stylesheet_link_tag '/designs/icons/default/style.css' %>
  15 +
  16 + <%= javascript_include_tag(:defaults) %>
  17 +
  18 + <base target='_top'/>
  19 + </head>
  20 +
  21 + <body class='noosfero-block'>
  22 + <%= yield %>
  23 + </body>
  24 +
  25 +</html>
... ...
public/designs/icons/default/README
... ... @@ -38,6 +38,7 @@ gtk-go-up.png Nuovo stock/
38 38 gtk-go-down.png Nuovo stock/
39 39 gnome-search.png Nuovo apps/
40 40 gtk-ok.png Nuovo stock/
  41 +password.png Nuovo apps/
41 42 ### END OF ICONS LISTING ###
42 43  
43 44 Licensing of GNOME themes
... ...
public/designs/icons/default/password.png 0 → 100644

921 Bytes

public/designs/icons/default/style.css
... ... @@ -18,3 +18,4 @@
18 18 .button.down { background-image: url(gtk-go-down.png); }
19 19 .button.search { background-image: url(gnome-search.png); }
20 20 .button.ok { background-image: url(gtk-ok.png); }
  21 +.button.login { background-image: url(password.png); }
... ...
public/stylesheets/block.css 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +body.noosfero-block {
  2 + background: white;
  3 + font-size: 12px;
  4 +}
  5 +
  6 +h2 {
  7 + padding: 0px;
  8 + margin: 0px;
  9 + font-size: 14px;
  10 + border-bottom: 1px solid black;
  11 +}
  12 +
  13 +input {
  14 + font-size: 10px;
  15 +}
  16 +
  17 +#login-box {
  18 + text-align: center;
  19 +}
  20 +
... ...
public/stylesheets/blocks.css
  1 +/***********************************************************
  2 + * style for blocks
  3 + ***********************************************************/
1 4  
2   -/* main box */
3   -div.box-1 {
4   - margin-left: 210px;
5   - margin-right: 210px;
6   -}
7   -
8   -div.box-2 {
9   - float: left;
10   - width: 200px;
11   -}
12   -
13   -div.box-3 {
14   - float: right;
15   - width: 200px;
  5 +.block iframe {
  6 + width: 100%;
  7 + border: none;
16 8 }
17 9  
18   -
19   -.block {
20   - margin: 5px;
21   - padding: 5px;
22   -}
  10 +/***********************************************************
  11 + * the handles to where you can drag the blocks
  12 + ***********************************************************/
23 13  
24 14 .block-target {
25 15 margin: 5px;
... ... @@ -34,11 +24,6 @@ div.box-3 {
34 24 height: 30px;
35 25 }
36 26  
37   -.block iframe {
38   - width: 100%;
39   - border: none;
40   -}
41   -
42 27 /***********************************************************
43 28 * put borders around boxes and blocks when organizing boxes
44 29 ***********************************************************/
... ...
public/stylesheets/common.css
... ... @@ -3,6 +3,8 @@ body {
3 3 margin: 0px;
4 4 font-family: Verdana, Sans-Serif;
5 5 font-size: 14px;
  6 +}
  7 +body.noosfero {
6 8 /*
7 9 ** a imagem de fundo colorida é mais pesada, por isso carregamos
8 10 ** essa cinza mais leve antes para melhorar a esperiência do usuário.
... ... @@ -24,7 +26,7 @@ body.category3 #wrap { background-image: url(&quot;../images/bg-top-lilas.png&quot;); }
24 26 body.category4 #wrap { background-image: url("../images/bg-top-vermelho.png"); }
25 27  
26 28 #header {
27   - height: 60px;
  29 + height: 30px;
28 30 }
29 31  
30 32 #design_boxes {
... ...
test/fixtures/person_infos.yml
... ... @@ -4,4 +4,5 @@ person_info_for_ze:
4 4 name: "Zé, José, Zezinho"
5 5 address: "house of the hat"
6 6 contact_information: "Pavilhão 9, Quadrante 13, Esquina com Avenida das Alamedas, 467, fundos, falar com Dona Ivete após as 16"
  7 + created_at: '2007-12-01'
7 8  
... ...
test/functional/account_controller_test.rb
... ... @@ -246,6 +246,18 @@ class AccountControllerTest &lt; Test::Unit::TestCase
246 246 assert_no_tag :tag => "body" # e.g. no layout
247 247 end
248 248  
  249 + should 'provide login block' do
  250 + get :login_block
  251 + assert_template 'login_block'
  252 + assert_tag :tag => 'body', :attributes => { :class => 'noosfero-block' }
  253 + end
  254 +
  255 + should 'display user info in login block when logged in' do
  256 + login_as('ze')
  257 + get :login_block
  258 + assert_template 'user_info'
  259 + end
  260 +
249 261 protected
250 262 def create_user(options = {})
251 263 post :signup, :user => { :login => 'quire', :email => 'quire@example.com',
... ...
test/functional/environment_design_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +require 'environment_design_controller'
  3 +
  4 +# Re-raise errors caught by the controller.
  5 +class EnvironmentDesignController; def rescue_action(e) raise e end; end
  6 +
  7 +class EnvironmentDesignControllerTest < Test::Unit::TestCase
  8 + def setup
  9 + @controller = EnvironmentDesignController.new
  10 + @request = ActionController::TestRequest.new
  11 + @response = ActionController::TestResponse.new
  12 + end
  13 +
  14 + # Replace this with your real tests.
  15 + def test_truth
  16 + assert true
  17 + end
  18 +end
... ...
test/unit/login_block_test.rb 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class LoginBlockTest < Test::Unit::TestCase
  4 +
  5 + def setup
  6 + @block = LoginBlock.new
  7 + end
  8 + attr_reader :block
  9 +
  10 + should 'describe itself' do
  11 + assert_not_equal Block.description, LoginBlock.description
  12 + end
  13 +
  14 + should 'point to account/login_block' do
  15 + assert_equal({ :controller => 'account', :action => 'login_block' }, block.content)
  16 + end
  17 +
  18 +end
... ...