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

AllowedGroups.vue « AdminSettings « views « src - github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 35a8ff7393b6521af9ec99d675ee5173646bdf48 (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
<!--
 - @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com>
 -
 - @author Joas Schilling <coding@schilljs.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>
	<div id="allowed_groups" class="videocalls section">
		<h2>{{ t('spreed', 'Limit to groups') }}</h2>
		<p class="settings-hint">
			{{ t('spreed', 'When at least one group is selected, only people of the listed groups can be part of conversations.') }}
		</p>
		<p class="settings-hint">
			{{ t('spreed', 'Guests can still join public conversations.') }}
		</p>
		<p class="settings-hint">
			{{ t('spreed', 'Users that can not use Talk anymore will still be listed as participants in their previous conversations and also their chat messages will be kept.') }}
		</p>

		<p class="allowed-groups-settings-content">
			<Multiselect v-model="allowedGroups"
				class="allowed-groups-select"
				:options="groups"
				:placeholder="t('spreed', 'Limit app usage to groups.')"
				:disabled="loading"
				:multiple="true"
				:searchable="true"
				:tag-width="60"
				:loading="loadingGroups"
				:show-no-options="false"
				:close-on-select="false"
				@search-change="searchGroup" />

			<button class="button primary"
				:disabled="loading"
				@click="saveChanges">
				{{ saveButtonText }}
			</button>
		</p>
	</div>
</template>

<script>
import axios from 'nextcloud-axios'
import debounce from 'debounce'
import { Multiselect } from 'nextcloud-vue'
import { generateOcsUrl } from 'nextcloud-router/dist/index'
import { loadState } from 'nextcloud-initial-state'

export default {
	name: 'AllowedGroups',

	components: {
		Multiselect,
	},

	data() {
		return {
			loading: false,
			loadingGroups: false,
			groups: [],
			allowedGroups: [],
			saveButtonText: t('spreed', 'Save changes'),
		}
	},

	mounted() {
		this.loading = true
		this.allowedGroups = loadState('talk', 'allowed_groups')
		this.groups = this.allowedGroups
		this.loading = false

		this.searchGroup('')
	},

	methods: {
		searchGroup: debounce(async function(query) {
			this.loadingGroups = true
			try {
				const res = await axios.get(generateOcsUrl('cloud', 2) + `groups?offset=0&search=${encodeURIComponent(query)}&limit=20`)
				// remove duplicates and sort
				this.groups = [...new Set(res.data.ocs.data.groups)].sort(function(a, b) {
					return a.localeCompare(b)
				})
			} catch (err) {
				console.error('Could not fetch groups', err)
			} finally {
				this.loadingGroups = false
			}
		}, 500),

		saveChanges() {
			this.loading = true
			this.loadingGroups = true
			this.saveButtonText = t('spreed', 'Saving …')

			OCP.AppConfig.setValue('spreed', 'allowed_groups', JSON.stringify(this.allowedGroups), {
				success: function() {
					this.loading = false
					this.loadingGroups = false
					this.saveButtonText = t('spreed', 'Saved!')
					setTimeout(function() {
						this.saveButtonText = t('spreed', 'Save changes')
					}.bind(this), 5000)
				}.bind(this),
			})
		},
	},
}
</script>

<style lang="scss" scoped>
.allowed-groups-settings-content {
	display: flex;
	align-items: center;

	.allowed-groups-select {
		width: 300px;
	}
	button {
		margin-left: 10px;
	}
}
</style>