Project

General

Profile

Feature #6984 » 6984-enable-to-reorder-project-menu.patch

Takenori TAKAKI, 2024-05-15 16:54

View differences:

app/assets/stylesheets/application.css
444 444
.query-columns select {
445 445
  min-width:150px;
446 446
}
447
.menu-items label {
448
  display:block;
449
}
450
.menu-items select {
451
  min-width: 200px;
452
}
447 453

  
448 454
.query-totals {text-align:right; margin-top:-2.3em;}
449 455
.query-totals>span:not(:first-child) {margin-left:0.6em;}
app/views/settings/_projects.html.erb
39 39
  </p>
40 40
</fieldset>
41 41

  
42
<fieldset class="box">
43
  <legend><%= l(:setting_project_menu_order) %></legend>
44
  <div id="list-definition">
45
    <% menu_order_tag_id = "project_menu_order" %>
46
    <% project_menu_items = menu_items(:project_menu) %>
47
    <div>
48
      <div class="menu-items">
49
        <%= label_tag menu_order_tag_id, l(:label_menu_order) %>
50
        <%= select_tag "settings[#{menu_order_tag_id}]",
51
              options_for_select(project_menu_items.map {|m| [m.caption, m.name]}),
52
              :id => menu_order_tag_id,
53
              :multiple => true, :size => project_menu_items.count %>
54
      </div>
55
      <div class="buttons">
56
        <input type="button" value="&#8648;" onclick="moveOptionTop(this.form.<%= menu_order_tag_id %>);" />
57
        <input type="button" value="&#8593;" onclick="moveOptionUp(this.form.<%= menu_order_tag_id %>);" />
58
        <input type="button" value="&#8595;" onclick="moveOptionDown(this.form.<%= menu_order_tag_id %>);" />
59
        <input type="button" value="&#8650;" onclick="moveOptionBottom(this.form.<%= menu_order_tag_id %>);" />
60
      </div>
61
      <%= javascript_tag do %>
62
      $(document).ready(function(){
63
        $('.menu-items').closest('form').submit(function(){
64
          $('#<%= menu_order_tag_id %> option:not(:disabled)').prop('selected', true);
65
        });
66
      });
67
      <% end %>
68
    </div>
69
  </div>
70
</fieldset>
71

  
42 72

  
43 73
<%= submit_tag l(:button_save) %>
44 74
<% end %>
config/locales/en.yml
516 516
  setting_timelog_accept_future_dates: Accept time logs on future dates
517 517
  setting_show_status_changes_in_mail_subject: Show status changes in issue mail notifications subject
518 518
  setting_project_list_defaults: Projects list defaults
519
  setting_project_menu_order: Project menu order
520
  label_menu_order: order
519 521
  setting_twofa: Two-factor authentication
520 522

  
521 523
  permission_add_project: Create project
config/locales/ja.yml
1299 1299
  label_display_type: 表示形式
1300 1300
  label_display_type_list: リスト
1301 1301
  label_display_type_board: ボード
1302
  setting_project_menu_order: プロジェクトメニューの並び順
1303
  label_menu_order: 順序
1302 1304
  label_my_bookmarks: My bookmarks
1303 1305
  label_import_time_entries: 作業時間のインポート
1304 1306
  field_toolbar_language_options: ツールバーのコードハイライトボタンで使用する言語
config/settings.yml
344 344
  default: 1
345 345
show_status_changes_in_mail_subject:
346 346
  default: 1
347
project_menu_order:
348
  serialized: true
349
  default:
350
    - new_object
351
    - overview
352
    - activity
353
    - roadmap
354
    - issues
355
    - new_issue
356
    - time_entries
357
    - gantt
358
    - calendar
359
    - news
360
    - documents
361
    - wiki
362
    - boards
363
    - files
364
    - repository
365
    - settings
lib/redmine/menu_manager.rb
193 193

  
194 194
      def menu_items_for(menu, project=nil)
195 195
        items = []
196
        Redmine::MenuManager.items(menu).root.children.each do |node|
196
        menu_items(menu).each do |node|
197 197
          if node.allowed?(User.current, project)
198 198
            if block_given?
199 199
              yield node
......
205 205
        return block_given? ? nil : items
206 206
      end
207 207

  
208
      def menu_items(menu)
209
        items = Redmine::MenuManager.items(menu).root.children
210
        if Setting.available_settings.include?("#{menu.to_s}_order")
211
          items.sort_by.with_index do |menu_item, i|
212
            (Setting.send("#{menu.to_s}_order") || []).index { |menu_name| menu_item.name.to_s == menu_name.to_s } || i
213
          end
214
        else
215
          items
216
        end
217
      end
218

  
208 219
      def extract_node_details(node, project=nil)
209 220
        item = node
210 221
        url =
test/unit/lib/redmine/menu_manager/menu_helper_test.rb
381 381
    items = menu_items_for(menu_name, Project.find(1))
382 382
    assert_equal 1, items.size
383 383
  end
384

  
385
  def test_menu_items_should_return_orderd_items_when_project_menu_is_ordered
386
    Redmine::MenuManager.items(:project_menu).root.children.clear
387
    Redmine::MenuManager.map :project_menu do |menu|
388
      menu.push(:project_menu_1, '/', {})
389
      menu.push(:project_menu_2, '/', {})
390
      menu.push(:project_menu_3, '/', {})
391
    end
392
    Redmine::MenuManager.map :other_menu do |menu|
393
      menu.push(:other_menu_1, '/', {})
394
      menu.push(:other_menu_2, '/', {})
395
      menu.push(:other_menu_3, '/', {})
396
    end
397

  
398
    with_settings :project_menu_order => [:project_menu_3, :project_menu_1, :project_menu_2] do
399
      project_menu_items = menu_items(:project_menu)
400
      assert_equal 3, project_menu_items.size
401
      assert_equal [:project_menu_3, :project_menu_1, :project_menu_2], project_menu_items.map(&:name)
402

  
403
      other_menu_items = menu_items(:other_menu)
404
      assert_equal 3, other_menu_items.size
405
      assert_equal [:other_menu_1, :other_menu_2, :other_menu_3], other_menu_items.map(&:name)
406
    end
407
  end
384 408
end
test/unit/setting_test.rb
149 149
  def test_default_text_formatting_for_new_installations_is_common_mark
150 150
    assert_equal 'common_mark', Setting.text_formatting
151 151
  end
152

  
153
  def test_project_menu_order_should_return_project_menu_names
154
    assert_equal %w(new_object overview activity roadmap issues new_issue time_entries gantt calendar news documents wiki boards files repository settings), Setting.project_menu_order
155
  end
152 156
end
(1-1/6)