Memory problem in 'My page' with 'Open aprovals' option #1333

This commit is contained in:
Karel.Picman 2022-02-01 09:12:51 +01:00
parent 172904428e
commit b3a79a816e
3 changed files with 142 additions and 30 deletions

View File

@ -0,0 +1,26 @@
<%
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright © 2011-22 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
%>
<li>
<%= context_menu_link l(:button_delete), dmsf_link_path(dmsf_link), method: :delete, class: 'icon icon-del',
data: { confirm: l(:text_are_you_sure) }, id: 'dmsf-cm-delete', disabled: !allowed %>
</li>

View File

@ -20,28 +20,27 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
%>
<% assignments = Array.new %>
<% if @user %>
<% all_assignments = DmsfWorkflowStepAssignment.
left_outer_joins(:dmsf_workflow_step_actions).
joins(:dmsf_workflow_step).
joins(:dmsf_file_revision).
where(dmsf_file_revisions: { deleted: DmsfFileRevision::STATUS_ACTIVE, workflow: DmsfWorkflow::STATE_WAITING_FOR_APPROVAL }).
where(dmsf_workflow_step_assignments: { user_id: @user.id }).
where(dmsf_workflow_step_assignments: { user_id: @user&.id }).
where(['dmsf_workflow_step_actions.id IS NULL OR dmsf_workflow_step_actions.action = ?',
DmsfWorkflowStepAction::ACTION_DELEGATE]).
order('dmsf_workflow_step_assignments.dmsf_file_revision_id, dmsf_workflow_steps.step').to_a %>
<% assignments = all_assignments.delete_if { |a| (a.dmsf_file_revision != a.dmsf_file_revision.dmsf_file.last_revision) } %>
<% assignments.uniq! { |a| a.dmsf_file_revision } %>
<% end %>
<% unless defined?(EasyExtensions) %>
<h3><%= l(:open_approvals)%> (<%= assignments.size %>)</h3>
<% end %>
<% if assignments.any? %>
<%= form_tag do %>
<%= form_tag({}, data: { cm_url: dmsf_context_menu_path(back_url: my_page_path) }) do %>
<table class="list">
<thead>
<tr>
<th class="checkbox hide-when-print">
<%= check_box_tag 'check_all', '', false, class: 'toggle-selection',
title: "#{l(:button_check_all)}/#{l(:button_uncheck_all)}" %>
</th>
<th><%= l(:field_project) %></th>
<th><%= l(:field_label_dmsf_workflow) %></th>
<th><%= l(:field_status) %></th>
@ -52,16 +51,19 @@
</thead>
<tbody>
<% assignments.each do |assignment| %>
<tr id="assignment-<%= assignment.id %>">
<tr id="file-<%= assignment.dmsf_file_revision.dmsf_file.id %>" class="hascontextmenu">
<td class="checkbox hide-when-print">
<%= check_box_tag 'ids[]', "file-#{assignment.dmsf_file_revision.dmsf_file.id}", false, id: nil %>
</td>
<td class="project">
<% if assignment.dmsf_file_revision.dmsf_file.project %>
<%= link_to_project(assignment.dmsf_file_revision.dmsf_file.project) %>
<%= link_to_project assignment.dmsf_file_revision.dmsf_file.project %>
<% end %>
</td>
<td>
<% if assignment.dmsf_workflow_step && assignment.dmsf_workflow_step.dmsf_workflow %>
<%= link_to(h(assignment.dmsf_workflow_step.dmsf_workflow.name),
edit_dmsf_workflow_path(assignment.dmsf_workflow_step.dmsf_workflow)) %>
<%= link_to h(assignment.dmsf_workflow_step.dmsf_workflow.name),
edit_dmsf_workflow_path(assignment.dmsf_workflow_step.dmsf_workflow) %>
<% end %>
</td>
<td class="dmsf_workflow">
@ -80,36 +82,29 @@
<td class="title">
<% if assignment.dmsf_file_revision && assignment.dmsf_file_revision.dmsf_file %>
<%= link_to h(assignment.dmsf_file_revision.title),
{ controller: 'dmsf_files', action: :show, id: assignment.dmsf_file_revision.dmsf_file } %>
dmsf_file_path(id: assignment.dmsf_file_revision.dmsf_file) %>
<% end %>
</td>
<td class="title">
<% if assignment.dmsf_file_revision %>
<% if assignment.dmsf_file_revision.dmsf_file.dmsf_folder %>
<%= link_to h(assignment.dmsf_file_revision.dmsf_file.dmsf_folder.title),
{ controller: 'dmsf', action: 'show', id: assignment.dmsf_file_revision.dmsf_file.project,
folder_id: assignment.dmsf_file_revision.dmsf_file.dmsf_folder} %>
dmsf_folder_path(id: assignment.dmsf_file_revision.dmsf_file.project,
folder_id: assignment.dmsf_file_revision.dmsf_file.dmsf_folder) %>
<% elsif assignment.dmsf_file_revision.dmsf_file.project %>
<%= link_to l(:link_documents),
{ controller: 'dmsf', action: 'show', id: assignment.dmsf_file_revision.dmsf_file.project } %>
<%= link_to l(:link_documents), dmsf_folder_path(id: assignment.dmsf_file_revision.dmsf_file.project) %>
<% end %>
<% end %>
</td>
<td class="dmsf-buttons">
<%= render partial: 'dmsf_workflows/approval_workflow_button',
locals: { file: assignment.dmsf_file_revision.dmsf_file,
file_approval_allowed: User.current.allowed_to?(:file_approval,
assignment.dmsf_file_revision.dmsf_file.project),
workflows_available: nil,
project: assignment.dmsf_file_revision.dmsf_file.project,
wf: assignment.dmsf_workflow_step.dmsf_workflow, dmsf_link_id: nil,
back_url: my_page_path } %>
<td>
<%= link_to_context_menu %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<%= context_menu %>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>

