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
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/js/store
parent5e04fe191f047d88080db44c60b0b562d7b1f62a (diff)
added hide options if booked out and move some logic to backend (#1449)
Diffstat (limited to 'src/js/store')
-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
3 files changed, 3 insertions, 55 deletions
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