Merge pull request #1360 from mlorb/ml-sci-2837

Fix empty projects page bug and projects tree bug [SCI-2837]
This commit is contained in:
mlorb 2018-11-08 15:00:44 +01:00 committed by GitHub
commit 46080a2b21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 30 deletions

View file

@ -435,13 +435,13 @@
sort: projectsViewSort sort: projectsViewSort
}, },
success: function(data) { success: function(data) {
if (data.html.search(/id="edit-project-cards-form-\d+"/)) { viewContainer.html(data.html);
viewContainer.html(data.html); if (data.count === 0 && projectsViewFilter !== 'archived') {
$('#projects-absent').hide();
$('#projects-present').show();
} else {
$('#projects-present').hide(); $('#projects-present').hide();
$('#projects-absent').show(); $('#projects-absent').show();
} else {
$('#projects-absent').hide();
$('#projects-present').show();
} }
initFormSubmitLinks(viewContainer); initFormSubmitLinks(viewContainer);
init(); init();
@ -664,16 +664,7 @@
{ data: 'tasks' }, { data: 'tasks' },
{ data: 'actions' } { data: 'actions' }
], ],
fnPreDrawCallback: function() {
$('#projects-absent').hide();
$('#projects-present').show();
},
fnDrawCallback: function() { fnDrawCallback: function() {
var $table = TABLE.table().node();
if ($('.dataTables_empty', $table).length) {
$('#projects-present').hide();
$('#projects-absent').show();
}
animateSpinner(this, false); animateSpinner(this, false);
updateDataTableSelectAllCtrl(); updateDataTableSelectAllCtrl();
initRowSelection(); initRowSelection();
@ -712,6 +703,8 @@
if ($(event.target).data('mode') === 'table') { if ($(event.target).data('mode') === 'table') {
// table tab // table tab
$('#sortMenu').hide(); $('#sortMenu').hide();
$('#projects-absent').hide();
$('#projects-present').show();
if ($.isEmptyObject(TABLE)) { if ($.isEmptyObject(TABLE)) {
dataTableInit(); dataTableInit();
} else if (projectsViewFilterChanged) { } else if (projectsViewFilterChanged) {

View file

@ -36,7 +36,8 @@ class ProjectsController < ApplicationController
html: render_to_string( html: render_to_string(
partial: 'projects/index/team_projects.html.erb', partial: 'projects/index/team_projects.html.erb',
locals: { projects: @projects } locals: { projects: @projects }
) ),
count: @projects.size
} }
end end
format.html do format.html do
@ -357,9 +358,7 @@ class ProjectsController < ApplicationController
@current_team = current_team if current_team @current_team = current_team if current_team
@current_team ||= current_user.teams.first @current_team ||= current_user.teams.first
@current_sort ||= 'new' @current_sort ||= 'new'
@projects_tree = current_user.projects_tree( @projects_tree = current_user.projects_tree(@current_team, @current_sort)
@current_team, @current_filter, @current_sort
)
else else
@projects_tree = [] @projects_tree = []
end end

View file

@ -350,7 +350,7 @@ class User < ApplicationRecord
result || [] result || []
end end
def projects_tree(team, filter_by = nil, sort_by = nil) def projects_tree(team, sort_by = nil)
result = team.projects.includes(active_experiments: :active_my_modules) result = team.projects.includes(active_experiments: :active_my_modules)
unless is_admin_of_team?(team) unless is_admin_of_team?(team)
# Only admins see all projects of the team # Only admins see all projects of the team
@ -359,14 +359,6 @@ class User < ApplicationRecord
) )
end end
result = case filter_by
when 'archived'
result.where(archived: true)
when 'active'
result.where(archived: false)
else
result
end
sort = case sort_by sort = case sort_by
when 'old' when 'old'
{ created_at: :asc } { created_at: :asc }
@ -377,7 +369,7 @@ class User < ApplicationRecord
else else
{ created_at: :desc } { created_at: :desc }
end end
result.distinct.order(sort) result.where(archived: false).distinct.order(sort)
end end
# Finds all activities of user that is assigned to project. If user # Finds all activities of user that is assigned to project. If user

View file

@ -29,7 +29,7 @@
<div class="content-pane" id="projects-index"> <div class="content-pane" id="projects-index">
<div id="projects-absent" style="<%= 'display:none' if @projects_tree.any? %>"> <div id="projects-absent" style="display:none">
<div class="jumbotron text-center" style="margin-top:12%"> <div class="jumbotron text-center" style="margin-top:12%">
<strong><%=t 'projects.index.no_projects.text' %></strong> <strong><%=t 'projects.index.no_projects.text' %></strong>
<% if @teams.exists? && can_create_projects?(current_team) %> <% if @teams.exists? && can_create_projects?(current_team) %>
@ -44,7 +44,7 @@
<% end %> <% end %>
</div> </div>
</div> </div>
<div id="projects-present" style="<%= 'display:none' if @projects_tree.empty? %>"> <div id="projects-present" style="display:none">
<!-- Edit project modal --> <!-- Edit project modal -->
<div class="modal" id="edit-project-modal" tabindex="-1" role="dialog" aria-labelledby="edit-project-modal-label"> <div class="modal" id="edit-project-modal" tabindex="-1" role="dialog" aria-labelledby="edit-project-modal-label">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">