mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
3.7 KiB
138 lines
3.7 KiB
2 years ago
|
<script>
|
||
|
import MonacoJsonObjectEditor from '@/components/monaco/MonacoJsonObjectEditor'
|
||
2 years ago
|
const editEnabled = inject < boolean > 'editEnabled'
|
||
2 years ago
|
|
||
|
export default {
|
||
|
name: 'JsonEditableCell',
|
||
|
components: { MonacoJsonObjectEditor },
|
||
|
props: {
|
||
|
value: [String, Object],
|
||
2 years ago
|
isForm: Boolean,
|
||
2 years ago
|
},
|
||
|
data: () => ({
|
||
|
localState: '',
|
||
|
expand: false,
|
||
|
isValid: true,
|
||
2 years ago
|
error: undefined,
|
||
2 years ago
|
}),
|
||
|
computed: {
|
||
|
parentListeners() {
|
||
|
const $listeners = {}
|
||
|
|
||
|
if (this.$listeners.blur) {
|
||
|
$listeners.blur = this.$listeners.blur
|
||
|
}
|
||
|
if (this.$listeners.focus) {
|
||
|
$listeners.focus = this.$listeners.focus
|
||
|
}
|
||
|
|
||
|
return $listeners
|
||
2 years ago
|
},
|
||
2 years ago
|
},
|
||
|
watch: {
|
||
|
value(val) {
|
||
|
try {
|
||
|
this.localState = typeof val === 'string' ? JSON.parse(val) : val
|
||
|
} catch (e) {
|
||
|
// ignore parse error for invalid JSON
|
||
|
}
|
||
|
},
|
||
|
localState(val) {
|
||
|
if (this.isForm) {
|
||
|
this.$emit('input', JSON.stringify(val))
|
||
|
}
|
||
2 years ago
|
},
|
||
2 years ago
|
},
|
||
|
created() {
|
||
|
try {
|
||
|
this.localState = typeof this.value === 'string' ? JSON.parse(this.value) : this.value
|
||
|
} catch (e) {
|
||
|
// ignore parse error for invalid JSON
|
||
|
}
|
||
|
},
|
||
2 years ago
|
mounted() {},
|
||
2 years ago
|
methods: {
|
||
|
save() {
|
||
|
this.expand = false
|
||
|
this.$emit('input', JSON.stringify(this.localState))
|
||
|
},
|
||
|
validate(n, e) {
|
||
|
this.isValid = n
|
||
|
this.error = e
|
||
2 years ago
|
},
|
||
|
},
|
||
2 years ago
|
}
|
||
|
</script>
|
||
|
|
||
2 years ago
|
<template>
|
||
|
<v-dialog :is="expand ? 'v-dialog' : 'div'" v-model="expand" max-width="800px" class="cell-container" @keydown.stop.enter>
|
||
|
<div class="d-flex pa-1" :class="{ backgroundColor: expand }">
|
||
|
<v-spacer />
|
||
|
<v-icon small class="mr-2" @click="expand = !expand">
|
||
|
{{ expand ? 'mdi-arrow-collapse' : 'mdi-arrow-expand' }}
|
||
|
</v-icon>
|
||
|
<template v-if="!isForm">
|
||
|
<v-btn outlined x-small class="mr-1" @click="$emit('cancel')">
|
||
|
<!-- Cancel -->
|
||
|
{{ $t('general.cancel') }}
|
||
|
</v-btn>
|
||
|
<v-btn x-small color="primary" :disabled="!isValid" @click="save">
|
||
|
<!-- Save -->
|
||
|
{{ $t('general.save') }}
|
||
|
</v-btn>
|
||
|
</template>
|
||
|
<v-btn v-else-if="expand" x-small @click="expand = false">
|
||
|
<!-- Close -->
|
||
|
{{ $t('general.close') }}
|
||
|
</v-btn>
|
||
|
</div>
|
||
|
<MonacoJsonObjectEditor
|
||
|
v-if="expand"
|
||
|
v-model="localState"
|
||
|
class="text-left caption"
|
||
|
style="width: 300px; min-height: min(600px, 80vh); min-width: 100%"
|
||
|
@validate="validate"
|
||
|
/>
|
||
|
<MonacoJsonObjectEditor
|
||
|
v-else
|
||
|
v-model="localState"
|
||
|
class="text-left caption"
|
||
|
style="width: 300px; min-height: 200px; min-width: 100%"
|
||
|
@validate="validate"
|
||
|
/>
|
||
|
<div v-show="error" class="px-2 py-1 text-left caption error--text">
|
||
|
{{ error }}
|
||
|
</div>
|
||
|
</v-dialog>
|
||
|
</template>
|
||
|
|
||
2 years ago
|
<style scoped>
|
||
|
.cell-container {
|
||
2 years ago
|
width: 100%;
|
||
2 years ago
|
}
|
||
|
</style>
|
||
|
<!--
|
||
|
/**
|
||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
|
||
|
*
|
||
|
* @author Naveen MR <oof1lab@gmail.com>
|
||
|
* @author Pranav C Balan <pranavxc@gmail.com>
|
||
|
*
|
||
|
* @license GNU AGPL version 3 or any later version
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|