View File

@ -0,0 +1,91 @@
<%
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright © 2011-22 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
%>
<% folders = [] %>
<% files = [] %>
<% folders = DmsfFolder.visible.joins(
'JOIN dmsf_locks ON dmsf_folders.id = dmsf_locks.entity_id').where(
['dmsf_locks.entity_type = ? AND dmsf_locks.user_id = ? AND (dmsf_locks.expires_at IS NULL OR dmsf_locks.expires_at > ?)',
1, @user.id, Time.current]).all if @user %>
<% files = DmsfFile.visible.joins(
'JOIN dmsf_locks ON dmsf_files.id = dmsf_locks.entity_id').where(
['dmsf_locks.entity_type = ? AND dmsf_locks.user_id = ? AND (dmsf_locks.expires_at IS NULL OR dmsf_locks.expires_at > ?)',
0, @user.id, Time.current]).all if @user %>
<% unless defined?(EasyExtensions) %>
<h3><%= l(:locked_documents)%> (<%= folders.count %>/<%= files.count %>)</h3>
<% end %>
<% if folders.any? || files.any?%>
<%= form_tag({}) do %>
<table class="list">
<thead>
<tr>
<th><%= l(:field_project) %></th>
<th><%= l(:label_document) %>/<%= l(:field_folder) %></th>
<th><%= l(:field_folder) %></th>
</tr>
</thead>
<tbody>
<% folders.each do |folder| %>
<tr id="folder-<%= folder.id %>">
<td class="project">
<%= link_to_project(folder.project) %>
</td>
<td class="title">
<%= link_to h(folder.title), { controller: 'dmsf', action: 'show', id: folder.project, folder_id: folder},
class: 'icon icon-folder' %>
</td>
<td class="title">
<% if folder.dmsf_folder %>
<%= link_to h(folder.dmsf_folder.title),
{ controller: 'dmsf', action: 'show', id: folder.project, folder_id: folder.dmsf_folder } %>
<% else %>
<%= link_to l(:link_documents), { controller: 'dmsf', action: 'show', id: folder.project } %>
<% end %>
</td>
</tr>
<% end %>
<% files.each do |file| %>
<tr id="file-<%= file.id %>">
<td class="project">
<%= link_to_project(file.project) if file.project %>
</td>
<td class="title">
<%= link_to h(file.title), { controller: 'dmsf_files', action: :show, id: file },
class: "icon icon-file #{DmsfHelper.filetype_css(file.name)}" %>
</td>
<td class="title">
<% if file.dmsf_folder %>
<%= link_to h(file.dmsf_folder.title),
{ controller: 'dmsf', action: 'show', id: file.project, folder_id: file.dmsf_folder } %>
<% else %>
<%= link_to_if file.project, l(:link_documents),
{ controller: 'dmsf', action: 'show', id: file.project } %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>