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:
authordartcafe <github@dartcafe.de>2021-01-10 23:28:11 +0300
committerdartcafe <github@dartcafe.de>2021-01-11 00:43:46 +0300
commit98feeb300ebd1a46c3bc4a9a7fd4c6d82a247d9b (patch)
tree1a8d91ee23e5c4e5c885e59d15ef993ca60270b2 /src/js/store
parentc8a5e72cdd7451347011b83a320ec21a8ce927b4 (diff)
refactoring, optimization, tidy
Signed-off-by: dartcafe <github@dartcafe.de>
Diffstat (limited to 'src/js/store')
-rw-r--r--src/js/store/modules/poll.js23
-rw-r--r--src/js/store/modules/share.js (renamed from src/js/store/modules/subModules/share.js)37
-rw-r--r--src/js/store/modules/subModules/options.js6
-rw-r--r--src/js/store/modules/subModules/shares.js5
-rw-r--r--src/js/store/modules/subModules/votes.js4
5 files changed, 40 insertions, 35 deletions
diff --git a/src/js/store/modules/poll.js b/src/js/store/modules/poll.js
index b21119bf..2ee542bd 100644
--- a/src/js/store/modules/poll.js
+++ b/src/js/store/modules/poll.js
@@ -28,7 +28,6 @@ import acl from './subModules/acl.js'
import comments from './subModules/comments.js'
import options from './subModules/options.js'
import shares from './subModules/shares.js'
-import share from './subModules/share.js'
import votes from './subModules/votes.js'
const defaultPoll = () => {
@@ -61,7 +60,6 @@ const modules = {
options: options,
shares: shares,
votes: votes,
- share: share,
}
const mutations = {
@@ -143,29 +141,20 @@ const actions = {
get(context, payload) {
let endPoint = 'apps/polls'
- if (payload.token) {
- endPoint = endPoint + '/s/' + payload.token + '/poll'
- } else if (payload.pollId) {
- endPoint = endPoint + '/poll/' + payload.pollId
+
+ if (context.rootState.route.name === 'publicVote') {
+ endPoint = endPoint + '/s/' + context.rootState.route.params.token
+ } else if (context.rootState.route.name === 'vote') {
+ endPoint = endPoint + '/poll/' + context.rootState.route.params.id
} else {
context.commit('reset')
context.commit('acl/reset')
- // context.commit('comments/reset')
- // context.commit('options/reset')
- // context.commit('shares/reset')
- context.commit('share/reset')
- // context.commit('votes/reset')
return
}
- return axios.get(generateUrl(endPoint))
+ return axios.get(generateUrl(endPoint + '/poll'))
.then((response) => {
context.commit('set', response.data)
context.commit('acl/set', response.data)
- // context.commit('comments/set', response.data)
- // context.commit('options/set', response.data)
- // context.commit('shares/set', response.data)
- context.commit('share/set', response.data)
- // context.commit('votes/set', response.data)
return response
})
.catch((error) => {
diff --git a/src/js/store/modules/subModules/share.js b/src/js/store/modules/share.js
index 4d7dd9cf..98cab838 100644
--- a/src/js/store/modules/subModules/share.js
+++ b/src/js/store/modules/share.js
@@ -49,26 +49,37 @@ const mutations = {
reset(state) {
Object.assign(state, defaultShares())
},
-
}
const actions = {
- get(context, payload) {
- const endPoint = 'apps/polls/share'
- return axios.get(generateUrl(endPoint + '/' + payload.token))
+ get(context) {
+ let endPoint = 'apps/polls'
+ if (context.rootState.route.name === 'publicVote') {
+ endPoint = endPoint + '/s/' + context.rootState.route.params.token
+ } else {
+ context.commit('reset')
+ return
+ }
+ return axios.get(generateUrl(endPoint + '/share'))
.then((response) => {
context.commit('set', { share: response.data.share })
return response.data
})
.catch((error) => {
- console.error('Error retrieving share', { error: error.response }, { payload: payload })
- throw error
+ console.debug('Error retrieving share', { error: error.response })
+ throw error.response
})
},
register(context, payload) {
- const endPoint = 'apps/polls/s'
- return axios.post(generateUrl(endPoint + '/' + context.state.token + '/register'), {
+ let endPoint = 'apps/polls'
+ if (context.rootState.route.name === 'publicVote') {
+ endPoint = endPoint + '/s/' + context.rootState.route.params.token
+ } else {
+ return
+ }
+
+ return axios.post(generateUrl(endPoint + '/register'), {
userName: payload.userName,
emailAddress: payload.emailAddress,
})
@@ -83,8 +94,14 @@ const actions = {
},
resendInvitation(context, payload) {
- const endPoint = 'apps/polls/s'
- return axios.get(generateUrl(endPoint + '/' + context.state.token + '/resend'))
+ let endPoint = 'apps/polls'
+ if (context.rootState.route.name === 'publicVote') {
+ endPoint = endPoint + '/s/' + context.rootState.route.params.token
+ } else {
+ return
+ }
+
+ return axios.get(generateUrl(endPoint + '/resend'))
.then((response) => {
return response
})
diff --git a/src/js/store/modules/subModules/options.js b/src/js/store/modules/subModules/options.js
index 55de7776..91894b1e 100644
--- a/src/js/store/modules/subModules/options.js
+++ b/src/js/store/modules/subModules/options.js
@@ -137,7 +137,7 @@ const actions = {
context.commit('set', { options: response.data.options })
})
.catch((error) => {
- console.error('Error loding options', { error: error.response }, { pollId: context.rootState.poll.id })
+ console.error('Error loding options', { error: error.response }, { pollId: context.rootState.route.params.id })
throw error
})
},
@@ -145,7 +145,7 @@ const actions = {
add(context, payload) {
const endPoint = 'apps/polls/option'
return axios.post(generateUrl(endPoint), {
- pollId: context.rootState.poll.id,
+ pollId: context.rootState.route.params.id,
timestamp: payload.timestamp,
pollOptionText: payload.pollOptionText,
})
@@ -207,7 +207,7 @@ const actions = {
reorder(context, payload) {
const endPoint = 'apps/polls/poll'
context.commit('reorder', { options: payload })
- return axios.post(generateUrl(endPoint + '/' + context.rootState.poll.id + '/options/reorder'), {
+ return axios.post(generateUrl(endPoint + '/' + context.rootState.route.params.id + '/options/reorder'), {
options: payload,
})
.then((response) => {
diff --git a/src/js/store/modules/subModules/shares.js b/src/js/store/modules/subModules/shares.js
index ec52ea90..c2002827 100644
--- a/src/js/store/modules/subModules/shares.js
+++ b/src/js/store/modules/subModules/shares.js
@@ -98,20 +98,19 @@ const actions = {
context.commit('reset')
return
}
-
return axios.get(generateUrl(endPoint + '/shares'))
.then((response) => {
context.commit('set', response.data)
return response.data
})
.catch((error) => {
- console.error('Error loading shares', { error: error.response }, { pollId: context.rootState.poll.id })
+ console.error('Error loading shares', { error: error.response }, { pollId: context.rootState.route.params.id })
throw error
})
},
add(context, payload) {
- const endPoint = 'apps/polls/poll/' + context.rootState.poll.id
+ const endPoint = 'apps/polls/poll/' + context.rootState.route.params.id
return axios.post(generateUrl(endPoint + '/share'), payload.share)
.then((response) => {
diff --git a/src/js/store/modules/subModules/votes.js b/src/js/store/modules/subModules/votes.js
index 6736237d..cfddad12 100644
--- a/src/js/store/modules/subModules/votes.js
+++ b/src/js/store/modules/subModules/votes.js
@@ -133,7 +133,7 @@ const actions = {
setTo: payload.setTo,
})
.then((response) => {
- context.commit('setItem', { option: payload.option, pollId: context.rootState.poll.id, vote: response.data.vote })
+ context.commit('setItem', { option: payload.option, pollId: context.rootState.route.params.id, vote: response.data.vote })
return response.data
})
.catch((error) => {
@@ -143,7 +143,7 @@ const actions = {
},
deleteUser(context, payload) {
- const endPoint = 'apps/polls/poll/' + context.rootState.poll.id + '/user/' + payload.userId
+ const endPoint = 'apps/polls/poll/' + context.rootState.route.params.id + '/user/' + payload.userId
return axios.delete(generateUrl(endPoint))
.then(() => {
context.commit('deleteVotes', payload)