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.
134 lines
3.5 KiB
134 lines
3.5 KiB
4 years ago
|
<template>
|
||
|
<v-dialog v-model="localState" max-width="500">
|
||
|
<v-card class="elevation-20">
|
||
2 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')"
|
||
2 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 />
|
||
2 years ago
|
<v-btn class="" small @click="$emit('input', false)">
|
||
3 years ago
|
{{ $t('general.cancel') }}
|
||
4 years ago
|
</v-btn>
|
||
2 years ago
|
<v-btn small :loading="loading" class="primary" :disabled="!valid" @click="createView">
|
||
3 years ago
|
{{ $t('general.submit') }}
|
||
4 years ago
|
</v-btn>
|
||
|
</v-card-actions>
|
||
|
</v-card>
|
||
|
</v-dialog>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
2 years ago
|
import { ViewTypes } from 'nocodb-sdk';
|
||
3 years ago
|
|
||
4 years ago
|
export default {
|
||
3 years ago
|
name: 'CreateViewDialog',
|
||
2 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,
|
||
2 years ago
|
queryParams: {},
|
||
4 years ago
|
}),
|
||
3 years ago
|
computed: {
|
||
|
localState: {
|
||
3 years ago
|
get() {
|
||
2 years ago
|
return this.value;
|
||
3 years ago
|
},
|
||
3 years ago
|
set(v) {
|
||
2 years ago
|
this.$emit('input', v);
|
||
|
},
|
||
3 years ago
|
},
|
||
|
typeAlias() {
|
||
2 years ago
|
return {
|
||
3 years ago
|
[ViewTypes.GRID]: 'grid',
|
||
|
[ViewTypes.GALLERY]: 'gallery',
|
||
|
[ViewTypes.FORM]: 'form',
|
||
2 years ago
|
[ViewTypes.KANBAN]: 'kanban',
|
||
|
}[this.show_as];
|
||
|
},
|
||
3 years ago
|
},
|
||
3 years ago
|
mounted() {
|
||
4 years ago
|
try {
|
||
|
if (this.copyView && this.copyView.query_params) {
|
||
2 years ago
|
this.queryParams = { ...JSON.parse(this.copyView.query_params) };
|
||
4 years ago
|
}
|
||
2 years ago
|
} catch (e) {}
|
||
|
this.view_name = `${this.alias || this.table}${this.viewsCount}`;
|
||
4 years ago
|
|
||
|
this.$nextTick(() => {
|
||
2 years ago
|
const input = this.$refs.name.$el.querySelector('input');
|
||
|
input.setSelectionRange(0, this.view_name.length);
|
||
|
input.focus();
|
||
|
});
|
||
4 years ago
|
},
|
||
|
methods: {
|
||
3 years ago
|
async createView() {
|
||
3 years ago
|
if (!this.valid) {
|
||
2 years ago
|
return;
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
this.loading = true;
|
||
4 years ago
|
try {
|
||
2 years ago
|
let data;
|
||
3 years ago
|
switch (this.show_as) {
|
||
|
case ViewTypes.GRID:
|
||
2 years ago
|
data = await this.$api.dbView.gridCreate(this.meta.id, {
|
||
3 years ago
|
title: this.view_name,
|
||
2 years ago
|
copy_from_id: this.selectedViewId,
|
||
|
});
|
||
|
break;
|
||
3 years ago
|
case ViewTypes.GALLERY:
|
||
2 years ago
|
data = await this.$api.dbView.galleryCreate(this.meta.id, {
|
||
3 years ago
|
title: this.view_name,
|
||
2 years ago
|
copy_from_id: this.selectedViewId,
|
||
|
});
|
||
|
break;
|
||
3 years ago
|
case ViewTypes.FORM:
|
||
2 years ago
|
data = await this.$api.dbView.formCreate(this.meta.id, {
|
||
3 years ago
|
title: this.view_name,
|
||
2 years ago
|
copy_from_id: this.selectedViewId,
|
||
|
});
|
||
|
break;
|
||
3 years ago
|
}
|
||
2 years ago
|
this.$toast.success('View created successfully').goAway(3000);
|
||
|
this.$emit('created', data);
|
||
|
this.$emit('input', false);
|
||
4 years ago
|
} catch (e) {
|
||
2 years ago
|
this.$toast.error(e.message).goAway(3000);
|
||
4 years ago
|
}
|
||
2 years ago
|
this.loading = false;
|
||
|
},
|
||
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
2 years ago
|
<style scoped></style>
|