Browse Source

Merge pull request #3364 from nocodb/fix/gui-v2-form-view-email-me

fix(gui-v2): email me in form view
pull/3406/head
Raju Udava 2 years ago committed by GitHub
parent
commit
284f48945c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/nc-gui-v2/components/dashboard/settings/AppStore.vue
  2. 33
      packages/nc-gui-v2/components/smartsheet/Form.vue
  3. 2
      packages/nocodb-sdk/src/lib/Api.ts
  4. 43
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts
  5. 9
      packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts
  6. 1
      packages/nocodb/src/lib/models/Plugin.ts
  7. 2
      scripts/sdk/swagger.json

2
packages/nc-gui-v2/components/dashboard/settings/AppStore.vue

@ -30,7 +30,7 @@ const fetchPluginApps = async () => {
const resetPlugin = async () => {
try {
await $api.plugin.update(pluginApp.id, {
input: undefined,
input: null,
active: false,
})
message.success('Plugin uninstalled successfully')

33
packages/nc-gui-v2/components/smartsheet/Form.vue

@ -94,7 +94,6 @@ function updateView() {
message.error('Data too long for Form Description')
return
}
updateFormView(formViewData.value)
}
@ -250,21 +249,14 @@ function setFormData() {
show_blank_form: !!((formViewData?.value as any)?.show_blank_form ?? 0),
} as any
{
// email me
let data: Record<string, boolean> = {}
try {
data = JSON.parse(formViewData.value?.email || '') || {}
} catch (e) {
// noop
}
data[state.user.value?.email as string] = emailMe.value
formViewData.value!.email = JSON.stringify(data)
// email me
let data: Record<string, boolean> = {}
try {
data = JSON.parse(formViewData.value?.email || '') || {}
} catch (e) {}
checkSMTPStatus()
}
emailMe.value = data[state.user.value?.email as string]
checkSMTPStatus()
localColumns.value = col
.filter(
@ -307,9 +299,18 @@ function isRequired(_columnObj: Record<string, any>, required = false) {
return required || (columnObj && columnObj.rqd && !columnObj.cdf)
}
function updateEmail() {
try {
const data = JSON.parse(formViewData.value?.email) || {}
data[state.user.value?.email as string] = emailMe.value
formViewData.value!.email = JSON.stringify(data)
checkSMTPStatus()
} catch (e) {}
}
function onEmailChange() {
updateEmail()
updateView()
checkSMTPStatus()
}
async function submitCallback() {

2
packages/nocodb-sdk/src/lib/Api.ts

@ -512,7 +512,7 @@ export interface PluginType {
tags?: string;
category?: string;
input_schema?: string;
input?: string;
input?: string | null;
creator?: string;
creator_website?: string;
price?: string;

43
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -1930,6 +1930,46 @@ class BaseModelSqlv2 {
if (hookName === 'After.insert' && view.type === ViewTypes.FORM) {
try {
const formView = await view.getView<FormView>();
const { columns } = await FormView.getWithInfo(formView.fk_view_id);
const allColumns = await this.model.getColumns();
const fieldById = columns.reduce(
(o: Record<string, any>, f: Record<string, any>) => ({
...o,
[f.fk_column_id]: f,
}),
{}
);
let order = 1;
const filteredColumns = allColumns
?.map((c: Record<string, any>) => ({
...c,
fk_column_id: c.id,
fk_view_id: formView.fk_view_id,
...(fieldById[c.id] ? fieldById[c.id] : {}),
order: (fieldById[c.id] && fieldById[c.id].order) || order++,
id: fieldById[c.id] && fieldById[c.id].id,
}))
.sort(
(a: Record<string, any>, b: Record<string, any>) =>
a.order - b.order
)
.filter(
(f: Record<string, any>) =>
f.show &&
f.uidt !== UITypes.Rollup &&
f.uidt !== UITypes.Lookup &&
f.uidt !== UITypes.Formula &&
f.uidt !== UITypes.SpecificDBType
)
.sort(
(a: Record<string, any>, b: Record<string, any>) =>
a.order - b.order
)
.map((c: Record<string, any>) => ({
...c,
required: !!(c.required || 0),
}));
const emails = Object.entries(JSON.parse(formView?.email) || {})
.filter((a) => a[1])
.map((a) => a[0]);
@ -1937,9 +1977,8 @@ class BaseModelSqlv2 {
const transformedData = _transformSubmittedFormDataForEmail(
data,
formView,
await this.model.getColumns()
filteredColumns
);
// todo: notification template
(await NcPluginMgrv2.emailAdapter())?.mailSend({
to: emails.join(','),
subject: 'NocoDB Form',

9
packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts

@ -6,6 +6,7 @@ import Hook from '../../models/Hook';
import Filter from '../../models/Filter';
import HookLog from '../../models/HookLog';
import { HookLogType } from 'nocodb-sdk';
import FormView from '../../models/FormView';
export function parseBody(template: string, data: any): string {
if (!template) {
@ -268,16 +269,11 @@ export function _transformSubmittedFormDataForEmail(
// @ts-ignore
formView,
// @ts-ignore
columns: Column[]
columns: (Column<any> & FormView<any>)[]
) {
const transformedData = { ...data };
for (const col of columns) {
if (!formView.query_params?.showFields?.[col.title]) {
delete transformedData[col.title];
continue;
}
if (col.uidt === 'Attachment') {
if (typeof transformedData[col.title] === 'string') {
transformedData[col.title] = JSON.parse(transformedData[col.title]);
@ -301,6 +297,7 @@ export function _transformSubmittedFormDataForEmail(
transformedData[col.title] = JSON.stringify(transformedData[col.title]);
}
}
return transformedData;
}
function parseHrtimeToMilliSeconds(hrtime) {

1
packages/nocodb/src/lib/models/Plugin.ts

@ -71,6 +71,7 @@ export default class Plugin implements PluginType {
o = { ...o, ...updateObj };
// set cache
await NocoCache.set(key, o);
await NocoCache.set(`${CacheScope.PLUGIN}:${o.title}`, o);
}
// set meta
await Noco.ncMeta.metaUpdate(

2
scripts/sdk/swagger.json

@ -7718,7 +7718,7 @@
"type": "string"
},
"input": {
"type": "string"
"type": ["string", "null"]
},
"creator": {
"type": "string"

Loading…
Cancel
Save