fix(front): [WIP] privacy_level slider on manageUploads - correct Vue syntax for 2-way binding `computed`; support `undefined` value
This commit is contained in:
parent
13f4567429
commit
180d23ab7c
|
@ -39,6 +39,7 @@ onMounted(() => {
|
||||||
<Layout
|
<Layout
|
||||||
stack
|
stack
|
||||||
no-gap
|
no-gap
|
||||||
|
:class="$style.slider"
|
||||||
:style="`
|
:style="`
|
||||||
--step-size: calc(100% / ${keys.length + 2});
|
--step-size: calc(100% / ${keys.length + 2});
|
||||||
--slider-width: calc(var(--step-size) * ${keys.length - 1} + 16px);
|
--slider-width: calc(var(--step-size) * ${keys.length - 1} + 16px);
|
||||||
|
@ -120,6 +121,7 @@ onMounted(() => {
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style module lang="scss">
|
<style module lang="scss">
|
||||||
|
.slider {
|
||||||
.label {
|
.label {
|
||||||
margin-top: -18px;
|
margin-top: -18px;
|
||||||
padding-bottom: 8px;
|
padding-bottom: 8px;
|
||||||
|
@ -175,5 +177,12 @@ onMounted(() => {
|
||||||
background-color: var(--focus-ring-color);
|
background-color: var(--focus-ring-color);
|
||||||
outline: 2px solid currentcolor;
|
outline: 2px solid currentcolor;
|
||||||
}
|
}
|
||||||
|
&[disabled] .pin {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
&[disabled] * {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -106,23 +106,39 @@ const options = {
|
||||||
|
|
||||||
// Model for use in global slider `privacy_level`
|
// Model for use in global slider `privacy_level`
|
||||||
const globalPrivacyLevel = computed<PrivacyLevel | undefined>({
|
const globalPrivacyLevel = computed<PrivacyLevel | undefined>({
|
||||||
get: () =>
|
get () {
|
||||||
selectedItems.value.map(({ privacy_level }) =>
|
return selectedItems.value.length === 0
|
||||||
privacy_level as 'me' | 'instance' | 'everyone' | undefined
|
? undefined
|
||||||
).reduce((acc, item) =>
|
: selectedItems.value.map(({ privacy_level }) => privacy_level)
|
||||||
acc === item
|
.reduce((acc, item) =>
|
||||||
? acc
|
acc === item
|
||||||
: undefined
|
? acc
|
||||||
),
|
: undefined
|
||||||
set: function (level) {
|
)
|
||||||
items.value
|
},
|
||||||
= items.value.map(item => ({
|
set (level) {
|
||||||
...item,
|
if (level === undefined) return
|
||||||
privacy_level:
|
|
||||||
level === undefined || !item.selected
|
const changes = []
|
||||||
? item.privacy_level
|
|
||||||
: level
|
for (const [index, item] of items.value.entries()) {
|
||||||
}))
|
if (!item.selected || item.privacy_level === level)
|
||||||
|
break;
|
||||||
|
|
||||||
|
changes.push({
|
||||||
|
uuid: item.uuid,
|
||||||
|
privacy_level: level
|
||||||
|
})
|
||||||
|
|
||||||
|
items.value[index].privacy_level = level
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: This will never set privacy_level to undefined.
|
||||||
|
// privacy_level as undefined is only a workaround for items in legacy libraries.
|
||||||
|
axios.patch<paths['/api/v2/uploads/bulk_update/']['patch']['responses']['200']['content']['application/json']>(
|
||||||
|
'uploads/bulk_update/',
|
||||||
|
{ params: changes }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -303,6 +319,7 @@ const getPrivacyLevelChoice = (privacyLevel: PrivacyLevel) => {
|
||||||
|
|
||||||
<Slider
|
<Slider
|
||||||
v-model="globalPrivacyLevel"
|
v-model="globalPrivacyLevel"
|
||||||
|
:disabled="selectedItems.length === 0"
|
||||||
:options="options"
|
:options="options"
|
||||||
:label="`Privacy level (${ selectedItems.length } items)`"
|
:label="`Privacy level (${ selectedItems.length } items)`"
|
||||||
/>
|
/>
|
||||||
|
@ -412,7 +429,10 @@ const getPrivacyLevelChoice = (privacyLevel: PrivacyLevel) => {
|
||||||
|
|
||||||
<Pill
|
<Pill
|
||||||
:title="t('components.manage.library.UploadsTable.table.upload.header.privacyLevel')"
|
:title="t('components.manage.library.UploadsTable.table.upload.header.privacyLevel')"
|
||||||
@click="addSearchToken('privacy_level', item.privacy_level)"
|
v-bind="item.privacy_level
|
||||||
|
? { onClick: () => addSearchToken('privacy_level', item.privacy_level as PrivacyLevel) }
|
||||||
|
: { disabled: true }
|
||||||
|
"
|
||||||
>
|
>
|
||||||
{{ item.privacy_level }}
|
{{ item.privacy_level }}
|
||||||
</Pill>
|
</Pill>
|
||||||
|
|
Loading…
Reference in New Issue