OSDN Git Service

implement(in progress): WorkTime plug-in extension. refs #1362 (http://www.r-labs...
authorAkira Saito <akrstjp@users.sourceforge.jp>
Wed, 18 Mar 2015 15:20:12 +0000 (00:20 +0900)
committerAkira Saito <akrstjp@users.sourceforge.jp>
Wed, 18 Mar 2015 15:20:12 +0000 (00:20 +0900)
app/controllers/quick_view_worktime_issues_controller.rb [new file with mode: 0644]
app/views/hooks/_quick_view_issues_footer.html.erb
app/views/hooks/_quick_view_issues_header.html.erb [new file with mode: 0644]
app/views/quick_view_worktime_issues/quick_view_worktime_tooltip.html.erb [new file with mode: 0644]
config/routes.rb
hooks.rb

diff --git a/app/controllers/quick_view_worktime_issues_controller.rb b/app/controllers/quick_view_worktime_issues_controller.rb
new file mode 100644 (file)
index 0000000..6fe71de
--- /dev/null
@@ -0,0 +1,21 @@
+class QuickViewWorktimeIssuesController < ApplicationController
+  before_filter :find_issue, :find_project_from_association, :only => [:show]
+
+  def show
+    respond_to do |format|
+      format.html {
+        render :template => 'quick_view_worktime_issues/quick_view_worktime_tooltip',
+               :layout => false,
+               :issue => @issue
+      }
+    end
+  end
+
+private
+  def find_issue
+    logger.info "issue_id => #{params[:id]}"
+    @issue = @object = Issue.find(params[:id])
+  rescue ActiveRecord::RecordNotFound
+    render_404
+  end
+end
index 986c851..31858df 100644 (file)
@@ -1,4 +1,5 @@
 <div id="quick_view_dialogs"></div>
+<div id="quick_view_tooltip" style="background-color: white; border: solid 1px gray;"></div>
 
 <script>
 //<![CDATA[
