Rails noob going crazy! trying to develop a very simple plugin!!

Added by Christopher Tufaro almost 9 years ago

Hi everyone!

I've been tasked with writing a plugin for Redmine (duh, why else would I be here). The plugin is simple, a pop-up box with a happy face, neutral face, frowney face, is to appear AFTER a user CLOSES or RESOLVES an issue. We want to know how happy/sad people are when they work. We expect a lot of frowns :(

I've started the plugin, read up on Hooks, Callbacks, Internals, and the Polls Plugins tutorial.

I originally thought to use a View Hook and pop up my faces view for a user to answer. However, I think redirecting the user AFTER they save an issue is better (assuming the issue is being resolved or closed).

I then went down the rabbit hole of using callbacks (after_save). However I have no idea how to pass the issue information to the view (status_id and tracker_id to be specific).

I'm lost and have already burnt a week trying to figure this out.

Any suggestions or pointers is GREATLY APPRECIATED!!

Thanks!!

Replies (1)

RE: Rails noob going crazy! trying to develop a very simple plugin!! - Added by Razi Baluchi almost 9 years ago

Here is an example from a plugin that updates the done ratio when an issue is updated. You can reference any attribute you want similarly. e.g. self.status_id or self.tracker_id

module RedmineAutoPercent
  module IssuePatch
    def self.included(base)
      base.extend(ClassMethods)

      base.send(:include, InstanceMethods)

      base.class_eval do
        before_save :update_percent
      end
    end
  end

  module ClassMethods
  end

  module InstanceMethods
    def update_percent
      if !new_record? && status_id_changed?
      self.done_ratio =  self.status.default_done_ratio if (!self.status.default_done_ratio.blank? && !self.done_ratio_changed?) || (!self.status.default_done_ratio.blank? && self.status.is_closed?)
      end
    end
  end
end

(1-1/1)