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 /src/js/components
parent8df58e63e2145b2754e94b0d55b77fc8e8131c7c (diff)
move backend requests from store to new api
Signed-off-by: dartcafe <github@dartcafe.de>
Diffstat (limited to 'src/js/components')
-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
5 files changed, 54 insertions, 46 deletions
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 {