From 3d6d8bd1921e54c90915a71aa10ce66ade57928c Mon Sep 17 00:00:00 2001
From: Hagen Schink
Date: Tue, 2 Jul 2013 14:54:49 +0200
Subject: [PATCH] Show work package relations
---
.../work_package_relations_controller.rb | 52 +++++++++++++++++++
.../work_package_relations/_form.html.erb | 27 ++++++++++
.../work_package_relations/create.js.erb | 21 ++++++++
.../work_package_relations/destroy.js.erb | 13 +++++
app/views/work_packages/_relation.html.erb | 39 ++++++++++++++
app/views/work_packages/_relations.html.erb | 36 +++++++++++++
app/views/work_packages/show.html.erb | 2 +-
7 files changed, 189 insertions(+), 1 deletion(-)
create mode 100644 app/controllers/work_package_relations_controller.rb
create mode 100644 app/views/work_package_relations/_form.html.erb
create mode 100644 app/views/work_package_relations/create.js.erb
create mode 100644 app/views/work_package_relations/destroy.js.erb
create mode 100644 app/views/work_packages/_relation.html.erb
create mode 100644 app/views/work_packages/_relations.html.erb
diff --git a/app/controllers/work_package_relations_controller.rb b/app/controllers/work_package_relations_controller.rb
new file mode 100644
index 0000000000..cd6751fb71
--- /dev/null
+++ b/app/controllers/work_package_relations_controller.rb
@@ -0,0 +1,52 @@
+#-- encoding: UTF-8
+#-- copyright
+# OpenProject is a project management system.
+#
+# Copyright (C) 2012-2013 the OpenProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# See doc/COPYRIGHT.rdoc for more details.
+#++
+
+class WorkPackageRelationsController < ApplicationController
+ before_filter :find_work_package, :find_project_from_association, :authorize
+
+ def create
+ @relation = @work_package.new_relation.tap do |r|
+ r.issue_to = WorkPackage.visible.find_by_id(params[:relation][:issue_to_id].match(/\d+/).to_s)
+ r.relation_type = params[:relation][:relation_type]
+ r.delay = params[:relation][:delay]
+ end
+
+ @relation.save
+
+ respond_to do |format|
+ format.html { redirect_to work_package_path(@work_package) }
+ format.js {}
+ end
+ end
+
+ def destroy
+ @relation = @work_package.relation(params[:id])
+
+ @relation.destroy
+
+ respond_to do |format|
+ format.html { redirect_to issue_path(@issue) }
+ format.js {}
+ end
+ end
+
+ def work_package
+ @work_package
+ end
+
+private
+ def find_work_package
+ @work_package = @object = WorkPackage.find(params[:work_package_id])
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
+end
diff --git a/app/views/work_package_relations/_form.html.erb b/app/views/work_package_relations/_form.html.erb
new file mode 100644
index 0000000000..a38d2f9649
--- /dev/null
+++ b/app/views/work_package_relations/_form.html.erb
@@ -0,0 +1,27 @@
+<%#-- copyright
+OpenProject is a project management system.
+
+Copyright (C) 2012-2013 the OpenProject Team
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License version 3.
+
+See doc/COPYRIGHT.rdoc for more details.
+
+++#%>
+
+<%= error_messages_for 'relation' %>
+
+
+ <%= f.select :relation_type, collection_for_relation_type_select, {}, :onchange => "setPredecessorFieldsVisibility();" %>
+ <%= WorkPackage.model_name.human %> #<%= f.text_field :issue_to_id, :size => 10 %>
+
+ <%= javascript_tag "observeRelatedIssueField('#{issues_auto_complete_path(:id => controller.work_package, :project_id => @project, :escape => false) }')" %>
+
+ <%= IssueRelation.human_attribute_name(:delay) %>: <%= f.text_field :delay, :size => 3 %> <%= l(:label_day_plural) %>
+
+ <%= submit_tag l(:button_add) %>
+ <%= toggle_link l(:button_cancel), 'new-relation-form'%>
+
+
+<%= javascript_tag "setPredecessorFieldsVisibility();" %>
diff --git a/app/views/work_package_relations/create.js.erb b/app/views/work_package_relations/create.js.erb
new file mode 100644
index 0000000000..18e5c8b91d
--- /dev/null
+++ b/app/views/work_package_relations/create.js.erb
@@ -0,0 +1,21 @@
+<%#-- copyright
+OpenProject is a project management system.
+
+Copyright (C) 2012-2013 the OpenProject Team
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License version 3.
+
+See doc/COPYRIGHT.rdoc for more details.
+
+++#%>
+
+jQuery('#relations #errorExplanation').remove();
+
+<% if @relation.errors.empty? %>
+ jQuery('#relations tbody').append("<%= escape_javascript(render :partial => 'work_packages/relation', :locals => { :relation => @relation }) %>");
+
+ jQuery('#relation_issue_to_id').val('');
+<% else %>
+ jQuery('#relations table').after("<%= escape_javascript(error_messages_for(@relation)) %>");
+<% end %>
diff --git a/app/views/work_package_relations/destroy.js.erb b/app/views/work_package_relations/destroy.js.erb
new file mode 100644
index 0000000000..a54da194d2
--- /dev/null
+++ b/app/views/work_package_relations/destroy.js.erb
@@ -0,0 +1,13 @@
+<%#-- copyright
+OpenProject is a project management system.
+
+Copyright (C) 2012-2013 the OpenProject Team
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License version 3.
+
+See doc/COPYRIGHT.rdoc for more details.
+
+++#%>
+
+jQuery('#issue_relation_<%= @relation.id %>').remove();
diff --git a/app/views/work_packages/_relation.html.erb b/app/views/work_packages/_relation.html.erb
new file mode 100644
index 0000000000..d385c1da4f
--- /dev/null
+++ b/app/views/work_packages/_relation.html.erb
@@ -0,0 +1,39 @@
+<%#-- copyright
+OpenProject is a project management system.
+
+Copyright (C) 2012-2013 the OpenProject Team
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License version 3.
+
+See doc/COPYRIGHT.rdoc for more details.
+
+++#%>
+
+
+
+ <%= l(relation.label_for(controller.work_package)) %> <%= "(#{l('datetime.distance_in_words.x_days', :count => relation.delay)})" if relation.delay && relation.delay != 0 %>
+ <%= h(relation.other_issue(controller.work_package).project) + ' - ' if Setting.cross_project_issue_relations? %>
+ <%= link_to_issue(relation.other_issue(controller.work_package), :truncate => 60) %>
+ |
+ <% if not relation.other_issue(controller.work_package).kind.nil? %>
+
+ <%= h(relation.other_issue(controller.work_package).kind.name) %>
+ |
+ <% else %>
+ |
+ <% end %>
+
+ <%= format_date(relation.other_issue(controller.work_package).start_date) %>
+ |
+
+ <%= format_date(relation.other_issue(controller.work_package).due_date) %>
+ |
+
+ <%= link_to(image_tag('delete.png'), work_package_relation_path(controller.work_package, relation),
+ :method => :delete,
+ :remote => true,
+ :title => l(:label_relation_delete),
+ :alt => l(:label_relation_delete)) if authorize_for('issue_relations', 'destroy') %>
+ |
+
diff --git a/app/views/work_packages/_relations.html.erb b/app/views/work_packages/_relations.html.erb
new file mode 100644
index 0000000000..99f8602eec
--- /dev/null
+++ b/app/views/work_packages/_relations.html.erb
@@ -0,0 +1,36 @@
+<%#-- copyright
+OpenProject is a project management system.
+
+Copyright (C) 2012-2013 the OpenProject Team
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License version 3.
+
+See doc/COPYRIGHT.rdoc for more details.
+
+++#%>
+
+
+ <%=l(:label_related_issues)%>
+ <% if authorize_for('issue_relations', 'create') %>
+ (<%= toggle_link l(:label_add_related_issues), 'new-relation-form', {:focus => 'relation_issue_to_id'} %>)
+ <% end %>
+
+
+
+
+ <%= render :partial => 'work_packages/relation', :collection => controller.work_package.relations, :as => :relation -%>
+
+
+
+<%= form_for(controller.work_package.new_relation,
+ :as => :relation,
+ :url => work_package_relations_path(controller.work_package),
+ :method => :post,
+ :remote => true,
+ :complete => "Form.Element.focus('relation_issue_to_id');",
+ :html => {:id => 'new-relation-form', :style => (@relation ? '' : 'display: none;')}) do |f| %>
+
+ <%= render :partial => 'work_package_relations/form', :locals => {:f => f}%>
+
+<% end %>
diff --git a/app/views/work_packages/show.html.erb b/app/views/work_packages/show.html.erb
index 29a13c0b56..0ae31cdbec 100644
--- a/app/views/work_packages/show.html.erb
+++ b/app/views/work_packages/show.html.erb
@@ -96,7 +96,7 @@ See doc/COPYRIGHT.rdoc for more details.
<% if authorize_for('issue_relations', 'create') || controller.relations.present? %>
- <%#= render :partial => 'relations' %>
+ <%= render :partial => 'relations' %>
<% end %>