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.
152 lines
4.0 KiB
152 lines
4.0 KiB
3 years ago
|
<template>
|
||
3 years ago
|
<div class="d-flex align-center">
|
||
2 years ago
|
<span v-if="!hideLabel" v-ripple class="caption font-weight-bold pointer" @click="templatesModal = true"
|
||
|
>Templates</span
|
||
|
>
|
||
3 years ago
|
<v-dialog v-if="templatesModal" v-model="templatesModal">
|
||
3 years ago
|
<v-card height="90vh">
|
||
3 years ago
|
<project-templates
|
||
|
:create-project="createProject"
|
||
2 years ago
|
style="height: 90vh"
|
||
3 years ago
|
modal
|
||
|
:loading="loading"
|
||
3 years ago
|
:project-template.sync="templateData"
|
||
3 years ago
|
@import="importTemplate"
|
||
|
/>
|
||
3 years ago
|
</v-card>
|
||
|
</v-dialog>
|
||
3 years ago
|
|
||
|
<v-overlay :value="projectCreation" z-index="99999" opacity=".9">
|
||
|
<div class="d-flex flex-column align-center">
|
||
|
<v-progress-circular indeterminate size="100" width="15" class="mb-10" />
|
||
|
<span class="title">{{ loaderMessages[loaderMessagesIndex] }}</span>
|
||
|
</div>
|
||
|
</v-overlay>
|
||
3 years ago
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
2 years ago
|
import ProjectTemplates from '~/components/templates/List';
|
||
3 years ago
|
|
||
3 years ago
|
export default {
|
||
|
name: 'TemplatesModal',
|
||
|
components: { ProjectTemplates },
|
||
3 years ago
|
props: {
|
||
|
hideLabel: Boolean,
|
||
|
value: Boolean,
|
||
2 years ago
|
createProject: Boolean,
|
||
3 years ago
|
},
|
||
3 years ago
|
data: () => ({
|
||
3 years ago
|
templateData: null,
|
||
3 years ago
|
loading: false,
|
||
|
projectCreation: false,
|
||
|
loaderMessagesIndex: 0,
|
||
|
loaderMessages: [
|
||
|
'Setting up new database configs',
|
||
|
'Inferring database schema',
|
||
|
'Generating APIs.',
|
||
|
'Generating APIs..',
|
||
|
'Generating APIs...',
|
||
|
'Generating APIs....',
|
||
|
'Please wait',
|
||
|
'Please wait.',
|
||
|
'Please wait..',
|
||
|
'Please wait...',
|
||
|
'Please wait..',
|
||
|
'Please wait.',
|
||
|
'Please wait',
|
||
|
'Please wait.',
|
||
|
'Please wait..',
|
||
|
'Please wait...',
|
||
|
'Please wait..',
|
||
|
'Please wait.',
|
||
|
'Please wait..',
|
||
2 years ago
|
'Please wait...',
|
||
|
],
|
||
3 years ago
|
}),
|
||
3 years ago
|
computed: {
|
||
|
templatesModal: {
|
||
|
get() {
|
||
2 years ago
|
return this.value;
|
||
3 years ago
|
},
|
||
|
set(v) {
|
||
2 years ago
|
this.$emit('input', v);
|
||
|
},
|
||
|
},
|
||
3 years ago
|
},
|
||
3 years ago
|
methods: {
|
||
3 years ago
|
async importTemplate(template, projectType) {
|
||
|
if (this.createProject) {
|
||
2 years ago
|
this.projectCreation = true;
|
||
3 years ago
|
try {
|
||
|
const interv = setInterval(() => {
|
||
2 years ago
|
this.loaderMessagesIndex =
|
||
|
this.loaderMessagesIndex < this.loaderMessages.length - 1 ? this.loaderMessagesIndex + 1 : 6;
|
||
|
}, 1000);
|
||
3 years ago
|
|
||
2 years ago
|
const result = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
null,
|
||
|
'projectCreateByWebWithXCDB',
|
||
|
{
|
||
|
title: template.title,
|
||
|
projectType,
|
||
|
template,
|
||
|
},
|
||
|
]);
|
||
3 years ago
|
|
||
2 years ago
|
await this.$store.dispatch('project/ActLoadProjectInfo');
|
||
3 years ago
|
|
||
2 years ago
|
clearInterval(interv);
|
||
3 years ago
|
|
||
2 years ago
|
this.projectReloading = false;
|
||
3 years ago
|
|
||
2 years ago
|
if (
|
||
|
this.$store.state.project.appInfo.firstUser ||
|
||
|
this.$store.state.project.appInfo.authType === 'masterKey'
|
||
|
) {
|
||
3 years ago
|
return this.$router.push({
|
||
2 years ago
|
path: '/user/authentication/signup',
|
||
|
});
|
||
3 years ago
|
}
|
||
|
|
||
|
this.$router.push({
|
||
|
path: `/nc/${result.id}`,
|
||
|
query: {
|
||
2 years ago
|
new: 1,
|
||
|
},
|
||
|
});
|
||
3 years ago
|
} catch (e) {
|
||
2 years ago
|
this.$toast.error(e.message).goAway(3000);
|
||
3 years ago
|
}
|
||
2 years ago
|
this.projectCreation = false;
|
||
3 years ago
|
} else {
|
||
|
try {
|
||
2 years ago
|
const res = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
// todo: extract based on active
|
||
|
dbAlias: 'db', // this.nodes.dbAlias,
|
||
|
env: '_noco',
|
||
|
},
|
||
|
'xcModelsCreateFromTemplate',
|
||
|
{
|
||
|
template,
|
||
|
},
|
||
|
]);
|
||
3 years ago
|
|
||
|
if (res && res.tables && res.tables.length) {
|
||
2 years ago
|
this.$toast.success(`Imported ${res.tables.length} tables successfully`).goAway(3000);
|
||
3 years ago
|
} else {
|
||
2 years ago
|
this.$toast.success('Template imported successfully').goAway(3000);
|
||
3 years ago
|
}
|
||
2 years ago
|
this.templatesModal = false;
|
||
3 years ago
|
} catch (e) {
|
||
2 years ago
|
this.$toast.error(e.message).goAway(3000);
|
||
3 years ago
|
}
|
||
3 years ago
|
}
|
||
2 years ago
|
},
|
||
|
},
|
||
|
};
|
||
3 years ago
|
</script>
|
||
|
|
||
2 years ago
|
<style scoped></style>
|