|
|
@ -1,5 +1,5 @@ |
|
|
<script> |
|
|
<script> |
|
|
import api from "builderStore/api" |
|
|
import { API } from "api" |
|
|
import { tables } from "stores/backend" |
|
|
import { tables } from "stores/backend" |
|
|
|
|
|
|
|
|
import Table from "./Table.svelte" |
|
|
import Table from "./Table.svelte" |
|
|
@ -9,6 +9,7 @@ |
|
|
import ExportButton from "./buttons/ExportButton.svelte" |
|
|
import ExportButton from "./buttons/ExportButton.svelte" |
|
|
import ManageAccessButton from "./buttons/ManageAccessButton.svelte" |
|
|
import ManageAccessButton from "./buttons/ManageAccessButton.svelte" |
|
|
import HideAutocolumnButton from "./buttons/HideAutocolumnButton.svelte" |
|
|
import HideAutocolumnButton from "./buttons/HideAutocolumnButton.svelte" |
|
|
|
|
|
import { notifications } from "@budibase/bbui" |
|
|
|
|
|
|
|
|
export let view = {} |
|
|
export let view = {} |
|
|
|
|
|
|
|
|
@ -20,33 +21,31 @@ |
|
|
$: name = view.name |
|
|
$: name = view.name |
|
|
|
|
|
|
|
|
// Fetch rows for specified view |
|
|
// Fetch rows for specified view |
|
|
$: { |
|
|
$: fetchViewData(name, view.field, view.groupBy, view.calculation) |
|
|
loading = true |
|
|
|
|
|
fetchViewData(name, view.field, view.groupBy, view.calculation) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function fetchViewData(name, field, groupBy, calculation) { |
|
|
async function fetchViewData(name, field, groupBy, calculation) { |
|
|
|
|
|
loading = true |
|
|
const _tables = $tables.list |
|
|
const _tables = $tables.list |
|
|
const allTableViews = _tables.map(table => table.views) |
|
|
const allTableViews = _tables.map(table => table.views) |
|
|
const thisView = allTableViews.filter( |
|
|
const thisView = allTableViews.filter( |
|
|
views => views != null && views[name] != null |
|
|
views => views != null && views[name] != null |
|
|
)[0] |
|
|
)[0] |
|
|
|
|
|
|
|
|
// don't fetch view data if the view no longer exists |
|
|
// Don't fetch view data if the view no longer exists |
|
|
if (!thisView) { |
|
|
if (!thisView) { |
|
|
|
|
|
loading = false |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
const params = new URLSearchParams() |
|
|
try { |
|
|
if (calculation) { |
|
|
data = await API.fetchViewData({ |
|
|
params.set("field", field) |
|
|
name, |
|
|
params.set("calculation", calculation) |
|
|
calculation, |
|
|
} |
|
|
field, |
|
|
if (groupBy) { |
|
|
groupBy, |
|
|
params.set("group", groupBy) |
|
|
}) |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
notifications.error("Error fetching view data") |
|
|
} |
|
|
} |
|
|
const QUERY_VIEW_URL = `/api/views/${name}?${params}` |
|
|
|
|
|
const response = await api.get(QUERY_VIEW_URL) |
|
|
|
|
|
data = await response.json() |
|
|
|
|
|
loading = false |
|
|
loading = false |
|
|
} |
|
|
} |
|
|
</script> |
|
|
</script> |
|
|
|