Project

General

Profile

automatically update custom field value

Added by Théodore Biadala over 13 years ago

hi,

I've been working on a plugin which helps bug triage using the "user pain" concept. It's pretty easy to get and to basically implement but i need some help as to how to make it work well inside of redmine.

For now i have a custom field of type integer (or float) named "User Pain" which value i update each time an issue is created or updated. The value is easy to compute, the core of it is :

( tracker's position in the tracker list * priority's position in the priority list ) / (available trackers * priority list length )

This bit works fine. The problem is when the priority list and / or the available trackers are modified. The value is not updated.

To sum up :

  • I create an issue, the value of user pain is accurate.
  • Then i add a tracker to the issue's project.
  • the value of user pain for the issue is not accurate anymore it needs to be computed again.

I've thought of computing the value each time an issue is loaded but i can't find the right hook to do that. I've thought of updating every issues each time tracker or priority is changed, but that's not really effective…

So if you know how i should best implement that, please tell me :)


Replies (6)

RE: automatically update custom field value - Added by Felix Schäfer over 13 years ago

You could use a virtual attribute instead of saving the attribute to the DB, i.e. extend the issue model with something like:

def user_pain
  # some computation to determine the user_pain
end

That way, you wouldn't need to "update" it, it would just be the correct value each time you call it.

RE: automatically update custom field value - Added by Théodore Biadala over 13 years ago

Indeed that would be best. I choose to go with a custom field to get the table/filter/ordering bit for "free". Do you have an exemple of how i could use this virtual attribute to order/filter the issue list ?

RE: automatically update custom field value - Added by Felix Schäfer over 13 years ago

Théodore Biadala wrote:

Indeed that would be best. I choose to go with a custom field to get the table/filter/ordering bit for "free". Do you have an exemple of how i could use this virtual attribute to order/filter the issue list ?

No easy way. Then use an after_initialize callback to recompute the value each time the object is loaded, see http://rails.rubyonrails.org/v2.3.8/classes/ActiveRecord/Callbacks.html

RE: automatically update custom field value - Added by Théodore Biadala over 13 years ago

Ok, i wanted to do this properly so i spent time looking at the budget and questions plugin. I've been able to add a column referencing the computed value. It's sortable too. No luck with grouping and adding a filter but it's that important.

code is here http://github.com/theodoreb/redmine_user_pain

I've still got a probleme with translations of ui strings : "translation missing: fr, field_user_pain". I've added a lang/en.yml and lang/fr.yml with value: UI text, is there something more to it ?

Thank you for your help so far :)

RE: automatically update custom field value - Added by Felix Schäfer over 13 years ago

Locale files need to be in config/locales, keys for a particular language have to be scoped under the top-level key for that locale. Example here: http://github.com/thegcat/redmine_doodles/blob/master/config/locales/fr.yml

RE: automatically update custom field value - Added by Théodore Biadala over 13 years ago

It still won't work for me but i'll figure it out now that i know how it's supposed to work.

Thanks again :)

    (1-6/6)