To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / .svn / text-base / queries_controller.rb.svn-base @ 442:753f1380d6bc
History | View | Annotate | Download (3.18 KB)
| 1 | 0:513646585e45 | Chris | # redMine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
||
| 3 | # |
||
| 4 | # This program is free software; you can redistribute it and/or |
||
| 5 | # modify it under the terms of the GNU General Public License |
||
| 6 | # as published by the Free Software Foundation; either version 2 |
||
| 7 | # of the License, or (at your option) any later version. |
||
| 8 | # |
||
| 9 | # This program is distributed in the hope that it will be useful, |
||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 12 | # GNU General Public License for more details. |
||
| 13 | # |
||
| 14 | # You should have received a copy of the GNU General Public License |
||
| 15 | # along with this program; if not, write to the Free Software |
||
| 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||
| 17 | |||
| 18 | class QueriesController < ApplicationController |
||
| 19 | menu_item :issues |
||
| 20 | before_filter :find_query, :except => :new |
||
| 21 | before_filter :find_optional_project, :only => :new |
||
| 22 | |||
| 23 | def new |
||
| 24 | @query = Query.new(params[:query]) |
||
| 25 | @query.project = params[:query_is_for_all] ? nil : @project |
||
| 26 | @query.user = User.current |
||
| 27 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
||
| 28 | 441:cbce1fd3b1b7 | Chris | |
| 29 | @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) if params[:fields] || params[:f] |
||
| 30 | @query.group_by ||= params[:group_by] |
||
| 31 | @query.column_names = params[:c] if params[:c] |
||
| 32 | 0:513646585e45 | Chris | @query.column_names = nil if params[:default_columns] |
| 33 | |||
| 34 | if request.post? && params[:confirm] && @query.save |
||
| 35 | flash[:notice] = l(:notice_successful_create) |
||
| 36 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query |
||
| 37 | return |
||
| 38 | end |
||
| 39 | render :layout => false if request.xhr? |
||
| 40 | end |
||
| 41 | |||
| 42 | def edit |
||
| 43 | if request.post? |
||
| 44 | @query.filters = {}
|
||
| 45 | 441:cbce1fd3b1b7 | Chris | @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) if params[:fields] || params[:f] |
| 46 | 0:513646585e45 | Chris | @query.attributes = params[:query] |
| 47 | @query.project = nil if params[:query_is_for_all] |
||
| 48 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
||
| 49 | 441:cbce1fd3b1b7 | Chris | @query.group_by ||= params[:group_by] |
| 50 | @query.column_names = params[:c] if params[:c] |
||
| 51 | 0:513646585e45 | Chris | @query.column_names = nil if params[:default_columns] |
| 52 | |||
| 53 | if @query.save |
||
| 54 | flash[:notice] = l(:notice_successful_update) |
||
| 55 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query |
||
| 56 | end |
||
| 57 | end |
||
| 58 | end |
||
| 59 | |||
| 60 | def destroy |
||
| 61 | @query.destroy if request.post? |
||
| 62 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 |
||
| 63 | end |
||
| 64 | |||
| 65 | private |
||
| 66 | def find_query |
||
| 67 | @query = Query.find(params[:id]) |
||
| 68 | @project = @query.project |
||
| 69 | render_403 unless @query.editable_by?(User.current) |
||
| 70 | rescue ActiveRecord::RecordNotFound |
||
| 71 | render_404 |
||
| 72 | end |
||
| 73 | |||
| 74 | def find_optional_project |
||
| 75 | @project = Project.find(params[:project_id]) if params[:project_id] |
||
| 76 | render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true) |
||
| 77 | rescue ActiveRecord::RecordNotFound |
||
| 78 | render_404 |
||
| 79 | end |
||
| 80 | end |