recentfilelist.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-FileCopyrightText: 2014-2016 ownCloud, Inc.
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. // HACK: this piece needs to be loaded AFTER the files app (for unit tests)
  7. window.addEventListener('DOMContentLoaded', function () {
  8. (function (OCA) {
  9. /**
  10. * @class OCA.Files.RecentFileList
  11. * @augments OCA.Files.RecentFileList
  12. *
  13. * @classdesc Recent file list.
  14. * Displays the list of recently modified files
  15. *
  16. * @param $el container element with existing markup for the .files-controls
  17. * and a table
  18. * @param [options] map of options, see other parameters
  19. */
  20. var RecentFileList = function ($el, options) {
  21. options.sorting = {
  22. mode: 'mtime',
  23. direction: 'desc'
  24. };
  25. this.initialize($el, options);
  26. this._allowSorting = false;
  27. };
  28. RecentFileList.prototype = _.extend({}, OCA.Files.FileList.prototype,
  29. /** @lends OCA.Files.RecentFileList.prototype */ {
  30. id: 'recent',
  31. appName: t('files', 'Recent'),
  32. _clientSideSort: true,
  33. _allowSelection: false,
  34. /**
  35. * @private
  36. */
  37. initialize: function () {
  38. OCA.Files.FileList.prototype.initialize.apply(this, arguments);
  39. if (this.initialized) {
  40. return;
  41. }
  42. OC.Plugins.attach('OCA.Files.RecentFileList', this);
  43. },
  44. updateEmptyContent: function () {
  45. var dir = this.getCurrentDirectory();
  46. if (dir === '/') {
  47. // root has special permissions
  48. this.$el.find('.emptyfilelist.emptycontent').toggleClass('hidden', !this.isEmpty);
  49. this.$el.find('.files-filestable thead th').toggleClass('hidden', this.isEmpty);
  50. }
  51. else {
  52. OCA.Files.FileList.prototype.updateEmptyContent.apply(this, arguments);
  53. }
  54. },
  55. getDirectoryPermissions: function () {
  56. return OC.PERMISSION_READ | OC.PERMISSION_DELETE;
  57. },
  58. updateStorageStatistics: function () {
  59. // no op because it doesn't have
  60. // storage info like free space / used space
  61. },
  62. reload: function () {
  63. this.showMask();
  64. if (this._reloadCall?.abort) {
  65. this._reloadCall.abort();
  66. }
  67. // there is only root
  68. this._setCurrentDir('/', false);
  69. this._reloadCall = $.ajax({
  70. url: OC.generateUrl('/apps/files/api/v1/recent'),
  71. type: 'GET',
  72. dataType: 'json'
  73. });
  74. var callBack = this.reloadCallback.bind(this);
  75. return this._reloadCall.then(callBack, callBack);
  76. },
  77. reloadCallback: function (result) {
  78. delete this._reloadCall;
  79. this.hideMask();
  80. if (result.files) {
  81. this.setFiles(result.files.sort(this._sortComparator));
  82. return true;
  83. }
  84. return false;
  85. }
  86. });
  87. OCA.Files.RecentFileList = RecentFileList;
  88. })(OCA);
  89. });