From c22b88802ebab47a158eb1764395c9790ecb1336 Mon Sep 17 00:00:00 2001 From: Laurent FABRE Date: Fri, 24 Aug 2018 10:09:39 +0900 Subject: [PATCH] Added macros to reference a file's version and last update date: Example: {{dmsfversion(123)}} -> "2.5" -> return version of file with id "123" {{dmsflastupdate(123)}} -> "2018-08-24 08:46" -> returns the file's last update date (formatted according to redmine settings) --- README.md | 8 +++++++- lib/redmine_dmsf/macros.rb | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0098e989..86d901dd 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,13 @@ Link to a document with id 17 with link text "File": `{{dmsf(17, File)}}` Link to the details of a document with id 17: `{{dmsfd(17)}}` -Link to the description of a document with id 17: `{{dmsfdesc(17)}}` +Link to the details of a document with id 17 with link text "Details": `{{dmsfd(17, Details)}}` + +Text of the description of a document with id 17: `{{dmsfdesc(17)}}` + +Text referring to the version of a document with id 17: `{{dmsfversion(17)}}` + +Text referring to the last update date of a document with id 17: `{{dmsflastupdate(17)}}` Link to the preview of 5 lines from a document with id 17: `{{dmsft(17, 5)}}` diff --git a/lib/redmine_dmsf/macros.rb b/lib/redmine_dmsf/macros.rb index 31f373a3..5505c83c 100644 --- a/lib/redmine_dmsf/macros.rb +++ b/lib/redmine_dmsf/macros.rb @@ -87,8 +87,8 @@ Redmine::WikiFormatting::Macros.register do end end - # dmsfdesc - link to the document's description - desc "Wiki link to DMSF document description:\n\n" + + # dmsfdesc - text referring to the document's description + desc "Text referring to DMSF document description:\n\n" + "{{dmsfdesc(document_id)}}\n\n" + "_document_id_ can be found in the document's details." macro :dmsfdesc do |obj, args| @@ -101,6 +101,34 @@ Redmine::WikiFormatting::Macros.register do end end + # dmsfversion - text referring to the document's version + desc "Text referring to DMSF document version:\n\n" + + "{{dmsfversion(document_id)}}\n\n" + + "_document_id_ can be found in the document's details." + macro :dmsfversion 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.version) + else + raise l(:notice_not_authorized) + end + end + + # dmsflastupdate - text referring to the document's last update date + desc "Text referring to DMSF document last update date:\n\n" + + "{{dmsflastupdate(document_id)}}\n\n" + + "_document_id_ can be found in the document's details." + macro :dmsflastupdate 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(format_time(file.last_revision.updated_at)) + else + raise l(:notice_not_authorized) + end + end + # dmsft - link to the document's content preview desc "Wiki link to DMSF document's content preview:\n\n" + "{{dmsft(file_id)}}\n\n" + @@ -203,4 +231,4 @@ Redmine::WikiFormatting::Macros.register do end end -end \ No newline at end of file +end