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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
<!--
- @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="poll-list">
<div class="area__header">
<h2 class="title">
{{ title }}
</h2>
</div>
<div class="area__main">
<div>
<h2 class="title">
{{ t('polls', 'Manage polls') }}
</h2>
<h3 class="description">
{{ t('polls', 'Manage polls of other users. You can take over the ownership or delete polls.') }}
</h3>
</div>
<EmptyContent v-if="noPolls" icon="icon-polls">
{{ t('polls', 'No polls found for this category') }}
<template #desc>
{{ t('polls', 'Add one or change category!') }}
</template>
</EmptyContent>
<transition-group v-else
name="list"
tag="div"
class="poll-list__list">
<PollItem key="0"
:header="true"
:sort="sort"
:reverse="reverse"
@sort-list="setSort($event)" />
<PollItem v-for="(poll) in sortedList" :key="poll.id" :poll="poll">
<template #actions>
<Actions :force-menu="true">
<ActionButton icon="icon-add"
:close-after-click="true"
@click="confirmTakeOver(poll.id, poll.owner)">
{{ t('polls', 'Take over') }}
</ActionButton>
<ActionButton :icon="poll.deleted ? 'icon-history' : 'icon-category-app-bundles'"
:close-after-click="true"
@click="toggleArchive(poll.id)">
{{ poll.deleted ? t('polls', 'Restore poll') : t('polls', 'Archive poll') }}
</ActionButton>
<ActionButton icon="icon-delete"
class="danger"
:close-after-click="true"
@click="confirmDelete(poll.id)">
{{ t('polls', 'Delete poll') }}
</ActionButton>
</Actions>
</template>
</PollItem>
</transition-group>
</div>
<LoadingOverlay v-if="isLoading" />
<Modal v-if="takeOverModal" @close="takeOverModal = false">
<div class="modal__content">
<h2>{{ t('polls', 'Do you want to take over this poll from {username} and change the ownership?', {username: takeOverOwner}) }}</h2>
<div>{{ t('polls', 'The original owner will be notified.') }}</div>
<div class="modal__buttons">
<ButtonDiv :title="t('polls', 'No')"
@click="takeOverModal = false" />
<ButtonDiv :primary="true"
:title="t('polls', 'Yes')"
@click="takeOver()" />
</div>
</div>
</Modal>
<Modal v-if="deleteModal" @close="deleteModal = false">
<div class="modal__content">
<h2>{{ t('polls', 'Do you want to delete this poll?') }}</h2>
<div>{{ t('polls', 'This action cannot be reverted.') }}</div>
<div>{{ t('polls', 'The original owner will be notified.') }}</div>
<div class="modal__buttons">
<ButtonDiv :title="t('polls', 'No')"
@click="deleteModal = false" />
<ButtonDiv :primary="true"
:title="t('polls', 'Yes')"
@click="deletePoll()" />
</div>
</div>
</Modal>
</AppContent>
</template>
<script>
import { mapGetters } from 'vuex'
import { showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { Actions, ActionButton, AppContent, EmptyContent, Modal } from '@nextcloud/vue'
import sortBy from 'lodash/sortBy'
import LoadingOverlay from '../components/Base/LoadingOverlay'
import PollItem from '../components/PollList/PollItem'
export default {
name: 'Administration',
components: {
AppContent,
Actions,
ActionButton,
LoadingOverlay,
PollItem,
EmptyContent,
Modal,
},
data() {
return {
isLoading: false,
sort: 'created',
reverse: true,
takeOverModal: false,
takeOverOwner: '',
takeOverPollId: 0,
deleteModal: false,
deletePollId: 0,
}
},
computed: {
...mapGetters({
filteredPolls: 'pollsAdmin/filtered',
}),
title() {
return t('polls', 'Administration')
},
windowTitle() {
return t('polls', 'Polls') + ' - ' + this.title
},
sortedList() {
if (this.reverse) {
return sortBy(this.filteredPolls(this.$route.params.type), this.sort).reverse()
}
return sortBy(this.filteredPolls(this.$route.params.type), this.sort)
},
noPolls() {
return this.sortedList.length < 1
},
},
watch: {
$route() {
this.refreshView()
},
},
mounted() {
this.refreshView()
},
methods: {
confirmTakeOver(pollId, owner) {
this.takeOverPollId = pollId
this.takeOverOwner = owner
this.takeOverModal = true
},
confirmDelete(pollId) {
this.deletePollId = pollId
this.deleteModal = true
},
async toggleArchive(pollId) {
try {
await this.$store.dispatch('poll/toggleArchive', { pollId })
emit('update-polls')
} catch {
showError(t('polls', 'Error archiving/restoring poll.'))
}
},
async deletePoll() {
try {
await this.$store.dispatch('poll/delete', { pollId: this.deletePollId })
emit('update-polls')
this.deleteModal = false
} catch {
showError(t('polls', 'Error deleting poll.'))
this.deleteModal = false
}
},
async takeOver() {
try {
await this.$store.dispatch('pollsAdmin/takeOver', { pollId: this.takeOverPollId })
emit('update-polls')
this.takeOverModal = false
} catch {
showError(t('polls', 'Error overtaking poll.'))
this.takeOverModal = false
}
},
refreshView() {
window.document.title = t('polls', 'Polls') + ' - ' + this.title
if (!this.filteredPolls(this.$route.params.type).find((poll) => poll.id === this.$store.state.poll.id)) {
emit('toggle-sidebar', { open: false })
}
},
setSort(payload) {
if (this.sort === payload.sort) {
this.reverse = !this.reverse
} else {
this.sort = payload.sort
this.reverse = true
}
},
},
}
</script>
<style lang="scss" scoped>
.area__header {
margin-left: 33px !important;
}
.poll-list__list {
width: 100%;
display: flex;
flex-direction: column;
overflow: scroll;
padding-bottom: 14px;
}
</style>
|