2020-08-21 17:10:56 +02:00
|
|
|
<script>
|
|
|
|
import { Button, Icon, DropdownMenu } from "@budibase/bbui"
|
2020-08-24 17:26:00 +02:00
|
|
|
import { createEventDispatcher } from "svelte"
|
2020-08-21 17:10:56 +02:00
|
|
|
import { backendUiStore } from "builderStore"
|
|
|
|
|
2020-08-24 17:26:00 +02:00
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
let anchor, dropdown
|
2020-08-21 17:10:56 +02:00
|
|
|
|
2020-08-24 17:26:00 +02:00
|
|
|
export let value = {}
|
|
|
|
|
|
|
|
function handleSelected(selected) {
|
|
|
|
dispatch("change", selected)
|
|
|
|
dropdown.hide()
|
|
|
|
}
|
2020-08-21 17:10:56 +02:00
|
|
|
|
|
|
|
const models = $backendUiStore.models.map(m => ({
|
2020-08-24 17:26:00 +02:00
|
|
|
label: m.name,
|
|
|
|
name: `all_${m._id}`,
|
2020-08-21 17:10:56 +02:00
|
|
|
modelId: m._id,
|
2020-08-24 17:26:00 +02:00
|
|
|
isModel: true,
|
2020-08-21 17:10:56 +02:00
|
|
|
}))
|
|
|
|
|
|
|
|
const views = $backendUiStore.models.reduce((acc, cur) => {
|
|
|
|
let viewsArr = Object.entries(cur.views).map(([key, value]) => ({
|
2020-08-24 17:26:00 +02:00
|
|
|
label: key,
|
2020-08-21 17:10:56 +02:00
|
|
|
name: key,
|
2020-08-26 18:03:30 +02:00
|
|
|
...value,
|
2020-08-21 17:10:56 +02:00
|
|
|
}))
|
|
|
|
return [...acc, ...viewsArr]
|
|
|
|
}, [])
|
|
|
|
</script>
|
|
|
|
|
2020-08-24 17:26:00 +02:00
|
|
|
<div bind:this={anchor}>
|
|
|
|
<Button secondary small on:click={dropdown.show}>
|
|
|
|
<span>{value.label ? value.label : 'Model / View'}</span>
|
2020-08-21 17:10:56 +02:00
|
|
|
<Icon name="arrowdown" />
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
<DropdownMenu
|
2020-08-24 17:26:00 +02:00
|
|
|
bind:this={dropdown}
|
2020-08-21 17:10:56 +02:00
|
|
|
width="175px"
|
|
|
|
borderColor="#d1d1d1ff"
|
2020-08-24 17:26:00 +02:00
|
|
|
{anchor}
|
2020-08-21 17:10:56 +02:00
|
|
|
align="right">
|
|
|
|
<div class="model-view-container">
|
|
|
|
<p>Tables</p>
|
2020-08-26 18:03:30 +02:00
|
|
|
|
2020-08-21 17:10:56 +02:00
|
|
|
<ul>
|
|
|
|
{#each models as model}
|
|
|
|
<li
|
2020-08-24 17:26:00 +02:00
|
|
|
class:selected={value === model}
|
|
|
|
on:click={() => handleSelected(model)}>
|
|
|
|
{model.label}
|
2020-08-21 17:10:56 +02:00
|
|
|
</li>
|
|
|
|
{/each}
|
|
|
|
</ul>
|
|
|
|
<hr />
|
|
|
|
<p>Views</p>
|
|
|
|
<ul>
|
|
|
|
{#each views as view}
|
|
|
|
<li
|
2020-08-24 17:26:00 +02:00
|
|
|
class:selected={value === view}
|
|
|
|
on:click={() => handleSelected(view)}>
|
|
|
|
{view.label}
|
2020-08-21 17:10:56 +02:00
|
|
|
</li>
|
|
|
|
{/each}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</DropdownMenu>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.model-view-container {
|
|
|
|
padding-bottom: 8px;
|
|
|
|
font: var(--smallheavybodytext);
|
|
|
|
}
|
|
|
|
|
|
|
|
p {
|
|
|
|
color: var(--grey-7);
|
|
|
|
margin: 0px;
|
|
|
|
padding: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
span {
|
|
|
|
text-transform: capitalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr {
|
|
|
|
margin: 10px 0px 5px 0px;
|
|
|
|
}
|
|
|
|
|
|
|
|
ul {
|
|
|
|
list-style: none;
|
|
|
|
padding-left: 0px;
|
|
|
|
margin: 0px;
|
|
|
|
}
|
|
|
|
|
|
|
|
li {
|
|
|
|
cursor: pointer;
|
|
|
|
margin: 0px;
|
|
|
|
padding: 5px 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.selected {
|
|
|
|
background-color: var(--grey-4);
|
|
|
|
}
|
|
|
|
|
|
|
|
li:hover {
|
|
|
|
background-color: var(--grey-4);
|
|
|
|
}
|
|
|
|
</style>
|