From: Lukasz Rekucki Date: Wed, 19 Aug 2009 14:19:43 +0000 (+0200) Subject: Opcje konfguracyjne pluginu. Walidacja przy wpisywaniu publikacji do zagadnienia... X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/d940e6b2345b50ffbd50bbe5f508f6d4ff4e0054?hp=77c7ccaf2f09308a537ffd30edc0477dde11d74a Opcje konfguracyjne pluginu. Walidacja przy wpisywaniu publikacji do zagadnienia. Skrypt do zapelniania bazy publikacji z repozytorium. Refs #25 --- 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 mode 100644 index 56af6024..00000000 Binary files a/redmine/redmine_publications/lib/redmine_publications/.issue_patch.rb.swp and /dev/null differ 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'