Skip to content

Commit 177a77b

Browse files
author
philippe lhardy
committed
merge generic variant in main ( after 8.2.0rc.2)
Move code VoteItem code into VoteButton Add drop-down list in VoteButton adapt with new poll types
1 parent 9628cf4 commit 177a77b

File tree

5 files changed

+56
-43
lines changed

5 files changed

+56
-43
lines changed

src/components/VoteTable/VoteButton.vue

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const vote = computed(() =>
4848
}),
4949
)
5050
51+
const chosenRank=JSON.parse(pollStore.configuration.chosenRank)
52+
5153
const nextAnswer = computed<richAnswer>(() => {
5254
if (['no', ''].includes(vote.value.answer)) {
5355
return richAnswers.yes
@@ -76,7 +78,10 @@ async function setVote() {
7678
}
7779
}
7880
79-
async function handleRankSelected(rank){
81+
async function handleRankSelected(event){
82+
const selectElement = event.target
83+
const rank = selectElement.value
84+
console.log('rank',rank,'event',event)
8085
try {
8186
await votesStore.set({
8287
option,
@@ -94,19 +99,31 @@ async function handleRankSelected(rank){
9499
</script>
95100

96101
<template>
97-
<button
98-
class="vote-button active"
99-
:class="[vote.answer]"
100-
:aria-label="
101-
t('polls', 'Click to vote with {nextAnswer} for option {option}', {
102-
option: option.text,
103-
nextAnswer: nextAnswer.translated,
104-
})
105-
"
106-
@click="setVote()"
107-
@select-change="handleRankSelected">
108-
<VoteIndicator :answer="vote.answer" />
109-
</button>
102+
<div v-if="pollStore.votingVariant === 'generic'" class="generic-vote">
103+
<select
104+
:value="vote.answer"
105+
class="vote-ranking"
106+
@change="handleRankSelected">
107+
<option disabled value=""></option>
108+
<option v-for="rank in chosenRank" :key="rank" :value="rank">
109+
{{ rank }}
110+
</option>
111+
</select>
112+
</div>
113+
<div v-else>
114+
<button
115+
class="vote-button active"
116+
:class="[vote.answer]"
117+
:aria-label="
118+
t('polls', 'Click to vote with {nextAnswer} for option {option}', {
119+
option: option.text,
120+
nextAnswer: nextAnswer.translated,
121+
})
122+
"
123+
@click="setVote()">
124+
<VoteIndicator :answer="vote.answer" />
125+
</button>
126+
</div>
110127
</template>
111128

112129
<style lang="scss" scoped>

src/components/VoteTable/VoteIndicator.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import CloseIcon from 'vue-material-design-icons/Close.vue'
1010
import CancelIcon from 'vue-material-design-icons/Cancel.vue'
1111
import MaybeIcon from '../AppIcons/MaybeIcon.vue'
1212
import { Answer } from '../../stores/votes.types'
13+
import { usePollStore } from '../../stores/poll.js'
1314
const pollStore = usePollStore()
1415
const chosenRank=JSON.parse(pollStore.configuration.chosenRank)
1516

src/components/VoteTable/VoteItem.vue

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,6 @@ const vote = computed(() =>
3131
}),
3232
)
3333
34-
35-
async function handleRankSelected(rank){
36-
if (isVotable.value) {
37-
try {
38-
await votesStore.set({
39-
option,
40-
setTo: String(rank),
41-
});
42-
showSuccess(t('polls', 'Vote saved'), { timeout: 2000 });
43-
} catch (error) {
44-
if ((error as AxiosError).status === 409) {
45-
showError(t('polls', 'Vote already booked out'));
46-
} else {
47-
showError(t('polls', 'Error saving vote'));
48-
}
49-
}
50-
} else {
51-
showError(t('polls', 'Error saving vote'));
52-
}
53-
}
54-
55-
5634
const iconAnswer = computed(() => {
5735
if (option.locked && currentUser && !pollStore.isClosed) {
5836
return 'locked'
@@ -68,7 +46,7 @@ const iconAnswer = computed(() => {
6846

6947
<template>
7048
<div class="vote-item" :class="vote.answer">
71-
<VoteIndicator :answer="iconAnswer" @select-change="handleRankSelected" />
49+
<VoteIndicator :answer="iconAnswer" />
7250
</div>
7351
</template>
7452

src/stores/poll.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import type {
2929
AllowProposals,
3030
PollStore,
3131
PollTypesType,
32+
VotingVariant,
33+
VotingVariantsType
3234
} from './poll.types'
3335
import type { ViewMode } from './preferences.types'
3436

@@ -45,7 +47,16 @@ export const pollTypes: Record<PollType, PollTypesType> = {
4547
},
4648
}
4749

48-
const DEFAULT_CHOSEN_RANK = [] ;
50+
export const votingVariants: Record<VotingVariant, VotingVariantsType> = {
51+
simple: {
52+
name: t('polls', 'Simple variant'),
53+
},
54+
generic: {
55+
name: t('polls', 'Generic variant'),
56+
}
57+
}
58+
59+
const DEFAULT_CHOSEN_RANK : Array<string> = [] ;
4960

5061
export const usePollStore = defineStore('poll', {
5162
state: (): PollStore => ({
@@ -59,10 +70,10 @@ export const usePollStore = defineStore('poll', {
5970
access: 'private',
6071
allowComment: false,
6172
allowMaybe: false,
62-
chosenRank: JSON.stringify(DEFAULT_CHOSEN_RANK),
6373
allowProposals: 'disallow',
6474
anonymous: false,
6575
autoReminder: false,
76+
chosenRank: JSON.stringify(DEFAULT_CHOSEN_RANK),
6677
collapseDescription: true,
6778
expire: 0,
6879
forceConfidentialComments: false,
@@ -299,11 +310,11 @@ export const usePollStore = defineStore('poll', {
299310
}
300311
},
301312

302-
async add(payload: { type: PollType; title: string }): Promise<Poll | void> {
313+
async add(payload: { type: PollType; title: string; votingVariant: VotingVariant }): Promise<Poll | void> {
303314
const pollsStore = usePollsStore()
304315

305316
try {
306-
const response = await PollsAPI.addPoll(payload.type, payload.title)
317+
const response = await PollsAPI.addPoll(payload.type, payload.title, payload.votingVariant)
307318
return response.data.poll
308319
} catch (error) {
309320
if ((error as AxiosError)?.code === 'ERR_CANCELED') {

src/stores/poll.types.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ export type PollTypesType = {
1111
name: string
1212
}
1313

14-
export type VoteVariant = 'simple'
14+
export type VotingVariant = 'simple' | 'generic'
15+
16+
export type VotingVariantsType = {
17+
name : string
18+
}
19+
1520
export type AccessType = 'private' | 'open'
1621
export type ShowResults = 'always' | 'closed' | 'never'
1722
export type AllowProposals = 'allow' | 'disallow' | 'review'
@@ -30,6 +35,7 @@ export type PollConfiguration = {
3035
anonymous: boolean
3136
autoReminder: boolean
3237
collapseDescription: boolean
38+
chosenRank: string
3339
description: string
3440
expire: number
3541
forceConfidentialComments: boolean
@@ -98,7 +104,7 @@ export type CurrentUserStatus = {
98104
export type Poll = {
99105
id: number
100106
type: PollType
101-
voteVariant: VoteVariant
107+
votingVariant: VotingVariant
102108
descriptionSafe: string
103109
configuration: PollConfiguration
104110
owner: User

0 commit comments

Comments
 (0)