Browse Source

fix: revise logic based on PR comments

pull/2552/head
Wing-Kam Wong 2 years ago
parent
commit
17eef6e31f
  1. 12
      packages/nc-gui/components/project/spreadsheet/components/SharedViewsList.vue
  2. 11
      packages/nc-gui/components/project/spreadsheet/components/SpreadsheetNavDrawer.vue
  3. 11
      packages/nocodb/src/lib/models/View.ts

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

@ -52,7 +52,7 @@
</td> </td>
<td class="caption text-center"> <td class="caption text-center">
<template v-if="'meta' in currentView"> <template v-if="'meta' in currentView">
<span>{{ ~~JSON.parse(currentView.meta).allowCSVDownload === 1 ? '✔' : '❌' }}</span> <span>{{ renderAllowCSVDownload(currentView) }}</span>
</template> </template>
</td> </td>
<td class="caption"> <td class="caption">
@ -91,7 +91,7 @@
</td> </td>
<td class="caption text-center"> <td class="caption text-center">
<template v-if="'meta' in link"> <template v-if="'meta' in link">
<span>{{ ~~JSON.parse(link.meta).allowCSVDownload === 1 ? '✔' : '❌' }}</span> <span>{{ renderAllowCSVDownload(link) }}</span>
</template> </template>
</td> </td>
<td class="caption"> <td class="caption">
@ -187,6 +187,14 @@ export default {
} }
return `/nc/${viewType}/${view.uuid}`; return `/nc/${viewType}/${view.uuid}`;
}, },
renderAllowCSVDownload(view) {
if (view.type === ViewTypes.GRID) {
view.meta = view.meta && typeof view.meta === 'string' ? JSON.parse(view.meta) : view.meta;
return view.meta.allowCSVDownload ? '✔' : '❌';
} else {
return 'N/A';
}
},
}, },
}; };
</script> </script>

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

@ -658,10 +658,14 @@ export default {
}, },
async saveAllowCSVDownload() { async saveAllowCSVDownload() {
try { try {
const meta = JSON.parse(this.shareLink.meta); const meta =
this.shareLink.meta && typeof this.shareLink.meta === 'string'
? JSON.parse(this.shareLink.meta)
: this.shareLink.meta;
meta.allowCSVDownload = this.allowCSVDownload; meta.allowCSVDownload = this.allowCSVDownload;
await this.$api.dbViewShare.update(this.shareLink.id, { await this.$api.dbViewShare.update(this.shareLink.id, {
meta: JSON.stringify(meta), meta,
}); });
this.$toast.success('Successfully updated').goAway(3000); this.$toast.success('Successfully updated').goAway(3000);
} catch (e) { } catch (e) {
@ -767,10 +771,11 @@ export default {
}, },
async genShareLink() { async genShareLink() {
const shared = await this.$api.dbViewShare.create(this.selectedViewId); const shared = await this.$api.dbViewShare.create(this.selectedViewId);
shared.meta = shared.meta && typeof shared.meta === 'string' ? JSON.parse(shared.meta) : shared.meta;
// todo: url // todo: url
this.shareLink = shared; this.shareLink = shared;
this.passwordProtect = shared.password !== null; this.passwordProtect = shared.password !== null;
this.allowCSVDownload = JSON.parse(shared.meta).allowCSVDownload; this.allowCSVDownload = shared.meta.allowCSVDownload;
this.showShareModel = true; this.showShareModel = true;
}, },
copyView(view, i) { copyView(view, i) {

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

@ -42,7 +42,7 @@ export default class View implements ViewType {
project_id?: string; project_id?: string;
base_id?: string; base_id?: string;
show_system_fields?: boolean; show_system_fields?: boolean;
meta?: string; meta?: any;
constructor(data: View) { constructor(data: View) {
Object.assign(this, data); Object.assign(this, data);
@ -638,7 +638,7 @@ export default class View implements ViewType {
}, },
viewId viewId
); );
view.meta = JSON.stringify(defaultMeta); view.meta = defaultMeta;
} }
return view; return view;
} }
@ -700,6 +700,7 @@ export default class View implements ViewType {
lock_type?: string; lock_type?: string;
password?: string; password?: string;
uuid?: string; uuid?: string;
meta?: any;
}, },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
) { ) {
@ -712,12 +713,16 @@ export default class View implements ViewType {
'meta', 'meta',
'uuid', 'uuid',
]); ]);
updateObj.meta = JSON.stringify(updateObj.meta);
// get existing cache // get existing cache
const key = `${CacheScope.VIEW}:${viewId}`; const key = `${CacheScope.VIEW}:${viewId}`;
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) { if (o) {
// update data // update data
o = { ...o, ...updateObj }; o = {
...o,
...updateObj,
};
if (o.is_default) { if (o.is_default) {
await NocoCache.set(`${CacheScope.VIEW}:${o.fk_model_id}:default`, o); await NocoCache.set(`${CacheScope.VIEW}:${o.fk_model_id}:default`, o);
} }

Loading…
Cancel
Save