1 # $Id$ |
2 |
3 class HudsonApplicationHooks < Redmine::Hook::ViewListener |
4 |
5 include ActionView::Helpers::DateHelper |
6 include ApplicationHelper |
7 |
8 def view_layouts_base_html_head(context = {}) |
9 project = context[:project] |
10 return '' unless project |
11 controller = context[:controller] |
12 return '' unless controller |
13 action_name = controller.action_name |
14 return '' unless action_name |
15 |
16 baseurl = url_for(:controller => 'hudson', :action => 'index', :id => project) + '/../../..' |
17 |
18 if (controller.class.name == 'ProjectsController' and action_name == 'activity') |
19 hudson = Hudson.find_by_project_id(project.id) |
20 return '' unless hudson.settings.url |
21 o = "" |
22 o << "<style type='text/css'>" |
23 o << ".hudson-build { background-image: url(#{hudson.settings.url}favicon.ico); }" |
24 o << "</style>\n" |
25 o << "<!--[if IE]>" |
26 o << "<style type='text/css'>" |
27 o << ".hudson-build { background-image: url(#{baseurl}/plugin_assets/redmine_hudson/images/hudson_icon.png); }" |
28 o << "</style>\n" |
29 o << "<![endif]-->" |
30 return o |
31 end |
32 |
33 if (controller.class.name == 'IssuesController' and action_name == 'show') |
34 o = "" |
35 o << stylesheet_link_tag(baseurl + "/plugin_assets/redmine_hudson/stylesheets/hudson.css") + "\n" |
36 o << javascript_include_tag(baseurl + "/plugin_assets/redmine_hudson/javascripts/build_result.js") + "\n" |
37 o << javascript_include_tag(baseurl + "/plugin_assets/redmine_hudson/javascripts/revision_build_results.js") + "\n" |
38 return o |
39 end |
40 |
41 end |
42 |
43 def view_issues_show_description_bottom(context = {}) |
44 return '' unless context[:issue] |
45 issue = context[:issue] |
46 |
47 o = '' |
48 o << "<script type='text/javascript'>" + "\n" |
49 o << "builds = $H();" + "\n" |
50 issue.changesets.each {|changeset| |
51 builds = HudsonBuild.find_by_changeset(changeset) |
52 next if builds.length == 0 |
53 o << "results = new RevisionBuildResults('#{changeset.revision}');" + "\n" |
54 builds.each{|build| |
55 job = HudsonJob.find(:first, :conditions=>["#{HudsonJob.table_name}.id = ?", build.hudson_job_id]) |
56 finished_at_tag = link_to(distance_of_time_in_words(Time.now, build.finished_at), |
57 {:controller => 'projects', :action => 'activity', :id => @project, :from => build.finished_at.to_date}, |
58 :title => format_time(build.finished_at)) |
59 o << "results.add(" |
60 o << "new BuildResult('#{job.name}',#{build.number},'#{build.result}','#{build.finished_at}','#{finished_at_tag}','#{build.url_for(:user)}'));" + "\n" |
61 } |
62 o << "builds.set(results.revision, results);" + "\n" |
63 } |
64 o << "Event.observe(window, 'load', add_build_info_to_changesets);" + "\n" |
65 o << "function add_build_info_to_changesets(){" + "\n" |
66 o << " var messages = $$('div[class^=\"changeset\"] p');" + "\n" |
67 o << " messages.each(function(message){" + "\n" |
68 o << " if ( message.innerHTML.indexOf('#{l(:label_revision)}') > 0) {" + "\n" |
69 o << " add_build_info_to_changeset(message);" + "\n" |
70 o << " }" + "\n" |
71 o << " });" + "\n" |
72 o << "};" + "\n" |
73 o << "function add_build_info_to_changeset(message){" + "\n" |
74 o << " var keys = builds.keys();" + "\n" |
75 o << " for( var index=0; index<keys.length; index++ ) {" + "\n" |
76 o << " build = builds.get(keys[index]);" + "\n" |
77 o << " if ( message.innerHTML.indexOf('#{l(:label_revision)} ' + keys[index]) > 0 ) {" + "\n" |
78 o << " buildKeys = build.results.keys();" + "\n" |
79 o << " for ( var bIndex=0; bIndex<buildKeys.length; bIndex++ ) {" + "\n" |
80 o << " result = build.results.get(buildKeys[bIndex]);" + "\n" |
81 o << " message.innerHTML += '<br>' + result.message();" + "\n" |
82 o << " }" + "\n" |
83 o << " }" + "\n" |
84 o << " }" + "\n" |
85 o << "}" + "\n" |
86 o << "</script>" |
87 end |
88 end |