Skip to content

Commit

Permalink
Merge pull request #556 from nextcloud/fix/column-link-provider-selec…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
juliusknorr authored Sep 14, 2023
2 parents ce87749 + a2ef4bc commit 7a093d5
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 22 deletions.
9 changes: 5 additions & 4 deletions src/modules/modals/EditColumn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
:title-missing-error="editErrorTitle" />
</div>
<div class="col-2 space-LR space-T">
<component :is="getColumnForm" :column="editColumn" />
<component :is="getColumnForm" :column="editColumn" :can-save.sync="canSave" />
</div>
</div>
<div class="buttons">
Expand All @@ -36,7 +36,7 @@
{{ t('tables', 'Cancel') }}
</NcButton>
</div>
<NcButton type="primary" :aria-label="t('tables', 'Save')" @click="saveColumn">
<NcButton type="primary" :aria-label="t('tables', 'Save')" :disabled="!canSave" @click="saveColumn">
{{ t('tables', 'Save') }}
</NcButton>
</div>
Expand Down Expand Up @@ -108,9 +108,10 @@ export default {
data() {
return {
loading: false,
editColumn: structuredClone(this.column),
editColumn: Object.assign({}, this.column),
deleteId: null,
editErrorTitle: false,
canSave: true, // avoid to save an incorrect config
}
},
computed: {
Expand Down Expand Up @@ -165,7 +166,7 @@ export default {
this.editErrorTitle = false
},
async updateColumn() {
const data = { ...this.editColumn }
const data = Object.assign({}, this.editColumn)
if ((this.column.type === ColumnTypes.SelectionMulti || this.column.type === ColumnTypes.SelectionCheck) && data.selectionDefault !== null) data.selectionDefault = JSON.stringify(data.selectionDefault)
delete data.type
delete data.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default {
type: Object,
default: null,
},
canSave: {
type: Boolean,
default: true,
},
},
data() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export default {
type: Object,
default: null,
},
canSave: {
type: Boolean,
default: true,
},
},
data() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export default {
type: Object,
default: null,
},
canSave: {
type: Boolean,
default: true,
},
},
data() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export default {
type: Object,
default: null,
},
canSave: {
type: Boolean,
default: true,
},
},
data() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default {
type: Object,
default: null,
},
canSave: {
type: Boolean,
default: true,
},
},
data() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export default {
type: Object,
default: null,
},
canSave: {
type: Boolean,
default: true,
},
},
data() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default {
type: Object,
default: null,
},
canSave: {
type: Boolean,
default: true,
},
},
data() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export default {
type: Object,
default: null,
},
canSave: {
type: Boolean,
default: true,
},
},
data() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export default {
type: Object,
default: null,
},
canSave: {
type: Boolean,
default: true,
},
},
data() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export default {
type: Object,
default: null,
},
canSave: {
type: Boolean,
default: true,
},
},
data() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<div class="fix-col-4">
{{ t('tables', 'Allowed types') }}
</div>
<div v-if="!canSave" class="fix-col-4">
<NcNoteCard type="warning">
{{ t('tables', 'Please select at least one provider.') }}
</NcNoteCard>
</div>
<div class="col-4 space-B typeSelection">
<NcCheckboxRadioSwitch v-for="provider in getProviders" :key="provider.id" :checked.sync="provider.active" type="switch">
{{ provider.label }}
Expand All @@ -20,7 +25,7 @@
</template>

