Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use oc-select in settings #1979

Merged
merged 4 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/use-oc-select-for-settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Use oc-select

Replace oc-drop with oc select in settings

https://github.com/owncloud/ocis/pull/1979
35 changes: 3 additions & 32 deletions settings/pkg/assets/embed.go

Large diffs are not rendered by default.

64 changes: 17 additions & 47 deletions settings/ui/components/settings/SettingMultiChoice.vue
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
<template>
<div>
<oc-button :id="buttonElementId" class="uk-width-expand" justify-content="space-between">
<span v-if="selectedOptions !== null && selectedOptions.length > 0">
{{ selectedOptionsDisplayValues }}
</span>
<span v-else>
{{ setting.placeholder || $gettext('Please select') }}
</span>
<oc-icon name="expand_more" />
</oc-button>
<oc-drop
:drop-id="dropElementId"
:toggle="`#${buttonElementId}`"
mode="click"
position="bottom-justify"
:options="{ offset: 0, delayHide: 200, flip: false }"
>
<ul class="uk-list">
<li
v-for="(option, index) in setting.multiChoiceValue.options"
:key="getOptionElementId(index)"
>
<oc-checkbox
v-model="selectedOptions"
:option="option"
@input="onSelectedOption"
:label="option.displayValue"
/>
</li>
</ul>
</oc-drop>
</div>
<oc-select
v-model="selectedOptions"
:clearable="false"
:options="displayOptions"
@input="onSelectedOption"
multiple
/>
</template>

<script>
Expand All @@ -53,28 +28,21 @@ export default {
},
data () {
return {
selectedOptions: null
selectedOptions: []
}
},
computed: {
selectedOptionsDisplayValues () {
return Array.from(this.selectedOptions).map(option => option.displayValue).join(', ')
},
dropElementId () {
return `multi-choice-drop-${this.setting.id}`
},
buttonElementId () {
return `multi-choice-toggle-${this.setting.id}`
displayOptions () {
return this.setting.multiChoiceValue.options.map(val => val.displayValue)
}
},
methods: {
getOptionElementId (index) {
return `${this.setting.id}-${index}`
},
async onSelectedOption () {
const values = []
if (!isNil(this.selectedOptions)) {
this.selectedOptions.forEach(option => {
this.selectedOptions.forEach(displayValue => {
const option = this.setting.multiChoiceValue.options.find(val => val.displayValue === displayValue)

if (option.value.intValue) {
values.push({ intValue: option.value.intValue })
}
Expand Down Expand Up @@ -123,13 +91,15 @@ export default {
return selectedValues.includes(option.value.stringValue)
}
return false
})
}).map(val => val.displayValue)
}
}
// TODO: load the settings value of the authenticated user and set it in `selectedOptions`
// if not set, yet, apply defaults from settings bundle definition
if (this.selectedOptions === null) {
this.selectedOptions = this.setting.multiChoiceValue.options.filter(option => option.default)
this.selectedOptions = this.setting.multiChoiceValue.options
.filter(option => option.default)
.map(val => val.displayValue)
}
}
}
Expand Down
61 changes: 16 additions & 45 deletions settings/ui/components/settings/SettingSingleChoice.vue
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
<template>
<div>
<oc-button :id="buttonElementId" class="uk-width-expand" justify-content="space-between">
<span v-if="selectedOption">
{{ selectedOption.displayValue }}
</span>
<span v-else>
{{ setting.placeholder || $gettext('Please select') }}
</span>
<oc-icon name="expand_more" />
</oc-button>
<oc-drop
:drop-id="dropElementId"
:toggle="`#${buttonElementId}`"
mode="click"
close-on-click
position="bottom-justify"
:options="{ offset: 0, delayHide: 200, flip: false }"
>
<ul class="uk-list">
<li
v-for="(option, index) in setting.singleChoiceValue.options"
:key="getOptionElementId(index)"
>
<oc-radio
v-model="selectedOption"
:option="option"
@input="onSelectedOption"
:label="option.displayValue"
/>
</li>
</ul>
</oc-drop>
<oc-select
v-model="selectedOption"
:clearable="false"
:options="displayOptions"
@input="onSelectedOption"
/>
</div>
</template>

Expand Down Expand Up @@ -58,25 +33,21 @@ export default {
}
},
computed: {
dropElementId () {
return `single-choice-drop-${this.setting.id}`
},
buttonElementId () {
return `single-choice-toggle-${this.setting.id}`
displayOptions () {
return this.setting.singleChoiceValue.options.map(val => val.displayValue)
}
},
methods: {
getOptionElementId (index) {
return `${this.setting.id}-${index}`
},
async onSelectedOption () {
const values = []
if (!isNil(this.selectedOption)) {
if (this.selectedOption.value.intValue) {
values.push({ intValue: this.selectedOption.value.intValue })
const option = this.setting.singleChoiceValue.options.find(val => val.displayValue === this.selectedOption)

if (option.value.intValue) {
values.push({ intValue: option.value.intValue })
}
if (this.selectedOption.value.stringValue) {
values.push({ stringValue: this.selectedOption.value.stringValue })
if (option.value.stringValue) {
values.push({ stringValue: option.value.stringValue })
}
}
const payload = {
Expand Down Expand Up @@ -106,14 +77,14 @@ export default {
}
})
if (filtered.length > 0) {
this.selectedOption = filtered[0]
this.selectedOption = filtered[0].displayValue
}
}
// if not set, yet, apply default from settings bundle definition
if (isNil(this.selectedOption)) {
const defaults = this.setting.singleChoiceValue.options.filter(option => option.default)
if (defaults.length === 1) {
this.selectedOption = defaults[0]
this.selectedOption = defaults[0].displayValue
}
}
}
Expand Down