J3RN / time-tracker

A time tracking application
http://timesheet.j3rn.com
MIT License
6 stars 14 forks source link

Order first by whether time is due today, then by priority #71

Closed J3RN closed 7 years ago

J3RN commented 7 years ago

This implementation is inelegant, and I would appreciate it if anyone could suggest a better one.

3ygun commented 7 years ago

Could you do:

todos = all.sort_by! { |x| -x.priority }
today = todos.reject { |x| x.time_remaining_today.zero? }
not_today = todos.select { |x| x.time_remaining_today.zero? }

today + not_today
J3RN commented 7 years ago

@3ygun Thanks! That's definitely DRYer, isn't it?

I'm holding out on a purely database solution to this. What I'd love is if there was some sort of computed column, time_remaining_today. I'm not sure if that's even possible or pragmatic, but it's something I'd definitely like to look into.

UPDATE: It looks like I'd have to use a view or a function. There's some pragmatic issue with this, namely that the logic for the application would be split between the Rails application and the database. What I have seen elsewhere is people putting giant SQL queries in their models, but that hardly seems pragmatic either. I'll look into this more when I have time.

J3RN commented 7 years ago

I've decided that your refactor is good enough for now, and I can dig deeper if I need to or have extra time.