1220bea17553bcee3f7a1eeabe553f69efce3b4b
[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         regexp = Regexp.new(Setting.plugin_redmine_publications['pattern'])
17         Repository.all.each do |repo|
18           repo.entries.each do |entry|
19             match = entry.path.match(regexp)
20             if match
21               Publication.find_or_create_by_name(:name => match[1], 
22                 :source_file => entry.path, :repository_id => repo.id)
23             end
24           end
25         end     
26   end
27
28   def issues
29         @publication = Publication.find_by_name(params[:pub])
30
31         joins = "JOIN issue_publications ON (issues.id = issue_publications.issue_id)"
32         conditions = ['issue_publications.publication_id = ? ', @publication.id ]
33         @issues = Issue.all(:joins => joins, :conditions =>  conditions)
34         respond_to do |format|
35           format.html
36           format.xml do 
37             render :xml => @issues
38           end
39
40           format.json do
41             headers['Content-Type'] = 'application/json'
42             render :json => @issues
43           end
44         end
45   end
46
47   def redirect_to_platform
48         render :text => ""
49   end
50
51   private
52
53   def find_project
54     @project = Project.find(params[:project_id])
55   end
56
57 end