From 18e52e2c6f371d31c646bf6b46c9cd6401b5fa5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Wed, 24 Oct 2018 00:29:30 +0200 Subject: [PATCH 1/4] Fix fetching all user projects [SCI-2787] --- app/controllers/experiments_controller.rb | 2 +- app/controllers/my_modules_controller.rb | 2 +- app/controllers/projects_controller.rb | 4 ++- app/models/user.rb | 34 +++++++++++++---------- 4 files changed, 25 insertions(+), 17 deletions(-) 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 From 43fdab561f108bc4ea835882efeb6153d61659f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Wed, 24 Oct 2018 01:37:57 +0200 Subject: [PATCH 2/4] Fix project archiving and restoring edge case [SCI-2787] --- app/views/projects/index/_project.html.erb | 2 +- app/views/projects/index/_project_actions_dropdown.html.erb | 2 +- app/views/projects/index_dt.json.jbuilder | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/projects/index/_project.html.erb b/app/views/projects/index/_project.html.erb index da464a3ec..9e5ed1713 100644 --- a/app/views/projects/index/_project.html.erb +++ b/app/views/projects/index/_project.html.erb @@ -5,7 +5,7 @@ data-project-users-tab-url="<%= url_for project_user_projects_path(project_id: project.id, format: :json) %>">
- <%= render partial: "projects/index/project_actions_dropdown.html.erb", locals: { project: project } %> + <%= render partial: "projects/index/project_actions_dropdown.html.erb", locals: { project: project, view: 'cards' } %>
diff --git a/app/views/projects/index/_project_actions_dropdown.html.erb b/app/views/projects/index/_project_actions_dropdown.html.erb index 0a1c5e763..c717cb267 100644 --- a/app/views/projects/index/_project_actions_dropdown.html.erb +++ b/app/views/projects/index/_project_actions_dropdown.html.erb @@ -6,7 +6,7 @@ <% project_form = nil %> - <%= form_for project, format: :json, method: :put, remote: true do |f| %> + <%= form_for project, format: :json, method: :put, remote: true, html: {id: "edit-project-#{view}-form-#{project.id}" } do |f| %> <% project_form = f %> <%= f.hidden_field :archived, value: active %> <% end %> diff --git a/app/views/projects/index_dt.json.jbuilder b/app/views/projects/index_dt.json.jbuilder index 9516f674c..998bae65b 100644 --- a/app/views/projects/index_dt.json.jbuilder +++ b/app/views/projects/index_dt.json.jbuilder @@ -34,7 +34,7 @@ json.data do json.set! 'tasks', project.task_count json.set! 'actions', render( partial: 'projects/index/project_actions_dropdown.html.erb', - locals: { project: project } + locals: { project: project, view: 'table' } ) end end From c89488e105eb4273461cea1008414d93ceab2b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Wed, 24 Oct 2018 03:34:13 +0200 Subject: [PATCH 3/4] Fix displaying projects when all are archived [SCI-2787] --- app/assets/javascripts/projects/index.js | 9 ++++++++- app/views/projects/index.html.erb | 7 ++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/projects/index.js b/app/assets/javascripts/projects/index.js index 356c3522b..659c06797 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-') > 0) { + $('#projects-absent').hide(); + $('#projects-present').show(); + viewContainer.html(data.html); + } else { + $('#projects-present').hide(); + $('#projects-absent').show(); + } initFormSubmitLinks(viewContainer); init(); }, 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 @@
- <% if @projects_tree.empty? %> +
<%=t 'projects.index.no_projects.text' %> <% if @teams.exists? && can_create_projects?(current_team) %> @@ -44,7 +44,8 @@

<%=t 'projects.index.no_projects.no_permission_title' %>

<% end %>
- <% else %> +
+
- <% end %> +
From 6447750ff7ca0d8e29df76c2d649553d41b4c5b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Thu, 25 Oct 2018 22:31:00 +0200 Subject: [PATCH 4/4] Fix showing projects in table view when all are archived [SCI-2787] --- app/assets/javascripts/projects/index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/projects/index.js b/app/assets/javascripts/projects/index.js index 659c06797..d592226a8 100644 --- a/app/assets/javascripts/projects/index.js +++ b/app/assets/javascripts/projects/index.js @@ -435,10 +435,10 @@ sort: projectsViewSort }, success: function(data) { - if (data.html.search('id="edit-project-cards-form-') > 0) { + if (data.html.search(/id="edit-project-cards-form-\d+"/)) { + viewContainer.html(data.html); $('#projects-absent').hide(); $('#projects-present').show(); - viewContainer.html(data.html); } else { $('#projects-present').hide(); $('#projects-absent').show(); @@ -664,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();