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>2022-11-07 02:42:58 +0300
committerdartcafe <github@dartcafe.de>2022-11-07 02:42:58 +0300
commit97509e53a1a487ae3985170061d26df9287b551b (patch)
treed236069fbd79cac696441468f0ea7ec9a45b7764
parent8df58e63e2145b2754e94b0d55b77fc8e8131c7c (diff)
move backend requests from store to new api
Signed-off-by: dartcafe <github@dartcafe.de>
-rw-r--r--src/js/Api/AxiosHelper.js110
-rw-r--r--src/js/Api/activity.js45
-rw-r--r--src/js/Api/appSettings.js47
-rw-r--r--src/js/Api/calendar.js46
-rw-r--r--src/js/Api/comments.js57
-rw-r--r--src/js/Api/options.js121
-rw-r--r--src/js/Api/polls.js141
-rw-r--r--src/js/Api/public.js203
-rw-r--r--src/js/Api/shares.js94
-rw-r--r--src/js/Api/userSettings.js47
-rw-r--r--src/js/Api/validators.js49
-rw-r--r--src/js/Api/votes.js55
-rw-r--r--src/js/Exceptions/Exceptions.js11
-rw-r--r--src/js/components/Actions/ActionSendConfirmedOptions.vue3
-rw-r--r--src/js/components/Calendar/CalendarPeek.vue5
-rw-r--r--src/js/components/Export/ExportPoll.vue3
-rw-r--r--src/js/components/Poll/PublicRegisterModal.vue86
-rw-r--r--src/js/components/User/UserMenu.vue3
-rw-r--r--src/js/helpers/AxiosHelper.js (renamed from src/js/helpers/AxiosDefault.js)3
-rw-r--r--src/js/mixins/watchPolls.js2
-rw-r--r--src/js/store/modules/activity.js15
-rw-r--r--src/js/store/modules/appSettings.js21
-rw-r--r--src/js/store/modules/combo.js26
-rw-r--r--src/js/store/modules/comments.js71
-rw-r--r--src/js/store/modules/options.js144
-rw-r--r--src/js/store/modules/poll.js75
-rw-r--r--src/js/store/modules/polls.js10
-rw-r--r--src/js/store/modules/pollsAdmin.js13
-rw-r--r--src/js/store/modules/settings.js20
-rw-r--r--src/js/store/modules/share.js55
-rw-r--r--src/js/store/modules/shares.js43
-rw-r--r--src/js/store/modules/subscription.js50
-rw-r--r--src/js/store/modules/votes.js62
33 files changed, 1269 insertions, 467 deletions
diff --git a/src/js/Api/AxiosHelper.js b/src/js/Api/AxiosHelper.js
new file mode 100644
index 00000000..2002a452
--- /dev/null
+++ b/src/js/Api/AxiosHelper.js
@@ -0,0 +1,110 @@
+/**
+ * @copyright Copyright (c) 2022 Rene Gieling <github@dartcafe.de>
+ *
+ * @author Rene Gieling <github@dartcafe.de>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import axios from '@nextcloud/axios'
+import { generateUrl, generateOcsUrl } from '@nextcloud/router'
+import { CancelledRequest } from '../Exceptions/Exceptions.js'
+
+const clientSessionId = Math.random().toString(36).substring(2)
+
+const axiosConfig = {
+ baseURL: generateUrl('apps/polls/'),
+ headers: {
+ Accept: 'application/json',
+ 'Nc-Polls-Client-Id': clientSessionId,
+ },
+}
+
+const axiosOcsConfig = {
+ baseURL: generateOcsUrl('apps/'),
+ headers: {
+ Accept: 'application/json',
+ },
+}
+
+const CancelToken = axios.CancelToken
+const axiosInstance = axios.create(axiosConfig)
+const axiosOcsInstance = axios.create(axiosOcsConfig)
+
+const axiosRequest = (payload) => {
+ try {
+ const response = axiosInstance.request(payload)
+ return response
+ } catch (e) {
+ if (axios.canceled()) {
+ throw new CancelledRequest('Request cancelled')
+ }
+ throw e
+ }
+}
+
+const axiosOcsRequest = (payload) => {
+ try {
+ const response = axiosOcsInstance.request(payload)
+ return response
+ } catch (e) {
+ if (axios.canceled()) {
+ throw new CancelledRequest('Request cancelled')
+ }
+ throw e
+ }
+}
+
+/**
+ * Description
+ *
+ * @param {any} apiObject
+ * @return {any}
+ */
+const createCancelTokenHandler = (apiObject) => {
+ // initializing the cancel token handler object
+ const cancelTokenHandler = {}
+
+ // for each property in apiObject, i.e. for each request
+ Object
+ .getOwnPropertyNames(apiObject)
+ .forEach((propertyName) => {
+ // initializing the cancel token of the request
+ const cancelTokenRequestHandler = {
+ cancelToken: undefined,
+ }
+
+ // associating the cancel token handler to the request name
+ cancelTokenHandler[propertyName] = {
+ handleRequestCancellation: () => {
+ // if a previous cancel token exists,
+ // cancel the request
+ cancelTokenRequestHandler.cancelToken && cancelTokenRequestHandler.cancelToken.cancel(`${propertyName} canceled`)
+
+ // creating a new cancel token
+ cancelTokenRequestHandler.cancelToken = CancelToken.source()
+
+ // returning the new cancel token
+ return cancelTokenRequestHandler.cancelToken
+ },
+ }
+ })
+
+ return cancelTokenHandler
+}
+
+export { axiosConfig, axiosOcsInstance, axiosOcsRequest, axiosRequest, axiosInstance, createCancelTokenHandler }
diff --git a/src/js/Api/activity.js b/src/js/Api/activity.js
new file mode 100644
index 00000000..a951414f
--- /dev/null
+++ b/src/js/Api/activity.js
@@ -0,0 +1,45 @@
+/**
+ * @copyright Copyright (c) 2022 Rene Gieling <github@dartcafe.de>
+ *
+ * @author Rene Gieling <github@dartcafe.de>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import { axiosOcsRequest, createCancelTokenHandler } from './AxiosHelper.js'
+
+const activity = {
+ getActivities(pollId) {
+ const response = axiosOcsRequest({
+ method: 'GET',
+ url: 'activity/api/v2/activity/filter',
+ params: {
+ format: 'json',
+ since: 0,
+ limit: 50,
+ object_type: 'poll',
+ object_id: pollId,
+ },
+ cancelToken: cancelTokenHandlerObject[this.getActivities.name].handleRequestCancellation().token,
+ })
+ return response
+ },
+}
+
+const cancelTokenHandlerObject = createCancelTokenHandler(activity)
+
+export { activity as ActivityAPI }
diff --git a/src/js/Api/appSettings.js b/src/js/Api/appSettings.js
new file mode 100644
index 00000000..064b4ac9
--- /dev/null
+++ b/src/js/Api/appSettings.js
@@ -0,0 +1,47 @@
+/**
+ * @copyright Copyright (c) 2022 Rene Gieling <github@dartcafe.de>
+ *
+ * @author Rene Gieling <github@dartcafe.de>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import { axiosRequest, createCancelTokenHandler } from './AxiosHelper.js'
+
+const appSettings = {
+ getAppSettings() {
+ return axiosRequest({
+ method: 'GET',
+ url: 'settings/app',
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getAppSettings.name].handleRequestCancellation().token,
+ })
+ },
+
+ writeAppSettings(appSettings) {
+ return axiosRequest({
+ method: 'POST',
+ url: 'settings/app',
+ data: appSettings,
+ cancelToken: cancelTokenHandlerObject[this.writeAppSettings.name].handleRequestCancellation().token,
+ })
+ },
+}
+
+const cancelTokenHandlerObject = createCancelTokenHandler(appSettings)
+
+export { appSettings as AppSettingsAPI }
diff --git a/src/js/Api/calendar.js b/src/js/Api/calendar.js
new file mode 100644
index 00000000..b359e19c
--- /dev/null
+++ b/src/js/Api/calendar.js
@@ -0,0 +1,46 @@
+/**
+ * @copyright Copyright (c) 2022 Rene Gieling <github@dartcafe.de>
+ *
+ * @author Rene Gieling <github@dartcafe.de>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import { axiosRequest, createCancelTokenHandler } from './AxiosHelper.js'
+
+const calendar = {
+ getCalendars() {
+ return axiosRequest({
+ method: 'GET',
+ url: 'calendars',
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getCalendars.name].handleRequestCancellation().token,
+ })
+ },
+ getEvents(pollId) {
+ return axiosRequest({
+ method: 'GET',
+ url: `option/${pollId}/events`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getEvents.name].handleRequestCancellation().token,
+ })
+ },
+}
+
+const cancelTokenHandlerObject = createCancelTokenHandler(calendar)
+
+export { calendar as CalendarAPI }
diff --git a/src/js/Api/comments.js b/src/js/Api/comments.js
new file mode 100644
index 00000000..b5131eed
--- /dev/null
+++ b/src/js/Api/comments.js
@@ -0,0 +1,57 @@
+/**
+ * @copyright Copyright (c) 2022 Rene Gieling <github@dartcafe.de>
+ *
+ * @author Rene Gieling <github@dartcafe.de>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import { axiosRequest, createCancelTokenHandler } from './AxiosHelper.js'
+
+const comments = {
+ getComments(pollId) {
+ return axiosRequest({
+ method: 'GET',
+ url: `poll/${pollId}/comments`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getComments.name].handleRequestCancellation().token,
+ })
+ },
+ addComment(pollId, message) {
+ return axiosRequest({
+ method: 'POST',
+ url: `poll/${pollId}/comment`,
+ data: { message },
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.addComment.name].handleRequestCancellation().token,
+ })
+ },
+
+ deleteComment(commentId) {
+ return axiosRequest({
+ method: 'DELETE',
+ url: `comment/${commentId}`,
+ params: { time: +new Date() },
+
+ cancelToken: cancelTokenHandlerObject[this.deleteComment.name].handleRequestCancellation().token,
+ })
+ },
+}
+
+const cancelTokenHandlerObject = createCancelTokenHandler(comments)
+
+export { comments as CommentsAPI }
diff --git a/src/js/Api/options.js b/src/js/Api/options.js
new file mode 100644
index 00000000..c1588971
--- /dev/null
+++ b/src/js/Api/options.js
@@ -0,0 +1,121 @@
+/**
+ * @copyright Copyright (c) 2022 Rene Gieling <github@dartcafe.de>
+ *
+ * @author Rene Gieling <github@dartcafe.de>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import { axiosRequest, createCancelTokenHandler } from './AxiosHelper.js'
+
+const options = {
+ getOptions(pollId) {
+ return axiosRequest({
+ method: 'GET',
+ url: `poll/${pollId}/options`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getOptions.name].handleRequestCancellation().token,
+ })
+ },
+
+ addOption(option) {
+ return axiosRequest({
+ method: 'POST',
+ url: 'option',
+ data: { ...option },
+ cancelToken: cancelTokenHandlerObject[this.addOption.name].handleRequestCancellation().token,
+ })
+ },
+
+ updateOption(option) {
+ return axiosRequest({
+ method: 'PUT',
+ url: `option/${option.id}`,
+ // TODO: replace text with timestamp
+ data: { ...option },
+ cancelToken: cancelTokenHandlerObject[this.updateOption.name].handleRequestCancellation().token,
+ })
+ },
+
+ deleteOption(optionId) {
+ return axiosRequest({
+ method: 'DELETE',
+ url: `option/${optionId}`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.deleteOption.name].handleRequestCancellation().token,
+ })
+ },
+
+ addOptions(pollId, optionsBatch) {
+ return axiosRequest({
+ method: 'POST',
+ url: 'option/bulk',
+ data: {
+ pollId,
+ text: optionsBatch,
+ },
+ cancelToken: cancelTokenHandlerObject[this.takeOver.name].handleRequestCancellation().token,
+ })
+ },
+
+ confirmOption(optionId) {
+ return axiosRequest({
+ method: 'PUT',
+ url: `option/${optionId}/confirm`,
+ cancelToken: cancelTokenHandlerObject[this.confirmOption.name].handleRequestCancellation().token,
+ })
+ },
+
+ reorderOptions(pollId, options) {
+ return axiosRequest({
+ method: 'POST',
+ url: `poll/${pollId}/options/reorder`,
+ data: { options },
+ cancelToken: cancelTokenHandlerObject[this.reorderOptions.name].handleRequestCancellation().token,
+ })
+ },
+
+ addOptionsSequence(optionId, step, unit, amount) {
+ return axiosRequest({
+ method: 'POST',
+ url: `option/${optionId}/sequence`,
+ data: {
+ step,
+ unit,
+ amount,
+ },
+ cancelToken: cancelTokenHandlerObject[this.addOptionsSequence.name].handleRequestCancellation().token,
+ })
+ },
+
+ shiftOptions(pollId, step, unit) {
+ return axiosRequest({
+ method: 'POST',
+ url: `poll/${pollId}/shift`,
+ data: {
+ step,
+ unit,
+ },
+ cancelToken: cancelTokenHandlerObject[this.shiftOptions.name].handleRequestCancellation().token,
+ })
+ },
+
+}
+
+const cancelTokenHandlerObject = createCancelTokenHandler(options)
+
+export { options as OptionsAPI }
diff --git a/src/js/Api/polls.js b/src/js/Api/polls.js
new file mode 100644
index 00000000..176e99ad
--- /dev/null
+++ b/src/js/Api/polls.js
@@ -0,0 +1,141 @@
+/**
+ * @copyright Copyright (c) 2022 Rene Gieling <github@dartcafe.de>
+ *
+ * @author Rene Gieling <github@dartcafe.de>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import { axiosRequest, createCancelTokenHandler } from './AxiosHelper.js'
+
+const polls = {
+ getPolls() {
+ return axiosRequest({
+ method: 'GET',
+ url: 'polls',
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getPolls.name].handleRequestCancellation().token,
+ })
+ },
+
+ getPollsForAdmin() {
+ return axiosRequest({
+ method: 'GET',
+ url: 'administration/polls',
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getPollsForAdmin.name].handleRequestCancellation().token,
+ })
+ },
+
+ getPoll(pollId) {
+ return axiosRequest({
+ method: 'GET',
+ url: `poll/${pollId}/poll`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getPoll.name].handleRequestCancellation().token,
+ })
+ },
+
+ takeOver(pollId) {
+ return axiosRequest({
+ method: 'PUT',
+ url: `apps/polls/administration/poll/${pollId}/takeover`,
+ cancelToken: cancelTokenHandlerObject[this.takeOver.name].handleRequestCancellation().token,
+ })
+ },
+
+ addPoll(type, title) {
+ return axiosRequest({
+ method: 'POST',
+ url: 'poll/add',
+ data: {
+ type,
+ title,
+ },
+ cancelToken: cancelTokenHandlerObject[this.addPoll.name].handleRequestCancellation().token,
+ })
+ },
+
+ updatePoll(poll) {
+ return axiosRequest({
+ method: 'PUT',
+ url: `poll/${poll.id}`,
+ data: { poll },
+ cancelToken: cancelTokenHandlerObject[this.updatePoll.name].handleRequestCancellation().token,
+ })
+ },
+
+ deletePoll(pollId) {
+ return axiosRequest({
+ method: 'DELETE',
+ url: `poll/${pollId}`,
+ cancelToken: cancelTokenHandlerObject[this.deletePoll.name].handleRequestCancellation().token,
+ })
+ },
+
+ toggleArchive(pollId) {
+ return axiosRequest({
+ method: 'PUT',
+ url: `poll/${pollId}/toggleArchive`,
+ cancelToken: cancelTokenHandlerObject[this.toggleArchive.name].handleRequestCancellation().token,
+ })
+ },
+
+ clonePoll(pollId) {
+ return axiosRequest({
+ method: 'POST',
+ url: `poll/${pollId}/clone`,
+ cancelToken: cancelTokenHandlerObject[this.clonePoll.name].handleRequestCancellation().token,
+ })
+ },
+
+ sendConfirmation(pollId) {
+ return axiosRequest({
+ method: 'POST',
+ url: `poll/${pollId}/confirmation`,
+ cancelToken: cancelTokenHandlerObject[this.sendConfirmation.name].handleRequestCancellation().token,
+ })
+ },
+
+ getParticipantsEmailAddresses(pollId) {
+ return axiosRequest({
+ method: 'GET',
+ url: `poll/${pollId}/addresses`,
+ cancelToken: cancelTokenHandlerObject[this.getParticipantsEmailAddresses.name].handleRequestCancellation().token,
+ })
+ },
+
+ getSubscription(pollId) {
+ return axiosRequest({
+ method: 'GET',
+ url: `poll/${pollId}/subscription`,
+ cancelToken: cancelTokenHandlerObject[this.getSubscription.name].handleRequestCancellation().token,
+ })
+ },
+
+ setSubscription(pollId, subscription) {
+ return axiosRequest({
+ method: 'PUT',
+ url: `poll/${pollId}${subscription ? '/subscribe' : '/unsubscribe'}`,
+ cancelToken: cancelTokenHandlerObject[this.setSubscription.name].handleRequestCancellation().token,
+ })
+ },
+}
+
+const cancelTokenHandlerObject = createCancelTokenHandler(polls)
+
+export { polls as PollsAPI }
diff --git a/src/js/Api/public.js b/src/js/Api/public.js
new file mode 100644
index 00000000..40f28f25
--- /dev/null
+++ b/src/js/Api/public.js
@@ -0,0 +1,203 @@
+/**
+ * @copyright Copyright (c) 2022 Rene Gieling <github@dartcafe.de>
+ *
+ * @author Rene Gieling <github@dartcafe.de>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import { axiosRequest, createCancelTokenHandler } from './AxiosHelper.js'
+
+const publicPoll = {
+ getPoll(shareToken) {
+ return axiosRequest({
+ method: 'GET',
+ url: `/s/${shareToken}/poll`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getPoll.name].handleRequestCancellation().token,
+ })
+ },
+
+ watch(shareToken) {
+ return axiosRequest({
+ method: 'GET',
+ url: `s/${shareToken}/watch`,
+ cancelToken: cancelTokenHandlerObject[this.watch.name].handleRequestCancellation().token,
+ })
+ },
+
+ getOptions(shareToken) {
+ return axiosRequest({
+ method: 'GET',
+ url: `/s/${shareToken}/options`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getOptions.name].handleRequestCancellation().token,
+ })
+ },
+
+ addOption(shareToken, option) {
+ return axiosRequest({
+ method: 'POST',
+ url: `/s/${shareToken}/option`,
+ data: { ...option },
+ cancelToken: cancelTokenHandlerObject[this.addOption.name].handleRequestCancellation().token,
+ })
+ },
+
+ deleteOption(shareToken, optionId) {
+ return axiosRequest({
+ method: 'DELETE',
+ url: `s/${shareToken}/option/${optionId}`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.deleteOption.name].handleRequestCancellation().token,
+ })
+ },
+
+ getVotes(shareToken) {
+ return axiosRequest({
+ method: 'GET',
+ url: `/s/${shareToken}/votes`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getVotes.name].handleRequestCancellation().token,
+ })
+ },
+
+ setVote(shareToken, optionId, setTo) {
+ return axiosRequest({
+ method: 'PUT',
+ url: `s/${shareToken}/vote`,
+ data: { optionId, setTo },
+ cancelToken: cancelTokenHandlerObject[this.setVote.name].handleRequestCancellation().token,
+ })
+ },
+
+ removeVotes(shareToken) {
+ return axiosRequest({
+ method: 'DELETE',
+ url: `s/${shareToken}/user`,
+ cancelToken: cancelTokenHandlerObject[this.removeVotes.name].handleRequestCancellation().token,
+ })
+ },
+
+ getComments(shareToken) {
+ return axiosRequest({
+ method: 'GET',
+ url: `/s/${shareToken}/comments`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getComments.name].handleRequestCancellation().token,
+ })
+ },
+
+ addComment(shareToken, message) {
+ return axiosRequest({
+ method: 'POST',
+ url: `s/${shareToken}/comment`,
+ data: { message },
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.addComment.name].handleRequestCancellation().token,
+ })
+ },
+
+ deleteComment(shareToken, commentId) {
+ return axiosRequest({
+ method: 'DELETE',
+ url: `s/${shareToken}/${commentId}`,
+ params: { time: +new Date() },
+
+ cancelToken: cancelTokenHandlerObject[this.deleteComment.name].handleRequestCancellation().token,
+ })
+ },
+
+ getShare(shareToken) {
+ return axiosRequest({
+ method: 'GET',
+ url: `s/${shareToken}/share`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getShare.name].handleRequestCancellation().token,
+ })
+ },
+
+ setEmail(shareToken, emailAddress) {
+ return axiosRequest({
+ method: 'PUT',
+ url: `s/${shareToken}/email/${emailAddress}`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.setEmail.name].handleRequestCancellation().token,
+ })
+ },
+
+ deleteEmailAddress(shareToken) {
+ return axiosRequest({
+ method: 'DELETE',
+ url: `s/${shareToken}/email`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.setEmailAddress.name].handleRequestCancellation().token,
+ })
+ },
+
+ setDisplayName(shareToken, displayName) {
+ return axiosRequest({
+ method: 'PUT',
+ url: `s/${shareToken}/name/${displayName}`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.setDisplayName.name].handleRequestCancellation().token,
+ })
+ },
+
+ resendInvitation(shareToken) {
+ return axiosRequest({
+ method: 'POST',
+ url: `s/${shareToken}/resend`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.resendInvitation.name].handleRequestCancellation().token,
+ })
+ },
+
+ getSubscription(shareToken) {
+ return axiosRequest({
+ method: 'GET',
+ url: `s/${shareToken}/subscription`,
+ cancelToken: cancelTokenHandlerObject[this.getSubscription.name].handleRequestCancellation().token,
+ })
+ },
+
+ setSubscription(shareToken, subscription) {
+ return axiosRequest({
+ method: 'PUT',
+ url: `s/${shareToken}${subscription ? '/subscribe' : '/unsubscribe'}`,
+ cancelToken: cancelTokenHandlerObject[this.setSubscription.name].handleRequestCancellation().token,
+ })
+ },
+
+ register(shareToken, userName, emailAddress, timeZone) {
+ return axiosRequest({
+ method: 'POST',
+ url: `s/${shareToken}/register`,
+ data: {
+ userName,
+ emailAddress,
+ timeZone,
+ },
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.register.name].handleRequestCancellation().token,
+ })
+ },
+}
+
+const cancelTokenHandlerObject = createCancelTokenHandler(publicPoll)
+
+export { publicPoll as PublicAPI }
diff --git a/src/js/Api/shares.js b/src/js/Api/shares.js
new file mode 100644
index 00000000..4a48ee40
--- /dev/null
+++ b/src/js/Api/shares.js
@@ -0,0 +1,94 @@
+/**
+ * @copyright Copyright (c) 2022 Rene Gieling <github@dartcafe.de>
+ *
+ * @author Rene Gieling <github@dartcafe.de>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import { axiosRequest, createCancelTokenHandler } from './AxiosHelper.js'
+
+const shares = {
+ getShares(pollId) {
+ return axiosRequest({
+ method: 'GET',
+ url: `poll/${pollId}/shares`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getShares.name].handleRequestCancellation().token,
+ })
+ },
+
+ addShare(pollId, share) {
+ return axiosRequest({
+ method: 'POST',
+ url: `poll/${pollId}/share`,
+ data: {
+ ...share,
+ },
+ cancelToken: cancelTokenHandlerObject[this.addShare.name].handleRequestCancellation().token,
+ })
+ },
+
+ switchAdmin(shareToken, setTo) {
+ return axiosRequest({
+ method: 'PUT',
+ url: `share/${shareToken}/${setTo}`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.switchAdmin.name].handleRequestCancellation().token,
+ })
+ },
+
+ setEmailAddressConstraint(shareToken, setTo) {
+ return axiosRequest({
+ method: 'PUT',
+ url: `share/${shareToken}/publicpollemail/${setTo}`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.setEmailAddressConstraint.name].handleRequestCancellation().token,
+ })
+ },
+
+ sendInvitation(shareToken) {
+ return axiosRequest({
+ method: 'POST',
+ url: `share/${shareToken}/invite`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.sendInvitation.name].handleRequestCancellation().token,
+ })
+ },
+
+ resolveShare(shareToken) {
+ return axiosRequest({
+ method: 'GET',
+ url: `share/${shareToken}/resolve`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.resolveShare.name].handleRequestCancellation().token,
+ })
+ },
+
+ deleteShare(shareToken) {
+ return axiosRequest({
+ method: 'DELETE',
+ url: `share/${shareToken}`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.deleteShare.name].handleRequestCancellation().token,
+ })
+ },
+}
+
+const cancelTokenHandlerObject = createCancelTokenHandler(shares)
+
+export { shares as SharesAPI }
diff --git a/src/js/Api/userSettings.js b/src/js/Api/userSettings.js
new file mode 100644
index 00000000..17ab77cb
--- /dev/null
+++ b/src/js/Api/userSettings.js
@@ -0,0 +1,47 @@
+/**
+ * @copyright Copyright (c) 2022 Rene Gieling <github@dartcafe.de>
+ *
+ * @author Rene Gieling <github@dartcafe.de>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import { axiosRequest, createCancelTokenHandler } from './AxiosHelper.js'
+
+const userSettings = {
+ getUserSettings() {
+ return axiosRequest({
+ method: 'GET',
+ url: 'preferences',
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getUserSettings.name].handleRequestCancellation().token,
+ })
+ },
+
+ writeUserSettings(settings) {
+ return axiosRequest({
+ method: 'POST',
+ url: 'settings/app',
+ data: settings,
+ cancelToken: cancelTokenHandlerObject[this.writeUserSettings.name].handleRequestCancellation().token,
+ })
+ },
+}
+
+const cancelTokenHandlerObject = createCancelTokenHandler(userSettings)
+
+export { userSettings as UserSettingsAPI }
diff --git a/src/js/Api/validators.js b/src/js/Api/validators.js
new file mode 100644
index 00000000..dbbfdc70
--- /dev/null
+++ b/src/js/Api/validators.js
@@ -0,0 +1,49 @@
+/**
+ * @copyright Copyright (c) 2022 Rene Gieling <github@dartcafe.de>
+ *
+ * @author Rene Gieling <github@dartcafe.de>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import { axiosRequest, createCancelTokenHandler } from './AxiosHelper.js'
+
+const validators = {
+ validateEmailAddress(emailAddress) {
+ return axiosRequest({
+ method: 'GET',
+ url: `check/emailaddress/${emailAddress}`,
+ cancelToken: cancelTokenHandlerObject[this.validateEmailAddress.name].handleRequestCancellation().token,
+ })
+ },
+
+ validateName(pollToken, name) {
+ return axiosRequest({
+ method: 'POST',
+ url: 'check/username',
+ cancelToken: cancelTokenHandlerObject[this.validateName.name].handleRequestCancellation().token,
+ data: {
+ userName: name,
+ token: pollToken,
+ },
+ })
+ },
+}
+
+const cancelTokenHandlerObject = createCancelTokenHandler(validators)
+
+export { validators as ValidatorAPI }
diff --git a/src/js/Api/votes.js b/src/js/Api/votes.js
new file mode 100644
index 00000000..2ff1586e
--- /dev/null
+++ b/src/js/Api/votes.js
@@ -0,0 +1,55 @@
+/**
+ * @copyright Copyright (c) 2022 Rene Gieling <github@dartcafe.de>
+ *
+ * @author Rene Gieling <github@dartcafe.de>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import { axiosRequest, createCancelTokenHandler } from './AxiosHelper.js'
+
+const votes = {
+ getVotes(pollId) {
+ return axiosRequest({
+ method: 'GET',
+ url: `poll/${pollId}/votes`,
+ params: { time: +new Date() },
+ cancelToken: cancelTokenHandlerObject[this.getVotes.name].handleRequestCancellation().token,
+ })
+ },
+
+ setVote(optionId, setTo) {
+ return axiosRequest({
+ method: 'PUT',
+ url: 'vote',
+ data: { optionId, setTo },
+ cancelToken: cancelTokenHandlerObject[this.setVote.name].handleRequestCancellation().token,
+ })
+ },
+
+ removeUser(pollId, userId = null) {
+ return axiosRequest({
+ method: 'DELETE',
+ url: userId ? `poll/${pollId}/user/${userId}` : `poll/${pollId}/user`,
+ cancelToken: cancelTokenHandlerObject[this.removeUser.name].handleRequestCancellation().token,
+ })
+ },
+}
+
+const cancelTokenHandlerObject = createCancelTokenHandler(votes)
+
+export { votes as VotesAPI }
diff --git a/src/js/Exceptions/Exceptions.js b/src/js/Exceptions/Exceptions.js
index 4e5ae135..83a56a17 100644
--- a/src/js/Exceptions/Exceptions.js
+++ b/src/js/Exceptions/Exceptions.js
@@ -47,4 +47,13 @@ class InvalidJSON extends Error {
}
-export { Exception, InvalidJSON, NotReady }
+class CancelledRequest extends Error {
+
+ constructor(message) {
+ super(message)
+ this.name = 'cancelledRequest'
+ }
+
+}
+
+export { Exception, InvalidJSON, NotReady, CancelledRequest }
diff --git a/src/js/components/Actions/ActionSendConfirmedOptions.vue b/src/js/components/Actions/ActionSendConfirmedOptions.vue
index fe36c6d0..b161c73c 100644
--- a/src/js/components/Actions/ActionSendConfirmedOptions.vue
+++ b/src/js/components/Actions/ActionSendConfirmedOptions.vue
@@ -56,6 +56,7 @@
import { NcButton } from '@nextcloud/vue'
import EmailCheckIcon from 'vue-material-design-icons/EmailCheck.vue' // view-comfy-outline
import { showError, showSuccess } from '@nextcloud/dialogs'
+import { PollsAPI } from '../../Api/polls.js'
export default {
name: 'ActionSendConfirmedOptions',
@@ -75,7 +76,7 @@ export default {
methods: {
async clickAction() {
- this.confirmations = await this.$store.dispatch('poll/sendConfirmation')
+ this.confirmations = await PollsAPI.sendConfirmation(this.$route.params.id)
this.headerCaption = t('polls', 'Confirmations processed')
this.confirmations.sent.forEach((confirmation) => {
showSuccess(t('polls', `Confirmation sent to ${confirmation}`))
diff --git a/src/js/components/Calendar/CalendarPeek.vue b/src/js/components/Calendar/CalendarPeek.vue
index b808f5aa..f2a7ea88 100644
--- a/src/js/components/Calendar/CalendarPeek.vue
+++ b/src/js/components/Calendar/CalendarPeek.vue
@@ -43,8 +43,9 @@ import { mapState } from 'vuex'
import { orderBy } from 'lodash'
import { NcPopover } from '@nextcloud/vue'
import moment from '@nextcloud/moment'
-import CalendarInfo from '../Calendar/CalendarInfo.vue'
+import CalendarInfo from './CalendarInfo.vue'
import { showError } from '@nextcloud/dialogs'
+import { CalendarAPI } from '../../Api/calendar.js'
export default {
name: 'CalendarPeek',
@@ -115,7 +116,7 @@ export default {
methods: {
async getEvents() {
try {
- const response = await this.$store.dispatch('options/getEvents', { option: this.option })
+ const response = CalendarAPI.getEvents(this.option.pollId)
this.events = response.data.events
} catch (e) {
if (e.message === 'Network Error') {
diff --git a/src/js/components/Export/ExportPoll.vue b/src/js/components/Export/ExportPoll.vue
index 04f2edfa..3e5254d8 100644
--- a/src/js/components/Export/ExportPoll.vue
+++ b/src/js/components/Export/ExportPoll.vue
@@ -65,6 +65,7 @@ import FileTableIcon from 'vue-material-design-icons/FileTableOutline.vue'
import CsvIcon from 'vue-material-design-icons/FileDelimited.vue'
import XmlIcon from 'vue-material-design-icons/Xml.vue'
import ExportIcon from 'vue-material-design-icons/FileDownloadOutline.vue'
+import { PollsAPI } from '../../Api/polls.js'
export default {
name: 'ExportPoll',
@@ -128,7 +129,7 @@ export default {
participantsHeader.push(t('polls', 'Email address'))
fromHeader.push('')
toHeader.push('')
- const response = await this.$store.dispatch('poll/getParticipantsEmailAddresses')
+ const response = await PollsAPI.getParticipantsEmailAddresses(this.$route.params.id)
this.emailAddresses = response.data
}
diff --git a/src/js/components/Poll/PublicRegisterModal.vue b/src/js/components/Poll/PublicRegisterModal.vue
index 6bc6a46c..57cc3ac6 100644
--- a/src/js/components/Poll/PublicRegisterModal.vue
+++ b/src/js/components/Poll/PublicRegisterModal.vue
@@ -92,7 +92,7 @@
<script>
import { debounce } from 'lodash'
-import axios from '@nextcloud/axios'
+// import axios from '@nextcloud/axios'
import { showError } from '@nextcloud/dialogs'
import { generateUrl } from '@nextcloud/router'
import { NcButton, NcModal, NcCheckboxRadioSwitch } from '@nextcloud/vue'
@@ -100,6 +100,9 @@ import { mapState } from 'vuex'
import { RichText } from '@nextcloud/vue-richtext'
import InputDiv from '../Base/InputDiv.vue'
import SimpleLink from '../../helpers/SimpleLink.js'
+import { ValidatorAPI } from '../../Api/validators.js'
+import { PublicAPI } from '../../Api/public.js'
+import { setCookie } from '../../helpers/cookieHelper.js'
export default {
name: 'PublicRegisterModal',
@@ -115,13 +118,13 @@ export default {
data() {
return {
+ status: {
+ email: 'invalid',
+ userName: 'invalid',
+ },
userName: '',
emailAddress: '',
- checkingUserName: false,
- checkingEmailAddress: false,
redirecting: false,
- isValidName: false,
- isValidEmailAddress: false,
modal: true,
modalSize: 'large',
saveCookie: true,
@@ -144,11 +147,11 @@ export default {
},
registrationIsValid() {
- return this.isValidName && (this.isValidEmailAddress || (this.emailAddress.length === 0 && this.share.publicPollEmail !== 'mandatory'))
+ return this.status.userName === 'valid' && (this.status.email === 'valid' || (this.emailAddress.length === 0 && this.share.publicPollEmail !== 'mandatory'))
},
disableSubmit() {
- return !this.registrationIsValid || this.checkingUserName
+ return !this.registrationIsValid || this.status.userName === 'checking'
},
privacyRich() {
@@ -175,7 +178,7 @@ export default {
},
userNameCheck() {
- if (this.checkingUserName) {
+ if (this.status.userName === 'checking') {
return {
result: t('polls', 'Checking name …'),
status: 'checking',
@@ -189,7 +192,7 @@ export default {
}
}
- if (!this.isValidName) {
+ if (this.status.userName === 'invalid') {
return {
result: t('polls', 'The name {username} is invalid or reserved.', { username: this.userName }),
status: 'error',
@@ -203,7 +206,7 @@ export default {
},
emailCheck() {
- if (this.checkingEmailAddress) {
+ if (this.status.email === 'checking') {
return {
result: t('polls', 'Checking email address …'),
status: 'checking',
@@ -223,7 +226,7 @@ export default {
}
}
- if (!this.isValidEmailAddress) {
+ if (this.status.email === 'invalid') {
return {
result: t('polls', 'Invalid email address.'),
status: 'error',
@@ -241,23 +244,19 @@ export default {
watch: {
userName() {
if (this.userName) {
- this.checkingUserName = true
if (this.userName !== this.share.userid) {
this.validatePublicUsername()
}
} else {
- this.checkingUserName = false
- this.isValidName = false
+ this.status.userName = 'invalid'
}
},
emailAddress() {
if (this.emailAddress) {
- this.checkingEmailAddress = true
this.validateEmailAddress()
} else {
- this.checkingEmailAddress = false
- this.isValidEmailAddress = false
+ this.status.email = 'invalid'
}
},
},
@@ -285,53 +284,58 @@ export default {
},
validatePublicUsername: debounce(async function() {
- const endpoint = 'apps/polls/check/username'
-
+ this.status.userName = 'checking'
try {
- await axios.post(generateUrl(endpoint), {
- headers: { Accept: 'application/json' },
- userName: this.userName,
- token: this.$route.params.token,
- })
- this.isValidName = true
+ await ValidatorAPI.validateName(this.$route.params.token, this.userName)
+ this.status.userName = 'valid'
} catch {
- this.isValidName = false
+ this.status.userName = 'invalid'
}
- this.checkingUserName = false
}, 500),
validateEmailAddress: debounce(async function() {
- const endpoint = `apps/polls/check/emailaddress/${this.emailAddress}`
-
+ this.status.email = 'checking'
try {
- await axios.get(generateUrl(endpoint), {
- headers: { Accept: 'application/json' },
- })
- this.isValidEmailAddress = true
+ await ValidatorAPI.validateEmailAddress(this.emailAddress)
+ this.status.email = 'valid'
} catch {
- this.isValidEmailAddress = false
+ this.status.email = 'valid'
}
- this.checkingEmailAddress = false
}, 500),
async submitRegistration() {
if (this.registrationIsValid) {
try {
- const response = await this.$store.dispatch('share/register', { userName: this.userName, emailAddress: this.emailAddress, saveCookie: this.saveCookie })
+ const response = await PublicAPI.register(
+ this.$route.params.token,
+ this.userName,
+ this.emailAddress,
+ )
+
+ if (this.saveCookie && this.$route.params.type === 'public') {
+ const cookieExpiration = (30 * 24 * 60 * 1000)
+ setCookie(this.$route.params.token, response.data.share.token, cookieExpiration)
+ }
- if (this.$route.params.token === response.token) {
- this.$store.dispatch({ type: 'poll/get', pollId: this.$route.params.id, token: this.$route.params.token })
+ if (this.$route.params.token === response.data.share.token) {
+ // if share was not a public share, but a personal share
+ // (i.e. email shares allow to change personal data by fist entering of the poll),
+ // just load the poll
+ this.$store.dispatch({ type: 'poll/get' })
this.closeModal()
} else {
+ // in case of a public share, redirect to the generated share
this.redirecting = true
- this.$router.replace({ name: 'publicVote', params: { token: response.token } })
+ this.$router.replace({ name: 'publicVote', params: { token: response.data.share.token } })
this.closeModal()
}
+
+ // TODO: Is that correct, is this possible in any way?
if (this.share.emailAddress && !this.share.invitationSent) {
showError(t('polls', 'Email could not be sent to {emailAddress}', { emailAddress: this.share.emailAddress }))
}
- } catch {
- showError(t('polls', 'Error saving name'))
+ } catch (e) {
+ showError(t('polls', 'Error registering to poll', { error: e.response }))
}
}
diff --git a/src/js/components/User/UserMenu.vue b/src/js/components/User/UserMenu.vue
index 0f0daa43..605d7f65 100644
--- a/src/js/components/User/UserMenu.vue
+++ b/src/js/components/User/UserMenu.vue
@@ -112,6 +112,7 @@ import ClippyIcon from 'vue-material-design-icons/ClipboardArrowLeftOutline.vue'
import ResetVotesIcon from 'vue-material-design-icons/Undo.vue'
import LogoutIcon from 'vue-material-design-icons/Logout.vue'
import { deleteCookieByValue, findCookieByValue } from '../../helpers/cookieHelper.js'
+import { PollsAPI } from '../../Api/polls.js'
export default {
name: 'UserMenu',
@@ -330,7 +331,7 @@ export default {
async getAddresses() {
try {
- const response = await this.$store.dispatch('poll/getParticipantsEmailAddresses')
+ const response = await PollsAPI.getParticipantsEmailAddresses(this.$route.params.id)
await navigator.clipboard.writeText(response.data.map((item) => item.combined))
showSuccess(t('polls', 'Link copied to clipboard'))
} catch {
diff --git a/src/js/helpers/AxiosDefault.js b/src/js/helpers/AxiosHelper.js
index 834b13e6..df5e15af 100644
--- a/src/js/helpers/AxiosDefault.js
+++ b/src/js/helpers/AxiosHelper.js
@@ -21,6 +21,7 @@
*/
const clientSessionId = Math.random().toString(36).substring(2)
+
const axiosDefaultConfig = {
headers: {
Accept: 'application/json',
@@ -28,4 +29,4 @@ const axiosDefaultConfig = {
},
}
-export default axiosDefaultConfig
+export { axiosDefaultConfig }
diff --git a/src/js/mixins/watchPolls.js b/src/js/mixins/watchPolls.js
index 4e3b4e6d..7534d2df 100644
--- a/src/js/mixins/watchPolls.js
+++ b/src/js/mixins/watchPolls.js
@@ -26,7 +26,7 @@ import { generateUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import { mapState } from 'vuex'
import { InvalidJSON } from '../Exceptions/Exceptions.js'
-import axiosDefaultConfig from '../helpers/AxiosDefault.js'
+import { axiosDefaultConfig } from '../helpers/AxiosHelper.js'
const defaultSleepTimeout = 30
diff --git a/src/js/store/modules/activity.js b/src/js/store/modules/activity.js
index b8ec60bd..9bb5e2f2 100644
--- a/src/js/store/modules/activity.js
+++ b/src/js/store/modules/activity.js
@@ -21,9 +21,7 @@
*
*/
-import axios from '@nextcloud/axios'
-import { generateOcsUrl } from '@nextcloud/router'
-import axiosDefaultConfig from '../../helpers/AxiosDefault.js'
+import { ActivityAPI } from '../../Api/activity.js'
const defaultActivities = () => ({
list: [],
@@ -49,18 +47,11 @@ const mutations = {
const actions = {
async list(context) {
- const params = new URLSearchParams()
- params.append('format', 'json')
- params.append('since', 0)
- params.append('limit', 50)
- params.append('object_type', 'poll')
- params.append('object_id', context.rootState.route.params.id)
- const endPoint = generateOcsUrl('apps/activity/api/v2/activity/filter?') + params
try {
- const response = await axios.get(endPoint, axiosDefaultConfig)
+ const response = await ActivityAPI.getActivities(context.rootState.route.params.id)
context.commit('set', response.data.ocs.data)
- } catch {
+ } catch (error) {
context.commit('reset')
}
},
diff --git a/src/js/store/modules/appSettings.js b/src/js/store/modules/appSettings.js
index 3e2f23a8..7fcc62db 100644
--- a/src/js/store/modules/appSettings.js
+++ b/src/js/store/modules/appSettings.js
@@ -21,9 +21,7 @@
*
*/
-import axios from '@nextcloud/axios'
-import { generateUrl } from '@nextcloud/router'
-import axiosDefaultConfig from '../../helpers/AxiosDefault.js'
+import { AppSettingsAPI } from '../../Api/appSettings.js'
const defaultAppSettings = () => ({
allAccessGroups: [],
@@ -71,12 +69,8 @@ const mutations = {
const actions = {
async get(context) {
- const endPoint = 'apps/polls/settings/app'
try {
- const response = await axios.get(generateUrl(endPoint), {
- ...axiosDefaultConfig,
- params: { time: +new Date() },
- })
+ const response = await AppSettingsAPI.getAppSettings()
context.commit('set', response.data.appSettings)
} catch {
// context.commit('reset')
@@ -84,15 +78,14 @@ const actions = {
},
async write(context) {
- const endPoint = 'apps/polls/settings/app'
try {
- const response = await axios.post(generateUrl(endPoint), {
- appSettings: context.state,
- }, axiosDefaultConfig)
+ const response = await AppSettingsAPI.writeAppSettings(context.state)
context.commit('set', response.data.appSettings)
} catch (e) {
- console.error('Error writing appSettings', { error: e.response }, { appSettings: state })
- throw e
+ if (e.name !== 'CancelledRequest') {
+ console.error('Error writing appSettings', { error: e.response }, { appSettings: state })
+ throw e
+ }
}
},
}
diff --git a/src/js/store/modules/combo.js b/src/js/store/modules/combo.js
index 19128926..6adc9a0b 100644
--- a/src/js/store/modules/combo.js
+++ b/src/js/store/modules/combo.js
@@ -21,11 +21,11 @@
*
*/
-import axios from '@nextcloud/axios'
-import { generateUrl } from '@nextcloud/router'
import { uniqueOptions, uniqueParticipants } from '../../helpers/arrayHelper.js'
import { sortBy } from 'lodash'
-import axiosDefaultConfig from '../../helpers/AxiosDefault.js'
+import { PollsAPI } from '../../Api/polls.js'
+import { OptionsAPI } from '../../Api/options.js'
+import { VotesAPI } from '../../Api/votes.js'
const defaultCombo = () => ({
id: 1,
@@ -143,12 +143,8 @@ const actions = {
},
async addPoll(context, payload) {
- const endPoint = `apps/polls/poll/${payload.pollId}/poll`
try {
- const response = await axios.get(generateUrl(endPoint), {
- ...axiosDefaultConfig,
- params: { time: +new Date() },
- })
+ const response = await PollsAPI.getPoll(payload.pollId)
context.commit('addPoll', response.data)
} catch (e) {
console.debug('Error loading poll for combo', { error: e.response })
@@ -156,13 +152,8 @@ const actions = {
},
async addOptions(context, payload) {
- const endPoint = `apps/polls/poll/${payload.pollId}/options`
-
try {
- const response = await axios.get(generateUrl(endPoint), {
- ...axiosDefaultConfig,
- params: { time: +new Date() },
- })
+ const response = await OptionsAPI.getOptions(payload.pollId)
context.commit('addOptions', response.data)
} catch (e) {
console.debug('Error loading options for combo', { error: e.response })
@@ -170,13 +161,8 @@ const actions = {
},
async addVotes(context, payload) {
- const endPoint = `apps/polls/poll/${payload.pollId}/votes`
-
try {
- const response = await axios.get(generateUrl(endPoint), {
- ...axiosDefaultConfig,
- params: { time: +new Date() },
- })
+ const response = await VotesAPI.getVotes(payload.pollId)
context.commit('addVotes', response.data)
} catch (e) {
console.debug('Error loading options for combo', { error: e.response })
diff --git a/src/js/store/modules/comments.js b/src/js/store/modules/comments.js
index 487e0f80..f3c66d3c 100644
--- a/src/js/store/modules/comments.js
+++ b/src/js/store/modules/comments.js
@@ -21,9 +21,8 @@
*
*/
-import axios from '@nextcloud/axios'
-import { generateUrl } from '@nextcloud/router'
-import axiosDefaultConfig from '../../helpers/AxiosDefault.js'
+import { CommentsAPI } from '../../Api/comments.js'
+import { PublicAPI } from '../../Api/public.js'
const defaultComments = () => ({
list: [],
@@ -57,24 +56,17 @@ const getters = {
const actions = {
async list(context) {
- let endPoint = 'apps/polls'
-
- 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 if (context.rootState.route.name === 'list' && context.rootState.route.params.id) {
- endPoint = `${endPoint}/poll/${context.rootState.route.params.id}`
- } else {
- context.commit('reset')
- return
- }
-
try {
- const response = await axios.get(generateUrl(`${endPoint}/comments`), {
- ...axiosDefaultConfig,
- params: { time: +new Date() },
- })
+ let response = null
+ if (context.rootState.route.name === 'publicVote') {
+ response = await PublicAPI.getComments(context.rootState.route.params.token)
+ } else if (context.rootState.route.name === 'vote') {
+ response = await CommentsAPI.getComments(context.rootState.route.params.id)
+ } else {
+ context.commit('reset')
+ return
+ }
+
context.commit('set', response.data)
} catch {
context.commit('reset')
@@ -82,23 +74,16 @@ const actions = {
},
async add(context, payload) {
- let endPoint = 'apps/polls'
-
- 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 if (context.rootState.route.name === 'list' && context.rootState.route.params.id) {
- endPoint = `${endPoint}/poll/${context.rootState.route.params.id}`
- } else {
- context.commit('reset')
- return
- }
-
try {
- await axios.post(generateUrl(`${endPoint}/comment`), {
- message: payload.message,
- }, axiosDefaultConfig)
+ if (context.rootState.route.name === 'publicVote') {
+ await PublicAPI.addComment(context.rootState.route.params.token, payload.message)
+ } else if (context.rootState.route.name === 'vote') {
+ await CommentsAPI.addComment(context.rootState.route.params.id, payload.message)
+ } else {
+ context.commit('reset')
+ return
+ }
+
context.dispatch('list')
// context.commit('add', { comment: response.data.comment })
} catch (e) {
@@ -108,15 +93,13 @@ const actions = {
},
async delete(context, payload) {
- let endPoint = 'apps/polls'
-
- if (context.rootState.route.name === 'publicVote') {
- endPoint = `${endPoint}/s/${context.rootState.route.params.token}`
- }
- endPoint = `${endPoint}/comment/${payload.comment.id}`
-
try {
- await axios.delete(generateUrl(endPoint), axiosDefaultConfig)
+ if (context.rootState.route.name === 'publicVote') {
+ await PublicAPI.deleteComment(context.rootState.route.params.token, payload.comment.id)
+ } else {
+ await CommentsAPI.deleteComment(payload.comment.id)
+ }
+
context.commit('delete', { comment: payload.comment })
} catch (e) {
console.error('Error deleting comment', { error: e.response }, { payload })
diff --git a/src/js/store/modules/options.js b/src/js/store/modules/options.js
index f59d3bd8..96e969f4 100644
--- a/src/js/store/modules/options.js
+++ b/src/js/store/modules/options.js
@@ -21,11 +21,10 @@
*
*/
-import axios from '@nextcloud/axios'
-import { generateUrl } from '@nextcloud/router'
import { orderBy } from 'lodash'
import moment from '@nextcloud/moment'
-import axiosDefaultConfig from '../../helpers/AxiosDefault.js'
+import { OptionsAPI } from '../../Api/options.js'
+import { PublicAPI } from '../../Api/public.js'
const defaultOptions = () => ({
list: [],
@@ -137,23 +136,18 @@ const getters = {
const actions = {
async list(context) {
- let endPoint = 'apps/polls'
- if (context.rootState.route.name === 'publicVote') {
- endPoint = `${endPoint}/s/${context.rootState.route.params.token}/options`
- } else if (context.rootState.route.name === 'vote') {
- endPoint = `${endPoint}/poll/${context.rootState.route.params.id}/options`
- } else if (context.rootState.route.name === 'list' && context.rootState.route.params.id) {
- endPoint = `${endPoint}/poll/${context.rootState.route.params.id}/options`
- } else {
- context.commit('reset')
- return
- }
-
try {
- const response = await axios.get(generateUrl(endPoint), {
- ...axiosDefaultConfig,
- params: { time: +new Date() },
- })
+ let response = null
+
+ if (context.rootState.route.name === 'publicVote') {
+ response = await PublicAPI.getOptions(context.rootState.route.params.token)
+ } else if (context.rootState.route.params.id) {
+ response = await OptionsAPI.getOptions(context.rootState.route.params.id)
+ } else {
+ context.commit('reset')
+ return
+ }
+
context.commit('set', { options: response.data.options })
} catch (e) {
console.error('Error loding options', { error: e.response }, { pollId: context.rootState.route.params.id })
@@ -162,20 +156,28 @@ const actions = {
},
async add(context, payload) {
- let endPoint = 'apps/polls'
- if (context.rootState.route.name === 'publicVote') {
- endPoint = `${endPoint}/s/${context.rootState.route.params.token}/option`
- } else {
- endPoint = `${endPoint}/option`
- }
-
try {
- const response = await axios.post(generateUrl(endPoint), {
- pollId: context.rootState.route.params.id,
- timestamp: payload.timestamp,
- text: payload.text,
- duration: payload.duration,
- }, axiosDefaultConfig)
+ let response = null
+ if (context.rootState.route.name === 'publicVote') {
+ response = await PublicAPI.addOption(
+ context.rootState.route.params.token,
+ {
+ pollId: context.rootState.route.params.id,
+ timestamp: payload.timestamp,
+ text: payload.text,
+ duration: payload.duration,
+ }
+ )
+ } else {
+ response = await OptionsAPI.addOption(
+ {
+ pollId: context.rootState.route.params.id,
+ timestamp: payload.timestamp,
+ text: payload.text,
+ duration: payload.duration,
+ }
+ )
+ }
context.commit('setItem', { option: response.data.option })
} catch (e) {
console.error(`Error adding option: ${e.response.data}`, { error: e.response }, { payload })
@@ -185,14 +187,8 @@ const actions = {
},
async update(context, payload) {
- const endPoint = `apps/polls/option/${payload.option.id}`
-
try {
- const response = await axios.put(generateUrl(endPoint), {
- timestamp: payload.option.timestamp,
- text: payload.option.timeStamp,
- duration: payload.option.duration,
- }, axiosDefaultConfig)
+ const response = await OptionsAPI.updateOption(payload.option)
context.commit('setItem', { option: response.data.option })
} catch (e) {
console.error('Error updating option', { error: e.response }, { payload })
@@ -202,16 +198,12 @@ const actions = {
},
async delete(context, payload) {
- let endPoint = 'apps/polls'
-
- if (context.rootState.route.name === 'publicVote') {
- endPoint = `${endPoint}/s/${context.rootState.route.params.token}/option/${payload.option.id}`
- } else {
- endPoint = `${endPoint}/option/${payload.option.id}`
- }
-
try {
- await axios.delete(generateUrl(endPoint), axiosDefaultConfig)
+ if (context.rootState.route.name === 'publicVote') {
+ await PublicAPI.deleteOption(context.rootState.route.params.token, payload.option.id)
+ } else {
+ await OptionsAPI.deleteOption(payload.option.id)
+ }
context.commit('delete', { option: payload.option })
} catch (e) {
console.error('Error deleting option', { error: e.response }, { payload })
@@ -221,13 +213,8 @@ const actions = {
},
async addBulk(context, payload) {
- const endPoint = 'apps/polls/option/bulk'
-
try {
- const response = await axios.post(generateUrl(endPoint), {
- pollId: context.rootState.route.params.id,
- text: payload.text,
- }, axiosDefaultConfig)
+ const response = OptionsAPI.addOptions(context.rootState.route.params.id, payload.text)
context.commit('set', { options: response.data.options })
} catch (e) {
console.error(`Error adding option: ${e.response.data}`, { error: e.response }, { payload })
@@ -237,12 +224,9 @@ const actions = {
},
async confirm(context, payload) {
- const endPoint = `apps/polls/option/${payload.option.id}/confirm`
-
context.commit('confirm', { option: payload.option })
-
try {
- const response = await axios.put(generateUrl(endPoint), null, axiosDefaultConfig)
+ const response = OptionsAPI.confirmOption(payload.optionId)
context.commit('setItem', { option: response.data.option })
} catch (e) {
console.error('Error confirming option', { error: e.response }, { payload })
@@ -252,14 +236,10 @@ const actions = {
},
async reorder(context, payload) {
- const endPoint = `apps/polls/poll/${context.rootState.route.params.id}/options/reorder`
-
context.commit('reorder', { options: payload })
try {
- const response = await axios.post(generateUrl(endPoint), {
- options: payload,
- }, axiosDefaultConfig)
+ const response = await OptionsAPI.reorderOptions(context.rootState.route.params.id, payload)
context.commit('set', { options: response.data.options })
} catch (e) {
console.error('Error reordering option', { error: e.response }, { payload })
@@ -269,14 +249,13 @@ const actions = {
},
async sequence(context, payload) {
- const endPoint = `apps/polls/option/${payload.option.id}/sequence`
-
try {
- const response = await axios.post(generateUrl(endPoint), {
- step: payload.sequence.step,
- unit: payload.sequence.unit.value,
- amount: payload.sequence.amount,
- }, axiosDefaultConfig)
+ const response = await OptionsAPI.addOptionsSequence(
+ payload.option.id,
+ payload.sequence.step,
+ payload.sequence.unit.value,
+ payload.sequence.amount,
+ )
context.commit('set', { options: response.data.options })
} catch (e) {
console.error('Error creating sequence', { error: e.response }, { payload })
@@ -286,13 +265,12 @@ const actions = {
},
async shift(context, payload) {
- const endPoint = `apps/polls/poll/${context.rootState.route.params.id}/shift`
-
try {
- const response = await axios.post(generateUrl(endPoint), {
- step: payload.shift.step,
- unit: payload.shift.unit.value,
- }, axiosDefaultConfig)
+ const response = await OptionsAPI.shiftOptions(
+ context.rootState.route.params.id,
+ payload.shift.step,
+ payload.shift.unit.value,
+ )
context.commit('set', { options: response.data.options })
} catch (e) {
console.error('Error shifting dates', { error: e.response }, { payload })
@@ -300,20 +278,6 @@ const actions = {
throw e
}
},
-
- async getEvents(context, payload) {
- const endPoint = `apps/polls/option/${payload.option.id}/events`
-
- try {
- return await axios.get(generateUrl(endPoint), {
- ...axiosDefaultConfig,
- params: { tz: Intl.DateTimeFormat().resolvedOptions().timeZone },
- })
- } catch (e) {
- return { events: [] }
- }
- },
-
}
export default { state, mutations, getters, actions, namespaced }
diff --git a/src/js/store/modules/poll.js b/src/js/store/modules/poll.js
index aa587336..14aedb22 100644
--- a/src/js/store/modules/poll.js
+++ b/src/js/store/modules/poll.js
@@ -21,12 +21,11 @@
*
*/
-import axios from '@nextcloud/axios'
import moment from '@nextcloud/moment'
-import { generateUrl } from '@nextcloud/router'
import acl from './subModules/acl.js'
import { uniqueArrayOfObjects } from '../../helpers/arrayHelper.js'
-import axiosDefaultConfig from '../../helpers/AxiosDefault.js'
+import { PollsAPI } from '../../Api/polls.js'
+import { PublicAPI } from '../../Api/public.js'
const defaultPoll = () => ({
id: 0,
@@ -173,52 +172,40 @@ const actions = {
},
async get(context) {
- let endPoint = 'apps/polls'
-
- if (context.rootState.route.name === 'publicVote') {
- endPoint = `${endPoint}/s/${context.rootState.route.params.token}/poll`
- } else if (context.rootState.route.name === 'vote') {
- endPoint = `${endPoint}/poll/${context.rootState.route.params.id}/poll`
- } else {
- context.commit('reset')
- context.commit('acl/reset')
- return
- }
try {
- const response = await axios.get(generateUrl(endPoint), {
- ...axiosDefaultConfig,
- params: { time: +new Date() },
- })
+ let response = null
+ if (context.rootState.route.name === 'publicVote') {
+ response = await PublicAPI.getPoll(context.rootState.route.params.token)
+ } else if (context.rootState.route.name === 'vote') {
+ response = await PollsAPI.getPoll(context.rootState.route.params.id)
+ } else {
+ context.commit('reset')
+ context.commit('acl/reset')
+ return
+ }
context.commit('set', response.data)
context.commit('acl/set', response.data)
} catch (e) {
- console.debug('Error loading poll', { error: e.response })
+ console.debug('Error loading poll', { error: e })
throw e
}
},
async add(context, payload) {
- const endPoint = 'apps/polls/poll/add'
try {
- const response = await axios.post(generateUrl(endPoint), {
- title: payload.title,
- type: payload.type,
- }, axiosDefaultConfig)
-
- context.dispatch('polls/list', null, { root: true })
+ const response = await PollsAPI.addPoll(payload.type, payload.title)
return response
} catch (e) {
console.error('Error adding poll:', { error: e.response }, { state: context.state })
throw e
+ } finally {
+ context.dispatch('polls/list', null, { root: true })
}
},
async update(context) {
- const endPoint = `apps/polls/poll/${context.state.id}`
try {
- const response = await axios.put(generateUrl(endPoint), {
- poll: context.state,
- }, axiosDefaultConfig)
+ const response = await PollsAPI.updatePoll(context.state)
context.commit('set', response.data)
context.commit('acl/set', response.data)
} catch (e) {
@@ -231,9 +218,8 @@ const actions = {
},
async delete(context, payload) {
- const endPoint = `apps/polls/poll/${payload.pollId}`
try {
- await axios.delete(generateUrl(endPoint), axiosDefaultConfig)
+ await PollsAPI.deletePoll(payload.pollId)
} catch (e) {
console.error('Error deleting poll', { error: e.response }, { payload })
} finally {
@@ -242,9 +228,8 @@ const actions = {
},
async toggleArchive(context, payload) {
- const endPoint = `apps/polls/poll/${payload.pollId}/toggleArchive`
try {
- await axios.put(generateUrl(endPoint), null, axiosDefaultConfig)
+ await PollsAPI.toggleArchive(payload.pollId)
} catch (e) {
console.error('Error archiving/restoring', { error: e.response }, { payload })
} finally {
@@ -253,34 +238,14 @@ const actions = {
},
async clone(context, payload) {
- const endPoint = `apps/polls/poll/${payload.pollId}/clone`
try {
- const response = await axios.post(generateUrl(endPoint), null, axiosDefaultConfig)
+ const response = await PollsAPI.clonePoll(payload.pollId)
context.dispatch('polls/list', null, { root: true })
return response
} catch (e) {
console.error('Error cloning poll', { error: e.response }, { payload })
}
},
-
- async sendConfirmation(context, payload) {
- const endPoint = `apps/polls/poll/${context.rootState.route.params.id}/confirmation`
- try {
- const response = await axios.post(generateUrl(endPoint), null, axiosDefaultConfig)
- return response.data.confirmations
- } catch (e) {
- console.error('Error sending confirmation', { error: e.response }, { payload })
- }
- },
-
- async getParticipantsEmailAddresses(context) {
- const endPoint = `apps/polls/poll/${context.state.id}/addresses`
- try {
- return await axios.get(generateUrl(endPoint), axiosDefaultConfig)
- } catch (e) {
- console.error('Error retrieving email addresses', { error: e.response })
- }
- },
}
export default { namespaced, state, mutations, getters, actions, modules }
diff --git a/src/js/store/modules/polls.js b/src/js/store/modules/polls.js
index e188ac7b..17c0ad94 100644
--- a/src/js/store/modules/polls.js
+++ b/src/js/store/modules/polls.js
@@ -23,11 +23,9 @@
*
*/
-import axios from '@nextcloud/axios'
import moment from '@nextcloud/moment'
-import { generateUrl } from '@nextcloud/router'
import { orderBy } from 'lodash'
-import axiosDefaultConfig from '../../helpers/AxiosDefault.js'
+import { PollsAPI } from '../../Api/polls.js'
const state = {
list: [],
@@ -197,13 +195,9 @@ const actions = {
},
async list(context) {
- const endPoint = 'apps/polls/polls'
try {
- const response = await axios.get(generateUrl(endPoint), {
- ...axiosDefaultConfig,
- params: { time: +new Date() },
- })
+ const response = await PollsAPI.getPolls()
context.commit('set', { list: response.data.list })
context.commit('setPollCreationAllowed', { pollCreationAllowed: response.data.pollCreationAllowed })
context.commit('setComboAllowed', { comboAllowed: response.data.comboAllowed })
diff --git a/src/js/store/modules/pollsAdmin.js b/src/js/store/modules/pollsAdmin.js
index d30f1338..f718948e 100644
--- a/src/js/store/modules/pollsAdmin.js
+++ b/src/js/store/modules/pollsAdmin.js
@@ -21,10 +21,8 @@
*
*/
-import axios from '@nextcloud/axios'
import { getCurrentUser } from '@nextcloud/auth'
-import { generateUrl } from '@nextcloud/router'
-import axiosDefaultConfig from '../../helpers/AxiosDefault.js'
+import { PollsAPI } from '../../Api/polls.js'
const namespaced = true
const state = {
@@ -47,12 +45,8 @@ const actions = {
return
}
- const endPoint = 'apps/polls/administration/polls'
try {
- const response = await axios.get(generateUrl(endPoint), {
- ...axiosDefaultConfig,
- params: { time: +new Date() },
- })
+ const response = await PollsAPI.getPollsForAdmin()
context.commit('set', { list: response.data })
} catch (e) {
console.error('Error loading polls', { error: e.response })
@@ -64,8 +58,7 @@ const actions = {
return
}
- const endPoint = `apps/polls/administration/poll/${payload.pollId}/takeover`
- axios.put(generateUrl(endPoint), null, axiosDefaultConfig)
+ PollsAPI.takeOver(payload.pollId)
},
}
diff --git a/src/js/store/modules/settings.js b/src/js/store/modules/settings.js
index b5e03338..c2ef1c66 100644
--- a/src/js/store/modules/settings.js
+++ b/src/js/store/modules/settings.js
@@ -21,9 +21,8 @@
*
*/
-import axios from '@nextcloud/axios'
-import { generateUrl } from '@nextcloud/router'
-import axiosDefaultConfig from '../../helpers/AxiosDefault.js'
+import { CalendarAPI } from '../../Api/calendar.js'
+import { UserSettingsAPI } from '../../Api/userSettings.js'
const defaultSettings = () => ({
user: {
@@ -122,12 +121,8 @@ const getters = {
const actions = {
async get(context) {
- const endPoint = 'apps/polls/preferences'
try {
- const response = await axios.get(generateUrl(endPoint), {
- ...axiosDefaultConfig,
- params: { time: +new Date() },
- })
+ const response = await UserSettingsAPI.getUserSettings()
if (response.data.preferences.defaultViewTextPoll === 'desktop') {
response.data.preferences.defaultViewTextPoll = 'table-view'
}
@@ -148,18 +143,14 @@ const actions = {
async setPollCombo(context, payload) {
await context.commit('setPollCombo', {
- headers: { Accept: 'application/json' },
pollCombo: payload.pollCombo,
})
context.dispatch('write')
},
async write(context) {
- const endPoint = 'apps/polls/preferences'
try {
- const response = await axios.post(generateUrl(endPoint), {
- settings: context.state.user,
- }, axiosDefaultConfig)
+ const response = await UserSettingsAPI.writeUserSettings(context.state.user)
context.commit('setPreference', response.data.preferences)
} catch (e) {
console.error('Error writing preferences', { error: e.response }, { preferences: state.user })
@@ -168,8 +159,7 @@ const actions = {
},
async getCalendars(context) {
- const endPoint = 'apps/polls/calendars'
- const response = await axios.get(generateUrl(endPoint), axiosDefaultConfig)
+ const response = await CalendarAPI.getCalendars()
context.commit('setCalendars', { calendars: response.data.calendars })
return response
},
diff --git a/src/js/store/modules/share.js b/src/js/store/modules/share.js
index 43b50adb..e671f938 100644
--- a/src/js/store/modules/share.js
+++ b/src/js/store/modules/share.js
@@ -21,10 +21,7 @@
*
*/
-import axios from '@nextcloud/axios'
-import { generateUrl } from '@nextcloud/router'
-import { setCookie } from '../../helpers/cookieHelper.js'
-import axiosDefaultConfig from '../../helpers/AxiosDefault.js'
+import { PublicAPI } from '../../Api/public.js'
const defaultShares = () => ({
displayName: '',
@@ -62,13 +59,8 @@ const actions = {
return
}
- const endPoint = `apps/polls/s/${context.rootState.route.params.token}/share`
-
try {
- const response = await axios.get(generateUrl(endPoint), {
- ...axiosDefaultConfig,
- params: { time: +new Date() },
- })
+ const response = await PublicAPI.getShare(context.rootState.route.params.token)
context.commit('set', { share: response.data.share })
return response.data
} catch (e) {
@@ -77,42 +69,13 @@ const actions = {
}
},
- async register(context, payload) {
- if (context.rootState.route.name !== 'publicVote') {
- return
- }
-
- const endPoint = `apps/polls/s/${context.rootState.route.params.token}/register`
-
- try {
- const response = await axios.post(generateUrl(endPoint), {
- userName: payload.userName,
- emailAddress: payload.emailAddress,
- timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
- }, axiosDefaultConfig)
-
- if (payload.saveCookie && context.state.type === 'public') {
- const cookieExpiration = (30 * 24 * 60 * 1000)
- setCookie(context.rootState.route.params.token, response.data.share.token, cookieExpiration)
- }
-
- return { token: response.data.share.token }
-
- } catch (e) {
- console.error('Error writing personal share', { error: e.response }, { payload })
- throw e
- }
- },
-
async updateEmailAddress(context, payload) {
if (context.rootState.route.name !== 'publicVote') {
return
}
- const endPoint = `apps/polls/s/${context.rootState.route.params.token}/email/${payload.emailAddress}`
-
try {
- const response = await axios.put(generateUrl(endPoint), null, axiosDefaultConfig)
+ const response = await PublicAPI.setEmail(context.rootState.route.params.token, payload.emailAddress)
context.commit('set', { share: response.data.share })
context.dispatch('poll/get', null, { root: true })
} catch (e) {
@@ -126,10 +89,8 @@ const actions = {
return
}
- const endPoint = `apps/polls/s/${context.rootState.route.params.token}/name/${payload.displayName}`
-
try {
- const response = await axios.put(generateUrl(endPoint), null, axiosDefaultConfig)
+ const response = await PublicAPI.setDisplayName(context.rootState.route.params.token, payload.displayName)
context.commit('set', { share: response.data.share })
context.dispatch('poll/get', null, { root: true })
context.dispatch('comments/list', null, { root: true })
@@ -146,10 +107,8 @@ const actions = {
return
}
- const endPoint = `apps/polls/s/${context.rootState.route.params.token}/email`
-
try {
- const response = await axios.delete(generateUrl(endPoint), axiosDefaultConfig)
+ const response = PublicAPI.deleteEmailAddress(context.rootState.route.params.token)
context.commit('set', { share: response.data.share })
context.dispatch('subscription/update', false, { root: true })
context.dispatch('poll/get', null, { root: true })
@@ -164,10 +123,8 @@ const actions = {
return
}
- const endPoint = `apps/polls/s/${context.rootState.route.params.token}/resend`
-
try {
- return await axios.put(generateUrl(endPoint), null, axiosDefaultConfig)
+ return await PublicAPI.resendInvitation(context.rootState.route.params.token)
} catch (e) {
console.error('Error sending invitation', { error: e.response }, { payload })
throw e
diff --git a/src/js/store/modules/shares.js b/src/js/store/modules/shares.js
index 8095cb36..9fce6d73 100644
--- a/src/js/store/modules/shares.js
+++ b/src/js/store/modules/shares.js
@@ -21,9 +21,7 @@
*
*/
-import axios from '@nextcloud/axios'
-import { generateUrl } from '@nextcloud/router'
-import axiosDefaultConfig from '../../helpers/AxiosDefault.js'
+import { SharesAPI } from '../../Api/shares.js'
const defaultShares = () => ({
list: [],
@@ -72,13 +70,8 @@ const getters = {
const actions = {
async list(context) {
- const endPoint = `apps/polls/poll/${context.rootState.route.params.id}/shares`
-
try {
- const response = await axios.get(generateUrl(endPoint), {
- ...axiosDefaultConfig,
- params: { time: +new Date() },
- })
+ const response = await SharesAPI.getShares(context.rootState.route.params.id)
context.commit('set', response.data)
} catch (e) {
console.error('Error loading shares', { error: e.response }, { pollId: context.rootState.route.params.id })
@@ -87,10 +80,8 @@ const actions = {
},
async add(context, payload) {
- const endPoint = `apps/polls/poll/${context.rootState.route.params.id}/share`
-
try {
- await axios.post(generateUrl(endPoint), payload.share, axiosDefaultConfig)
+ await SharesAPI.addShare(context.rootState.route.params.id, payload.share)
} catch (e) {
console.error('Error writing share', { error: e.response }, { payload })
throw e
@@ -100,18 +91,12 @@ const actions = {
},
async switchAdmin(context, payload) {
- let endPoint = `apps/polls/share/${payload.share.token}`
-
- if (payload.share.type === 'admin') {
- endPoint = `${endPoint}/user`
- } else if (payload.share.type === 'user') {
- endPoint = `${endPoint}/admin`
- }
+ const setTo = payload.share.type === 'user' ? 'admin' : 'user'
try {
- await axios.put(generateUrl(endPoint), null, axiosDefaultConfig)
+ await SharesAPI.switchAdmin(payload.share.token, setTo)
} catch (e) {
- console.error('Error switching type', { error: e.response }, { payload })
+ console.error(`Error switching type to ${setTo}`, { error: e.response }, { payload })
throw e
} finally {
context.dispatch('list')
@@ -119,10 +104,8 @@ const actions = {
},
async setPublicPollEmail(context, payload) {
- const endPoint = `apps/polls/share/${payload.share.token}/publicpollemail/${payload.value}`
-
try {
- await axios.put(generateUrl(endPoint), null, axiosDefaultConfig)
+ await SharesAPI.setEmailAddressConstraint(payload.share.token, payload.value)
} catch (e) {
console.error('Error changing email register setting', { error: e.response }, { payload })
throw e
@@ -132,10 +115,8 @@ const actions = {
},
async sendInvitation(context, payload) {
- const endPoint = `apps/polls/share/${payload.share.token}/invite`
-
try {
- return await axios.post(generateUrl(endPoint), null, axiosDefaultConfig)
+ return await SharesAPI.sendInvitation(payload.share.token)
} catch (e) {
console.error('Error sending invitation', { error: e.response }, { payload })
throw e
@@ -145,10 +126,9 @@ const actions = {
},
async resolveGroup(context, payload) {
- const endPoint = `apps/polls/share/${payload.share.token}/resolve`
try {
- await axios.get(generateUrl(endPoint), axiosDefaultConfig)
+ await SharesAPI.resolveShare(payload.share.token)
} catch (e) {
console.error('Error exploding group', e.response.data, { error: e.response }, { payload })
throw e
@@ -158,12 +138,9 @@ const actions = {
},
async delete(context, payload) {
- const endPoint = `apps/polls/share/${payload.share.token}`
-
context.commit('delete', { share: payload.share })
-
try {
- await axios.delete(generateUrl(endPoint), axiosDefaultConfig)
+ await SharesAPI.deleteShare(payload.share.token)
} catch (e) {
console.error('Error removing share', { error: e.response }, { payload })
throw e
diff --git a/src/js/store/modules/subscription.js b/src/js/store/modules/subscription.js
index 3a531066..837c1736 100644
--- a/src/js/store/modules/subscription.js
+++ b/src/js/store/modules/subscription.js
@@ -21,9 +21,8 @@
*
*/
-import axios from '@nextcloud/axios'
-import { generateUrl } from '@nextcloud/router'
-import axiosDefaultConfig from '../../helpers/AxiosDefault.js'
+import { PollsAPI } from '../../Api/polls.js'
+import { PublicAPI } from '../../Api/public.js'
const defaultSubscription = () => ({
subscribed: false,
@@ -47,22 +46,16 @@ const mutations = {
const actions = {
async get(context) {
- let endPoint = 'apps/polls'
-
- if (context.rootState.route.name === 'publicVote') {
- endPoint = `${endPoint}/s/${context.rootState.route.params.token}/subscription`
- } else if (context.rootState.route.name === 'vote') {
- endPoint = `${endPoint}/poll/${context.rootState.route.params.id}/subscription`
- } else {
- context.commit('reset')
- return
- }
-
try {
- const response = await axios.get(generateUrl(endPoint), {
- ...axiosDefaultConfig,
- params: { time: +new Date() },
- })
+ let response = null
+ if (context.rootState.route.name === 'publicVote') {
+ response = await PublicAPI.getSubscription(context.rootState.route.token)
+ } else if (context.rootState.route.name === 'vote') {
+ response = await PollsAPI.getSubscription(context.rootState.route.params.id)
+ } else {
+ context.commit('reset')
+ return
+ }
context.commit('set', response.data)
} catch {
context.commit('set', false)
@@ -70,19 +63,16 @@ const actions = {
},
async update(context, payload) {
- let endPoint = 'apps/polls'
-
- if (context.rootState.route.name === 'publicVote') {
- endPoint = `${endPoint}/s/${context.rootState.route.params.token}${payload ? '/subscribe' : '/unsubscribe'}`
- } else if (context.rootState.route.name === 'vote') {
- endPoint = `${endPoint}/poll/${context.rootState.route.params.id}${payload ? '/subscribe' : '/unsubscribe'}`
- } else {
- context.commit('reset')
- return
- }
-
try {
- const response = await axios.put(generateUrl(endPoint), null, axiosDefaultConfig)
+ let response = null
+ if (context.rootState.route.name === 'publicVote') {
+ response = PublicAPI.setSubscription(context.rootState.route.params.token)
+ } else if (context.rootState.route.name === 'vote') {
+ response = PollsAPI.setSubscription(context.rootState.route.params.id)
+ } else {
+ context.commit('reset')
+ return
+ }
context.commit('set', response.data)
} catch (e) {
console.error(e.response)
diff --git a/src/js/store/modules/votes.js b/src/js/store/modules/votes.js
index 9a7fb92d..16f94ed1 100644
--- a/src/js/store/modules/votes.js
+++ b/src/js/store/modules/votes.js
@@ -21,9 +21,8 @@
*
*/
-import axios from '@nextcloud/axios'
-import { generateUrl } from '@nextcloud/router'
-import axiosDefaultConfig from '../../helpers/AxiosDefault.js'
+import { VotesAPI } from '../../Api/votes.js'
+import { PublicAPI } from '../../Api/public.js'
const defaultVotes = () => ({
list: [],
@@ -81,21 +80,16 @@ const getters = {
const actions = {
async list(context) {
- let endPoint = 'apps/polls'
-
- 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')
- return
- }
try {
- const response = await axios.get(generateUrl(`${endPoint}/votes`), {
- ...axiosDefaultConfig,
- params: { time: +new Date() },
- })
+ let response = null
+ if (context.rootState.route.name === 'publicVote') {
+ response = await PublicAPI.getVotes(context.rootState.route.params.token)
+ } else if (context.rootState.route.name === 'vote') {
+ response = await VotesAPI.getVotes(context.rootState.route.params.id)
+ } else {
+ context.commit('reset')
+ return
+ }
const votes = []
response.data.votes.forEach((vote) => {
if (vote.answer === 'yes') {
@@ -117,17 +111,13 @@ const actions = {
},
async set(context, payload) {
- let endPoint = 'apps/polls'
-
- if (context.rootState.route.name === 'publicVote') {
- endPoint = `${endPoint}/s/${context.rootState.poll.acl.token}`
- }
-
try {
- const response = await axios.put(generateUrl(`${endPoint}/vote`), {
- optionId: payload.option.id,
- setTo: payload.setTo,
- }, axiosDefaultConfig)
+ let response = null
+ if (context.rootState.route.name === 'publicVote') {
+ response = await PublicAPI.setVote(context.rootState.route.params.token, payload.option.id, payload.setTo)
+ } else {
+ response = await VotesAPI.setVote(payload.option.id, payload.setTo)
+ }
context.commit('setItem', { option: payload.option, pollId: context.rootState.poll.id, vote: response.data.vote })
context.dispatch('options/list', null, { root: true })
context.dispatch('poll/get', null, { root: true })
@@ -144,16 +134,13 @@ const actions = {
},
async resetVotes(context) {
- let endPoint = 'apps/polls'
-
- if (context.rootState.route.name === 'publicVote') {
- endPoint = `${endPoint}/s/${context.rootState.poll.acl.token}/user`
- } else {
- endPoint = `${endPoint}/poll/${context.rootState.route.params.id}/user`
- }
-
try {
- const response = await axios.delete(generateUrl(endPoint), axiosDefaultConfig)
+ let response = null
+ if (context.rootState.route.name === 'publicVote') {
+ response = await PublicAPI.removeVotes(context.rootState.route.params.token)
+ } else {
+ response = await VotesAPI.removeUser(context.rootState.route.params.id)
+ }
context.commit('deleteVotes', { userId: response.data.deleted })
} catch (e) {
console.error('Error deleting votes', { error: e.response })
@@ -162,9 +149,8 @@ const actions = {
},
async deleteUser(context, payload) {
- const endPoint = `apps/polls/poll/${context.rootState.route.params.id}/user/${payload.userId}`
try {
- await axios.delete(generateUrl(endPoint), axiosDefaultConfig)
+ await VotesAPI.removeUser(context.rootState.route.params.id, payload.userId)
context.commit('deleteVotes', payload)
} catch (e) {
console.error('Error deleting votes', { error: e.response }, { payload })