Skip to content

Conversation

kfischer-okarin
Copy link
Member

Redmine Issue: https://www.redmine.org/issues/2848

Scrapbox Memo (Japanese): https://scrapbox.io/redmine-patch/%E7%AC%AC2%E5%9B%9E%2FSort(%232848)

Written in cooperation with Goh Matsumoto, Akiko Takano and akipii

time_columns = %w(tyear tmonth tweek spent_on)
@hours = []
@scope.includes(:activity).
reorder(nil).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここはソートが解除されますが、@scopeにクエリーで指定したのソート順が入っているので、それを適用すればいいのでは?

reorder(nil).
group(@criteria.collect{|criteria| @available_criteria[criteria][:sql]} + time_columns).
joins(@criteria.collect{|criteria| @available_criteria[criteria][:joins]}.compact).
order(@criteria.collect{|criteria| @available_criteria[criteria][:order]}.compact).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

もう一度考えてみれば、ここは本当はこういう感じでやりたい

results = @scope.includes(:activity).
                 reorder(nil).
                 group(...).
                 joins(...)

@criteria.collect{|criteria| @available_criteria[criteria][:order]}.compact.each do |order_by_criteria|
  results = order_by_criteria(results)
end

result.sum(:hours).each do |hash, hours|
  ...

orderの項目を変換するブロックにしたらいい

@available_criteria = {
          'project' => {:sql => "#{TimeEntry.table_name}.project_id",
                        ...
                        order: ->(results) { results.order("#{Project.table_name}.name") }

これで、joinsとか必要だった場合に、その「メソッド」の任せたらいい。

@kfischer-okarin kfischer-okarin force-pushed the development branch 3 times, most recently from 7721af8 to b82bcac Compare September 4, 2020 14:50
@kfischer-okarin kfischer-okarin force-pushed the fix/2848 branch 2 times, most recently from 9ec8c6c to 4c7ddc1 Compare September 5, 2020 02:19
@kfischer-okarin kfischer-okarin force-pushed the development branch 2 times, most recently from 439883b to 7287657 Compare September 5, 2020 02:52
@kfischer-okarin kfischer-okarin force-pushed the development branch 3 times, most recently from fb09dfd to a9c8777 Compare September 5, 2020 03:10
@kfischer-okarin kfischer-okarin force-pushed the development branch 4 times, most recently from 2bed14b to 126c097 Compare September 5, 2020 03:33
@kfischer-okarin kfischer-okarin force-pushed the fix/2848 branch 2 times, most recently from 4e3092f to c2523d4 Compare September 5, 2020 05:22
@kfischer-okarin kfischer-okarin force-pushed the development branch 2 times, most recently from 3bd6e7f to 4e02d13 Compare September 5, 2020 06:30
@kfischer-okarin kfischer-okarin force-pushed the development branch 2 times, most recently from f842c84 to 0fcefd7 Compare September 11, 2020 07:46
@sanak sanak self-assigned this Mar 13, 2022
@github-actions
Copy link

Patch can be downloaded here

@sanak
Copy link
Member

sanak commented Mar 13, 2022

@kfischer-okarin こちら、本家のIssueのその後の経緯を確認したところ、Yuichi HARADAさんが6ヶ月前から別のパッチを作成され、1ヶ月ほど前にtrunkにマージされ、次期メジャーバージョンでリリースされるようでした。
https://www.redmine.org/issues/2848#note-9

問題なさそうでしたら、こちらはクローズしようかと思いますので、よろしくお願いします。

@sanak sanak assigned kfischer-okarin and unassigned sanak Mar 13, 2022
@kfischer-okarin kfischer-okarin deleted the fix/2848 branch March 14, 2022 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants