Signed-off-by: dartcafe <github@dartcafe.de>
This commit is contained in:
dartcafe 2021-03-06 09:37:01 +01:00
Родитель 5a5dd80dea
Коммит c55bb68f8a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: CCE73CEF3035D3C8
16 изменённых файлов: 136 добавлений и 72 удалений

Просмотреть файл

@ -197,7 +197,7 @@ class Poll extends Entity implements JsonSerializable {
} }
public function getDescriptionSafe() { public function getDescriptionSafe() {
return filter_var($this->description,FILTER_SANITIZE_SPECIAL_CHARS); return htmlspecialchars($this->description);
} }
private function getDisplayName(): string { private function getDisplayName(): string {

Просмотреть файл

@ -0,0 +1,75 @@
<!--
- @copyright Copyright (c) 2018 René Gieling <github@dartcafe.de>
-
- @author René Gieling <github@dartcafe.de>
-
- @license GNU AGPL version 3 or any later version
-
- 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/>.
-
-->
<template>
<!-- eslint-disable-next-line vue/no-v-html -->
<div class="description" v-html="markedDescription">
{{ markedDescription }}
</div>
</template>
<script>
import marked from 'marked'
import DOMPurify from 'dompurify'
import { mapState } from 'vuex'
export default {
name: 'MarkUpDescription',
data() {
return {
delay: 50,
isLoading: false,
manualViewDatePoll: '',
manualViewTextPoll: '',
ranked: false,
voteSaved: false,
}
},
computed: {
...mapState({
description: state => state.poll.description,
descriptionSafe: state => state.poll.descriptionSafe,
}),
markedDescription() {
if (this.description) {
return DOMPurify.sanitize(marked(this.description))
} else {
return t('polls', 'No description provided')
}
},
},
}
</script>
<style lang="scss" scoped>
.description {
white-space: pre-wrap;
}
.description a {
font-weight: bold;
}
</style>

Просмотреть файл

@ -35,7 +35,7 @@
<script> <script>
import { mapState } from 'vuex' import { mapState } from 'vuex'
import ConfigBox from '../Base/ConfigBox' import ConfigBox from '../Base/ConfigBox'
import UserSearch from '../Base/UserSearch' import UserSearch from '../User/UserSearch'
import SharesEffective from '../Shares/SharesEffective' import SharesEffective from '../Shares/SharesEffective'
import SharesPublic from '../Shares/SharesPublic' import SharesPublic from '../Shares/SharesPublic'
import SharesUnsent from '../Shares/SharesUnsent' import SharesUnsent from '../Shares/SharesUnsent'

Просмотреть файл

@ -83,9 +83,9 @@ import { showSuccess } from '@nextcloud/dialogs'
import { Actions, ActionButton, Modal } from '@nextcloud/vue' import { Actions, ActionButton, Modal } from '@nextcloud/vue'
import orderBy from 'lodash/orderBy' import orderBy from 'lodash/orderBy'
import CalendarPeek from '../Calendar/CalendarPeek' import CalendarPeek from '../Calendar/CalendarPeek'
import Counter from '../Base/Counter' import Counter from '../Options/Counter'
import Confirmation from '../Base/Confirmation' import Confirmation from '../Options/Confirmation'
import UserMenu from '../Base/UserMenu' import UserMenu from '../User/UserMenu'
import VoteItem from './VoteItem' import VoteItem from './VoteItem'
import VoteTableHeaderItem from './VoteTableHeaderItem' import VoteTableHeaderItem from './VoteTableHeaderItem'
import { confirmOption } from '../../mixins/optionMixins' import { confirmOption } from '../../mixins/optionMixins'

Просмотреть файл

@ -33,7 +33,7 @@ import { translate, translatePlural } from '@nextcloud/l10n'
import { generateFilePath } from '@nextcloud/router' import { generateFilePath } from '@nextcloud/router'
import { Tooltip } from '@nextcloud/vue' import { Tooltip } from '@nextcloud/vue'
import UserItem from './components/Base/UserItem' import UserItem from './components/User/UserItem'
import ButtonDiv from './components/Base/ButtonDiv' import ButtonDiv from './components/Base/ButtonDiv'
/* eslint-disable-next-line camelcase, no-undef */ /* eslint-disable-next-line camelcase, no-undef */

Просмотреть файл

@ -9,6 +9,9 @@ export const watchPolls = {
restart: false, restart: false,
watching: true, watching: true,
lastUpdated: Math.round(Date.now() / 1000), lastUpdated: Math.round(Date.now() / 1000),
retryCounter: 0,
retryTimeout: 30000,
maxTries: 5,
} }
}, },
@ -18,11 +21,45 @@ export const watchPolls = {
this.cancelToken.cancel() this.cancelToken.cancel()
}, },
async loadTables(tables) {
let dispatches = []
tables.forEach((item) => {
this.lastUpdated = (item.updated > this.lastUpdated) ? item.updated : this.lastUpdated
// an updated poll table is reported
if (item.table === 'polls') {
if (this.$route.name !== 'publicVote') {
// load poll list only, when not in public poll
dispatches.push('polls/load')
}
if (item.pollId === parseInt(this.$route.params.id ?? this.$store.state.share.pollId)) {
// if current poll is affected, load current poll configuration
dispatches.push('poll/get')
// load also options and votes
dispatches.push('votes/list')
dispatches.push('options/list')
}
} else if (['votes', 'options'].includes(item.table)) {
dispatches.push('votes/list')
dispatches.push('options/list')
} else {
// a table of the current poll was reported, load
// corresponding stores
dispatches.push(item.table + '/list')
}
})
// remove duplicates
dispatches = [...new Set(dispatches)]
// execute all loads within one promise
const requests = dispatches.map(dispatches => this.$store.dispatch(dispatches))
await Promise.all(requests)
},
async watchPolls() { async watchPolls() {
console.debug('polls', 'Watch for updates') console.debug('polls', 'Watch for updates')
this.cancelToken = axios.CancelToken.source() this.cancelToken = axios.CancelToken.source()
this.retryCounter = 0
while (this.watching) { while (this.retryCounter < this.maxTries) {
let endPoint = 'apps/polls' let endPoint = 'apps/polls'
if (this.$route.name === 'publicVote') { if (this.$route.name === 'publicVote') {
endPoint = endPoint + '/s/' + this.$route.params.token endPoint = endPoint + '/s/' + this.$route.params.token
@ -35,77 +72,37 @@ export const watchPolls = {
params: { offset: this.lastUpdated }, params: { offset: this.lastUpdated },
cancelToken: this.cancelToken.token, cancelToken: this.cancelToken.token,
}) })
let dispatches = []
console.debug('polls', 'update detected', response.data.updates) console.debug('polls', 'update detected', response.data.updates)
this.retryCounter = 0
response.data.updates.forEach((item) => { await this.loadTables(response.data.updates)
this.lastUpdated = (item.updated > this.lastUpdated) ? item.updated : this.lastUpdated
// an updated poll table is reported
if (item.table === 'polls') {
if (this.$route.name !== 'publicVote') {
// load poll list only, when not in public poll
dispatches.push('polls/load')
}
if (item.pollId === parseInt(this.$route.params.id ?? this.$store.state.share.pollId)) {
// if current poll is affected, load current poll configuration
dispatches.push('poll/get')
// load also options and votes
dispatches.push('votes/list')
dispatches.push('options/list')
}
} else if (['votes', 'options'].includes(item.table)) {
dispatches.push('votes/list')
dispatches.push('options/list')
} else {
// a table of the current poll was reported, load
// corresponding stores
dispatches.push(item.table + '/list')
}
})
// remove duplicates
dispatches = [...new Set(dispatches)]
// execute all loads within one promise
const requests = dispatches.map(dispatches => this.$store.dispatch(dispatches))
await Promise.all(requests)
this.watching = true
} catch (e) { } catch (e) {
this.watching = false
if (axios.isCancel(e)) { if (axios.isCancel(e)) {
if (this.restart) { if (this.restart) {
console.debug('restart watch') console.debug('restart watch')
this.watching = true this.retryCounter = 0
this.restart = false this.restart = false
this.cancelToken = axios.CancelToken.source() this.cancelToken = axios.CancelToken.source()
} else { } else {
console.debug('Watch canceled') console.debug('Watch canceled')
this.watching = true
this.restart = false
return return
} }
} else if (e.response) { } else if (e.response) {
if (e.response.status === 304) { if (e.response.status === 304) {
this.watching = true // timeout of poll --> restart
continue this.retryCounter = 0
} else if (e.response.status === 503) {
console.debug('Server not available, reconnect watch in 30 sec')
await new Promise(resolve => setTimeout(resolve, 30000))
this.watching = true
continue
} else { } else {
this.retryCounter++
console.error('Unhandled error watching polls', e) console.error('Unhandled error watching polls', e)
return console.debug('error request', this.retryCounter)
await new Promise(resolve => setTimeout(resolve, this.retryTimeout))
} }
} else if (e.request) { } else if (e.request) {
console.debug('Watch aborted') this.retryCounter++
this.watching = true console.debug('No response - request aborted')
return console.debug('failed request', this.retryCounter)
await new Promise(resolve => setTimeout(resolve, this.retryTimeout))
} }
} }
} }

