1. Wyświetlanie i edycja pola "source_file" w widoku ticketu.
authorLukasz Rekucki <lreqc@localhost.(none)>
Tue, 18 Aug 2009 14:32:47 +0000 (16:32 +0200)
committerLukasz Rekucki <lreqc@localhost.(none)>
Tue, 18 Aug 2009 14:32:47 +0000 (16:32 +0200)
2. Pobieranie przez HTTP listy zagadnień związych z daną publikacją

20 files changed:
README.txt
redmine/redmine_publications/README.rdoc [new file with mode: 0644]
redmine/redmine_publications/app/controllers/publications_controller.rb [new file with mode: 0644]
redmine/redmine_publications/app/helpers/publications_helper.rb [new file with mode: 0644]
redmine/redmine_publications/app/models/issue_publication.rb [new file with mode: 0644]
redmine/redmine_publications/app/models/publication.rb [new file with mode: 0644]
redmine/redmine_publications/app/views/issues/_issue_form_pub.html.erb [new file with mode: 0644]
redmine/redmine_publications/app/views/publications/index.html.erb [new file with mode: 0644]
redmine/redmine_publications/db/migrate/001_create_publications.rb [new file with mode: 0644]
redmine/redmine_publications/db/migrate/002_create_issue_publications.rb [new file with mode: 0644]
redmine/redmine_publications/init.rb [new file with mode: 0644]
redmine/redmine_publications/lang/en.yml [new file with mode: 0644]
redmine/redmine_publications/lib/issue_publication_hook.rb [new file with mode: 0644]
redmine/redmine_publications/lib/redmine_publications/.issue_patch.rb.swp [new file with mode: 0644]
redmine/redmine_publications/lib/redmine_publications/issue_patch.rb [new file with mode: 0644]
redmine/redmine_publications/routes.rb [new file with mode: 0644]
redmine/redmine_publications/test/fixtures/publications.yml [new file with mode: 0644]
redmine/redmine_publications/test/functional/publications_controller_test.rb [new file with mode: 0644]
redmine/redmine_publications/test/test_helper.rb [new file with mode: 0644]
redmine/redmine_publications/test/unit/publication_test.rb [new file with mode: 0644]

