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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
<!--
- @copyright Copyright (c) 2020 Georg Ehrke <oc.list@georgehrke.com>
- @author Georg Ehrke <oc.list@georgehrke.com>
-
- @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>
<NcModal size="normal"
:title="$t('user_status', 'Set status')"
@close="closeModal">
<div class="set-status-modal">
<!-- Status selector -->
<div class="set-status-modal__header">
<h2>{{ $t('user_status', 'Online status') }}</h2>
</div>
<div class="set-status-modal__online-status">
<OnlineStatusSelect v-for="status in statuses"
:key="status.type"
v-bind="status"
:checked="status.type === statusType"
@select="changeStatus" />
</div>
<!-- Status message -->
<div class="set-status-modal__header">
<h2>{{ $t('user_status', 'Status message') }}</h2>
</div>
<div class="set-status-modal__custom-input">
<CustomMessageInput ref="customMessageInput"
:icon="icon"
:message="message"
@change="setMessage"
@submit="saveStatus"
@select-icon="setIcon" />
</div>
<div v-if="messageId"
class="set-status-modal__automation-hint">
{{ $t('user_status', 'Your status was set automatically') }}
</div>
<PreviousStatus v-if="messageId"
:icon="backupIcon"
:message="backupMessage"
@select="revertBackupFromServer" />
<PredefinedStatusesList @select-status="selectPredefinedMessage" />
<ClearAtSelect :clear-at="clearAt"
@select-clear-at="setClearAt" />
<div class="status-buttons">
<NcButton :wide="true"
type="tertiary"
:text="$t('user_status', 'Clear status message')"
:disabled="isSavingStatus"
@click="clearStatus">
{{ $t('user_status', 'Clear status message') }}
</NcButton>
<NcButton :wide="true"
type="primary"
:text="$t('user_status', 'Set status message')"
:disabled="isSavingStatus"
@click="saveStatus">
{{ $t('user_status', 'Set status message') }}
</NcButton>
</div>
</div>
</NcModal>
</template>
<script>
import { showError } from '@nextcloud/dialogs'
import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import { getAllStatusOptions } from '../services/statusOptionsService.js'
import OnlineStatusMixin from '../mixins/OnlineStatusMixin.js'
import PredefinedStatusesList from './PredefinedStatusesList.vue'
import PreviousStatus from './PreviousStatus.vue'
import CustomMessageInput from './CustomMessageInput.vue'
import ClearAtSelect from './ClearAtSelect.vue'
import OnlineStatusSelect from './OnlineStatusSelect.vue'
export default {
name: 'SetStatusModal',
components: {
ClearAtSelect,
CustomMessageInput,
NcModal,
OnlineStatusSelect,
PredefinedStatusesList,
PreviousStatus,
NcButton,
},
mixins: [OnlineStatusMixin],
data() {
return {
clearAt: null,
isSavingStatus: false,
statuses: getAllStatusOptions(),
}
},
computed: {
messageId() {
return this.$store.state.userStatus.messageId
},
icon() {
return this.$store.state.userStatus.icon
},
message() {
return this.$store.state.userStatus.message || ''
},
backupIcon() {
return this.$store.state.userBackupStatus.icon || ''
},
backupMessage() {
return this.$store.state.userBackupStatus.message || ''
},
resetButtonText() {
if (this.backupIcon && this.backupMessage) {
return this.$t('user_status', 'Reset status to "{icon} {message}"', {
icon: this.backupIcon,
message: this.backupMessage,
})
} else if (this.backupMessage) {
return this.$t('user_status', 'Reset status to "{message}"', {
message: this.backupMessage,
})
} else if (this.backupIcon) {
return this.$t('user_status', 'Reset status to "{icon}"', {
icon: this.backupIcon,
})
}
return this.$t('user_status', 'Reset status')
},
},
/**
* Loads the current status when a user opens dialog
*/
mounted() {
this.$store.dispatch('fetchBackupFromServer')
if (this.$store.state.userStatus.clearAt !== null) {
this.clearAt = {
type: '_time',
time: this.$store.state.userStatus.clearAt,
}
}
},
methods: {
/**
* Closes the Set Status modal
*/
closeModal() {
this.$emit('close')
},
/**
* Sets a new icon
*
* @param {string} icon The new icon
*/
setIcon(icon) {
this.messageId = null
this.icon = icon
this.$nextTick(() => {
this.$refs.customMessageInput.focus()
})
},
/**
* Sets a new message
*
* @param {string} message The new message
*/
setMessage(message) {
this.messageId = null
this.message = message
},
/**
* Sets a new clearAt value
*
* @param {object} clearAt The new clearAt object
*/
setClearAt(clearAt) {
this.clearAt = clearAt
},
/**
* Sets new icon/message/clearAt based on a predefined message
*
* @param {object} status The predefined status object
*/
selectPredefinedMessage(status) {
this.messageId = status.id
this.clearAt = status.clearAt
this.icon = status.icon
this.message = status.message
},
/**
* Saves the status and closes the
*
* @return {Promise<void>}
*/
async saveStatus() {
if (this.isSavingStatus) {
return
}
try {
this.isSavingStatus = true
if (this.messageId !== undefined && this.messageId !== null) {
await this.$store.dispatch('setPredefinedMessage', {
messageId: this.messageId,
clearAt: this.clearAt,
})
} else {
await this.$store.dispatch('setCustomMessage', {
message: this.message,
icon: this.icon,
clearAt: this.clearAt,
})
}
} catch (err) {
showError(this.$t('user_status', 'There was an error saving the status'))
console.debug(err)
this.isSavingStatus = false
return
}
this.isSavingStatus = false
this.closeModal()
},
/**
*
* @return {Promise<void>}
*/
async clearStatus() {
try {
this.isSavingStatus = true
await this.$store.dispatch('clearMessage')
} catch (err) {
showError(this.$t('user_status', 'There was an error clearing the status'))
console.debug(err)
this.isSavingStatus = false
return
}
this.isSavingStatus = false
this.closeModal()
},
/**
*
* @return {Promise<void>}
*/
async revertBackupFromServer() {
try {
this.isSavingStatus = true
await this.$store.dispatch('revertBackupFromServer', {
messageId: this.messageId,
})
} catch (err) {
showError(this.$t('user_status', 'There was an error reverting the status'))
console.debug(err)
this.isSavingStatus = false
return
}
this.isSavingStatus = false
},
},
}
</script>
<style lang="scss" scoped>
.set-status-modal {
padding: 8px 20px 20px 20px;
&__header {
text-align: center;
font-weight: bold;
margin: 15px 0;
}
&__online-status {
display: grid;
grid-template-columns: 1fr 1fr;
}
&__custom-input {
display: flex;
width: 100%;
margin-bottom: 10px;
}
&__automation-hint {
display: flex;
width: 100%;
margin-bottom: 10px;
color: var(--color-text-maxcontrast);
}
.status-buttons {
display: flex;
padding: 3px;
padding-left:0;
gap: 3px;
}
}
@media only screen and (max-width: 500px) {
.set-status-modal__online-status {
grid-template-columns: none !important;
}
}
</style>
|