From d940e6b2345b50ffbd50bbe5f508f6d4ff4e0054 Mon Sep 17 00:00:00 2001 From: Lukasz Rekucki Date: Wed, 19 Aug 2009 16:19:43 +0200 Subject: [PATCH] Opcje konfguracyjne pluginu. Walidacja przy wpisywaniu publikacji do zagadnienia. Skrypt do zapelniania bazy publikacji z repozytorium. Refs #25 --- .gitignore | 3 +- .../controllers/publications_controller.rb | 37 +++++++++-- .../app/models/publication.rb | 1 + .../app/views/issues/_issue_form_pub.html.erb | 7 +-- .../app/views/publications/index.html.erb | 10 +-- .../app/views/publications/issues.html.erb | 4 ++ .../settings/_publications_settings.html.erb | 13 ++++ .../migrate/003_publications_add_repo_id.rb | 8 +++ .../db/migrate/004_publications_add_name.rb | 8 +++ redmine/redmine_publications/init.rb | 12 +++- .../lib/issue_publication_hook.rb | 18 ++++-- .../redmine_publications/.issue_patch.rb.swp | Bin 12288 -> 0 bytes .../lib/redmine_publications/issue_patch.rb | 58 +++++++++++------- redmine/redmine_publications/routes.rb | 11 ++-- 14 files changed, 141 insertions(+), 49 deletions(-) create mode 100644 redmine/redmine_publications/app/views/publications/issues.html.erb create mode 100644 redmine/redmine_publications/app/views/settings/_publications_settings.html.erb create mode 100644 redmine/redmine_publications/db/migrate/003_publications_add_repo_id.rb create mode 100644 redmine/redmine_publications/db/migrate/004_publications_add_name.rb delete mode 100644 redmine/redmine_publications/lib/redmine_publications/.issue_patch.rb.swp diff --git a/.gitignore b/.gitignore index fd81eda1..a5d48645 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ localsettings.py dev.sqlite *.pyc +.*.swp .DS_Store media -files \ No newline at end of file +files diff --git a/redmine/redmine_publications/app/controllers/publications_controller.rb b/redmine/redmine_publications/app/controllers/publications_controller.rb index c7d16e3f..1220bea1 100644 --- a/redmine/redmine_publications/app/controllers/publications_controller.rb +++ b/redmine/redmine_publications/app/controllers/publications_controller.rb @@ -1,14 +1,35 @@ - class PublicationsController < ApplicationController unloadable - @@source_file_field_id = 1 +# before_filter :authorize, :only => [:issues] + + def index + @publications = Publication.all + respond_to do |format| + format.html + format.xml { render :xml => @publications } + format.json { render :json => @publications } + end + end + + def refresh + regexp = Regexp.new(Setting.plugin_redmine_publications['pattern']) + Repository.all.each do |repo| + repo.entries.each do |entry| + match = entry.path.match(regexp) + if match + Publication.find_or_create_by_name(:name => match[1], + :source_file => entry.path, :repository_id => repo.id) + end + end + end + end 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)" + @publication = Publication.find_by_name(params[:pub]) - conditions = ['publications.source_file = ? ', params[:pub] ] + joins = "JOIN issue_publications ON (issues.id = issue_publications.issue_id)" + conditions = ['issue_publications.publication_id = ? ', @publication.id ] @issues = Issue.all(:joins => joins, :conditions => conditions) respond_to do |format| format.html @@ -27,4 +48,10 @@ class PublicationsController < ApplicationController render :text => "" end + private + + def find_project + @project = Project.find(params[:project_id]) + end + end diff --git a/redmine/redmine_publications/app/models/publication.rb b/redmine/redmine_publications/app/models/publication.rb index b0e567d8..15444023 100644 --- a/redmine/redmine_publications/app/models/publication.rb +++ b/redmine/redmine_publications/app/models/publication.rb @@ -1,3 +1,4 @@ class Publication < ActiveRecord::Base has_many :issues, :through => :issuepublications + belongs_to :repository 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 index 638c0f6c..f0f7a1a0 100644 --- a/redmine/redmine_publications/app/views/issues/_issue_form_pub.html.erb +++ b/redmine/redmine_publications/app/views/issues/_issue_form_pub.html.erb @@ -1,6 +1,5 @@
-

