You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

search.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* eslint-disable */
  2. /*
  3. * Copyright (c) 2014
  4. *
  5. * This file is licensed under the Affero General Public License version 3
  6. * or later.
  7. *
  8. * See the COPYING-README file.
  9. *
  10. */
  11. (function(OC, OCA, $) {
  12. 'use strict'
  13. /**
  14. * Construct a new FileActions instance
  15. * @constructs Files
  16. */
  17. var Comment = function() {
  18. this.initialize()
  19. }
  20. Comment.prototype = {
  21. fileList: null,
  22. /**
  23. * Initialize the file search
  24. */
  25. initialize: function() {
  26. var self = this
  27. this.fileAppLoaded = function() {
  28. return !!OCA.Files && !!OCA.Files.App
  29. }
  30. function inFileList($row, result) {
  31. return false
  32. if (!self.fileAppLoaded()) {
  33. return false
  34. }
  35. var dir = self.fileList.getCurrentDirectory().replace(/\/+$/, '')
  36. var resultDir = OC.dirname(result.path)
  37. return dir === resultDir && self.fileList.inList(result.name)
  38. }
  39. function hideNoFilterResults() {
  40. var $nofilterresults = $('.nofilterresults')
  41. if (!$nofilterresults.hasClass('hidden')) {
  42. $nofilterresults.addClass('hidden')
  43. }
  44. }
  45. /**
  46. *
  47. * @param {jQuery} $row
  48. * @param {Object} result
  49. * @param {int} result.id
  50. * @param {string} result.comment
  51. * @param {string} result.authorId
  52. * @param {string} result.authorName
  53. * @param {string} result.link
  54. * @param {string} result.fileName
  55. * @param {string} result.path
  56. * @returns {*}
  57. */
  58. this.renderCommentResult = function($row, result) {
  59. if (inFileList($row, result)) {
  60. return null
  61. }
  62. hideNoFilterResults()
  63. /* render preview icon, show path beneath filename,
  64. show size and last modified date on the right */
  65. this.updateLegacyMimetype(result)
  66. var $pathDiv = $('<div>').addClass('path').text(result.path)
  67. var $avatar = $('<div>')
  68. $avatar.addClass('avatar')
  69. .css('display', 'inline-block')
  70. .css('vertical-align', 'middle')
  71. .css('margin', '0 5px 2px 3px')
  72. if (result.authorName) {
  73. $avatar.avatar(result.authorId, 21, undefined, false, undefined, result.authorName)
  74. } else {
  75. $avatar.avatar(result.authorId, 21)
  76. }
  77. $row.find('td.info div.name').after($pathDiv).text(result.comment).prepend($('<span>').addClass('path').css('margin-right', '5px').text(result.authorName)).prepend($avatar)
  78. $row.find('td.result a').attr('href', result.link)
  79. $row.find('td.icon')
  80. .css('background-image', 'url(' + OC.imagePath('core', 'actions/comment') + ')')
  81. .css('opacity', '.4')
  82. var dir = OC.dirname(result.path)
  83. // "result.path" does not include a leading "/", so "OC.dirname"
  84. // returns the path itself for files or folders in the root.
  85. if (dir === result.path) {
  86. dir = '/'
  87. }
  88. $row.find('td.info a').attr('href',
  89. OC.generateUrl('/apps/files/?dir={dir}&scrollto={scrollto}', { dir: dir, scrollto: result.fileName })
  90. )
  91. return $row
  92. }
  93. this.handleCommentClick = function($row, result, event) {
  94. if (self.fileAppLoaded() && self.fileList.id === 'files') {
  95. self.fileList.changeDirectory(OC.dirname(result.path))
  96. self.fileList.scrollTo(result.name)
  97. return false
  98. } else {
  99. return true
  100. }
  101. }
  102. this.updateLegacyMimetype = function(result) {
  103. // backward compatibility:
  104. if (!result.mime && result.mime_type) {
  105. result.mime = result.mime_type
  106. }
  107. }
  108. this.setFileList = function(fileList) {
  109. this.fileList = fileList
  110. }
  111. OC.Plugins.register('OCA.Search.Core', this)
  112. },
  113. attach: function(search) {
  114. search.setRenderer('comment', this.renderCommentResult.bind(this))
  115. search.setHandler('comment', this.handleCommentClick.bind(this))
  116. }
  117. }
  118. OCA.Search.comment = new Comment()
  119. })(OC, OCA, $)