2020-05-29 14:28:12 +02:00
|
|
|
<script>
|
2020-11-18 23:04:18 +01:00
|
|
|
import { onMount } from "svelte"
|
2020-12-05 13:09:58 +01:00
|
|
|
import { goto, params, url } from "@sveltech/routify"
|
2020-12-09 19:18:47 +01:00
|
|
|
import {
|
|
|
|
store,
|
2020-12-14 12:14:16 +01:00
|
|
|
allScreens,
|
2020-12-09 19:18:47 +01:00
|
|
|
currentAsset,
|
|
|
|
backendUiStore,
|
|
|
|
selectedAccessRole,
|
|
|
|
} from "builderStore"
|
2020-12-05 13:09:58 +01:00
|
|
|
import { FrontendTypes } from "constants"
|
2021-01-14 11:03:33 +01:00
|
|
|
import ComponentNavigationTree from "components/design/NavigationPanel/ComponentNavigationTree/index.svelte"
|
|
|
|
import Layout from "components/design/NavigationPanel/Layout.svelte"
|
|
|
|
import NewScreenModal from "components/design/NavigationPanel/NewScreenModal.svelte"
|
|
|
|
import NewLayoutModal from "components/design/NavigationPanel/NewLayoutModal.svelte"
|
2020-12-09 19:18:47 +01:00
|
|
|
import { Modal, Switcher, Select } from "@budibase/bbui"
|
2020-05-29 19:32:52 +02:00
|
|
|
|
2020-12-01 17:22:06 +01:00
|
|
|
const tabs = [
|
|
|
|
{
|
|
|
|
title: "Screens",
|
2020-12-05 13:09:58 +01:00
|
|
|
key: "screen",
|
2020-12-01 17:22:06 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Layouts",
|
2020-12-05 13:09:58 +01:00
|
|
|
key: "layout",
|
2020-12-01 17:22:06 +01:00
|
|
|
},
|
|
|
|
]
|
2020-11-18 23:04:18 +01:00
|
|
|
|
2020-12-01 17:22:06 +01:00
|
|
|
let modal
|
2020-11-18 23:04:18 +01:00
|
|
|
let routes = {}
|
2020-12-05 13:09:58 +01:00
|
|
|
let tab = $params.assetType
|
2020-12-02 14:41:00 +01:00
|
|
|
|
2020-12-14 12:14:16 +01:00
|
|
|
const navigate = ({ detail }) => {
|
|
|
|
if (!detail) {
|
|
|
|
return
|
|
|
|
}
|
2020-12-07 17:06:20 +01:00
|
|
|
$goto(`../${detail.heading.key}`)
|
2020-12-02 14:41:00 +01:00
|
|
|
}
|
2020-11-18 23:04:18 +01:00
|
|
|
|
2020-12-14 12:14:16 +01:00
|
|
|
const updateAccessRole = event => {
|
|
|
|
const role = event.target.value
|
|
|
|
|
|
|
|
// Select a valid screen with this new role - otherwise we'll not be
|
|
|
|
// able to change role at all because ComponentNavigationTree will kick us
|
|
|
|
// back the current role again because the same screen ID is still selected
|
|
|
|
const firstValidScreenId = $allScreens.find(
|
|
|
|
screen => screen.routing.roleId === role
|
|
|
|
)?._id
|
|
|
|
if (firstValidScreenId) {
|
|
|
|
store.actions.screens.select(firstValidScreenId)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise clear the selected screen ID so that the first new valid screen
|
|
|
|
// can be selected by ComponentNavigationTree
|
|
|
|
else {
|
|
|
|
store.update(state => {
|
|
|
|
state.selectedScreenId = null
|
|
|
|
return state
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
selectedAccessRole.set(role)
|
|
|
|
}
|
|
|
|
|
2020-11-18 23:04:18 +01:00
|
|
|
onMount(() => {
|
2020-11-19 22:07:25 +01:00
|
|
|
store.actions.routing.fetch()
|
2020-11-18 23:04:18 +01:00
|
|
|
})
|
2020-05-29 14:28:12 +02:00
|
|
|
</script>
|
|
|
|
|
2020-10-22 19:12:40 +02:00
|
|
|
<div class="title">
|
2020-12-03 16:15:14 +01:00
|
|
|
<Switcher headings={tabs} bind:value={tab} on:change={navigate}>
|
2020-12-05 13:09:58 +01:00
|
|
|
{#if tab === FrontendTypes.SCREEN}
|
2020-12-01 17:22:06 +01:00
|
|
|
<i
|
|
|
|
on:click={modal.show}
|
|
|
|
data-cy="new-screen"
|
|
|
|
class="ri-add-circle-fill" />
|
2020-12-09 19:18:47 +01:00
|
|
|
<div class="role-select">
|
|
|
|
<Select
|
|
|
|
extraThin
|
|
|
|
secondary
|
2020-12-14 12:14:16 +01:00
|
|
|
on:change={updateAccessRole}
|
|
|
|
value={$selectedAccessRole}
|
2020-12-09 19:18:47 +01:00
|
|
|
label="Filter by Access">
|
|
|
|
{#each $backendUiStore.roles as role}
|
|
|
|
<option value={role._id}>{role.name}</option>
|
|
|
|
{/each}
|
|
|
|
</Select>
|
|
|
|
</div>
|
2020-12-14 12:14:16 +01:00
|
|
|
<div class="nav-items-container">
|
|
|
|
<ComponentNavigationTree />
|
|
|
|
</div>
|
2020-12-01 17:22:06 +01:00
|
|
|
<Modal bind:this={modal}>
|
|
|
|
<NewScreenModal />
|
|
|
|
</Modal>
|
2020-12-05 13:09:58 +01:00
|
|
|
{:else if tab === FrontendTypes.LAYOUT}
|
2020-12-05 00:16:07 +01:00
|
|
|
<i
|
|
|
|
on:click={modal.show}
|
|
|
|
data-cy="new-layout"
|
|
|
|
class="ri-add-circle-fill" />
|
2020-12-09 19:18:47 +01:00
|
|
|
{#each $store.layouts as layout, idx (layout._id)}
|
|
|
|
<Layout {layout} border={idx > 0} />
|
2020-12-02 15:49:43 +01:00
|
|
|
{/each}
|
2020-12-05 00:16:07 +01:00
|
|
|
<Modal bind:this={modal}>
|
|
|
|
<NewLayoutModal />
|
|
|
|
</Modal>
|
2020-12-01 17:22:06 +01:00
|
|
|
{/if}
|
|
|
|
</Switcher>
|
2020-05-29 14:28:12 +02:00
|
|
|
</div>
|
2020-12-01 17:22:06 +01:00
|
|
|
|
2020-10-22 19:12:40 +02:00
|
|
|
<style>
|
|
|
|
.title {
|
|
|
|
display: flex;
|
2020-12-04 15:07:56 +01:00
|
|
|
flex-direction: column;
|
|
|
|
justify-content: flex-start;
|
|
|
|
align-items: stretch;
|
2020-12-04 15:52:40 +01:00
|
|
|
position: relative;
|
2020-10-22 19:12:40 +02:00
|
|
|
}
|
|
|
|
.title i {
|
|
|
|
font-size: 20px;
|
2020-12-04 15:52:40 +01:00
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
2020-10-22 19:12:40 +02:00
|
|
|
}
|
|
|
|
.title i:hover {
|
|
|
|
cursor: pointer;
|
|
|
|
color: var(--blue);
|
|
|
|
}
|
2020-12-09 19:18:47 +01:00
|
|
|
|
|
|
|
.role-select {
|
|
|
|
margin-bottom: var(--spacing-m);
|
|
|
|
}
|
2020-10-22 19:12:40 +02:00
|
|
|
</style>
|