A new macro for a document's approval workflows status added

This commit is contained in:
Karel Picman 2016-03-04 10:17:47 +01:00
parent 35b35f3132
commit de8da43bc8
4 changed files with 206 additions and 154 deletions

View File

@ -101,16 +101,16 @@ Search will now automatically search DMSF content when a Redmine search is perfo
###Linking DMSF files from Wiki entries: ###Linking DMSF files from Wiki entries:
####Link to a file with id 17: ####Link to a document with id 17:
`{{dmsf(17)}}` `{{dmsf(17)}}`
####Link to a file with id 17 with link text "File" ####Link to a document with id 17 with link text "File"
`{{dmsf(17, File)}}` `{{dmsf(17, File)}}`
####Link to the description of a file with id 17 ####Link to the description of a document with id 17
`{{dmsfd(17)}}` `{{dmsfd(17)}}`
####Link to the preview of the first 5 lines from a file with id 17 ####Link to the preview of 5 lines from a document with id 17
`{{dmsft(17, 5)}}` `{{dmsft(17, 5)}}`
####An inline picture of the file with id 8; it must be an image file such as JPEG, PNG,... ####An inline picture of the file with id 8; it must be an image file such as JPEG, PNG,...
@ -137,8 +137,11 @@ Search will now automatically search DMSF content when a Redmine search is perfo
####A thumbnail with custom size ####A thumbnail with custom size
`{{dmsftn(8, size=300)}}` `{{dmsftn(8, size=300)}}`
####Approval workflow status of a document with id 8
`{{dmsfw(8)}}`
The DMSF file/revision id can be found in link for file/revision download from within Redmine.
The DMSF document/revision id can be found in document details.
###Linking DMSF folders from Wiki entries: ###Linking DMSF folders from Wiki entries:
@ -166,7 +169,13 @@ In the file <redmine_root>/public/help/<language>/wiki_syntax_detailed.html, aft
<li><strong>{{dmsff(5, Folder)}}</strong> (a link to the folder with id 5 with the link text "Folder")</li> <li><strong>{{dmsff(5, Folder)}}</strong> (a link to the folder with id 5 with the link text "Folder")</li>
<li><strong>{{dmsf_image(8)}}</strong> (an inline picture of the file with id 8; it must be an image file such as JPEG, PNG,...)</li> <li><strong>{{dmsf_image(8)}}</strong> (an inline picture of the file with id 8; it must be an image file such as JPEG, PNG,...)</li>
<li><strong>{{dmsf_image(8, size=300)}}</strong> (an inline picture with custom size)</li> <li><strong>{{dmsf_image(8, size=300)}}</strong> (an inline picture with custom size)</li>
<li><strong>{{dmsf_image(8, size=640x480)}}</strong> (an inline picture with custom size)</li> <li><strong>{{dmsf_image(8, size=640x480)}}</strong> (an inline picture with custom size)</li>
<li><strong>{{dmsf_image(8, size=50%)}}</strong> (an inline picture with custom size)</li>
<li><strong>{{dmsf_image(8, height=300)}}</strong> (an inline picture with custom size)</li>
<li><strong>{{dmsf_image(8, width=300)}}</strong> (an inline picture with custom size)</li>
<li><strong>{{dmsftn(8)}}</strong> (a thumbnail with height of 200px)</li>
<li><strong>{{dmsftn(8, size=300)}}</strong> (a thumbnail with custom size)</li>
<li><strong>{{dmsfw(8)}}</strong> (approval workflow status of a document with id 8)</li>
</ul> </ul>
The DMSF file/revision id can be found in the link for file/revision download from within Redmine.<br /> The DMSF file/revision id can be found in the link for file/revision download from within Redmine.<br />
The DMSF folder id can be found in the link when opening folders within Redmine. The DMSF folder id can be found in the link when opening folders within Redmine.

150
init.rb
View File

