Ver Fonte

add desing

Gogs há 4 semanas atrás
pai
commit
d073a1255a
2 ficheiros alterados com 229 adições e 0 exclusões
  1. 144 0
      app/design/admin.coffee
  2. 85 0
      app/design/site.coffee

+ 144 - 0
app/design/admin.coffee

@@ -0,0 +1,144 @@
+module.exports = {
+  _id: '_design/admin',
+  version: '1.0.0',
+  appVersion: '1.0.0',
+  hash: 'admin_v1_0_0_' + Date.now(),
+  
+  views: {
+    # Слайды главной страницы
+    slides: {
+      map: ((doc) ->
+        if doc.type == 'hero_slide' && doc.active != false
+          emit(doc.order, {
+            _id: doc._id,
+            title: doc.title,
+            subtitle: doc.subtitle,
+            image: doc.image,
+            buttonText: doc.buttonText,
+            buttonLink: doc.buttonLink,
+            active: doc.active,
+            order: doc.order,
+            domains: doc.domains
+          })
+      ).toString()
+    },
+    
+    # Товары
+    products: {
+      map: ((doc) ->
+        if doc.type == 'product'
+          emit([doc.category, doc.createdAt], {
+            _id: doc._id,
+            name: doc.name,
+            price: doc.price,
+            oldPrice: doc.oldPrice,
+            active: doc.active,
+            sku: doc.sku,
+            category: doc.category,
+            domains: doc.domains,
+            createdAt: doc.createdAt
+          })
+      ).toString()
+    },
+    
+    # Товары по категориям
+    products_by_category: {
+      map: ((doc) ->
+        if doc.type == 'product' && doc.active != false
+          emit(doc.category, {
+            _id: doc._id,
+            name: doc.name,
+            price: doc.price,
+            oldPrice: doc.oldPrice,
+            sku: doc.sku,
+            image: doc.image
+          })
+      ).toString()
+    },
+    
+    # Категории
+    categories: {
+      map: ((doc) ->
+        if doc.type == 'category'
+          emit(doc.order, {
+            _id: doc._id,
+            name: doc.name,
+            slug: doc.slug,
+            parent: doc.parent,
+            order: doc.order,
+            active: doc.active
+          })
+      ).toString()
+    },
+    
+    # Статьи блога
+    blog_articles: {
+      map: ((doc) ->
+        if doc.type == 'blog_article' && doc.published != false
+          emit(doc.createdAt, {
+            _id: doc._id,
+            title: doc.title,
+            slug: doc.slug,
+            excerpt: doc.excerpt,
+            image: doc.image,
+            author: doc.author,
+            published: doc.published,
+            createdAt: doc.createdAt,
+            domains: doc.domains
+          })
+      ).toString()
+    },
+    
+    # Настройки доменов
+    domain_settings: {
+      map: ((doc) ->
+        if doc.type == 'domain_settings'
+          emit(doc.domain, {
+            _id: doc._id,
+            domain: doc.domain,
+            companyName: doc.companyName,
+            languages: doc.languages,
+            theme: doc.theme,
+            contacts: doc.contacts
+          })
+      ).toString()
+    },
+    
+    # Пользовательские маршруты
+    custom_routes: {
+      map: ((doc) ->
+        if doc.type == 'route'
+          emit(doc.path, {
+            _id: doc._id,
+            path: doc.path,
+            component: doc.component,
+            title: doc.title,
+            active: doc.active,
+            domains: doc.domains
+          })
+      ).toString()
+    }
+  },
+  
+  filters: {
+    # Фильтр по доменам
+    by_domain: ((doc, req) ->
+      if !doc.domains || doc.domains.length == 0
+        return true
+      
+      domain = req.query.domain
+      if domain && doc.domains.includes(domain)
+        return true
+      
+      return false
+    ).toString(),
+    
+    # Фильтр по типу документа
+    by_type: ((doc, req) ->
+      type = req.query.type
+      if type && doc.type == type
+        return true
+      return !type
+    ).toString()
+  }
+}

+ 85 - 0
app/design/site.coffee

@@ -0,0 +1,85 @@
+module.exports = {
+  _id: '_design/site',
+  version: '1.0.0', 
+  appVersion: '1.0.0',
+  hash: 'site_v1_0_0_' + Date.now(),
+  
+  views: {
+    # Активные товары для каталога
+    active_products: {
+      map: ((doc) ->
+        if doc.type == 'product' && doc.active == true
+          emit([doc.category, doc.name], {
+            _id: doc._id,
+            name: doc.name,
+            price: doc.price,
+            oldPrice: doc.oldPrice,
+            sku: doc.sku,
+            image: doc.image,
+            category: doc.category,
+            description: doc.description,
+            attributes: doc.attributes
+          })
+      ).toString()
+    },
+    
+    # Опубликованные статьи блога
+    published_articles: {
+      map: ((doc) ->
+        if doc.type == 'blog_article' && doc.published == true
+          emit([doc.createdAt], {
+            _id: doc._id,
+            title: doc.title,
+            slug: doc.slug,
+            excerpt: doc.excerpt,
+            image: doc.image,
+            author: doc.author,
+            createdAt: doc.createdAt,
+            content: doc.content
+          })
+      ).toString()
+    },
+    
+    # Активные слайды
+    active_slides: {
+      map: ((doc) ->
+        if doc.type == 'hero_slide' && doc.active == true
+          emit(doc.order, {
+            _id: doc._id,
+            title: doc.title,
+            subtitle: doc.subtitle,
+            image: doc.image,
+            buttonText: doc.buttonText,
+            buttonLink: doc.buttonLink
+          })
+      ).toString()
+    }
+  },
+  
+  validates_doc_update: ((newDoc, oldDoc, userCtx) ->
+    # Базовая валидация документов
+    
+    # Запрещаем изменение design документов
+    if newDoc._id && newDoc._id.startsWith('_design/')
+      if oldDoc  # existing document
+        throw { forbidden: 'Design documents can only be updated by admins' }
+    
+    # Валидация товаров
+    if newDoc.type == 'product'
+      if !newDoc.name
+        throw { forbidden: 'Product must have a name' }
+      if !newDoc.price || isNaN(parseFloat(newDoc.price))
+        throw { forbidden: 'Product must have a valid price' }
+      if !newDoc.sku
+        throw { forbidden: 'Product must have SKU' }
+    
+    # Валидация статей блога
+    if newDoc.type == 'blog_article'
+      if !newDoc.title
+        throw { forbidden: 'Blog article must have a title' }
+      if !newDoc.slug
+        throw { forbidden: 'Blog article must have a slug' }
+    
+    return true
+  ).toString()
+}