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 class="caption text-center">
<template v-if="'meta' in currentView">
<span>{{ ~~JSON.parse(currentView.meta).allowCSVDownload === 1 ? '✔' : '❌' }}</span>
<span>{{ renderAllowCSVDownload(currentView) }}</span>
</template>
</td>
<td class="caption">
@ -91,7 +91,7 @@
</td>
<td class="caption text-center">
<template v-if="'meta' in link">
<span>{{ ~~JSON.parse(link.meta).allowCSVDownload === 1 ? '✔' : '❌' }}</span>
<span>{{ renderAllowCSVDownload(link) }}</span>
</template>
</td>
<td class="caption">
@ -187,6 +187,14 @@ export default {
}
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>

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

@ -658,10 +658,14 @@ export default {
},
async saveAllowCSVDownload() {
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;
await this.$api.dbViewShare.update(this.shareLink.id, {
meta: JSON.stringify(meta),
meta,
});
this.$toast.success('Successfully updated').goAway(3000);
} catch (e) {
@ -767,10 +771,11 @@ export default {
},
async genShareLink() {
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
this.shareLink = shared;
this.passwordProtect = shared.password !== null;
this.allowCSVDownload = JSON.parse(shared.meta).allowCSVDownload;
this.allowCSVDownload = shared.meta.allowCSVDownload;
this.showShareModel = true;
},
copyView(view, i) {

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

Loading…
Cancel
Save