Browse Source

fix: table missing from table list

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/872/head
Pranav C 3 years ago
parent
commit
8e52fa01a1
  1. 3
      packages/nc-gui/components/ProjectTreeView.vue
  2. 14
      packages/nc-gui/components/project/projectMetadata/disableOrEnableModels.vue
  3. 4
      packages/nc-gui/store/tabs.js
  4. 1
      packages/nocodb/package.json
  5. 56
      packages/nocodb/src/example/dockerRunMysql.ts
  6. 2
      packages/nocodb/src/lib/noco/Noco.ts
  7. 4
      packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts
  8. 6
      packages/nocodb/src/lib/noco/common/XcMigrationSource.ts
  9. 29
      packages/nocodb/src/lib/noco/common/jobs/ncParentModelTitleUpgrader.ts
  10. 41
      packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts
  11. 4
      packages/nocodb/src/lib/noco/meta/NcMetaMgrEE.ts
  12. 38
      packages/nocodb/src/lib/noco/migrations/nc_010_add_parent_title_column.ts

3
packages/nc-gui/components/ProjectTreeView.vue

@ -1222,6 +1222,9 @@ export default {
this.dialogGetFunctionName.dialogShow = true;
} else if (action === 'ENV_DB_FUNCTIONS_CREATE') {
this.dialogGetFunctionName.dialogShow = true;
} else if (action === "ENV_DB_TABLES_REFRESH") {
await this.loadTables(this.menuItem);
this.$toast.success('Tables refreshed').goAway(1000);
}else if (action === 'ENV_DB_VIEWS_REFRESH') {
await this.loadViews(this.menuItem);
this.$toast.success('Views refreshed').goAway(1000);

14
packages/nc-gui/components/project/projectMetadata/disableOrEnableModels.vue

@ -1,11 +1,11 @@
<template>
<div>
<v-tabs v-model="dbsTab" color="x-active" height="30">
<v-tab href="#xc-project-meta">
<v-tab href="#xc-project-meta" @dblclick="uiacl = true">
<v-icon icon x-small class="mr-2">
mdi-file-table-box-multiple-outline
</v-icon>
<span class="caption text-capitalize"> Project Metadata</span>
<span class="caption text-capitalize"> Export/Import Metadata</span>
</v-tab>
<v-tab-item value="xc-project-meta">
<div class="d-flex justify-center d-100">
@ -15,7 +15,8 @@
<template v-for="(db,i) in dbAliasList">
<v-tab :key="db.meta.dbAlias + i" :href="'#' + db.meta.dbAlias" class="text-capitalize caption">
{{ db.connection.database | extractDbName }} {{ db.meta.dbAlias }} Metadata
<!-- {{ db.connection.database | extractDbName }} {{ db.meta.dbAlias }} -->
Metadata
</v-tab>
<v-tab-item :key="db.meta.dbAlias + 't' + i" :value=" db.meta.dbAlias">
<v-tabs color="x-active" height="28">
@ -59,9 +60,10 @@
</v-tab-item>
</v-tabs>
</v-tab-item>
<template v-if="uiacl">
<v-tab :key="db.meta.dbAlias + 'acl'" :href="'#' + db.meta.dbAlias + 'acl'" class="text-capitalize caption nc-ui-acl-tab">
{{ db.connection.database | extractDbName }} UI Access Control
<!-- {{ db.connection.database | extractDbName }}-->
UI Access Control
</v-tab>
<v-tab-item :key="db.meta.dbAlias + 'aclt'" :value=" db.meta.dbAlias + 'acl'">
<v-tabs color="x-active" height="28">
@ -106,6 +108,7 @@
</v-tabs>
</v-tab-item>
</template>
</template>
</v-tabs>
</div>
</template>
@ -132,6 +135,7 @@ export default {
},
props: ['nodes'],
data: () => ({
uiacl: false,
edited: false,
models: null,
updating: false,

4
packages/nc-gui/store/tabs.js

@ -119,7 +119,7 @@ export const actions = {
type: 'tableDir'
}
}, { root: true })
await dispatch('project/_loadViews', {
/* await dispatch('project/_loadViews', {
dbKey: '0.projectJson.envs._noco.db.0',
key: '0.projectJson.envs._noco.db.0.views',
_nodes: {
@ -129,7 +129,7 @@ export const actions = {
// key: "0.projectJson.envs._noco.db.0.tables",
type: 'viewDir'
}
}, { root: true })
}, { root: true }) */
switch (type) {
case 'table':

1
packages/nocodb/package.json

@ -68,6 +68,7 @@
"watch:build": "nodemon -e ts,js -w ./src -x npm run build",
"watch:serve": "nodemon -e ts -w ./build -x npm run debug-local ",
"watch:run": "cross-env EE=true nodemon -e ts,js -w ./src -x \"ts-node src/example/docker --log-error --project tsconfig.json\"",
"watch:run:mysql": "cross-env EE=true nodemon -e ts,js -w ./src -x \"ts-node src/example/dockerRunMysql --log-error --project tsconfig.json\"",
"run": "ts-node src/example/docker",
"watch:try": "nodemon -e ts,js -w ./src -x \"ts-node src/example/try --log-error --project tsconfig.json\"",
"example:docker": "ts-node ./src/example/docker.ts"

56
packages/nocodb/src/example/dockerRunMysql.ts

@ -0,0 +1,56 @@
import cors from 'cors';
import express from 'express';
import Noco from '../lib/noco/Noco';
process.env.NC_VERSION = '0009044';
const server = express();
server.use(
cors({
exposedHeaders: 'xc-db-response'
})
);
server.set('view engine', 'ejs');
const date = new Date();
process.env[
`NC_DB`
] = `mysql2://localhost:3306?u=root&p=password&d=meta_${date.getFullYear()}_${date.getMonth() +
1}_${date.getDate()}`;
// process.env[`NC_DB`] = `pg://localhost:3306?u=root&p=password&d=mar_24`;
// process.env[`NC_DB`] = `pg://localhost:5432?u=postgres&p=password&d=abcde`;
// process.env[`NC_TRY`] = 'true';
// process.env[`NC_DASHBOARD_URL`] = '/test';
process.env[`DEBUG`] = 'xc*';
(async () => {
server.use(await Noco.init({}));
server.listen(process.env.PORT || 8080, () => {
console.log(`App started successfully.\nVisit -> ${Noco.dashboardUrl}`);
});
})().catch(e => console.log(e));
/**
* @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/>.
*
*/

2
packages/nocodb/src/lib/noco/Noco.ts

@ -90,7 +90,7 @@ export default class Noco {
constructor() {
process.env.PORT = process.env.PORT || '8080';
// todo: move
process.env.NC_VERSION = '0083006';
process.env.NC_VERSION = '0083007';
this.router = express.Router();
this.projectRouter = express.Router();

4
packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts

@ -29,6 +29,7 @@ import NcConnectionMgr from './NcConnectionMgr';
import updateColumnNameInFormula from './helpers/updateColumnNameInFormula';
import addErrorOnColumnDeleteInFormula from './helpers/addErrorOnColumnDeleteInFormula';
import ncModelsOrderUpgrader from './jobs/ncModelsOrderUpgrader';
import ncParentModelTitleUpgrader from './jobs/ncParentModelTitleUpgrader';
const log = debug('nc:api:base');
@ -1268,7 +1269,8 @@ export default abstract class BaseApiBuilder<T extends Noco>
const NC_VERSIONS = [
{ name: '0009000', handler: null },
{ name: '0009044', handler: this.ncUpManyToMany.bind(this) },
{ name: '0083006', handler: ncModelsOrderUpgrader }
{ name: '0083006', handler: ncModelsOrderUpgrader },
{ name: '0083007', handler: ncParentModelTitleUpgrader }
];
if (!(await this.xcMeta?.knex?.schema?.hasTable?.('nc_store'))) {
return;

6
packages/nocodb/src/lib/noco/common/XcMigrationSource.ts

@ -7,6 +7,7 @@ import * as nc_006_alter_nc_shared_views from '../migrations/nc_006_alter_nc_sha
import * as nc_007_alter_nc_shared_views_1 from '../migrations/nc_007_alter_nc_shared_views_1';
import * as nc_008_add_nc_shared_bases from '../migrations/nc_008_add_nc_shared_bases';
import * as nc_009_add_model_order from '../migrations/nc_009_add_model_order';
import * as nc_010_add_parent_title_column from '../migrations/nc_010_add_parent_title_column';
// Create a custom migration source class
export default class XcMigrationSource {
@ -24,7 +25,8 @@ export default class XcMigrationSource {
'nc_006_alter_nc_shared_views',
'nc_007_alter_nc_shared_views_1',
'nc_008_add_nc_shared_bases',
'nc_009_add_model_order'
'nc_009_add_model_order',
'nc_010_add_parent_title_column'
]);
}
@ -52,6 +54,8 @@ export default class XcMigrationSource {
return nc_008_add_nc_shared_bases;
case 'nc_009_add_model_order':
return nc_009_add_model_order;
case 'nc_010_add_parent_title_column':
return nc_010_add_parent_title_column;
}
}
}

29
packages/nocodb/src/lib/noco/common/jobs/ncParentModelTitleUpgrader.ts

@ -0,0 +1,29 @@
import { NcBuilderUpgraderCtx } from '../BaseApiBuilder';
export default async function(ctx: NcBuilderUpgraderCtx) {
const views = await ctx.xcMeta.metaList(
ctx.projectId,
ctx.dbAlias,
'nc_models',
{
condition: {
type: 'vtable'
}
}
);
for (const view of views) {
await ctx.xcMeta.metaUpdate(
ctx.projectId,
ctx.dbAlias,
'nc_disabled_models_for_role',
{
parent_model_title: view.parent_model_title
},
{
type: 'vtable',
title: view.title
}
);
}
}

41
packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

@ -4873,6 +4873,10 @@ export default class NcMetaMgr {
);
for (const d of disabledList) {
if (
!result[d.title].ptn ||
result[d.title].ptn === d.parent_model_title
)
result[d.title].disabled[d.role] = !!d.disabled;
}
@ -4900,6 +4904,9 @@ export default class NcMetaMgr {
},
{
type: { eq: 'view' }
},
{
type: { eq: 'vtable' }
}
]
},
@ -4910,6 +4917,7 @@ export default class NcMetaMgr {
);
const result = models.reduce((obj, table) => {
if (table.type !== 'vtable')
obj[table.title] = {
tn: table.title,
_tn: table.alias || table.title,
@ -4922,6 +4930,17 @@ export default class NcMetaMgr {
return obj;
}, {});
// @ts-ignore
const viewsObj = models.reduce((obj, tableView) => {
obj[tableView.parent_model_title || tableView.title] =
obj[tableView.parent_model_title || tableView.title] || {};
obj[tableView.parent_model_title || tableView.title][
tableView.title
] = { ...defaultDisabled };
return obj;
}, {});
// @ts-ignore
const disabledList = await this.xcMeta.metaList(
args.project_id,
this.getDbAlias(args),
@ -4934,6 +4953,9 @@ export default class NcMetaMgr {
},
{
type: { eq: 'view' }
},
{
type: { eq: 'vtable' }
}
]
}
@ -4941,9 +4963,25 @@ export default class NcMetaMgr {
);
for (const d of disabledList) {
result[d.title].disabled[d.role] = !!d.disabled;
if (d.type === 'vtable') {
if (viewsObj?.[d.parent_model_title]?.[d.title])
viewsObj[d.parent_model_title][d.title][d.role] = d.disabled;
} else {
if (viewsObj?.[d.title]?.[d.title])
viewsObj[d.title][d.title][d.role] = d.disabled;
}
}
for (const [title, aclObj] of Object.entries(viewsObj)) {
for (const role in result[title].disabled) {
result[title].disabled[role] = Object.values(aclObj).every(
v => v[role]
);
}
}
// result[d.title].disabled[d.role] = !!d.disabled;
return Object.values(result);
}
break;
@ -5303,7 +5341,6 @@ export default class NcMetaMgr {
protected async xcTableAndViewList(req, args): Promise<any> {
const roles = req.session?.passport?.user?.roles;
let tables = await this.xcVisibilityMetaGet({
...args,
args: { type: 'table_view', ...args.args }

4
packages/nocodb/src/lib/noco/meta/NcMetaMgrEE.ts

@ -411,6 +411,7 @@ export default class NcMetaMgrEE extends NcMetaMgr {
type: d.type,
title: d[field],
role,
parent_model_title: d.ptn,
...props
}
);
@ -425,6 +426,7 @@ export default class NcMetaMgrEE extends NcMetaMgr {
disabled: d.disabled[role]
},
{
parent_model_title: d.ptn,
type: d.type,
title: d[field],
role,
@ -438,6 +440,7 @@ export default class NcMetaMgrEE extends NcMetaMgr {
this.getDbAlias(args),
'nc_disabled_models_for_role',
{
parent_model_title: d.ptn,
type: d.type,
title: d[field],
role,
@ -451,6 +454,7 @@ export default class NcMetaMgrEE extends NcMetaMgr {
this.getDbAlias(args),
'nc_disabled_models_for_role',
{
parent_model_title: d.ptn,
disabled: d.disabled[role],
type: d.type,
title: d[field],

38
packages/nocodb/src/lib/noco/migrations/nc_010_add_parent_title_column.ts

@ -0,0 +1,38 @@
import Knex from 'knex';
const up = async (knex: Knex) => {
await knex.schema.alterTable('nc_disabled_models_for_role', table => {
table.string('parent_model_title');
});
};
const down = async knex => {
await knex.schema.alterTable('nc_disabled_models_for_role', table => {
table.dropColumn('parent_model_title');
});
};
export { up, down };
/**
* @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/>.
*
*/
Loading…
Cancel
Save