diff --git a/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte b/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte index 9d00edf351..593030985d 100644 --- a/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte @@ -23,7 +23,6 @@ const params = new URLSearchParams() if (calculation) { params.set("field", field) - // todo, maybe won't work params.set("calculation", calculation) } if (groupBy) { @@ -38,6 +37,8 @@ - + {#if view.calculation} + + {/if}
diff --git a/packages/builder/src/components/backend/DataTable/popovers/CalculatePopover.svelte b/packages/builder/src/components/backend/DataTable/popovers/CalculatePopover.svelte index 7dee7fb3d5..1a14e64475 100644 --- a/packages/builder/src/components/backend/DataTable/popovers/CalculatePopover.svelte +++ b/packages/builder/src/components/backend/DataTable/popovers/CalculatePopover.svelte @@ -28,9 +28,10 @@ $: fields = viewTable && Object.keys(viewTable.schema).filter( - field => viewTable.schema[field].type === "number" + field => + view.calculation === "count" || + viewTable.schema[field].type === "number" ) - $: valid = view.calculation === "count" || view.field function saveView() { if (!view.calculation) view.calculation = "stats" @@ -51,21 +52,19 @@ {/each} -

of

- + {#if view.calculation} +

of

+ + {/if} diff --git a/packages/builder/src/components/settings/tabs/Users.svelte b/packages/builder/src/components/settings/tabs/Users.svelte index adaede6e23..3d4a44fc73 100644 --- a/packages/builder/src/components/settings/tabs/Users.svelte +++ b/packages/builder/src/components/settings/tabs/Users.svelte @@ -74,7 +74,7 @@ {#await fetchUsersPromise} Loading... - {:then [object Object]} + {:then users} - {:catch [object Object]} + {:catch err} Something went wrong when trying to fetch users. Please refresh (CMD + R / CTRL + R) the page and try again. {/await} diff --git a/packages/builder/src/components/start/AppList.svelte b/packages/builder/src/components/start/AppList.svelte index b172d9a2f3..aeed85655e 100644 --- a/packages/builder/src/components/start/AppList.svelte +++ b/packages/builder/src/components/start/AppList.svelte @@ -24,7 +24,7 @@
- {:then [object Object]} + {:then apps}
@@ -36,7 +36,7 @@
- {:catch [object Object]} + {:catch err}

{err}

{/await} diff --git a/packages/builder/src/components/start/TemplateList.svelte b/packages/builder/src/components/start/TemplateList.svelte index 8be25c1981..64e0671c83 100644 --- a/packages/builder/src/components/start/TemplateList.svelte +++ b/packages/builder/src/components/start/TemplateList.svelte @@ -20,7 +20,7 @@
- {:then [object Object]} + {:then templates}
{#each templates as template}
@@ -39,7 +39,7 @@
{/each}
- {:catch [object Object]} + {:catch err}

{err}

{/await} diff --git a/packages/builder/src/pages/[application]/_reset.svelte b/packages/builder/src/pages/[application]/_reset.svelte index f757259ecb..b6d6149da3 100644 --- a/packages/builder/src/pages/[application]/_reset.svelte +++ b/packages/builder/src/pages/[application]/_reset.svelte @@ -80,9 +80,9 @@ {#await promise}
- {:then [object Object]} + {:then _} - {:catch [object Object]} + {:catch error}

Something went wrong: {error.message}

{/await}
diff --git a/packages/server/src/api/controllers/row.js b/packages/server/src/api/controllers/row.js index a9ce510457..3f5d56e507 100644 --- a/packages/server/src/api/controllers/row.js +++ b/packages/server/src/api/controllers/row.js @@ -11,6 +11,12 @@ const { cloneDeep } = require("lodash") const TABLE_VIEW_BEGINS_WITH = `all${SEPARATOR}${DocumentTypes.TABLE}${SEPARATOR}` +const CALCULATION_TYPES = { + SUM: "sum", + COUNT: "count", + STATS: "stats" +} + validateJs.extend(validateJs.validators.datetime, { parse: function(value) { return new Date(value).getTime() @@ -152,13 +158,12 @@ exports.fetchView = async function(ctx) { group, }) - // TODO: create constants for calculation types if (!calculation) { response.rows = response.rows.map(row => row.doc) ctx.body = await linkRows.attachLinkInfo(instanceId, response.rows) } - if (calculation === "stats") { + if (calculation === CALCULATION_TYPES.STATS) { response.rows = response.rows.map(row => ({ group: row.key, field, @@ -168,13 +173,15 @@ exports.fetchView = async function(ctx) { ctx.body = response.rows } - if (calculation === "count" || calculation === "sum") { - ctx.body = field - ? response.rows.map(row => ({ - field, - value: row.value, - })) - : [{ field: "All Rows", value: response.total_rows }] + if ( + calculation === CALCULATION_TYPES.COUNT || + calculation === CALCULATION_TYPES.SUM + ) { + ctx.body = response.rows.map(row => ({ + group: row.key, + field, + value: row.value, + })) } } diff --git a/packages/server/src/api/controllers/view/viewBuilder.js b/packages/server/src/api/controllers/view/viewBuilder.js index 082db8bebf..550480d52c 100644 --- a/packages/server/src/api/controllers/view/viewBuilder.js +++ b/packages/server/src/api/controllers/view/viewBuilder.js @@ -89,8 +89,7 @@ function parseFilterExpression(filters) { * @param {String?} groupBy - field to group calculation results on, if any */ function parseEmitExpression(field, groupBy) { - if (field) return `emit(doc["${groupBy || "_id"}"], doc["${field}"]);` - return `emit(doc._id, 1);` + return `emit(doc["${groupBy || "_id"}"], doc["${field}"]);` } /** diff --git a/packages/standard-components/src/Test/TestApp.svelte b/packages/standard-components/src/Test/TestApp.svelte index 1ad2cc484e..0c6da55601 100644 --- a/packages/standard-components/src/Test/TestApp.svelte +++ b/packages/standard-components/src/Test/TestApp.svelte @@ -35,7 +35,7 @@ {#await _appPromise} loading -{:then [object Object]} +{:then _}
{/await}