Browse Source

feat: make view name unique, add view_name in shared view table

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/642/head
Pranav C 3 years ago
parent
commit
fca74cab57
  1. 3
      packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue
  2. 5
      packages/nc-gui/components/project/spreadsheet/dialog/createViewDialog.vue
  3. 5
      packages/nocodb/src/lib/noco/common/XcMigrationSource.ts
  4. 1
      packages/nocodb/src/lib/noco/meta/NcMetaMgrEE.ts
  5. 38
      packages/nocodb/src/lib/noco/migrations/nc_005_add_view_name_column.ts

3
packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue

@ -420,6 +420,7 @@
:meta="meta"
:copy-view="copyViewRef"
:alias="meta._tn"
:views-list="viewsList"
@created="onViewCreate"
/>
@ -717,6 +718,7 @@ export default {
parent_model_title: this.meta._tn
})
this.$toast.success('View renamed successfully').goAway(3000)
this.$set(view, 'edit', false)
} catch (e) {
this.$toast.error(e.message).goAway(3000)
}
@ -762,6 +764,7 @@ export default {
extraViewParams: this.extraViewParams,
selectedViewId: this.selectedViewId
},
view_name: this.selectedView.title,
type: this.selectedView.type,
show_as: this.selectedView.show_as,
password: this.sharedViewPassword

5
packages/nc-gui/components/project/spreadsheet/dialog/createViewDialog.vue

@ -11,7 +11,7 @@
ref="name"
v-model="view_name"
label="View Name"
:rules="[v=>!!v || 'View name required']"
:rules="[v=>!!v || 'View name required', v => viewsList.every((v1) => (v1.alias || v1.title) !== v) || 'View name should be unique']"
autofocus
/>
</v-form>
@ -39,7 +39,7 @@
export default {
name: 'CreateViewDialog',
props: ['value', 'nodes', 'table', 'alias', 'show_as', 'viewsCount', 'primaryValueColumn', 'meta', 'copyView'],
props: ['value', 'nodes', 'table', 'alias', 'show_as', 'viewsCount', 'primaryValueColumn', 'meta', 'copyView', 'viewsList'],
data: () => ({
valid: false,
view_name: '',
@ -74,6 +74,7 @@ export default {
},
methods: {
async createView() {
if (!this.valid) { return }
let showFields = null
let attachmentCol
if (this.show_as === 'gallery') {

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

@ -2,6 +2,7 @@ import * as project from '../migrations/nc_001_init';
import * as m2m from '../migrations/nc_002_add_m2m';
import * as fkn from '../migrations/nc_003_add_fkn_column';
import * as viewType from '../migrations/nc_004_add_view_type_column';
import * as viewName from '../migrations/nc_005_add_view_name_column';
// Create a custom migration source class
export default class XcMigrationSource {
@ -10,7 +11,7 @@ export default class XcMigrationSource {
// arguments to getMigrationName and getMigration
public getMigrations(): Promise<any> {
// In this example we are just returning migration names
return Promise.resolve(['project', 'm2m', 'fkn', 'viewType']);
return Promise.resolve(['project', 'm2m', 'fkn', 'viewType', 'viewName']);
}
public getMigrationName(migration): string {
@ -27,6 +28,8 @@ export default class XcMigrationSource {
return fkn;
case 'viewType':
return viewType;
case 'viewName':
return viewName;
}
}
}

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

@ -184,6 +184,7 @@ export default class NcMetaMgrEE extends NcMetaMgr {
project_id: args.project_id,
db_alias: this.getDbAlias(args),
model_name: args.args.model_name,
view_name: args.args.view_name,
meta: JSON.stringify(args.args.meta),
query_params: JSON.stringify(args.args.query_params),
view_id: uuidv4(),

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

@ -0,0 +1,38 @@
import Knex from 'knex';
const up = async (knex: Knex) => {
await knex.schema.alterTable('nc_shared_views', table => {
table.integer('view_name');
});
};
const down = async knex => {
await knex.schema.alterTable('nc_shared_views', table => {
table.dropColumns('view_name');
});
};
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