From 378fe7c80dbc369bceb24e57e2cd81d3bd690ee9 Mon Sep 17 00:00:00 2001 From: Lukasz Rekucki Date: Tue, 18 Aug 2009 16:32:47 +0200 Subject: [PATCH] =?utf8?q?1.=20Wy=C5=9Bwietlanie=20i=20edycja=20pola=20"so?= =?utf8?q?urce=5Ffile"=20w=20widoku=20ticketu.=202.=20Pobieranie=20przez?= =?utf8?q?=20HTTP=20listy=20zagadnie=C5=84=20zwi=C4=85zych=20z=20dan=C4=85?= =?utf8?q?=20publikacj=C4=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- README.rdoc | 3 + app/controllers/publications_controller.rb | 30 ++++++++ app/helpers/publications_helper.rb | 2 + app/models/issue_publication.rb | 4 + app/models/publication.rb | 3 + app/views/issues/_issue_form_pub.html.erb | 6 ++ app/views/publications/index.html.erb | 4 + db/migrate/001_create_publications.rb | 11 +++ db/migrate/002_create_issue_publications.rb | 12 +++ init.rb | 27 +++++++ lang/en.yml | 2 + lib/issue_publication_hook.rb | 16 ++++ lib/redmine_publications/.issue_patch.rb.swp | Bin 0 -> 12288 bytes lib/redmine_publications/issue_patch.rb | 70 ++++++++++++++++++ routes.rb | 10 +++ test/fixtures/publications.yml | 7 ++ .../publications_controller_test.rb | 8 ++ test/test_helper.rb | 5 ++ test/unit/publication_test.rb | 10 +++ 19 files changed, 230 insertions(+) create mode 100644 README.rdoc create mode 100644 app/controllers/publications_controller.rb create mode 100644 app/helpers/publications_helper.rb create mode 100644 app/models/issue_publication.rb create mode 100644 app/models/publication.rb create mode 100644 app/views/issues/_issue_form_pub.html.erb create mode 100644 app/views/publications/index.html.erb create mode 100644 db/migrate/001_create_publications.rb create mode 100644 db/migrate/002_create_issue_publications.rb create mode 100644 init.rb create mode 100644 lang/en.yml create mode 100644 lib/issue_publication_hook.rb create mode 100644 lib/redmine_publications/.issue_patch.rb.swp create mode 100644 lib/redmine_publications/issue_patch.rb create mode 100644 routes.rb create mode 100644 test/fixtures/publications.yml create mode 100644 test/functional/publications_controller_test.rb create mode 100644 test/test_helper.rb create mode 100644 test/unit/publication_test.rb diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 0000000..2bcee99 --- /dev/null +++ b/README.rdoc @@ -0,0 +1,3 @@ += publications + +Description goes here diff --git a/app/controllers/publications_controller.rb b/app/controllers/publications_controller.rb new file mode 100644 index 0000000..c7d16e3 --- /dev/null +++ b/app/controllers/publications_controller.rb @@ -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/app/helpers/publications_helper.rb b/app/helpers/publications_helper.rb new file mode 100644 index 0000000..50f110e --- /dev/null +++ b/app/helpers/publications_helper.rb @@ -0,0 +1,2 @@ +module PublicationsHelper +end diff --git a/app/models/issue_publication.rb b/app/models/issue_publication.rb new file mode 100644 index 0000000..ef7bf92 --- /dev/null +++ b/app/models/issue_publication.rb @@ -0,0 +1,4 @@ +class IssuePublication < ActiveRecord::Base + belongs_to :publication + belongs_to :issue +end diff --git a/app/models/publication.rb b/app/models/publication.rb new file mode 100644 index 0000000..b0e567d --- /dev/null +++ b/app/models/publication.rb @@ -0,0 +1,3 @@ +class Publication < ActiveRecord::Base + has_many :issues, :through => :issuepublications +end diff --git a/app/views/issues/_issue_form_pub.html.erb b/app/views/issues/_issue_form_pub.html.erb new file mode 100644 index 0000000..638c0f6 --- /dev/null +++ b/app/views/issues/_issue_form_pub.html.erb @@ -0,0 +1,6 @@ +
+

+' /> +

diff --git a/app/views/publications/index.html.erb b/app/views/publications/index.html.erb new file mode 100644 index 0000000..423d724 --- /dev/null +++ b/app/views/publications/index.html.erb @@ -0,0 +1,4 @@ +

Microrest#related-issues