-' /> +

+' />

diff --git a/redmine/redmine_publications/app/views/publications/index.html.erb b/redmine/redmine_publications/app/views/publications/index.html.erb index 423d724b..9a7e3ce0 100644 --- a/redmine/redmine_publications/app/views/publications/index.html.erb +++ b/redmine/redmine_publications/app/views/publications/index.html.erb @@ -1,4 +1,6 @@ -

Microrest#related-issues

-<%= @issues %> - - +

Publikacje

+
    +<% @publications.each do |pub| %> +
  1. <%= pub.name %>
  2. +<% end %> +
diff --git a/redmine/redmine_publications/app/views/publications/issues.html.erb b/redmine/redmine_publications/app/views/publications/issues.html.erb new file mode 100644 index 00000000..f36a875d --- /dev/null +++ b/redmine/redmine_publications/app/views/publications/issues.html.erb @@ -0,0 +1,4 @@ +

Issues for publication: <%= @publication.name %>

+<% @issues.each do |issue| %> +

<%= issue.subject %>

+<% end %> diff --git a/redmine/redmine_publications/app/views/settings/_publications_settings.html.erb b/redmine/redmine_publications/app/views/settings/_publications_settings.html.erb new file mode 100644 index 00000000..65e436eb --- /dev/null +++ b/redmine/redmine_publications/app/views/settings/_publications_settings.html.erb @@ -0,0 +1,13 @@ +<% @tracker = Tracker.find(settings['tracker']) %> + +
+

+ + <%= collection_select(:tracker, :id, Tracker.all, :id, :name, {}, {:name => "settings[tracker]"}) %> +

+ +

+ + <%= text_field_tag 'settings[pattern]', @settings['pattern'] %> +

