Wyświetlanie wg. repozytoriów.
[redakcja_redmine.git] / 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         Repository.all.each do |repo|
20           repo_status = []
21           repo.entries.each do |entry|
22             match = entry.path.match(regexp)
23             if match
24               Publication.find_or_create_by_name(:name => match[1], 
25                 :source_file => entry.path, :repository_id => repo.id)
26               repo_status += [{:path => entry.path, :match => match[1], :matched => true}]
27             else
28               repo_status += [{:path => entry.path, :match =>nil, :matched => false}]
29             end
30           end
31           @match_status += [{:repo => repo, :status => repo_status}]
32         end     
33         
34         respond_to do |format|  
35           format.html
36           format.xml { render :xml => @match_status}
37           format.json { render :json => @match_status }
38         end
39   end
40
41   def issues
42         @publication = Publication.find_by_name(params[:pub])
43
44         joins = "JOIN issue_publications ON (issues.id = issue_publications.issue_id)"
45         conditions = ['issue_publications.publication_id = ? ', @publication.id ]
46         @issues = Issue.all(:joins => joins, :conditions =>  conditions)
47         respond_to do |format|
48           format.html
49           format.xml do 
50             render :xml => @issues
51           end
52
53           format.json do
54             headers['Content-Type'] = 'application/json'
55             render :json => @issues
56           end
57         end
58   end
59
60   def redirect_to_platform
61         render :text => ""
62   end
63
64   private
65
66   def find_project
67     @project = Project.find(params[:project_id])
68   end
69
70 end