@ -96,153 +96,7 @@ Redmine::Plugin.register :redmine_dmsf do
menu.push :approvalworkflows, menu.push :approvalworkflows,
{:controller => 'dmsf_workflows', :action => 'index'}, {:controller => 'dmsf_workflows', :action => 'index'},
:caption => :label_dmsf_workflow_plural :caption => :label_dmsf_workflow_plural
end end
Redmine::WikiFormatting::Macros.register do
desc "Wiki link to DMSF file:\n\n" +
"{{dmsf(file_id [, title [, revision_id]])}}\n\n" +
"_file_id_ / _revision_id_ can be found in the link for file/revision download."
macro :dmsf do |obj, args|
raise ArgumentError if args.length < 1 # Requires file id
file = DmsfFile.visible.find args[0].strip
if args[2].blank?
revision = file.last_revision
else
revision = DmsfFileRevision.find(args[2])
if revision.file != file
raise ActiveRecord::RecordNotFound
end
end
if User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
file_view_url = url_for(:controller => :dmsf_files, :action => 'view', :id => file, :download => args[2])
return link_to(h(args[1] ? args[1] : file.title),
file_view_url,
:target => '_blank',
:title => l(:title_title_version_version_download, :title => h(file.title), :version => file.version),
'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{file_view_url}")
else
raise l(:notice_not_authorized)
end
end
desc "Wiki link to DMSF folder:\n\n" +
"{{dmsff(folder_id [, title])}}\n\n" +
"_folder_id_ may be missing. _folder_id_ can be found in the link for folder opening."
macro :dmsff do |obj, args|
if args.length < 1
return link_to l(:link_documents), dmsf_folder_url(@project)
else
folder = DmsfFolder.visible.find args[0].strip
if User.current && User.current.allowed_to?(:view_dmsf_folders, folder.project)
return link_to h(args[1] ? args[1] : folder.title),
dmsf_folder_url(folder.project, :folder_id => folder)
else
raise l(:notice_not_authorized)
end
end
end
desc "Wiki link to DMSF document description:\n\n" +
"{{dmsfd(file_id)}}\n\n" +
"_file_id_ can be found in the link for file/revision download."
macro :dmsfd do |obj, args|
raise ArgumentError if args.length < 1 # Requires file id
file = DmsfFile.visible.find args[0].strip
if User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
return textilizable(file.description)
else
raise l(:notice_not_authorized)
end
end
desc "Wiki link to DMSF document's content preview:\n\n" +
"{{dmsft(file_id)}}\n\n" +
"_file_id_ can be found in the link for file/revision download."
macro :dmsft do |obj, args|
raise ArgumentError if args.length < 2 # Requires file id and lines number
file = DmsfFile.visible.find args[0].strip
if User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
return file.preview(args[1].strip).gsub("\n", '<br/>').html_safe
else
raise l(:notice_not_authorized)
end
end
desc "Wiki DMSF image:\n\n" +
"{{dmsf_image(file_id)}}\n" +
"{{dmsf_image(file_id, size=300)}} -- with custom title and size\n" +
"{{dmsf_image(file_id, height=300)}} -- with custom title and height (auto width)\n" +
"{{dmsf_image(file_id, width=300)}} -- with custom title and width (auto height)\n" +
"{{dmsf_image(file_id, size=640x480)}}"
macro :dmsf_image do |obj, args|
args, options = extract_macro_options(args, :size, :width, :height, :title)
file_id = args.first
raise 'DMSF document ID required' unless file_id.present?
size = options[:size]
width = options[:width]
height = options[:height]
if file = DmsfFile.find_by_id(file_id)
unless User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
raise l(:notice_not_authorized)
end
raise 'Not supported image format' unless file.image?
url = url_for(:controller => :dmsf_files, :action => 'view', :id => file)
if size && size.include?('%')
image_tag(url, :alt => file.title, :width => size, :height => size)
elsif height
image_tag(url, :alt => file.title, :width => 'auto', :height => height)
elsif width
image_tag(url, :alt => file.title, :width => width, :height => 'auto')
else
image_tag(url, :alt => file.title, :size => size)
end
else
raise "Document ID #{file_id} not found"
end
end
desc "Wiki DMSF thumbnail:\n\n" +
"{{dmsftn(file_id)}}\n" +
"{{dmsftn(file_id, size=300)}} -- with custom title and size\n" +
"{{dmsftn(file_id, height=300)}} -- with custom title and height (auto width)\n" +
"{{dmsftn(file_id, width=300)}} -- with custom title and width (auto height)\n" +
"{{dmsftn(file_id, size=640x480)}}"
macro :dmsftn do |obj, args|
args, options = extract_macro_options(args, :size, :width, :height, :title)
file_id = args.first
raise 'DMSF document ID required' unless file_id.present?
size = options[:size]
width = options[:width]
height = options[:height]
if file = DmsfFile.find_by_id(file_id)
unless User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
raise l(:notice_not_authorized)
end
raise 'Not supported image format' unless file.image?
url = url_for(:controller => :dmsf_files, :action => 'view', :id => file)
file_view_url = url_for(:controller => :dmsf_files, :action => 'view', :id => file, :download => args[2])
if size && size.include?("%")
img = image_tag(url, :alt => file.title, :width => size, :height => size)
elsif size && size.include?("x")
img = image_tag(url, :alt => file.title, :size => size)
elsif height
img = image_tag(url, :alt => file.title, :width => 'auto', :height => height)
elsif width
img = image_tag(url, :alt => file.title, :width => width, :height => 'auto')
else
img = image_tag(url, :alt => file.title, :width => 'auto', :height => 200)
end
link_to(img,
file_view_url, :target => '_blank',
:title => l(:title_title_version_version_download, :title => h(file.title), :version => file.version),
'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{file_view_url}")
else
raise "Document ID #{file_id} not found"
end
end
end
# Rubyzip configuration # Rubyzip configuration
Zip.unicode_names = true Zip.unicode_names = true
@ -251,4 +105,4 @@ end
Redmine::Search.map do |search| Redmine::Search.map do |search|
search.register :dmsf_files search.register :dmsf_files
search.register :dmsf_folders search.register :dmsf_folders
end end

View File

@ -52,6 +52,9 @@ require 'redmine_dmsf/errors/dmsf_zip_max_file_error.rb'
require 'redmine_dmsf/hooks/view_projects_form_hook' require 'redmine_dmsf/hooks/view_projects_form_hook'
require 'redmine_dmsf/hooks/base_view_hooks' require 'redmine_dmsf/hooks/base_view_hooks'
# Macros
require 'redmine_dmsf/macros'
module RedmineDmsf module RedmineDmsf
end end

186
lib/redmine_dmsf/macros.rb Normal file
View File

@ -0,0 +1,186 @@
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-16 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.
Redmine::WikiFormatting::Macros.register do
# dmsf - link to a document
desc "Wiki link to DMSF file:\n\n" +
"{{dmsf(file_id [, title [, revision_id]])}}\n\n" +
"_file_id_ / _revision_id_ can be found in the link for file/revision download."
macro :dmsf do |obj, args|
raise ArgumentError if args.length < 1 # Requires file id
file = DmsfFile.visible.find args[0].strip
if args[2].blank?
revision = file.last_revision
else
revision = DmsfFileRevision.find(args[2])
if revision.file != file
raise ActiveRecord::RecordNotFound
end
end
if User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
file_view_url = url_for(:controller => :dmsf_files, :action => 'view', :id => file, :download => args[2])
return link_to(h(args[1] ? args[1] : file.title),
file_view_url,
:target => '_blank',
:title => l(:title_title_version_version_download, :title => h(file.title), :version => file.version),
'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{file_view_url}")
else
raise l(:notice_not_authorized)
end
end
# dmsff - link to a folder
desc "Wiki link to DMSF folder:\n\n" +
"{{dmsff(folder_id [, title])}}\n\n" +
"_folder_id_ may be missing. _folder_id_ can be found in the link for folder opening."
macro :dmsff do |obj, args|
if args.length < 1
return link_to l(:link_documents), dmsf_folder_url(@project)
else
folder = DmsfFolder.visible.find args[0].strip
if User.current && User.current.allowed_to?(:view_dmsf_folders, folder.project)
return link_to h(args[1] ? args[1] : folder.title),
dmsf_folder_url(folder.project, :folder_id => folder)
else
raise l(:notice_not_authorized)
end
end
end
# dmsfd - link to a document's description
desc "Wiki link to DMSF document description:\n\n" +
"{{dmsfd(file_id)}}\n\n" +
"_file_id_ can be found in the document's details."
macro :dmsfd do |obj, args|
raise ArgumentError if args.length < 1 # Requires file id
file = DmsfFile.visible.find args[0].strip
if User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
return textilizable(file.description)
else
raise l(:notice_not_authorized)
end
end
# dmsft - link to a document's content preview
desc "Wiki link to DMSF document's content preview:\n\n" +
"{{dmsft(file_id)}}\n\n" +
"_file_id_ can be found in the document's details."
macro :dmsft do |obj, args|
raise ArgumentError if args.length < 2 # Requires file id and lines number
file = DmsfFile.visible.find args[0].strip
if User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
return file.preview(args[1].strip).gsub("\n", '<br/>').html_safe
else
raise l(:notice_not_authorized)
end
end
# dmsf_image - link to an image
desc "Wiki DMSF image:\n\n" +
"{{dmsf_image(file_id)}}\n" +
"{{dmsf_image(file_id, size=300)}} -- with custom title and size\n" +
"{{dmsf_image(file_id, height=300)}} -- with custom title and height (auto width)\n" +
"{{dmsf_image(file_id, width=300)}} -- with custom title and width (auto height)\n" +
"{{dmsf_image(file_id, size=640x480)}}"
macro :dmsf_image do |obj, args|
args, options = extract_macro_options(args, :size, :width, :height, :title)
file_id = args.first
raise 'DMSF document ID required' unless file_id.present?
size = options[:size]
width = options[:width]
height = options[:height]
if file = DmsfFile.find_by_id(file_id)
unless User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
raise l(:notice_not_authorized)
end
raise 'Not supported image format' unless file.image?
url = url_for(:controller => :dmsf_files, :action => 'view', :id => file)
if size && size.include?('%')
image_tag(url, :alt => file.title, :width => size, :height => size)
elsif height
image_tag(url, :alt => file.title, :width => 'auto', :height => height)
elsif width
image_tag(url, :alt => file.title, :width => width, :height => 'auto')
else
image_tag(url, :alt => file.title, :size => size)
end
else
raise "Document ID #{file_id} not found"
end
end
# dmsftn - link to an image thumbnail
desc "Wiki DMSF thumbnail:\n\n" +
"{{dmsftn(file_id)}}\n" +
"{{dmsftn(file_id, size=300)}} -- with custom title and size\n" +
"{{dmsftn(file_id, height=300)}} -- with custom title and height (auto width)\n" +
"{{dmsftn(file_id, width=300)}} -- with custom title and width (auto height)\n" +
"{{dmsftn(file_id, size=640x480)}}"
macro :dmsftn do |obj, args|
args, options = extract_macro_options(args, :size, :width, :height, :title)
file_id = args.first
raise 'DMSF document ID required' unless file_id.present?
size = options[:size]
width = options[:width]
height = options[:height]
if file = DmsfFile.find_by_id(file_id)
unless User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
raise l(:notice_not_authorized)
end
raise 'Not supported image format' unless file.image?
url = url_for(:controller => :dmsf_files, :action => 'view', :id => file)
file_view_url = url_for(:controller => :dmsf_files, :action => 'view', :id => file, :download => args[2])
if size && size.include?("%")
img = image_tag(url, :alt => file.title, :width => size, :height => size)
elsif size && size.include?("x")
img = image_tag(url, :alt => file.title, :size => size)
elsif height
img = image_tag(url, :alt => file.title, :width => 'auto', :height => height)
elsif width
img = image_tag(url, :alt => file.title, :width => width, :height => 'auto')
else
img = image_tag(url, :alt => file.title, :width => 'auto', :height => 200)
end
link_to(img,
file_view_url, :target => '_blank',
:title => l(:title_title_version_version_download, :title => h(file.title), :version => file.version),
'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{file_view_url}")
else
raise "Document ID #{file_id} not found"
end
end
# dmsfw - link to a document's approval workflow status
desc "Wiki link to DMSF document's approval workflow status:\n\n" +
"{{dmsfw(file_id)}}\n\n" +
"_file_id_ can be found in the document's details."
macro :dmsfw do |obj, args|
raise ArgumentError if args.length < 1 # Requires file id
file = DmsfFile.visible.find args[0].strip
if User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
raise ActiveRecord::RecordNotFound unless file.last_revision
return file.last_revision.workflow_str(false)
else
raise l(:notice_not_authorized)
end
end
end