Fixed critical bug: new parts not added to version control after creation.
[redakcja.git] / redmine / redmine_publications / app / controllers / publications_controller.rb
1 class PublicationsController < ApplicationController
2   unloadable
3
4   #  before_filter :authorize, :only => [:issues]
5
6   def index
7         @publications = Publication.all
8     respond_to do |format|
9       format.html
10       format.xml { render :xml => @publications }
11       format.json { render :json => @publications }
12     end
13   end
14
15   def refresh
16     @match_status = []
17
18     regexp = Regexp.new(Setting.plugin_redmine_publications[:pattern])
19     Publication.delete_all()
20     repos = Repository.all
21     if repos
22       repos.each do |repo|
23         repo_status = []
24         if repo.entries
25           repo.entries.each do |entry|
26             match = entry.path.match(regexp)
27             if match
28               Publication.find_or_create_by_name(:name => match[1],
29                 :source_file => entry.path, :repository_id => repo.id)
30               repo_status += [{:path => entry.path, :match => match[1], :matched => true}]
31             else
32               repo_status += [{:path => entry.path, :match =>nil, :matched => false}]
33             end
34           end
35           @match_status += [{:repo => repo, :status => repo_status}]
36         end
37       end
38         
39       respond_to do |format|
40         format.html
41         format.xml { render :xml => @match_status}
42         format.json { render :json => @match_status }
43       end
44     end
45   end
46
47   def issues
48     @publication = Publication.find_by_name(params[:pub])
49
50     joins = "JOIN issue_publications ON (issues.id = issue_publications.issue_id)"
51     conditions = ['issue_publications.publication_id = ? ', @publication.id ]
52     @issues = Issue.all(:joins => joins, :conditions =>  conditions)
53
54     respond_to do |fmt| 
55       fmt.json { render :json => @issues, :callback => params[:callback] }
56     end
57   end
58
59   private
60
61   def find_project
62     @project = Project.find(params[:project_id])
63   end
64
65 end