Рефакторинг всего раздела
This commit is contained in:
1 parent
a375c1e47f
commit
241966bb89
8 files changed
+79
-42
No files matched your search
@@ -8,24 +8,24 @@
|
|||||||
<!-- Безопасность -->
|
<!-- Безопасность -->
|
||||||
<!-- {{ safetyData }} -->
|
<!-- {{ safetyData }} -->
|
||||||
<v-row class="bg-red">
|
<v-row class="bg-red">
|
||||||
<v-col cols="4" class="bg-orange" v-for="item in safetyData" :key="item.id">
|
<v-col>
|
||||||
<v-card
|
<v-card class="bg-orange" v-for="item in safetyData" :key="item.id">
|
||||||
width="500"
|
<v-card-title>{{ item.name }}</v-card-title>
|
||||||
:title="item.name_chapter">
|
<v-card-actions v-for="category in item.categories" :key="category.id">
|
||||||
<v-card-actions>
|
<v-btn>{{ category.name }}</v-btn>
|
||||||
<v-btn>{{ item.document_category }}</v-btn>
|
<v-btn :icon="showMore[category.id] ? 'mdi-chevron-up' : 'mdi-chevron-down'" @click="showMore[category.id] = !showMore[category.id]"></v-btn>
|
||||||
<v-btn :icon="showMore[item.id] ? 'mdi-chevron-up' : 'mdi-chevron-down'" @click="showMore[item.id] = !showMore[item.id]"></v-btn>
|
<v-expand-transition>
|
||||||
</v-card-actions>
|
<div v-show="showMore[category.id]">
|
||||||
<v-expand-transition>
|
<!-- <v-divider></v-divider> -->
|
||||||
<div v-show="showMore[item.id]">
|
<v-card-actions v-for="file in category.files" :key="file.id">
|
||||||
<v-divider></v-divider>
|
<v-card-text>{{ file.name }}</v-card-text>
|
||||||
<v-card-actions>
|
|
||||||
<v-card-text>Название документа</v-card-text>
|
|
||||||
<v-btn icon="mdi-eye" color="grey"></v-btn>
|
<v-btn icon="mdi-eye" color="grey"></v-btn>
|
||||||
<v-btn icon='mdi-cloud-download' color="grey"></v-btn>
|
<v-btn icon='mdi-cloud-download' color="grey"></v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
</div>
|
</div>
|
||||||
</v-expand-transition>
|
</v-expand-transition>
|
||||||
|
</v-card-actions>
|
||||||
|
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
@@ -36,23 +36,25 @@ import { ref, onBeforeMount } from 'vue';
|
|||||||
import { pagecounter } from '@/utils/universal_functions'
|
import { pagecounter } from '@/utils/universal_functions'
|
||||||
import { axiosApiInstance } from '@/utils/axios-api';
|
import { axiosApiInstance } from '@/utils/axios-api';
|
||||||
|
|
||||||
pagecounter()
|
pagecounter();
|
||||||
|
|
||||||
const safetyData = ref([])
|
const safetyData = ref([]);
|
||||||
const showMore = ref(true)
|
const showMore = ref(false);
|
||||||
|
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
axiosApiInstance.get(`api/safety/files/`).then(result => {
|
axiosApiInstance.get(`api/safety/files/`).then(result => {
|
||||||
safetyData.value = result.data
|
safetyData.value = result.data
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
console.log(safetyData.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
showMore.value = safetyData.value.reduce((acc, value) => {
|
showMore.value = safetyData.value.reduce((acc, value) => {
|
||||||
acc[value.id] = false
|
acc[value.id] = false
|
||||||
return acc
|
return acc
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style></style>
|
<style></style>
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
class="text-white text-center text-lg-h5 h-100"
|
|
||||||
align-content="center"
|
|
||||||
justify="center"
|
|
||||||
File renamed without changes.
@@ -1,3 +0,0 @@
|
|||||||
class="text-white text-center text-lg-h5 h-100"
|
|
||||||
align-content="center"
|
|
||||||
justify="center"
|
|
||||||
+4
-5
@@ -4,11 +4,10 @@ from .models import SafetyFile
|
|||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SafetyFileAdmin(admin.ModelAdmin):
|
class SafetyFileAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name_chapter', 'date_file', 'document_category', 'file_document')
|
list_display = ('name', 'chapter_id', 'category_id', 'sign_date')
|
||||||
list_editable = ('date_file', 'document_category')
|
list_editable = ('sign_date', 'category_id')
|
||||||
list_filter = ('name_chapter', 'date_file', 'document_category', 'file_document')
|
list_filter = ('name', 'sign_date', 'category_id',)
|
||||||
fields = ('name_chapter', 'date_file', 'document_category', 'file_document')
|
fields = ('name', 'url', 'chapter_id', 'category_id', 'sign_date')
|
||||||
|
|
||||||
admin.site.register(SafetyFile, SafetyFileAdmin)
|
admin.site.register(SafetyFile, SafetyFileAdmin)
|
||||||
+33
-12
@@ -1,22 +1,44 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
|
class EnumChoice(Enum):
|
||||||
|
@classmethod
|
||||||
|
def get_choices(cls):
|
||||||
|
return [(enum_.name, enum_.value) for enum_ in cls]
|
||||||
|
|
||||||
CATEGORY_DOCUMENT = (
|
class SafetyChapter(EnumChoice):
|
||||||
('Нормативные документы', 'Нормативные документы'),
|
fire_safety = "Пожарная безопасность"
|
||||||
('Инструкции', 'Инструкции'),
|
information_safety = "Информационная безопасность"
|
||||||
('Учебные материалы', 'Учебные материалы'),
|
occupational_safety = "Охрана труда"
|
||||||
)
|
access_mode = "Пропускной и внутриобъектовый режим"
|
||||||
|
civil_defense = "Гражданская оборона"
|
||||||
|
state_secrets = "Защита гостайны"
|
||||||
|
military_registration = "Мобилизационная подготовка и воинский учет"
|
||||||
|
|
||||||
|
class SafetyDocumentCategory(EnumChoice):
|
||||||
|
regulations = "Нормативные документы"
|
||||||
|
instructions = "Инструкции"
|
||||||
|
orders = "Приказы"
|
||||||
|
provisions = "Положения"
|
||||||
|
educational_materials = "Учебные материалы"
|
||||||
|
laws = "Законы"
|
||||||
|
decrees = "Указы"
|
||||||
|
resolutions = "Постановления"
|
||||||
|
thematic_materials = "Тематические материалы"
|
||||||
|
methodological_materials = "Методологические материалы"
|
||||||
|
|
||||||
|
|
||||||
# Общая модель для раздела "Безопасность"
|
# Общая модель для раздела "Безопасность"
|
||||||
class SafetyFile(models.Model):
|
class SafetyFile(models.Model):
|
||||||
name_chapter = models.CharField(verbose_name='Название модуля', max_length=255, blank=False, db_index=True)
|
name = models.CharField(verbose_name='Имя документа', max_length=255)
|
||||||
date_file = models.DateField(verbose_name='Дата документа')
|
url = models.FileField(verbose_name='Путь до файла',upload_to='safety')
|
||||||
|
chapter_id = models.CharField(verbose_name='Раздел', max_length=255, blank=False, db_index=True, choices=SafetyChapter.get_choices())
|
||||||
|
category_id = models.CharField(verbose_name='Категория документа', max_length=255, blank=False, db_index=True, choices=SafetyDocumentCategory.get_choices())
|
||||||
|
sign_date = models.DateField(verbose_name='Дата документа')
|
||||||
created_at = models.DateTimeField(verbose_name='Дата загрузки файла', auto_now_add=True)
|
created_at = models.DateTimeField(verbose_name='Дата загрузки файла', auto_now_add=True)
|
||||||
update_at = models.DateTimeField(verbose_name='Дата обновления файла', auto_now=True)
|
update_at = models.DateTimeField(verbose_name='Дата обновления файла', auto_now=True)
|
||||||
document_category = models.CharField(verbose_name='Категория документа', max_length=255, choices=CATEGORY_DOCUMENT, default='Нормативные документы', blank=False)
|
|
||||||
file_document = models.FileField(verbose_name='Имя документа', upload_to='safety')
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
@@ -24,5 +46,4 @@ class SafetyFile(models.Model):
|
|||||||
verbose_name_plural = 'Документы раздела безопасности'
|
verbose_name_plural = 'Документы раздела безопасности'
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.name_chapter)
|
return str(self.name)
|
||||||
|
|
||||||
@@ -2,6 +2,9 @@ from rest_framework import serializers
|
|||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
class SafetyFileSerializer(serializers.ModelSerializer):
|
class SafetyFileSerializer(serializers.ModelSerializer):
|
||||||
|
chapter_name = serializers.CharField(source='get_chapter_id_display')
|
||||||
|
category_name = serializers.CharField(source='get_category_id_display')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = SafetyFile
|
model = SafetyFile
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
+19
-1
@@ -1,3 +1,5 @@
|
|||||||
|
from itertools import groupby
|
||||||
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
@@ -10,5 +12,21 @@ class SafetyFileAPIView(APIView):
|
|||||||
|
|
||||||
all_file = SafetyFile.objects.all()
|
all_file = SafetyFile.objects.all()
|
||||||
serializer_for_file = SafetyFileSerializer(instance=all_file, many=True)
|
serializer_for_file = SafetyFileSerializer(instance=all_file, many=True)
|
||||||
|
|
||||||
|
data = []
|
||||||
|
|
||||||
return Response(serializer_for_file.data)
|
for (chapter_id, chapter_name), row in groupby(serializer_for_file.data, lambda x: (x['chapter_id'], x['chapter_name'])):
|
||||||
|
chapter = {
|
||||||
|
'id': chapter_id,
|
||||||
|
'name': chapter_name,
|
||||||
|
'categories': []
|
||||||
|
}
|
||||||
|
data.append(chapter)
|
||||||
|
for (category_id, category_name), files in groupby(row, lambda x: (x['category_id'], x['category_name'])):
|
||||||
|
chapter['categories'].append({
|
||||||
|
'id': category_id,
|
||||||
|
'name': category_name,
|
||||||
|
'files': [file for file in files]
|
||||||
|
})
|
||||||
|
|
||||||
|
return Response(data)
|
||||||
Reference in new issue
Block a user