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.
130 lines
3.5 KiB
130 lines
3.5 KiB
4 years ago
|
<template>
|
||
|
<v-dialog v-model="localState" max-width="500">
|
||
|
<v-card class="elevation-20">
|
||
3 years ago
|
<v-card-title class="grey darken-2 subheading" style="height:30px" />
|
||
4 years ago
|
<v-card-text class="pt-4 pl-4">
|
||
|
<p class="headline">
|
||
3 years ago
|
{{ $t('general.create') }} <span class="text-capitalize">{{ typeAlias }}</span> {{ $t('objects.view') }}
|
||
4 years ago
|
</p>
|
||
|
<v-form ref="form" v-model="valid" @submit.prevent="createView">
|
||
3 years ago
|
<!-- label="View Name" -->
|
||
4 years ago
|
<v-text-field
|
||
|
ref="name"
|
||
3 years ago
|
v-model="view_name"
|
||
3 years ago
|
:label="$t('labels.viewName')"
|
||
3 years ago
|
:rules="[v=>!!v || 'View name required', v => viewsList.every((v1) => (v1.alias || v1.title) !== v) || 'View name should be unique']"
|
||
4 years ago
|
autofocus
|
||
3 years ago
|
/>
|
||
4 years ago
|
</v-form>
|
||
|
</v-card-text>
|
||
|
<v-card-actions class="pa-4">
|
||
3 years ago
|
<v-spacer />
|
||
4 years ago
|
<v-btn class="" small @click="$emit('input',false)">
|
||
3 years ago
|
{{ $t('general.cancel') }}
|
||
4 years ago
|
</v-btn>
|
||
|
<v-btn
|
||
|
small
|
||
|
:loading="loading"
|
||
|
class="primary "
|
||
|
:disabled="!valid"
|
||
3 years ago
|
@click="createView"
|
||
|
>
|
||
3 years ago
|
{{ $t('general.submit') }}
|
||
4 years ago
|
</v-btn>
|
||
|
</v-card-actions>
|
||
|
</v-card>
|
||
|
</v-dialog>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
|
||
3 years ago
|
import { ViewTypes } from 'nocodb-sdk'
|
||
|
|
||
4 years ago
|
export default {
|
||
3 years ago
|
name: 'CreateViewDialog',
|
||
3 years ago
|
props: ['value', 'nodes', 'table', 'alias', 'show_as', 'viewsCount', 'primaryValueColumn', 'meta', 'copyView', 'viewsList', 'selectedViewId'],
|
||
4 years ago
|
data: () => ({
|
||
|
valid: false,
|
||
|
view_name: '',
|
||
|
loading: false,
|
||
|
queryParams: {}
|
||
|
}),
|
||
3 years ago
|
computed: {
|
||
|
localState: {
|
||
3 years ago
|
get() {
|
||
3 years ago
|
return this.value
|
||
|
},
|
||
3 years ago
|
set(v) {
|
||
3 years ago
|
this.$emit('input', v)
|
||
|
}
|
||
3 years ago
|
},
|
||
|
typeAlias() {
|
||
|
return ({
|
||
|
[ViewTypes.GRID]: 'grid',
|
||
|
[ViewTypes.GALLERY]: 'gallery',
|
||
|
[ViewTypes.FORM]: 'form',
|
||
|
[ViewTypes.KANBAN]: 'kanban'
|
||
|
})[this.show_as]
|
||
3 years ago
|
}
|
||
|
},
|
||
3 years ago
|
mounted() {
|
||
4 years ago
|
try {
|
||
|
if (this.copyView && this.copyView.query_params) {
|
||
3 years ago
|
this.queryParams = { ...JSON.parse(this.copyView.query_params) }
|
||
4 years ago
|
}
|
||
|
} catch (e) {
|
||
|
|
||
|
}
|
||
|
this.view_name = `${this.alias || this.table}${this.viewsCount}`
|
||
|
|
||
|
this.$nextTick(() => {
|
||
3 years ago
|
const input = this.$refs.name.$el.querySelector('input')
|
||
4 years ago
|
input.setSelectionRange(0, this.view_name.length)
|
||
3 years ago
|
input.focus()
|
||
4 years ago
|
})
|
||
|
},
|
||
|
methods: {
|
||
3 years ago
|
async createView() {
|
||
3 years ago
|
if (!this.valid) {
|
||
|
return
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
this.loading = true
|
||
4 years ago
|
try {
|
||
3 years ago
|
let data
|
||
|
switch (this.show_as) {
|
||
|
case ViewTypes.GRID:
|
||
|
data = (await this.$api.dbView.gridCreate(this.meta.id, {
|
||
|
title: this.view_name,
|
||
|
copy_from_id: this.selectedViewId
|
||
|
}))
|
||
|
break
|
||
|
case ViewTypes.GALLERY:
|
||
|
data = (await this.$api.dbView.galleryCreate(this.meta.id, {
|
||
|
title: this.view_name,
|
||
|
copy_from_id: this.selectedViewId
|
||
|
}))
|
||
|
break
|
||
|
case ViewTypes.FORM:
|
||
|
data = (await this.$api.dbView.formCreate(this.meta.id, {
|
||
|
title: this.view_name,
|
||
|
copy_from_id: this.selectedViewId
|
||
|
}))
|
||
|
break
|
||
|
}
|
||
3 years ago
|
this.$toast.success('View created successfully').goAway(3000)
|
||
3 years ago
|
this.$emit('created', data)
|
||
3 years ago
|
this.$emit('input', false)
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error(e.message).goAway(3000)
|
||
4 years ago
|
}
|
||
3 years ago
|
this.loading = false
|
||
4 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
|
|
||
|
</style>
|