comparison app/controllers/queries_controller.rb @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
30 @offset, @limit = api_offset_and_limit 30 @offset, @limit = api_offset_and_limit
31 else 31 else
32 @limit = per_page_option 32 @limit = per_page_option
33 end 33 end
34 34
35 @query_count = Query.visible.count 35 @query_count = IssueQuery.visible.count
36 @query_pages = Paginator.new self, @query_count, @limit, params['page'] 36 @query_pages = Paginator.new @query_count, @limit, params['page']
37 @queries = Query.visible.all(:limit => @limit, :offset => @offset, :order => "#{Query.table_name}.name") 37 @queries = IssueQuery.visible.all(:limit => @limit, :offset => @offset, :order => "#{Query.table_name}.name")
38 38
39 respond_to do |format| 39 respond_to do |format|
40 format.html { render :nothing => true }
41 format.api 40 format.api
42 end 41 end
43 end 42 end
44 43
45 def new 44 def new
46 @query = Query.new 45 @query = IssueQuery.new
47 @query.user = User.current 46 @query.user = User.current
48 @query.project = @project 47 @query.project = @project
49 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? 48 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
50 build_query_from_params 49 @query.build_from_params(params)
51 end 50 end
52 51
53 def create 52 def create
54 @query = Query.new(params[:query]) 53 @query = IssueQuery.new(params[:query])
55 @query.user = User.current 54 @query.user = User.current
56 @query.project = params[:query_is_for_all] ? nil : @project 55 @query.project = params[:query_is_for_all] ? nil : @project
57 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? 56 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
58 build_query_from_params 57 @query.build_from_params(params)
59 @query.column_names = nil if params[:default_columns] 58 @query.column_names = nil if params[:default_columns]
60 59
61 if @query.save 60 if @query.save
62 flash[:notice] = l(:notice_successful_create) 61 flash[:notice] = l(:notice_successful_create)
63 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query 62 redirect_to _project_issues_path(@project, :query_id => @query)
64 else 63 else
65 render :action => 'new', :layout => !request.xhr? 64 render :action => 'new', :layout => !request.xhr?
66 end 65 end
67 end 66 end
68 67
71 70
72 def update 71 def update
73 @query.attributes = params[:query] 72 @query.attributes = params[:query]
74 @query.project = nil if params[:query_is_for_all] 73 @query.project = nil if params[:query_is_for_all]
75 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? 74 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
76 build_query_from_params 75 @query.build_from_params(params)
77 @query.column_names = nil if params[:default_columns] 76 @query.column_names = nil if params[:default_columns]
78 77
79 if @query.save 78 if @query.save
80 flash[:notice] = l(:notice_successful_update) 79 flash[:notice] = l(:notice_successful_update)
81 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query 80 redirect_to _project_issues_path(@project, :query_id => @query)
82 else 81 else
83 render :action => 'edit' 82 render :action => 'edit'
84 end 83 end
85 end 84 end
86 85
87 def destroy 86 def destroy
88 @query.destroy 87 @query.destroy
89 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 88 redirect_to _project_issues_path(@project, :set_filter => 1)
90 end 89 end
91 90
92 private 91 private
93 def find_query 92 def find_query
94 @query = Query.find(params[:id]) 93 @query = IssueQuery.find(params[:id])
95 @project = @query.project 94 @project = @query.project
96 render_403 unless @query.editable_by?(User.current) 95 render_403 unless @query.editable_by?(User.current)
97 rescue ActiveRecord::RecordNotFound 96 rescue ActiveRecord::RecordNotFound
98 render_404 97 render_404
99 end 98 end