Просмотреть файл

@ -57,10 +57,7 @@
class="error" /> class="error" />
</h2> </h2>
<!-- eslint-disable-next-line vue/no-v-html --> <MarkUpDescription />
<div class="description" v-html="linkifyDescription">
{{ poll.description ? linkifyDescription : t('polls', 'No description provided') }}
</div>
</div> </div>
<div class="area__main" :class="viewMode"> <div class="area__main" :class="viewMode">
@ -93,18 +90,16 @@
<script> <script>
import { showError, showSuccess } from '@nextcloud/dialogs' import { showError, showSuccess } from '@nextcloud/dialogs'
// import linkifyUrls from 'linkify-urls'
import marked from 'marked'
import DOMPurify from 'dompurify'
import { mapState, mapGetters } from 'vuex' import { mapState, mapGetters } from 'vuex'
import { Actions, ActionButton, AppContent, EmptyContent } from '@nextcloud/vue' import { Actions, ActionButton, AppContent, EmptyContent } from '@nextcloud/vue'
import { getCurrentUser } from '@nextcloud/auth' import { getCurrentUser } from '@nextcloud/auth'
import { emit } from '@nextcloud/event-bus' import { emit } from '@nextcloud/event-bus'
import moment from '@nextcloud/moment' import moment from '@nextcloud/moment'
import Badge from '../components/Base/Badge' import Badge from '../components/Base/Badge'
import MarkUpDescription from '../components/Poll/MarkUpDescription'
import LoadingOverlay from '../components/Base/LoadingOverlay' import LoadingOverlay from '../components/Base/LoadingOverlay'
import PollInformation from '../components/Base/PollInformation' import PollInformation from '../components/Poll/PollInformation'
import PublicRegisterModal from '../components/Base/PublicRegisterModal' import PublicRegisterModal from '../components/Poll/PublicRegisterModal'
import VoteTable from '../components/VoteTable/VoteTable' import VoteTable from '../components/VoteTable/VoteTable'
export default { export default {
@ -114,6 +109,7 @@ export default {
ActionButton, ActionButton,
AppContent, AppContent,
Badge, Badge,
MarkUpDescription,
EmptyContent, EmptyContent,
LoadingOverlay, LoadingOverlay,
PollInformation, PollInformation,
@ -183,10 +179,6 @@ export default {
} }
}, },
linkifyDescription() {
return DOMPurify.sanitize(marked(this.poll.descriptionSafe))
},
windowTitle() { windowTitle() {
return t('polls', 'Polls') + ' - ' + this.poll.title return t('polls', 'Polls') + ' - ' + this.poll.title
}, },