#1080 Workflow link & revision view

This commit is contained in:
Karel Pičman 2020-02-27 15:59:45 +01:00
parent 50e2f0730e
commit 10871350e0
11 changed files with 223 additions and 145 deletions

View File

@ -233,6 +233,18 @@ class DmsfWorkflowsController < ApplicationController
end
def log
if params[:dmsf_file_revision_id].present?
@revision = DmsfFileRevision.find_by(id: params[:dmsf_file_revision_id])
elsif params[:dmsf_file_id].present?
dmsf_file = DmsfFile.find_by(id: params[:dmsf_file_id])
@revision = dmsf_file.last_revision if dmsf_file
elsif params[:dmsf_link_id].present?
dmsf_link = DmsfLink.find_by(id: params[:dmsf_link_id])
if dmsf_link
dmsf_file = dmsf_link.target_file
@revision = dmsf_file.last_revision
end
end
respond_to do |format|
format.html
format.js

View File

@ -239,6 +239,12 @@ class DmsfFile < ActiveRecord::Base
self.project_id = project.id
self.dmsf_folder = folder
new_revision = last_revision.clone
new_revision.workflow = nil
new_revision.dmsf_workflow_id = nil
new_revision.dmsf_workflow_assigned_by_user_id = nil
new_revision.dmsf_workflow_assigned_at = nil
new_revision.dmsf_workflow_started_by_user_id = nil
new_revision.dmsf_workflow_started_at = nil
new_revision.dmsf_file = self
new_revision.comment = l(:comment_moved_from, source: source)
new_revision.custom_values = []

View File

@ -186,8 +186,10 @@ class DmsfQuery < Query
users.lastname AS lastname,
users.id AS author,
'folder' AS type,
dmsf_folders.deleted AS deleted,
0 AS sort #{cf_columns}}).
joins('LEFT JOIN users ON dmsf_folders.user_id = users.id')
joins('LEFT JOIN users ON dmsf_folders.user_id = users.id')#.
#visible(!deleted)
if deleted
scope.where(dmsf_folders: { project_id: project.id, deleted: deleted })
else
@ -218,6 +220,7 @@ class DmsfQuery < Query
users.lastname AS lastname,
users.id AS author,
'folder-link' AS type,
dmsf_links.deleted AS deleted,
0 AS sort #{cf_columns}}).
joins('LEFT JOIN dmsf_folders ON dmsf_links.target_id = dmsf_folders.id').
joins('LEFT JOIN users ON users.id = COALESCE(dmsf_folders.user_id, dmsf_links.user_id)')
@ -252,6 +255,7 @@ class DmsfQuery < Query
users.lastname AS lastname,
users.id AS author,
'file' AS type,
dmsf_files.deleted AS deleted,
1 AS sort #{cf_columns}}).
joins(:dmsf_file_revisions).
joins('LEFT JOIN users ON dmsf_file_revisions.user_id = users.id ').
@ -286,6 +290,7 @@ class DmsfQuery < Query
users.lastname AS lastname,
users.id AS author,
'file-link' AS type,
dmsf_links.deleted AS deleted,
1 AS sort #{cf_columns}}).
joins('JOIN dmsf_files ON dmsf_files.id = dmsf_links.target_id').
joins('JOIN dmsf_file_revisions ON dmsf_file_revisions.dmsf_file_id = dmsf_files.id').
@ -321,6 +326,7 @@ class DmsfQuery < Query
users.lastname AS lastname,
users.id AS author,
'url-link' AS type,
dmsf_links.deleted AS deleted,
1 AS sort #{cf_columns}}).
joins('LEFT JOIN users ON dmsf_links.user_id = users.id ')
if deleted

View File

