more filtering updates
This commit is contained in:
parent
11927d2340
commit
3ba8f19e7f
|
@ -23,7 +23,6 @@
|
||||||
const params = new URLSearchParams()
|
const params = new URLSearchParams()
|
||||||
if (calculation) {
|
if (calculation) {
|
||||||
params.set("field", field)
|
params.set("field", field)
|
||||||
// todo, maybe won't work
|
|
||||||
params.set("calculation", calculation)
|
params.set("calculation", calculation)
|
||||||
}
|
}
|
||||||
if (groupBy) {
|
if (groupBy) {
|
||||||
|
@ -38,6 +37,8 @@
|
||||||
<Table title={decodeURI(name)} schema={view.schema} {data}>
|
<Table title={decodeURI(name)} schema={view.schema} {data}>
|
||||||
<FilterButton {view} />
|
<FilterButton {view} />
|
||||||
<CalculateButton {view} />
|
<CalculateButton {view} />
|
||||||
|
{#if view.calculation}
|
||||||
<GroupByButton {view} />
|
<GroupByButton {view} />
|
||||||
|
{/if}
|
||||||
<ExportButton {view} />
|
<ExportButton {view} />
|
||||||
</Table>
|
</Table>
|
||||||
|
|
|
@ -28,9 +28,10 @@
|
||||||
$: fields =
|
$: fields =
|
||||||
viewTable &&
|
viewTable &&
|
||||||
Object.keys(viewTable.schema).filter(
|
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() {
|
function saveView() {
|
||||||
if (!view.calculation) view.calculation = "stats"
|
if (!view.calculation) view.calculation = "stats"
|
||||||
|
@ -51,21 +52,19 @@
|
||||||
<option value={calculation.key}>{calculation.name}</option>
|
<option value={calculation.key}>{calculation.name}</option>
|
||||||
{/each}
|
{/each}
|
||||||
</Select>
|
</Select>
|
||||||
|
{#if view.calculation}
|
||||||
<p>of</p>
|
<p>of</p>
|
||||||
<Select secondary thin bind:value={view.field}>
|
<Select secondary thin bind:value={view.field}>
|
||||||
<option value={''}>
|
<option value={''}>You must choose an option</option>
|
||||||
{#if view.calculation === 'count'}
|
|
||||||
All Rows
|
|
||||||
{:else}You must choose an option{/if}
|
|
||||||
</option>
|
|
||||||
{#each fields as field}
|
{#each fields as field}
|
||||||
<option value={field}>{field}</option>
|
<option value={field}>{field}</option>
|
||||||
{/each}
|
{/each}
|
||||||
</Select>
|
</Select>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<Button secondary on:click={onClosed}>Cancel</Button>
|
<Button secondary on:click={onClosed}>Cancel</Button>
|
||||||
<Button primary on:click={saveView} disabled={!valid}>Save</Button>
|
<Button primary on:click={saveView} disabled={!view.field}>Save</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@
|
||||||
<Label extraSmall grey>Current Users</Label>
|
<Label extraSmall grey>Current Users</Label>
|
||||||
{#await fetchUsersPromise}
|
{#await fetchUsersPromise}
|
||||||
Loading...
|
Loading...
|
||||||
{:then [object Object]}
|
{:then users}
|
||||||
<ul>
|
<ul>
|
||||||
{#each users as user}
|
{#each users as user}
|
||||||
<li>
|
<li>
|
||||||
|
@ -84,7 +84,7 @@
|
||||||
<li>No Users found</li>
|
<li>No Users found</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
{:catch [object Object]}
|
{:catch err}
|
||||||
Something went wrong when trying to fetch users. Please refresh (CMD + R /
|
Something went wrong when trying to fetch users. Please refresh (CMD + R /
|
||||||
CTRL + R) the page and try again.
|
CTRL + R) the page and try again.
|
||||||
{/await}
|
{/await}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
<div class="spinner-container">
|
<div class="spinner-container">
|
||||||
<Spinner size="30" />
|
<Spinner size="30" />
|
||||||
</div>
|
</div>
|
||||||
{:then [object Object]}
|
{:then apps}
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{:catch [object Object]}
|
{:catch err}
|
||||||
<h1 style="color:red">{err}</h1>
|
<h1 style="color:red">{err}</h1>
|
||||||
{/await}
|
{/await}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<div class="spinner-container">
|
<div class="spinner-container">
|
||||||
<Spinner size="30" />
|
<Spinner size="30" />
|
||||||
</div>
|
</div>
|
||||||
{:then [object Object]}
|
{:then templates}
|
||||||
<div class="templates">
|
<div class="templates">
|
||||||
{#each templates as template}
|
{#each templates as template}
|
||||||
<div class="templates-card">
|
<div class="templates-card">
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{:catch [object Object]}
|
{:catch err}
|
||||||
<h1 style="color:red">{err}</h1>
|
<h1 style="color:red">{err}</h1>
|
||||||
{/await}
|
{/await}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -80,9 +80,9 @@
|
||||||
{#await promise}
|
{#await promise}
|
||||||
<!-- This should probably be some kind of loading state? -->
|
<!-- This should probably be some kind of loading state? -->
|
||||||
<div />
|
<div />
|
||||||
{:then [object Object]}
|
{:then _}
|
||||||
<slot />
|
<slot />
|
||||||
{:catch [object Object]}
|
{:catch error}
|
||||||
<p>Something went wrong: {error.message}</p>
|
<p>Something went wrong: {error.message}</p>
|
||||||
{/await}
|
{/await}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -11,6 +11,12 @@ const { cloneDeep } = require("lodash")
|
||||||
|
|
||||||
const TABLE_VIEW_BEGINS_WITH = `all${SEPARATOR}${DocumentTypes.TABLE}${SEPARATOR}`
|
const TABLE_VIEW_BEGINS_WITH = `all${SEPARATOR}${DocumentTypes.TABLE}${SEPARATOR}`
|
||||||
|
|
||||||
|
const CALCULATION_TYPES = {
|
||||||
|
SUM: "sum",
|
||||||
|
COUNT: "count",
|
||||||
|
STATS: "stats"
|
||||||
|
}
|
||||||
|
|
||||||
validateJs.extend(validateJs.validators.datetime, {
|
validateJs.extend(validateJs.validators.datetime, {
|
||||||
parse: function(value) {
|
parse: function(value) {
|
||||||
return new Date(value).getTime()
|
return new Date(value).getTime()
|
||||||
|
@ -152,13 +158,12 @@ exports.fetchView = async function(ctx) {
|
||||||
group,
|
group,
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: create constants for calculation types
|
|
||||||
if (!calculation) {
|
if (!calculation) {
|
||||||
response.rows = response.rows.map(row => row.doc)
|
response.rows = response.rows.map(row => row.doc)
|
||||||
ctx.body = await linkRows.attachLinkInfo(instanceId, response.rows)
|
ctx.body = await linkRows.attachLinkInfo(instanceId, response.rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (calculation === "stats") {
|
if (calculation === CALCULATION_TYPES.STATS) {
|
||||||
response.rows = response.rows.map(row => ({
|
response.rows = response.rows.map(row => ({
|
||||||
group: row.key,
|
group: row.key,
|
||||||
field,
|
field,
|
||||||
|
@ -168,13 +173,15 @@ exports.fetchView = async function(ctx) {
|
||||||
ctx.body = response.rows
|
ctx.body = response.rows
|
||||||
}
|
}
|
||||||
|
|
||||||
if (calculation === "count" || calculation === "sum") {
|
if (
|
||||||
ctx.body = field
|
calculation === CALCULATION_TYPES.COUNT ||
|
||||||
? response.rows.map(row => ({
|
calculation === CALCULATION_TYPES.SUM
|
||||||
|
) {
|
||||||
|
ctx.body = response.rows.map(row => ({
|
||||||
|
group: row.key,
|
||||||
field,
|
field,
|
||||||
value: row.value,
|
value: row.value,
|
||||||
}))
|
}))
|
||||||
: [{ field: "All Rows", value: response.total_rows }]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,8 +89,7 @@ function parseFilterExpression(filters) {
|
||||||
* @param {String?} groupBy - field to group calculation results on, if any
|
* @param {String?} groupBy - field to group calculation results on, if any
|
||||||
*/
|
*/
|
||||||
function parseEmitExpression(field, groupBy) {
|
function parseEmitExpression(field, groupBy) {
|
||||||
if (field) return `emit(doc["${groupBy || "_id"}"], doc["${field}"]);`
|
return `emit(doc["${groupBy || "_id"}"], doc["${field}"]);`
|
||||||
return `emit(doc._id, 1);`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
{#await _appPromise}
|
{#await _appPromise}
|
||||||
loading
|
loading
|
||||||
{:then [object Object]}
|
{:then _}
|
||||||
<div id="current_component" bind:this={currentComponent} />
|
<div id="current_component" bind:this={currentComponent} />
|
||||||
{/await}
|
{/await}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue