richtext_doc.vm 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #**
  2. * Render a complex document in the results list
  3. *#
  4. ## Load Mime-Type List and Mapping
  5. #parse('mime_type_lists.vm')
  6. ## Sets:
  7. ## * supportedMimeTypes, AKA supportedtypes
  8. ## * mimeExtensionsMap, AKA extMap
  9. ## Title
  10. #if($doc.getFieldValue('title'))
  11. #set($title = $esc.html($doc.getFirstValue('title')))
  12. #else
  13. #set($title = "["+$doc.getFieldValue('id')+"]")
  14. #end
  15. ## URL
  16. #if($doc.getFieldValue('url'))
  17. #set($url = $doc.getFieldValue('url'))
  18. #elseif($doc.getFieldValue('resourcename'))
  19. #set($url = "file:///$doc.getFieldValue('resourcename')")
  20. #else
  21. #set($url = "$doc.getFieldValue('id')")
  22. #end
  23. ## Sort out Mime-Type
  24. #set($ct = $list.get($doc.getFirstValue('content_type').split(";"),0))
  25. #set($filename = $doc.getFieldValue('resourcename'))
  26. #set($filetype = false)
  27. #set($filetype = $mimeExtensionsMap.get($ct))
  28. ## TODO: falling back to file extension is convenient,
  29. ## except when you don't have an icon for that extension
  30. ## example "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
  31. ## document with a .docx extension.
  32. ## It'd be nice to fall back to an "unknown" or the existing "file" type
  33. ## We sort of do this below, but only if the filename has no extension
  34. ## (anything after the last dot).
  35. #if(!$filetype)
  36. #set($filetype = $filename.substring($filename.lastIndexOf(".")).substring(1))
  37. #end
  38. ## #if(!$filetype)
  39. ## #set($filetype = "file")
  40. ## #end
  41. ## #if(!$supportedMimeTypes.contains($filetype))
  42. ## #set($filetype = "file")
  43. ## #end
  44. ## Row 1: Icon and Title and mlt link
  45. <div class="result-title">
  46. ## Icon
  47. ## Small file type icons from http://www.splitbrain.org/projects/file_icons (public domain)
  48. <img src="#{url_root}/img/filetypes/${filetype}.png" align="center">
  49. ## Title, hyperlinked
  50. <a href="${url}" target="_blank">
  51. <b>$title</b></a>
  52. ## Link for MLT / More Like This / Find Similar
  53. <span class="mlt">
  54. #if($params.getBool('mlt', false) == false)
  55. <a href="#lensNoQ&q=id:%22$docId%22&mlt=true">
  56. More Like This</a>
  57. #end
  58. </span>
  59. </div>
  60. ## Row 2?: ID / URL
  61. <div>
  62. Id: #field('id')
  63. </div>
  64. ## Resource Name
  65. <div>
  66. #if($doc.getFieldValue('resourcename'))
  67. Resource name: $filename
  68. #elseif($url)
  69. URL: $url
  70. #end
  71. #if($ct)
  72. ($ct)
  73. #end
  74. </div>
  75. ## Author
  76. #if($doc.getFieldValue('author'))
  77. <div>
  78. Author: #field('author')
  79. </div>
  80. #end
  81. ## Last_Modified Date
  82. #if($doc.getFieldValue('last_modified'))
  83. <div>
  84. last-modified:
  85. #field('last_modified')
  86. </div>
  87. #end
  88. ## Main content of doc
  89. <div class="result-body">
  90. #field('content')
  91. </div>
  92. ## Display Similar Documents / MLT = More Like This
  93. <div class="mlt">
  94. #set($mlt = $mltResults.get($docId))
  95. #set($mltOn = $params.getBool('mlt'))
  96. #if($mltOn == true)
  97. <div class="field-name">
  98. Similar Items
  99. </div>
  100. #end
  101. ## If has MLT enabled An Entries to show
  102. #if ($mltOn && $mlt && $mlt.size() > 0)
  103. <ul>
  104. #foreach($mltHit in $mlt)
  105. #set($mltId = $mltHit.getFieldValue('id'))
  106. <li>
  107. <div>
  108. <a href="#url_for_home?q=id:$mltId">
  109. $mltId</a>
  110. </div>
  111. <div>
  112. <span class="field-name">
  113. Title:
  114. </span>
  115. $mltHit.getFieldValue('title')
  116. </div>
  117. <div>
  118. <span class="field-name">
  119. Author:
  120. </span>
  121. $mltHit.getFieldValue('author')
  122. <span class="field-name">
  123. Description:
  124. </span>
  125. $mltHit.getFieldValue('description')
  126. </div>
  127. </li>
  128. #end ## end for each mltHit in $mlt
  129. </ul>
  130. ## Else MLT Enabled but no mlt results for this query
  131. #elseif($mltOn && $mlt.size() == 0)
  132. <div>No Similar Items Found</div>
  133. #end
  134. </div> ## div class=mlt
  135. #parse('debug.vm')