Add saving of calculation view updates
This commit is contained in:
parent
608331018a
commit
6d294be646
|
@ -41,7 +41,7 @@
|
||||||
|
|
||||||
const open = () => {
|
const open = () => {
|
||||||
calculations = extractCalculations(schema)
|
calculations = extractCalculations(schema)
|
||||||
groupings = extractGroupings(schema)
|
groupings = calculations.length ? extractGroupings(schema) : []
|
||||||
modal?.show()
|
modal?.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,18 +138,26 @@
|
||||||
const save = async () => {
|
const save = async () => {
|
||||||
let schema = {}
|
let schema = {}
|
||||||
|
|
||||||
const rand = ("" + Math.random()).substring(2)
|
// Add calculations
|
||||||
|
for (let calc of calculations) {
|
||||||
|
const name = `${calc.type} of ${calc.field}`
|
||||||
|
schema[name] = {
|
||||||
|
calculationType: calc.type,
|
||||||
|
field: calc.field,
|
||||||
|
visible: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add groupings
|
||||||
|
for (let grouping of groupings) {
|
||||||
|
schema[grouping.field] = {
|
||||||
|
visible: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
await datasource.actions.saveDefinition({
|
await datasource.actions.saveDefinition({
|
||||||
...$definition,
|
...$definition,
|
||||||
primaryDisplay: null,
|
primaryDisplay: null,
|
||||||
schema: {
|
schema,
|
||||||
["Average game length " + rand]: {
|
|
||||||
visible: true,
|
|
||||||
calculationType: CalculationType.AVG,
|
|
||||||
field: "Game Length",
|
|
||||||
width: 300,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
await rows.actions.refreshData()
|
await rows.actions.refreshData()
|
||||||
}
|
}
|
||||||
|
@ -168,7 +176,9 @@
|
||||||
>
|
>
|
||||||
{#if !calculations.length}
|
{#if !calculations.length}
|
||||||
<div>
|
<div>
|
||||||
<ActionButton quiet icon="Add">Add your first calculation</ActionButton>
|
<ActionButton quiet icon="Add" on:click={addCalc}>
|
||||||
|
Add your first calculation
|
||||||
|
</ActionButton>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="calculations">
|
<div class="calculations">
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
const newView = await viewsV2.create({
|
const newView = await viewsV2.create({
|
||||||
name: trimmedName,
|
name: trimmedName,
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
schema: enrichSchema(table.schema),
|
schema: calculation ? {} : enrichSchema(table.schema),
|
||||||
primaryDisplay: calculation ? undefined : table.primaryDisplay,
|
primaryDisplay: calculation ? undefined : table.primaryDisplay,
|
||||||
type: calculation ? ViewV2Type.CALCULATION : undefined,
|
type: calculation ? ViewV2Type.CALCULATION : undefined,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue