52
This commit is contained in:
1 parent
631cecc8cd
commit
2aeb3ef513
8 files changed
+158
-105
No files matched your search
@@ -1,13 +1,16 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from .models import SafetyFile
|
from .models import SafetyFile, SafetyType, SafetyDocumentCategory
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
||||||
|
|
||||||
class SafetyFileAdmin(admin.ModelAdmin):
|
class SafetyFileAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name', 'chapter_id', 'category_id', 'sign_date', 'formainpage')
|
|
||||||
list_editable = ('sign_date', 'category_id', 'formainpage')
|
list_display = ('name', 'chapter', 'category', 'sign_date', 'formainpage')
|
||||||
list_filter = ('name', 'sign_date', 'category_id',)
|
list_editable = ('sign_date', 'category', 'formainpage')
|
||||||
fields = ('name', 'url', 'chapter_id', 'category_id', 'sign_date', 'formainpage')
|
list_filter = ('name', 'sign_date', 'category',)
|
||||||
|
fields = ('name', 'url', 'chapter', 'category', 'sign_date', 'formainpage')
|
||||||
admin.site.register(SafetyFile, SafetyFileAdmin)
|
|
||||||
|
admin.site.register(SafetyType)
|
||||||
|
admin.site.register(SafetyDocumentCategory)
|
||||||
|
admin.site.register(SafetyFile, SafetyFileAdmin)
|
||||||
+12
-28
@@ -1,42 +1,26 @@
|
|||||||
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):
|
class SafetyDocumentCategory(models.Model):
|
||||||
@classmethod
|
name = models.CharField(max_length=255)
|
||||||
def get_choices(cls):
|
|
||||||
return [(enum_.name, enum_.value) for enum_ in cls]
|
|
||||||
|
|
||||||
class SafetyChapter(EnumChoice):
|
def __str__(self):
|
||||||
fire_safety = "Пожарная безопасность"
|
return str(self.name)
|
||||||
information_safety = "Информационная безопасность"
|
|
||||||
occupational_safety = "Охрана труда"
|
|
||||||
access_mode = "Пропускной и внутриобъектовый режим"
|
|
||||||
civil_defense = "Гражданская оборона"
|
|
||||||
state_secrets = "Защита гостайны"
|
|
||||||
military_registration = "Мобилизационная подготовка и воинский учет"
|
|
||||||
|
|
||||||
class SafetyDocumentCategory(EnumChoice):
|
class SafetyType(models.Model):
|
||||||
regulations = "Нормативные документы"
|
name = models.CharField(max_length=255)
|
||||||
instructions = "Инструкции"
|
path = models.CharField(max_length=255, null=True)
|
||||||
orders = "Приказы"
|
|
||||||
provisions = "Положения"
|
def __str__(self):
|
||||||
educational_materials = "Учебные материалы"
|
return str(self.name)
|
||||||
laws = "Законы"
|
|
||||||
decrees = "Указы"
|
|
||||||
resolutions = "Постановления"
|
|
||||||
thematic_materials = "Тематические материалы"
|
|
||||||
methodological_materials = "Методологические материалы"
|
|
||||||
evacuation_plan = 'План эвакуации'
|
|
||||||
|
|
||||||
|
|
||||||
# Общая модель для раздела "Безопасность"
|
# Общая модель для раздела "Безопасность"
|
||||||
class SafetyFile(models.Model):
|
class SafetyFile(models.Model):
|
||||||
name = models.CharField(verbose_name='Имя документа', max_length=255)
|
name = models.CharField(verbose_name='Имя документа', max_length=255)
|
||||||
url = models.FileField(verbose_name='Путь до файла',upload_to='safety')
|
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())
|
chapter = models.ForeignKey('SafetyType', models.DO_NOTHING, null=True, verbose_name='Раздел', related_name="type_file")
|
||||||
category_id = models.CharField(verbose_name='Категория документа', max_length=255, blank=False, db_index=True, choices=SafetyDocumentCategory.get_choices())
|
category = models.ForeignKey('SafetyDocumentCategory', models.DO_NOTHING, null=True, verbose_name='Категория документа')
|
||||||
formainpage = models.BooleanField(default=False, verbose_name="Основная информация")
|
formainpage = models.BooleanField(default=False, verbose_name="Основная информация")
|
||||||
sign_date = models.DateField(verbose_name='Дата документа')
|
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)
|
||||||
|
|||||||
@@ -1,10 +1,43 @@
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from .models import *
|
from .models import *
|
||||||
|
from django.db.models import Count
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class OneFileSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = SafetyFile
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
|
||||||
|
class SafetyTypeSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = SafetyType
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
|
||||||
class SafetyFileSerializer(serializers.ModelSerializer):
|
class SafetyFileSerializer(serializers.ModelSerializer):
|
||||||
chapter_name = serializers.CharField(source='get_chapter_id_display')
|
# chapter_name = serializers.CharField(source='get_chapter_id_display')
|
||||||
category_name = serializers.CharField(source='get_category_id_display')
|
# category_name = serializers.CharField(source='get_category_id_display')
|
||||||
|
categories = serializers.SerializerMethodField('get_categories')
|
||||||
class Meta:
|
class Meta:
|
||||||
model = SafetyFile
|
model = SafetyType
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
def get_categories(self, obj):
|
||||||
|
|
||||||
|
files = obj.type_file.all().order_by('category__name')
|
||||||
|
categories = files.values("category","category__name").distinct()
|
||||||
|
for x in files:
|
||||||
|
for y in categories:
|
||||||
|
if 'files' not in y.keys():
|
||||||
|
y['files'] = []
|
||||||
|
if x.category.id == y['category']:
|
||||||
|
y['files'].append(OneFileSerializer(x).data)
|
||||||
|
|
||||||
|
return categories
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -4,6 +4,7 @@ from rest_framework.routers import DefaultRouter
|
|||||||
from .views import *
|
from .views import *
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
path('gettypes/', SafetyTypeAPIView.as_view(), name="SafetyTypeAPIView"),
|
||||||
path('files/', SafetyFileAPIView.as_view(), name='safety_files'),
|
path('files/', SafetyFileAPIView.as_view(), name='safety_files'),
|
||||||
path('responsibility/', SafetyResponsebilityAPIView.as_view(), name='responsibility'),
|
path('responsibility/', SafetyResponsebilityAPIView.as_view(), name='responsibility'),
|
||||||
path('committee_files/', CommitteeFilesAPIView.as_view(), name='committee_files')
|
path('committee_files/', CommitteeFilesAPIView.as_view(), name='committee_files')
|
||||||
|
|||||||
+10
-22
@@ -1,5 +1,6 @@
|
|||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
from django.db.models import Count
|
||||||
|
from rest_framework.generics import ListAPIView
|
||||||
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
|
||||||
@@ -9,30 +10,17 @@ from userauth.serializers import *
|
|||||||
from userauth.models import *
|
from userauth.models import *
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
class SafetyTypeAPIView(ListAPIView):
|
||||||
|
def get(self, request):
|
||||||
|
chapters = SafetyType.objects.annotate(Count("type_file")).filter(type_file__count__gt=0)
|
||||||
|
return Response(SafetyTypeSerializer(chapters, many=True).data)
|
||||||
|
|
||||||
class SafetyFileAPIView(APIView):
|
class SafetyFileAPIView(APIView):
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
|
|
||||||
chapters = self.request.query_params.get('chapter_id', 1)
|
chapters = self.request.query_params.get('chapter', "fire_safety")
|
||||||
all_file = SafetyFile.objects.filter(chapter_id=chapters).order_by('chapter_id', 'category_id').all()
|
safety_group = SafetyType.objects.get(path=chapters)
|
||||||
serializer_for_file = SafetyFileSerializer(instance=all_file, many=True)
|
return Response(SafetyFileSerializer(safety_group).data)
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
class SafetyResponsebilityAPIView(APIView):
|
class SafetyResponsebilityAPIView(APIView):
|
||||||
|
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ import { useTheme } from "vuetify";
|
|||||||
import AuthForm from '@/components/UI/Auth-form.vue'
|
import AuthForm from '@/components/UI/Auth-form.vue'
|
||||||
import OnlineUsers from '@/components/UI/fiousercard/onlineUsers.vue'
|
import OnlineUsers from '@/components/UI/fiousercard/onlineUsers.vue'
|
||||||
import CardLike from '@/components/cardLike.vue'
|
import CardLike from '@/components/cardLike.vue'
|
||||||
import { clearAxios } from '@/utils/axios-api'
|
import { axiosApiInstance, clearAxios } from '@/utils/axios-api'
|
||||||
|
|
||||||
import { baseURL } from '@/utils/axios-api'
|
import { baseURL } from '@/utils/axios-api'
|
||||||
import VcardUser from '@/components/UI/fiousercard/vcardUser.vue'
|
import VcardUser from '@/components/UI/fiousercard/vcardUser.vue'
|
||||||
@@ -378,7 +378,7 @@ export default {
|
|||||||
|
|
||||||
// ]
|
// ]
|
||||||
|
|
||||||
const navigations = [
|
const navigations = ref([
|
||||||
|
|
||||||
{
|
{
|
||||||
name: 'Структура',
|
name: 'Структура',
|
||||||
@@ -421,16 +421,6 @@ export default {
|
|||||||
ico: 'mdi-newspaper',
|
ico: 'mdi-newspaper',
|
||||||
path: "/news"
|
path: "/news"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'Безопасность',
|
|
||||||
ico: 'mdi-security',
|
|
||||||
submenu: [
|
|
||||||
{
|
|
||||||
name: 'Пожарная безопасность',
|
|
||||||
path: "/fire_safety"
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'О портале',
|
name: 'О портале',
|
||||||
ico: 'mdi-information-variant',
|
ico: 'mdi-information-variant',
|
||||||
@@ -453,8 +443,8 @@ export default {
|
|||||||
// ico: 'mdi-cake-variant',
|
// ico: 'mdi-cake-variant',
|
||||||
// path: "/fnshol"
|
// path: "/fnshol"
|
||||||
// }
|
// }
|
||||||
]
|
])
|
||||||
|
|
||||||
const imageSrc = computed(() => {
|
const imageSrc = computed(() => {
|
||||||
return new URL(`@/assets/FNS-logo-xs.png`, import.meta.url).href;
|
return new URL(`@/assets/FNS-logo-xs.png`, import.meta.url).href;
|
||||||
})
|
})
|
||||||
@@ -464,7 +454,26 @@ export default {
|
|||||||
// feedalert.value=true
|
// feedalert.value=true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getSafetyChapter = () => {
|
||||||
|
axiosApiInstance.get('api/safety/gettypes/').then(response => {
|
||||||
|
response.data.forEach(item => {
|
||||||
|
if(!item.path.startsWith('/')) {
|
||||||
|
item.path = '/' + item.path
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.data.length > 0) {
|
||||||
|
let safetyMenu = {
|
||||||
|
name: 'Безопасность',
|
||||||
|
ico: 'mdi-security',
|
||||||
|
submenu: response.data
|
||||||
|
}
|
||||||
|
navigations.value.splice(5, 0, safetyMenu)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
getSafetyChapter()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
theme,
|
theme,
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ const routes = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/:chapter_id',
|
path: '/:chapter',
|
||||||
component: () => import('@/views/safety/ChaptersSafety.vue'),
|
component: () => import('@/views/safety/ChaptersSafety.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: "Разделы безопасности",
|
title: "Разделы безопасности",
|
||||||
|
|||||||
@@ -22,28 +22,62 @@
|
|||||||
<v-window-item value="document" class="h-100">
|
<v-window-item value="document" class="h-100">
|
||||||
<v-row no-gutters class="gap h-100 ">
|
<v-row no-gutters class="gap h-100 ">
|
||||||
<v-col lg="6">
|
<v-col lg="6">
|
||||||
<v-card class="h-100 flex-column d-flex gap">
|
<v-card class="h-100 flex-column d-flex gap ">
|
||||||
<v-row class="ma-0 my-3 overflow-auto h-0 pb-1">
|
<v-row class="ma-0 my-3 overflow-auto h-0 pb-1">
|
||||||
<v-card v-for="item in safetyData" :key="item.id" class="overflow-y-auto flex-grow-1 flex-shrink-1 h-100">
|
|
||||||
<v-card-title>{{ item.name }}</v-card-title>
|
<v-card class="overflow-y-auto flex-grow-1 flex-shrink-1 h-100">
|
||||||
<v-container
|
|
||||||
v-for="category in item.categories"
|
<v-card-title>{{ safetyData.name }}</v-card-title>
|
||||||
:key="item.id + category.id"
|
<v-expansion-panels
|
||||||
:fluid="true"
|
|
||||||
|
flat
|
||||||
|
>
|
||||||
|
|
||||||
|
<v-expansion-panel
|
||||||
|
elevation=0
|
||||||
|
v-for="category in safetyData.categories"
|
||||||
|
:key="category.id"
|
||||||
|
|
||||||
|
|
||||||
class="py-0">
|
class="py-0">
|
||||||
<v-card-actions v-if="category.id != 'evacuation_plan'">
|
<v-expansion-panel-title class="font-weight-medium">{{ category.category__name }}</v-expansion-panel-title>
|
||||||
|
|
||||||
|
<v-expansion-panel-text>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div v-for="file in category.files" :key="file.id" class="overflow-y-auto d-flex justify-space-between">
|
||||||
|
<div
|
||||||
|
class="cursor-pointer"
|
||||||
|
@click="openPDF(file.url), loading=true">
|
||||||
|
{{ file.name }}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<v-btn size="small" variant="text" icon="mdi-file-pdf-box" color="red" @click="openPDF(file.url), loading=true"></v-btn>
|
||||||
|
<v-btn size="small" variant="text" icon='mdi-file-download-outline' color="green" @click="downloadItem(burl + file.url, file.name)"></v-btn>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</v-expansion-panel-text>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- <v-card-actions v-if="category.id != 'evacuation_plan'">
|
||||||
<v-btn
|
<v-btn
|
||||||
@click="showMore[item.id + category.id] = !showMore[item.id + category.id]"
|
@click="showMore[ category.id] = !showMore[category.id]"
|
||||||
variant="text">
|
variant="text">
|
||||||
{{ category.name }}
|
{{ category.category__name }}
|
||||||
</v-btn>
|
</v-btn>
|
||||||
<v-btn
|
<v-btn
|
||||||
:icon="showMore[item.id + category.id] ? 'mdi-chevron-up' : 'mdi-chevron-down'"
|
:icon="showMore[ category.id] ? 'mdi-chevron-up' : 'mdi-chevron-down'"
|
||||||
@click="showMore[item.id + category.id] = !showMore[item.id + category.id]">
|
@click="showMore[category.id] = !showMore[ category.id]">
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>-->
|
||||||
<v-expand-transition>
|
<!-- <v-expand-transition>
|
||||||
<div v-show="showMore[item.id + category.id]">
|
<div v-show="showMore[ category.id]">
|
||||||
<v-card-actions v-for="file in category.files" :key="file.id" class="overflow-y-auto">
|
<v-card-actions v-for="file in category.files" :key="file.id" class="overflow-y-auto">
|
||||||
<v-card-text
|
<v-card-text
|
||||||
class="cursor-pointer"
|
class="cursor-pointer"
|
||||||
@@ -54,12 +88,13 @@
|
|||||||
<v-btn icon='mdi-file-download-outline' color="green" @click="downloadItem(burl + file.url, file.name)"></v-btn>
|
<v-btn icon='mdi-file-download-outline' color="green" @click="downloadItem(burl + file.url, file.name)"></v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
</div>
|
</div>
|
||||||
</v-expand-transition>
|
</v-expand-transition> -->
|
||||||
</v-container>
|
</v-expansion-panel>
|
||||||
|
</v-expansion-panels>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-row>
|
</v-row>
|
||||||
<v-row class="ma-0 overflow-auto h-0">
|
<v-row class="ma-0 overflow-auto h-0">
|
||||||
<v-card class="overflow-y-auto flex-grow-1 flex-shrink-1 h-100">
|
<v-card class="overflow-y-auto flex-grow-1 h-100">
|
||||||
<v-card-title>{{ responsibilityData.name }}</v-card-title>
|
<v-card-title>{{ responsibilityData.name }}</v-card-title>
|
||||||
<v-container
|
<v-container
|
||||||
v-for="file in responsibilityData.files"
|
v-for="file in responsibilityData.files"
|
||||||
@@ -137,12 +172,12 @@ const route = useRoute();
|
|||||||
|
|
||||||
// Вынес запрос в отдельную функцию, чтобы избежать дублирования одного и того же запроса на сервер.
|
// Вынес запрос в отдельную функцию, чтобы избежать дублирования одного и того же запроса на сервер.
|
||||||
function getSafety() {
|
function getSafety() {
|
||||||
axiosApiInstance.get(`api/safety/files/?chapter_id=${route.params.chapter_id}`).then(result => {
|
axiosApiInstance.get(`api/safety/files/?chapter=${route.params.chapter}`).then(result => {
|
||||||
safetyData.value = result.data
|
safetyData.value = result.data
|
||||||
console.log(safetyData.value);
|
// console.log(safetyData.value);
|
||||||
loading.value=true
|
loading.value=true
|
||||||
pdfSource.value =burl + safetyData.value[0].categories[1].files[0].url
|
pdfSource.value =burl + safetyData.value.categories[0].files[0].url
|
||||||
console.log(safetyData.value);
|
// console.log(safetyData.value);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +185,7 @@ const formainpage = computed({
|
|||||||
get() {
|
get() {
|
||||||
let arr=[]
|
let arr=[]
|
||||||
if(safetyData.value.length>0){
|
if(safetyData.value.length>0){
|
||||||
safetyData.value[0].categories.forEach(element => {
|
safetyData.value.categories.forEach(element => {
|
||||||
element.files.forEach((e)=>{
|
element.files.forEach((e)=>{
|
||||||
if(e.formainpage==true){
|
if(e.formainpage==true){
|
||||||
arr.push(e)}
|
arr.push(e)}
|
||||||
@@ -172,10 +207,10 @@ getResponsibility()
|
|||||||
onBeforeMount(() => getSafety());
|
onBeforeMount(() => getSafety());
|
||||||
|
|
||||||
// Проверяем по ID на какой категории срабатывает клик на раскрытии/скрытии, чтобы избежать срабатывания у всех категорий одновременно
|
// Проверяем по ID на какой категории срабатывает клик на раскрытии/скрытии, чтобы избежать срабатывания у всех категорий одновременно
|
||||||
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
|
||||||
}, {});
|
// }, {});
|
||||||
|
|
||||||
const downloadItem = (url, fileName) => {
|
const downloadItem = (url, fileName) => {
|
||||||
axiosApiInstance.get(url, {responseType: 'blob'})
|
axiosApiInstance.get(url, {responseType: 'blob'})
|
||||||
|
|||||||
Reference in new issue
Block a user