rearranging components
Signed-off-by: dartcafe <github@dartcafe.de>
This commit is contained in:
Родитель
5a5dd80dea
Коммит
c55bb68f8a
|
@ -197,7 +197,7 @@ class Poll extends Entity implements JsonSerializable {
|
|||
}
|
||||
|
||||
public function getDescriptionSafe() {
|
||||
return filter_var($this->description,FILTER_SANITIZE_SPECIAL_CHARS);
|
||||
return htmlspecialchars($this->description);
|
||||
}
|
||||
|
||||
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>
|
||||
import { mapState } from 'vuex'
|
||||
import ConfigBox from '../Base/ConfigBox'
|
||||
import UserSearch from '../Base/UserSearch'
|
||||
import UserSearch from '../User/UserSearch'
|
||||
import SharesEffective from '../Shares/SharesEffective'
|
||||
import SharesPublic from '../Shares/SharesPublic'
|
||||
import SharesUnsent from '../Shares/SharesUnsent'
|
||||
|
|
|
@ -83,9 +83,9 @@ import { showSuccess } from '@nextcloud/dialogs'
|
|||
import { Actions, ActionButton, Modal } from '@nextcloud/vue'
|
||||
import orderBy from 'lodash/orderBy'
|
||||
import CalendarPeek from '../Calendar/CalendarPeek'
|
||||
import Counter from '../Base/Counter'
|
||||
import Confirmation from '../Base/Confirmation'
|
||||
import UserMenu from '../Base/UserMenu'
|
||||
import Counter from '../Options/Counter'
|
||||
import Confirmation from '../Options/Confirmation'
|
||||
import UserMenu from '../User/UserMenu'
|
||||
import VoteItem from './VoteItem'
|
||||
import VoteTableHeaderItem from './VoteTableHeaderItem'
|
||||
import { confirmOption } from '../../mixins/optionMixins'
|
||||
|
|
|
@ -33,7 +33,7 @@ import { translate, translatePlural } from '@nextcloud/l10n'
|
|||
import { generateFilePath } from '@nextcloud/router'
|
||||
import { Tooltip } from '@nextcloud/vue'
|
||||
|
||||
import UserItem from './components/Base/UserItem'
|
||||
import UserItem from './components/User/UserItem'
|
||||
import ButtonDiv from './components/Base/ButtonDiv'
|
||||
|
||||
/* eslint-disable-next-line camelcase, no-undef */
|
||||
|
|
|
@ -9,6 +9,9 @@ export const watchPolls = {
|
|||
restart: false,
|
||||
watching: true,
|
||||
lastUpdated: Math.round(Date.now() / 1000),
|
||||
retryCounter: 0,
|
||||
retryTimeout: 30000,
|
||||
maxTries: 5,
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -18,11 +21,45 @@ export const watchPolls = {
|
|||
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() {
|
||||
console.debug('polls', 'Watch for updates')
|
||||
this.cancelToken = axios.CancelToken.source()
|
||||
this.retryCounter = 0
|
||||
|
||||
while (this.watching) {
|
||||
while (this.retryCounter < this.maxTries) {
|
||||
let endPoint = 'apps/polls'
|
||||
if (this.$route.name === 'publicVote') {
|
||||
endPoint = endPoint + '/s/' + this.$route.params.token
|
||||
|
@ -35,77 +72,37 @@ export const watchPolls = {
|
|||
params: { offset: this.lastUpdated },
|
||||
cancelToken: this.cancelToken.token,
|
||||
})
|
||||
let dispatches = []
|
||||
|
||||
console.debug('polls', 'update detected', response.data.updates)
|
||||
|
||||
response.data.updates.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)
|
||||
|
||||
this.watching = true
|
||||
this.retryCounter = 0
|
||||
await this.loadTables(response.data.updates)
|
||||
|
||||
} catch (e) {
|
||||
this.watching = false
|
||||
|
||||
if (axios.isCancel(e)) {
|
||||
if (this.restart) {
|
||||
console.debug('restart watch')
|
||||
this.watching = true
|
||||
this.retryCounter = 0
|
||||
this.restart = false
|
||||
this.cancelToken = axios.CancelToken.source()
|
||||
} else {
|
||||
console.debug('Watch canceled')
|
||||
this.watching = true
|
||||
this.restart = false
|
||||
return
|
||||
}
|
||||
} else if (e.response) {
|
||||
|
||||
if (e.response.status === 304) {
|
||||
this.watching = true
|
||||
continue
|
||||
} 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
|
||||
// timeout of poll --> restart
|
||||
this.retryCounter = 0
|
||||
} else {
|
||||
this.retryCounter++
|
||||
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) {
|
||||
console.debug('Watch aborted')
|
||||
this.watching = true
|
||||
return
|
||||
this.retryCounter++
|
||||
console.debug('No response - request aborted')
|
||||
console.debug('failed request', this.retryCounter)
|
||||
await new Promise(resolve => setTimeout(resolve, this.retryTimeout))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,10 +57,7 @@
|
|||
class="error" />
|
||||
</h2>
|
||||
|
||||
<!-- eslint-disable-next-line vue/no-v-html -->
|
||||
<div class="description" v-html="linkifyDescription">
|
||||
{{ poll.description ? linkifyDescription : t('polls', 'No description provided') }}
|
||||
</div>
|
||||
<MarkUpDescription />
|
||||
</div>
|
||||
|
||||
<div class="area__main" :class="viewMode">
|
||||
|
@ -93,18 +90,16 @@
|
|||
|
||||
<script>
|
||||
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 { Actions, ActionButton, AppContent, EmptyContent } from '@nextcloud/vue'
|
||||
import { getCurrentUser } from '@nextcloud/auth'
|
||||
import { emit } from '@nextcloud/event-bus'
|
||||
import moment from '@nextcloud/moment'
|
||||
import Badge from '../components/Base/Badge'
|
||||
import MarkUpDescription from '../components/Poll/MarkUpDescription'
|
||||
import LoadingOverlay from '../components/Base/LoadingOverlay'
|
||||
import PollInformation from '../components/Base/PollInformation'
|
||||
import PublicRegisterModal from '../components/Base/PublicRegisterModal'
|
||||
import PollInformation from '../components/Poll/PollInformation'
|
||||
import PublicRegisterModal from '../components/Poll/PublicRegisterModal'
|
||||
import VoteTable from '../components/VoteTable/VoteTable'
|
||||
|
||||
export default {
|
||||
|
@ -114,6 +109,7 @@ export default {
|
|||
ActionButton,
|
||||
AppContent,
|
||||
Badge,
|
||||
MarkUpDescription,
|
||||
EmptyContent,
|
||||
LoadingOverlay,
|
||||
PollInformation,
|
||||
|
@ -183,10 +179,6 @@ export default {
|
|||
}
|
||||
},
|
||||
|
||||
linkifyDescription() {
|
||||
return DOMPurify.sanitize(marked(this.poll.descriptionSafe))
|
||||
},
|
||||
|
||||
windowTitle() {
|
||||
return t('polls', 'Polls') + ' - ' + this.poll.title
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче