admin.coffee 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. module.exports = {
  2. _id: '_design/admin',
  3. version: '1.0.0',
  4. appVersion: '1.0.0',
  5. hash: 'admin_v1_0_0_' + Date.now(),
  6. views: {
  7. # Слайды главной страницы
  8. slides: {
  9. map: ((doc) ->
  10. if doc.type == 'hero_slide' && doc.active != false
  11. emit(doc.order, {
  12. _id: doc._id,
  13. title: doc.title,
  14. subtitle: doc.subtitle,
  15. image: doc.image,
  16. buttonText: doc.buttonText,
  17. buttonLink: doc.buttonLink,
  18. active: doc.active,
  19. order: doc.order,
  20. domains: doc.domains
  21. })
  22. ).toString()
  23. },
  24. # Товары
  25. products: {
  26. map: ((doc) ->
  27. if doc.type == 'product'
  28. emit([doc.category, doc.createdAt], {
  29. _id: doc._id,
  30. name: doc.name,
  31. price: doc.price,
  32. oldPrice: doc.oldPrice,
  33. active: doc.active,
  34. sku: doc.sku,
  35. category: doc.category,
  36. domains: doc.domains,
  37. createdAt: doc.createdAt
  38. })
  39. ).toString()
  40. },
  41. # Товары по категориям
  42. products_by_category: {
  43. map: ((doc) ->
  44. if doc.type == 'product' && doc.active != false
  45. emit(doc.category, {
  46. _id: doc._id,
  47. name: doc.name,
  48. price: doc.price,
  49. oldPrice: doc.oldPrice,
  50. sku: doc.sku,
  51. image: doc.image
  52. })
  53. ).toString()
  54. },
  55. # Категории
  56. categories: {
  57. map: ((doc) ->
  58. if doc.type == 'category'
  59. emit(doc.order, {
  60. _id: doc._id,
  61. name: doc.name,
  62. slug: doc.slug,
  63. parent: doc.parent,
  64. order: doc.order,
  65. active: doc.active
  66. })
  67. ).toString()
  68. },
  69. # Статьи блога
  70. blog_articles: {
  71. map: ((doc) ->
  72. if doc.type == 'blog_article' && doc.published != false
  73. emit(doc.createdAt, {
  74. _id: doc._id,
  75. title: doc.title,
  76. slug: doc.slug,
  77. excerpt: doc.excerpt,
  78. image: doc.image,
  79. author: doc.author,
  80. published: doc.published,
  81. createdAt: doc.createdAt,
  82. domains: doc.domains
  83. })
  84. ).toString()
  85. },
  86. # Настройки доменов
  87. domain_settings: {
  88. map: ((doc) ->
  89. if doc.type == 'domain_settings'
  90. emit(doc.domain, {
  91. _id: doc._id,
  92. domain: doc.domain,
  93. companyName: doc.companyName,
  94. languages: doc.languages,
  95. theme: doc.theme,
  96. contacts: doc.contacts
  97. })
  98. ).toString()
  99. },
  100. # Пользовательские маршруты
  101. custom_routes: {
  102. map: ((doc) ->
  103. if doc.type == 'route'
  104. emit(doc.path, {
  105. _id: doc._id,
  106. path: doc.path,
  107. component: doc.component,
  108. title: doc.title,
  109. active: doc.active,
  110. domains: doc.domains
  111. })
  112. ).toString()
  113. }
  114. },
  115. filters: {
  116. # Фильтр по доменам
  117. by_domain: ((doc, req) ->
  118. if !doc.domains || doc.domains.length == 0
  119. return true
  120. domain = req.query.domain
  121. if domain && doc.domains.includes(domain)
  122. return true
  123. return false
  124. ).toString(),
  125. # Фильтр по типу документа
  126. by_type: ((doc, req) ->
  127. type = req.query.type
  128. if type && doc.type == type
  129. return true
  130. return !type
  131. ).toString()
  132. }
  133. }