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.

74 lines
2.0 KiB

  1. 'use strict'
  2. import $ from 'jquery'
  3. import Vue from 'vue'
  4. import _ from 'lodash'
  5. const rootUrl = '/'
  6. module.exports = (alerts, socket) => {
  7. if ($('#page-type-all').length) {
  8. let vueAllPages = new Vue({ // eslint-disable-line no-unused-vars
  9. el: '#page-type-all',
  10. data: {
  11. tree: []
  12. },
  13. methods: {
  14. fetch: function (basePath) {
  15. let self = this
  16. $('#notifload').addClass('active')
  17. Vue.nextTick(() => {
  18. socket.emit('treeFetch', { basePath }, (data) => {
  19. if (self.tree.length > 0) {
  20. let branch = _.last(self.tree)
  21. branch.hasChildren = true
  22. _.find(branch.pages, { _id: basePath }).isActive = true
  23. }
  24. self.tree.push({
  25. hasChildren: false,
  26. pages: data
  27. })
  28. $('#notifload').removeClass('active')
  29. })
  30. })
  31. },
  32. goto: function (entryPath) {
  33. window.location.assign(rootUrl + entryPath)
  34. },
  35. unfold: function (entryPath) {
  36. let self = this
  37. let lastIndex = 0
  38. _.forEach(self.tree, branch => {
  39. lastIndex++
  40. if (_.find(branch.pages, { _id: entryPath }) !== undefined) {
  41. return false
  42. }
  43. })
  44. self.tree = _.slice(self.tree, 0, lastIndex)
  45. let branch = _.last(self.tree)
  46. branch.hasChildren = false
  47. branch.pages.forEach(page => {
  48. page.isActive = false
  49. })
  50. },
  51. mainAction: function (page) {
  52. let self = this
  53. if (page.isActive) {
  54. self.unfold(page._id)
  55. } else if (page.isDirectory) {
  56. self.fetch(page._id)
  57. } else {
  58. self.goto(page._id)
  59. }
  60. }
  61. },
  62. mounted: function () {
  63. let basePath = window.location.pathname.slice(0, -4)
  64. if (basePath.length > 1) {
  65. basePath = basePath.slice(1)
  66. }
  67. this.fetch(basePath)
  68. }
  69. })
  70. }
  71. }