+<%= @issues %> + + diff --git a/db/migrate/001_create_publications.rb b/db/migrate/001_create_publications.rb new file mode 100644 index 0000000..f9d93ef --- /dev/null +++ b/db/migrate/001_create_publications.rb @@ -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/db/migrate/002_create_issue_publications.rb b/db/migrate/002_create_issue_publications.rb new file mode 100644 index 0000000..e972442 --- /dev/null +++ b/db/migrate/002_create_issue_publications.rb @@ -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/init.rb b/init.rb new file mode 100644 index 0000000..1df1e93 --- /dev/null +++ b/init.rb @@ -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/lang/en.yml b/lang/en.yml new file mode 100644 index 0000000..e338591 --- /dev/null +++ b/lang/en.yml @@ -0,0 +1,2 @@ +# English strings go here +my_label: "My label" diff --git a/lib/issue_publication_hook.rb b/lib/issue_publication_hook.rb new file mode 100644 index 0000000..4cfc3ba --- /dev/null +++ b/lib/issue_publication_hook.rb @@ -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 = "Source File(s):" + names = context[:issue].source_files.map {|name| "" + name + ""} + result << names.join(', ') + result + "" + 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/lib/redmine_publications/.issue_patch.rb.swp b/lib/redmine_publications/.issue_patch.rb.swp new file mode 100644 index 0000000000000000000000000000000000000000..56af602414e24dae2ae0822665803c26210160d7 GIT binary patch literal 12288 zcmeHNzi%8x6rRwS0|HSZprCp9gnUOXYdat%7#x!jAvq$BLlP)ZwA$O5vo{&GZXSfbA_VbrF&wYJ+noS*HOy=Uv*pC0lC6!s1Do;eZzu?Fzy|XkCafi%h&8un;2F3}7>GDyXQmiS?}tP9|G)hk z!0ksEy9Im*+yppq7B~Yu4m=9nd6=;ufcJs-fG+SHZ~{04{B)49Pk`rvS>P$42|NKj z2K@C9W4{7-fbW5?fX{#sxCFca90%rs!@%zkLKgT1_zw62_#C(hoC2nRKOcY`@FVao z@G+193b+jX(O~QwU=6qktOB#ZZ}9z7;3MD`@B#2H@D8vA?G@jv4}k zUXt=qD)DCOnKVU-kwjyoFZ6AmJU-LiX^`hDHq0BJHnIt0Ip@*h{2n zrO}4Kx>Rh2k=82Kp&ikIh~jnPiU#&|0D~LVCLJnwz1pU?;C+K=Ay%nLTt6c%o}xFV ztKP+tTRNyshHXo9dgUxl%Agf8fZDn*5{_EI=?-gfA%zjVwC4s5AT^-nowSuwVI*aX zhHIcAF7jNYrgANS3nDfIHT?ml%1~>U-$@$Ff{UeAKNzE_ZJlj2soaN(w9tYhqOxq` z1U)+yVRJ{=m=Yc6OeUr^Lo;A}(zIG!Ds{cc!tqru#cY~6eb`gs$E|%QnA4*o<2F-9 zwltWVb9syC5CXD;ZQFS|8IkE>4qc@-6jV{=!>BT+Y5LrS<&`~@(S;RiO-9u1u`8rw z1F(R%ZG@3P*AyCLZSGX2(?kN7Q7xUa9`D6bwa``7i{tEp*nT8Ya-;R*(~B)P+b#>a zEZD}Rf^y-=G`9!Qq)-*@JxmKWqReKTOI&=6rxMTJFQlO5RGTP` z#d%@Y71wUceblE=CHImXZc9pw&0_K4x3j#VbCoKCt@bVx=UT^`Ym z!P8dn030q<#c4BTAuBEEuv$xzN})B1QfIITmMyhvW$mF*lTLF^)gELNy;`mt5BR%Z3KrI?QTuzgo8j`YDg)NKUMs7aT=GY*mAh*p#s z+DxQ$xzH8WB+i&5MV0qa^w|auvdWKcq(ui*ve~fNF3_ktVa9CFz=7Zq@}k z*`arCxrPm`n$gbAd;(+Rdxj=!~@>tizw~-L&ke6~hu;J1a(a{mjM+skC2u;8$#Z?GbN8cZs{R4Q> B-|YYZ literal 0 HcmV?d00001 diff --git a/lib/redmine_publications/issue_patch.rb b/lib/redmine_publications/issue_patch.rb new file mode 100644 index 0000000..dbcbfa8 --- /dev/null +++ b/lib/redmine_publications/issue_patch.rb @@ -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/routes.rb b/routes.rb new file mode 100644 index 0000000..bdca2b8 --- /dev/null +++ b/routes.rb @@ -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/test/fixtures/publications.yml b/test/fixtures/publications.yml new file mode 100644 index 0000000..9d7d113 --- /dev/null +++ b/test/fixtures/publications.yml @@ -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/test/functional/publications_controller_test.rb b/test/functional/publications_controller_test.rb new file mode 100644 index 0000000..62b35f6 --- /dev/null +++ b/test/functional/publications_controller_test.rb @@ -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/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..bd1ed0c --- /dev/null +++ b/test/test_helper.rb @@ -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/test/unit/publication_test.rb b/test/unit/publication_test.rb new file mode 100644 index 0000000..ccf8aa4 --- /dev/null +++ b/test/unit/publication_test.rb @@ -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 -- 2.20.1