fix empty projects page bug and projects tree bug

This commit is contained in:
mlorb 2018-11-07 13:45:46 +01:00
parent 039faf2964
commit 4d156080ac
4 changed files with 14 additions and 30 deletions

View file

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

View file

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

View file

@ -350,7 +350,7 @@ class User < ApplicationRecord
result || []
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)
unless is_admin_of_team?(team)
# Only admins see all projects of the team
@ -359,14 +359,6 @@ class User < ApplicationRecord
)
end
result = case filter_by
when 'archived'
result.where(archived: true)
when 'active'
result.where(archived: false)
else
result
end
sort = case sort_by
when 'old'
{ created_at: :asc }
@ -377,7 +369,7 @@ class User < ApplicationRecord
else
{ created_at: :desc }
end
result.distinct.order(sort)
result.where(archived: false).distinct.order(sort)
end
# 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 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%">
<strong><%=t 'projects.index.no_projects.text' %></strong>
<% if @teams.exists? && can_create_projects?(current_team) %>
@ -44,7 +44,7 @@
<% end %>
</div>
</div>
<div id="projects-present" style="<%= 'display:none' if @projects_tree.empty? %>">
<div id="projects-present" style="display:none">
<!-- Edit project modal -->
<div class="modal" id="edit-project-modal" tabindex="-1" role="dialog" aria-labelledby="edit-project-modal-label">
<div class="modal-dialog" role="document">