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.
365 lines
12 KiB
365 lines
12 KiB
4 years ago
|
<template>
|
||
3 years ago
|
<v-container v-if="db" fluid>
|
||
4 years ago
|
<v-card>
|
||
|
<v-row>
|
||
3 years ago
|
<!-- <v-col cols="12">-->
|
||
|
<!-- <h4 class="text-center my-2 grey--text text--darken-2 title"> Metadata Management-->
|
||
|
<!-- </h4></v-col>-->
|
||
4 years ago
|
<v-col cols="8">
|
||
|
<v-card class="pb-2">
|
||
|
<v-toolbar flat height="50" class="toolbar-border-bottom">
|
||
3 years ago
|
<v-text-field
|
||
|
v-if="dbAliasList && db"
|
||
|
v-model="filter"
|
||
|
dense
|
||
|
hide-details
|
||
|
class="my-2 mx-auto"
|
||
|
:placeholder="`Search '${db.connection.database}' models`"
|
||
|
prepend-inner-icon="search"
|
||
3 years ago
|
style="max-width: 500px"
|
||
3 years ago
|
outlined
|
||
|
/>
|
||
4 years ago
|
|
||
3 years ago
|
<v-spacer />
|
||
|
<x-btn
|
||
|
outlined
|
||
3 years ago
|
:tooltip="$t('tooltip.reloadList')"
|
||
3 years ago
|
small
|
||
|
color="primary"
|
||
|
icon="refresh"
|
||
3 years ago
|
@click="
|
||
|
loadModels();
|
||
|
loadTableList();
|
||
|
"
|
||
3 years ago
|
>
|
||
|
Reload
|
||
4 years ago
|
</x-btn>
|
||
3 years ago
|
<x-btn
|
||
|
outlined
|
||
|
:loading="updating"
|
||
|
:disabled="updating || !edited"
|
||
3 years ago
|
:tooltip="$t('tooltip.saveChanges')"
|
||
3 years ago
|
small
|
||
|
color="primary"
|
||
|
icon="save"
|
||
|
@click="saveModels()"
|
||
|
>
|
||
3 years ago
|
<!-- Save -->
|
||
|
{{ $t('general.save') }}
|
||
4 years ago
|
</x-btn>
|
||
|
</v-toolbar>
|
||
|
|
||
|
<div class="d-flex d-100 justify-center">
|
||
3 years ago
|
<v-simple-table dense style="min-width: 400px">
|
||
4 years ago
|
<thead>
|
||
3 years ago
|
<tr>
|
||
|
<th>
|
||
3 years ago
|
Models
|
||
|
<span v-show="!isNewOrDeletedModelFound" class="caption ml-1">({{ enableCountText }})</span>
|
||
3 years ago
|
</th>
|
||
|
<th>APIs</th>
|
||
|
<th>Actions</th>
|
||
|
<th>Comment</th>
|
||
|
</tr>
|
||
4 years ago
|
</thead>
|
||
|
<tbody>
|
||
3 years ago
|
<template v-for="model in comparedModelList">
|
||
|
<tr v-if="model.title.toLowerCase().indexOf(filter.toLowerCase()) > -1" :key="model.title">
|
||
3 years ago
|
<td>{{ model.title }}</td>
|
||
|
<td>
|
||
|
<v-checkbox
|
||
|
v-model="model.enabled"
|
||
|
dense
|
||
|
:disabled="model.new || model.deleted"
|
||
|
@change="edited = true"
|
||
|
/>
|
||
|
</td>
|
||
|
<td>
|
||
|
<template v-if="model.new">
|
||
3 years ago
|
<!-- <x-icon small color="success success" tooltip="Add and sync meta information"-->
|
||
|
<!-- @click="addTableMeta([model.title])">mdi-plus-circle-outline-->
|
||
|
<!-- </x-icon>-->
|
||
3 years ago
|
</template>
|
||
|
<template v-else-if="model.deleted">
|
||
3 years ago
|
<!-- <x-icon small v-else-if="model.deleted" color="error error" tooltip="Delete meta information"-->
|
||
|
<!-- @click="deleteTableMeta([model.title])">mdi-delete-outline-->
|
||
|
<!-- </x-icon>-->
|
||
3 years ago
|
</template>
|
||
|
<x-icon
|
||
|
v-else
|
||
|
small
|
||
|
color="primary"
|
||
|
tooltip="Recreate metadata"
|
||
|
@click="recreateTableMeta(model.title)"
|
||
|
>
|
||
|
mdi-reload
|
||
|
</x-icon>
|
||
|
</td>
|
||
4 years ago
|
|
||
3 years ago
|
<td>
|
||
3 years ago
|
<span v-if="model.new" class="caption success--text"
|
||
|
>New table found in DB. Yet to be synced.</span
|
||
|
>
|
||
|
<span v-else-if="model.deleted" class="caption error--text"
|
||
|
>This table doesn't exist in DB. Yet to be synced.</span
|
||
|
>
|
||
|
<!-- <span v-else class="caption grey--text">Recreate metadata.</span>-->
|
||
3 years ago
|
</td>
|
||
|
</tr>
|
||
|
</template>
|
||
4 years ago
|
</tbody>
|
||
|
</v-simple-table>
|
||
|
</div>
|
||
|
</v-card>
|
||
|
</v-col>
|
||
3 years ago
|
<v-col cols="4" style="padding-top: 100px">
|
||
4 years ago
|
<div class="d-flex">
|
||
3 years ago
|
<v-spacer />
|
||
4 years ago
|
|
||
|
<v-tooltip bottom>
|
||
3 years ago
|
<template #activator="{ on }">
|
||
3 years ago
|
<v-alert
|
||
|
v-if="isNewOrDeletedModelFound"
|
||
|
dense
|
||
|
border="left"
|
||
|
colored-border
|
||
|
elevation="2"
|
||
|
color="warning"
|
||
|
type="warning"
|
||
|
v-on="on"
|
||
|
>
|
||
3 years ago
|
Procedures metadata <br />is out of sync
|
||
4 years ago
|
</v-alert>
|
||
3 years ago
|
<v-alert v-else dense outlined type="success" v-on="on"> Procedures metadata is in sync </v-alert>
|
||
4 years ago
|
</template>
|
||
|
<template v-if="!isNewOrDeletedModelFound">
|
||
3 years ago
|
Metadata for API creation & management is in sync with '{{ db.connection.database }}' Database.
|
||
4 years ago
|
</template>
|
||
|
<template v-else>
|
||
3 years ago
|
Metadata for API creation & management isn't sync with '{{ db.connection.database }}' Database.
|
||
4 years ago
|
</template>
|
||
|
</v-tooltip>
|
||
3 years ago
|
<v-spacer />
|
||
4 years ago
|
</div>
|
||
3 years ago
|
<div v-if="isNewOrDeletedModelFound" class="d-flex justify-center">
|
||
3 years ago
|
<x-btn x-large btn.class="mx-auto primary" tooltip="Sync metadata" @click="syncMetadata">
|
||
|
<v-icon color="white" class="mr-2 mt-n1"> mdi-database-sync </v-icon>
|
||
4 years ago
|
Sync Now
|
||
|
</x-btn>
|
||
|
</div>
|
||
|
</v-col>
|
||
|
</v-row>
|
||
|
</v-card>
|
||
|
</v-container>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import { mapGetters } from 'vuex';
|
||
|
import { isMetaTable } from '@/helpers/xutils';
|
||
4 years ago
|
|
||
|
export default {
|
||
3 years ago
|
name: 'DisableOrEnableProcedures',
|
||
|
props: ['nodes', 'db'],
|
||
4 years ago
|
data: () => ({
|
||
|
edited: false,
|
||
|
models: null,
|
||
|
updating: false,
|
||
|
dbsTab: 0,
|
||
|
filter: '',
|
||
3 years ago
|
procedures: null,
|
||
4 years ago
|
}),
|
||
3 years ago
|
async mounted() {
|
||
3 years ago
|
await this.loadModels();
|
||
|
await this.loadTableList();
|
||
4 years ago
|
},
|
||
|
methods: {
|
||
3 years ago
|
async addTableMeta(tables) {
|
||
4 years ago
|
try {
|
||
3 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
dbAlias: this.db.meta.dbAlias,
|
||
|
env: this.$store.getters['project/GtrEnv'],
|
||
|
},
|
||
|
'procedureMetaCreate',
|
||
|
{
|
||
|
tableNames: tables, // this.comparedModelList.filter(t => t.new).map(t=>t.title)
|
||
|
},
|
||
|
]);
|
||
|
setTimeout(async () => {
|
||
|
await this.loadModels();
|
||
|
this.$toast.success('Table metadata added successfully').goAway(3000);
|
||
|
}, 1000);
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error('Some error occurred').goAway(5000);
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async deleteTableMeta(tables) {
|
||
4 years ago
|
try {
|
||
3 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
dbAlias: this.db.meta.dbAlias,
|
||
|
env: this.$store.getters['project/GtrEnv'],
|
||
|
},
|
||
|
'procedureMetaDelete',
|
||
|
{
|
||
|
tableNames: tables,
|
||
|
},
|
||
|
]);
|
||
|
setTimeout(async () => {
|
||
|
await this.loadModels();
|
||
|
this.$toast.success('Table metadata deleted successfully').goAway(3000);
|
||
|
}, 1000);
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error('Some error occurred').goAway(5000);
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async syncMetadata() {
|
||
3 years ago
|
const addTables = this.comparedModelList.filter(t => t.new).map(t => t.title);
|
||
|
const deleteTables = this.comparedModelList.filter(t => t.deleted).map(t => t.title);
|
||
4 years ago
|
if (addTables.length) {
|
||
3 years ago
|
await this.addTableMeta(addTables);
|
||
4 years ago
|
}
|
||
|
if (deleteTables.length) {
|
||
3 years ago
|
await this.deleteTableMeta(deleteTables);
|
||
4 years ago
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
async recreateTableMeta(table) {
|
||
4 years ago
|
try {
|
||
3 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
dbAlias: this.db.meta.dbAlias,
|
||
|
env: this.$store.getters['project/GtrEnv'],
|
||
|
},
|
||
|
'procedureMetaRecreate',
|
||
|
{
|
||
|
tn: table,
|
||
|
},
|
||
|
]);
|
||
|
setTimeout(async () => {
|
||
|
await this.loadModels();
|
||
|
this.$toast.success('Table metadata recreated successfully').goAway(3000);
|
||
|
}, 1000);
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error('Some error occurred').goAway(5000);
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async loadModels() {
|
||
4 years ago
|
if (this.dbAliasList[this.dbsTab]) {
|
||
3 years ago
|
this.models = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
dbAlias: this.db.meta.dbAlias,
|
||
|
env: this.$store.getters['project/GtrEnv'],
|
||
|
},
|
||
|
'xcProcedureModelsList',
|
||
|
]);
|
||
|
this.edited = false;
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async loadTableList() {
|
||
3 years ago
|
this.procedures = (
|
||
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
dbAlias: this.db.meta.dbAlias,
|
||
|
env: this.$store.getters['project/GtrEnv'],
|
||
|
},
|
||
|
'procedureList',
|
||
|
])
|
||
|
).data.list;
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
async saveModels() {
|
||
3 years ago
|
this.updating = true;
|
||
4 years ago
|
try {
|
||
3 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
dbAlias: this.db.meta.dbAlias,
|
||
|
env: this.$store.getters['project/GtrEnv'],
|
||
|
},
|
||
|
'xcProcedureModelsEnable',
|
||
|
this.models.filter(m => m.enabled).map(m => m.title),
|
||
|
]);
|
||
|
this.$toast.success('Models changes are updated successfully').goAway(3000);
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error('Some error occurred').goAway(3000);
|
||
|
console.log(e.message);
|
||
4 years ago
|
}
|
||
3 years ago
|
this.updating = false;
|
||
|
this.edited = false;
|
||
|
},
|
||
4 years ago
|
},
|
||
|
computed: {
|
||
|
...mapGetters({
|
||
3 years ago
|
dbAliasList: 'project/GtrDbAliasList',
|
||
4 years ago
|
}),
|
||
3 years ago
|
enableCountText() {
|
||
3 years ago
|
return this.models ? `${this.models.filter(m => m.enabled).length}/${this.models.length} enabled` : '';
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
isNewOrDeletedModelFound() {
|
||
3 years ago
|
return this.comparedModelList.some(m => m.new || m.deleted);
|
||
4 years ago
|
},
|
||
3 years ago
|
comparedModelList() {
|
||
3 years ago
|
const res = [];
|
||
|
const getPriority = item => {
|
||
3 years ago
|
if (item.new) {
|
||
3 years ago
|
return 2;
|
||
3 years ago
|
}
|
||
|
if (item.deleted) {
|
||
3 years ago
|
return 1;
|
||
3 years ago
|
}
|
||
3 years ago
|
return 0;
|
||
|
};
|
||
4 years ago
|
if (this.procedures && this.models) {
|
||
3 years ago
|
const tables = this.procedures.filter(t => !isMetaTable(t.procedure_name)).map(t => t.procedure_name);
|
||
|
res.push(
|
||
|
...this.models.map(m => {
|
||
|
const i = tables.indexOf(m.title);
|
||
|
if (i === -1) {
|
||
|
m.deleted = true;
|
||
|
} else {
|
||
|
tables.splice(i, 1);
|
||
|
}
|
||
|
return m;
|
||
|
})
|
||
|
);
|
||
|
res.push(
|
||
|
...tables.map(t => ({
|
||
|
title: t,
|
||
|
new: true,
|
||
|
}))
|
||
|
);
|
||
4 years ago
|
}
|
||
3 years ago
|
res.sort((a, b) => getPriority(b) - getPriority(a));
|
||
|
return res;
|
||
|
},
|
||
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
3 years ago
|
<style scoped></style>
|
||
4 years ago
|
<!--
|
||
|
/**
|
||
|
* @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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|