index 239441f..cb42e71 100644 (file)
@@ -4,3 +4,9 @@ Zależności
  * [Django 1.1](http://djangoproject.com/)
  * [Mercurial 1.3.1](http://www.selenic.com/mercurial/)
  * [librarian 1.1](http://redmine.nowoczesnapolska.org.pl/projects/show/librarian)
+
+
+Moduły
+======
+
+ * redmine -- wtyczka do Redmine dodająca informacje o publikacjach do zagadnień.
diff --git a/redmine/redmine_publications/README.rdoc b/redmine/redmine_publications/README.rdoc
new file mode 100644 (file)
index 0000000..2bcee99
--- /dev/null
@@ -0,0 +1,3 @@
+= publications
+
+Description goes here
diff --git a/redmine/redmine_publications/app/controllers/publications_controller.rb b/redmine/redmine_publications/app/controllers/publications_controller.rb
new file mode 100644 (file)
index 0000000..c7d16e3
--- /dev/null
@@ -0,0 +1,30 @@
+
+class PublicationsController < ApplicationController
+  unloadable
+
+  @@source_file_field_id = 1
+
+  def issues
+       logger.info "Searching for issues with document name = " + params[:pub] + "."
+       joins = "JOIN issue_publications ON (issues.id = issue_publications.issue_id) JOIN publications ON (issue_publications.publication_id = publications.id)"
+
+       conditions = ['publications.source_file = ? ', params[:pub] ]
+       @issues = Issue.all(:joins => joins, :conditions =>  conditions)
+       respond_to do |format|
+         format.html
+          format.xml do 
+           render :xml => @issues
+          end
+
+         format.json do
+           headers['Content-Type'] = 'application/json'
+           render :json => @issues
+         end
+        end
+  end
+
+  def redirect_to_platform
+       render :text => ""
+  end
+
+end
diff --git a/redmine/redmine_publications/app/helpers/publications_helper.rb b/redmine/redmine_publications/app/helpers/publications_helper.rb
new file mode 100644 (file)
index 0000000..50f110e
--- /dev/null
@@ -0,0 +1,2 @@
+module PublicationsHelper
+end
diff --git a/redmine/redmine_publications/app/models/issue_publication.rb b/redmine/redmine_publications/app/models/issue_publication.rb
new file mode 100644 (file)
index 0000000..ef7bf92
--- /dev/null
@@ -0,0 +1,4 @@
+class IssuePublication < ActiveRecord::Base
+  belongs_to :publication
+  belongs_to :issue
+end    
diff --git a/redmine/redmine_publications/app/models/publication.rb b/redmine/redmine_publications/app/models/publication.rb
new file mode 100644 (file)
index 0000000..b0e567d
--- /dev/null
@@ -0,0 +1,3 @@
+class Publication < ActiveRecord::Base
+  has_many :issues, :through => :issuepublications
+end
diff --git a/redmine/redmine_publications/app/views/issues/_issue_form_pub.html.erb b/redmine/redmine_publications/app/views/issues/_issue_form_pub.html.erb
new file mode 100644 (file)
index 0000000..638c0f6
--- /dev/null
@@ -0,0 +1,6 @@
+<div>
+<p><label for="issue_source_files">Source File(s)</label>
+<input type='text'
+       id='issue_source_files' name="issue_source_files"
+       value='<%= @issue.source_files.join(' ') %>' />
+</div>
diff --git a/redmine/redmine_publications/app/views/publications/index.html.erb b/redmine/redmine_publications/app/views/publications/index.html.erb
new file mode 100644 (file)
index 0000000..423d724
--- /dev/null
@@ -0,0 +1,4 @@
+<h2>Microrest#related-issues</h2>
+<%= @issues %>
+
+
diff --git a/redmine/redmine_publications/db/migrate/001_create_publications.rb b/redmine/redmine_publications/db/migrate/001_create_publications.rb
new file mode 100644 (file)
index 0000000..f9d93ef
--- /dev/null
@@ -0,0 +1,11 @@
+class CreatePublications < ActiveRecord::Migration
+  def self.up
+    create_table :publications do |t|
+      t.column :source_file, :string, :null => false
+    end
+  end
+
+  def self.down
+    drop_table :publications
+  end
+end
diff --git a/redmine/redmine_publications/db/migrate/002_create_issue_publications.rb b/redmine/redmine_publications/db/migrate/002_create_issue_publications.rb
new file mode 100644 (file)
index 0000000..e972442
--- /dev/null
@@ -0,0 +1,12 @@
+class CreateIssuePublications < ActiveRecord::Migration
+  def self.up
+    create_table :issue_publications do |t| 
+       t.column :publication_id, :integer, :null => false
+        t.column :issue_id, :intrger, :null => false
+    end
+  end
+
+  def self.down
+    drop_table :issue_publications
+  end
+end
diff --git a/redmine/redmine_publications/init.rb b/redmine/redmine_publications/init.rb
new file mode 100644 (file)
index 0000000..1df1e93
--- /dev/null
@@ -0,0 +1,27 @@
+require 'redmine'
+
+# Patches to the Redmine core.
+require 'dispatcher'
+Dispatcher.to_prepare :redmine_kanban do
+  require_dependency 'issue'
+  # Guards against including the module multiple time (like in tests)
+  # and registering multiple callbacks
+  unless Issue.included_modules.include? RedminePublications::IssuePatch
+    Issue.send(:include, RedminePublications::IssuePatch)
+  end
+end
+
+require_dependency 'issue_publication_hook'
+
+Redmine::Plugin.register :redmine_publicatons do
+  name 'Publications managment plugin'
+  author 'Łukasz Rekucki'
+  description 'This plugn helps manage issues related to a publication.'
+  version '0.0.3'
+
+
+  requires_redmine :version_or_higher => '0.8.0'        
+
+end
+
diff --git a/redmine/redmine_publications/lang/en.yml b/redmine/redmine_publications/lang/en.yml
new file mode 100644 (file)
index 0000000..e338591
--- /dev/null
@@ -0,0 +1,2 @@
+# English strings go here
+my_label: "My label"
diff --git a/redmine/redmine_publications/lib/issue_publication_hook.rb b/redmine/redmine_publications/lib/issue_publication_hook.rb
new file mode 100644 (file)
index 0000000..4cfc3ba
--- /dev/null
@@ -0,0 +1,16 @@
+# Provides a link to the document on the platform
+class IssuesPublicationHook < Redmine::Hook::ViewListener
+  def view_issues_show_details_bottom(context)
+        result = "<tr><td><b>Source File(s):</b></td><td>"
+       names = context[:issue].source_files.map {|name| "<span>" + name + "</span>"} 
+       result << names.join(', ')
+       result + "</td></tr>"
+  end
+
+  def controller_issues_edit_before_save(context)
+       pub_field = context[:params][:issue_source_files]
+       context[:issue].source_files = pub_field
+  end
+
+  render_on :view_issues_form_details_bottom, :partial => 'issue_form_pub'
+end
diff --git a/redmine/redmine_publications/lib/redmine_publications/.issue_patch.rb.swp b/redmine/redmine_publications/lib/redmine_publications/.issue_patch.rb.swp
new file mode 100644 (file)
index 0000000..56af602
Binary files /dev/null and b/redmine/redmine_publications/lib/redmine_publications/.issue_patch.rb.swp differ
diff --git a/redmine/redmine_publications/lib/redmine_publications/issue_patch.rb b/redmine/redmine_publications/lib/redmine_publications/issue_patch.rb
new file mode 100644 (file)
index 0000000..dbcbfa8
--- /dev/null
@@ -0,0 +1,70 @@
+module RedminePublications
+  # Patches Redmine's Issues dynamically. Adds a +after_save+ filter.
+
+  module IssuePatch
+    def self.included(base) # :nodoc:
+      base.extend(ClassMethods)
+      base.send(:include, InstanceMethods)
+      # Same as typing in the class
+      base.class_eval do
+        unloadable # Send unloadable so it will not be unloaded in development
+        after_save :update_relations
+        # after_destroy :check_relations
+        # Add visible to Redmine 0.8.x
+        unless respond_to?(:visible)
+          named_scope :visible, lambda {|*args| { :include => :project,
+              :conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } }
+        end
+      end
+    end
+    
+    module ClassMethods
+    end
+    
+    module InstanceMethods
+      def source_files
+       if not @source_files
+         @source_files = self.lookup_source_files.map { |pub| pub.source_file }
+        end
+       @source_files        
+      end
+
+      def source_files=(value)
+       @source_files = value
+      end
+
+      def lookup_source_files
+        Publication.all( 
+         :joins => 
+           "JOIN issue_publications ON (issue_publications.publication_id = publications.id)",
+         :conditions =>
+           [" issue_publications.issue_id = ? ", self.id] )    
+      end
+       
+      def update_relations
+        self.reload
+       current_assocs = self.lookup_source_files
+       new_assocs_names = self.source_files.split(' ')
+
+       # delete unused relations
+       deleted = current_assocs.select { |v| not (new_assocs_names.include?(v.source_file)) }
+       deleted.each { |pub| IssuePublication.delete_all( 
+         :contitions => ["issue_publications.issue_id = ? AND issue_publicatons.publication_id = ?",
+               self.id, pub.id]) }
+
+       new_assocs_names.each do |name|
+               pub = Publication.find_or_create_by_source_file(name)
+               IssuePublication.find_or_create_by_publication_id_and_issue_id(pub.id, self.id)
+       end
+
+        return true
+      end
+
+    end
+  end
+end
diff --git a/redmine/redmine_publications/routes.rb b/redmine/redmine_publications/routes.rb
new file mode 100644 (file)
index 0000000..bdca2b8
--- /dev/null
@@ -0,0 +1,10 @@
+connect 'publications/:pub',
+       :controller => 'publications',
+       :action => 'redirect_to_platform'
+
+connect 'publications/:pub/:action', 
+       :controller => 'publications',
+       :format => 'html'
+       
+connect 'publications/:pub/:action.:format', 
+       :controller => 'publications' 
diff --git a/redmine/redmine_publications/test/fixtures/publications.yml b/redmine/redmine_publications/test/fixtures/publications.yml
new file mode 100644 (file)
index 0000000..9d7d113
--- /dev/null
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+  id: 1
+  source_file: One
+two:
+  id: 2
+  source_file: Two
diff --git a/redmine/redmine_publications/test/functional/publications_controller_test.rb b/redmine/redmine_publications/test/functional/publications_controller_test.rb
new file mode 100644 (file)
index 0000000..62b35f6
--- /dev/null
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class MicrorestControllerTest < ActionController::TestCase
+  # Replace this with your real tests.
+  def test_truth
+    assert true
+  end
+end
diff --git a/redmine/redmine_publications/test/test_helper.rb b/redmine/redmine_publications/test/test_helper.rb
new file mode 100644 (file)
index 0000000..bd1ed0c
--- /dev/null
@@ -0,0 +1,5 @@
+# Load the normal Rails helper
+require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper')
+
+# Ensure that we are using the temporary fixture path
+Engines::Testing.set_fixture_path
diff --git a/redmine/redmine_publications/test/unit/publication_test.rb b/redmine/redmine_publications/test/unit/publication_test.rb
new file mode 100644 (file)
index 0000000..ccf8aa4
--- /dev/null
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class PublicationTest < Test::Unit::TestCase
+  fixtures :publications
+
+  # Replace this with your real tests.
+  def test_truth
+    assert true
+  end
+end