Merge pull request #1346 from mz3944/mz-SCI-2787

In project list table table is not updated when archiving/restoring project [SCI-2787]
This commit is contained in:
mz3944 2018-10-28 14:36:17 +01:00 committed by GitHub
commit d733f4e357
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 49 additions and 24 deletions

View file

@ -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();

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -29,7 +29,7 @@
<div class="content-pane" id="projects-index">
<% if @projects_tree.empty? %>
<div id="projects-absent" style="<%= 'display:none' if @projects_tree.any? %>">
<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,8 @@
<p><strong><%=t 'projects.index.no_projects.no_permission_title' %></strong></p>
<% end %>
</div>
<% else %>
</div>
<div id="projects-present" style="<%= 'display:none' if @projects_tree.empty? %>">
<!-- 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">
@ -146,7 +147,7 @@
<%= render partial: "projects/index/team_projects_table" %>
</div>
</div>
<% end %>
</div>
</div>

View file

@ -5,7 +5,7 @@
data-project-users-tab-url="<%= url_for project_user_projects_path(project_id: project.id, format: :json) %>">
<div class="panel-heading">
<%= 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' } %>
<div class="pull-right">
<input class="project-card-selector" type="checkbox" name="project-<%= project.id %>">

View file

@ -6,7 +6,7 @@
<span class="caret"></span>
</button>
<% 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 %>

View file

@ -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