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
|
<!--
- SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<Fragment>
<NcModal v-if="showRemoveGroupModal"
@close="showRemoveGroupModal = false">
<div class="modal__content">
<h2 class="modal__header">
{{ t('settings', 'Please confirm the group removal') }}
</h2>
<NcNoteCard type="warning"
show-alert>
{{ t('settings', 'You are about to remove the group "{group}". The accounts will NOT be deleted.', { group: name }) }}
</NcNoteCard>
<div class="modal__button-row">
<NcButton type="secondary"
@click="showRemoveGroupModal = false">
{{ t('settings', 'Cancel') }}
</NcButton>
<NcButton type="primary"
@click="removeGroup">
{{ t('settings', 'Confirm') }}
</NcButton>
</div>
</div>
</NcModal>
<NcAppNavigationItem :key="id"
:exact="true"
:name="name"
:to="{ name: 'group', params: { selectedGroup: encodeURIComponent(id) } }"
:loading="loadingRenameGroup"
:menu-open="openGroupMenu"
@update:menuOpen="handleGroupMenuOpen">
<template #icon>
<AccountGroup :size="20" />
</template>
<template #counter>
<NcCounterBubble v-if="count"
:type="active ? 'highlighted' : undefined">
{{ count }}
</NcCounterBubble>
</template>
<template #actions>
<NcActionInput v-if="id !== 'admin' && id !== 'disabled' && (settings.isAdmin || settings.isDelegatedAdmin)"
ref="displayNameInput"
:trailing-button-label="t('settings', 'Submit')"
type="text"
:value="name"
:label=" t('settings', 'Rename group')"
@submit="renameGroup(id)">
<template #icon>
<Pencil :size="20" />
</template>
</NcActionInput>
<NcActionButton v-if="id !== 'admin' && id !== 'disabled' && (settings.isAdmin || settings.isDelegatedAdmin)"
@click="showRemoveGroupModal = true">
<template #icon>
<Delete :size="20" />
</template>
{{ t('settings', 'Remove group') }}
</NcActionButton>
</template>
</NcAppNavigationItem>
</Fragment>
</template>
<script>
import { Fragment } from 'vue-frag'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActionInput from '@nextcloud/vue/dist/Components/NcActionInput.js'
import NcAppNavigationItem from '@nextcloud/vue/dist/Components/NcAppNavigationItem.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcCounterBubble from '@nextcloud/vue/dist/Components/NcCounterBubble.js'
import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
import AccountGroup from 'vue-material-design-icons/AccountGroup.vue'
import Delete from 'vue-material-design-icons/Delete.vue'
import Pencil from 'vue-material-design-icons/Pencil.vue'
import { showError } from '@nextcloud/dialogs'
export default {
name: 'GroupListItem',
components: {
AccountGroup,
Delete,
Fragment,
NcActionButton,
NcActionInput,
NcAppNavigationItem,
NcButton,
NcCounterBubble,
NcModal,
NcNoteCard,
Pencil,
},
props: {
/**
* If this group is currently selected
*/
active: {
type: Boolean,
required: true,
},
/**
* Number of members within this group
*/
count: {
type: Number,
default: null,
},
/**
* Identifier of this group
*/
id: {
type: String,
required: true,
},
/**
* Name of this group
*/
name: {
type: String,
required: true,
},
},
data() {
return {
loadingRenameGroup: false,
openGroupMenu: false,
showRemoveGroupModal: false,
}
},
computed: {
settings() {
return this.$store.getters.getServerData
},
},
methods: {
handleGroupMenuOpen() {
this.openGroupMenu = true
},
async renameGroup(gid) {
// check if group id is valid
if (gid.trim() === '') {
return
}
const displayName = this.$refs.displayNameInput.$el.querySelector('input[type="text"]').value
// check if group name is valid
if (displayName.trim() === '') {
return
}
try {
this.openGroupMenu = false
this.loadingRenameGroup = true
await this.$store.dispatch('renameGroup', {
groupid: gid.trim(),
displayName: displayName.trim(),
})
this.loadingRenameGroup = false
} catch {
this.openGroupMenu = true
this.loadingRenameGroup = false
}
},
async removeGroup() {
try {
await this.$store.dispatch('removeGroup', this.id)
this.showRemoveGroupModal = false
} catch (error) {
showError(t('settings', 'Failed to remove group "{group}"', { group: this.name }))
}
},
},
}
</script>
<style lang="scss" scoped>
.modal {
&__header {
margin: 0;
}
&__content {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
gap: 4px 0;
}
&__button-row {
display: flex;
width: 100%;
justify-content: space-between;
}
}
</style>
|