æ¨æ¥ï¼Redmineプラグイン作成でHookを使ってみる - torutkのブログï¼ã¯ãRedmineãç¨æããããã¯ã®æ©æ§ã使ã£ã¦ããã±ããä¸è¦§è¡¨ç¤ºç»é¢ã®ä¸ã«ä»»æã®è¡¨ç¤ºãå·®ãè¾¼ãã§ã¿ã¾ããããã ãã表示ã¯åºå®æååã®ã¿ã§ãããRuby on Railsã§ã¯ãæ¡å¼µå.erbã®ãã¡ã¤ã«ã§HTMLã®ãã³ãã¬ã¼ããç¨æãå®è¡æã«æ±ºã¾ãå¤ãåæ ãããã¨ãªã©ãå¯è½ã§ããæ¨æ¥ã¯åºå®æååã ãæ¸ãã¦ãåçãªè¨è¿°ã課é¡ã¨ãã¦ç©ã¿æ®ãã¦ããerbãã¡ã¤ã«ã®è¨è¿°æ¹æ³ãå°ã追ã£ã¦ã¿ã¾ãã
ãã©ã°ã¤ã³ã®app/views/issues/_issuesIndexBottom.html.erb ãããã
Redmineæ¬ä½ã«ã¯ãæ¡å¼µåã.html.erbã¨ãªã£ã¦ããå¤æ°ã®ãã¡ã¤ã«ãåå¨ãã¾ããããããåèã¨ãã¾ãã
ãã±ããä¸è¦§è¡¨ç¤ºã§ã¯ã
ãã®index.html.erbãè¦ã¦ããã¨ã@ã§å§ã¾ãå¤æ°ã®åç §ãããã¤ãè¦ããã¾ãã
@project @query @issues @issue_pages @issue_count @sort_criteria
Ruby on Railsã§ã¯ãHTMLã®ãã³ãã¬ã¼ããã¡ã¤ã«åã¯ã<ã¢ã¯ã·ã§ã³å>.html.erbã¨ããè¦ç´ã®ããã§ããRedmineã®ãã±ããä¸è¦§è¡¨ç¤ºã¯ã¢ã¯ã·ã§ã³ãindexãªã®ã§ãindex.html.erbã¨ãªã£ã¦ããã¨æããã¾ãããã³ãã¬ã¼ãã¯ãµã¤ãã«HTMLã®è¨è¿°ãå¯è½ã§ãããå®è¡æã«æ±ºã¾ãåçãªå¤ã¯ãã¢ã¯ã·ã§ã³ï¼ã³ã³ããã¼ã©ï¼ã®ã¤ã³ã¹ã¿ã³ã¹å¤æ°ã«å¤ãè©°ãããã³ãã¬ã¼ãããã¤ã³ã¹ã¿ã³ã¹å¤æ°ãåç §ãã¦å¤ãé©ç¨ãã¾ãããã®ã¤ã³ã¹ã¿ã³ã¹å¤æ°ãä¸è¿°ã®@ã§å§ã¾ãå¤æ°ã§ãã
ããã§ãã©ããªã¤ã³ã¹ã¿ã³ã¹å¤æ°ãåå¨ããã®ãã確èªããããã
class IssuesController < ApplicationController :ï¼ç¥ï¼ def index : @issue_count = @query.issue_count @issue_pages = Paginator.new @issue_count, @limit, params['page'] @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], .. @issue_count_by_group = @query.issue_count_by_group
ã¨ãã£ãã¤ã³ã¹ã¿ã³ã¹å¤æ°ãå®ç¾©ããã¦ãã¾ãã
Rubyã§ã¯ãå¤æ°å®£è¨ã¯ãªããå
é ãã@ãã§å§ã¾ãå¤æ°ãã¤ã³ã¹ã¿ã³ã¹å¤æ°ã¨ãã¦æ±ãã¾ãã
ã§ã¯ãæ¨æ¥ä½æããView hooksã¨ãã¦å·®ãè¾¼ããã³ãã¬ã¼ããå°ãä¿®æ£ãã¦ã¿ã¾ãã
- ãã©ã°ã¤ã³ã®app/views/issues/_issuesIndexBottom.html.erb
<h3>HOOKED</h3> <p>issue count is <%= @issue_count %></p>
ä¿®æ£ãä¿åãããã±ããä¸è¦§è¡¨ç¤ºãã¼ã¸ã«ã¢ã¯ã»ã¹ãã¾ããdevelopment ã¢ã¼ãã ããããWEBrickã®åèµ·åãããªãã¦ãåæ ããã¾ããã
ããã¨
HOOKED issue count is 26
ã¨è¡¨ç¤ºããã¾ããã
å¤ã§ã¯ãªãããªãã¸ã§ã¯ãã¸ã®ã¡ã½ããå¼ã³åºãã®çµæã表示ãããå ´åãã
<h3>HOOKED</h3> <p>issues displayed are <%= @issues.length %></p>
ã¨ã¡ã½ããå¼ã³åºãã®è¨è¿°ãå¯è½ã§ããï¼lengthã¯ãé åã®è¦ç´ æ°ãã¡ãªã¿ã«ãã®@issues.lengthã¯è¡¨ç¤ºãã¦ãã件æ°ãè¿ãã¾ããï¼
ããã¯ï¼View hooksï¼ã¨ã¯
Redmineæ¬ä½ã§ãããããæ¡å¼µç¨ã«ç¨æããã表示é¨ä½ãView hooksã§ããã±ããä¸è¦§è¡¨ç¤ºã®å ´åã¯ãä¸è¦§è¡¨ç¤ºã®ä¸ã«view_issues_index_bottomã®ååã§ããã¯ãè¨ãããã¦ãã¾ãã
ããã¯ã«ã³ã¼ã«ããã¯ããããã¦ããã¨ã表示ã«éãã¦ã³ã¼ã«ããã¯ãå¼ã°ããããã«è¿½å ã®è¡¨ç¤ºãå ¥ãè¾¼ããã¨ãã§ãã¾ããã³ã¼ã«ããã¯ã¯ãRedmine::Hook::ViewListenerã¯ã©ã¹ãç¶æ¿ããã¯ã©ã¹ã¨ãã¦å®ç¾©ããinit.rbã«require_dependencyæã§å®ç¾©ãèªã¿è¾¼ã¾ãã¾ãã
ã³ã¼ã«ããã¯ã®å¦çã¯ã表示系ã®å ´å render_on ãã«ãã¼ã§ããã¯åã¨è¡¨ç¤ºãã³ãã¬ã¼ãï¼ãã¼ã·ã£ã«ï¼ï¼ãæå®ãã¦ããã¨ããã®ãã³ãã¬ã¼ãã«ãã£ã¦çæããã表示ãããã¯ã®é¨ä½ã«å·®ãè¾¼ã¾ãã¾ãã
表示ãã³ãã¬ã¼ãã§åç §ã§ããã®ã¯ãã³ã³ããã¼ã©ã®ã¤ã³ã¹ã¿ã³ã¹å¤æ°ã¨ãªãã®ã§ãã³ã³ããã¼ã©ãæ³å®ãã¦ããç¯å²ã®ãã¼ã¿ã使ã£ã¦åçãªè¡¨ç¤ºãå®ç¾ã§ãã¾ããéã«ããã以ä¸ã®ãã¨ãããããã¨ããããããã¯ã§ã¯ãªãå¥ã®æ段ã使ããã¨ã«ãªãã®ãã¨æãã¾ãã
ãã¾ã
ã³ã³ããã¼ã©ããã¯
ãã±ãã表示é¢ä¿ã®ã³ã³ããã¼ã©ããã¯ãæ¢ãã¦ã¿ãã¨ï¼grep -r call_hook * | grep controlï¼ã次ã®ååãé¢ä¿ãã¦ãããã§ãã
- :controller_issues_new_before_save
- :controller_issues_new_after_save
- :controller_issues_bulk_edit_before_save
- :controller_issues_edit_before_save
- :controller_issues_edit_after_save
ãã±ããå¤æ´ã®åå¾ã§å¦çãå·®ãè¾¼ããã¨ãã§ãããã§ãã
ãã ãããã«ã¯ä¸è¦§è¡¨ç¤ºã«å·®ãè¾¼ãããã¯ã¯ãªãããã§ãã
ã¢ãã«ããã¯
Redmineå ¨ä½ã§2ã¤ã®ããã§ãã
- model_changeset_scan_commit_for_issue_ids_pre_issue_update
- model_project_copy_before_save