Добавлены компоненты подсчета процентов в главном окне и кона подтверждения выбора

This commit is contained in:
Andrei Filippov committed 2024-10-22 17:17:25 +03:00
1 parent 928a014ce4
commit 4168c7b100
7 files changed
+155 -20

No files matched your search

+6 -2
View File
@@ -5,11 +5,13 @@ from django.db import models
class ThanksVote(models.Model):
voted_user = models.CharField(blank=False, max_length=255)
department_user = models.CharField(
blank=False, default=None, max_length=255)
cand_name = models.CharField(blank=False, default=None, max_length=255)
vote_thanks_date = models.DateTimeField(auto_now_add=True)
class Meta:
unique_together = ('voted_user', 'cand_name')
# unique_together = ('cand_name', 'voted_user')
verbose_name = "Голосование, хочу сказать спасибо!"
verbose_name_plural = "Голосование, хочу сказать спасибо!"
@@ -19,11 +21,13 @@ class ThanksVote(models.Model):
class BestVote(models.Model):
voted_user = models.CharField(blank=False, max_length=255)
department_user = models.CharField(
blank=False, default=None, max_length=255)
cand_name = models.CharField(blank=False, default=None, max_length=255)
vote_best_date = models.DateTimeField(auto_now_add=True)
class Meta:
unique_together = ('voted_user', 'cand_name')
# unique_together = ('cand_name', 'voted_user')
verbose_name = "Голосование, мой коллега самый лучший"
verbose_name_plural = "Голосование, мой коллега самый лучший"
+7 -2
View File
@@ -29,9 +29,11 @@ class GetForBst(APIView):
class SetThanks(APIView):
def post(self, request):
voted_user = request.data['voted_user']
department_user = request.data['department_user']
cand_name = request.data['cand_name_id']
ThanksVote.objects.create(
voted_user=voted_user,
department_user=department_user,
cand_name=cand_name
)
return Response("Ваш голос добавлен!")
@@ -39,7 +41,7 @@ class SetThanks(APIView):
class GetThanks(APIView):
def get(self, request):
# Группировка товаров по имени и подсчет каждого
# Группировка кандидатов по имени и подсчет каждого
count_thanks = ThanksVote.objects.values(
'cand_name').annotate(total=Count('id'))
return Response(count_thanks)
@@ -48,9 +50,11 @@ class GetThanks(APIView):
class SetBest(APIView):
def post(self, request):
voted_user = request.data['voted_user']
department_user = request.data['department_user']
cand_name = request.data['cand_name_id']
BestVote.objects.create(
voted_user=voted_user,
department_user=department_user,
cand_name=cand_name
)
return Response("Ваш голос добавлен!")
@@ -58,6 +62,7 @@ class SetBest(APIView):
class GetBest(APIView):
def get(self, request):
count_bests = ThanksVote.objects.values(
# Группировка кандидатов по имени и подсчет каждого
count_bests = BestVote.objects.values(
'cand_name').annotate(total=Count('id'))
return Response(count_bests)
+47
View File
@@ -0,0 +1,47 @@
<template>
<span>{{ perc_best }}%</span>
</template>
<script>
import { ref } from "vue";
import { computed } from "vue";
import { clearAxios } from "@/utils/axios-api";
import { useAccountStore } from '@/store/AccountStore';
export default {
setup() {
let account_login = useAccountStore().user.login;
let department_id = useAccountStore().user.id_dict_department;
let all_dep = ref([]);
let all_voted = ref([]);
let perc_best = ref();
const getAllDep = () => {
clearAxios.get(`api/vote/get_for_bst/?login=${account_login}&dep=${department_id}`).then((data) => {
all_dep.value = data.data;
});
};
const getVoted = () => {
clearAxios.get(`api/vote/getbest/`).then((data) => {
all_voted.value = data.data;
});
};
getAllDep();
getVoted();
perc_best = computed(() => Math.round(all_voted.value.length / all_dep.value.length * 100))
return {
all_dep,
all_voted,
perc_best,
}
}
}
</script>
<style></style>
+46
View File
@@ -0,0 +1,46 @@
<template>
<span>{{ perc_thn }}%</span>
</template>
<script>
import { ref } from "vue";
import { computed } from "vue";
import { clearAxios } from "@/utils/axios-api";
import { useAccountStore } from '@/store/AccountStore';
export default {
setup() {
let account_login = useAccountStore().user.login;
let all_cod = ref([]);
let all_voted = ref([]);
let perc_thn = ref();
const getAllCod = () => {
clearAxios.get(`api/vote/get_for_thn/?login=${account_login}`).then((data) => {
all_cod.value = data.data;
});
};
const getVoted = () => {
clearAxios.get(`api/vote/getthanks/`).then((data) => {
all_voted.value = data.data;
});
};
getAllCod();
getVoted();
perc_thn = computed(() => Math.round(all_voted.value.length / all_cod.value.length * 100))
return {
all_cod,
all_voted,
perc_thn,
}
}
}
</script>
<style></style>
@@ -7,10 +7,31 @@
<v-checkbox v-model="vote" :id="item.fio" :value="item.fio" :label="item.fio" />
</template>
</v-virtual-scroll>
</v-card>
<v-card-actions class="justify-center vote-button-back">
<v-btn variant="elevated" color="teal-darken-1" type="submit">ПРОГОЛОСОВАТЬ</v-btn>
<v-dialog max-width="500">
<template v-slot:activator="{ props: activatorProps }">
<v-btn variant="elevated" v-bind="activatorProps" color="teal-darken-1"
@click="approveCandidate">Подтвердить выбор</v-btn>
</template>
<template v-slot:default="{ isActive }">
<v-card class="justify-center align-center">
<v-card-title>Вы подтверждаете выбор?</v-card-title>
<v-card-text>После подтверждения внесение измений станет невозможным.</v-card-text>
<p>Выбранный кандидат</p>
<v-card-title>{{ approve_name }}</v-card-title>
<v-col class="d-flex flex-rows justify-center align-center" cols="12">
<v-col cols="2">
<v-btn variant="elevated" color="green-darken-1" @click="voteSend">ДА</v-btn>
</v-col>
<v-col cols="2">
<v-btn variant="elevated" color="red-darken-1" @click="isActive.value = false">НЕТ</v-btn>
</v-col>
</v-col>
</v-card>
</template>
</v-dialog>
<!-- <v-btn variant="elevated" color="teal-darken-1" type="submit">Подтвердить выбор</v-btn> -->
</v-card-actions>
</v-form>
</template>
@@ -25,11 +46,13 @@ export default {
setup(props) {
let account_login = useAccountStore().user.login;
let department_id = useAccountStore().user.id_dict_department;
let department_name = useAccountStore().user.department
let type_fetch = props.type_fetch;
let vote = ref();
let get_address = ref();
let send_address = ref();
let vote_data = ref([]);
let approve_name = ref();
if (type_fetch == "thn") {
get_address = `api/vote/get_for_thn/?login=${account_login}`;
@@ -45,9 +68,15 @@ export default {
});
};
const approveCandidate = () => {
approve_name.value = vote.value;
}
const voteSend = () => {
window.location.reload();
clearAxios.post(send_address, {
cand_name_id: vote.value,
department_user: department_name,
voted_user: account_login
},
{
@@ -58,11 +87,15 @@ export default {
);
};
getVotesData();
return {
approveCandidate,
voteSend,
vote_data,
vote,
approve_name,
}
},
+7 -11
View File
@@ -1,11 +1,8 @@
<template>
<v-row class="justify-center ma-0 ">
<v-col
class="flex-column d-flex"
>
<news-crossroad/>
<v-col class="flex-column d-flex">
<news-crossroad />
</v-col>
</v-row>
@@ -13,18 +10,17 @@
<script>
import {pagecounter} from '@/utils/universal_functions'
import { pagecounter } from '@/utils/universal_functions'
import newsCrossroad from '../components/news-crossroad.vue'
// import NewsListNews from '../components/news-list-news.vue'
export default {
components: {
newsCrossroad
},
setup(){
pagecounter()
}
setup() {
pagecounter()
}
}
</script>
+7 -3
View File
@@ -3,7 +3,7 @@
<v-col cols="12" class="h-15 d-flex justify-center proc-count_cell">
<v-col justify="center" align="center" cols="2">
<v-card color="teal-darken-1" width="200" height="100" elevation="24" class="procent-card-font">
<span>45%</span>
<perc-bst />
</v-card>
</v-col>
<v-col justify="center" align="center" cols="4" class="vote-cards_cell ">
@@ -11,7 +11,7 @@
</v-col>
<v-col justify="center" align="center" cols="2">
<v-card color="teal-darken-1" width="200" height="100" elevation="24" class="procent-card-font">
<span>55%</span>
<perc-thn />
</v-card>
</v-col>
</v-col>
@@ -105,7 +105,9 @@
</template>
<script>
import { ref } from "vue";
import VoteForm from '@/components/VoteForm.vue';
import VoteForm from '@/components/vote/VoteForm.vue';
import PercBst from '@/components/vote/PercBst.vue';
import PercThn from '@/components/vote/PercThn.vue';
import CountDown from '@/components/CountDown.vue';
export default {
@@ -113,6 +115,8 @@ export default {
components: {
VoteForm,
CountDown,
PercBst,
PercThn,
},
setup() {