Redmine locale fix. Some RAL tweaks. Added line numbers to code-mirror.
authorŁukasz Rekucki <lrekucki@gmail.com>
Thu, 24 Sep 2009 15:30:21 +0000 (17:30 +0200)
committerŁukasz Rekucki <lrekucki@gmail.com>
Thu, 24 Sep 2009 15:30:21 +0000 (17:30 +0200)
app/controllers/publications_controller.rb
app/views/issues/_issue_form_pub.html.erb
app/views/issues/_issue_view_pub.erb
init.rb
lib/redmine_publications/change_patch.rb [new file with mode: 0644]
lib/redmine_publications/issue_patch.rb
locales/en.yml [new file with mode: 0644]
locales/pl.yml [new file with mode: 0644]

index 6c1e734..ebf735b 100644 (file)
@@ -19,28 +19,28 @@ class PublicationsController < ApplicationController
     Publication.delete_all()
     repos = Repository.all
     if repos
     Publication.delete_all()
     repos = Repository.all
     if repos
-    repos.each do |repo|
-      repo_status = []
-      if repo.entries
-      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)
-          repo_status += [{:path => entry.path, :match => match[1], :matched => true}]
-        else
-          repo_status += [{:path => entry.path, :match =>nil, :matched => false}]
+      repos.each do |repo|
+        repo_status = []
+        if repo.entries
+          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)
+              repo_status += [{:path => entry.path, :match => match[1], :matched => true}]
+            else
+              repo_status += [{:path => entry.path, :match =>nil, :matched => false}]
+            end
+          end
+          @match_status += [{:repo => repo, :status => repo_status}]
         end
       end
         end
       end
-      @match_status += [{:repo => repo, :status => repo_status}]
-      end
-    end
        
        
-    respond_to do |format|
-      format.html
-      format.xml { render :xml => @match_status}
-      format.json { render :json => @match_status }
-    end
+      respond_to do |format|
+        format.html
+        format.xml { render :xml => @match_status}
+        format.json { render :json => @match_status }
+      end
     end
   end
 
     end
   end
 
@@ -52,7 +52,7 @@ class PublicationsController < ApplicationController
     @issues = Issue.all(:joins => joins, :conditions =>  conditions)
 
     respond_to do |fmt| 
     @issues = Issue.all(:joins => joins, :conditions =>  conditions)
 
     respond_to do |fmt| 
-       fmt.json { render :json => @issues, :callback => params[:callback] }
+      fmt.json { render :json => @issues, :callback => params[:callback] }
     end
   end
 
     end
   end
 
index f0f7a1a..ebb903c 100644 (file)
@@ -1,5 +1,5 @@
 <div>
 <div>
-<p><label for="issue_source_files">Publication(s)</label>
+<p><label for="issue_source_files"><%= l(:field_publications) %>:</label>
 <input type='text' id='publications' name="publications" size="50"
        value='<%= @issue.publication_names.join(', ') %>' />
 </div>
 <input type='text' id='publications' name="publications" size="50"
        value='<%= @issue.publication_names.join(', ') %>' />
 </div>
index 26ce997..a22c78b 100644 (file)
@@ -1,5 +1,5 @@
 <tr>
 <tr>
-    <td><b>Publication(s)</b></td>
+    <td><b><%= l(:field_publications) %>:</b></td>
     <td>
 <% @issue.publication_names.each  do |pub| %>
       <a href="<%= Setting.plugin_redmine_publications[:editorurl].sub(':pubid', pub) %>"><%= pub %></a><br />
     <td>
 <% @issue.publication_names.each  do |pub| %>
       <a href="<%= Setting.plugin_redmine_publications[:editorurl].sub(':pubid', pub) %>"><%= pub %></a><br />
diff --git a/init.rb b/init.rb
index 0aa6f07..4298f60 100644 (file)
--- a/init.rb
+++ b/init.rb
@@ -11,6 +11,10 @@ Dispatcher.to_prepare :redmine_publications do
   unless Issue.included_modules.include? RedminePublications::IssuePatch
     Issue.send(:include, RedminePublications::IssuePatch)
   end
   unless Issue.included_modules.include? RedminePublications::IssuePatch
     Issue.send(:include, RedminePublications::IssuePatch)
   end