+
diff --git a/redmine/redmine_publications/db/migrate/003_publications_add_repo_id.rb b/redmine/redmine_publications/db/migrate/003_publications_add_repo_id.rb new file mode 100644 index 00000000..8f232c92 --- /dev/null +++ b/redmine/redmine_publications/db/migrate/003_publications_add_repo_id.rb @@ -0,0 +1,8 @@ +class PublicationsAddRepoId < ActiveRecord::Migration + def self.up + add_column :publications, :repository_id, :integer, :null => false, :default => 0 + end + + def self.down + end +end diff --git a/redmine/redmine_publications/db/migrate/004_publications_add_name.rb b/redmine/redmine_publications/db/migrate/004_publications_add_name.rb new file mode 100644 index 00000000..6b5bac61 --- /dev/null +++ b/redmine/redmine_publications/db/migrate/004_publications_add_name.rb @@ -0,0 +1,8 @@ +class PublicationsAddName < ActiveRecord::Migration + def self.up + add_column :publications, :name, :string + end + + def self.down + end +end diff --git a/redmine/redmine_publications/init.rb b/redmine/redmine_publications/init.rb index 1df1e936..f2b5b59c 100644 --- a/redmine/redmine_publications/init.rb +++ b/redmine/redmine_publications/init.rb @@ -3,7 +3,7 @@ require 'redmine' # Patches to the Redmine core. require 'dispatcher' -Dispatcher.to_prepare :redmine_kanban do +Dispatcher.to_prepare :redmine_publications do require_dependency 'issue' # Guards against including the module multiple time (like in tests) # and registering multiple callbacks @@ -14,12 +14,18 @@ end require_dependency 'issue_publication_hook' -Redmine::Plugin.register :redmine_publicatons do +Redmine::Plugin.register :redmine_publications do name 'Publications managment plugin' author 'Łukasz Rekucki' description 'This plugn helps manage issues related to a publication.' - version '0.0.3' + version '0.0.9' + # permission :view_issues_for_publication, :publications => :issues + + settings :partial => 'settings/publications_settings', + :default => { :tracker => '1', :pattern => '.*/[a-z_].xml'} + + menu :application_menu, :publications, { :controller => 'publications', :action => 'index' }, :caption => 'Publikacje' requires_redmine :version_or_higher => '0.8.0' diff --git a/redmine/redmine_publications/lib/issue_publication_hook.rb b/redmine/redmine_publications/lib/issue_publication_hook.rb index 4cfc3ba5..9c972339 100644 --- a/redmine/redmine_publications/lib/issue_publication_hook.rb +++ b/redmine/redmine_publications/lib/issue_publication_hook.rb @@ -1,15 +1,21 @@ # 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 + "" + # TODO: złapać wyjątek konwersji + if context[:issue].tracker_id == Setting.plugin_redmine_publications['tracker'].to_i + result = "Publication(s):" + names = context[:issue].publication_names {|name| "" + name + ""} + result << names.join(', ') + result << "" + end end def controller_issues_edit_before_save(context) - pub_field = context[:params][:issue_source_files] - context[:issue].source_files = pub_field + if context[:issue].tracker_id == Setting.plugin_redmine_publications['tracker'].to_i + pub_field = context[:params][:publications] + context[:issue].publication_names = pub_field.split(',').map { |n| n.strip } + end end render_on :view_issues_form_details_bottom, :partial => 'issue_form_pub' diff --git a/redmine/redmine_publications/lib/redmine_publications/.issue_patch.rb.swp b/redmine/redmine_publications/lib/redmine_publications/.issue_patch.rb.swp deleted file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I?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 diff --git a/redmine/redmine_publications/lib/redmine_publications/issue_patch.rb b/redmine/redmine_publications/lib/redmine_publications/issue_patch.rb index dbcbfa8f..f8a83c4b 100644 --- a/redmine/redmine_publications/lib/redmine_publications/issue_patch.rb +++ b/redmine/redmine_publications/lib/redmine_publications/issue_patch.rb @@ -11,8 +11,8 @@ module RedminePublications base.class_eval do unloadable # Send unloadable so it will not be unloaded in development + validate :check_relations after_save :update_relations - # after_destroy :check_relations # Add visible to Redmine 0.8.x unless respond_to?(:visible) @@ -27,43 +27,57 @@ module RedminePublications end module InstanceMethods - def source_files - if not @source_files - @source_files = self.lookup_source_files.map { |pub| pub.source_file } - end - @source_files + + def publication_names + if not @pubnames + self.publications.map { |pub| pub.name } + else + @pubnames + end end - def source_files=(value) - @source_files = value + def publication_names=(value) + @pubnames = value.sort! end - def lookup_source_files + def publications Publication.all( :joins => "JOIN issue_publications ON (issue_publications.publication_id = publications.id)", :conditions => - [" issue_publications.issue_id = ? ", self.id] ) + ["issue_publications.issue_id = ? ", self.id] ) end - - def update_relations + + def check_relations + current_names = self.publication_names + non_existant = [] + + pubs = Publication.find_all_by_name(current_names).map {|i| i.name} + missing = current_names.select {|name| not pubs.include?name } + + if not missing.empty? + errors.add("publications", "Missing publication(s): " + missing.join(', ')) + end + end + + def update_relations self.reload - current_assocs = self.lookup_source_files - new_assocs_names = self.source_files.split(' ') + old = self.publications + current_names = self.publication_names # 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]) } + deleted = old.select { |v| not (current_names.include?(v.name)) } + deleted.each do |pub| + IssuePublication.delete_all(["issue_publications.issue_id = ? AND issue_publications.publication_id = ?", self.id, pub.id]) + end - 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) + current_names.each do |name| + pub = Publication.find_by_name(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 index bdca2b83..d1cf0579 100644 --- a/redmine/redmine_publications/routes.rb +++ b/redmine/redmine_publications/routes.rb @@ -1,10 +1,13 @@ -connect 'publications/:pub', +connect 'publications/:action', :controller => 'publications', - :action => 'redirect_to_platform' + :format => 'html' + +connect 'publications/:action.:format', + :controller => 'publications' -connect 'publications/:pub/:action', +connect 'publications/:action/:pub', :controller => 'publications', :format => 'html' -connect 'publications/:pub/:action.:format', +connect 'publications/:action/:pub.:format', :controller => 'publications' -- 2.20.1