diff --git a/app/assets/javascripts/projects/index.js b/app/assets/javascripts/projects/index.js index 356c3522b..d592226a8 100644 --- a/app/assets/javascripts/projects/index.js +++ b/app/assets/javascripts/projects/index.js @@ -435,7 +435,14 @@ sort: projectsViewSort }, success: function(data) { - viewContainer.html(data.html); + if (data.html.search(/id="edit-project-cards-form-\d+"/)) { + viewContainer.html(data.html); + $('#projects-absent').hide(); + $('#projects-present').show(); + } else { + $('#projects-present').hide(); + $('#projects-absent').show(); + } initFormSubmitLinks(viewContainer); init(); }, @@ -657,7 +664,16 @@ { 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(); diff --git a/app/controllers/experiments_controller.rb b/app/controllers/experiments_controller.rb index a7dce3b7d..af6d2d714 100644 --- a/app/controllers/experiments_controller.rb +++ b/app/controllers/experiments_controller.rb @@ -349,7 +349,7 @@ class ExperimentsController < ApplicationController end def load_projects_tree - @projects_tree = current_user.projects_tree(current_team, nil) + @projects_tree = current_user.projects_tree(current_team) end def check_view_permissions diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index eb9cd313b..48bdff2e6 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -661,7 +661,7 @@ class MyModulesController < ApplicationController end def load_projects_tree - @projects_tree = current_user.projects_tree(current_team, nil) + @projects_tree = current_user.projects_tree(current_team) end def check_manage_permissions diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index d0bed08f8..8111579f9 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -357,7 +357,9 @@ 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_sort) + @projects_tree = current_user.projects_tree( + @current_team, @current_filter, @current_sort + ) else @projects_tree = [] end diff --git a/app/models/user.rb b/app/models/user.rb index 8d4a1726a..3ac31a6b2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -350,7 +350,7 @@ class User < ApplicationRecord result || [] end - def projects_tree(team, sort_by = nil) + def projects_tree(team, filter_by = nil, 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,19 +359,25 @@ class User < ApplicationRecord ) end - sort = - case sort_by - when 'old' - { created_at: :asc } - when 'atoz' - { name: :asc } - when 'ztoa' - { name: :desc } - else - { created_at: :desc } - end - - result.where(archived: false).distinct.order(sort) + 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 } + when 'atoz' + { name: :asc } + when 'ztoa' + { name: :desc } + else + { created_at: :desc } + end + result.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 675f8cc83..94118b517 100644 --- a/app/views/projects/index.html.erb +++ b/app/views/projects/index.html.erb @@ -29,7 +29,7 @@