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.
499 lines
18 KiB
499 lines
18 KiB
4 years ago
|
<template>
|
||
3 years ago
|
<v-container fluid>
|
||
3 years ago
|
<v-row class="pt-4">
|
||
|
<!-- <v-col cols="12">-->
|
||
|
<!-- <h4 class="text-center my-2 grey--text text--darken-2 title"> Metadata Management-->
|
||
|
<!-- </h4></v-col>-->
|
||
|
<v-col cols="8">
|
||
|
<v-card class="pb-2 pa">
|
||
|
<v-toolbar flat height="50" class="toolbar-border-bottom">
|
||
|
<v-text-field
|
||
|
v-if="dbAliasList && dbAliasList[dbsTab]"
|
||
|
v-model="filter"
|
||
|
dense
|
||
|
hide-details
|
||
|
class="my-2 mx-auto caption"
|
||
|
:placeholder="$t('placeholder.searchModels')"
|
||
|
prepend-inner-icon="search"
|
||
|
style="max-width: 500px"
|
||
|
outlined
|
||
|
/>
|
||
3 years ago
|
|
||
3 years ago
|
<v-spacer />
|
||
|
<x-btn
|
||
|
btn.class="nc-btn-metasync-reload"
|
||
|
outlined
|
||
|
:tooltip="$t('tooltip.reloadList')"
|
||
|
small
|
||
|
color="primary"
|
||
|
icon="refresh"
|
||
|
@click="clickReload"
|
||
|
>
|
||
|
<!-- Reload -->
|
||
|
{{ $t('general.reload') }}
|
||
|
</x-btn>
|
||
|
<!-- <x-btn
|
||
3 years ago
|
outlined
|
||
3 years ago
|
:tooltip="$t('tooltip.reloadList')"
|
||
3 years ago
|
small
|
||
|
color="primary"
|
||
|
icon="refresh"
|
||
|
@click="loadModels();loadTableList()"
|
||
|
>
|
||
3 years ago
|
{{ $t('general.reload') }}
|
||
3 years ago
|
</x-btn>-->
|
||
3 years ago
|
<!--x-btn
|
||
3 years ago
|
outlined
|
||
|
:loading="updating"
|
||
|
:disabled="updating || !edited"
|
||
3 years ago
|
:tooltip="$t('tooltip.saveChanges')"
|
||
3 years ago
|
small
|
||
|
color="primary"
|
||
|
icon="save"
|
||
|
@click="saveModels()"
|
||
|
>
|
||
|
Save
|
||
3 years ago
|
</!--x-btn-->
|
||
3 years ago
|
</v-toolbar>
|
||
4 years ago
|
|
||
3 years ago
|
<div class="d-flex d-100 justify-center">
|
||
|
<v-simple-table dense style="min-width: 400px">
|
||
|
<thead>
|
||
|
<tr>
|
||
|
<th class="grey--text">
|
||
|
<!--Models-->
|
||
|
{{ $t('labels.models') }}
|
||
|
</th>
|
||
|
<!-- <th>APIs</th>-->
|
||
|
<th class="grey--text">
|
||
|
<!--Sync state-->
|
||
|
{{ $t('labels.syncState') }}
|
||
|
</th>
|
||
|
<th />
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody>
|
||
|
<tr
|
||
|
v-for="model in diff"
|
||
|
v-show="
|
||
|
!filter.trim() ||
|
||
|
(model.table_name || model.title || '').toLowerCase().includes(filter.toLowerCase())
|
||
|
"
|
||
|
:key="model.table_name"
|
||
|
:class="`nc-metasync-row nc-metasync-row-${model.table_name}`"
|
||
|
>
|
||
|
<!-- v-if="model.alias.toLowerCase().indexOf(filter.toLowerCase()) > -1">-->
|
||
|
<td>
|
||
|
<!-- <v-icon small :color="viewIcons[model.type==='table'?'grid':'view'].color" v-on="on">
|
||
3 years ago
|
{{ viewIcons[model.type === 'table' ? 'grid' : 'view'].icon }}
|
||
3 years ago
|
</v-icon>-->
|
||
3 years ago
|
<v-tooltip bottom>
|
||
|
<template #activator="{ on }">
|
||
|
<span v-on="on">{{ model.table_name && model.table_name.slice(prefix.length) }}</span>
|
||
|
</template>
|
||
|
<span class="caption">{{ model.title }}</span>
|
||
|
</v-tooltip>
|
||
|
</td>
|
||
|
<!-- <td>
|
||
3 years ago
|
<v-checkbox
|
||
|
v-model="model.enabled"
|
||
|
dense
|
||
|
:disabled="model.new || model.deleted"
|
||
|
@change="edited = true"
|
||
|
/>
|
||
|
</td>-->
|
||
3 years ago
|
<!--td>
|
||
3 years ago
|
<x-icon
|
||
|
small
|
||
|
color="primary"
|
||
|
tooltip="Recreate metadata"
|
||
|
>
|
||
|
mdi-reload
|
||
|
</x-icon>
|
||
|
</!--td-->
|
||
3 years ago
|
|
||
3 years ago
|
<td>
|
||
|
<span v-if="model.detectedChanges && model.detectedChanges.length" class="caption error--text">{{
|
||
|
model.detectedChanges.map(m => m.msg).join(', ')
|
||
|
}}</span>
|
||
|
<span v-else class="caption grey--text">
|
||
|
<!--{{ 'No change identified' }}-->
|
||
|
{{ $t('msg.info.metaNoChange') }}
|
||
|
</span>
|
||
|
<!-- <span v-else class="caption grey--text">Recreate metadata.</span>-->
|
||
|
</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</v-simple-table>
|
||
|
<!-- </div> <div class="d-flex d-100 justify-center">
|
||
3 years ago
|
<v-simple-table dense style="min-width: 400px">
|
||
|
<thead>
|
||
|
<tr>
|
||
|
<th class="grey--text">
|
||
3 years ago
|
Models <span v-show="!isNewOrDeletedModelFound" class="caption ml-1">({{
|
||
|
enableCountText
|
||
|
}})</span>
|
||
|
</th>
|
||
3 years ago
|
<!– <th>APIs</th>–>
|
||
|
<th class="grey--text">
|
||
3 years ago
|
Actions
|
||
|
</th>
|
||
|
<th />
|
||
3 years ago
|
</tr>
|
||
4 years ago
|
</thead>
|
||
|
<tbody>
|
||
3 years ago
|
<tr v-for="model in comparedModelList" :key="model.title">
|
||
3 years ago
|
<!– v-if="model.alias.toLowerCase().indexOf(filter.toLowerCase()) > -1">–>
|
||
3 years ago
|
<td>
|
||
|
<v-tooltip bottom>
|
||
|
<template #activator="{on}">
|
||
|
<span v-on="on">{{ model.alias }}</span>
|
||
|
</template>
|
||
|
<span class="caption">{{ model.title }}</span>
|
||
|
</v-tooltip>
|
||
|
</td>
|
||
3 years ago
|
<!– <td>
|
||
|
<v-checkbox
|
||
|
v-model="model.enabled"
|
||
|
dense
|
||
|
:disabled="model.new || model.deleted"
|
||
|
@change="edited = true"
|
||
|
/>
|
||
|
</td>–>
|
||
3 years ago
|
<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>
|
||
|
<span
|
||
|
v-if="model.new"
|
||
3 years ago
|
class="caption success--text"
|
||
3 years ago
|
>New table found in DB. Yet to be synced.</span>
|
||
3 years ago
|
<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>
|
||
4 years ago
|
</tbody>
|
||
|
</v-simple-table>
|
||
3 years ago
|
</div>-->
|
||
3 years ago
|
</div>
|
||
|
</v-card>
|
||
|
</v-col>
|
||
|
<v-col cols="4" style="padding-top: 100px">
|
||
|
<div class="d-flex">
|
||
|
<v-spacer />
|
||
4 years ago
|
|
||
3 years ago
|
<!-- <v-tooltip bottom>-->
|
||
|
<!-- 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"
|
||
|
>
|
||
|
Tables 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"
|
||
|
>
|
||
|
Tables metadata is in sync
|
||
4 years ago
|
</v-alert>
|
||
|
</template>
|
||
|
<template v-if="!isNewOrDeletedModelFound">
|
||
|
Metadata for API creation & management is in sync with
|
||
|
'{{ dbAliasList[dbsTab].connection.database }}' Database.
|
||
|
</template>
|
||
3 years ago
|
<template-- v-else>
|
||
4 years ago
|
Metadata for API creation & management isn't sync with
|
||
|
'{{ dbAliasList[dbsTab].connection.database }}' Database.
|
||
3 years ago
|
</template-->
|
||
3 years ago
|
<!-- </v-tooltip>-->
|
||
|
<v-spacer />
|
||
|
</div>
|
||
|
<!-- <div-->
|
||
|
<!-- v-if="isNewOrDeletedModelFound" -->
|
||
|
<div class="d-flex justify-center">
|
||
|
<v-btn
|
||
|
v-if="isChanged"
|
||
|
v-t="['a:proj-meta:meta-data:sync']"
|
||
|
x-large
|
||
|
class="mx-auto primary nc-btn-metasync-sync-now"
|
||
|
@click="syncMetaDiff"
|
||
|
>
|
||
|
<v-icon color="white" class="mr-2 mt-n1"> mdi-database-sync </v-icon>
|
||
|
Sync Now
|
||
|
</v-btn>
|
||
3 years ago
|
|
||
3 years ago
|
<v-alert v-else dense outlined type="success"> Tables metadata is in sync </v-alert>
|
||
|
</div>
|
||
|
</v-col>
|
||
|
</v-row>
|
||
|
</v-container>
|
||
4 years ago
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import { mapGetters } from 'vuex';
|
||
|
import viewIcons from '~/helpers/viewIcons';
|
||
4 years ago
|
|
||
|
export default {
|
||
3 years ago
|
name: 'DisableOrEnableTables',
|
||
|
props: ['nodes', 'db'],
|
||
4 years ago
|
data: () => ({
|
||
3 years ago
|
viewIcons,
|
||
4 years ago
|
edited: false,
|
||
|
models: null,
|
||
|
updating: false,
|
||
|
dbsTab: 0,
|
||
3 years ago
|
filter: '',
|
||
3 years ago
|
tables: null,
|
||
3 years ago
|
diff: null,
|
||
4 years ago
|
}),
|
||
3 years ago
|
async mounted() {
|
||
3 years ago
|
await this.loadXcDiff();
|
||
3 years ago
|
// await this.loadMode// await this.loadTableList()
|
||
4 years ago
|
},
|
||
|
methods: {
|
||
3 years ago
|
async loadXcDiff() {
|
||
3 years ago
|
this.diff = await this.$api.project.metaDiffGet(this.$store.state.project.projectId, this.db.id);
|
||
3 years ago
|
|
||
|
// this.diff = await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||
|
// dbAlias: this.db.meta.dbAlias,
|
||
|
// env: this.$store.getters['project/GtrEnv']
|
||
|
// }, 'xcMetaDiff'])
|
||
|
},
|
||
|
clickReload() {
|
||
3 years ago
|
this.loadXcDiff();
|
||
3 years ago
|
this.$e('a:proj-meta:meta-data:reload');
|
||
3 years ago
|
},
|
||
3 years ago
|
/* async addTableMeta(tables) {
|
||
4 years ago
|
try {
|
||
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||
|
dbAlias: this.db.meta.dbAlias,
|
||
|
env: this.$store.getters['project/GtrEnv']
|
||
|
}, 'tableMetaCreate', {
|
||
3 years ago
|
tableNames: tables// this.comparedModelList.filter(t => t.new).map(t=>t.title)
|
||
|
}])
|
||
3 years ago
|
setTimeout(async() => {
|
||
4 years ago
|
await this.loadModels()
|
||
3 years ago
|
this.$toast.success('Table metadata added successfully').goAway(3000)
|
||
|
}, 1000)
|
||
4 years ago
|
} catch (e) {
|
||
|
this.$toast.error('Some error occurred').goAway(5000)
|
||
|
}
|
||
|
},
|
||
3 years ago
|
async deleteTableMeta(tables) {
|
||
4 years ago
|
try {
|
||
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||
|
dbAlias: this.db.meta.dbAlias,
|
||
|
env: this.$store.getters['project/GtrEnv']
|
||
|
}, 'tableMetaDelete', {
|
||
|
tableNames: tables
|
||
3 years ago
|
}])
|
||
3 years ago
|
setTimeout(async() => {
|
||
4 years ago
|
await this.loadModels()
|
||
3 years ago
|
this.$toast.success('Table metadata deleted successfully').goAway(3000)
|
||
|
}, 1000)
|
||
4 years ago
|
} catch (e) {
|
||
|
this.$toast.error('Some error occurred').goAway(5000)
|
||
|
}
|
||
|
},
|
||
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
|
*/
|
||
3 years ago
|
async syncMetaDiff() {
|
||
|
try {
|
||
3 years ago
|
await this.$api.project.metaDiffSync(this.$store.state.project.projectId, this.db.id);
|
||
3 years ago
|
// await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||
|
// dbAlias: this.db.meta.dbAlias,
|
||
|
// env: this.$store.getters['project/GtrEnv']
|
||
|
// }, 'xcMetaDiffSync', {}])
|
||
3 years ago
|
this.$toast.success('Table metadata recreated successfully').goAway(3000);
|
||
3 years ago
|
await this.loadXcDiff();
|
||
3 years ago
|
|
||
3 years ago
|
this.$store.commit('tabs/removeTableOrViewTabs');
|
||
3 years ago
|
await this.$nextTick();
|
||
3 years ago
|
await this.$store.dispatch('project/_loadTables', {
|
||
|
dbKey: '0.projectJson.envs._noco.db.0',
|
||
|
key: '0.projectJson.envs._noco.db.0.tables',
|
||
3 years ago
|
_nodes: {
|
||
3 years ago
|
dbAlias: 'db',
|
||
|
env: '_noco',
|
||
|
type: 'tableDir',
|
||
3 years ago
|
},
|
||
|
});
|
||
3 years ago
|
await this.$store.commit('meta/MutClear');
|
||
3 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast[e.response?.status === 402 ? 'info' : 'error'](e.message).goAway(3000);
|
||
3 years ago
|
}
|
||
3 years ago
|
},
|
||
3 years ago
|
|
||
3 years ago
|
/* async recreateTableMeta(table) {
|
||
|
try {
|
||
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||
|
dbAlias: this.db.meta.dbAlias,
|
||
|
env: this.$store.getters['project/GtrEnv']
|
||
|
}, 'tableMetaRecreate', {
|
||
|
tn: table
|
||
|
}])
|
||
|
setTimeout(async() => {
|
||
|
await this.loadModels()
|
||
|
this.$toast.success('Table metadata recreated successfully').goAway(3000)
|
||
|
}, 1000)
|
||
|
} catch (e) {
|
||
|
this.$toast[e.response?.status === 402 ? 'info' : 'error'](e.message).goAway(3000)
|
||
|
}
|
||
|
},
|
||
|
async loadModels() {
|
||
|
if (this.dbAliasList[this.dbsTab]) {
|
||
|
this.models = await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||
|
dbAlias: this.db.meta.dbAlias,
|
||
|
env: this.$store.getters['project/GtrEnv']
|
||
|
}, 'xcTableModelsList'])
|
||
|
this.edited = false
|
||
|
}
|
||
|
},
|
||
|
async loadTableList() {
|
||
|
this.tables = (await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||
4 years ago
|
dbAlias: this.db.meta.dbAlias,
|
||
|
env: this.$store.getters['project/GtrEnv']
|
||
3 years ago
|
}, 'tableList', { force: true, includeM2M: true }])).data.list
|
||
|
},
|
||
4 years ago
|
|
||
3 years ago
|
async saveModels() {
|
||
|
this.updating = true
|
||
|
try {
|
||
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||
|
dbAlias: this.db.meta.dbAlias,
|
||
|
env: this.$store.getters['project/GtrEnv']
|
||
|
}, 'xcTableModelsEnable', this.models.filter(m => m.enabled).map(m => m.title)])
|
||
|
this.$toast.success('Models changes are updated successfully').goAway(3000)
|
||
|
} catch (e) {
|
||
|
this.$toast[e.response?.status === 402 ? 'info' : 'error'](e.message).goAway(3000)
|
||
|
console.log(e.message)
|
||
|
}
|
||
|
this.updating = false
|
||
|
this.edited = false
|
||
|
} */
|
||
4 years ago
|
},
|
||
|
computed: {
|
||
|
...mapGetters({
|
||
3 years ago
|
dbAliasList: 'project/GtrDbAliasList',
|
||
3 years ago
|
}),
|
||
3 years ago
|
isChanged() {
|
||
3 years ago
|
return this.diff && this.diff.some(d => d && d.detectedChanges && d.detectedChanges.length);
|
||
3 years ago
|
},
|
||
3 years ago
|
prefix() {
|
||
3 years ago
|
return this.$store.getters['project/GtrProjectPrefix'] || '';
|
||
3 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() {
|
||
4 years ago
|
return this.comparedModelList.some(m => m.new || m.deleted)
|
||
|
},
|
||
3 years ago
|
comparedModelList() {
|
||
3 years ago
|
const res = []
|
||
4 years ago
|
const getPriority = (item) => {
|
||
3 years ago
|
if (item.new) {
|
||
|
return 2
|
||
|
}
|
||
|
if (item.deleted) {
|
||
|
return 1
|
||
|
}
|
||
3 years ago
|
return 0
|
||
4 years ago
|
}
|
||
|
if (this.tables && this.models) {
|
||
3 years ago
|
const tables = this.tables.filter(t => !isMetaTable(t.table_name)).map(t => t.table_name)
|
||
3 years ago
|
res.push(...this.models.map((m) => {
|
||
|
const i = tables.indexOf(m.title)
|
||
4 years ago
|
if (i === -1) {
|
||
3 years ago
|
m.deleted = true
|
||
4 years ago
|
} else {
|
||
3 years ago
|
tables.splice(i, 1)
|
||
4 years ago
|
}
|
||
3 years ago
|
return m
|
||
|
}))
|
||
4 years ago
|
res.push(...tables.map(t => ({
|
||
|
title: t, new: true, alias: t
|
||
|
})))
|
||
|
}
|
||
|
res.sort((a, b) => getPriority(b) - getPriority(a))
|
||
3 years ago
|
return res
|
||
3 years ago
|
} */
|
||
3 years ago
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
|
<style scoped lang="scss">
|
||
|
::v-deep {
|
||
|
.v-tabs-bar {
|
||
|
border-bottom: solid 1px #7f828b33;
|
||
|
}
|
||
|
|
||
|
.v-tab {
|
||
|
border-right: 1px solid #7f828b33;
|
||
|
}
|
||
|
}
|
||
|
</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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|