Opcje konfguracyjne pluginu. Walidacja przy wpisywaniu publikacji do zagadnienia...
authorLukasz Rekucki <lreqc@localhost.(none)>
Wed, 19 Aug 2009 14:19:43 +0000 (16:19 +0200)
committerLukasz Rekucki <lreqc@localhost.(none)>
Wed, 19 Aug 2009 14:19:43 +0000 (16:19 +0200)
zapelniania bazy publikacji z repozytorium. Refs #25

14 files changed:
.gitignore
redmine/redmine_publications/app/controllers/publications_controller.rb
redmine/redmine_publications/app/models/publication.rb
redmine/redmine_publications/app/views/issues/_issue_form_pub.html.erb
redmine/redmine_publications/app/views/publications/index.html.erb
redmine/redmine_publications/app/views/publications/issues.html.erb [new file with mode: 0644]
redmine/redmine_publications/app/views/settings/_publications_settings.html.erb [new file with mode: 0644]
redmine/redmine_publications/db/migrate/003_publications_add_repo_id.rb [new file with mode: 0644]
redmine/redmine_publications/db/migrate/004_publications_add_name.rb [new file with mode: 0644]
redmine/redmine_publications/init.rb
redmine/redmine_publications/lib/issue_publication_hook.rb
redmine/redmine_publications/lib/redmine_publications/.issue_patch.rb.swp [deleted file]
redmine/redmine_publications/lib/redmine_publications/issue_patch.rb
redmine/redmine_publications/routes.rb

index fd81eda..a5d4864 100644 (file)
@@ -1,6 +1,7 @@
 localsettings.py
 dev.sqlite
 *.pyc
+.*.swp
 .DS_Store
 media
-files
\ No newline at end of file
+files
index c7d16e3..1220bea 100644 (file)
@@ -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
index b0e567d..1544402 100644 (file)
@@ -1,3 +1,4 @@
 class Publication < ActiveRecord::Base
   has_many :issues, :through => :issuepublications
+  belongs_to :repository
 end
index 638c0f6..f0f7a1a 100644 (file)
@@ -1,6 +1,5 @@
 <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(' ') %>' />
+<p><label for="issue_source_files">Publication(s)</label>
+<input type='text' id='publications' name="publications" size="50"
+       value='<%= @issue.publication_names.join(', ') %>' />
 </div>
index 423d724..9a7e3ce 100644 (file)
@@ -1,4 +1,6 @@
-<h2>Microrest#related-issues</h2>
-<%= @issues %>
-
-
+<h2>Publikacje</h2>
+<ol>
+<% @publications.each do |pub| %>
+       <li><a href="/publications/issues/<%= pub.name %>"><%= pub.name %></a></li>
+<% end %>
+</ol>
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 (file)
index 0000000..f36a875
--- /dev/null
@@ -0,0 +1,4 @@
+<h2>Issues for publication: <%= @publication.name %></h2>
+<% @issues.each do |issue| %>
+<p><%= issue.subject %></p>
+<% 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 (file)
index 0000000..65e436e
--- /dev/null
@@ -0,0 +1,13 @@
+<% @tracker = Tracker.find(settings['tracker']) %>
+
+<fieldset>
+<p>
+  <label for="settings[tracker]">Typ zagadnienia: </label>
+  <%= collection_select(:tracker, :id, Tracker.all, :id, :name, {}, {:name => "settings[tracker]"}) %>
+</p>
+
+<p>
+  <label for="settings[pattern]">Filtr publikacji: </label>
+  <%= text_field_tag 'settings[pattern]', @settings['pattern'] %>
+</p>
+</fieldset>
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 (file)
index 0000000..8f232c9
--- /dev/null
@@ -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 (file)
index 0000000..6b5bac6
--- /dev/null
@@ -0,0 +1,8 @@
+class PublicationsAddName < ActiveRecord::Migration
+  def self.up
+    add_column :publications, :name, :string
+  end
+
+  def self.down 
+  end
+end
index 1df1e93..f2b5b59 100644 (file)
@@ -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'        
 
index 4cfc3ba..9c97233 100644 (file)
@@ -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 = "<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>"
+       # TODO: złapać wyjątek konwersji
+       if context[:issue].tracker_id == Setting.plugin_redmine_publications['tracker'].to_i
+          result = "<tr><td><b>Publication(s):</b></td><td>"
+         names = context[:issue].publication_names {|name| "<span>" + name + "</span>"} 
+         result << names.join(', ')
+         result << "</td></tr>"
+       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 (file)
index 56af602..0000000
Binary files a/redmine/redmine_publications/lib/redmine_publications/.issue_patch.rb.swp and /dev/null differ
index dbcbfa8..f8a83c4 100644 (file)
@@ -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
index bdca2b8..d1cf057 100644 (file)
@@ -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'