| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408 |
- # Design документ для универсальной CMS
- design_documents =
- # Design документ для блог постов
- blog_posts:
- version: "1.2"
- views:
- # Все опубликованные блог посты
- published:
- map: ((doc) ->
- if doc.type is 'blog_post' and doc.status is 'published'
- emit(doc.created_at, doc)).toString()
-
- # Блог посты по домену и языку
- by_domain_language:
- map: ((doc) ->
- if doc.type is 'blog_post' and doc.status is 'published' and doc.domain and doc.language
- for domain in doc.domain
- for lang in doc.language
- emit([domain, lang, doc.created_at], doc)).toString()
-
- # Избранные блог посты
- featured:
- map: ((doc) ->
- if doc.type is 'blog_post' and doc.status is 'published' and doc.featured
- emit(doc.created_at, doc)).toString()
-
- # Блог посты по категории
- by_category:
- map: ((doc) ->
- if doc.type is 'blog_post' and doc.status is 'published' and doc.category_id
- emit([doc.category_id, doc.created_at], doc)).toString()
-
- # Блог посты по тегам
- by_tags:
- map: ((doc) ->
- if doc.type is 'blog_post' and doc.status is 'published' and doc.tags
- for tag_array, lang_index in doc.tags
- for tag in tag_array
- emit([tag, doc.created_at], doc)).toString()
- # Design документ для страниц (page)
- pages:
- version: "1.1"
- views:
- # Все опубликованные страницы
- published:
- map: ((doc) ->
- if doc.type is 'page' and doc.status is 'published'
- emit(doc.order || 0, doc)).toString()
-
- # Страницы по домену и языку
- by_domain_language:
- map: ((doc) ->
- if doc.type is 'page' and doc.status is 'published' and doc.domain and doc.language
- for domain in doc.domain
- for lang in doc.language
- emit([domain, lang, doc.order || 0], doc)).toString()
-
- # Страницы по пути (для меню и навигации)
- by_path:
- map: ((doc) ->
- if doc.type is 'page' and doc.status is 'published' and doc.category_path
- for path_segment in doc.category_path
- emit([path_segment, doc.order || 0], doc)).toString()
-
- # Страницы по родительскому ID (для иерархии)
- by_parent:
- map: ((doc) ->
- if doc.type is 'page' and doc.status is 'published'
- parent_id = doc.parent_id || 'root'
- emit([parent_id, doc.order || 0], doc)).toString()
-
- # Защищенные страницы (требующие авторизации)
- protected:
- map: ((doc) ->
- if doc.type is 'page' and doc.status is 'published' and doc.protected
- emit(doc.order || 0, doc)).toString()
-
- # Страницы для карты сайта
- sitemap:
- map: ((doc) ->
- if doc.type is 'page' and doc.status is 'published' and doc.show_in_sitemap != false
- emit(doc.order || 0, doc)).toString()
- # Design документ для событий (events)
- events:
- version: "1.2"
- views:
- # Все опубликованные события
- published:
- map: ((doc) ->
- if doc.type is 'event' and doc.status is 'published'
- emit(doc.event_data?.event_date || doc.created_at, doc)).toString()
-
- # События по домену и языку
- by_domain_language:
- map: ((doc) ->
- if doc.type is 'event' and doc.status is 'published' and doc.domain and doc.language
- for domain in doc.domain
- for lang in doc.language
- emit([domain, lang, doc.event_data?.event_date || doc.created_at], doc)).toString()
-
- # Предстоящие события
- upcoming:
- map: ((doc) ->
- if doc.type is 'event' and doc.status is 'published' and doc.event_data
- event_date = doc.event_data.event_date
- if event_date and new Date(event_date) > new Date()
- emit(event_date, doc)).toString()
-
- # Прошедшие события
- past:
- map: ((doc) ->
- if doc.type is 'event' and doc.status is 'published' and doc.event_data
- event_date = doc.event_data.event_date
- if event_date and new Date(event_date) <= new Date()
- emit(event_date, doc)).toString()
-
- # События по статусу
- by_status:
- map: ((doc) ->
- if doc.type is 'event' and doc.status is 'published' and doc.event_data
- status = doc.event_data.status || 'upcoming'
- emit([status, doc.event_data?.event_date || doc.created_at], doc)).toString()
-
- # Избранные события
- featured:
- map: ((doc) ->
- if doc.type is 'event' and doc.status is 'published' and doc.featured
- emit(doc.event_data?.event_date || doc.created_at, doc)).toString()
-
- # События по категории
- by_category:
- map: ((doc) ->
- if doc.type is 'event' and doc.status is 'published' and doc.category_id
- emit([doc.category_id, doc.event_data?.event_date || doc.created_at], doc)).toString()
-
- # События по местоположению
- by_location:
- map: ((doc) ->
- if doc.type is 'event' and doc.status is 'published' and doc.event_data?.location
- for location_array, lang_index in doc.event_data.location
- for location in location_array
- emit([location, doc.event_data?.event_date || doc.created_at], doc)).toString()
- # Design документ для товаров (products)
- products:
- version: "1.1"
- views:
- # Все опубликованные товары
- published:
- map: ((doc) ->
- if doc.type is 'product' and doc.status is 'published'
- emit(doc.created_at, doc)).toString()
-
- # Товары по домену и языку
- by_domain_language:
- map: ((doc) ->
- if doc.type is 'product' and doc.status is 'published' and doc.domain and doc.language
- for domain in doc.domain
- for lang in doc.language
- emit([domain, lang, doc.created_at], doc)).toString()
-
- # Товары по статусу наличия
- by_availability:
- map: ((doc) ->
- if doc.type is 'product' and doc.status is 'published' and doc.product_data
- status = doc.product_data.status || 'available'
- emit([status, doc.created_at], doc)).toString()
-
- # Избранные товары
- featured:
- map: ((doc) ->
- if doc.type is 'product' and doc.status is 'published' and doc.featured
- emit(doc.created_at, doc)).toString()
-
- # Товары по категории
- by_category:
- map: ((doc) ->
- if doc.type is 'product' and doc.status is 'published' and doc.category_id
- emit([doc.category_id, doc.created_at], doc)).toString()
-
- # Товары по цене
- by_price:
- map: ((doc) ->
- if doc.type is 'product' and doc.status is 'published' and doc.product_data?.price
- price = doc.product_data.price[0] || 0
- emit(price, doc)).toString()
- # Design документ для слайдеров (slides)
- slides:
- version: "1.1"
- views:
- # Все активные слайды
- active:
- map: ((doc) ->
- if doc.type is 'slide' and doc.status is 'published' and doc.slide_data?.active != false
- current_date = new Date().toISOString()
- start_date = doc.slide_data.start_date || '2000-01-01'
- end_date = doc.slide_data.end_date || '2100-01-01'
- if start_date <= current_date <= end_date
- emit(doc.slide_data?.order || 0, doc)).toString()
-
- # Слайды по домену и языку
- by_domain_language:
- map: ((doc) ->
- if doc.type is 'slide' and doc.status is 'published' and doc.slide_data?.active != false and doc.domain and doc.language
- current_date = new Date().toISOString()
- start_date = doc.slide_data.start_date || '2000-01-01'
- end_date = doc.slide_data.end_date || '2100-01-01'
- if start_date <= current_date <= end_date
- for domain in doc.domain
- for lang in doc.language
- emit([domain, lang, doc.slide_data?.order || 0], doc)).toString()
-
- # Слайды по порядку отображения
- by_order:
- map: ((doc) ->
- if doc.type is 'slide' and doc.status is 'published' and doc.slide_data?.active != false
- current_date = new Date().toISOString()
- start_date = doc.slide_data.start_date || '2000-01-01'
- end_date = doc.slide_data.end_date || '2100-01-01'
- if start_date <= current_date <= end_date
- emit(doc.slide_data.order || 0, doc)).toString()
- # Design документ для категорий
- categories:
- version: "1.1"
- views:
- # Все активные категории
- active:
- map: ((doc) ->
- if doc.type is 'category' and doc.active != false
- emit(doc.level || 0, doc)).toString()
-
- # Категории по домену и языку
- by_domain_language:
- map: ((doc) ->
- if doc.type is 'category' and doc.active != false and doc.domain and doc.language
- for domain in doc.domain
- for lang in doc.language
- emit([domain, lang, doc.level || 0], doc)).toString()
-
- # Категории по родительскому ID
- by_parent:
- map: ((doc) ->
- if doc.type is 'category' and doc.active != false
- parent_id = doc.parent_id || 'root'
- emit([parent_id, doc.order || 0], doc)).toString()
-
- # Категории для меню
- menu:
- map: ((doc) ->
- if doc.type is 'category' and doc.active != false and doc.show_in_menu != false
- emit([doc.level || 0, doc.menu_order || 0], doc)).toString()
-
- # Избранные категории
- featured:
- map: ((doc) ->
- if doc.type is 'category' and doc.active != false and doc.featured
- emit(doc.level || 0, doc)).toString()
- # Design документ для настроек доменов
- domain_settings:
- version: "1.1"
- views:
- # Все активные настройки доменов
- active:
- map: ((doc) ->
- if doc.type is 'domain_settings' and doc.active != false
- emit(doc.domain, doc)).toString()
-
- # Настройки по приоритету
- by_priority:
- map: ((doc) ->
- if doc.type is 'domain_settings' and doc.active != false
- emit(doc.priority || 0, doc)).toString()
- # Design документ для пользователей
- users:
- version: "1.1"
- views:
- # Все активные пользователи
- active:
- map: ((doc) ->
- if doc.type is 'user' and doc.active != false
- emit(doc.email, doc)).toString()
-
- # Пользователи по роли
- by_role:
- map: ((doc) ->
- if doc.type is 'user' and doc.active != false
- emit(doc.role, doc)).toString()
-
- # Пользователи по домену доступа
- by_domain_access:
- map: ((doc) ->
- if doc.type is 'user' and doc.active != false and doc.domains_access
- for domain in doc.domains_access
- emit([domain, doc.email], doc)).toString()
- # Design документ для заказов
- orders:
- version: "1.1"
- views:
- # Все заказы
- all:
- map: ((doc) ->
- if doc.type is 'order'
- emit(doc.created_at, doc)).toString()
-
- # Заказы по статусу
- by_status:
- map: ((doc) ->
- if doc.type is 'order'
- emit([doc.status, doc.created_at], doc)).toString()
-
- # Заказы по пользователю
- by_user:
- map: ((doc) ->
- if doc.type is 'order' and doc.user_id
- emit([doc.user_id, doc.created_at], doc)).toString()
-
- # Заказы по домену
- by_domain:
- map: ((doc) ->
- if doc.type is 'order' and doc.domain
- emit([doc.domain, doc.created_at], doc)).toString()
- # Design документ для аудита
- audit_logs:
- version: "1.1"
- views:
- # Все записи аудита
- all:
- map: ((doc) ->
- if doc.type is 'audit_log'
- emit(doc.created_at, doc)).toString()
-
- # Записи аудита по пользователю
- by_user:
- map: ((doc) ->
- if doc.type is 'audit_log' and doc.user_id
- emit([doc.user_id, doc.created_at], doc)).toString()
-
- # Записи аудита по типу ресурса
- by_resource_type:
- map: ((doc) ->
- if doc.type is 'audit_log' and doc.resource_type
- emit([doc.resource_type, doc.created_at], doc)).toString()
-
- # Записи аудита по действию
- by_action:
- map: ((doc) ->
- if doc.type is 'audit_log' and doc.action
- emit([doc.action, doc.created_at], doc)).toString()
- # Универсальные представления для всех типов документов
- universal:
- version: "1.2"
- views:
- # Документы по типу и домену
- by_type_domain:
- map: ((doc) ->
- if doc.type and doc.domain
- if Array.isArray(doc.domain)
- for domain in doc.domain
- emit([doc.type, domain, doc.created_at], doc)
- else
- emit([doc.type, doc.domain, doc.created_at], doc)).toString()
-
- # Документы по типу и статусу
- by_type_status:
- map: ((doc) ->
- if doc.type and doc.status
- emit([doc.type, doc.status, doc.created_at], doc)).toString()
-
- # Поиск по текстовым полям (для полнотекстового поиска)
- text_search:
- map: ((doc) ->
- if doc.title and Array.isArray(doc.title)
- for title in doc.title
- words = title.toLowerCase().split(/\s+/)
- for word in words when word.length > 2
- emit(word, {_id: doc._id, type: doc.type, title: doc.title})
-
- if doc.content and Array.isArray(doc.content)
- for content in doc.content
- words = content.toLowerCase().split(/\s+/)
- for word in words when word.length > 2
- emit(word, {_id: doc._id, type: doc.type, content: content})
-
- if doc.tags and Array.isArray(doc.tags)
- for tag_array in doc.tags
- for tag in tag_array
- emit(tag.toLowerCase(), {_id: doc._id, type: doc.type, tags: doc.tags})).toString()
-
- # Документы с поддержкой мультиязычности
- multilingual:
- map: ((doc) ->
- if doc.language and Array.isArray(doc.language) and doc.domain
- domain_array = if Array.isArray(doc.domain) then doc.domain else [doc.domain]
- for domain in domain_array
- for lang in doc.language
- emit([domain, lang, doc.type, doc.created_at], doc)).toString()
- # Экспорт design документов
- module.exports = design_documents
|