files_versions_tab.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @copyright 2022 Carl Schwan <carl@carlschwan.eu>
  3. * @license AGPL-3.0-or-later
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. import Vue from 'vue'
  20. import { translate as t, translatePlural as n } from '@nextcloud/l10n'
  21. import VersionTab from './views/VersionTab.vue'
  22. import VTooltip from 'v-tooltip'
  23. Vue.prototype.t = t
  24. Vue.prototype.n = n
  25. Vue.use(VTooltip)
  26. // Init Sharing tab component
  27. const View = Vue.extend(VersionTab)
  28. let TabInstance = null
  29. window.addEventListener('DOMContentLoaded', function() {
  30. if (OCA.Files && OCA.Files.Sidebar) {
  31. OCA.Files.Sidebar.registerTab(new OCA.Files.Sidebar.Tab({
  32. id: 'version_vue',
  33. name: t('files_versions', 'Version'),
  34. icon: 'icon-history',
  35. async mount(el, fileInfo, context) {
  36. if (TabInstance) {
  37. TabInstance.$destroy()
  38. }
  39. TabInstance = new View({
  40. // Better integration with vue parent component
  41. parent: context,
  42. })
  43. // Only mount after we have all the info we need
  44. await TabInstance.update(fileInfo)
  45. TabInstance.$mount(el)
  46. },
  47. update(fileInfo) {
  48. TabInstance.update(fileInfo)
  49. },
  50. destroy() {
  51. TabInstance.$destroy()
  52. TabInstance = null
  53. },
  54. }))
  55. }
  56. })