Project

General

Profile

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

Takenori TAKAKI, 2024-05-21 02:43

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 menu.to_sym == :project_menu || menu.to_sym == :application_menu
211
          menu_order = Setting.project_menu_order
212
          menu_order.unshift([:projects]) if menu.to_sym == :application_menu # Projects menu should always be first
213
          items.sort_by.with_index do |menu_item, i|
214
            menu_order.index { |menu_name| menu_item.name.to_s == menu_name.to_s } || i
215
          end
216
        else
217
          items
218
        end
219
      end
220

  
208 221
      def extract_node_details(node, project=nil)
209 222
        item = node
210 223
        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_for_project_menu
386
    Redmine::MenuManager.items(:project_menu).root.children.clear
387
    Redmine::MenuManager.map :project_menu do |menu|
388
      menu.push(:menu_1, '/', {})
389
      menu.push(:menu_2, '/', {})
390
      menu.push(:menu_3, '/', {})
391
    end
392

  
393
    with_settings :project_menu_order => [:menu_3, :menu_1, :menu_2] do
394
      project_menu_items = menu_items(:project_menu)
395
      assert_equal 3, project_menu_items.size
396
      assert_equal [:menu_3, :menu_1, :menu_2], project_menu_items.map(&:name)
397
    end
398
  end
399

  
400
  def test_menu_items_should_return_orderd_items_for_application_menu
401
    Redmine::MenuManager.items(:application_menu).root.children.clear
402
    Redmine::MenuManager.map :application_menu do |menu|
403
      menu.push(:projects, '/projects', {})
404
      menu.push(:menu_1, '/', {})
405
      menu.push(:menu_2, '/', {})
406
      menu.push(:menu_3, '/', {})
407
    end
408

  
409
    with_settings :project_menu_order => [:menu_3, :menu_1, :menu_2] do
410
      application_menu_items = menu_items(:application_menu)
411
      assert_equal 4, application_menu_items.size
412
      assert_equal [:projects, :menu_3, :menu_1, :menu_2], application_menu_items.map(&:name)
413
    end
414
  end
415

  
416
  def test_menu_items_should_not_change_order_for_other_menu
417
    Redmine::MenuManager.map :other_menu do |menu|
418
      menu.push(:menu_1, '/', {})
419
      menu.push(:menu_2, '/', {})
420
      menu.push(:menu_3, '/', {})
421
    end
422

  
423
    with_settings :project_menu_order => [:menu_3, :menu_1, :menu_2] do
424
      other_menu_items = menu_items(:other_menu)
425
      assert_equal 3, other_menu_items.size
426
      assert_equal [:menu_1, :menu_2, :menu_3], other_menu_items.map(&:name)
427
    end
428
  end
384 429
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
(5-5/6)