@ -39,6 +39,21 @@ class DmsfWorkflow < ActiveRecord::Base
STATUS_LOCKED = 0
STATUS_ACTIVE = 1
def self.workflow_str(workflow)
case workflow
when STATE_WAITING_FOR_APPROVAL
l(:title_waiting_for_approval)
when STATE_APPROVED
l(:title_approved)
when STATE_ASSIGNED
l(:title_assigned)
when STATE_REJECTED
l(:title_rejected)
when DmsfWorkflow::STATE_OBSOLETE
l(:title_obsolete)
end
end
def participiants
users = Array.new
dmsf_workflow_steps.each do |step|

View File

@ -23,8 +23,8 @@
%>
<div class="box tabular">
<strong><%= l(:heading_new_revision) %> <a href="#" id="newRevisionFormContentToggle">[-]</a></strong>
<div id="newRevisionFormContent">
<strong><%= l(:heading_new_revision) %> <a href="#" id="new_revision_form_content_toggle">[+]</a></strong>
<div id="new_revision_form_content">
<% if @file.locked_for_user? %>
<p class="warning"><%= l(:info_file_locked) %></p>
<% else %>

View File

@ -79,21 +79,25 @@
<div class="dmsf_revision_box dataTables_wrapper">
<div class="fg-toolbar ui-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix">
<div class="dataTables_lenght">
<div id="dmsf_tag" class="dmsf_controls">
<%= link_to_function image_tag('group.png'),
"$('#revision_access-#{revision.id}').toggle()",
title: l(:title_download_entries) %>
<%= link_to image_tag('download.png'),
view_dmsf_file_path(@file, download: revision),
title: l(:title_title_version_version_download, title: h(revision.title), version: revision.version) %>
<%= link_to image_tag('close_hl.png'),
obsolete_revision_path(revision),
data: { confirm: l(:text_are_you_sure) },
title: l(:title_obsolete_revision) if @file_manipulation_allowed && (revision.workflow == DmsfWorkflow::STATE_APPROVED) %>
<%= link_to image_tag('delete.png'),
delete_revision_path(revision),
data: { confirm: l(:text_are_you_sure) },
title: l(:title_delete_revision) if @file_delete_allowed && (@file.dmsf_file_revisions.visible.count > 1) %>
<div id="dmsf_tag" class="dmsf_controls contextual">
<%= actions_dropdown do %>
<%= link_to_function l(:title_download_entries),
"$('#revision_access-#{revision.id}').toggle()",
class: 'icon icon-group' %>
<%= link_to l(:title_download),
view_dmsf_file_path(@file, download: revision),
title: l(:title_title_version_version_download, title: h(revision.title), version: revision.version),
class: 'icon icon-download' %>
<%= link_to l(:title_obsolete_revision),
obsolete_revision_path(revision),
data: { confirm: l(:text_are_you_sure) },
class: 'icon icon-close' if @file_manipulation_allowed && (revision.workflow == DmsfWorkflow::STATE_APPROVED) %>
<%= link_to l(:button_delete),
delete_revision_path(revision),
data: { confirm: l(:text_are_you_sure) },
title: l(:title_delete_revision),
class: 'icon icon-del' if @file_delete_allowed && (@file.dmsf_file_revisions.visible.count > 1) %>
<% end %>
</div>
<i><%= l(:info_revision, rev: revision.id) %></i>
<%= (revision.source_revision.nil? ? l(:label_created) : l(:label_changed)).downcase %>
@ -199,14 +203,14 @@
}
$('#version_0').prop('disabled', true);
});
$('#newRevisionFormContentToggle').click(function() {
if($('#newRevisionFormContent').is(':visible')) {
$('#new_revision_form_content_toggle').click(function() {
if($('#new_revision_form_content').is(':visible')) {
$(this).text('[+]');
$('#newRevisionFormContent').hide();
$('#new_revision_form_content').hide();
}
else {
$(this).text('[-]');
$('#newRevisionFormContent').show();
$('#new_revision_form_content').show();
}
});
$('.dmsf_list').dataTable({
@ -218,12 +222,6 @@
}
});
<% end %>
<% if @revision.valid? && @file.valid? %>
<%= late_javascript_tag do %>
$('#newRevisionFormContentToggle').text('[+]');
$('#newRevisionFormContent').hide();
<% end %>
<% end %>
<% content_for :header_tags do %>
<%= stylesheet_link_tag 'jquery.dataTables/datatables.min.css', plugin: :redmine_dmsf %>

View File

@ -22,86 +22,83 @@
<h3 class="title"><%= l(:title_dmsf_workflow_log) %></h3>
<p>
<% if params[:dmsf_file_revision_id].present? %>
<% revision = DmsfFileRevision.find_by(id: params[:dmsf_file_revision_id]) %>
<% if revision %>
<div class="dmsf_log_header_box">
<div class="dmsf_log_header_left">
<%= label_tag 'workflow_name', "#{l(:link_workflow)} #{l(:field_name).downcase} " %>
<% if User.current.allowed_to?(:manage_workflows, @dmsf_workflow.project) %>
<%= link_to @dmsf_workflow.name, dmsf_workflow_path(@dmsf_workflow) %>
<% else %>
<%= @dmsf_workflow.name %>
<% end %>
</div>
<div>
<%= label_tag 'workflow_status', l(:field_status) %>
<%= revision.workflow_str false %>
</div>
</div>
<div class="tab-content" id="tab-content-members">
<table class="list">
<thead><tr>
<th></th>
<th><%= l(:label_dmsf_workflow_step) %></th>
<th><%= l(:label_user) %></th>
<th><%= l(:label_action) %></th>
<th><%= l(:link_workflow) %></th>
<th><%= l(:label_note) %></th>
<th><%= l(:label_date)%></th>
</tr></thead>
<tbody>
<tr id="step-0" class="even">
<% if revision %>
<div class="dmsf_log_header_box">
<div class="dmsf_log_header_left">
<%= label_tag 'workflow_name', "#{l(:link_workflow)} #{l(:field_name).downcase} " %>
<% if User.current.allowed_to?(:manage_workflows, @dmsf_workflow.project) %>
<%= link_to @dmsf_workflow.name, dmsf_workflow_path(@dmsf_workflow) %>
<% else %>
<%= @dmsf_workflow.name %>
<% end %>
</div>
<div>
<%= label_tag 'workflow_status', l(:field_status) %>
<%= revision.workflow_str false %>
</div>
</div>
<div class="tab-content" id="tab-content-members">
<table class="list">
<thead><tr>
<th></th>
<th><%= l(:label_dmsf_workflow_step) %></th>
<th><%= l(:label_user) %></th>
<th><%= l(:label_action) %></th>
<th><%= l(:link_workflow) %></th>
<th><%= l(:label_note) %></th>
<th><%= l(:label_date)%></th>
</tr></thead>
<tbody>
<tr id="step-0" class="even">
<td class="id"></td>
<td></td>
<td></td>
<td></td>
<td><%= DmsfWorkflowStepAction.workflow_str(0) %></td>
<td class="dmsf_note"></td>
<td></td>
</tr>
<tr id="step-1" class="odd">
<td class="id"></td>
<td></td>
<td></td>
<td></td>
<td><%= DmsfWorkflowStepAction.workflow_str(0) %></td>
<td class="dmsf_note"></td>
<td></td>
<td></td>
<td><%= link_to_user revision.dmsf_workflow_assigned_by_user if revision.dmsf_workflow_assigned_by_user %></td>
<td><%= DmsfWorkflowStepAction.action_str(DmsfWorkflowStepAction::ACTION_ASSIGN) %></td>
<td><%= DmsfWorkflowStepAction.workflow_str(DmsfWorkflowStepAction::ACTION_ASSIGN) %></td>
<td class="dmsf_note"></td>
<td><%= format_time(revision.dmsf_workflow_assigned_at) if revision.dmsf_workflow_assigned_at %></td>
</tr>
<tr id="step-2" class="even">
<td class="id"></td>
<td></td>
<td><%= link_to_user revision.dmsf_workflow_started_by_user if revision.dmsf_workflow_started_by_user %></td>
<td><%= DmsfWorkflowStepAction.action_str(DmsfWorkflowStepAction::ACTION_START) %></td>
<td><%= DmsfWorkflowStepAction.workflow_str(DmsfWorkflowStepAction::ACTION_START) if revision.dmsf_workflow_started_by_user %></td>
<td class="dmsf_note"></td>
<td><%= format_time(revision.dmsf_workflow_started_at) if revision.dmsf_workflow_started_at %></td>
</tr>
<% sql = "SELECT c.action, c.note, c.created_at, c.author_id, a.user_id, s.step, s.name FROM dmsf_workflow_step_actions c RIGHT JOIN dmsf_workflow_step_assignments a ON a.id = c.dmsf_workflow_step_assignment_id RIGHT JOIN dmsf_workflow_steps s ON s.id = a.dmsf_workflow_step_id WHERE a.dmsf_file_revision_id = #{revision.id} ORDER BY s.step, s.id, c.action DESC, c.created_at" %>
<% result = DmsfWorkflowStep.connection.exec_query sql %>
<% last_step = 0 %>
<% result.each_with_index do |row, i| %>
<tr id="step-<%= i + 3 %>">
<td class="id"><%= row['step'] unless row['step'] == last_step %></td>
<% last_step = row['step'] %>
<td class="name"><%= row['name'] %></td>
<td><%= link_to_user User.find_by(id: row['author_id'].present? ? row['author_id'] : row['user_id']) %></td>
<td><%= DmsfWorkflowStepAction.action_str(row['action']) %></td>
<td>
<% if (row['step'].to_i == @dmsf_workflow.dmsf_workflow_steps.last.step) && (revision.workflow == DmsfWorkflow::STATE_APPROVED) && (row['action'] != DmsfWorkflowStepAction::ACTION_DELEGATE) %>
<%= l(:title_approved) %>
<% else %>
<%= DmsfWorkflowStepAction.workflow_str(row['action']) %>
<% end %>
</td>
<td class="dmsf_note"><%= row['note'] %></td>
<td><%= format_time(row['created_at']) if row['created_at'].present? %></td>
</tr>
<tr id="step-1" class="odd">
<td class="id"></td>
<td></td>
<td><%= link_to_user revision.dmsf_workflow_assigned_by_user if revision.dmsf_workflow_assigned_by_user %></td>
<td><%= DmsfWorkflowStepAction.action_str(DmsfWorkflowStepAction::ACTION_ASSIGN) %></td>
<td><%= DmsfWorkflowStepAction.workflow_str(DmsfWorkflowStepAction::ACTION_ASSIGN) %></td>
<td class="dmsf_note"></td>
<td><%= format_time(revision.dmsf_workflow_assigned_at) if revision.dmsf_workflow_assigned_at %></td>
</tr>
<tr id="step-2" class="even">
<td class="id"></td>
<td></td>
<td><%= link_to_user revision.dmsf_workflow_started_by_user if revision.dmsf_workflow_started_by_user %></td>
<td><%= DmsfWorkflowStepAction.action_str(DmsfWorkflowStepAction::ACTION_START) %></td>
<td><%= DmsfWorkflowStepAction.workflow_str(DmsfWorkflowStepAction::ACTION_START) if revision.dmsf_workflow_started_by_user %></td>
<td class="dmsf_note"></td>
<td><%= format_time(revision.dmsf_workflow_started_at) if revision.dmsf_workflow_started_at %></td>
</tr>
<% sql = "SELECT c.action, c.note, c.created_at, c.author_id, a.user_id, s.step, s.name FROM dmsf_workflow_step_actions c RIGHT JOIN dmsf_workflow_step_assignments a ON a.id = c.dmsf_workflow_step_assignment_id RIGHT JOIN dmsf_workflow_steps s ON s.id = a.dmsf_workflow_step_id WHERE a.dmsf_file_revision_id = #{revision.id} ORDER BY s.step, s.id, c.action DESC, c.created_at" %>
<% result = DmsfWorkflowStep.connection.exec_query sql %>
<% last_step = 0 %>
<% result.each_with_index do |row, i| %>
<tr id="step-<%= i + 3 %>">
<td class="id"><%= row['step'] unless row['step'] == last_step %></td>
<% last_step = row['step'] %>
<td class="name"><%= row['name'] %></td>
<td><%= link_to_user User.find_by(id: row['author_id'].present? ? row['author_id'] : row['user_id']) %></td>
<td><%= DmsfWorkflowStepAction.action_str(row['action']) %></td>
<td>
<% if (row['step'].to_i == @dmsf_workflow.dmsf_workflow_steps.last.step) && (revision.workflow == DmsfWorkflow::STATE_APPROVED) && (row['action'] != DmsfWorkflowStepAction::ACTION_DELEGATE) %>
<%= l(:title_approved) %>
<% else %>
<%= DmsfWorkflowStepAction.workflow_str(row['action']) %>
<% end %>
</td>
<td class="dmsf_note"><%= row['note'] %></td>
<td><%= format_time(row['created_at']) if row['created_at'].present? %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% end %>
<% end %>
<% end %>
</tbody>
</table>
</div>
<% end %>
</p>

View File

@ -19,4 +19,4 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.%>
<%= render :partial => 'log', :locals => {:workflow => @dmsf_workflow} %>
<%= render partial: 'log', locals: { workflow: @dmsf_workflow, revision: @revision } %>

View File

@ -21,6 +21,6 @@
var modal = $('#ajax-modal');
modal.html('<%= escape_javascript(render :partial => 'log', :locals => {:workflow => @dmsf_workflow}) %>');
modal.html('<%= escape_javascript(render partial: 'log', locals: { workflow: @dmsf_workflow, revision: @revision }) %>');
showModal('ajax-modal', '90%');
modal.addClass('workflow-log');

View File

@ -196,6 +196,10 @@ table.display thead th div.DataTables_sort_wrapper span {
.dmsf_workflows.locked a { color: #aaa; }
/* DMSF revision box */
#new_revision_form_content {
display: none;
}
.dmsf_revision_box {
padding: 0 0 0 0;
margin-bottom: 10px;

View File

@ -36,61 +36,101 @@ module RedmineDmsf
when :id
case item.type
when 'file', 'file-link'
link_to h(value), dmsf_file_path(id: item.id)
if item.deleted && (item.deleted > 0)
super column, item, value
else
link_to h(value), dmsf_file_path(id: item.id)
end
when 'folder', 'folder-link'
if(item.id)
link_to h(value), edit_dmsf_path(id: item.project_id, folder_id: item.id)
if item.deleted && (item.deleted > 0)
super column, item, value
else
link_to h(value), edit_dmsf_path(id: item.project_id, folder_id: item.id)
end
else
link_to h(item.project_id), edit_root_dmsf_path(id: item.project_id)
if item.deleted && (item.deleted > 0)
super column, item, item.project_id
else
link_to h(item.project_id), edit_root_dmsf_path(id: item.project_id)
end
end
else
h(value)
end
when :author
link_to "#{item.firstname} #{item.lastname}", user_path(id: value)
if value
link_to "#{item.firstname} #{item.lastname}", user_path(id: value)
else
return super column, item, value
end
when :title
case item.type
when 'folder'
"<span class=\"dmsf_expander\" onclick=\"dmsfToggle('#{item.id}','#{item.id}span','#{escape_javascript(exp_folder_dmsf_path)}')\"></span>".html_safe +
link_to(h(value),
dmsf_folder_path(id: item.project_id, folder_id: item.id),
class: 'icon icon-folder',
title: h(value)) +
content_tag('div', item.filename, class: 'dmsf_filename', title: l(:title_filename_for_download))
if item.deleted && (item.deleted > 0)
tag = content_tag('span', value, class: 'icon icon-folder')
else
tag = "<span class=\"dmsf_expander\" onclick=\"dmsfToggle('#{item.id}','#{item.id}span','#{escape_javascript(exp_folder_dmsf_path)}')\"></span>".html_safe +
link_to(h(value),
dmsf_folder_path(id: item.project_id, folder_id: item.id),
class: 'icon icon-folder',
title: h(value))
end
tag + content_tag('div', item.filename, class: 'dmsf_filename', title: l(:title_filename_for_download))
when 'folder-link'
"<span class=\"dmsf_expander\"></span>".html_safe +
link_to(h(value),
dmsf_folder_path(id: item.project_id, folder_id: item.id),
class: 'icon icon-folder',
title: h(value)) +
content_tag('div', item.filename, class: 'dmsf_filename', title: l(:title_filename_for_download))
if item.deleted && (item.deleted > 0)
tag = content_tag('span', value, class: 'icon icon-folder')
else
tag = "<span class=\"dmsf_expander\"></span>".html_safe +
link_to(h(value),
dmsf_folder_path(id: item.project_id, folder_id: item.id),
class: 'icon icon-folder',
title: h(value))
end
tag + content_tag('div', item.filename, class: 'dmsf_filename', title: l(:label_target_folder))
when 'file', 'file-link'
file_view_url = url_for({ controller: :dmsf_files, action: 'view', id: item.id })
content_type = Redmine::MimeType.of(value)
content_type = 'application/octet-stream' if content_type.blank?
"<span class=\"dmsf_expander\"></span>".html_safe +
link_to(h(value),
file_view_url,
target: '_blank',
class: "icon icon-file #{DmsfHelper.filetype_css(item.filename)}",
title: h(value),
'data-downloadurl': "#{content_type}:#{h(value)}:#{file_view_url}") +
content_tag('div', item.filename, class: 'dmsf_filename', title: l(:title_filename_for_download))
if item.deleted && (item.deleted > 0)
tag = content_tag('span', value, class: "icon icon-file #{DmsfHelper.filetype_css(item.filename)}")
else
file_view_url = url_for({ controller: :dmsf_files, action: 'view', id: item.id })
content_type = Redmine::MimeType.of(value)
content_type = 'application/octet-stream' if content_type.blank?
tag = "<span class=\"dmsf_expander\"></span>".html_safe +
link_to(h(value),
file_view_url,
target: '_blank',
class: "icon icon-file #{DmsfHelper.filetype_css(item.filename)}",
title: h(value),
'data-downloadurl': "#{content_type}:#{h(value)}:#{file_view_url}")
end
tag + content_tag('div', item.filename, class: 'dmsf_filename', title: l(:title_filename_for_download))
when 'url-link'
"<span class=\"dmsf_expander\"></span>".html_safe +
link_to(h(value), item.filename, target: '_blank', class: 'icon icon-link') +
content_tag('div', item.filename, class: 'dmsf_filename', title: l(:title_filename_for_download))
if item.deleted && (item.deleted > 0)
tag = content_tag('span', value, class: 'icon icon-link')
else
tag = "<span class=\"dmsf_expander\"></span>".html_safe +
link_to(h(value), item.filename, target: '_blank', class: 'icon icon-link')
end
tag + content_tag('div', item.filename, class: 'dmsf_filename', title: l(:field_url))
else
h(value)
end
when :size
number_to_human_size(value)
when :workflow
if value && item.workflow_id
link_to h(DmsfWorkflowStepAction.workflow_str(value)),
log_dmsf_workflow_path(project_id: item.project_id, id: item.workflow_id,
dmsf_file_revision_id: item.revision_id),
remote: true
if value
if item.workflow_id && (!(item.deleted && (item.deleted > 0)))
if item.type == 'file'
url = log_dmsf_workflow_path(project_id: item.project_id, id: item.workflow_id, dmsf_file_id: item.id)
else
url = log_dmsf_workflow_path(project_id: item.project_id, id: item.workflow_id, dmsf_link_id: item.id)
end
link_to(h(DmsfWorkflow.workflow_str(value.to_i)), url, remote: true)
else
h(DmsfWorkflow.workflow_str(value.to_i))
end
else
super column, item, value
end
else
super column, item, value