Browse Source

fix: use meta column instead

pull/2552/head
Wing-Kam Wong 2 years ago
parent
commit
c4c1bef8c7
  1. 8
      packages/nc-gui/components/project/spreadsheet/components/SharedViewsList.vue
  2. 24
      packages/nc-gui/components/project/spreadsheet/components/SpreadsheetNavDrawer.vue
  3. 6
      packages/nc-gui/components/project/spreadsheet/public/XcTable.vue
  4. 8
      packages/nocodb/src/lib/migrations/XcMigrationSourcev2.ts
  5. 4
      packages/nocodb/src/lib/migrations/v2/nc_018_add_meta_in_view.ts
  6. 29
      packages/nocodb/src/lib/models/View.ts

8
packages/nc-gui/components/project/spreadsheet/components/SharedViewsList.vue

@ -51,8 +51,8 @@
</template>
</td>
<td class="caption text-center">
<template v-if="'download' in currentView">
<span>{{ ~~currentView.download === 1 ? '✔' : '❌' }}</span>
<template v-if="'meta' in currentView">
<span>{{ (~~(JSON.parse(currentView.meta).allowCSVDownload) === 1) ? '✔' : '❌' }}</span>
</template>
</td>
<td class="caption">
@ -94,8 +94,8 @@
</template>
</td>
<td class="caption text-center">
<template v-if="'download' in link">
<span>{{ ~~link.download === 1 ? '✔' : '❌' }}</span>
<template v-if="'meta' in link">
<span>{{ ~~((JSON.parse(link.meta)).allowCSVDownload) === 1 ? '✔' : '❌' }}</span>
</template>
</td>
<td class="caption">

24
packages/nc-gui/components/project/spreadsheet/components/SpreadsheetNavDrawer.vue

