1
0
Fork 0
mirror of synced 2024-10-03 19:43:32 +13:00

more filtering updates

This commit is contained in:
Martin McKeaveney 2020-10-15 12:09:41 +01:00
parent a23440c740
commit f0f9015819
9 changed files with 42 additions and 36 deletions

View file

@ -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 @@
<Table title={decodeURI(name)} schema={view.schema} {data}>
<FilterButton {view} />
<CalculateButton {view} />
<GroupByButton {view} />
{#if view.calculation}
<GroupByButton {view} />
{/if}
<ExportButton {view} />
</Table>

View file

@ -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 @@
<option value={calculation.key}>{calculation.name}</option>
{/each}
</Select>
<p>of</p>
<Select secondary thin bind:value={view.field}>
<option value={''}>
{#if view.calculation === 'count'}
All Rows
{:else}You must choose an option{/if}
</option>
{#each fields as field}
<option value={field}>{field}</option>
{/each}
</Select>
{#if view.calculation}
<p>of</p>
<Select secondary thin bind:value={view.field}>
<option value={''}>You must choose an option</option>
{#each fields as field}
<option value={field}>{field}</option>
{/each}
</Select>
{/if}
</div>
<div class="footer">
<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>

View file

@ -74,7 +74,7 @@
<Label extraSmall grey>Current Users</Label>
{#await fetchUsersPromise}
Loading...
{:then [object Object]}
{:then users}
<ul>
{#each users as user}
<li>
@ -84,7 +84,7 @@
<li>No Users found</li>
{/each}
</ul>
{: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}

View file

@ -24,7 +24,7 @@
<div class="spinner-container">
<Spinner size="30" />
</div>
{:then [object Object]}
{:then apps}
<div class="inner">
<div>
<div>
@ -36,7 +36,7 @@
</div>
</div>
</div>
{:catch [object Object]}
{:catch err}
<h1 style="color:red">{err}</h1>
{/await}
</div>

View file

@ -20,7 +20,7 @@
<div class="spinner-container">
<Spinner size="30" />
</div>
{:then [object Object]}
{:then templates}
<div class="templates">
{#each templates as template}
<div class="templates-card">
@ -39,7 +39,7 @@
</div>
{/each}
</div>
{:catch [object Object]}
{:catch err}
<h1 style="color:red">{err}</h1>
{/await}
</div>

View file

@ -80,9 +80,9 @@
{#await promise}
<!-- This should probably be some kind of loading state? -->
<div />
{:then [object Object]}
{:then _}
<slot />
{:catch [object Object]}
{:catch error}
<p>Something went wrong: {error.message}</p>
{/await}
</div>

View file

@ -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,
}))
}
}

View file

@ -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}"]);`
}
/**

View file

@ -35,7 +35,7 @@
{#await _appPromise}
loading
{:then [object Object]}
{:then _}
<div id="current_component" bind:this={currentComponent} />
{/await}