Project

General

Profile

Feature #1233 » adds_default_page.patch

Makoto NAKAYA, 2012-05-09 07:03

View differences:

app/controllers/account_controller.rb
201 201
      set_autologin_cookie(user)
202 202
    end
203 203
    call_hook(:controller_account_success_authentication_after, {:user => user })
204
    redirect_back_or_default :controller => 'my', :action => 'page'
204
    if user.default_page == "top"
205
      redirect_back_or_default :controller => 'welcome'
206
    elsif user.default_page == "my_page"
207
      redirect_back_or_default :controller => 'my', :action => 'page'
208
    elsif user.default_page == "my_project"
209
      redirect_back_or_default :controller => 'projects', :action => 'show', :id => user.default_project_id
210
    else
211
      redirect_back_or_default :controller => 'my', :action => 'page'
212
    end
205 213
  end
206 214

  
207 215
  def set_autologin_cookie(user)
app/controllers/application_controller.rb
259 259
    end
260 260
  end
261 261

  
262
  def back_url
263
    params[:back_url] || request.env['HTTP_REFERER']
264
  end
265

  
266 262
  def redirect_back_or_default(default)
267 263
    back_url = CGI.unescape(params[:back_url].to_s)
268 264
    if !back_url.blank?
app/helpers/application_helper.rb
967 967
  end  
968 968

  
969 969
  def back_url_hidden_field_tag
970
    back_url = params[:back_url] || request.env['HTTP_REFERER']
970
    back_url = params[:back_url]
971 971
    back_url = CGI.unescape(back_url.to_s)
972 972
    hidden_field_tag('back_url', CGI.escape(back_url), :id => nil) unless back_url.blank?
973 973
  end
app/helpers/users_helper.rb
39 39
    user.valid_notification_options.collect {|o| [l(o.last), o.first]}
40 40
  end
41 41

  
42
  def user_default_page_options(user)
43
    user.valid_default_page_options.collect {|o| [l(o.last), o.first]}
44
  end
45

  
42 46
  def change_status_link(user)
43 47
    url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil}
44 48

  
app/models/user.rb
44 44
    ['none', :label_user_mail_option_none]
45 45
  ]
46 46

  
47
  DEFAULT_PAGE_OPTIONS = [
48
    ['top', :label_user_default_page_option_top],
49
    ['my_page', :label_user_default_page_option_my_page],
50
    ['my_project', :label_user_default_page_option_my_project]
51
  ]
52

  
47 53
  has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
48 54
                                   :after_remove => Proc.new {|user, group| group.user_removed(user)}
49 55
  has_many :changesets, :dependent => :nullify
......
78 84
  validates_length_of :mail, :maximum => MAIL_LENGTH_LIMIT, :allow_nil => true
79 85
  validates_confirmation_of :password, :allow_nil => true
80 86
  validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true
87
  validates_inclusion_of :default_page, :in => DEFAULT_PAGE_OPTIONS.collect(&:first), :allow_blank => true
81 88
  validate :validate_password_length
82 89

  
83 90
  before_create :set_mail_notification
......
314 321
    self.class.valid_notification_options(self)
315 322
  end
316 323

  
324
  def valid_default_page_options
325
    self.class.valid_default_page_options(self)
326
  end
327

  
317 328
  # Only users that belong to more than 1 project can select projects for which they are notified
318 329
  def self.valid_notification_options(user=nil)
319 330
    # Note that @user.membership.size would fail since AR ignores
......
325 336
    end
326 337
  end
327 338

  
339
  def self.valid_default_page_options(user=nil)
340
    if user.projects.count == 0
341
      DEFAULT_PAGE_OPTIONS.reject {|option| option.first == 'my_project'}
342
    else
343
      DEFAULT_PAGE_OPTIONS
344
    end
345
  end
346

  
328 347
  # Find a user account by matching the exact login and then a case-insensitive
329 348
  # version.  Exact matches will be given priority.
330 349
  def self.find_by_login(login)
......
500 519
    'language',
501 520
    'custom_field_values',
502 521
    'custom_fields',
503
    'identity_url'
522
    'identity_url',
523
    'default_page',
524
    'default_project_id'
504 525

  
505 526
  safe_attributes 'status',
506 527
    'auth_source_id',
app/views/my/account.html.erb
27 27
  <%= call_hook(:view_my_account, :user => @user, :form => f) %>
28 28
</fieldset>
29 29

  
30
<fieldset class="box">
31
  <legend><%=l(:label_my_default_page)%></legend>
32
  <%= render :partial => 'users/default_page' %>
33
</fieldset>
34

  
30 35
<%= submit_tag l(:button_save) %>
31 36
</div>
32 37

  
app/views/users/_default_page.erb
1
<p>
2
<%= label_tag "user_default_page", l(:description_user_default_page), :class => "hidden-for-sighted" %>
3
<%= select_tag 'user[default_page]', options_for_select(user_default_page_options(@user), @user.default_page),
4
                                      :onchange => 'if (this.value == "my_project") {Element.show("default-projects")} else {Element.hide("default-projects")}' %>
5
</p>
6
<% if @user.projects.count > 0 %>
7
<% content_tag 'div', :id => 'default-projects', :style => (@user.default_page == 'my_project' ? '' : 'display:none;') do %>
8
<p>
9
<%= select_tag 'user[default_project_id]', options_for_select(project_tree_options_for_select(@user.projects, :selected => @user.projects.select{|p| p.id == @user.default_project_id})) %>
10
</p>
11
<% end %>
12
<% end %>
config/locales/en.yml
518 518
  label_my_account: My account
519 519
  label_my_projects: My projects
520 520
  label_my_page_block: My page block
521
  label_my_default_page: My default page
521 522
  label_administration: Administration
522 523
  label_login: Sign in
523 524
  label_logout: Sign out
......
776 777
  label_theme: Theme
777 778
  label_default: Default
778 779
  label_search_titles_only: Search titles only
780
  label_user_default_page_option_top: "Top"
781
  label_user_default_page_option_my_page: "My page"
782
  label_user_default_page_option_my_project: "My project"
779 783
  label_user_mail_option_all: "For any event on all my projects"
780 784
  label_user_mail_option_selected: "For any event on the selected projects only..."
781 785
  label_user_mail_option_none: "No events"
......
1018 1022
  description_query_sort_criteria_attribute: Sort attribute
1019 1023
  description_query_sort_criteria_direction: Sort direction
1020 1024
  description_user_mail_notification: Mail notification settings
1025
  description_user_default_page: Default page settings
1021 1026
  description_available_columns: Available Columns
1022 1027
  description_selected_columns: Selected Columns
1023 1028
  description_all_columns: All Columns
config/locales/ja.yml
526 526
  label_my_account: 個人設定
527 527
  label_my_projects: マイプロジェクト
528 528
  label_my_page_block: マイページパーツ
529
  label_my_default_page: ログイン後のページ
529 530
  label_administration: 管理
530 531
  label_login: ログイン
531 532
  label_logout: ログアウト
......
777 778
  label_theme: テーマ
778 779
  label_default: 既定
779 780
  label_search_titles_only: タイトルのみ
781
  label_user_default_page_option_top: "トップページ"
782
  label_user_default_page_option_my_page: "マイページ"
783
  label_user_default_page_option_my_project: "参加しているプロジェクト"
780 784
  label_user_mail_option_all: "参加しているプロジェクトのすべての通知"
781 785
  label_user_mail_option_selected: "選択したプロジェクトのすべての通知..."
782 786
  label_user_mail_option_none: "通知しない"
......
1015 1019
  description_project_scope: 検索範囲
1016 1020
  description_filter: Filter
1017 1021
  description_user_mail_notification: メール通知の設定
1022
  description_user_default_page: ログイン後のページの設定
1018 1023
  description_date_from: 開始日
1019 1024
  description_message_content: 内容
1020 1025
  description_available_columns: 利用できる項目
db/migrate/20120509070818_add_users_default_page.rb
1
class AddUsersDefaultPage < ActiveRecord::Migration
2
  def self.up
3
    add_column :users, :default_page, :string, :default => "top"
4
    add_column :users, :default_project_id, :integer, :default => 0
5
  end
6

  
7
  def self.down
8
    remove_column :users, :default_page
9
    remove_column :users, :default_project_id
10
  end
11
end
    (1-1/1)