From 4d156080acfbe639ec310c9a821e7709454d9daa Mon Sep 17 00:00:00 2001 From: mlorb Date: Wed, 7 Nov 2018 13:45:46 +0100 Subject: [PATCH] fix empty projects page bug and projects tree bug --- app/assets/javascripts/projects/index.js | 21 +++++++-------------- app/controllers/projects_controller.rb | 7 +++---- app/models/user.rb | 12 ++---------- app/views/projects/index.html.erb | 4 ++-- 4 files changed, 14 insertions(+), 30 deletions(-) diff --git a/app/assets/javascripts/projects/index.js b/app/assets/javascripts/projects/index.js index 22071e941..fe1968834 100644 --- a/app/assets/javascripts/projects/index.js +++ b/app/assets/javascripts/projects/index.js @@ -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) { diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 8111579f9..88432c82e 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 3ac31a6b2..84ba229e8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb index 7b615c4c2..66b99f382 100644 --- a/app/views/projects/index.html.erb +++ b/app/views/projects/index.html.erb @@ -29,7 +29,7 @@
-
+ -
+