index.coffee 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. document.head.insertAdjacentHTML('beforeend','<style type="text/tailwindcss">'+stylFns['app/pages/Admin/index.styl']+'</style>')
  2. PouchDB = require 'app/utils/pouch'
  3. # Иконки для меню (упрощенные компоненты)
  4. MenuIcons =
  5. SliderIcon:
  6. template: '<svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 8h16M4 16h16"></path></svg>'
  7. ProductsIcon:
  8. template: '<svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"></path></svg>'
  9. ClientsIcon:
  10. template: '<svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path></svg>'
  11. BlogIcon:
  12. template: '<svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path></svg>'
  13. RoutesIcon:
  14. template: '<svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"></path></svg>'
  15. SettingsIcon:
  16. template: '<svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"></path><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path></svg>'
  17. module.exports =
  18. name: 'AdminPanel'
  19. components: MenuIcons
  20. render: (new Function '_ctx', '_cache', renderFns['app/pages/Admin/index.pug'])()
  21. data: ->
  22. return {
  23. currentDomain: window.location.hostname
  24. mobileMenuOpen: false
  25. menuItems: [
  26. {
  27. id: 'slider'
  28. name: 'Слайдер'
  29. path: '/admin/slider'
  30. icon: 'SliderIcon'
  31. }
  32. {
  33. id: 'products'
  34. name: 'Товары'
  35. path: '/admin/products'
  36. icon: 'ProductsIcon'
  37. }
  38. {
  39. id: 'clients'
  40. name: 'Клиенты'
  41. path: '/admin/clients'
  42. icon: 'ClientsIcon'
  43. }
  44. {
  45. id: 'blog'
  46. name: 'Блог'
  47. path: '/admin/blog'
  48. icon: 'BlogIcon'
  49. }
  50. {
  51. id: 'routes'
  52. name: 'Маршруты'
  53. path: '/admin/routes'
  54. icon: 'RoutesIcon'
  55. }
  56. {
  57. id: 'settings'
  58. name: 'Настройки'
  59. path: '/admin/settings'
  60. icon: 'SettingsIcon'
  61. }
  62. ]
  63. }
  64. computed:
  65. currentRoute: ->
  66. @$route.path.split('/').pop() || 'settings'
  67. showMobileMenuButton: ->
  68. window.innerWidth < 1024
  69. methods:
  70. navigateTo: (path) ->
  71. @mobileMenuOpen = false
  72. @$router.push(path)
  73. toggleMobileMenu: ->
  74. @mobileMenuOpen = !@mobileMenuOpen
  75. getMenuItemClass: (item) ->
  76. baseClass = 'admin__nav-item'
  77. isActive = @currentRoute == item.id
  78. if isActive
  79. return "#{baseClass} admin__nav-item--active"
  80. else
  81. return "#{baseClass} admin__nav-item--inactive"
  82. getSidebarClass: ->
  83. if @mobileMenuOpen
  84. return 'admin__sidebar--visible'
  85. else
  86. return 'admin__sidebar--hidden'
  87. loadDomainSettings: ->
  88. PouchDB.getDocument("domain_settings:#{@currentDomain}")
  89. .then (settings) =>
  90. @domainSettings = settings
  91. .catch (error) =>
  92. debug.log 'Настройки домена не найдены, используются значения по умолчанию'
  93. @domainSettings = null
  94. handleResize: ->
  95. if window.innerWidth >= 1024
  96. @mobileMenuOpen = false
  97. mounted: ->
  98. @loadDomainSettings()
  99. window.addEventListener 'resize', @handleResize
  100. beforeUnmount: ->
  101. window.removeEventListener 'resize', @handleResize