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