Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRené Gieling <github@dartcafe.de>2021-03-02 16:41:39 +0300
committerGitHub <noreply@github.com>2021-03-02 16:41:39 +0300
commit8bd5e69cb454e7315e4b8b3e20f415587356366e (patch)
tree445444dab8425aa8427bc4e6cf675ea241721351 /src
parent5e04fe191f047d88080db44c60b0b562d7b1f62a (diff)
added hide options if booked out and move some logic to backend (#1449)
Diffstat (limited to 'src')
-rw-r--r--src/js/components/Base/Confirmation.vue1
-rw-r--r--src/js/components/Options/OptionsDate.vue3
-rw-r--r--src/js/components/Options/OptionsText.vue5
-rw-r--r--src/js/components/SideBar/SideBarTabConfiguration.vue13
-rw-r--r--src/js/components/VoteTable/VoteItem.vue10
-rw-r--r--src/js/components/VoteTable/VoteTable.vue4
-rw-r--r--src/js/mixins/watchPolls.js8
-rw-r--r--src/js/store/modules/options.js29
-rw-r--r--src/js/store/modules/poll.js1
-rw-r--r--src/js/store/modules/votes.js28
10 files changed, 33 insertions, 69 deletions
diff --git a/src/js/components/Base/Confirmation.vue b/src/js/components/Base/Confirmation.vue
index 9feff19e..30091335 100644
--- a/src/js/components/Base/Confirmation.vue
+++ b/src/js/components/Base/Confirmation.vue
@@ -48,7 +48,6 @@ export default {
}),
...mapGetters({
- votesRank: 'votes/ranked',
participantsVoted: 'poll/participantsVoted',
closed: 'poll/closed',
confirmedOptions: 'options/confirmed',
diff --git a/src/js/components/Options/OptionsDate.vue b/src/js/components/Options/OptionsDate.vue
index d01f873f..483e3c10 100644
--- a/src/js/components/Options/OptionsDate.vue
+++ b/src/js/components/Options/OptionsDate.vue
@@ -24,7 +24,7 @@
<div>
<ConfigBox v-if="countOptions" :title="t('polls', 'Available Options')" icon-class="icon-calendar-000">
<transition-group is="ul">
- <OptionItem v-for="(option) in sortedOptions"
+ <OptionItem v-for="(option) in options"
:key="option.id"
:option="option"
:show-confirmed="true"
@@ -113,7 +113,6 @@ export default {
}),
...mapGetters({
- sortedOptions: 'options/sorted',
pollIsClosed: 'poll/closed',
countOptions: 'options/count',
}),
diff --git a/src/js/components/Options/OptionsText.vue b/src/js/components/Options/OptionsText.vue
index 04613a39..10c23726 100644
--- a/src/js/components/Options/OptionsText.vue
+++ b/src/js/components/Options/OptionsText.vue
@@ -89,19 +89,18 @@ export default {
computed: {
...mapState({
- options: state => state.options,
+ options: state => state.options.list,
acl: state => state.poll.acl,
}),
...mapGetters({
- sortedOptions: 'options/sorted',
PollIsClosed: 'poll/closed',
countOptions: 'options/count',
}),
sortOptions: {
get() {
- return this.sortedOptions
+ return this.options
},
set(value) {
this.$store.dispatch('options/reorder', value)
diff --git a/src/js/components/SideBar/SideBarTabConfiguration.vue b/src/js/components/SideBar/SideBarTabConfiguration.vue
index 0e42c21f..f19fe1f4 100644
--- a/src/js/components/SideBar/SideBarTabConfiguration.vue
+++ b/src/js/components/SideBar/SideBarTabConfiguration.vue
@@ -56,6 +56,10 @@
use-num-modifiers
@add="pollOptionLimit++"
@subtract="pollOptionLimit--" />
+ <CheckBoxDiv v-if="pollOptionLimit"
+ v-model="hideBookedUp"
+ class="indented"
+ :label="t('polls', 'Hide not availabe Options')" />
</ConfigBox>
<ConfigBox :title="t('polls', 'Poll closing status')" :icon-class="closed ? 'icon-polls-closed' : 'icon-polls-open'">
@@ -216,6 +220,15 @@ export default {
},
},
+ hideBookedUp: {
+ get() {
+ return (this.poll.hideBookedUp > 0)
+ },
+ set(value) {
+ this.writeValue({ hideBookedUp: +value })
+ },
+ },
+
pollShowResults: {
get() {
return this.poll.showResults
diff --git a/src/js/components/VoteTable/VoteItem.vue b/src/js/components/VoteTable/VoteItem.vue
index fd95e02b..040183ea 100644
--- a/src/js/components/VoteTable/VoteItem.vue
+++ b/src/js/components/VoteTable/VoteItem.vue
@@ -60,7 +60,11 @@ export default {
}),
isVotable() {
- return this.isActive && this.isValidUser && !this.pollIsClosed && !this.isLocked && !this.isBlocked
+ return this.isActive
+ && this.isValidUser
+ && !this.pollIsClosed
+ && !this.isLocked
+ && !this.option.isBookedUp
},
isActive() {
@@ -78,10 +82,6 @@ export default {
}).voteAnswer
},
- isBlocked() {
- return this.optionLimit > 0 && this.optionLimit <= this.option.yes && this.answer !== 'yes'
- },
-
isLocked() {
return (this.countYesVotes >= this.voteLimit && this.voteLimit > 0 && this.answer !== 'yes')
},
diff --git a/src/js/components/VoteTable/VoteTable.vue b/src/js/components/VoteTable/VoteTable.vue
index aeff9eb8..0aeb53cc 100644
--- a/src/js/components/VoteTable/VoteTable.vue
+++ b/src/js/components/VoteTable/VoteTable.vue
@@ -130,16 +130,16 @@ export default {
acl: state => state.poll.acl,
poll: state => state.poll,
settings: state => state.settings.user,
+ options: state => state.options.list,
}),
...mapGetters({
closed: 'poll/closed',
participants: 'poll/participants',
- sortedOptions: 'options/sorted',
}),
rankedOptions() {
- return orderBy(this.sortedOptions, this.ranked ? 'rank' : 'order', 'asc')
+ return orderBy(this.options, this.ranked ? 'rank' : 'order', 'asc')
},
},
diff --git a/src/js/mixins/watchPolls.js b/src/js/mixins/watchPolls.js
index aea224ca..b34d683c 100644
--- a/src/js/mixins/watchPolls.js
+++ b/src/js/mixins/watchPolls.js
@@ -47,10 +47,16 @@ export const watchPolls = {
// load poll list only, when not in public poll
dispatches.push('polls/load')
}
- if (item.pollId === parseInt(this.$route.params.id)) {
+ if (item.pollId === parseInt(this.$route.params.id ?? this.$store.state.share.pollId)) {
// if current poll is affected, load current poll configuration
dispatches.push('poll/get')
+ // load also options and votes
+ dispatches.push('votes/list')
+ dispatches.push('options/list')
}
+ } else if (['votes', 'options'].includes(item.table)) {
+ dispatches.push('votes/list')
+ dispatches.push('options/list')
} else {
// a table of the current poll was reported, load
// corresponding stores
diff --git a/src/js/store/modules/options.js b/src/js/store/modules/options.js
index 8efd4f4d..a6570336 100644
--- a/src/js/store/modules/options.js
+++ b/src/js/store/modules/options.js
@@ -21,7 +21,6 @@
*/
import axios from '@nextcloud/axios'
-import orderBy from 'lodash/orderBy'
import { generateUrl } from '@nextcloud/router'
const defaultOptions = () => {
@@ -82,34 +81,6 @@ const getters = {
return state.list.length
},
- sorted: (state, getters, rootState, rootGetters) => {
- let rankedOptions = []
- state.list.forEach((option) => {
- rankedOptions.push({
- ...option,
- rank: 0,
- no: 0,
- yes: rootState.votes.list.filter(vote => vote.voteOptionText === option.pollOptionText && vote.voteAnswer === 'yes').length,
- maybe: rootState.votes.list.filter(vote => vote.voteOptionText === option.pollOptionText && vote.voteAnswer === 'maybe').length,
- realno: rootState.votes.list.filter(vote => vote.voteOptionText === option.pollOptionText && vote.voteAnswer === 'no').length,
- votes: rootGetters['poll/participantsVoted'].length,
- })
- })
-
- rankedOptions = orderBy(rankedOptions, ['yes', 'maybe'], ['desc', 'desc'])
-
- for (let i = 0; i < rankedOptions.length; i++) {
- rankedOptions[i].no = rankedOptions[i].votes - rankedOptions[i].yes - rankedOptions[i].maybe
- if (i > 0 && rankedOptions[i].yes === rankedOptions[i - 1].yes && rankedOptions[i].maybe === rankedOptions[i - 1].maybe) {
- rankedOptions[i].rank = rankedOptions[i - 1].rank
- } else {
- rankedOptions[i].rank = i + 1
- }
- }
-
- return orderBy(rankedOptions, 'order')
- },
-
confirmed: state => {
return state.list.filter(option => {
return option.confirmed > 0
diff --git a/src/js/store/modules/poll.js b/src/js/store/modules/poll.js
index 6c67dc29..c1d16447 100644
--- a/src/js/store/modules/poll.js
+++ b/src/js/store/modules/poll.js
@@ -45,6 +45,7 @@ const defaultPoll = () => {
showResults: 'always',
adminAccess: 0,
important: 0,
+ hideBookedUp: 0,
}
}
diff --git a/src/js/store/modules/votes.js b/src/js/store/modules/votes.js
index bc9adff5..0a2fffd5 100644
--- a/src/js/store/modules/votes.js
+++ b/src/js/store/modules/votes.js
@@ -21,7 +21,6 @@
*/
import axios from '@nextcloud/axios'
-import orderBy from 'lodash/orderBy'
import { generateUrl } from '@nextcloud/router'
const defaultVotes = () => {
@@ -70,31 +69,6 @@ const getters = {
})
},
- ranked: (state, getters, rootState) => {
- let votesRank = []
- rootState.options.list.forEach(function(option) {
- const countYes = state.list.filter(vote => vote.voteOptionText === option.pollOptionText && vote.voteAnswer === 'yes').length
- const countMaybe = state.list.filter(vote => vote.voteOptionText === option.pollOptionText && vote.voteAnswer === 'maybe').length
- const countNo = state.list.filter(vote => vote.voteOptionText === option.pollOptionText && vote.voteAnswer === 'no').length
- votesRank.push({
- rank: 0,
- pollOptionText: option.pollOptionText,
- yes: countYes,
- no: countNo,
- maybe: countMaybe,
- })
- })
- votesRank = orderBy(votesRank, ['yes', 'maybe'], ['desc', 'desc'])
- for (let i = 0; i < votesRank.length; i++) {
- if (i > 0 && votesRank[i].yes === votesRank[i - 1].yes && votesRank[i].maybe === votesRank[i - 1].maybe) {
- votesRank[i].rank = votesRank[i - 1].rank
- } else {
- votesRank[i].rank = i + 1
- }
- }
- return votesRank
- },
-
countYesVotes: (state, getters, rootState) => {
return getters.relevant.filter(vote => vote.userId === rootState.poll.acl.userId && vote.voteAnswer === 'yes').length
},
@@ -149,9 +123,11 @@ const actions = {
setTo: payload.setTo,
})
context.commit('setItem', { option: payload.option, pollId: context.rootState.poll.id, vote: response.data.vote })
+ context.dispatch('options/list', null, { root: true })
} catch (e) {
if (e.response.status === 409) {
context.dispatch('list')
+ context.dispatch('options/list', null, { root: true })
} else {
console.error('Error setting vote', { error: e.response }, { payload: payload })
throw e