+
+  unless Change.included_modules.include? RedminePublications::ChangePatch
+    Change.send(:include, RedminePublications::ChangePatch)
+  end
 end
 
 require_dependency 'issue_publication_hook'
 end
 
 require_dependency 'issue_publication_hook'
diff --git a/lib/redmine_publications/change_patch.rb b/lib/redmine_publications/change_patch.rb
new file mode 100644 (file)
index 0000000..41ea959
--- /dev/null
@@ -0,0 +1,38 @@
+module RedminePublications
+  # Patches Redmine's Issues dynamically. Adds a +after_save+ filter.
+
+  module ChangePatch
+    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_publication
+      end
+
+    end
+
+    module ClassMethods
+    end
+
+    module InstanceMethods
+
+      def update_publication
+        if self.action == 'A'
+          regexp = Regexp.new(Setting.plugin_redmine_publications[:pattern])
+          match = self.path.match(regexp)
+          Rails.logger.info('[INFO] Adding publication: "' << match[1])
+          Publication.find_or_create_by_name(:name => match[1],
+            :source_file => self.path, :repository_id => self.changeset.repository.id )
+        end      
+      end
+      
+    end
+    
+  end
+
+
+end
index c108799..bd1f73e 100644 (file)
@@ -11,8 +11,8 @@ module RedminePublications
       base.class_eval do
         unloadable # Send unloadable so it will not be unloaded in development
  
       base.class_eval do
         unloadable # Send unloadable so it will not be unloaded in development
  
-       validate :check_relations
-       after_save :update_relations
+        validate :check_relations
+        after_save :update_relations
       end
  
     end
       end
  
     end
@@ -23,55 +23,55 @@ module RedminePublications
     module InstanceMethods
 
       def publication_names    
     module InstanceMethods
 
       def publication_names    
-       if not @pubnames
-         self.publications.map { |pub| pub.name }
+        if not @pubnames
+          self.publications.map { |pub| pub.name }
         else
         else
-         @pubnames        
-       end
+          @pubnames
+        end
       end
 
       def publication_names=(value)
       end
 
       def publication_names=(value)
-       @pubnames = value.sort!
+        @pubnames = value.sort!
       end
 
       def publications
         Publication.all( 
       end
 
       def publications
         Publication.all( 
-         :joins => 
-           "JOIN issue_publications ON (issue_publications.publication_id = publications.id)",
-         :conditions =>
-           ["issue_publications.issue_id = ? ", self.id] )     
+          :joins =>
+            "JOIN issue_publications ON (issue_publications.publication_id = publications.id)",
+          :conditions =>
+            ["issue_publications.issue_id = ? ", self.id] )
       end
 
       def check_relations
       end
 
       def check_relations
-       current_names = self.publication_names
-       non_existant = []
+        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 }
+        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
+        if not missing.empty?
+          errors.add("publications", "Missing publication(s): " + missing.join(', '))
+        end
+      end
 
 
-     def update_relations
-       old = self.publications
-       current_names = self.publication_names
-       Rails.logger.info('[INFO] Updating relations: old= ' << old.inspect << ' current=' << current_names.inspect)
+      def update_relations
+        old = self.publications
+        current_names = self.publication_names
+        Rails.logger.info('[INFO] Updating relations: old= ' << old.inspect << ' current=' << current_names.inspect)
 
 
-       # delete unused relations
-       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
+        # delete unused relations
+        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
 
 
-       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
+        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
 
         return true
-     end
+      end
 
     end
   end
 
     end
   end
diff --git a/locales/en.yml b/locales/en.yml
new file mode 100644 (file)
index 0000000..3932ef2
--- /dev/null
@@ -0,0 +1,3 @@
+## YAML Template.
+en:
+  field_publications: Publications
diff --git a/locales/pl.yml b/locales/pl.yml
new file mode 100644 (file)
index 0000000..2bf0783
--- /dev/null
@@ -0,0 +1,3 @@
+## YAML Template.
+pl:
+  field_publications: Publikacje