@ -443,12 +443,12 @@
</div>
<v-checkbox
v-if="selectedView && selectedView.type === viewTypes.GRID"
v-model="allowDownload"
v-model="allowCSVDownload"
class="caption"
label="Allow Download"
hide-details
dense
@change="onAllowDownloadChange"
@change="onAllowCSVDownloadChange"
/>
</v-expansion-panel-content>
</v-expansion-panel>
@ -525,7 +525,7 @@ export default {
searchQueryVal: '',
showShareLinkPassword: false,
passwordProtect: false,
allowDownload: true,
allowCSVDownload: true,
sharedViewPassword: '',
overAdvShieldIcon: false,
overShieldIcon: false,
@ -724,8 +724,8 @@ export default {
this.saveShareLinkPassword()
}
},
onAllowDownloadChange() {
this.saveAllowDownload()
onAllowCSVDownloadChange() {
this.saveAllowCSVDownload()
},
async saveShareLinkPassword() {
try {
@ -750,10 +750,12 @@ export default {
this.$e('a:view:share:enable-pwd')
},
async saveAllowDownload() {
async saveAllowCSVDownload() {
try {
const meta = JSON.parse(this.shareLink.meta)
meta.allowCSVDownload = this.allowCSVDownload
await this.$api.dbViewShare.update(this.shareLink.id, {
download: this.allowDownload
meta: JSON.stringify(meta)
})
this.$toast.success('Successfully updated').goAway(3000)
} catch (e) {
@ -761,10 +763,10 @@ export default {
.error(await this._extractSdkResponseErrorMsg(e))
.goAway(3000)
}
if (this.allowDownload) {
this.$e('a:view:share:enable-download')
if (this.allowCSVDownload) {
this.$e('a:view:share:enable-csv-download')
} else {
this.$e('a:view:share:disable-download')
this.$e('a:view:share:disable-csv-download')
}
},
async loadViews() {
@ -872,7 +874,7 @@ export default {
// todo: url
this.shareLink = shared
this.passwordProtect = shared.password !== null
this.allowDownload = shared.download
this.allowCSVDownload = JSON.parse(shared.meta).allowCSVDownload
this.showShareModel = true
},
copyView(view, i) {

6
packages/nc-gui/components/project/spreadsheet/public/XcTable.vue

@ -49,7 +49,7 @@
/>
<more-actions
v-if="allowDownload"
v-if="allowCSVDownload"
:is-view="isView"
:query-params="{...queryParams, showFields, fieldsOrder}"
:public-view-id="$route.params.id"
@ -227,7 +227,7 @@ export default {
rowContextMenu: null,
modelName: null,
tableMeta: null,
allowDownload: true,
allowCSVDownload: true,
}),
computed: {
concatenatedXWhere() {
@ -404,7 +404,7 @@ export default {
this.sorts = this.viewMeta.sorts
this.viewName = this.viewMeta.title
this.client = this.viewMeta.client
this.allowDownload = this.viewMeta.download
this.allowCSVDownload = JSON.parse(this.viewMeta.meta).allowCSVDownload
} catch (e) {
if (e.response && e.response.status === 404) {
this.notFound = true

8
packages/nocodb/src/lib/migrations/XcMigrationSourcev2.ts

@ -5,7 +5,7 @@ import * as nc_014_alter_column_data_types from './v2/nc_014_alter_column_data_t
import * as nc_015_add_meta_col_in_column_table from './v2/nc_015_add_meta_col_in_column_table';
import * as nc_016_alter_hooklog_payload_types from './v2/nc_016_alter_hooklog_payload_types';
import * as nc_017_add_user_token_version_column from './v2/nc_017_add_user_token_version_column';
import * as nc_018_add_download_in_view from './v2/nc_018_add_download_in_view';
import * as nc_018_add_meta_in_view from './v2/nc_018_add_meta_in_view';
// Create a custom migration source class
export default class XcMigrationSourcev2 {
@ -22,7 +22,7 @@ export default class XcMigrationSourcev2 {
'nc_015_add_meta_col_in_column_table',
'nc_016_alter_hooklog_payload_types',
'nc_017_add_user_token_version_column',
'nc_018_add_download_in_view',
'nc_018_add_meta_in_view',
]);
}
@ -46,8 +46,8 @@ export default class XcMigrationSourcev2 {
return nc_016_alter_hooklog_payload_types;
case 'nc_017_add_user_token_version_column':
return nc_017_add_user_token_version_column;
case 'nc_018_add_download_in_view':
return nc_018_add_download_in_view;
case 'nc_018_add_meta_in_view':
return nc_018_add_meta_in_view;
}
}
}

4
packages/nocodb/src/lib/migrations/v2/nc_018_add_download_in_view.ts → packages/nocodb/src/lib/migrations/v2/nc_018_add_meta_in_view.ts

@ -3,13 +3,13 @@ import { MetaTable } from '../../utils/globals';
const up = async (knex: Knex) => {
await knex.schema.alterTable(MetaTable.VIEWS, (table) => {
table.boolean('download').defaultTo(true);
table.text('meta');
});
};
const down = async (knex) => {
await knex.schema.alterTable(MetaTable.VIEWS, (table) => {
table.dropColumns('download');
table.dropColumns('meta');
});
};

29
packages/nocodb/src/lib/models/View.ts

@ -42,7 +42,7 @@ export default class View implements ViewType {
project_id?: string;
base_id?: string;
show_system_fields?: boolean;
download?: boolean;
meta?: string;
constructor(data: View) {
Object.assign(this, data);
@ -615,7 +615,30 @@ export default class View implements ViewType {
viewId
);
}
if (!view.meta) {
const defaultMeta = {
allowCSVDownload: true
}
// get existing cache
const key = `${CacheScope.VIEW}:${view.id}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
// update data
o.meta = JSON.stringify(defaultMeta);
// set cache
await NocoCache.set(key, o);
}
// set meta
await ncMeta.metaUpdate(
null,
null,
MetaTable.VIEWS,
{
meta: JSON.stringify(defaultMeta),
},
viewId
);
}
return view;
}
@ -685,7 +708,7 @@ export default class View implements ViewType {
'show_system_fields',
'lock_type',
'password',
'download',
'meta',
'uuid',
]);
// get existing cache

Loading…
Cancel
Save