@@ -15,39 +16,27 @@ function quick_view_work_time_extension_init(){
   var links = $(".wt_iss_link");
   links.each(function(){
      var link = $(this);
-     if (link.hasClass("has_quick_view_inited")) return;
-
-     link.tooltip();
+     if (link.hasClass("has_quick_view_anchor")) return;
 
      var insertTo = link.next(".wt_done_ratio");
      if (insertTo.length == 0) {
        insertTo = link;
      }
      var issue_id = link.data("issue");
-     $("<a style='margin-left: 5px;' href='javascript: quick_view_show_dialog("+issue_id+");'><img src='<%= image_path("external.png") %>'></img></a>").insertAfter(insertTo);
-     link.addClass("has_quick_view_inited");
+     var anchor_html="<a style='margin-left: 5px;' href='javascript: quick_view_show_dialog("+issue_id+");'><img src='<%= image_path("external.png") %>'></img></a>";
+     $(anchor_html).insertAfter(insertTo);
+     link.addClass("has_quick_view_anchor");
   });
 
-  links.mouseenter(function(){
+  links.mouseover(function(){
      var link = $(this);
      if (link.hasClass("has_tooltip")) return;
   
      var issue_id = link.data("issue");
-     var url = "<%= issue_path(0) %>".replace(/0$/, link.data("issue")) + ".json";
-     $.ajax( { url: url, dataType: 'json', success: function (json){
-       var title="";
-       title += "Project: " + json.issue.project.name + "<br>";
-       title += "Assignee: " + ((json.issue.assigned_to)?json.issue.assigned_to.name:"") + "<br>";
-       if (json.issue.due_date){
-         title += "Due date: " + /(....-..-..)/.exec(json.issue.due_date)[1]+"<br>";
-       } else {
-         title += "Due date: <br>";
-       }
-       title += "Spent time: " + json.issue.spent_hours + " hours<br>";
-       title += "<hr>";
-       title += "<span style='font-size:0.75em'>Updated on: " + /(....-..-..)/.exec(json.issue.updated_on)[1]+"</span><br>";
-       link.attr("title", title);
+     var url = "<%= quick_view_worktime_issue_path(0) %>".replace(/0$/, link.data("issue"));
+     $.ajax( { url: url, dataType: 'html', success: function (html){
        link.addClass("has_tooltip");
+       link.tooltip({tooltipClass:"quick_view_tooltip", track: true, create:function(){link.attr("title",html);}});
        link.tooltip("open");
      }});
   });
diff --git a/app/views/hooks/_quick_view_issues_header.html.erb b/app/views/hooks/_quick_view_issues_header.html.erb
new file mode 100644 (file)
index 0000000..84f51df
--- /dev/null
@@ -0,0 +1,29 @@
+<style>
+ .quick_view_tooltip {
+   background: white none;
+   font-size: 0.9em;
+}
+
+.quick_view_tooltip .subject p{
+//  font-size: 0.8em;
+   margin-top: 0.2em;
+   margin-bottom: 0.2em;
+}
+
+.quick_view_tooltip .subject h3{
+   font-size: 1.25em;
+   margin-left: 0px;
+}
+
+.quick_view_tooltip .subject div{
+   margin-left: 1em;
+}
+
+.quick_view_tooltip div.subject{
+   margin-left: -1em;
+}
+
+.quick_view_tooltip_attributes th {
+   text-align: left;
+}
+</style>
diff --git a/app/views/quick_view_worktime_issues/quick_view_worktime_tooltip.html.erb b/app/views/quick_view_worktime_issues/quick_view_worktime_tooltip.html.erb
new file mode 100644 (file)
index 0000000..3c3a39f
--- /dev/null
@@ -0,0 +1,48 @@
+<%
+  #template args
+  #  issue - drawing target
+
+  extend ProjectsHelper
+  extend IssuesHelper
+  extend AttachmentsHelper
+  extend CustomFieldsHelper
+#  extend RepositoriesHelper
+#  extend JournalsHelper
+
+  issue = @issue
+  project = @issue.project
+%>
+     <div>
+        <div class="subject">
+        <%= render_issue_subject_with_tree(issue) %>
+        </div>
+        <hr>
+        <table class="quick_view_tooltip_attributes">
+          <tr><th class="status"><%=l(:field_status) %></th><td class="status" ><%= h(issue.status.name)%></td></tr>
+          <tr><th class="priority"><%=l(:field_priority) %></th><td class="priority"><%= h(issue.priority.name)%></td></tr>
+          <tr><th class="assigned-to"><%=l(:field_assigned_to) %></th><td class="assigned_to"><%= avatar(issue.assigned_to, :size => "14").to_s.html_safe + (issue.assigned_to ? link_to_user(issue.assigned_to) : "-") %></td></tr>
+          <tr><th class="start-date"><%=l(:field_start_date) %></th><td class="start-date"><%= format_date(issue.start_date)%></td></tr>
+          <tr><th class="due-date"><%=l(:field_due_date) %></th><td class="due-date"><%= format_date(issue.due_date)%></td></tr>
+          <% unless issue.disabled_core_fields.include?('estimated_hours') %>
+          <%  unless issue.estimated_hours.nil? %>
+          <tr><th class="estimated-hours"><%=l(:field_estimated_hours) %></th><td class="estimated-hours"><%= format_date(issue.estimated_hours)%></td></tr>
+          <%  end %>
+          <% end%>
+          <% if User.current.allowed_to?(:view_time_entries, project) %>
+          <tr>
+          <%  redmine_version = Redmine::VERSION::MAJOR * 10 + Redmine::VERSION::MINOR %>
+          <%  if redmine_version < 26 %>
+            <th class="spent-time"><%=l(:label_spent_time) %></th>
+            <td class="spent-time"><%= (issue.total_spent_hours > 0 ? link_to(l_hours(issue.total_spent_hours), project_issue_time_entries_path(project, issue)) : "-") %></td>
+          <%  else %>
+            <th class="spent-time"><%=l(:label_spent_time) %></th>
+            <td class="spent-time"><%= (issue.total_spent_hours > 0 ? link_to(l_hours(issue.total_spent_hours), issue_time_entries_path(issue)) : "-") %></td>
+          <%  end %>
+          </tr>
+          <% end %>
+        </table>
+        <hr>
+        <% if issue.created_on != issue.updated_on %>
+        <%= l(:label_updated_time, time_tag(issue.updated_on)).html_safe %>.
+        <% end %>
+     </div>
index 5f1f857..e56cfd3 100644 (file)
@@ -3,6 +3,7 @@
 RedmineApp::Application.routes.draw do
 
   resources :quick_view_issues, :controller => 'quick_view_issues', :only => [:show]
+  resources :quick_view_worktime_issues, :controller => 'quick_view_worktime_issues', :only => [:show]
   resources :issues do
     shallow do
     end
index ec733fb..bbf50d6 100644 (file)
--- a/hooks.rb
+++ b/hooks.rb
@@ -2,5 +2,6 @@
 
 class QuickViewHooks < Redmine::Hook::ViewListener
        render_on :view_issues_context_menu_end, :partial=> 'hooks/quick_view_context'
+        render_on :view_layouts_base_html_head, :partial=> 'hooks/quick_view_issues_header'
         render_on :view_layouts_base_body_bottom, :partial=> 'hooks/quick_view_issues_footer'
 end