فهرست منبع

restart projeckt

Gogs 3 هفته پیش
والد
کامیت
344fe42a33
3فایلهای تغییر یافته به همراه81 افزوده شده و 57 حذف شده
  1. 7 2
      app/components/Admin/CategoryNode/index.pug
  2. 19 0
      app/components/Admin/CategoryNode/index.styl
  3. 55 55
      app/design/site.coffee

+ 7 - 2
app/components/Admin/CategoryNode/index.pug

@@ -12,9 +12,14 @@ div(
     ) {{ isExpanded ? '−' : '+' }}
     span(v-else class="category-node__spacer") •
     
-    span(class="category-node__name") {{ category.name }}
+    span(class="category-node__name") {{ category.name || 'Без названия' }}
     
-    span(class="category-node__badge") {{ category.children ? category.children.length : 0 }}
+    span(v-if="category.children" class="category-node__badge") {{ category.children.length }}
+    span(v-else class="category-node__badge") 0
+    
+    div(class="category-node__meta")
+      span(v-if="category._id" class="category-node__id") {{ category._id.substring(0, 8) }}
+      span(v-if="category.active === false" class="category-node__inactive") неактивна
     
     div(class="category-node__actions")
       ui-button(

+ 19 - 0
app/components/Admin/CategoryNode/index.styl

@@ -84,3 +84,22 @@
   
   .category-node__header
     flex-wrap: wrap
+
+
+.category-node__meta
+  display: flex
+  gap: var(--spacing-sm)
+  font-size: var(--font-size-xs)
+  opacity: 0.7
+
+.category-node__id
+  background: var(--color-secondary)
+  color: var(--color-white)
+  padding: 2px 6px
+  border-radius: 4px
+
+.category-node__inactive
+  background: var(--color-warning)
+  color: var(--color-dark)
+  padding: 2px 6px
+  border-radius: 4px

+ 55 - 55
app/design/site.coffee

@@ -161,65 +161,65 @@ class SiteDesignDocuments
     }
 
   getValidationDesignDoc: ->
-    {
-      _id: '_design/validation'
-      validate_doc_update: """
-        function(newDoc, oldDoc, userCtx, secObj) {
-          // Базовые проверки для всех документов
-          if (!newDoc.type) {
-            throw({forbidden: 'Document must have a type'});
-          }
-          
-          // Разрешенные типы документов
-          var validTypes = [
-            'product', 'category', 'order', 'user', 
-            'domain_settings', 'hero_slide', 'blog_article'
-          ];
-          
-          if (validTypes.indexOf(newDoc.type) === -1) {
-            throw({forbidden: 'Invalid document type: ' + newDoc.type});
-          }
-          
-          // Проверка товаров
-          if (newDoc.type === 'product') {
-            if (!newDoc.name || newDoc.name.trim() === '') {
-              throw({forbidden: 'Product must have a name'});
-            }
-            if (!newDoc.sku || newDoc.sku.trim() === '') {
-              throw({forbidden: 'Product must have SKU'});
-            }
-            if (typeof newDoc.price !== 'number' || newDoc.price < 0) {
-              throw({forbidden: 'Product must have valid price'});
-            }
-          }
-          
-          // Проверка категорий
-          if (newDoc.type === 'category') {
-            if (!newDoc.name || newDoc.name.trim() === '') {
-              throw({forbidden: 'Category must have a name'});
+      {
+        _id: '_design/validation'
+        validate_doc_update: """
+          function(newDoc, oldDoc, userCtx, secObj) {
+            // Функция проверки документов при сохранении 
+            
+            // Разрешаем удаление (помечание как удаленного)
+            if (newDoc._deleted || newDoc.deleted) {
+              // Проверяем права пользователя на удаление
+              if (userCtx.roles.indexOf('_admin') === -1) {
+                throw({forbidden: 'Only admins can delete documents'});
+              }
+              return; // Разрешаем удаление
+            }
+            
+            // Проверка типа документа
+            if (newDoc.type) {
+              var validTypes = [
+                'product', 'category', 'order', 'user', 
+                'domain_settings', 'hero_slide', 'blog_article'
+              ];
+              
+              if (validTypes.indexOf(newDoc.type) === -1) {
+                throw({forbidden: 'Invalid document type: ' + newDoc.type});
+              }
             }
-            if (!newDoc.slug || newDoc.slug.trim() === '') {
-              throw({forbidden: 'Category must have a slug'});
+            
+            // Проверка обязательных полей для товаров 
+            if (newDoc.type === 'product') {
+              if (!newDoc.name) {
+                throw({forbidden: 'Product must have a name'});
+              }
+              if (!newDoc.sku) {
+                throw({forbidden: 'Product must have SKU'});
+              }
+              if (typeof newDoc.price !== 'number' || newDoc.price < 0) {
+                throw({forbidden: 'Product must have valid price'});
+              }
             }
-          }
-          
-          // Проверка заказов
-          if (newDoc.type === 'order') {
-            if (!newDoc.userId) {
-              throw({forbidden: 'Order must have user ID'});
+            
+            // Проверка категорий
+            if (newDoc.type === 'category') {
+              if (!newDoc.name && !newDoc.deleted) {
+                throw({forbidden: 'Category must have a name'});
+              }
             }
-            if (!Array.isArray(newDoc.items) || newDoc.items.length === 0) {
-              throw({forbidden: 'Order must have items'});
+            
+            // Проверка неизменяемых полей
+            if (oldDoc) {
+              if (oldDoc.type !== newDoc.type) {
+                throw({forbidden: 'Document type cannot be changed'});
+              }
+              if (oldDoc.createdAt !== newDoc.createdAt) {
+                throw({forbidden: 'Creation date cannot be changed'});
+              }
             }
           }
-          
-          // Запрет изменения типа документа
-          if (oldDoc && oldDoc.type !== newDoc.type) {
-            throw({forbidden: 'Document type cannot be changed'});
-          }
-        }
-      """
-      language: "javascript"
-    }
+        """
+        language: "javascript"
+      }
 
 module.exports = new SiteDesignDocuments()