summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin_controller.rb18
-rw-r--r--app/controllers/queries_controller.rb17
-rw-r--r--app/helpers/queries_helper.rb2
-rw-r--r--app/models/project_query.rb36
-rw-r--r--app/views/admin/projects.html.erb52
-rw-r--r--app/views/projects/_list.html.erb14
-rw-r--r--app/views/queries/_form.html.erb3
-rw-r--r--app/views/queries/_query_form.html.erb5
8 files changed, 94 insertions, 53 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index 6f4dce808..cb91b38c8 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -26,19 +26,23 @@ class AdminController < ApplicationController
before_action :require_admin
+ helper :queries
+ include QueriesHelper
+ helper :projects_queries
+ helper :projects
+
def index
@no_configuration_data = Redmine::DefaultData::Loader::no_data?
end
def projects
- @status = params[:status] || 1
-
- scope = Project.status(@status).sorted
- scope = scope.like(params[:name]) if params[:name].present?
+ retrieve_query(ProjectQuery, false, :defaults => @default_columns_names)
+ @query.admin_projects = 1
+ scope = @query.results_scope
- @project_count = scope.count
- @project_pages = Paginator.new @project_count, per_page_option, params['page']
- @projects = scope.limit(@project_pages.per_page).offset(@project_pages.offset).to_a
+ @entry_count = scope.count
+ @entry_pages = Paginator.new @entry_count, per_page_option, params['page']
+ @projects = scope.limit(@entry_pages.per_page).offset(@entry_pages.offset).to_a
render :action => "projects", :layout => false if request.xhr?
end
diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb
index 13fa3ade7..d2fc5efb9 100644
--- a/app/controllers/queries_controller.rb
+++ b/app/controllers/queries_controller.rb
@@ -52,6 +52,7 @@ class QueriesController < ApplicationController
@query.user = User.current
@query.project = @project
@query.build_from_params(params)
+ render :layout => 'admin' if params[:admin_projects]
end
def create
@@ -62,13 +63,14 @@ class QueriesController < ApplicationController
if @query.save
flash[:notice] = l(:notice_successful_create)
- redirect_to_items(:query_id => @query)
+ redirect_to_items(:query_id => @query, :admin_projects => params[:admin_projects])
else
render :action => 'new', :layout => !request.xhr?
end
end
def edit
+ render :layout => 'admin' if params[:admin_projects]
end
def update
@@ -76,7 +78,7 @@ class QueriesController < ApplicationController
if @query.save
flash[:notice] = l(:notice_successful_update)
- redirect_to_items(:query_id => @query)
+ redirect_to_items(:query_id => @query, :admin_projects => params[:admin_projects])
else
render :action => 'edit'
end
@@ -110,10 +112,15 @@ class QueriesController < ApplicationController
@query ? @query.queried_class.to_s.underscore.pluralize.to_sym : nil
end
+ def current_menu(project)
+ super if params[:admin_projects].nil?
+ end
+
private
def find_query
@query = Query.find(params[:id])
+ @query.admin_projects = params[:admin_projects] if @query.is_a?(ProjectQuery)
@project = @query.project
render_403 unless @query.editable_by?(User.current)
rescue ActiveRecord::RecordNotFound
@@ -163,7 +170,11 @@ class QueriesController < ApplicationController
end
def redirect_to_project_query(options)
- redirect_to projects_path(options)
+ if params[:admin_projects]
+ redirect_to admin_projects_path(options)
+ else
+ redirect_to projects_path(options)
+ end
end
# Returns the Query subclass, IssueQuery by default
diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb
index 77a577998..ffd291280 100644
--- a/app/helpers/queries_helper.rb
+++ b/app/helpers/queries_helper.rb
@@ -462,6 +462,8 @@ module QueriesHelper
url_params =
if controller_name == 'issues'
{:controller => 'issues', :action => 'index', :project_id => @project}
+ elsif controller_name == 'admin' && action_name == 'projects'
+ {:admin_projects => '1'}
else
{}
end
diff --git a/app/models/project_query.rb b/app/models/project_query.rb
index 002437aeb..35f05fbae 100644
--- a/app/models/project_query.rb
+++ b/app/models/project_query.rb
@@ -18,6 +18,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class ProjectQuery < Query
+ attr_accessor :admin_projects
+
self.queried_class = Project
self.view_permission = :search_project
@@ -74,6 +76,12 @@ class ProjectQuery < Query
add_custom_fields_filters(project_custom_fields)
end
+ def build_from_params(params, defaults={})
+ query = super
+ query.admin_projects = params[:admin_projects]
+ query
+ end
+
def available_columns
return @available_columns if @available_columns
@@ -84,7 +92,27 @@ class ProjectQuery < Query
end
def available_display_types
- ['board', 'list']
+ if self.admin_projects
+ ['list']
+ else
+ ['board', 'list']
+ end
+ end
+
+ def display_type
+ if self.admin_projects
+ 'list'
+ else
+ super
+ end
+ end
+
+ def project_statuses_values
+ values = super
+ if self.admin_projects
+ values << [l(:project_status_archived), Project::STATUS_ARCHIVED.to_s]
+ end
+ values
end
def default_columns_names
@@ -100,7 +128,11 @@ class ProjectQuery < Query
end
def base_scope
- Project.visible.where(statement)
+ if self.admin_projects
+ Project.where(statement)
+ else
+ Project.visible.where(statement)
+ end
end
def results_scope(options={})
diff --git a/app/views/admin/projects.html.erb b/app/views/admin/projects.html.erb
index aa462741d..e6805453a 100644
--- a/app/views/admin/projects.html.erb
+++ b/app/views/admin/projects.html.erb
@@ -2,47 +2,21 @@
<%= link_to l(:label_project_new), new_project_path, :class => 'icon icon-add' %>
</div>
-<%= title l(:label_project_plural) %>
+<h2><%= @query.new_record? ? l(:label_project_plural) : @query.name %></h2>
-<%= form_tag({}, :method => :get) do %>
-<fieldset><legend><%= l(:label_filter_plural) %></legend>
-<label for='status'><%= l(:field_status) %>:</label>
-<%= select_tag 'status', project_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %>
-<label for='name'><%= l(:label_project) %>:</label>
-<%= text_field_tag 'name', params[:name], :size => 30 %>
-<%= submit_tag l(:button_apply), :class => "small", :name => nil %>
-<%= link_to l(:button_clear), admin_projects_path, :class => 'icon icon-reload' %>
-</fieldset>
+<%= form_tag(admin_projects_path(@project, nil), :method => :get, :id => 'query_form') do %>
+<%= hidden_field_tag 'admin_projects', '1' %>
+<%= render :partial => 'queries/query_form' %>
<% end %>
-&nbsp;
-<% if @projects.any? %>
-<div class="autoscroll">
-<table class="list">
- <thead><tr>
- <th><%=l(:label_project)%></th>
- <th><%=l(:field_is_public)%></th>
- <th><%=l(:field_created_on)%></th>
- <th></th>
- </tr></thead>
- <tbody>
-<% project_tree(@projects, :init_level => true) do |project, level| %>
- <tr class="<%= project.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
- <td class="name"><span><%= link_to_project_settings(project, {}, :title => project.short_description) %></span></td>
- <td><%= checked_image project.is_public? %></td>
- <td><%= format_date(project.created_on) %></td>
- <td class="buttons">
- <%= link_to(l(:button_archive), archive_project_path(project, :status => params[:status]), :data => {:confirm => l(:text_are_you_sure)}, :method => :post, :class => 'icon icon-lock') unless project.archived? %>
- <%= link_to(l(:button_unarchive), unarchive_project_path(project, :status => params[:status]), :method => :post, :class => 'icon icon-unlock') if project.archived? %>
- <%= link_to(l(:button_copy), copy_project_path(project), :class => 'icon icon-copy') %>
- <%= link_to(l(:button_delete), project_path(project), :method => :delete, :class => 'icon icon-del') %>
- </td>
- </tr>
+<% if @query.valid? %>
+ <%if @projects.any? %>
+ <%= render :partial => 'projects/list', :locals => { :entries => @projects }%>
+ <% else %>
+ <p class="nodata"><%= l(:label_no_data) %></p>
+ <% end %>
<% end %>
- </tbody>
-</table>
-</div>
-<span class="pagination"><%= pagination_links_full @project_pages, @project_count %></span>
-<% else %>
-<p class="nodata"><%= l(:label_no_data) %></p>
+
+<% content_for :sidebar do %>
+ <%= render :partial => 'projects/sidebar' %>
<% end %>
diff --git a/app/views/projects/_list.html.erb b/app/views/projects/_list.html.erb
index 0abbc59e0..ba26e9d61 100644
--- a/app/views/projects/_list.html.erb
+++ b/app/views/projects/_list.html.erb
@@ -6,6 +6,9 @@
<% @query.inline_columns.each do |column| %>
<%= column_header(@query, column) %>
<% end %>
+ <% if controller_name == 'admin' && action_name == 'projects' %>
+ <th></th>
+ <% end %>
</tr>
</thead>
<tbody>
@@ -23,12 +26,23 @@
<%= link_to_function("#{l(:button_collapse_all)}/#{l(:button_expand_all)}",
"toggleAllRowGroups(this)", :class => 'toggle-all') %>
</td>
+ <% if controller_name == 'admin' && action_name == 'projects' %>
+ <td></td>
+ <% end %>
</tr>
<% end %>
<tr id="project-<%= entry.id %>" class="<%= cycle('odd', 'even') %> <%= entry.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
<% @query.inline_columns.each do |column| %>
<%= content_tag('td', column_content(column, entry), :class => column.css_classes) %>
<% end %>
+ <% if controller_name == 'admin' && action_name == 'projects' %>
+ <td class="buttons">
+ <%= link_to(l(:button_archive), archive_project_path(entry, :status => params[:status]), :data => {:confirm => l(:text_are_you_sure)}, :method => :post, :class => 'icon icon-lock') unless entry.archived? %>
+ <%= link_to(l(:button_unarchive), unarchive_project_path(entry, :status => params[:status]), :method => :post, :class => 'icon icon-unlock') if entry.archived? %>
+ <%= link_to(l(:button_copy), copy_project_path(entry), :class => 'icon icon-copy') %>
+ <%= link_to(l(:button_delete), project_path(entry), :method => :delete, :class => 'icon icon-del') %>
+ </td>
+ <% end %>
</tr>
<% end -%>
</tbody>
diff --git a/app/views/queries/_form.html.erb b/app/views/queries/_form.html.erb
index 6a94712e0..260a6ea63 100644
--- a/app/views/queries/_form.html.erb
+++ b/app/views/queries/_form.html.erb
@@ -4,6 +4,7 @@
<div class="tabular">
<%= hidden_field_tag 'gantt', '1' if params[:gantt] %>
<%= hidden_field_tag 'calendar', '1' if params[:calendar] %>
+<%= hidden_field_tag 'admin_projects', '1' if params[:admin_projects] %>
<p><label for="query_name"><%=l(:field_name)%></label>
<%= text_field 'query', 'name', :size => 80 %></p>
@@ -34,6 +35,8 @@
<p><label for='display_type'><%= l(:label_display_type) %></label>
<%= available_display_types_tags(@query) %>
</p>
+ <% elsif @query.available_display_types.size == 1 %>
+ <%= hidden_field_tag 'query[display_type]', @query.available_display_types.first %>
<% end %>
<p id ="default_columns"><label for="query_default_columns"><%=l(:label_default_columns)%></label>
diff --git a/app/views/queries/_query_form.html.erb b/app/views/queries/_query_form.html.erb
index 9f1f9ea7e..87e455bd6 100644
--- a/app/views/queries/_query_form.html.erb
+++ b/app/views/queries/_query_form.html.erb
@@ -63,8 +63,9 @@
<% end %>
<% else %>
<% if @query.editable_by?(User.current) %>
- <%= link_to l(:button_edit_object, object_name: l(:label_query).downcase), edit_query_path(@query), :class => 'icon icon-edit' %>
- <%= delete_link query_path(@query), {}, l(:button_delete_object, object_name: l(:label_query).downcase) %>
+ <% redirect_params = (controller_name == 'admin' && action_name == 'projects') ? {:admin_projects => 1} : {} %>
+ <%= link_to l(:button_edit_object, object_name: l(:label_query).downcase), edit_query_path(@query, redirect_params), :class => 'icon icon-edit' %>
+ <%= delete_link query_path(@query, redirect_params), {}, l(:button_delete_object, object_name: l(:label_query).downcase) %>
<% end %>
<% end %>
</p>