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
|
<template>
<NcActions ref="quickShareActions"
class="share-select"
:menu-name="selectedOption"
:aria-label="ariaLabel"
type="tertiary-no-background"
force-name>
<template #icon>
<DropdownIcon :size="15" />
</template>
<NcActionButton v-for="option in options"
:key="option.label"
type="radio"
:model-value="option.label === selectedOption"
close-after-click
@click="selectOption(option.label)">
<template #icon>
<component :is="option.icon" />
</template>
{{ option.label }}
</NcActionButton>
</NcActions>
</template>
<script>
import DropdownIcon from 'vue-material-design-icons/TriangleSmallDown.vue'
import SharesMixin from '../mixins/SharesMixin.js'
import ShareDetails from '../mixins/ShareDetails.js'
import ShareTypes from '../mixins/ShareTypes.js'
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import IconEyeOutline from 'vue-material-design-icons/EyeOutline.vue'
import IconPencil from 'vue-material-design-icons/Pencil.vue'
import IconFileUpload from 'vue-material-design-icons/FileUpload.vue'
import IconTune from 'vue-material-design-icons/Tune.vue'
import {
BUNDLED_PERMISSIONS,
ATOMIC_PERMISSIONS,
} from '../lib/SharePermissionsToolBox.js'
export default {
name: 'SharingEntryQuickShareSelect',
components: {
DropdownIcon,
NcActions,
NcActionButton,
},
mixins: [SharesMixin, ShareDetails, ShareTypes],
props: {
share: {
type: Object,
required: true,
},
},
emits: ['open-sharing-details'],
data() {
return {
selectedOption: '',
}
},
computed: {
ariaLabel() {
return t('files_sharing', 'Quick share options, the current selected is "{selectedOption}"', { selectedOption: this.selectedOption })
},
canViewText() {
return t('files_sharing', 'View only')
},
canEditText() {
return t('files_sharing', 'Can edit')
},
fileDropText() {
return t('files_sharing', 'File drop')
},
customPermissionsText() {
return t('files_sharing', 'Custom permissions')
},
preSelectedOption() {
// We remove the share permission for the comparison as it is not relevant for bundled permissions.
if ((this.share.permissions & ~ATOMIC_PERMISSIONS.SHARE) === BUNDLED_PERMISSIONS.READ_ONLY) {
return this.canViewText
} else if (this.share.permissions === BUNDLED_PERMISSIONS.ALL || this.share.permissions === BUNDLED_PERMISSIONS.ALL_FILE) {
return this.canEditText
} else if ((this.share.permissions & ~ATOMIC_PERMISSIONS.SHARE) === BUNDLED_PERMISSIONS.FILE_DROP) {
return this.fileDropText
}
return this.customPermissionsText
},
options() {
const options = [{
label: this.canViewText,
icon: IconEyeOutline,
}, {
label: this.canEditText,
icon: IconPencil,
}]
if (this.supportsFileDrop) {
options.push({
label: this.fileDropText,
icon: IconFileUpload,
})
}
options.push({
label: this.customPermissionsText,
icon: IconTune,
})
return options
},
supportsFileDrop() {
if (this.isFolder && this.config.isPublicUploadEnabled) {
const shareType = this.share.type ?? this.share.shareType
return [this.SHARE_TYPES.SHARE_TYPE_LINK, this.SHARE_TYPES.SHARE_TYPE_EMAIL].includes(shareType)
}
return false
},
dropDownPermissionValue() {
switch (this.selectedOption) {
case this.canEditText:
return this.isFolder ? BUNDLED_PERMISSIONS.ALL : BUNDLED_PERMISSIONS.ALL_FILE
case this.fileDropText:
return BUNDLED_PERMISSIONS.FILE_DROP
case this.customPermissionsText:
return 'custom'
case this.canViewText:
default:
return BUNDLED_PERMISSIONS.READ_ONLY
}
},
},
created() {
this.selectedOption = this.preSelectedOption
},
methods: {
selectOption(optionLabel) {
this.selectedOption = optionLabel
if (optionLabel === this.customPermissionsText) {
this.$emit('open-sharing-details')
} else {
this.share.permissions = this.dropDownPermissionValue
this.queueUpdate('permissions')
// TODO: Add a focus method to NcActions or configurable returnFocus enabling to NcActionButton with closeAfterClick
this.$refs.quickShareActions.$refs.menuButton.$el.focus()
}
},
},
}
</script>
<style lang="scss" scoped>
.share-select {
display: block;
// TODO: NcActions should have a slot for custom trigger button like NcPopover
// Overrider NcActionms button to make it small
:deep(.action-item__menutoggle) {
color: var(--color-primary-element) !important;
font-size: 12.5px !important;
height: auto !important;
min-height: auto !important;
.button-vue__text {
font-weight: normal !important;
}
.button-vue__icon {
height: 24px !important;
min-height: 24px !important;
width: 24px !important;
min-width: 24px !important;
}
.button-vue__wrapper {
// Emulate NcButton's alignment=center-reverse
flex-direction: row-reverse !important;
}
}
}
</style>
|