<script>
import { NcCheckboxRadioSwitch } from '@nextcloud/vue'
import { NcCheckboxRadioSwitch, NcNoteCard } from '@nextcloud/vue'
import axios from '@nextcloud/axios'
import displayError from '../../../../../utils/displayError.js'
import { generateOcsUrl } from '@nextcloud/router'
Expand All @@ -30,12 +35,17 @@ export default {
components: {
NcCheckboxRadioSwitch,
NcNoteCard,
},
props: {
column: {
type: Object,
default: null,
},
canSave: {
type: Boolean,
default: true,
},
},
data() {
return {
Expand All @@ -60,11 +70,24 @@ export default {
})
return activeProviderIds
},
error: {
get() {
return !this.canSave
},
set(v) {
this.$emit('update:can-save', !v)
},
},
},
watch: {
getSelectedProviderIds() {
this.mutableColumn.textAllowedPattern = this.getSelectedProviderIds.join(',')
if (this.getSelectedProviderIds.length === 0) {
this.error = true
} else {
this.error = false
}
},
column() {
this.mutableColumn = this.column
Expand Down Expand Up @@ -108,8 +131,8 @@ export default {
})
},
isActive(providerId) {
if (this.column.textAllowedPattern) {
const selectedProviders = this.column.textAllowedPattern.split(',')
if (this.column?.id) {
const selectedProviders = this.column.textAllowedPattern?.split(',')
return selectedProviders.indexOf(providerId) !== -1
} else {
return this.preActivatedProviders.indexOf(providerId) !== -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export default {
type: Object,
default: null,
},
canSave: {
type: Boolean,
default: true,
},
},
data() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default {
type: Object,
default: null,
},
canSave: {
type: Boolean,
default: true,
},
},
data() {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
<template>
<RowFormWrapper :title="column.title" :mandatory="column.mandatory" :description="column.description" :loading="isLoadingResults">
<NcSelect v-model="localValue"
:options="results"
:clearable="true"
label="title"
style="width: 100%"
@search="v => term = v">
<template #option="props">
<LinkWidget :thumbnail-url="props.thumbnailUrl" :icon-url="props.icon" :title="props.title" :subline="props.subline" :icon-size="40" />
</template>
<template #selected-option="props">
<LinkWidget :thumbnail-url="props.thumbnailUrl" :icon-url="props.icon" :title="props.title" :subline="props.subline" :icon-size="40" />
</template>
</NcSelect>
<div class="row">
<div v-if="providers.length === 0" class="col-4">
<NcNoteCard type="info">
{{ t('tables', 'You can not insert any links in this field. Please configure at least one link provider in the column configuration.') }}
</NcNoteCard>
</div>
<div class="col-4">
<NcSelect v-model="localValue"
:options="results"
:clearable="true"
label="title"
style="width: 100%"
@search="v => term = v">
<template #option="props">
<LinkWidget :thumbnail-url="props.thumbnailUrl" :icon-url="props.icon" :title="props.title" :subline="props.subline" :icon-size="40" />
</template>
<template #selected-option="props">
<LinkWidget :thumbnail-url="props.thumbnailUrl" :icon-url="props.icon" :title="props.title" :subline="props.subline" :icon-size="40" />
</template>
</NcSelect>
</div>
</div>
</RowFormWrapper>
</template>

Expand All @@ -21,7 +30,7 @@ import RowFormWrapper from './RowFormWrapper.vue'
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import displayError from '../../../../utils/displayError.js'
import { NcSelect } from '@nextcloud/vue'
import { NcNoteCard, NcSelect } from '@nextcloud/vue'
import debounce from 'debounce'
import generalHelper from '../../../../mixins/generalHelper.js'
import LinkWidget from '../LinkWidget.vue'
Expand All @@ -30,6 +39,7 @@ import { translate as t } from '@nextcloud/l10n'
export default {
components: {
NcNoteCard,
RowFormWrapper,
NcSelect,
LinkWidget,
Expand Down Expand Up @@ -104,7 +114,11 @@ export default {
},
mounted() {
this.providers = this.column?.textAllowedPattern?.split(',')
if (this.column?.textAllowedPattern) {
this.providers = this.column?.textAllowedPattern?.split(',')
} else {
this.providers = []
}
},
methods: {
Expand Down

0 comments on commit 7a093d5

Please sign in to comment.