Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Vote.vue « views « js « src - github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6ee023effdd534bbf77f6b710d0b6c85d8cc2283 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!--
  - @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>
	<AppContent :class="[{ closed: closed }, poll.type]">
		<div class="area__header">
			<PollTitle />
			<div class="header-actions">
				<PollInformation />
				<ActionSortOptions />
				<ActionChangeView />
				<ActionToggleSidebar v-if="acl.allowEdit || poll.allowComment" />
			</div>
		</div>
		<div class="description">
			<MarkUpDescription class="area__description" />
			<OptionProposals v-if="acl.allowAddOptions && proposalsAllowed" class="area__proposal" />
		</div>

		<div class="area__main" :class="viewMode">
			<VoteTable v-show="options.length" :view-mode="viewMode" />

			<EmptyContent v-if="!options.length" :icon="pollTypeIcon">
				{{ t('polls', 'No vote options available') }}
				<template #desc>
					<button v-if="acl.allowEdit" @click="openOptions">
						{{ t('polls', 'Add some!') }}
					</button>
					<div v-if="!acl.allowEdit">
						{{ t('polls', 'Maybe the owner did not provide some until now.') }}
					</div>
				</template>
			</EmptyContent>
		</div>

		<div v-if="poll.anonymous" class="area__footer">
			<div>
				{{ t('poll', 'Although participant\'s names are hidden, this is not a real anonymous poll because they are not hidden from the owner.') }}
				{{ t('poll', 'Additionally the owner can remove the anonymous flag at any time, which will reveal the participant\'s names.') }}
			</div>
		</div>

		<PublicRegisterModal v-if="showRegisterModal" />
		<LoadingOverlay v-if="isLoading" />
	</AppContent>
</template>

<script>
import { showError, showSuccess } from '@nextcloud/dialogs'
import { mapState, mapGetters } from 'vuex'
import { AppContent, EmptyContent } from '@nextcloud/vue'
import { getCurrentUser } from '@nextcloud/auth'
import { emit } from '@nextcloud/event-bus'
import MarkUpDescription from '../components/Poll/MarkUpDescription'
import PollTitle from '../components/Poll/PollTitle'
import LoadingOverlay from '../components/Base/LoadingOverlay'
import PollInformation from '../components/Poll/PollInformation'
import PublicRegisterModal from '../components/Poll/PublicRegisterModal'
import VoteTable from '../components/VoteTable/VoteTable'
import ActionSortOptions from '../components/Actions/ActionSortOptions'
import ActionChangeView from '../components/Actions/ActionChangeView'
import ActionToggleSidebar from '../components/Actions/ActionToggleSidebar'
import OptionProposals from '../components/Options/OptionProposals'

export default {
	name: 'Vote',
	components: {
		ActionChangeView,
		ActionSortOptions,
		ActionToggleSidebar,
		AppContent,
		MarkUpDescription,
		EmptyContent,
		LoadingOverlay,
		PollInformation,
		PollTitle,
		PublicRegisterModal,
		VoteTable,
		OptionProposals,
	},

	data() {
		return {
			delay: 50,
			isLoading: false,
			voteSaved: false,
		}
	},

	computed: {
		...mapState({
			poll: (state) => state.poll,
			acl: (state) => state.poll.acl,
			share: (state) => state.share,
			settings: (state) => state.settings,
		}),

		...mapGetters({
			closed: 'poll/closed',
			options: 'options/rankedOptions',
			pollTypeIcon: 'poll/typeIcon',
			viewMode: 'settings/viewMode',
			proposalsAllowed: 'poll/proposalsAllowed',
		}),

		showEmailEdit() {
			return ['email', 'contact', 'external'].includes(this.share.type)
		},

		windowTitle() {
			return t('polls', 'Polls') + ' - ' + this.poll.title
		},

		showRegisterModal() {
			return (this.$route.name === 'publicVote'
				&& ['public', 'email', 'contact'].includes(this.share.type)
				&& !this.closed
				&& this.poll.id
			)
		},

	},

	created() {
		// simulate @media:prefers-color-scheme until it is supported for logged in users
		// This simulates the theme--dark
		// TODO: remove, when completely supported by core
		if (!window.matchMedia) {
			return true
		} else if (this.$route.name === 'publicVote' && window.matchMedia('(prefers-color-scheme: dark)').matches) {
			document.body.classList.add('theme--dark')
		}

		if (getCurrentUser() && this.$route.name === 'publicVote') {
			// reroute to the internal vote page, if the user is logged in
			this.$store.dispatch('share/get', { token: this.$route.params.token })
				.then((response) => {
					this.$router.replace({ name: 'vote', params: { id: response.share.pollId } })
				})
				.catch(() => {
					this.$router.replace({ name: 'notfound' })
				})
		} else {
			emit('toggle-sidebar', { open: (window.innerWidth > 920) })
		}
	},

	beforeDestroy() {
		this.$store.dispatch({ type: 'poll/reset' })
	},

	methods: {
		openOptions() {
			emit('toggle-sidebar', { open: true, activeTab: 'options' })
		},

		async submitEmailAddress(emailAddress) {
			try {
				await this.$store.dispatch('share/updateEmailAddress', { emailAddress })
				showSuccess(t('polls', 'Email address {emailAddress} saved.', { emailAddress }))
			} catch {
				showError(t('polls', 'Error saving email address {emailAddress}', { emailAddress }))
			}
		},
	},
}

</script>

<style lang="scss" scoped>
.area__header {
	display: flex;
}

.description {
	display: flex;
	flex-wrap: wrap;
}

.markup-description {
	padding: 8px;
	flex: 2 1;
}

.option-proposals {
	padding: 8px;
	flex: 1 1;
	align-self: flex-end;
	border: 1px solid var(--color-polls-foreground-yes);
	border-radius: var(--border-radius);
	background-color: var(--color-polls-background-yes);
	.mx-datepicker {
		.mx-input {
			background-clip: initial !important;
		}
	}
}

.header-actions {
	display: flex;
	flex-wrap: wrap-reverse;
	flex: 0 1 auto;
	justify-content: flex-end;
}

.icon.icon-settings.active {
	display: block;
	width: 44px;
	height: 44px;
}

</style>