Hours icon indicating copy to clipboard operation
Hours copied to clipboard

Sorting projects in dropdown based on recent activity not alphabetically

Open alexanderjeurissen opened this issue 9 years ago • 8 comments

Often I find myself working on a limited set of projects at any given time, I think it would speed up the time tracking process if the projects I recently created entries for are on top in the dropdown.

An alternative would be to sort the projects in the dropdown based on recent activity of the tenant as a whole. That way less active projects would be on the bottom of the dropdown list.

alexanderjeurissen avatar Sep 11 '15 10:09 alexanderjeurissen

Yes, I agree :)

jurre avatar Sep 11 '15 11:09 jurre

which of the two would seem more logical to you @jurre ? (based on recent activity of the user, or based on recent activity of the tenant as a whole )

alexanderjeurissen avatar Sep 11 '15 13:09 alexanderjeurissen

Either is an improvement, I think the users activity would probably be more relevant for this though

jurre avatar Sep 11 '15 13:09 jurre

HI guys,

I think that a possible solution is update the project (update the updated_at field only) after create a new entry. In this way, we only list the projects order by updated_at field. In other case, we need sort them by the last entry and we need to make a lot of queries and check all creation dates.

If you want (/cc @jurre @alexanderjeurissen ), I can change after save callback in entries to update the project field (updated_at). If you have any other possible solution I can do it too.

jnillo avatar Sep 18 '15 11:09 jnillo

You could just do

belongs_to :project, touch: true

Right?

jurre avatar Sep 18 '15 12:09 jurre

@jurre the entry model already has

belongs_to :project, touch: true

Only sorting the project list that is rendered is necessary, however that would result in sorting the projects based on activity of the whole tenant. creating the desired behaviour for just the current user is a bit more complex.

alexanderjeurissen avatar Sep 18 '15 12:09 alexanderjeurissen

I just checked and the Project model already has a scope named by_last_updated so changing the relevant line in https://github.com/DefactoSoftware/Hours/blob/development/app/views/application/_entry_form.html.haml#L5 to use that scope instead of by_name will result in the sorting based on project activity of the whole tenant.

alexanderjeurissen avatar Sep 18 '15 12:09 alexanderjeurissen

Yes, it's a possibility. You need consider what is a "update for the project" in order with the project philosophy. Of course if you update the name of the project you update the project but this action meaning that it's an active project in that moment? I mean that we need take a decision if we add a new field to manage the last real update of the project (new entry or other event) or an update the updated_at field is enough. In the first case, we need to create callback to update the new field in project model when a relevant success appear, for example, after create in Entry model will update this new field in his project. In the second case, only with the modification of @alexanderjeurissen is enough.

jnillo avatar Sep 18 '15 14:09 jnillo