QA #1148
奈良 裕記 さんが約3年前に更新
h3. ■現象/要望
チケットのバージョン選択時の表示順番を調整したい。
対象バージョン欄は、作業中バージョン(未完了)だけなので、選択時の問題は少ないが、
発見バージョン(カスタムフィールドのVersion)は、長期間の運用で選択肢が大量になり、誤認し易い。
名称?作成?順に表示されるようだが、表示順番を逆にできないか。
h3. ■解決策
app/models/version.rbの def <=>(version) を変更することで、ある程度修正可能(バージョン選択/ロードマップ表示順序一括)。
h4. 現状(Redmine4.1時点)
・期日が前のバージョンから表示
期日未設定の場合、バージョン名称の昇順
バージョン名称も同一の場合は、バージョンIDの昇順(古いものが先に表示される場合が多い)
この表示順序は、JPLが意図して設計したもの
Version numbering sort
https://redmine.org/issues/6881#note-2
<pre>
Jean-Philippe Lang が9年以上前に更新
Versions are sorted by date then by name (alphabetically),
so what you describe is not a defect (1.1 < 1.10 < 1.2 is alphabetically correct).
What you expect is some kind of version numbering sort when names looks like x.y where x and y are integers.
</pre>
h4. 筆者の考え
・対象バージョンの場合、期日優先の表示は意味があるが、発見バージョンの場合、期日優先に表示することは無意味。
・発見バージョンは大量になるため、単純にバージョン名称でソートした方が選択し易い。
・新しく定義したバージョンを先に表示/選択可能とする方が、必要なバージョンを選択する時間を短縮できる。
h4. 暫定対策
期日の無視/優先表示により対処が異なる。
この順番は、ロードマップ、対象バージョン、発見バージョン共に影響する。
期日を無視し、バージョン名、バージョンIDの降順のみでソートする。
(文字列大きい方が新しい場合が多いため)
<pre><code class="ruby">
# Versions are sorted by effective_date and name
# Those with no effective_date are at the end, sorted by name
def <=>(version)
-1 * ( name == version.name ? id <=> version.id : name <=> version.name)
end
</code></pre>
期日指定バージョン優先、バージョン文字列は降順(文字列大きい方が新しい場合が多いため)
変更点:名前・バージョンIDの大小関係判定時に符号変えただけ(下記、-1 * の2か所)
app/models/version.rb
<pre><code class="ruby">
# Versions are sorted by effective_date and name
# Those with no effective_date are at the end, sorted by name
def <=>(version)
if self.effective_date
if version.effective_date
if self.effective_date == version.effective_date
-1 *(name == version.name ? id <=> version.id : name <=> version.name)
else
self.effective_date <=> version.effective_date
end
else
-1
end
else
if version.effective_date
1
else
-1 *(name == version.name ? id <=> version.id : name <=> version.name)
end
end
end
</code></pre>
h3. ■対応状況
パッチ作成済
h3. ■補足
!https://unofficial-redmine.org/matomo/matomo.php?rec=1148! !https://unofficial-redmine.org/matomo/matomo.php?idsite=1&rec=1148!
戻る