Merge branch 'develop-testing' into test
This commit is contained in:
commit
505b34f426
31 files changed
+2206
-609
No files matched your search
@@ -129,7 +129,7 @@ class OrderResponsibility(models.Model):
|
|||||||
return f'{self.number} - {self.name}'
|
return f'{self.number} - {self.name}'
|
||||||
|
|
||||||
class OrderResponsibilityEmployee(models.Model):
|
class OrderResponsibilityEmployee(models.Model):
|
||||||
id_order_responsibility = models.ForeignKey(OrderResponsibility, models.DO_NOTHING, db_column='id_order_responsibility', primary_key=True, db_comment='╚─ яЁшърчр ю эрчэрўхэшш юЄтхЄёЄтхээ√ї ёюЄЁєфэшъют',related_name="respons_users") # The composite primary key (id_order_responsibility, id_dict_employee) found, that is not supported. The first column is selected.
|
id_order_responsibility = models.OneToOneField(OrderResponsibility, models.DO_NOTHING, db_column='id_order_responsibility', db_comment='╚─ яЁшърчр ю эрчэрўхэшш юЄтхЄёЄтхээ√ї ёюЄЁєфэшъют',related_name="respons_users") # The composite primary key (id_order_responsibility, id_dict_employee) found, that is not supported. The first column is selected.
|
||||||
employee = models.ForeignKey('userauth.DictEmployee', models.DO_NOTHING, db_column='id_dict_employee', db_comment='╚─ ёюЄЁєфэшър, ъюЄюЁ√щ эрчэрўхэ юЄтхЄёЄтхээ√ь яю фрээюьє яЁшърчє', related_name="user_respons")
|
employee = models.ForeignKey('userauth.DictEmployee', models.DO_NOTHING, db_column='id_dict_employee', db_comment='╚─ ёюЄЁєфэшър, ъюЄюЁ√щ эрчэрўхэ юЄтхЄёЄтхээ√ь яю фрээюьє яЁшърчє', related_name="user_respons")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -140,6 +140,7 @@ class OrderResponsibilityEmployee(models.Model):
|
|||||||
verbose_name_plural = 'Ответственные сотрудники'
|
verbose_name_plural = 'Ответственные сотрудники'
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.employee)
|
return str(self.employee)
|
||||||
|
|
||||||
class OrderResponsibilityFiles(models.Model):
|
class OrderResponsibilityFiles(models.Model):
|
||||||
id = models.PositiveIntegerField(primary_key=True, db_comment='╥рсхы№э√щ эюьхЁ')
|
id = models.PositiveIntegerField(primary_key=True, db_comment='╥рсхы№э√щ эюьхЁ')
|
||||||
id_order_responsibility = models.ForeignKey(OrderResponsibility, models.DO_NOTHING, db_column='id_order_responsibility', db_comment='╚─ яЁшърчр юс юЄтхЄёЄтхээ√ї ёюЄЁєфэшърї', related_name="get_resp_files")
|
id_order_responsibility = models.ForeignKey(OrderResponsibility, models.DO_NOTHING, db_column='id_order_responsibility', db_comment='╚─ яЁшърчр юс юЄтхЄёЄтхээ√ї ёюЄЁєфэшърї', related_name="get_resp_files")
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ from django.conf import settings
|
|||||||
from ckeditor.fields import RichTextField
|
from ckeditor.fields import RichTextField
|
||||||
from ckeditor_uploader.fields import RichTextUploadingField
|
from ckeditor_uploader.fields import RichTextUploadingField
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
from vote.models import Vote
|
||||||
|
from django.utils.timezone import now
|
||||||
|
|
||||||
class BaseSender(models.Model):
|
class BaseSender(models.Model):
|
||||||
name = models.CharField(verbose_name='Название', max_length=150, blank=True, db_index=True)
|
name = models.CharField(verbose_name='Название', max_length=150, blank=True, db_index=True)
|
||||||
@@ -39,6 +41,7 @@ class News(models.Model):
|
|||||||
cdate =models.DateTimeField(default=datetime.now, verbose_name='Дата создания')
|
cdate =models.DateTimeField(default=datetime.now, verbose_name='Дата создания')
|
||||||
author = models.ForeignKey(settings.AUTH_USER_MODEL, editable=False, on_delete=models.PROTECT, verbose_name='Автор')
|
author = models.ForeignKey(settings.AUTH_USER_MODEL, editable=False, on_delete=models.PROTECT, verbose_name='Автор')
|
||||||
link = models.ImageField(upload_to='newsimage/%Y/%m/%d', null=True, default="newsimage/default.jpg", verbose_name='Изображение')
|
link = models.ImageField(upload_to='newsimage/%Y/%m/%d', null=True, default="newsimage/default.jpg", verbose_name='Изображение')
|
||||||
|
vote = models.ForeignKey(Vote, on_delete=models.CASCADE, null=True, blank=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
@@ -125,14 +128,17 @@ class CommentNews(models.Model):
|
|||||||
|
|
||||||
names.short_description="ФИО"
|
names.short_description="ФИО"
|
||||||
|
|
||||||
|
def default_end_date():
|
||||||
|
return now().replace(hour=23, minute=0) + timedelta(days=7)
|
||||||
|
|
||||||
class Carousels(models.Model):
|
class Carousels(models.Model):
|
||||||
title=models.CharField(max_length=255, blank=True, null=True, verbose_name='Заголовок')
|
title=models.CharField(max_length=255, blank=True, null=True, verbose_name='Заголовок')
|
||||||
text= models.TextField(max_length=260, blank=True, null=True, verbose_name='Сообщение')
|
text= models.TextField(max_length=260, blank=True, null=True, verbose_name='Сообщение')
|
||||||
cdate =models.DateTimeField(default=datetime.now, verbose_name='Дата создания')
|
cdate =models.DateTimeField(default=now, verbose_name='Дата создания')
|
||||||
author = models.ForeignKey(settings.AUTH_USER_MODEL, editable=False, on_delete=models.PROTECT, verbose_name='Автор новости')
|
author = models.ForeignKey(settings.AUTH_USER_MODEL, editable=False, on_delete=models.PROTECT, verbose_name='Автор новости')
|
||||||
link = models.ImageField(upload_to='newsimage/%Y/%m/%d', null=True, default="newsimage/default.jpg", verbose_name='Картинка')
|
link = models.ImageField(upload_to='newsimage/%Y/%m/%d', null=True, default="newsimage/default.jpg", verbose_name='Картинка')
|
||||||
published = models.BooleanField(default=True, verbose_name='Опубликован')
|
published = models.BooleanField(default=True, verbose_name='Опубликован')
|
||||||
enddate = models.DateTimeField(default=datetime.now().replace(hour=23,minute=0,second=0,microsecond=0) + timedelta(days=7), verbose_name='Дата снятия с публикации')
|
enddate = models.DateTimeField(default=default_end_date, verbose_name='Дата снятия с публикации')
|
||||||
sender = models.ForeignKey(BaseSender, on_delete=models.PROTECT, related_name='get_base_sender', verbose_name='Тематика')
|
sender = models.ForeignKey(BaseSender, on_delete=models.PROTECT, related_name='get_base_sender', verbose_name='Тематика')
|
||||||
order = models.IntegerField(verbose_name='Порядок сортировки', null=True, blank=True)
|
order = models.IntegerField(verbose_name='Порядок сортировки', null=True, blank=True)
|
||||||
|
|
||||||
@@ -166,11 +172,13 @@ class BirthdayText(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.pk)
|
return str(self.pk)
|
||||||
|
|
||||||
|
def default_date():
|
||||||
|
return date.today().replace(year=1992)
|
||||||
|
|
||||||
class Screensaver(models.Model):
|
class Screensaver(models.Model):
|
||||||
img = models.ImageField(upload_to='screengallery/%Y/%m/%d', null=True, verbose_name='Изображение')
|
img = models.ImageField(upload_to='screengallery/%Y/%m/%d', null=True, verbose_name='Изображение')
|
||||||
cdate =models.DateField(default=date.today().replace(year=1992), null=True, verbose_name='Дата начала периода')
|
cdate =models.DateField(default=default_date, null=True, verbose_name='Дата начала периода')
|
||||||
enddate = models.DateField(default= date.today().replace(year=1992), verbose_name='Дата окончания периода', null=True)
|
enddate = models.DateField(default= default_date, verbose_name='Дата окончания периода', null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
|
|||||||
@@ -209,16 +209,16 @@ class ScreensaverAPIView(ListAPIView):
|
|||||||
# print(result, "--------------------------no foto screensaver")
|
# print(result, "--------------------------no foto screensaver")
|
||||||
# try:
|
# try:
|
||||||
# queryset = Screensaver.objects.all()
|
# queryset = Screensaver.objects.all()
|
||||||
# queryset = Screensaver.objects.filter(cdate__month__lte = date.today().month, cdate__day__lte = date.today().day,
|
queryset = Screensaver.objects.filter(cdate__month__lte = date.today().month, cdate__day__lte = date.today().day,
|
||||||
# enddate__month__gte=date.today().month, enddate__day__gte=date.today().day).order_by('-cdate')
|
enddate__month__gte=date.today().month, enddate__day__gte=date.today().day).order_by('-cdate')
|
||||||
queryset = Screensaver.objects.filter(cdate__month__lte = 6, cdate__day__lte = 3,
|
# queryset = Screensaver.objects.filter(cdate__month__lte = 6, cdate__day__lte = 3,
|
||||||
enddate__month__gte=6, enddate__day__gte=3).order_by('-cdate')
|
# enddate__month__gte=6, enddate__day__gte=3).order_by('-cdate')
|
||||||
b = Screensaver.objects.values('cdate__month', 'cdate__day', 'enddate__month', 'enddate__day')
|
# b = Screensaver.objects.values('cdate__month', 'cdate__day', 'enddate__month', 'enddate__day')
|
||||||
# result = ScreensaverSerializer(queryset, many= True).data
|
# result = ScreensaverSerializer(queryset, many= True).data
|
||||||
print(queryset,"--------------------------no foto screensaver")
|
queryset = queryset.filter(cdate=queryset[0].cdate).order_by("?")[:1]
|
||||||
# queryset = queryset.filter(cdate=queryset[0].cdate).order_by("?")[:1]
|
|
||||||
|
result = ScreensaverSerializer(queryset[0]).data
|
||||||
|
|
||||||
# result = ScreensaverSerializer(queryset, many= True).data
|
|
||||||
|
|
||||||
# except Exception as e:
|
# except Exception as e:
|
||||||
# print("no foto screensaver")
|
# print("no foto screensaver")
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ INSTALLED_APPS = [
|
|||||||
'about_inspection.apps.AboutInspectionConfig',
|
'about_inspection.apps.AboutInspectionConfig',
|
||||||
'calendar_of_events.apps.CalendarOfEventsConfig',
|
'calendar_of_events.apps.CalendarOfEventsConfig',
|
||||||
'tests.apps.TestsConfig',
|
'tests.apps.TestsConfig',
|
||||||
'ckeditor'
|
'django_ckeditor_5',
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -2,3 +2,5 @@ from django.contrib import admin
|
|||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
admin.site.register(Vote)
|
admin.site.register(Vote)
|
||||||
|
admin.site.register(Question)
|
||||||
|
admin.site.register(Answer)
|
||||||
+19
-7
@@ -9,7 +9,6 @@ class Vote(models.Model):
|
|||||||
description = models.TextField(verbose_name='Описание')
|
description = models.TextField(verbose_name='Описание')
|
||||||
datestart = models.DateTimeField(default=datetime.datetime.now, verbose_name='Дата и время начала периода')
|
datestart = models.DateTimeField(default=datetime.datetime.now, verbose_name='Дата и время начала периода')
|
||||||
dateend = models.DateTimeField(default=datetime.datetime.now, verbose_name='Дата и время окончания периода')
|
dateend = models.DateTimeField(default=datetime.datetime.now, verbose_name='Дата и время окончания периода')
|
||||||
settings = models.JSONField(default=dict, verbose_name='Json настроек голосования')
|
|
||||||
author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='Создатель голосования')
|
author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='Создатель голосования')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@@ -20,26 +19,39 @@ class Vote(models.Model):
|
|||||||
verbose_name_plural = "Голосования"
|
verbose_name_plural = "Голосования"
|
||||||
|
|
||||||
class Question(models.Model):
|
class Question(models.Model):
|
||||||
question = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
vote = models.ForeignKey(Vote, related_name='questions', on_delete=models.CASCADE)
|
vote = models.ForeignKey(Vote, related_name='questions', on_delete=models.CASCADE)
|
||||||
file = models.ImageField(upload_to='question_images/', null=True, blank=True)
|
file = models.ImageField(upload_to='question_images/', null=True, blank=True)
|
||||||
numb = models.PositiveIntegerField()
|
numb = models.PositiveIntegerField()
|
||||||
|
settings = models.JSONField(default=dict, verbose_name='Json настроек голосования')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.question
|
return self.name
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Вопрос"
|
||||||
|
verbose_name_plural = "Вопросы"
|
||||||
|
|
||||||
class Answer(models.Model):
|
class Answer(models.Model):
|
||||||
answer = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
file = models.FileField(upload_to='answer_files/', null=True, blank=True)
|
file = models.FileField(upload_to='answer_files/', null=True, blank=True)
|
||||||
question = models.ForeignKey(Question, related_name='answers', on_delete=models.CASCADE)
|
question = models.ForeignKey(Question, related_name='answers', on_delete=models.CASCADE)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.answer
|
return self.name
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Ответ"
|
||||||
|
verbose_name_plural = "Ответы"
|
||||||
|
|
||||||
class Result(models.Model):
|
class Result(models.Model):
|
||||||
user = models.ForeignKey(DictEmployee, on_delete=models.CASCADE)
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
answer = models.ForeignKey(Answer, on_delete=models.CASCADE)
|
answer = models.ForeignKey(Answer, on_delete=models.CASCADE)
|
||||||
comment = models.TextField(null=True, blank=True)
|
comment = models.TextField(null=True, blank=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'Result by {self.user.username} for {self.answer.answer}'
|
return self.answer.name
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Результат"
|
||||||
|
verbose_name_plural = "Результаты"
|
||||||
@@ -2,27 +2,57 @@ from rest_framework import serializers
|
|||||||
from .models import *
|
from .models import *
|
||||||
from userauth.models import *
|
from userauth.models import *
|
||||||
|
|
||||||
|
class VotesSerializer(serializers.ModelSerializer):
|
||||||
class VoteSerializer(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Vote
|
model = Vote
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
class QuestionSerializer(serializers.ModelSerializer):
|
def create(self, validated_data):
|
||||||
class Meta:
|
user = self.context['request'].user
|
||||||
model = Question
|
if user.is_authenticated:
|
||||||
fields = '__all__'
|
validated_data['author'] = user
|
||||||
|
|
||||||
|
return super().create(validated_data)
|
||||||
|
|
||||||
class AnswerSerializer(serializers.ModelSerializer):
|
class AnswerSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Answer
|
model = Answer
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
class QuestionSerializer(serializers.ModelSerializer):
|
||||||
|
answers = AnswerSerializer(many=True, read_only=True)
|
||||||
|
class Meta:
|
||||||
|
model = Question
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
class VoteSerializer(serializers.ModelSerializer):
|
||||||
|
questions = QuestionSerializer(many=True, read_only=True)
|
||||||
|
class Meta:
|
||||||
|
model = Vote
|
||||||
|
fields = '__all__'
|
||||||
|
# fields = ['id', 'name', 'description', 'datestart', 'dateend', 'settings', 'author']
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
user = self.context['request'].user
|
||||||
|
if user.is_authenticated:
|
||||||
|
validated_data['author'] = user
|
||||||
|
|
||||||
|
return super().create(validated_data)
|
||||||
|
|
||||||
class ResultSerializer(serializers.ModelSerializer):
|
class ResultSerializer(serializers.ModelSerializer):
|
||||||
|
answer=serializers.PrimaryKeyRelatedField( queryset=Answer.objects.all(),many=False)
|
||||||
|
user=serializers.PrimaryKeyRelatedField( queryset=User.objects.all(),many=False)
|
||||||
|
comment = serializers.CharField(allow_null=True)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Result
|
model = Result
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
class DictEmployeeSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = DictEmployee
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
class VoteResultSerializer(serializers.Serializer):
|
class VoteResultSerializer(serializers.Serializer):
|
||||||
answer = serializers.CharField(source='answer__answer')
|
answer = serializers.CharField(source='answer__answer')
|
||||||
count = serializers.IntegerField()
|
count = serializers.IntegerField()
|
||||||
|
employee = DictEmployeeSerializer(required=False)
|
||||||
@@ -5,4 +5,9 @@ from .views import *
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('getvotes/', GetVotes.as_view(),name='GetVotes'),
|
path('getvotes/', GetVotes.as_view(),name='GetVotes'),
|
||||||
|
path('votedetail/<int:id>/', VoteDetail.as_view(),name='VoteDetail'),
|
||||||
|
path('votecreate/', VoteCreate.as_view(),name='VoteCreate'),
|
||||||
|
path('getdictemployee/', GetDictEmployee.as_view(),name='GetDictEmployee'),
|
||||||
|
path('getresults/', GetResults.as_view(),name='GetResults'),
|
||||||
|
path('voteresultcreate/', VoteResultCreate.as_view(),name='VoteResultCreate'),
|
||||||
]
|
]
|
||||||
+177
-28
@@ -5,25 +5,43 @@ from django.db.models import Q
|
|||||||
from .models import *
|
from .models import *
|
||||||
from userauth.models import *
|
from userauth.models import *
|
||||||
from .serializers import *
|
from .serializers import *
|
||||||
import datetime
|
from datetime import datetime
|
||||||
|
from rest_framework import generics
|
||||||
|
from navigation.models import News
|
||||||
|
import json
|
||||||
|
from collections import defaultdict
|
||||||
|
import os
|
||||||
|
from django.conf import settings
|
||||||
|
from django.urls import reverse
|
||||||
|
import html
|
||||||
|
|
||||||
class GetVotes(APIView):
|
class GetVotes(APIView):
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
user = request.user
|
user = request.user
|
||||||
# user = DictEmployee.objects.get(login='9966-00-125')
|
# user = User.objects.get(username='9966-00-125')
|
||||||
now = datetime.datetime.now()
|
now = datetime.now()
|
||||||
status = request.query_params.get('status')
|
status = request.query_params.get('status')
|
||||||
print(status)
|
|
||||||
votes = self.get_votes_by_status(status, now)
|
votes = self.get_votes_by_status(status, now)
|
||||||
serialized_votes = VoteSerializer(votes, many=True).data
|
serialized_votes = VotesSerializer(votes, many=True).data
|
||||||
|
questions = Question.objects.filter(vote__in=votes)
|
||||||
|
|
||||||
|
questions_by_vote_id = defaultdict(list)
|
||||||
|
for question in questions:
|
||||||
|
questions_by_vote_id[question.vote.id].append(question)
|
||||||
|
|
||||||
for vote in serialized_votes:
|
for vote in serialized_votes:
|
||||||
vote['is_passed'] = self.has_participated(user, vote['id'])
|
vote['is_passed'] = self.has_participated(user, vote['id'])
|
||||||
|
related_questions = questions_by_vote_id[vote['id']]
|
||||||
|
vote['files'] = [question.file.url for question in related_questions if question.file]
|
||||||
|
|
||||||
return Response(serialized_votes)
|
return Response(serialized_votes)
|
||||||
|
|
||||||
def get_votes_by_status(self, status, now):
|
def get_votes_by_status(self, status, now):
|
||||||
|
print(status)
|
||||||
|
if status is None:
|
||||||
|
return Vote.objects.all().order_by('dateend')
|
||||||
|
|
||||||
status_filters = {
|
status_filters = {
|
||||||
'active': Vote.objects.filter(dateend__gt=now),
|
'active': Vote.objects.filter(dateend__gt=now),
|
||||||
'completed': Vote.objects.filter(dateend__lt=now),
|
'completed': Vote.objects.filter(dateend__lt=now),
|
||||||
@@ -34,35 +52,166 @@ class GetVotes(APIView):
|
|||||||
def has_participated(self, employee, vote):
|
def has_participated(self, employee, vote):
|
||||||
return Result.objects.filter(user=employee, answer__question__vote=vote).exists()
|
return Result.objects.filter(user=employee, answer__question__vote=vote).exists()
|
||||||
|
|
||||||
|
class VoteDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
queryset = Vote.objects.all()
|
||||||
|
serializer_class = VoteSerializer
|
||||||
|
lookup_url_kwarg = 'id'
|
||||||
|
lookup_field = 'id'
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
results = Result.objects.filter(answer__question__vote=kwargs['id'], user=request.user)
|
||||||
|
if results:
|
||||||
|
return Response({'status': 'error', 'message': 'voted'}, status=400)
|
||||||
|
|
||||||
|
try:
|
||||||
|
vote = Vote.objects.get(id=kwargs['id'])
|
||||||
|
except Exception as e:
|
||||||
|
return Response({'status': 'error', 'message': str(e)}, status=400)
|
||||||
|
|
||||||
|
answers_employee = Answer.objects.filter(question__vote=vote).filter(question__settings__choice="employee").values('name', 'question')
|
||||||
|
|
||||||
|
answers_names = [item['name'] for item in answers_employee]
|
||||||
|
question_ids = [item['question'] for item in answers_employee]
|
||||||
|
|
||||||
|
if answers_employee:
|
||||||
|
employees = DictEmployee.objects.filter(id__in=answers_names)
|
||||||
|
employee_dict = {employee['id']: employee for employee in DictEmployeeSerializer(employees, many=True).data}
|
||||||
|
|
||||||
|
serialized_data = self.retrieve(request, *args, **kwargs).data
|
||||||
|
|
||||||
|
for question in serialized_data['questions']:
|
||||||
|
for answer in question['answers']:
|
||||||
|
if question['id'] in question_ids:
|
||||||
|
if answer['name'] in answers_names:
|
||||||
|
answer['employee'] = employee_dict.get(int(answer['name']))
|
||||||
|
|
||||||
|
return Response(serialized_data)
|
||||||
|
|
||||||
|
class VoteCreate(APIView):
|
||||||
|
def post(self, request):
|
||||||
|
try:
|
||||||
|
vote = self.create_vote(request)
|
||||||
|
self.create_news(request, vote)
|
||||||
|
return Response({'status': 'success', 'message': 'Vote and news created successfully.'}, status=200)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
return Response({'status': 'error', 'message': str(e)}, status=400)
|
||||||
|
|
||||||
def create_vote(self, request):
|
def create_vote(self, request):
|
||||||
vote = Vote(
|
user = request.user
|
||||||
name=request.data['name'],
|
|
||||||
|
vote = Vote.objects.create(
|
||||||
|
name=request.data['title'],
|
||||||
description=request.data['description'],
|
description=request.data['description'],
|
||||||
datestart=request.data['datestart'],
|
datestart=request.data['startDate'],
|
||||||
dateend=request.data['dateend'],
|
dateend=request.data['endDate'],
|
||||||
settings=request.data.get('settings', {}),
|
author=user,
|
||||||
author=request.user,
|
|
||||||
)
|
)
|
||||||
vote.save()
|
|
||||||
|
|
||||||
def delete_vote(self,request):
|
questions_files = {file.name: file for file in request.FILES.getlist('questionsfiles')}
|
||||||
vote_id = request.data.get('vote_id')
|
answers_files = {file.name: file for file in request.FILES.getlist('answersfiles')}
|
||||||
|
|
||||||
|
questions = json.loads(request.data['questions'])
|
||||||
|
for count, question_data in enumerate(questions, start=1):
|
||||||
|
question_image = questions_files.get(question_data['image']['name']) if 'image' in question_data and question_data['image'] is not None else None
|
||||||
|
question = Question.objects.create(
|
||||||
|
name=question_data['text'],
|
||||||
|
vote=vote,
|
||||||
|
file=question_image,
|
||||||
|
numb=count,
|
||||||
|
settings=question_data.get('settings', {}),
|
||||||
|
)
|
||||||
|
|
||||||
|
for answer in question_data['answers']:
|
||||||
|
answer_image = answers_files.get(answer['image']['name']) if 'image' in answer and answer['image'] is not None else None
|
||||||
|
Answer.objects.create(
|
||||||
|
name=answer['text'],
|
||||||
|
file=answer_image,
|
||||||
|
question=question
|
||||||
|
)
|
||||||
|
|
||||||
|
return vote
|
||||||
|
|
||||||
|
def create_news(self, request, vote):
|
||||||
|
|
||||||
|
formatted_date = datetime.strptime(request.data["endDate"][:-1], "%Y-%m-%dT%H:%M:%S.%f").strftime("%d.%m.%Y %H:%M")
|
||||||
|
vote_url = make_clickable(request.data['title'], f"/vote/voting/{vote.id}")
|
||||||
|
|
||||||
|
news = News(
|
||||||
|
title = 'Пройдите голосование!',
|
||||||
|
text = f'Пройдите голосование "{vote_url}" до {formatted_date}',
|
||||||
|
cdate = request.data['startDate'],
|
||||||
|
author = request.user,
|
||||||
|
link = os.path.join(settings.MEDIA_ROOT,'defaultimg','vote.png'),
|
||||||
|
vote = vote
|
||||||
|
)
|
||||||
|
news.save()
|
||||||
|
|
||||||
|
def make_clickable(text, url):
|
||||||
|
text = html.escape(text)
|
||||||
|
anchor = f'<a href="{html.escape(url)}">{text}</a>'
|
||||||
|
return anchor
|
||||||
|
|
||||||
|
class GetDictEmployee(APIView):
|
||||||
|
def get(self, request):
|
||||||
|
employees = DictEmployee.objects.filter(deleted=0)
|
||||||
|
employees_serializer = DictEmployeeSerializer(employees, many=True).data
|
||||||
|
return Response(employees_serializer)
|
||||||
|
|
||||||
|
class GetResults(APIView):
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
vote_id = request.GET.get('id')
|
||||||
|
try:
|
||||||
vote = Vote.objects.get(id=vote_id)
|
vote = Vote.objects.get(id=vote_id)
|
||||||
questions = vote.questions.all()
|
except Vote.DoesNotExist:
|
||||||
for question in questions:
|
return Response({'status': 'error', 'message': 'Vote not found'}, status=404)
|
||||||
answers = question.answers.all()
|
|
||||||
answers.delete()
|
|
||||||
|
|
||||||
questions.delete()
|
serialized_data = VoteSerializer(vote).data
|
||||||
|
answers_employee = Answer.objects.filter(
|
||||||
|
question__vote=vote,
|
||||||
|
question__settings__choice="employee"
|
||||||
|
).values('name', 'question')
|
||||||
|
|
||||||
results = Result.objects.filter(answer__question__vote=vote)
|
answers_names = [item['name'] for item in answers_employee]
|
||||||
results.delete()
|
question_ids = [item['question'] for item in answers_employee]
|
||||||
|
|
||||||
vote.delete()
|
employee_dict = {}
|
||||||
|
if answers_employee:
|
||||||
|
employees = DictEmployee.objects.filter(id__in=answers_names)
|
||||||
|
employee_dict = {employee['id']: employee for employee in DictEmployeeSerializer(employees, many=True).data}
|
||||||
|
|
||||||
def get_vote_results(self, request):
|
results = Result.objects.filter(
|
||||||
vote_id = request.data.get('vote_id')
|
answer__question__vote=vote
|
||||||
vote = Vote.objects.get(id=vote_id)
|
).values('answer_id').annotate(count=Count('id'))
|
||||||
results = Result.objects.filter(answer__question__vote=vote).values('answer__answer').annotate(count=Count('id'))
|
|
||||||
serialized_results = VoteResultSerializer(results, many=True).data
|
result_dict = {int(result['answer_id']): result['count'] for result in results}
|
||||||
return Response(serialized_results)
|
|
||||||
|
for question in serialized_data['questions']:
|
||||||
|
for answer in question['answers']:
|
||||||
|
answer['count'] = result_dict.get(int(answer['id']), 0)
|
||||||
|
if question['id'] in question_ids:
|
||||||
|
if answer['name'] in answers_names:
|
||||||
|
answer['employee'] = employee_dict.get(int(answer['name']))
|
||||||
|
|
||||||
|
users = Result.objects.filter(answer__question__vote=vote).values('user_id')
|
||||||
|
users = User.objects.filter(created_at__lt=vote.dateend).exclude(id__in=users)
|
||||||
|
employee_ids = users.values_list('user_id', flat=True)
|
||||||
|
employees = DictEmployee.objects.filter(id__in=employee_ids)
|
||||||
|
serialized_data['nonvoting'] = DictEmployeeSerializer(employees, many=True).data
|
||||||
|
|
||||||
|
return Response(serialized_data)
|
||||||
|
|
||||||
|
from rest_framework.views import exception_handler
|
||||||
|
class VoteResultCreate(APIView):
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
user_id = request.user.id
|
||||||
|
answer_ids = [item['answer'] for item in request.data]
|
||||||
|
answers = Answer.objects.in_bulk(answer_ids)
|
||||||
|
vote = list(answers.values())[0].question.vote
|
||||||
|
results = Result.objects.bulk_create(
|
||||||
|
[Result(answer=answers[answer_id], user_id=user_id) for answer_id in answer_ids]
|
||||||
|
)
|
||||||
|
serializer = ResultSerializer(results, many=True)
|
||||||
|
return Response(serializer.data)
|
||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "front",
|
"name": "front",
|
||||||
"version": "0.0.82",
|
"version": "0.0.83",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "front",
|
"name": "front",
|
||||||
"version": "0.0.82",
|
"version": "0.0.83",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"-": "^0.0.1",
|
"-": "^0.0.1",
|
||||||
"@ckeditor/ckeditor5-build-classic": "^41.4.2",
|
"@ckeditor/ckeditor5-build-classic": "^41.4.2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "front",
|
"name": "front",
|
||||||
"version": "0.0.82",
|
"version": "0.0.83",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
@@ -88,7 +88,7 @@
|
|||||||
type="error"
|
type="error"
|
||||||
density="compact"
|
density="compact"
|
||||||
title="Ошибка авторизации"
|
title="Ошибка авторизации"
|
||||||
:text="info"
|
|
||||||
v-model="alert"
|
v-model="alert"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,137 @@
|
|||||||
|
<template>
|
||||||
|
<v-row class="px-2">
|
||||||
|
<v-card variant="text"
|
||||||
|
:disabled="disabledcard.disabled"
|
||||||
|
class="py-2 mx-auto">
|
||||||
|
<v-card-title class="text-body-1">
|
||||||
|
До {{ disabledcard.text }} голосования осталось:
|
||||||
|
|
||||||
|
</v-card-title>
|
||||||
|
<v-row no-gutters class="align-baseline">
|
||||||
|
<v-col class="text-center">
|
||||||
|
<v-card class="bg-yellow-darken-4">
|
||||||
|
<div>{{ displayDays }}</div>
|
||||||
|
</v-card>
|
||||||
|
<span class="text-caption">{{ declOfNum(displayDays, [' день', ' дня', ' дней']) }}</span>
|
||||||
|
</v-col>
|
||||||
|
<v-col cols="auto" class="px-1">:</v-col>
|
||||||
|
<v-col class="text-center">
|
||||||
|
<v-card class="bg-yellow-darken-4">
|
||||||
|
<div>{{ displayHours }}</div>
|
||||||
|
</v-card>
|
||||||
|
<span class="text-caption">{{ declOfNum(displayHours, [' час', ' часа', ' часов']) }}</span>
|
||||||
|
</v-col>
|
||||||
|
<v-col cols="auto" class="px-1">:</v-col>
|
||||||
|
<v-col class="text-center">
|
||||||
|
<v-card class="bg-yellow-darken-4">
|
||||||
|
<div>{{ displayMinutes }}</div>
|
||||||
|
</v-card>
|
||||||
|
<span class="text-caption">{{ declOfNum(displayMinutes, [' минута', ' минуты', ' минут']) }}</span>
|
||||||
|
</v-col>
|
||||||
|
<v-col cols="auto" class="px-1">:</v-col>
|
||||||
|
<v-col class="text-center">
|
||||||
|
<v-card class="bg-yellow-darken-4">
|
||||||
|
<div>{{ displaySeconds }}</div>
|
||||||
|
</v-card>
|
||||||
|
<span class="text-caption">{{ declOfNum(displaySeconds, [' секунда', ' секунды', ' секунд']) }}</span>
|
||||||
|
</v-col>
|
||||||
|
</v-row>
|
||||||
|
</v-card>
|
||||||
|
</v-row>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
voteTime: {
|
||||||
|
type: Object,
|
||||||
|
default: () => { return {
|
||||||
|
dateend: new Date().setFullYear(),
|
||||||
|
datestart: new Date().setFullYear()
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setup(props, {emit}) {
|
||||||
|
const seconds = 1000
|
||||||
|
const displayMinutes = ref(0);
|
||||||
|
const displayHours = ref(0);
|
||||||
|
const displayDays = ref(0);
|
||||||
|
const displaySeconds = ref(0);
|
||||||
|
const isFinished = ref(false);
|
||||||
|
|
||||||
|
|
||||||
|
const minutes = computed(() => seconds * 60);
|
||||||
|
const hours = computed(() => minutes.value * 60);
|
||||||
|
const days = computed(() => hours.value * 24);
|
||||||
|
|
||||||
|
function declOfNum(value, titles) {
|
||||||
|
const cases = [2, 0, 1, 1, 1, 2];
|
||||||
|
return titles[(value % 100 > 4 && value % 100 < 20) ? 2 : cases[(value % 10 < 5) ? value % 10 : 5]];
|
||||||
|
}
|
||||||
|
|
||||||
|
const disabledcard = ref({
|
||||||
|
text: 'окончания',
|
||||||
|
disabled: false
|
||||||
|
});
|
||||||
|
|
||||||
|
const dateendorStart = () => {
|
||||||
|
let param = 'dateend';
|
||||||
|
|
||||||
|
if (new Date().getTime() < new Date(props.voteTime.datestart).getTime()) {
|
||||||
|
param = 'datestart';
|
||||||
|
disabledcard.value = {
|
||||||
|
text: 'начала',
|
||||||
|
disabled: true,
|
||||||
|
};
|
||||||
|
emit('changeBtn', true);
|
||||||
|
} else {
|
||||||
|
disabledcard.value = {
|
||||||
|
text: 'окончания',
|
||||||
|
disabled: false,
|
||||||
|
};
|
||||||
|
emit('changeBtn', false);
|
||||||
|
}
|
||||||
|
return param;
|
||||||
|
};
|
||||||
|
|
||||||
|
function countDown() {
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
const date = new Date()
|
||||||
|
const distance = new Date(props.voteTime[dateendorStart()]).getTime() - date.getTime()
|
||||||
|
|
||||||
|
if (distance <= 1) {
|
||||||
|
clearInterval(timer)
|
||||||
|
setTimeout(()=>countDown(),1000)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const daysOf = Math.floor(distance / days.value)
|
||||||
|
const hoursOf = Math.floor((distance % days.value) / hours.value)
|
||||||
|
const minutesOf = Math.floor((distance % hours.value) / minutes.value)
|
||||||
|
const secondsOf = Math.floor((distance % minutes.value) / seconds)
|
||||||
|
|
||||||
|
displayDays.value = daysOf < 10 ? "0" + daysOf : daysOf
|
||||||
|
displayHours.value = hoursOf < 10 ? "0" + hoursOf : hoursOf
|
||||||
|
displayMinutes.value = minutesOf < 10 ? "0" + minutesOf : minutesOf
|
||||||
|
displaySeconds.value = secondsOf < 10 ? "0" + secondsOf : secondsOf
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
countDown()
|
||||||
|
|
||||||
|
return {
|
||||||
|
displayMinutes,
|
||||||
|
displayHours,
|
||||||
|
displayDays,
|
||||||
|
displaySeconds,
|
||||||
|
declOfNum,
|
||||||
|
dateendorStart,
|
||||||
|
disabledcard,
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -37,8 +37,6 @@
|
|||||||
hide-header
|
hide-header
|
||||||
@update:modelValue="dateStart"
|
@update:modelValue="dateStart"
|
||||||
border
|
border
|
||||||
:max="formatDash(new Date())"
|
|
||||||
:min="formatDash(appStore.countvisitor.visitdate)"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</v-locale-provider>
|
</v-locale-provider>
|
||||||
|
|||||||
@@ -156,7 +156,7 @@
|
|||||||
<br />
|
<br />
|
||||||
<span class="text-h5 text-grey"
|
<span class="text-h5 text-grey"
|
||||||
>Сейчас вакансий нет, <br />
|
>Сейчас вакансий нет, <br />
|
||||||
загляните позжет</span
|
загляните позже</span
|
||||||
>
|
>
|
||||||
</v-card-subtitle>
|
</v-card-subtitle>
|
||||||
</v-card>
|
</v-card>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
class="d-flex pa-1 flex-column "
|
class="d-flex pa-1 flex-column "
|
||||||
>
|
>
|
||||||
<news-card :news="x"/>
|
<news-card :news="x"/>
|
||||||
{{aNewsAll}}
|
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
<v-row class="flex-grow-0 ">
|
<v-row class="flex-grow-0 ">
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<template>
|
||||||
|
<div class="px-4">
|
||||||
|
{{ displayDays + declOfNum(displayDays, [' день', ' дня', ' дней']) }}
|
||||||
|
{{ displayHours + declOfNum(displayHours, [' час', ' часа', ' часов']) }}
|
||||||
|
{{ displayMinutes + declOfNum(displayMinutes, [' минута', ' минуты', ' минут']) }}
|
||||||
|
{{ displaySeconds + declOfNum(displaySeconds, [' секунда', ' секунды', ' секунд']) }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
endTime: {
|
||||||
|
type: Date,
|
||||||
|
default: () => { return new Date.setFullYear() }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
setup(props) {
|
||||||
|
|
||||||
|
const seconds = 1000
|
||||||
|
const displayMinutes = ref(0);
|
||||||
|
const displayHours = ref(0);
|
||||||
|
const displayDays = ref(0);
|
||||||
|
const displaySeconds = ref(0)
|
||||||
|
|
||||||
|
const minutes = computed(() => {
|
||||||
|
return seconds * 60
|
||||||
|
})
|
||||||
|
|
||||||
|
const hours = computed(() => {
|
||||||
|
return minutes.value * 60
|
||||||
|
})
|
||||||
|
|
||||||
|
const days = computed(() => {
|
||||||
|
return hours.value * 24
|
||||||
|
})
|
||||||
|
|
||||||
|
function declOfNum(value, titles) {
|
||||||
|
const cases = [2, 0, 1, 1, 1, 2]
|
||||||
|
return titles[(value % 100 > 4 && value % 100 < 20) ? 2 : cases[(value % 10 < 5) ? value % 10 : 5]]
|
||||||
|
}
|
||||||
|
|
||||||
|
function countDown() {
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
const date = new Date()
|
||||||
|
const distance = props.endTime.getTime() - date.getTime()
|
||||||
|
|
||||||
|
if (distance < 0) {
|
||||||
|
clearInterval(timer)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
displayDays.value = Math.floor(distance / days.value)
|
||||||
|
displayHours.value = Math.floor((distance % days.value) / hours.value)
|
||||||
|
displayMinutes.value = Math.floor((distance % hours.value) / minutes.value)
|
||||||
|
displaySeconds.value = Math.floor((distance % minutes.value) / seconds)
|
||||||
|
|
||||||
|
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
countDown()
|
||||||
|
|
||||||
|
return {
|
||||||
|
displayMinutes,
|
||||||
|
displayHours,
|
||||||
|
displayDays,
|
||||||
|
displaySeconds,
|
||||||
|
declOfNum,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,281 @@
|
|||||||
|
<template>
|
||||||
|
<template v-if="!isVoteSubmitted">
|
||||||
|
<v-card style="height: 85vh;">
|
||||||
|
<div class="d-flex flex-column flex-fill px-2 ">
|
||||||
|
<v-col cols="auto">
|
||||||
|
<v-row class="d-flex flex-column">
|
||||||
|
<v-col class="d-flex flex-row pa-0" cols="12">
|
||||||
|
<v-col>
|
||||||
|
<v-card-title>{{ data.name }}</v-card-title>
|
||||||
|
<v-card-subtitle>{{ data.description }}</v-card-subtitle>
|
||||||
|
</v-col>
|
||||||
|
<v-col cols="auto">
|
||||||
|
<v-btn color="red-darken-1" density="compact" icon="mdi-close-thick" size="small"
|
||||||
|
@click="$emit('closer')">
|
||||||
|
</v-btn>
|
||||||
|
</v-col>
|
||||||
|
</v-col>
|
||||||
|
</v-row>
|
||||||
|
</v-col>
|
||||||
|
<div class="d-flex flex-column flex-fill ">
|
||||||
|
<v-stepper v-model="activeStep" class="d-flex flex-column flex-fill">
|
||||||
|
<!-- Шаги голосования -->
|
||||||
|
<v-stepper-header class="py-0">
|
||||||
|
<template v-for="question in data.questions" :key="question.numb">
|
||||||
|
<v-stepper-item
|
||||||
|
:color="question.numb < activeStep+1?'success':'warning'"
|
||||||
|
:complete="question.numb < activeStep+1"
|
||||||
|
:step="question.numb" edit-icon="mdi-help">
|
||||||
|
Вопрос {{ question.numb }}
|
||||||
|
</v-stepper-item>
|
||||||
|
</template>
|
||||||
|
</v-stepper-header>
|
||||||
|
<v-stepper-window class="d-flex flex-column flex-fill">
|
||||||
|
<v-stepper-window-item
|
||||||
|
v-for="(question, index) in data.questions"
|
||||||
|
:key="question.numb"
|
||||||
|
:step="question.numb">
|
||||||
|
<div>
|
||||||
|
<h3 class="text-center">
|
||||||
|
{{ question.name }}
|
||||||
|
<span class="text-subtitle-1">(вариантов ответа: {{ question.settings.multiChoice }})</span>
|
||||||
|
</h3>
|
||||||
|
<v-row>
|
||||||
|
<div class="v-col align-self-start">
|
||||||
|
<VoteAnimation v-if="!question.file" />
|
||||||
|
<v-img
|
||||||
|
:src="question.file"
|
||||||
|
class="cursor-pointer"
|
||||||
|
style="max-height:45vh"
|
||||||
|
@click.stop="opendialog({ answer: question.question, file: question.file })"/>
|
||||||
|
</div>
|
||||||
|
<div class="v-col-6" style="max-height:50vh">
|
||||||
|
<v-list v-model:selected="result[question.id]" density="compact" select-strategy="leaf" slim style="max-height: 100%; overflow-y: auto;">
|
||||||
|
<template v-for="(answers, department) in groupedAnswers(question)" :key="department">
|
||||||
|
<v-list-item-subtitle v-if="department">
|
||||||
|
{{ department }}
|
||||||
|
</v-list-item-subtitle>
|
||||||
|
<v-list-item
|
||||||
|
v-for="answer in answers"
|
||||||
|
:key="answer.id"
|
||||||
|
:value="answer.id"
|
||||||
|
:disabled="result[question.id]?.length >= question.settings.multiChoice && !result[question.id]?.includes(answer.id)"
|
||||||
|
density="compact">
|
||||||
|
{{ answer.employee?.fio || answer.name }}
|
||||||
|
<template v-slot:prepend="{ isSelected }">
|
||||||
|
<v-list-item-action start>
|
||||||
|
<v-checkbox-btn :model-value="isSelected"></v-checkbox-btn>
|
||||||
|
</v-list-item-action>
|
||||||
|
</template>
|
||||||
|
<template v-slot:append>
|
||||||
|
<v-avatar
|
||||||
|
v-if="answer.file === null && answer.employee"
|
||||||
|
:image="checkremote(`${spravURL}${answer.employee.login}.jpg`)"
|
||||||
|
@click.stop="opendialog(checkremote(`${spravURL}${answer.employee.login}.jpg`))" />
|
||||||
|
<v-avatar
|
||||||
|
v-if="answer.file !== null"
|
||||||
|
:image="answer.file"
|
||||||
|
@click.stop="opendialog(answer)">
|
||||||
|
</v-avatar>
|
||||||
|
</template>
|
||||||
|
</v-list-item>
|
||||||
|
</template>
|
||||||
|
</v-list>
|
||||||
|
</div>
|
||||||
|
</v-row>
|
||||||
|
</div>
|
||||||
|
</v-stepper-window-item>
|
||||||
|
|
||||||
|
</v-stepper-window>
|
||||||
|
<v-stepper-actions>
|
||||||
|
<template v-slot:prev>
|
||||||
|
|
||||||
|
<v-btn outlined @click="prevStep">Назад</v-btn>
|
||||||
|
</template>
|
||||||
|
<template v-slot:next>
|
||||||
|
|
||||||
|
<v-btn v-if="activeStep < data.questions.length - 1" :disabled="!isCurrentQuestionAnswered"
|
||||||
|
color="teal-darken-4"
|
||||||
|
@click="nextStep">
|
||||||
|
Далее
|
||||||
|
</v-btn>
|
||||||
|
<v-btn v-else :disabled="!isCurrentQuestionAnswered" color="teal-darken-4" @click="submitVote">
|
||||||
|
Отправить
|
||||||
|
</v-btn>
|
||||||
|
</template>
|
||||||
|
</v-stepper-actions>
|
||||||
|
</v-stepper>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</v-card>
|
||||||
|
<v-dialog v-model="dialog" max-width="100vh">
|
||||||
|
<v-card max-height="800">
|
||||||
|
<v-card-title class="v-row">
|
||||||
|
<div class="v-col-auto">
|
||||||
|
{{ activepick.answer }}
|
||||||
|
</div>
|
||||||
|
<v-spacer></v-spacer>
|
||||||
|
<div>
|
||||||
|
<v-btn color="red-darken-1" density="compact" icon="mdi-close-thick" size="small" @click="dialog=false"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</v-card-title>
|
||||||
|
<v-card-item>
|
||||||
|
<v-img :src="activepick.file ?? activepick" max-height="600"></v-img>
|
||||||
|
</v-card-item>
|
||||||
|
</v-card>
|
||||||
|
</v-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Спасибо за голос -->
|
||||||
|
<template v-else>
|
||||||
|
<v-card class="mx-auto" width="400">
|
||||||
|
<v-row align="center" class="pa-3" justify="center">
|
||||||
|
<v-col class="text-center">
|
||||||
|
<v-icon :color="messeger[messeger.key].color" :icon="messeger[messeger.key].icon" size="64"/>
|
||||||
|
<h2>{{ messeger[messeger.key].text }}</h2>
|
||||||
|
<v-btn class="ma-3 " @click="$emit('closer')">Закрыть</v-btn>
|
||||||
|
</v-col>
|
||||||
|
</v-row>
|
||||||
|
</v-card>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import {axiosApiInstance, spravURL} from "@/utils/axios-api";
|
||||||
|
import {computed, ref} from "vue";
|
||||||
|
import {useAccountStore} from "@/store/AccountStore";
|
||||||
|
import {checkremote} from "@/utils/universal_functions";
|
||||||
|
import VoteAnimation from "@/components/vote/VoteAnimation.vue";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'CurrentVote',
|
||||||
|
components: {VoteAnimation},
|
||||||
|
methods: {
|
||||||
|
checkremote,
|
||||||
|
spravURL() {
|
||||||
|
return spravURL
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ['closer'],
|
||||||
|
props: {
|
||||||
|
data: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
default: () => ({}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
setup(props, {emit}) {
|
||||||
|
const accountStore = useAccountStore();
|
||||||
|
const messeger = ref({
|
||||||
|
good: {icon: 'mdi-check-circle', text: 'Спасибо за Ваш голос!', color: "green"},
|
||||||
|
bad: {icon: 'mdi-alert', text: 'Произошла ошибка!', color: "red"},
|
||||||
|
key: 'good'
|
||||||
|
})
|
||||||
|
const activeStep = ref(0);
|
||||||
|
const answers = ref(props.data.questions.map(() => null));
|
||||||
|
const isVoteSubmitted = ref(false);
|
||||||
|
|
||||||
|
const isCurrentQuestionAnswered = computed(() => {
|
||||||
|
let q = props.data.questions.find(e => e.numb === activeStep.value + 1)
|
||||||
|
return q !== undefined ? result.value[q.id].length > 0 : false;
|
||||||
|
});
|
||||||
|
|
||||||
|
const getres = () => {
|
||||||
|
return props.data.questions.reduce((acc, item) => {
|
||||||
|
acc[item.id] = []
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
}
|
||||||
|
const result = ref(getres())
|
||||||
|
const nextStep = () => {
|
||||||
|
if (activeStep.value < props.data.questions.length - 1) {
|
||||||
|
activeStep.value++;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const prevStep = () => {
|
||||||
|
if (activeStep.value > 0) {
|
||||||
|
activeStep.value--;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitVote = () => {
|
||||||
|
let voteData = []
|
||||||
|
for (let val of Object.values(result.value)) {
|
||||||
|
val.forEach(e => voteData.push({answer: e, comment: null, user: accountStore.user.id}))
|
||||||
|
}
|
||||||
|
|
||||||
|
axiosApiInstance.post('api/vote/voteresultcreate/', voteData).then(res => {
|
||||||
|
messeger.value.key = 'good'
|
||||||
|
|
||||||
|
}).catch(e => {
|
||||||
|
console.log(e);
|
||||||
|
messeger.value.key = 'bad'
|
||||||
|
}
|
||||||
|
).finally(() => isVoteSubmitted.value = true)
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const activepick = ref(null)
|
||||||
|
const dialog = ref(false)
|
||||||
|
const opendialog = (val) => {
|
||||||
|
dialog.value = true
|
||||||
|
activepick.value = val
|
||||||
|
}
|
||||||
|
|
||||||
|
const groupedAnswers = (question) => {
|
||||||
|
const filtered = question.answers.filter(answer => answer.employee?.id !== accountStore.user.is_idEmployee);
|
||||||
|
|
||||||
|
if (question.settings.onlyDep === null) {
|
||||||
|
return groupByDepartment(filtered);
|
||||||
|
} else if (question.settings.onlyDep) {
|
||||||
|
const byDepartment = filtered.filter(
|
||||||
|
(answer) => answer.employee?.department === accountStore.user.department
|
||||||
|
);
|
||||||
|
return groupByDepartment(byDepartment);
|
||||||
|
} else {
|
||||||
|
const notByDepartment = filtered.filter(
|
||||||
|
(answer) => answer.employee?.department !== accountStore.user.department
|
||||||
|
);
|
||||||
|
return groupByDepartment(notByDepartment);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const groupByDepartment = (answers) => {
|
||||||
|
return answers.reduce((groups, answer) => {
|
||||||
|
const department = answer.employee?.department || "";
|
||||||
|
if (!groups[department]) {
|
||||||
|
groups[department] = [];
|
||||||
|
}
|
||||||
|
groups[department].push(answer);
|
||||||
|
return groups;
|
||||||
|
}, {});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
groupedAnswers,
|
||||||
|
activepick,
|
||||||
|
opendialog,
|
||||||
|
dialog,
|
||||||
|
messeger,
|
||||||
|
activeStep,
|
||||||
|
answers,
|
||||||
|
isCurrentQuestionAnswered,
|
||||||
|
nextStep,
|
||||||
|
prevStep,
|
||||||
|
submitVote,
|
||||||
|
isVoteSubmitted,
|
||||||
|
result
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.v-label {
|
||||||
|
color: #000 !important;
|
||||||
|
opacity: 1 !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<template>
|
||||||
|
<v-container class="d-flex flex-column align-center">
|
||||||
|
<div class="animation-container">
|
||||||
|
<div class="ballot">
|
||||||
|
<span class="ballot-text">Голос</span>
|
||||||
|
</div>
|
||||||
|
<div class="urn">
|
||||||
|
<div class="slot"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</v-container>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
setup() {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.animation-container {
|
||||||
|
position: relative;
|
||||||
|
width: 200px;
|
||||||
|
height: 300px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: flex-end;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ballot {
|
||||||
|
position: absolute;
|
||||||
|
width: 60px;
|
||||||
|
height: 40px;
|
||||||
|
background-color: #004D40;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: bold;
|
||||||
|
text-align: center;
|
||||||
|
line-height: 40px;
|
||||||
|
animation: dropBallot 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
|
||||||
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ballot-text {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.urn {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
width: 120px;
|
||||||
|
height: 80px;
|
||||||
|
background-color: #546E7A;
|
||||||
|
border-top-left-radius: 10px;
|
||||||
|
border-top-right-radius: 10px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot {
|
||||||
|
width: 60px;
|
||||||
|
height: 10px;
|
||||||
|
background-color: #455A64;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes dropBallot {
|
||||||
|
0% {
|
||||||
|
top: -50px;
|
||||||
|
transform: rotate(0deg);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
40% {
|
||||||
|
transform: rotate(15deg);
|
||||||
|
}
|
||||||
|
60% {
|
||||||
|
top: 220px;
|
||||||
|
transform: rotate(-10deg);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
<template>
|
||||||
|
<v-card>
|
||||||
|
<v-card-text class="d-flex justify-space-between ga-3 text-h6">
|
||||||
|
<v-tooltip bottom>
|
||||||
|
<template v-slot:activator="{ props }">
|
||||||
|
<span
|
||||||
|
style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"
|
||||||
|
v-bind="props">
|
||||||
|
{{ voteCard.name }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<span>{{ voteCard.name }}</span>
|
||||||
|
</v-tooltip>
|
||||||
|
<!-- <v-btn v-if="user.id === voteCard.author || user.is_superuser" flat size="medium"-->
|
||||||
|
<!-- @click="$emit('openEditVoteModal', voteCard)">-->
|
||||||
|
<!-- <v-icon color="orange-lighten-1">mdi-pencil</v-icon>-->
|
||||||
|
<!-- </v-btn>-->
|
||||||
|
</v-card-text>
|
||||||
|
<v-row>
|
||||||
|
<v-col>
|
||||||
|
<v-carousel
|
||||||
|
cycle
|
||||||
|
height="200" hide-delimiters
|
||||||
|
show-arrows="hover">
|
||||||
|
<v-carousel-item
|
||||||
|
v-for="(picture, index) in images"
|
||||||
|
:key="index"
|
||||||
|
:src="images[index].length < 1 ? defaultImage : `${baseURL.slice(0, -1)}${picture}`">
|
||||||
|
</v-carousel-item>
|
||||||
|
</v-carousel>
|
||||||
|
</v-col>
|
||||||
|
</v-row>
|
||||||
|
<v-card-text class="">
|
||||||
|
<v-tooltip bottom>
|
||||||
|
<template v-slot:activator="{ props }">
|
||||||
|
<span
|
||||||
|
style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"
|
||||||
|
v-bind="props">
|
||||||
|
{{ voteCard.description }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<span>{{ voteCard.description }}</span>
|
||||||
|
</v-tooltip>
|
||||||
|
</v-card-text>
|
||||||
|
<div class="px-2">
|
||||||
|
<Timer v-if="!isFinished" :voteTime="{ dateend: voteCard.dateend, datestart: voteCard.datestart }"
|
||||||
|
@changeBtn="(time) => timeChange = time"/>
|
||||||
|
|
||||||
|
<div v-else class="font-weight-bold text-center"> Завершено: {{
|
||||||
|
new Date(voteCard.dateend).toLocaleDateString()
|
||||||
|
}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<v-card-actions class="justify-space-between mt-4 pb-2">
|
||||||
|
<template v-if="!isFinished">
|
||||||
|
<v-btn :disabled="voteCard.is_passed || timeChange" color="teal-darken-4" prepend-icon="mdi-vote-outline"
|
||||||
|
rounded="xl" size="small" variant="outlined" @click="$emit('openVoteModal', voteCard)">
|
||||||
|
{{ !voteCard.is_passed ? "Проголосовать" : "Уже проголосовали" }}
|
||||||
|
</v-btn>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<v-btn color="teal-darken-4" prepend-icon="mdi-trophy-outline"
|
||||||
|
rounded="xl" size="small" variant="outlined" @click="$emit('openResultModal', voteCard)">
|
||||||
|
Результаты
|
||||||
|
</v-btn>
|
||||||
|
</template>
|
||||||
|
<v-btn v-if="user.id === voteCard.author || user.is_superuser" color="error" size="medium" @click="youSure=true">
|
||||||
|
<v-icon>mdi-delete</v-icon>
|
||||||
|
<v-dialog v-model="youSure" width="500">
|
||||||
|
<v-card class="flex" max-width="450">
|
||||||
|
<v-btn
|
||||||
|
class="align-self-end ma-2 text-red"
|
||||||
|
icon="mdi-close"
|
||||||
|
size="medium"
|
||||||
|
variant="text"
|
||||||
|
@click="youSure = false"
|
||||||
|
/>
|
||||||
|
<div class="ml-5 text-h6">
|
||||||
|
Вы действительно хотите удалить голосование?
|
||||||
|
</div>
|
||||||
|
<template v-slot:actions>
|
||||||
|
<v-btn-group>
|
||||||
|
<v-btn
|
||||||
|
class="text-red"
|
||||||
|
@click="$emit('deleteVoting', voteCard.id), youSure = false">
|
||||||
|
Да
|
||||||
|
</v-btn>
|
||||||
|
<v-btn
|
||||||
|
class="text-green"
|
||||||
|
@click="youSure = false">
|
||||||
|
Нет
|
||||||
|
</v-btn>
|
||||||
|
</v-btn-group>
|
||||||
|
</template>
|
||||||
|
</v-card>
|
||||||
|
</v-dialog>
|
||||||
|
</v-btn>
|
||||||
|
</v-card-actions>
|
||||||
|
</v-card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Timer from "@/components/UI/Timer.vue"
|
||||||
|
import {baseURL} from "@/utils/axios-api";
|
||||||
|
import {computed, ref} from 'vue'
|
||||||
|
import {useAccountStore} from "@/store/AccountStore";
|
||||||
|
import defaultImage from '../../assets/emblem.png'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {Timer},
|
||||||
|
emits: ['openVoteModal', 'openEditVoteModal', 'deleteVoting', 'openResultModal'],
|
||||||
|
props: {
|
||||||
|
isFinished: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
voteCard: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {
|
||||||
|
return {
|
||||||
|
id: 0,
|
||||||
|
name: "",
|
||||||
|
description: "",
|
||||||
|
files: [],
|
||||||
|
dateend: new Date(new Date().getTime() + 600000),
|
||||||
|
is_passed: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setup(props) {
|
||||||
|
const timeChange = ref(false)
|
||||||
|
const youSure = ref(false)
|
||||||
|
const isFinished = ref(false);
|
||||||
|
const accountStore = useAccountStore();
|
||||||
|
const user = accountStore.user;
|
||||||
|
|
||||||
|
const images = computed(() => {
|
||||||
|
return props.voteCard.files.length > 0 ? props.voteCard.files : ['']
|
||||||
|
})
|
||||||
|
|
||||||
|
const date = new Date();
|
||||||
|
const endDate = new Date(props.voteCard.dateend);
|
||||||
|
const distance = endDate.getTime() - date.getTime();
|
||||||
|
|
||||||
|
if (distance <= 0) {
|
||||||
|
isFinished.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {timeChange, baseURL, images, youSure, isFinished, user, defaultImage}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,568 @@
|
|||||||
|
<template>
|
||||||
|
|
||||||
|
<v-row class="pt-2 mx-1 flex-column fill-height flex-grow-0 " >
|
||||||
|
<template v-if="isVoteCreated">
|
||||||
|
<v-card class="d-flex flex-column flex-grow-1 flex-shrink-0 text-center pa-8" flat>
|
||||||
|
<v-spacer></v-spacer>
|
||||||
|
<div class>
|
||||||
|
<v-icon color="success" size="48">mdi-check-circle</v-icon>
|
||||||
|
<h2 class="mt-4">Голосование создано!</h2>
|
||||||
|
<v-btn class="mt-4" color="teal-darken-4" @click="resetForm">Создать ещё</v-btn>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<v-spacer></v-spacer>
|
||||||
|
</v-card>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
|
||||||
|
<div class="v-col flex-grow-1 flex-shrink-0 ">
|
||||||
|
|
||||||
|
<v-stepper v-model="step" editable class="d-flex flex-column fill-height">
|
||||||
|
<v-stepper-header class="flex-grow-0 flex-shrink-1">
|
||||||
|
<v-stepper-item :complete="step > 0" step="1">Основная информация
|
||||||
|
|
||||||
|
</v-stepper-item>
|
||||||
|
<v-divider></v-divider>
|
||||||
|
<v-stepper-item :complete="step > 1" step="2">Создание опроса</v-stepper-item>
|
||||||
|
<v-divider></v-divider>
|
||||||
|
<v-stepper-item :complete="step > 2" step="3">Подтверждение</v-stepper-item>
|
||||||
|
</v-stepper-header>
|
||||||
|
|
||||||
|
<v-stepper-window class="fill-height">
|
||||||
|
<!-- Основная информация -->
|
||||||
|
<v-stepper-window-item step="1" class="fill-height">
|
||||||
|
<v-card flat class="fill-height d-flex flex-column ">
|
||||||
|
<v-card-title>Основная информация</v-card-title>
|
||||||
|
<v-card-text class="d-flex flex-column overflow-auto">
|
||||||
|
<v-text-field v-model="form.title" :rules="[rules.required]" label="Название голосования"
|
||||||
|
class="flex-grow-0 flex-shrink-1"
|
||||||
|
variant="underlined"></v-text-field>
|
||||||
|
<div class="flex-grow-1 flex-shrink-0">
|
||||||
|
|
||||||
|
<v-textarea v-model="form.description" :rules="[rules.required]" label="Описание"
|
||||||
|
|
||||||
|
variant="outlined"></v-textarea>
|
||||||
|
</div>
|
||||||
|
<v-divider></v-divider>
|
||||||
|
<div class="flex-grow-0 flex-shrink-1">
|
||||||
|
<div class="pt-2 text-overline text-grey">Дата и время:</div>
|
||||||
|
<div class="d-flex justify-space-around">
|
||||||
|
<div class="d-flex ga-3 align-center">
|
||||||
|
<h6 class="text-subtitle-1 pt-2">начало:</h6>
|
||||||
|
<date-select :datedefault="form.startDate" @returndate="returnstart" />
|
||||||
|
<v-select v-model="selectedTimeStart" :items="timeOptions" density="compact" variant="plain"
|
||||||
|
hide-details>
|
||||||
|
<template v-slot:prepend-inner>
|
||||||
|
<v-icon icon="mdi-timer" size="xsmall" color="red"></v-icon>
|
||||||
|
</template>
|
||||||
|
</v-select>
|
||||||
|
</div>
|
||||||
|
<div class="d-flex ga-3 align-center">
|
||||||
|
<h6 class="text-subtitle-1 pt-2">окончание:</h6>
|
||||||
|
<date-select :datedefault="form.endDate" @returndate="returnend" />
|
||||||
|
<v-select v-model="selectedTimeEnd" :items="timeOptions" density="compact" outlined variant="plain"
|
||||||
|
hide-details>
|
||||||
|
<template v-slot:prepend-inner>
|
||||||
|
<v-icon icon="mdi-timer" size="xsmall" color="red"></v-icon>
|
||||||
|
</template>
|
||||||
|
</v-select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</v-card-text>
|
||||||
|
|
||||||
|
<v-card-actions>
|
||||||
|
<v-btn color="teal-darken-4" size="medium" @click="step = 1">Далее</v-btn>
|
||||||
|
</v-card-actions>
|
||||||
|
</v-card>
|
||||||
|
</v-stepper-window-item>
|
||||||
|
|
||||||
|
<!-- Создание опроса -->
|
||||||
|
<v-stepper-window-item step="2" class="fill-height">
|
||||||
|
|
||||||
|
<v-card flat class="fill-height d-flex flex-column">
|
||||||
|
<v-card-title>Создание опроса:</v-card-title>
|
||||||
|
<v-card-text>
|
||||||
|
<transition-group name="list" tag="div">
|
||||||
|
<div v-for="(question, index) in form.questions" :key="index" class="mb-4">
|
||||||
|
<div class="d-flex">
|
||||||
|
<v-text-field density="comfortable" v-model="question.text" :label="'Вопрос ' + (index + 1)"
|
||||||
|
:rules="[rules.required]" variant="underlined">
|
||||||
|
<template v-slot:append>
|
||||||
|
<v-btn color="error" icon="mdi-delete" size="small" @click="removeQuestion(index)" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
</v-text-field>
|
||||||
|
</div>
|
||||||
|
<v-file-input density="comfortable" v-model="question.image" accept="image/*"
|
||||||
|
label="Картинка для вопроса" variant="outlined"></v-file-input>
|
||||||
|
<v-divider></v-divider>
|
||||||
|
<div class="py-2 text-overline text-grey">Настройки вопроса</div>
|
||||||
|
<div class="v-row ">
|
||||||
|
|
||||||
|
<v-col cols="auto" class="align-self-center font-weight-bold py-0">
|
||||||
|
Тип ответа
|
||||||
|
</v-col>
|
||||||
|
<v-col cols="3" class="py-0 align-self-center ">
|
||||||
|
|
||||||
|
<v-select density="compact" v-model="question.settings.choice" :items="questionTypes"
|
||||||
|
@update:model-value="question.answers=[]"
|
||||||
|
:list-props="{density:'compact'}"
|
||||||
|
item-title="name" item-value="choice" label="" hide-details variant="outlined"></v-select>
|
||||||
|
<!-- choice -->
|
||||||
|
|
||||||
|
</v-col>
|
||||||
|
<v-spacer/>
|
||||||
|
<v-col cols="auto" class="align-self-center font-weight-bold">
|
||||||
|
Число возможных ответов
|
||||||
|
</v-col>
|
||||||
|
<v-col cols="1" class="">
|
||||||
|
<v-text-field density="compact" v-model="question.settings.multiChoice"
|
||||||
|
:rules="[rules.required && question.settings.multiChoice > 0]" hide-details type="number"
|
||||||
|
min="1" variant="outlined">
|
||||||
|
<template v-slot:prepend>
|
||||||
|
|
||||||
|
</template>
|
||||||
|
</v-text-field>
|
||||||
|
</v-col>
|
||||||
|
</div>
|
||||||
|
<div class="v-row">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<v-card-text class="px-0">
|
||||||
|
<div v-if="question.settings.choice === 'free'">
|
||||||
|
<transition-group name="list" tag="div">
|
||||||
|
<div v-for="(answer, ind) in question.answers" :key="ind" class="d-flex align-start mb-4">
|
||||||
|
<v-text-field v-model="answer.text" :label="'Ответ ' + (ind + 1)" :rules="[rules.required]"
|
||||||
|
class="mr-4" variant="outlined" density="compact"></v-text-field>
|
||||||
|
<v-file-input v-model="answer.image" accept="image/*" dense hide-details label="Картинка"
|
||||||
|
variant="outlined" density="compact"></v-file-input>
|
||||||
|
<v-btn class="ms-1" color="error" icon="mdi-delete" size="small" @click="removeAnswer(index,ind)">
|
||||||
|
|
||||||
|
</v-btn>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</transition-group>
|
||||||
|
|
||||||
|
<div class="d-flex justify-start">
|
||||||
|
<v-btn size="small" color="teal-darken-4" @click="addAnswer(index)">Добавить ответ</v-btn>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
|
||||||
|
<div class="v-row">
|
||||||
|
|
||||||
|
<v-radio-group class="text-caption" inline v-model="question.settings.onlyDep">
|
||||||
|
<template v-slot:label>
|
||||||
|
<div class="text-body-2 font-weight-bold">Голосование по отделам:</div>
|
||||||
|
</template>
|
||||||
|
<v-radio v-for="x in onlyDepdict" :key="x.name" :value=x.value>
|
||||||
|
<template v-slot:label>
|
||||||
|
<div class="text-caption">{{ x.name }}</div>
|
||||||
|
</template>
|
||||||
|
</v-radio>
|
||||||
|
</v-radio-group>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<v-autocomplete
|
||||||
|
class=" text-no-wrap"
|
||||||
|
v-model="question.selectedEmployees" :items="allEmployeesgroupedbydep"
|
||||||
|
item-title="fio" item-value="id" label="Выберите сотрудников" multiple variant="outlined"
|
||||||
|
density="compact"
|
||||||
|
@update:model-value="(selected)=>question.answers=question.answers.filter(e=>selected.includes(e.text))"
|
||||||
|
>
|
||||||
|
<template #prepend-item>
|
||||||
|
<v-checkbox class="pa-0" :model-value="question.selectedEmployees.length==allEmployees.length" label="Все"
|
||||||
|
@update:model-value="handleSelectAll(question.selectedEmployees.length==allEmployees.length, index)"></v-checkbox>
|
||||||
|
</template>
|
||||||
|
<template #selection="{item}">
|
||||||
|
<v-chip
|
||||||
|
:prepend-avatar="checkremote(`${spravURL}${item.raw.login}.jpg`)"
|
||||||
|
>
|
||||||
|
|
||||||
|
{{ item.raw.familyname }}</v-chip>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<template #item="data">
|
||||||
|
|
||||||
|
<template v-if="typeof data.item.raw !== 'object'">
|
||||||
|
<v-divider/>
|
||||||
|
<v-list-group class='pa-4 text-overline text-grey' v-text="data.item.raw"></v-list-group>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<v-list-item
|
||||||
|
|
||||||
|
slim
|
||||||
|
density="compact"
|
||||||
|
:append-avatar="checkremote(`${spravURL}${data.item.raw.login}.jpg`)"
|
||||||
|
@click="onEmployeesChange(data.item.raw.id, index)"
|
||||||
|
>
|
||||||
|
<template #prepend>
|
||||||
|
|
||||||
|
<v-checkbox hide-details
|
||||||
|
|
||||||
|
:model-value="question.selectedEmployees.includes(data.item.raw.id)"
|
||||||
|
density="compact"></v-checkbox>
|
||||||
|
</template>
|
||||||
|
<v-list-item-title class="text-third" v-text="data.item.raw.fio"></v-list-item-title>
|
||||||
|
</v-list-item>
|
||||||
|
|
||||||
|
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</v-autocomplete>
|
||||||
|
<transition-group name="list" tag="div">
|
||||||
|
<div v-for="(person, ind) in question.answers" :key="person" class="v-row align-center mb-4">
|
||||||
|
<v-col cols="7" class="py-0" >
|
||||||
|
|
||||||
|
<v-chip :prepend-avatar="checkremote(`${spravURL}${findEmployeeById(person.text)?.login}.jpg`)" :text="findEmployeeById(person.text)?.fio ">
|
||||||
|
|
||||||
|
|
||||||
|
</v-chip>
|
||||||
|
</v-col>
|
||||||
|
<v-col class="py-0 d-flex" cols="5">
|
||||||
|
<v-file-input v-model="person.image" accept="image/*" dense hide-details label="Картинка"
|
||||||
|
variant="outlined" density="compact"></v-file-input>
|
||||||
|
<v-btn class="ms-1" color="error" icon="mdi-delete" size="small"
|
||||||
|
@click="question.selectedEmployees.splice(ind,1); removeAnswer(index,ind)">
|
||||||
|
|
||||||
|
</v-btn>
|
||||||
|
</v-col>
|
||||||
|
</div>
|
||||||
|
</transition-group>
|
||||||
|
</div>
|
||||||
|
</v-card-text>
|
||||||
|
</div>
|
||||||
|
</transition-group>
|
||||||
|
<v-divider class="ma-2 pa-1"></v-divider>
|
||||||
|
<div class="d-flex justify-center">
|
||||||
|
|
||||||
|
<v-btn size="small" color="orange-darken-4" @click="addQuestion">Добавить вопрос</v-btn>
|
||||||
|
</div>
|
||||||
|
</v-card-text>
|
||||||
|
<v-card-actions>
|
||||||
|
<v-btn color="teal-darken-4" size="medium" @click="step -= 1">Назад</v-btn>
|
||||||
|
<v-btn color="teal-darken-4" size="medium" @click="step = 2">Далее</v-btn>
|
||||||
|
</v-card-actions>
|
||||||
|
</v-card>
|
||||||
|
|
||||||
|
</v-stepper-window-item>
|
||||||
|
|
||||||
|
<!-- Подтверждение -->
|
||||||
|
<v-stepper-window-item step="3" class="fill-height">
|
||||||
|
|
||||||
|
<v-card flat class="fill-height d-flex flex-column">
|
||||||
|
<v-card-title>Подтверждение</v-card-title>
|
||||||
|
<v-card-text>
|
||||||
|
<v-alert v-if="errorMessage" class="mb-4 " type="error">
|
||||||
|
{{ errorMessage }}
|
||||||
|
</v-alert>
|
||||||
|
|
||||||
|
<p><v-icon size="xsmall" :class="form.title===null||form.title.length==0?'':'opacity-0'" color='red' icon="mdi-alert"/><strong class="px-2">Название:</strong> {{ form.title }}</p>
|
||||||
|
<p><v-icon size="xsmall" :class="form.description===null||form.description.length==0?'':'opacity-0'" color='red' icon="mdi-alert"/><strong class="px-2">Описание:</strong> {{ form.description }}</p>
|
||||||
|
<p><strong class="px-2">Дата начала:</strong> {{ form.startDate.toLocaleDateString() }}</p>
|
||||||
|
<p><strong class="px-2">Дата окончания:</strong> {{ form.endDate.toLocaleDateString() }}</p>
|
||||||
|
<p><strong class="px-2">Вопросы:</strong></p>
|
||||||
|
|
||||||
|
<v-card v-for="(question, index) in form.questions" :key="index" class="mb-4 pa-3">
|
||||||
|
<div class="pa-2">
|
||||||
|
|
||||||
|
<p><strong>Вопрос {{ index + 1 }}:</strong> {{ question.text }} ({{ question.type }})</p>
|
||||||
|
|
||||||
|
<div v-if="question.settings.choice === 'free' && question.answers.length">
|
||||||
|
<p><strong>Варианты ответов:</strong></p>
|
||||||
|
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li v-for="(answer, answerIndex) in question.answers" :key="answerIndex">
|
||||||
|
{{ answer.text }}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div v-if="question.settings.choice === 'employee' && question.answers.length">
|
||||||
|
<div>Количество допустимых ответов: {{ question.settings.multiChoice }}</div>
|
||||||
|
<div class="">Голосование по отделам: {{ onlyDepdict.find(e=>e.value===question.settings.onlyDep).name}}</div>
|
||||||
|
<p><strong>Выбранные сотрудники:</strong></p>
|
||||||
|
<ul>
|
||||||
|
<li v-for="employeeId in question.answers" :key="employeeId">
|
||||||
|
{{ findEmployeeById(employeeId.text).fio }}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</v-card>
|
||||||
|
|
||||||
|
</v-card-text>
|
||||||
|
<v-card-actions>
|
||||||
|
<v-btn color="teal-darken-4" size="medium" @click="step -= 1">Назад</v-btn>
|
||||||
|
<v-btn :disabled="errorMessage!=''" color="teal-darken-4" size="medium" @click="saveVoting">Сохранить</v-btn>
|
||||||
|
</v-card-actions>
|
||||||
|
|
||||||
|
</v-card>
|
||||||
|
</v-stepper-window-item>
|
||||||
|
|
||||||
|
</v-stepper-window>
|
||||||
|
</v-stepper>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</template>
|
||||||
|
</v-row>
|
||||||
|
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { computed, ref, watch } from "vue";
|
||||||
|
import { spravURL } from "@/utils/axios-api";
|
||||||
|
import { createVote, getEmployees } from "@/utils/axios-api";
|
||||||
|
import DateSelect from "@/components/UI/date-select.vue";
|
||||||
|
import { useAccountStore } from "@/store/AccountStore";
|
||||||
|
import { checkremote } from "@/utils/universal_functions";
|
||||||
|
export default {
|
||||||
|
components: { DateSelect },
|
||||||
|
emits: ['updating'],
|
||||||
|
setup(props, { emit }) {
|
||||||
|
const accountStore = useAccountStore();
|
||||||
|
const user = accountStore.user;
|
||||||
|
const step = ref(0);
|
||||||
|
const isVoteCreated = ref(false);
|
||||||
|
const form = ref({
|
||||||
|
title: "",
|
||||||
|
description: "",
|
||||||
|
startDate: new Date(),
|
||||||
|
endDate: new Date(new Date().setDate(new Date().getDate() + 14)),
|
||||||
|
questions: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
const rules = {
|
||||||
|
required: (value) => !!value || "Это поле обязательно для заполнения",
|
||||||
|
};
|
||||||
|
|
||||||
|
const currentQuestionIndex = ref(0);
|
||||||
|
const questionTypes = [{ name: "Ввести вручную", choice: 'free' }, { name: "Выбрать сотрудника", choice: 'employee' }];
|
||||||
|
|
||||||
|
const groupedEmployees = ref([]);
|
||||||
|
const allEmployees = computed(() => [
|
||||||
|
...groupedEmployees.value,
|
||||||
|
]);
|
||||||
|
|
||||||
|
getEmployees()
|
||||||
|
.then(r => groupedEmployees.value = r)
|
||||||
|
|
||||||
|
const currentQuestion = computed(() =>
|
||||||
|
form.value.questions[currentQuestionIndex.value] || null
|
||||||
|
);
|
||||||
|
const allEmployeesgroupedbydep = computed(()=>{
|
||||||
|
let groupped = []
|
||||||
|
for (let x of allEmployees.value.sort((a,b)=>a.id_dict_department-b.id_dict_department)){
|
||||||
|
if(!groupped.includes(x.department))groupped.push(x.department)
|
||||||
|
groupped.push(x)
|
||||||
|
}
|
||||||
|
return groupped
|
||||||
|
})
|
||||||
|
const findEmployeeById = (id) =>
|
||||||
|
groupedEmployees.value.find((employee) => employee.id === id) || {};
|
||||||
|
|
||||||
|
|
||||||
|
const handleSelectAll = (selected, index) => {
|
||||||
|
console.log(selected, index);
|
||||||
|
if (!selected) {
|
||||||
|
form.value.questions[index].answers = groupedEmployees.value.map((employee) => ({
|
||||||
|
text: employee.id,
|
||||||
|
image: null,
|
||||||
|
}));
|
||||||
|
form.value.questions[index].selectedEmployees = groupedEmployees.value.map(employee => employee.id);
|
||||||
|
} else {
|
||||||
|
form.value.questions[index].answers = [];
|
||||||
|
form.value.questions[index].selectedEmployees=[]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const isAllSelected = computed(() => currentQuestion.value.answers.length === groupedEmployees.value.length);
|
||||||
|
|
||||||
|
const addQuestion = () => {
|
||||||
|
form.value.questions.push({
|
||||||
|
text: "",
|
||||||
|
settings: { choice: "free", multiChoice: 1, onlyDep: null },
|
||||||
|
image: null,
|
||||||
|
answers: [],
|
||||||
|
selectedEmployees: []
|
||||||
|
});
|
||||||
|
currentQuestionIndex.value = form.value.questions.length - 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeQuestion = (index) => {
|
||||||
|
form.value.questions.splice(index, 1);
|
||||||
|
if (currentQuestionIndex.value >= form.value.questions.length) {
|
||||||
|
currentQuestionIndex.value = form.value.questions.length - 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const addAnswer = (index) => {
|
||||||
|
if (currentQuestion.value) {
|
||||||
|
form.value.questions[index].answers.push({ text: "", image: null });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeAnswer = (index,ind) => {
|
||||||
|
// if (currentQuestion.value) {
|
||||||
|
form.value.questions[index].answers.splice(ind, 1)
|
||||||
|
// currentQuestion.value.answers.splice(index, 1);
|
||||||
|
// }
|
||||||
|
};
|
||||||
|
|
||||||
|
const errorMessage = ref("");
|
||||||
|
|
||||||
|
const saveVoting = async () => {
|
||||||
|
if (!form.value.title || !form.value.description || form.value.questions.length < 1) {
|
||||||
|
errorMessage.value = "Все обязательные поля должны быть заполнены";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const response = await createVote(form.value);
|
||||||
|
console.log("Голосование успешно создано:", response);
|
||||||
|
isVoteCreated.value = true;
|
||||||
|
emit('updating', 'active')
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Ошибка при создании голосования:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const resetForm = () => {
|
||||||
|
form.value = {
|
||||||
|
title: "",
|
||||||
|
description: "",
|
||||||
|
startDate: new Date(),
|
||||||
|
endDate: new Date(new Date().setDate(new Date().getDate() + 14)),
|
||||||
|
questions: [],
|
||||||
|
};
|
||||||
|
step.value = 0;
|
||||||
|
isVoteCreated.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const timeOptions = Array.from({ length: 48 }, (_, i) => {
|
||||||
|
const hours = String(Math.floor(i / 2)).padStart(2, "0");
|
||||||
|
const minutes = i % 2 === 0 ? "00" : "30";
|
||||||
|
return `${hours}:${minutes}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
const selectedTimeStart = ref(
|
||||||
|
`${(form.value.startDate.getHours()+1).toString().padStart(2, "0")}:00`
|
||||||
|
);
|
||||||
|
|
||||||
|
const selectedTimeEnd = ref(
|
||||||
|
`${(form.value.endDate.getHours()+1).toString().padStart(2, "0")}:00`
|
||||||
|
);
|
||||||
|
|
||||||
|
watch(form.value, () => {
|
||||||
|
if (!form.value.title || !form.value.description || form.value.questions < 1) {
|
||||||
|
errorMessage.value = "Все обязательные поля должны быть заполнены";
|
||||||
|
} else {
|
||||||
|
errorMessage.value = "";
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(selectedTimeStart, () => {
|
||||||
|
updateStartDate()
|
||||||
|
})
|
||||||
|
watch(selectedTimeEnd, () => {
|
||||||
|
updateEndDate()
|
||||||
|
})
|
||||||
|
|
||||||
|
const updateStartDate = () => {
|
||||||
|
const [hours, minutes] = selectedTimeStart.value.split(":").map(Number);
|
||||||
|
form.value.startDate.setHours(hours, minutes);
|
||||||
|
};
|
||||||
|
const updateEndDate = () => {
|
||||||
|
const [hours, minutes] = selectedTimeEnd.value.split(":").map(Number);
|
||||||
|
form.value.endDate.setHours(hours, minutes);
|
||||||
|
};
|
||||||
|
|
||||||
|
const returnstart = (dates) => {
|
||||||
|
form.value.startDate = dates
|
||||||
|
}
|
||||||
|
|
||||||
|
const returnend = (dates) => {
|
||||||
|
form.value.endDate = dates
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedEmployees = ref([]);
|
||||||
|
|
||||||
|
const onEmployeesChange = (selected, index) => {
|
||||||
|
let ind = form.value.questions[index].selectedEmployees.findIndex(e=>e==selected)
|
||||||
|
if(ind>-1){
|
||||||
|
form.value.questions[index].selectedEmployees.splice(ind,1)
|
||||||
|
let answ =form.value.questions[index].answers.findIndex(a=>a.text==selected)
|
||||||
|
form.value.questions[index].answers.splice(answ,1)
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
form.value.questions[index].selectedEmployees.push(selected)
|
||||||
|
form.value.questions[index].answers.push({ text: selected, image: null });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onlyDepdict = [{name:'За любого сотрудника' ,value:null},{name:"Кроме своего отдела" ,value:false}, {name:"Только за свой отдел" ,value:true}]
|
||||||
|
return {
|
||||||
|
onlyDepdict,
|
||||||
|
allEmployeesgroupedbydep,
|
||||||
|
onEmployeesChange,
|
||||||
|
returnend,
|
||||||
|
returnstart,
|
||||||
|
step,
|
||||||
|
form,
|
||||||
|
questionTypes,
|
||||||
|
addQuestion,
|
||||||
|
removeQuestion,
|
||||||
|
addAnswer,
|
||||||
|
removeAnswer,
|
||||||
|
findEmployeeById,
|
||||||
|
saveVoting,
|
||||||
|
isVoteCreated,
|
||||||
|
resetForm,
|
||||||
|
rules,
|
||||||
|
errorMessage,
|
||||||
|
timeOptions,
|
||||||
|
selectedTimeStart,
|
||||||
|
selectedTimeEnd,
|
||||||
|
allEmployees,
|
||||||
|
handleSelectAll,
|
||||||
|
isAllSelected,
|
||||||
|
checkremote,
|
||||||
|
spravURL
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.v-input--horizontal .v-input__prepend {
|
||||||
|
margin-inline-end: 4px;
|
||||||
|
}
|
||||||
|
.list-enter-active,
|
||||||
|
.list-leave-active {
|
||||||
|
transition: all 0.5s ease;
|
||||||
|
}
|
||||||
|
.list-enter-from,
|
||||||
|
.list-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateX(50px);
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -1,19 +1,18 @@
|
|||||||
<template>
|
<template>
|
||||||
|
|
||||||
<v-form @submit="voteSend" ref="vot" >
|
<v-form ref="vot" @submit="voteSend">
|
||||||
<v-card id="scroll-window-chekbox" :height="heightel" elevation="0">
|
<v-card id="scroll-window-chekbox" :height="heightel" elevation="0">
|
||||||
<!-- Форма голосования -->
|
<!-- Форма голосования -->
|
||||||
|
|
||||||
<v-virtual-scroll :items="persons">
|
<v-virtual-scroll :items="persons">
|
||||||
<template v-slot:default="{ item }">
|
<template v-slot:default="{ item }">
|
||||||
<v-checkbox hide-details="true" v-model="vote" :id="item.fio" :value="item.fio" :label="item.fio" required />
|
<v-checkbox :id="item.fio" v-model="vote" :label="item.fio" :value="item.fio" hide-details="true" required/>
|
||||||
</template>
|
</template>
|
||||||
</v-virtual-scroll>
|
</v-virtual-scroll>
|
||||||
</v-card>
|
</v-card>
|
||||||
|
|
||||||
<v-dialog max-width="500" v-model="dialog">
|
<v-dialog v-model="dialog" max-width="500">
|
||||||
<!-- <template v-slot:activator>
|
<!-- <template v-slot:activator>
|
||||||
|
|
||||||
</template> -->
|
</template> -->
|
||||||
<template v-slot:default>
|
<template v-slot:default>
|
||||||
<v-card class="justify-center align-center">
|
<v-card class="justify-center align-center">
|
||||||
@@ -24,14 +23,17 @@
|
|||||||
<v-card-title v-else>Кандидат не выбран повторите голосование</v-card-title>
|
<v-card-title v-else>Кандидат не выбран повторите голосование</v-card-title>
|
||||||
<v-col class="d-flex flex-rows justify-center align-center" cols="12">
|
<v-col class="d-flex flex-rows justify-center align-center" cols="12">
|
||||||
<v-col cols="2">
|
<v-col cols="2">
|
||||||
<v-btn v-if="approve_name" variant="elevated" color="green-darken-1"
|
<v-btn v-if="approve_name" color="green-darken-1" variant="elevated"
|
||||||
@click="voteSend">ДА</v-btn>
|
@click="voteSend">ДА
|
||||||
<v-btn v-else variant="elevated" color="green-darken-1" @click="voteSend"
|
</v-btn>
|
||||||
disabled>ДА</v-btn>
|
<v-btn v-else color="green-darken-1" disabled variant="elevated"
|
||||||
|
@click="voteSend">ДА
|
||||||
|
</v-btn>
|
||||||
</v-col>
|
</v-col>
|
||||||
<v-col cols="2">
|
<v-col cols="2">
|
||||||
<v-btn variant="elevated" color="red-darken-1"
|
<v-btn color="red-darken-1" variant="elevated"
|
||||||
@click="dialog = false">НЕТ</v-btn>
|
@click="dialog = false">НЕТ
|
||||||
|
</v-btn>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-card>
|
</v-card>
|
||||||
@@ -42,21 +44,22 @@
|
|||||||
|
|
||||||
</template>
|
</template>
|
||||||
<script scope>
|
<script scope>
|
||||||
import { ref, computed } from "vue";
|
import {computed, ref} from "vue";
|
||||||
import { clearAxios, axiosApiInstance } from "@/utils/axios-api";
|
import {axiosApiInstance} from "@/utils/axios-api";
|
||||||
import {useAccountStore} from '@/store/AccountStore';
|
import {useAccountStore} from '@/store/AccountStore';
|
||||||
import Vote from "@/views/Vote.vue";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
||||||
props: {type_fetch:{type:String, default:'best'},
|
props: {
|
||||||
|
type_fetch: {type: String, default: 'best'},
|
||||||
persons: {
|
persons: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => []
|
default: () => []
|
||||||
},
|
},
|
||||||
myrealdep: {
|
myrealdep: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default:()=>{}
|
default: () => {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setup(props, {emit}) {
|
setup(props, {emit}) {
|
||||||
@@ -87,7 +90,6 @@ export default {
|
|||||||
// };
|
// };
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const approveCandidate = () => {
|
const approveCandidate = () => {
|
||||||
if (vote.value === 'False' || vote.value === '') {
|
if (vote.value === 'False' || vote.value === '') {
|
||||||
approve_name.value = false;
|
approve_name.value = false;
|
||||||
@@ -112,8 +114,7 @@ export default {
|
|||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
).then(res=>
|
).then(res => {
|
||||||
{
|
|
||||||
dialog.value = false
|
dialog.value = false
|
||||||
window.location.reload()
|
window.location.reload()
|
||||||
});
|
});
|
||||||
@@ -137,8 +138,6 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
@@ -0,0 +1,236 @@
|
|||||||
|
<template>
|
||||||
|
<v-container style="height: 85vh">
|
||||||
|
<div class="text-end">
|
||||||
|
<v-btn class="" color="red-darken-1" density="compact" icon="mdi-close-thick" size="small"
|
||||||
|
@click="$emit('closer')">
|
||||||
|
</v-btn>
|
||||||
|
</div>
|
||||||
|
<v-card-title class="text-subtitle-1">Результат голосования: {{ title }}</v-card-title>
|
||||||
|
<v-card-subtitle class="text-subtitle-2">{{ description }}</v-card-subtitle>
|
||||||
|
<v-tabs v-model="activeTab" class="mb-4">
|
||||||
|
<v-tab
|
||||||
|
v-for="(question, questionIndex) in questions"
|
||||||
|
:key="questionIndex"
|
||||||
|
>
|
||||||
|
<template v-if="shouldShowTooltip(question.name || 'Без названия', 10)">
|
||||||
|
<v-tooltip bottom>
|
||||||
|
<template v-slot:activator="{ props }">
|
||||||
|
<span v-bind="props">
|
||||||
|
{{ truncateText(question.name || 'Без названия', 10) }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<span>{{ question.name || 'Без названия' }}</span>
|
||||||
|
</v-tooltip>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<span>{{ truncateText(question.name || 'Без названия', 10) }}</span>
|
||||||
|
</template>
|
||||||
|
</v-tab>
|
||||||
|
<v-tab>Не голосовали</v-tab>
|
||||||
|
</v-tabs>
|
||||||
|
|
||||||
|
<v-tabs-window v-model="activeTab">
|
||||||
|
<v-tabs-window-item v-for="(question, questionIndex) in questions" :key="questionIndex">
|
||||||
|
<v-row>
|
||||||
|
<v-col cols="12">
|
||||||
|
<h3 class="text-center">{{ question.name }}</h3>
|
||||||
|
<v-card-title class="d-flex ga-2 align-center">
|
||||||
|
<h4 class="text-teal-darken-4">Победитель:</h4>
|
||||||
|
<h3>{{ getWinner(question).employee?.fio || getWinner(question).name }} 🏆</h3>
|
||||||
|
</v-card-title>
|
||||||
|
<v-card-subtitle>
|
||||||
|
Количество голосов: {{ getWinner(question)?.count || 0 }}
|
||||||
|
</v-card-subtitle>
|
||||||
|
</v-col>
|
||||||
|
<v-col cols="12">
|
||||||
|
<v-card class="mb-4">
|
||||||
|
<v-card-title class="text-teal-darken-3">Топ {{ getTopResults(question).length }}</v-card-title>
|
||||||
|
<v-card-text>
|
||||||
|
<v-list style="max-height: 45vh; overflow-y: auto;">
|
||||||
|
<v-list-item
|
||||||
|
v-for="(answer, answerIndex) in getTopResults(question)"
|
||||||
|
:key="answerIndex"
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
<v-avatar v-if="answer.file === null && answer.employee"
|
||||||
|
:image="checkremote(`${spravURL()}${answer.employee.login}.jpg`)"
|
||||||
|
class="cursor-pointer"
|
||||||
|
@click.stop="opendialog(checkremote(`${spravURL()}${answer.employee.login}.jpg`))"/>
|
||||||
|
<v-avatar v-if="answer.file !== null" :image="baseURL.slice(0, -1) + answer.file"
|
||||||
|
class="cursor-pointer"
|
||||||
|
@click.stop="opendialog(answer)"/>
|
||||||
|
<strong class="ml-4">{{ answer.employee ? answer.employee.fio : answer.name }}</strong>:
|
||||||
|
{{ answer.count }}
|
||||||
|
{{ voteCount(answer.count) }}
|
||||||
|
<template v-if="answer.employee">
|
||||||
|
<br/>
|
||||||
|
<small>Отдел: {{ answer.employee ? answer.employee.department : '' }}</small>
|
||||||
|
<br/>
|
||||||
|
<small>Должность: {{ answer.employee ? answer.employee.post : '' }}</small>
|
||||||
|
</template>
|
||||||
|
</p>
|
||||||
|
<v-progress-linear
|
||||||
|
:model-value="getPercentage(answer.count, question)"
|
||||||
|
color="teal-darken-4"
|
||||||
|
height="13"
|
||||||
|
rounded
|
||||||
|
striped
|
||||||
|
>
|
||||||
|
<template v-slot:default="{ value }">
|
||||||
|
<strong v-if="value < 50" class="text-grey-darken-3">{{ Math.ceil(value) }}%</strong>
|
||||||
|
<strong v-else class="text-grey-lighten-5">{{ Math.ceil(value) }}%</strong>
|
||||||
|
</template>
|
||||||
|
</v-progress-linear>
|
||||||
|
</v-list-item>
|
||||||
|
</v-list>
|
||||||
|
</v-card-text>
|
||||||
|
</v-card>
|
||||||
|
</v-col>
|
||||||
|
</v-row>
|
||||||
|
</v-tabs-window-item>
|
||||||
|
<v-tabs-window-item>
|
||||||
|
<v-card-title class="text-red-darken-3">Не голосовали:</v-card-title>
|
||||||
|
<v-card-item style="max-height: 60vh; overflow-y: auto;">
|
||||||
|
<template v-for="(voters, department) in groupedByDepartment" :key="department">
|
||||||
|
<v-list-item-title class="text-teal-darken-4">{{ department }}</v-list-item-title>
|
||||||
|
<v-list-item v-for="(voter, voterIndex) in voters" :key="voterIndex">
|
||||||
|
<!-- {{ voter.fio }}-->
|
||||||
|
<p>
|
||||||
|
<v-avatar :image="checkremote(`${spravURL()}${voter.login}.jpg`)"
|
||||||
|
class="cursor-pointer"
|
||||||
|
@click.stop="opendialog(checkremote(`${spravURL()}${voter.login}.jpg`))"/>
|
||||||
|
<strong class="ml-4">{{ voter.fio }}</strong>
|
||||||
|
(<small>{{ voter.post }}</small>) 👿
|
||||||
|
</p>
|
||||||
|
</v-list-item>
|
||||||
|
</template>
|
||||||
|
</v-card-item>
|
||||||
|
</v-tabs-window-item>
|
||||||
|
</v-tabs-window>
|
||||||
|
</v-container>
|
||||||
|
|
||||||
|
<v-dialog v-model="dialog" max-width="100vh">
|
||||||
|
<v-card max-height="800">
|
||||||
|
<v-card-title class="v-row">
|
||||||
|
<div class="v-col-auto">
|
||||||
|
{{ activepick.answer }}
|
||||||
|
</div>
|
||||||
|
<v-spacer></v-spacer>
|
||||||
|
<div>
|
||||||
|
<v-btn color="red-darken-1" density="compact" icon="mdi-close-thick" size="small" @click="dialog=false"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</v-card-title>
|
||||||
|
<v-card-item>
|
||||||
|
<v-img :src="activepick.file !== undefined ? baseURL.slice(0, -1) + activepick.file : activepick"
|
||||||
|
max-height="600"></v-img>
|
||||||
|
</v-card-item>
|
||||||
|
</v-card>
|
||||||
|
</v-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import {computed, ref} from 'vue';
|
||||||
|
import {baseURL, spravURL} from "@/utils/axios-api";
|
||||||
|
import {checkremote} from "@/utils/universal_functions";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'VoteResult',
|
||||||
|
methods: {
|
||||||
|
checkremote,
|
||||||
|
spravURL() {
|
||||||
|
return spravURL
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
baseURL() {
|
||||||
|
return baseURL
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ['closer'],
|
||||||
|
props: {
|
||||||
|
data: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
setup(props) {
|
||||||
|
const activeTab = ref(0);
|
||||||
|
const questions = computed(() => props.data.questions || []);
|
||||||
|
|
||||||
|
const title = props.data.name;
|
||||||
|
const description = props.data.description;
|
||||||
|
const nonVoters = props.data.nonvoting;
|
||||||
|
|
||||||
|
const getWinner = (question) => {
|
||||||
|
return question.answers.reduce(
|
||||||
|
(max, answer) => (answer.count > max.count ? answer : max),
|
||||||
|
{count: 0, employee: {fio: '', department: '', post: ''}, name: ''}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getTopResults = (question) => {
|
||||||
|
return [...question.answers].sort((a, b) => b.count - a.count).slice(0, 10);
|
||||||
|
};
|
||||||
|
|
||||||
|
const truncateText = (text, maxLength) => {
|
||||||
|
if (!text) return '';
|
||||||
|
return text.length > maxLength ? text.slice(0, maxLength) + '…' : text;
|
||||||
|
};
|
||||||
|
|
||||||
|
const shouldShowTooltip = (text, maxLength) => {
|
||||||
|
return text && text.length > maxLength;
|
||||||
|
};
|
||||||
|
|
||||||
|
const voteCount = (count) => {
|
||||||
|
let currentVote = '';
|
||||||
|
const lastDigit = count % 10;
|
||||||
|
if (lastDigit === 1) currentVote = 'голос'
|
||||||
|
if (lastDigit > 1) currentVote = 'голоса'
|
||||||
|
if (lastDigit > 4 || count === 0 || count === 11 || count === 12 || count === 13 || count === 14) currentVote = 'голосов'
|
||||||
|
return currentVote
|
||||||
|
}
|
||||||
|
|
||||||
|
const getPercentage = (count, question) => {
|
||||||
|
const totalVotes = question.answers.reduce((sum, answer) => sum + answer.count, 0);
|
||||||
|
return totalVotes > 0 ? (count / totalVotes) * 100 : 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const activepick = ref(null)
|
||||||
|
const dialog = ref(false)
|
||||||
|
const opendialog = (val) => {
|
||||||
|
dialog.value = true
|
||||||
|
activepick.value = val
|
||||||
|
}
|
||||||
|
|
||||||
|
const groupedByDepartment = computed(() => {
|
||||||
|
return nonVoters.reduce((groups, voter) => {
|
||||||
|
const department = voter.department || '';
|
||||||
|
if (!groups[department]) {
|
||||||
|
groups[department] = [];
|
||||||
|
}
|
||||||
|
groups[department].push(voter);
|
||||||
|
return groups;
|
||||||
|
}, {});
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
activepick,
|
||||||
|
opendialog,
|
||||||
|
dialog,
|
||||||
|
activeTab,
|
||||||
|
questions,
|
||||||
|
getWinner,
|
||||||
|
getTopResults,
|
||||||
|
truncateText,
|
||||||
|
shouldShowTooltip,
|
||||||
|
voteCount,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
getPercentage,
|
||||||
|
nonVoters,
|
||||||
|
groupedByDepartment
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -238,8 +238,8 @@ export default {
|
|||||||
if (!accountStore.cod2user) {
|
if (!accountStore.cod2user) {
|
||||||
|
|
||||||
clearAxios.get(`api/navigation/screensaver/`).then((data) => {
|
clearAxios.get(`api/navigation/screensaver/`).then((data) => {
|
||||||
console.log(data, 'saver--')
|
// console.log(data, 'saver--')
|
||||||
// scrimg.value = data.data[0].img;
|
scrimg.value = data.data.img;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -336,6 +336,11 @@ export default {
|
|||||||
ico: "mdi-vote",
|
ico: "mdi-vote",
|
||||||
path: "/vote",
|
path: "/vote",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Тестирование",
|
||||||
|
ico: "mdi-book-open-blank-variant",
|
||||||
|
path: "/test",
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: "Об инспекции",
|
name: "Об инспекции",
|
||||||
|
|||||||
@@ -140,18 +140,54 @@ const routes = [
|
|||||||
ico: "mdi-account",
|
ico: "mdi-account",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
path: "/vote",
|
path: "/vote",
|
||||||
name: "Vote",
|
name: "VoteHomePage",
|
||||||
component: () =>
|
component: () =>
|
||||||
import("@/views/Vote.vue")
|
import("@/views/VoteHomePage.vue"),
|
||||||
|
meta: {
|
||||||
|
title: "Голосование",
|
||||||
|
ico: "mdi-account",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/votehomepage",
|
path: "/vote/voting/:id",
|
||||||
name: "VoteHomePage",
|
name: "Voting",
|
||||||
|
component: () =>
|
||||||
|
import("@/views/VoteHomePage.vue"),
|
||||||
|
meta: {
|
||||||
|
title: "Голосование",
|
||||||
|
ico: "mdi-account",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/vote/vote-results/:id",
|
||||||
|
name: "VoteResults",
|
||||||
component: () =>
|
component: () =>
|
||||||
import("@/views/VoteHomePage.vue")
|
import("@/views/VoteHomePage.vue")
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/test",
|
||||||
|
name: "TestPage",
|
||||||
|
component: () =>
|
||||||
|
import("@/views/TestHomePage.vue"),
|
||||||
|
meta: {
|
||||||
|
title: "Тестирование",
|
||||||
|
ico: "mdi-account",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
path: '/secret',
|
||||||
|
name: 'Secret Page',
|
||||||
|
component: () =>
|
||||||
|
import("@/views/secret/SecretPage.vue")
|
||||||
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import {useAccountStore} from '@/store/AccountStore'
|
import {useAccountStore} from '@/store/AccountStore'
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
const spravURL = 'http://10.252.44.33/accounting6/images/photo/'
|
const spravURL = 'http://10.252.44.33/accounting6/images/photo/'
|
||||||
const spravURLBase = 'http://10.252.44.33/accounting6/'
|
const spravURLBase = 'http://10.252.44.33/accounting6/'
|
||||||
const baseURL = process.env.NODE_ENV === 'development' ? 'http://127.0.0.1:8000/' : `http://${window.location.host}/`;
|
const baseURL = process.env.NODE_ENV === 'development' ? 'http://127.0.0.1:8000/' : `http://${window.location.host}/`;
|
||||||
@@ -22,9 +23,7 @@ async function refreshToken() {
|
|||||||
localStorage.setItem('access', result.data.access)
|
localStorage.setItem('access', result.data.access)
|
||||||
|
|
||||||
return result.data.access;
|
return result.data.access;
|
||||||
}
|
} catch (e) {
|
||||||
|
|
||||||
catch(e) {
|
|
||||||
const accountStore = useAccountStore()
|
const accountStore = useAccountStore()
|
||||||
accountStore.logout()
|
accountStore.logout()
|
||||||
accountStore.cod2user.value = false
|
accountStore.cod2user.value = false
|
||||||
@@ -72,16 +71,12 @@ async error => {
|
|||||||
axiosApiInstance.defaults.headers.common['Authorization'] = `Bearer ${token}`;
|
axiosApiInstance.defaults.headers.common['Authorization'] = `Bearer ${token}`;
|
||||||
|
|
||||||
if (originalRequest.data) {
|
if (originalRequest.data) {
|
||||||
originalRequest.data = JSON.parse(originalRequest.data); }
|
originalRequest.data = JSON.parse(originalRequest.data);
|
||||||
|
}
|
||||||
|
|
||||||
return axiosApiInstance(originalRequest);
|
return axiosApiInstance(originalRequest);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
//
|
|
||||||
// if (window.location.pathname!='/auth') window.location.reload()
|
|
||||||
// window.location.reload()
|
|
||||||
|
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,13 +85,7 @@ async error => {
|
|||||||
|
|
||||||
async function getVotes(status) {
|
async function getVotes(status) {
|
||||||
try {
|
try {
|
||||||
const response = await axiosApiInstance.get(`/api/vote/getvotes?status=${status}`,
|
const response = await axiosApiInstance.get(`/api/vote/getvotes?status=${status}`);
|
||||||
// {
|
|
||||||
// params: {
|
|
||||||
// status,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
);
|
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Ошибка запроса голосования:', error);
|
console.error('Ошибка запроса голосования:', error);
|
||||||
@@ -104,22 +93,123 @@ async function getVotes(status) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getVotes('completed')
|
async function createVote(voteData) {
|
||||||
.then(data => {
|
|
||||||
console.log('Завершённые голосования:', data);
|
try {
|
||||||
})
|
|
||||||
.catch(err => {
|
const formData = new FormData();
|
||||||
console.error('Ошибка:', err);
|
voteData.questions.forEach(question => {
|
||||||
});
|
formData.append('questionsfiles', question.image)
|
||||||
|
if(!!question.image){
|
||||||
|
const {name,size,lastModified}=question.image
|
||||||
|
question.image={name,size,lastModified}
|
||||||
|
}
|
||||||
|
|
||||||
|
question.answers.forEach(answer=>{
|
||||||
|
|
||||||
|
formData.append('answersfiles', answer.image)
|
||||||
|
if(!!answer.image){
|
||||||
|
const {name,size,lastModified}=answer.image
|
||||||
|
answer.image={name,size,lastModified}
|
||||||
|
}
|
||||||
|
|
||||||
getVotes('active')
|
|
||||||
.then(data => {
|
|
||||||
console.log('Активные голосования:', data);
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
|
||||||
console.error('Ошибка:', err);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export { axiosApiInstance, clearAxios, baseURL,spravURL, spravURLBase, baseWS, getVotes }
|
formData.append('title', voteData.title);
|
||||||
|
formData.append('description', voteData.description);
|
||||||
|
formData.append('startDate', new Date(voteData.startDate).toISOString());
|
||||||
|
formData.append('endDate', new Date(voteData.endDate).toISOString());
|
||||||
|
formData.append('questions', JSON.stringify(voteData.questions));
|
||||||
|
|
||||||
|
|
||||||
|
const response = await axiosApiInstance.post('/api/vote/votecreate/', formData, {
|
||||||
|
headers: {'Content-Type': 'multipart/form-data'},
|
||||||
|
});
|
||||||
|
|
||||||
|
// return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка создания голосования:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getVoteDetail(id) {
|
||||||
|
try {
|
||||||
|
const response = await axiosApiInstance.get(`/api/vote/votedetail/${id}/`);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Ошибка получения деталей голосования:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// async function updateVote(id, updatedData) {
|
||||||
|
// try {
|
||||||
|
// const response = await axiosApiInstance.put(`/api/vote/votedetail/${id}/`, updatedData);
|
||||||
|
// return response.data;
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error("Ошибка обновления голосования:", error);
|
||||||
|
// throw error;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// async function patchVote(id, partialData) {
|
||||||
|
// try {
|
||||||
|
// const response = await axiosApiInstance.patch(`/api/vote/votedetail/${id}/`, partialData);
|
||||||
|
// return response.data;
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error("Ошибка частичного обновления голосования:", error);
|
||||||
|
// throw error;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
async function deleteVote(id) {
|
||||||
|
try {
|
||||||
|
await axiosApiInstance.delete(`/api/vote/votedetail/${id}/`);
|
||||||
|
console.log("Голосование успешно удалено");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Ошибка удаления голосования:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getEmployees() {
|
||||||
|
try {
|
||||||
|
const response = await axiosApiInstance.get(`api/vote/getdictemployee/`);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Ошибка получения всех сотрудников:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getVoteResult(id) {
|
||||||
|
try {
|
||||||
|
const response = await axiosApiInstance.get(`/api/vote/getresults/?id=${id}`);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Ошибка получения результата голосования:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export {
|
||||||
|
axiosApiInstance,
|
||||||
|
clearAxios,
|
||||||
|
baseURL,
|
||||||
|
spravURL,
|
||||||
|
spravURLBase,
|
||||||
|
baseWS,
|
||||||
|
getVotes,
|
||||||
|
createVote,
|
||||||
|
getVoteDetail,
|
||||||
|
// updateVote,
|
||||||
|
// patchVote,
|
||||||
|
deleteVote,
|
||||||
|
getEmployees,
|
||||||
|
getVoteResult,
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<template>
|
||||||
|
<v-row>
|
||||||
|
<v-col
|
||||||
|
class="text-h6 text-grey text-center align-self-center text--lighten-1 font-weight-light"
|
||||||
|
>
|
||||||
|
Тестирование
|
||||||
|
</v-col>
|
||||||
|
</v-row>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import {pagecounter} from '@/utils/universal_functions'
|
||||||
|
export default {
|
||||||
|
setup(){
|
||||||
|
pagecounter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -1,325 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-container>
|
|
||||||
<v-stepper v-model="step" editable>
|
|
||||||
<v-stepper-header>
|
|
||||||
<v-stepper-item :complete="step > 0" step="1">Основная информация</v-stepper-item>
|
|
||||||
<v-divider></v-divider>
|
|
||||||
<v-stepper-item :complete="step > 1" step="2">Создание опроса</v-stepper-item>
|
|
||||||
<v-divider></v-divider>
|
|
||||||
<v-stepper-item :complete="step > 2" step="3">Настройка ответов</v-stepper-item>
|
|
||||||
<v-divider></v-divider>
|
|
||||||
<v-stepper-item step="4">Подтверждение</v-stepper-item>
|
|
||||||
</v-stepper-header>
|
|
||||||
|
|
||||||
<v-stepper-window>
|
|
||||||
<!-- Основная информация -->
|
|
||||||
<v-stepper-window-item step="1">
|
|
||||||
<v-card flat>
|
|
||||||
<v-card-title>Основная информация</v-card-title>
|
|
||||||
<v-card-text>
|
|
||||||
<v-text-field v-model="form.title" label="Название голосования" outlined></v-text-field>
|
|
||||||
<v-textarea v-model="form.description" label="Описание" outlined></v-textarea>
|
|
||||||
<v-text-field
|
|
||||||
:placeholder="form.startDate.toLocaleDateString()"
|
|
||||||
:value="form.startDate.toLocaleDateString()"
|
|
||||||
color="teal-darken-4"
|
|
||||||
label="Дата начала"
|
|
||||||
persistentPlaceholder
|
|
||||||
readonly
|
|
||||||
>
|
|
||||||
<v-menu activator="parent">
|
|
||||||
<v-date-picker
|
|
||||||
v-model="form.startDate"
|
|
||||||
color="teal-darken-4"
|
|
||||||
hideHeader
|
|
||||||
hideWeekdays
|
|
||||||
>
|
|
||||||
</v-date-picker>
|
|
||||||
</v-menu>
|
|
||||||
<v-btn flat icon style="background-color: transparent">
|
|
||||||
<v-icon>mdi-calendar</v-icon>
|
|
||||||
</v-btn>
|
|
||||||
</v-text-field>
|
|
||||||
|
|
||||||
<v-text-field
|
|
||||||
:placeholder="form.endDate.toLocaleDateString()"
|
|
||||||
:value="form.endDate.toLocaleDateString()"
|
|
||||||
color="teal-darken-4"
|
|
||||||
label="Дата окончания"
|
|
||||||
persistentPlaceholder
|
|
||||||
readonly
|
|
||||||
>
|
|
||||||
<v-menu activator="parent">
|
|
||||||
<v-date-picker
|
|
||||||
v-model="form.endDate"
|
|
||||||
color="teal-darken-4"
|
|
||||||
hideHeader
|
|
||||||
hideWeekdays
|
|
||||||
>
|
|
||||||
</v-date-picker>
|
|
||||||
</v-menu>
|
|
||||||
<v-btn flat icon style="background-color: transparent">
|
|
||||||
<v-icon>mdi-calendar</v-icon>
|
|
||||||
</v-btn>
|
|
||||||
</v-text-field>
|
|
||||||
</v-card-text>
|
|
||||||
<v-card-actions>
|
|
||||||
<v-btn color="teal-darken-4" @click="step = 1" size="medium">Далее</v-btn>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</v-stepper-window-item>
|
|
||||||
|
|
||||||
<!-- Создание опроса -->
|
|
||||||
<v-stepper-window-item step="2">
|
|
||||||
<v-card flat>
|
|
||||||
<v-card-title>Создание опроса</v-card-title>
|
|
||||||
<v-card-text>
|
|
||||||
<div v-for="(question, index) in form.questions" :key="index" class="mb-4">
|
|
||||||
<v-text-field
|
|
||||||
v-model="question.text"
|
|
||||||
:label="'Вопрос ' + (index + 1)"
|
|
||||||
outlined
|
|
||||||
></v-text-field>
|
|
||||||
<v-file-input
|
|
||||||
v-model="question.image"
|
|
||||||
accept="image/*"
|
|
||||||
label="Картинка для вопроса"
|
|
||||||
outlined
|
|
||||||
></v-file-input>
|
|
||||||
<v-select
|
|
||||||
v-model="question.type"
|
|
||||||
:items="questionTypes"
|
|
||||||
label="Тип ответа"
|
|
||||||
outlined
|
|
||||||
></v-select>
|
|
||||||
<v-btn color="error" icon @click="removeQuestion(index)">
|
|
||||||
<v-icon>mdi-delete</v-icon>
|
|
||||||
</v-btn>
|
|
||||||
</div>
|
|
||||||
<v-btn color="teal-darken-4" @click="addQuestion">Добавить вопрос</v-btn>
|
|
||||||
</v-card-text>
|
|
||||||
<v-card-actions>
|
|
||||||
<v-btn color="teal-darken-4" size="medium" @click="step -= 1">Назад</v-btn>
|
|
||||||
<v-btn color="teal-darken-4" size="medium" @click="step = 2">Далее</v-btn>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</v-stepper-window-item>
|
|
||||||
|
|
||||||
<!-- Настройка ответов -->
|
|
||||||
<v-stepper-window-item step="3">
|
|
||||||
<v-card flat>
|
|
||||||
<v-card-title>
|
|
||||||
Настройка ответов
|
|
||||||
<v-select
|
|
||||||
v-model="currentQuestionIndex"
|
|
||||||
:items="form.questions.map((q, i) => ({ text: `Вопрос ${i + 1}: ${q.text || 'Без названия'}`, value: i }))"
|
|
||||||
class="ml-4"
|
|
||||||
dense
|
|
||||||
item-title="text"
|
|
||||||
item-value="value"
|
|
||||||
label="Выберите вопрос"
|
|
||||||
outlined
|
|
||||||
></v-select>
|
|
||||||
</v-card-title>
|
|
||||||
<v-card-text>
|
|
||||||
<div v-if="currentQuestion">
|
|
||||||
<div v-if="currentQuestion.type === 'Ввести вручную'">
|
|
||||||
<div
|
|
||||||
v-for="(answer, index) in currentQuestion.answers"
|
|
||||||
:key="index"
|
|
||||||
class="d-flex align-start mb-4"
|
|
||||||
>
|
|
||||||
<v-text-field
|
|
||||||
v-model="answer.text"
|
|
||||||
:label="'Ответ ' + (index + 1)"
|
|
||||||
class="mr-4"
|
|
||||||
outlined
|
|
||||||
></v-text-field>
|
|
||||||
<v-file-input
|
|
||||||
v-model="answer.image"
|
|
||||||
accept="image/*"
|
|
||||||
dense
|
|
||||||
hide-details
|
|
||||||
label="Картинка"
|
|
||||||
outlined
|
|
||||||
></v-file-input>
|
|
||||||
<v-btn color="error" icon @click="removeAnswer(index)">
|
|
||||||
<v-icon>mdi-delete</v-icon>
|
|
||||||
</v-btn>
|
|
||||||
</div>
|
|
||||||
<v-btn color="primary" @click="addAnswer">Добавить ответ</v-btn>
|
|
||||||
</div>
|
|
||||||
<div v-else>
|
|
||||||
<v-autocomplete
|
|
||||||
v-model="currentQuestion.selectedEmployees"
|
|
||||||
:items="groupedEmployees"
|
|
||||||
item-title="fio"
|
|
||||||
item-value="id"
|
|
||||||
label="Выберите сотрудников"
|
|
||||||
multiple
|
|
||||||
outlined
|
|
||||||
></v-autocomplete>
|
|
||||||
<div
|
|
||||||
v-for="(person, index) in currentQuestion.selectedEmployees"
|
|
||||||
:key="person.id"
|
|
||||||
class="d-flex align-center mb-4"
|
|
||||||
>
|
|
||||||
<v-chip>{{ findEmployeeById(person).fio }}</v-chip>
|
|
||||||
<v-file-input
|
|
||||||
v-model="currentQuestion.selectedEmployeeImages[person]"
|
|
||||||
accept="image/*"
|
|
||||||
class="ml-4"
|
|
||||||
dense
|
|
||||||
hide-details
|
|
||||||
label="Картинка"
|
|
||||||
outlined
|
|
||||||
></v-file-input>
|
|
||||||
<v-btn color="error" icon @click="removeEmployee(index)">
|
|
||||||
<v-icon>mdi-delete</v-icon>
|
|
||||||
</v-btn>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-else>
|
|
||||||
<p>Выберите вопрос, чтобы добавить ответы.</p>
|
|
||||||
</div>
|
|
||||||
</v-card-text>
|
|
||||||
<v-card-actions>
|
|
||||||
<v-btn color="teal-darken-4" size="medium" @click="step -= 1">Назад</v-btn>
|
|
||||||
<v-btn color="teal-darken-4" size="medium" @click="step = 3">Далее</v-btn>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</v-stepper-window-item>
|
|
||||||
|
|
||||||
<!-- Подтверждение -->
|
|
||||||
<v-stepper-window-item step="4">
|
|
||||||
<v-card flat>
|
|
||||||
<v-card-title>Подтверждение</v-card-title>
|
|
||||||
<v-card-text>
|
|
||||||
<p><strong>Название:</strong> {{ form.title }}</p>
|
|
||||||
<p><strong>Описание:</strong> {{ form.description }}</p>
|
|
||||||
<p><strong>Дата начала:</strong> {{ form.startDate.toLocaleDateString() }}</p>
|
|
||||||
<p><strong>Дата окончания:</strong> {{ form.endDate.toLocaleDateString() }}</p>
|
|
||||||
<p><strong>Вопросы:</strong></p>
|
|
||||||
<ul>
|
|
||||||
<li v-for="(question, index) in form.questions" :key="index" class="mb-4">
|
|
||||||
<p><strong>Вопрос {{ index + 1 }}:</strong> {{ question.text }} ({{ question.type }})</p>
|
|
||||||
<div v-if="question.type === 'Ввести вручную' && question.answers.length">
|
|
||||||
<p><strong>Варианты ответов:</strong></p>
|
|
||||||
<ul>
|
|
||||||
<li v-for="(answer, answerIndex) in question.answers" :key="answerIndex">
|
|
||||||
{{ answer.text }}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div v-if="question.type === 'Выбрать сотрудника' && question.selectedEmployees.length">
|
|
||||||
<p><strong>Выбранные сотрудники:</strong></p>
|
|
||||||
<ul>
|
|
||||||
<li
|
|
||||||
v-for="employeeId in question.selectedEmployees"
|
|
||||||
:key="employeeId"
|
|
||||||
>
|
|
||||||
{{ findEmployeeById(employeeId).fio }}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</v-card-text>
|
|
||||||
<v-card-actions>
|
|
||||||
<v-btn color="teal-darken-4" size="medium" @click="step -= 1">Назад</v-btn>
|
|
||||||
<v-btn color="teal-darken-4" size="medium" @click="saveVoting">Сохранить</v-btn>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</v-stepper-window-item>
|
|
||||||
|
|
||||||
</v-stepper-window>
|
|
||||||
</v-stepper>
|
|
||||||
</v-container>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import {computed, ref} from "vue";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
setup() {
|
|
||||||
const step = ref(0);
|
|
||||||
const form = ref({
|
|
||||||
title: "",
|
|
||||||
description: "",
|
|
||||||
startDate: new Date(),
|
|
||||||
endDate: new Date(new Date().setDate(new Date().getDate() + 14)),
|
|
||||||
questions: [],
|
|
||||||
});
|
|
||||||
|
|
||||||
const currentQuestionIndex = ref(0);
|
|
||||||
const questionTypes = ["Ввести вручную", "Выбрать сотрудника"];
|
|
||||||
|
|
||||||
const groupedEmployees = [
|
|
||||||
{id: 1, fio: "Иван Иванов", department: "Отдел A"},
|
|
||||||
{id: 2, fio: "Петр Петров", department: "Отдел B"},
|
|
||||||
];
|
|
||||||
|
|
||||||
const currentQuestion = computed(() =>
|
|
||||||
form.value.questions[currentQuestionIndex.value] || null
|
|
||||||
);
|
|
||||||
|
|
||||||
const findEmployeeById = (id) =>
|
|
||||||
groupedEmployees.find((employee) => employee.id === id) || {};
|
|
||||||
|
|
||||||
const removeEmployee = (index) => {
|
|
||||||
currentQuestion.value.selectedEmployees.splice(index, 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
const addQuestion = () => {
|
|
||||||
form.value.questions.push({
|
|
||||||
text: "",
|
|
||||||
type: "Ввести вручную",
|
|
||||||
image: null,
|
|
||||||
answers: [],
|
|
||||||
selectedEmployees: [],
|
|
||||||
selectedEmployeeImages: {},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const removeQuestion = (index) => {
|
|
||||||
form.value.questions.splice(index, 1);
|
|
||||||
if (currentQuestionIndex.value >= form.value.questions.length) {
|
|
||||||
currentQuestionIndex.value = form.value.questions.length - 1;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const addAnswer = () => {
|
|
||||||
if (currentQuestion.value) {
|
|
||||||
currentQuestion.value.answers.push({text: "", image: null});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const removeAnswer = (index) => {
|
|
||||||
if (currentQuestion.value) {
|
|
||||||
currentQuestion.value.answers.splice(index, 1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const saveVoting = () => {
|
|
||||||
console.log("Голосование сохранено:", form.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
step,
|
|
||||||
form,
|
|
||||||
questionTypes,
|
|
||||||
groupedEmployees,
|
|
||||||
currentQuestionIndex,
|
|
||||||
currentQuestion,
|
|
||||||
addQuestion,
|
|
||||||
removeQuestion,
|
|
||||||
addAnswer,
|
|
||||||
removeAnswer,
|
|
||||||
findEmployeeById,
|
|
||||||
removeEmployee,
|
|
||||||
saveVoting,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
@@ -1,220 +1,211 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-container>
|
<v-container class="pt-2 d-flex flex-column" fluid>
|
||||||
<v-toolbar color="transparent">
|
<v-row class="flex-column">
|
||||||
<v-toolbar-title>Голосования</v-toolbar-title>
|
<v-col cols="auto">
|
||||||
|
<v-tabs
|
||||||
|
v-model="currentTab"
|
||||||
|
align="center">
|
||||||
|
<v-tab v-for="x in tabs" :key="x.value" :value="x.value">{{ x.text }}</v-tab>
|
||||||
|
<v-tab v-if="accountStore.user.is_staff" value="constructor">Создать новое голосование</v-tab>
|
||||||
|
|
||||||
<template v-slot:extension>
|
|
||||||
<v-tabs v-model="currentTab">
|
|
||||||
<v-tab :key="0" value="current">Текущие голосования</v-tab>
|
|
||||||
<v-tab :key="1" value="completed">Завершенные голосования</v-tab>
|
|
||||||
<v-tab :key="2" value="constructor">Создать новое голосование</v-tab>
|
|
||||||
</v-tabs>
|
</v-tabs>
|
||||||
</template>
|
|
||||||
</v-toolbar>
|
|
||||||
|
|
||||||
<v-tabs-window v-model="currentTab">
|
</v-col>
|
||||||
|
<v-col class="pa-0 overflow-hidden">
|
||||||
|
|
||||||
|
<v-window v-model="currentTab" class="h-100">
|
||||||
<!-- Текущие голосования -->
|
<!-- Текущие голосования -->
|
||||||
<v-tabs-window-item value="current">
|
<v-tabs-window-item v-for="x in ['active','completed']" :value="x" class="h-100 overflow-auto">
|
||||||
<v-container>
|
<v-row class="mx-2">
|
||||||
<v-row>
|
|
||||||
<v-col
|
<v-col
|
||||||
v-for="voting in sortedCurrentVotes"
|
v-for="voting in sortedVotes"
|
||||||
:key="voting.id"
|
:key="voting.id"
|
||||||
cols="12" lg="3" md="4"
|
cols="12"
|
||||||
|
lg="3"
|
||||||
|
md="4"
|
||||||
>
|
>
|
||||||
<v-card :class="{ 'voted-card': voting.voted }">
|
<VoteCardVue
|
||||||
<v-card-title class="d-flex justify-space-between">{{ voting.title }}
|
:isFinished="currentTab==='active'"
|
||||||
<v-btn flat size="medium">
|
:voteCard="voting"
|
||||||
<v-icon color="orange-lighten-1">mdi-pencil</v-icon>
|
@deleteVoting="deleteVoting"
|
||||||
</v-btn>
|
@openResultModal="(voting) => openModal('results', voting)"
|
||||||
</v-card-title>
|
@openVoteModal="(voting) => openModal('vote', voting)"
|
||||||
<v-card-subtitle>
|
/>
|
||||||
Окончание: {{ formatDate(voting.endDate) }}
|
|
||||||
</v-card-subtitle>
|
|
||||||
<v-card-text>
|
|
||||||
Осталось: {{ timeRemaining(voting.endDate) }}
|
|
||||||
</v-card-text>
|
|
||||||
<v-card-actions class="justify-space-between">
|
|
||||||
<v-btn
|
|
||||||
v-if="!voting.voted"
|
|
||||||
color="teal-darken-4"
|
|
||||||
size="medium"
|
|
||||||
@click="openVoteModal(voting)"
|
|
||||||
>
|
|
||||||
Проголосовать
|
|
||||||
</v-btn>
|
|
||||||
<v-btn v-else color="teal-darken-4" disabled size="medium">Уже проголосовали</v-btn>
|
|
||||||
<v-btn color="error" @click="deleteVoting(voting.id)" size="medium">
|
|
||||||
<v-icon>mdi-delete</v-icon>
|
|
||||||
</v-btn>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
</v-container>
|
|
||||||
</v-tabs-window-item>
|
</v-tabs-window-item>
|
||||||
|
|
||||||
<!-- Завершенные голосования -->
|
|
||||||
<v-tabs-window-item value="completed">
|
|
||||||
<v-container>
|
|
||||||
<v-row>
|
|
||||||
<v-col
|
|
||||||
v-for="voting in sortedCompletedVotes"
|
|
||||||
:key="voting.id"
|
|
||||||
cols="12" lg="3" md="4"
|
|
||||||
>
|
|
||||||
<v-card>
|
|
||||||
<v-card-title>{{ voting.title }}</v-card-title>
|
|
||||||
<v-card-subtitle>
|
|
||||||
Завершено: {{ formatDate(voting.endDate) }}
|
|
||||||
</v-card-subtitle>
|
|
||||||
<v-card-actions class="justify-space-between">
|
|
||||||
<v-btn color="teal-darken-4" size="medium" @click="openResultsModal(voting)">
|
|
||||||
Результаты
|
|
||||||
</v-btn>
|
|
||||||
<v-btn color="error" size="medium" @click="deleteVoting(voting.id)">
|
|
||||||
<v-icon>mdi-delete</v-icon>
|
|
||||||
</v-btn>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</v-container>
|
|
||||||
</v-tabs-window-item>
|
|
||||||
|
|
||||||
<!-- Конструктор -->
|
<!-- Конструктор -->
|
||||||
<v-tabs-window-item value="constructor">
|
<v-tabs-window-item v-if="accountStore.user.is_staff" class="h-100 overflow-auto" value="constructor">
|
||||||
<VoteConstructor/>
|
<VoteConstructor @updating="updating"/>
|
||||||
</v-tabs-window-item>
|
</v-tabs-window-item>
|
||||||
</v-tabs-window>
|
</v-window>
|
||||||
|
|
||||||
<!-- Модальное окно для голосования -->
|
<!-- Модальные окна -->
|
||||||
<v-dialog v-model="voteModal" max-width="600px">
|
<v-dialog v-model="voteModal" @click:outside="closeModal">
|
||||||
|
<CurrentVote :data="res" @closer="closeModal"/>
|
||||||
|
</v-dialog>
|
||||||
|
|
||||||
|
<v-dialog v-model="resultsModal" max-width="1200px" @click:outside="closeModal">
|
||||||
<v-card>
|
<v-card>
|
||||||
<v-card-title>Голосование: {{ selectedVoting?.title }}</v-card-title>
|
<VoteResult :data="result" @closer="closeModal" />
|
||||||
<v-card-text>
|
|
||||||
<p>Описание голосования...</p>
|
|
||||||
</v-card-text>
|
|
||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
<v-btn color="primary" @click="submitVote">Проголосовать</v-btn>
|
<v-btn @click="closeModal">Закрыть</v-btn>
|
||||||
<v-btn @click="closeVoteModal">Закрыть</v-btn>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</v-dialog>
|
|
||||||
|
|
||||||
<!-- Модальное окно для результатов -->
|
|
||||||
<v-dialog v-model="resultsModal" max-width="600px">
|
|
||||||
<v-card>
|
|
||||||
<v-card-title>Результаты голосования: {{ selectedVoting?.title }}</v-card-title>
|
|
||||||
<v-card-text>
|
|
||||||
<p>Здесь отображаются результаты голосования...</p>
|
|
||||||
</v-card-text>
|
|
||||||
<v-card-actions>
|
|
||||||
<v-btn @click="closeResultsModal">Закрыть</v-btn>
|
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-dialog>
|
</v-dialog>
|
||||||
|
</v-col>
|
||||||
|
</v-row>
|
||||||
</v-container>
|
</v-container>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {computed, ref} from "vue";
|
import {computed, ref, watch} from "vue";
|
||||||
import VoteConstructor from "@/views/VoteConstructor.vue";
|
import VoteConstructor from "@/components/vote/VoteConstructor.vue";
|
||||||
|
import CurrentVote from "@/components/vote/CurrentVote.vue";
|
||||||
|
import VoteCardVue from "@/components/vote/VoteCard.vue";
|
||||||
|
import {useRoute, useRouter} from "vue-router";
|
||||||
|
import VoteResult from "@/components/vote/VoteResult.vue";
|
||||||
|
import {deleteVote, getVoteDetail, getVoteResult, getVotes} from "@/utils/axios-api";
|
||||||
|
import {formatDate} from "@vueuse/shared";
|
||||||
|
import { useAccountStore } from "@/store/AccountStore";
|
||||||
|
import {pagecounter} from '@/utils/universal_functions'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {VoteConstructor},
|
methods: {formatDate},
|
||||||
|
|
||||||
|
components: {CurrentVote, VoteConstructor, VoteCardVue, VoteResult},
|
||||||
setup() {
|
setup() {
|
||||||
const currentTab = ref("current");
|
pagecounter()
|
||||||
const votes = ref([
|
const accountStore = useAccountStore();
|
||||||
{
|
const tabs = [
|
||||||
id: 1,
|
{value: "active", text: 'Текущие голосования'},
|
||||||
title: "Голосование 1",
|
{value: "completed", text: 'Завершенные голосования'},
|
||||||
endDate: new Date(new Date().getTime() + 600000), // 10 минут
|
|
||||||
voted: false,
|
]
|
||||||
},
|
|
||||||
{
|
const currentTab = ref("active");
|
||||||
id: 2,
|
const votes = ref([]);
|
||||||
title: "Голосование 2",
|
const router = useRouter();
|
||||||
endDate: new Date(new Date().getTime() - 600000), // Уже завершено
|
const route = useRoute();
|
||||||
voted: true,
|
const res = ref(null);
|
||||||
},
|
const result = ref(null);
|
||||||
{
|
|
||||||
id: 3,
|
const updating = async (param) => {
|
||||||
title: "Голосование 3",
|
const data = await getVotes(param);
|
||||||
endDate: new Date(new Date().getTime() + 3600000), // 1 час
|
votes.value = data;
|
||||||
voted: true,
|
};
|
||||||
},
|
|
||||||
]);
|
updating("active");
|
||||||
|
|
||||||
const voteModal = ref(false);
|
const voteModal = ref(false);
|
||||||
const resultsModal = ref(false);
|
const resultsModal = ref(false);
|
||||||
const selectedVoting = ref(null);
|
const selectedVoting = ref(null);
|
||||||
|
|
||||||
const sortedCurrentVotes = computed(() => {
|
const sortedVotes = computed(() => currentTab.value === 'active' ? votes.value.sort((a, b) =>
|
||||||
return votes.value
|
new Date(a.dateend) - new Date(b.dateend)) :
|
||||||
.filter((v) => new Date(v.endDate) > new Date())
|
votes.value.sort((a, b) => new Date(b.dateend) - new Date(a.dateend)));
|
||||||
.sort((a, b) => new Date(a.endDate) - new Date(b.endDate));
|
|
||||||
});
|
|
||||||
|
|
||||||
const sortedCompletedVotes = computed(() => {
|
const loadVoteDetails = async (id) => {
|
||||||
return votes.value
|
try {
|
||||||
.filter((v) => new Date(v.endDate) <= new Date())
|
const data = await getVoteDetail(id);
|
||||||
.sort((a, b) => new Date(b.endDate) - new Date(a.endDate));
|
res.value = data;
|
||||||
});
|
} catch (error) {
|
||||||
|
console.error("Ошибка при загрузке данных голосования:", error);
|
||||||
|
// res.value = {};
|
||||||
|
|
||||||
const timeRemaining = (endDate) => {
|
throw error;
|
||||||
const now = new Date();
|
}
|
||||||
const diff = new Date(endDate) - now;
|
|
||||||
return diff > 0 ? `${Math.floor(diff / 60000)} минут` : "Завершено";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatDate = (date) => new Date(date).toLocaleString();
|
const loadVoteResult = async (id) => {
|
||||||
|
try {
|
||||||
const openVoteModal = (voting) => {
|
const data = await getVoteResult(id);
|
||||||
selectedVoting.value = voting;
|
result.value = data;
|
||||||
voteModal.value = true;
|
} catch (error) {
|
||||||
|
console.error("Ошибка при загрузке данных голосования:", error);
|
||||||
|
res.value = {};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeVoteModal = () => {
|
const closeModal = () => {
|
||||||
voteModal.value = false;
|
voteModal.value = false;
|
||||||
selectedVoting.value = null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const submitVote = () => {
|
|
||||||
selectedVoting.value.voted = true;
|
|
||||||
closeVoteModal();
|
|
||||||
};
|
|
||||||
|
|
||||||
const openResultsModal = (voting) => {
|
|
||||||
selectedVoting.value = voting;
|
|
||||||
resultsModal.value = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const closeResultsModal = () => {
|
|
||||||
resultsModal.value = false;
|
resultsModal.value = false;
|
||||||
selectedVoting.value = null;
|
selectedVoting.value = null;
|
||||||
|
router.push({name: "VoteHomePage"});
|
||||||
|
if (route.name === "Voting") updating('active')
|
||||||
|
if (route.name === "VoteResults") updating('completed')
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteVoting = (id) => {
|
const openModal = async (type, voting) => {
|
||||||
votes.value = votes.value.filter((v) => v.id !== id);
|
selectedVoting.value = voting;
|
||||||
|
if (type === "vote") {
|
||||||
|
try{
|
||||||
|
await loadVoteDetails(voting.id);
|
||||||
|
console.log("sd;lkjs;ljlmnjlk");
|
||||||
|
voteModal.value = true;
|
||||||
|
router.push({name: "Voting", params: {id: voting.id}});
|
||||||
|
}catch(e){
|
||||||
|
router.push({ name: "VoteHomePage" })
|
||||||
|
}
|
||||||
|
} else if (type === "results") {
|
||||||
|
await loadVoteResult(voting.id);
|
||||||
|
resultsModal.value = true;
|
||||||
|
router.push({name: "VoteResults", params: {id: voting.id}});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deleteVoting = async (id) => {
|
||||||
|
try {
|
||||||
|
await deleteVote(id);
|
||||||
|
votes.value = votes.value.filter((v) => v.id !== id);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Ошибка при удалении голосования:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
watch(currentTab, async () => await updating(currentTab.value))
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => route,
|
||||||
|
async () => {
|
||||||
|
if (!voteModal.value && !resultsModal.value) {
|
||||||
|
const voting = votes.value.find((v) => v.id === route.params.id);
|
||||||
|
if (route.name === "Voting") {
|
||||||
|
try{
|
||||||
|
await loadVoteDetails(route.params.id);
|
||||||
|
voteModal.value = true;}
|
||||||
|
catch(e){
|
||||||
|
router.push({ name: "VoteHomePage" })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if (route.name === "EditVote") editVoteModal.value = true;
|
||||||
|
if (route.name === "VoteResults") {
|
||||||
|
await loadVoteResult(route.params.id)
|
||||||
|
resultsModal.value = true;
|
||||||
|
}
|
||||||
|
selectedVoting.value = voting || null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{immediate: true}
|
||||||
|
);
|
||||||
|
|
||||||
|
updating("active");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
accountStore,
|
||||||
currentTab,
|
currentTab,
|
||||||
votes,
|
votes,
|
||||||
sortedCurrentVotes,
|
sortedVotes,
|
||||||
sortedCompletedVotes,
|
|
||||||
voteModal,
|
voteModal,
|
||||||
resultsModal,
|
resultsModal,
|
||||||
selectedVoting,
|
selectedVoting,
|
||||||
timeRemaining,
|
openModal,
|
||||||
formatDate,
|
closeModal,
|
||||||
openVoteModal,
|
|
||||||
closeVoteModal,
|
|
||||||
submitVote,
|
|
||||||
openResultsModal,
|
|
||||||
closeResultsModal,
|
|
||||||
deleteVoting,
|
deleteVoting,
|
||||||
|
updating,
|
||||||
|
res,
|
||||||
|
tabs,
|
||||||
|
result
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<template>
|
||||||
|
<!-- <v-container>
|
||||||
|
<TimerUI :endTime="end" />
|
||||||
|
<SmallTimer :endTime="end"/>
|
||||||
|
</v-container> -->
|
||||||
|
<VoteCard />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// import TimerUI from "@/components/secret/TimerUI.vue"
|
||||||
|
// import SmallTimer from "@/components/secret/SmallTimer.vue"
|
||||||
|
import VoteCard from "@/components/vote/VoteCard.vue"
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
// TimerUI,
|
||||||
|
// SmallTimer,
|
||||||
|
VoteCard
|
||||||
|
},
|
||||||
|
setup() {
|
||||||
|
// const end = new Date(2025, 0, 14, 15, 58, 5)
|
||||||
|
|
||||||
|
return {
|
||||||
|
// end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
Reference in new issue
Block a user