|
|
@ -3,12 +3,12 @@ |
|
|
import NewScreenModal from "components/design/NavigationPanel/NewScreenModal.svelte" |
|
|
import NewScreenModal from "components/design/NavigationPanel/NewScreenModal.svelte" |
|
|
import DatasourceModal from "components/design/NavigationPanel/DatasourceModal.svelte" |
|
|
import DatasourceModal from "components/design/NavigationPanel/DatasourceModal.svelte" |
|
|
import sanitizeUrl from "builderStore/store/screenTemplates/utils/sanitizeUrl" |
|
|
import sanitizeUrl from "builderStore/store/screenTemplates/utils/sanitizeUrl" |
|
|
import { Modal, notifications } from "@budibase/bbui" |
|
|
import { Modal, ModalContent, Select, notifications } from "@budibase/bbui" |
|
|
import { store, selectedAccessRole } from "builderStore" |
|
|
import { store, selectedAccessRole } from "builderStore" |
|
|
import analytics, { Events } from "analytics" |
|
|
import analytics, { Events } from "analytics" |
|
|
import { get } from "svelte/store" |
|
|
import { get } from "svelte/store" |
|
|
import getTemplates from "builderStore/store/screenTemplates" |
|
|
import getTemplates from "builderStore/store/screenTemplates" |
|
|
import { tables } from "stores/backend" |
|
|
import { tables, roles } from "stores/backend" |
|
|
|
|
|
|
|
|
let pendingScreen |
|
|
let pendingScreen |
|
|
|
|
|
|
|
|
@ -16,11 +16,22 @@ |
|
|
let newScreenModal |
|
|
let newScreenModal |
|
|
let screenDetailsModal |
|
|
let screenDetailsModal |
|
|
let datasourceModal |
|
|
let datasourceModal |
|
|
|
|
|
let screenAccessRoleModal |
|
|
|
|
|
|
|
|
|
|
|
// Cache variables for workflow |
|
|
|
|
|
let screenAccessRole = $selectedAccessRole + "" |
|
|
|
|
|
let selectedTemplates = null |
|
|
|
|
|
let blankScreenUrl = null |
|
|
|
|
|
|
|
|
|
|
|
let screenMode = null |
|
|
|
|
|
|
|
|
// External handler to show the screen wizard |
|
|
// External handler to show the screen wizard |
|
|
export const showModal = () => { |
|
|
export const showModal = () => { |
|
|
newScreenModal.show() |
|
|
selectedTemplates = null |
|
|
|
|
|
blankScreenUrl = null |
|
|
|
|
|
screenMode = null |
|
|
|
|
|
|
|
|
|
|
|
newScreenModal.show() |
|
|
// Reset state when showing modal again |
|
|
// Reset state when showing modal again |
|
|
pendingScreen = null |
|
|
pendingScreen = null |
|
|
} |
|
|
} |
|
|
@ -102,6 +113,8 @@ |
|
|
|
|
|
|
|
|
// Handler for NewScreenModal |
|
|
// Handler for NewScreenModal |
|
|
const confirmScreenSelection = async mode => { |
|
|
const confirmScreenSelection = async mode => { |
|
|
|
|
|
screenMode = mode |
|
|
|
|
|
|
|
|
if (mode == "autoCreate") { |
|
|
if (mode == "autoCreate") { |
|
|
datasourceModal.show() |
|
|
datasourceModal.show() |
|
|
} else { |
|
|
} else { |
|
|
@ -114,12 +127,18 @@ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Handler for DatasourceModal |
|
|
// Handler for DatasourceModal confirmation, move to screen access select |
|
|
const confirmScreenDatasources = async ({ templates, screenAccessRole }) => { |
|
|
const confirmScreenDatasources = async ({ templates }) => { |
|
|
|
|
|
selectedTemplates = templates |
|
|
|
|
|
screenAccessRoleModal.show() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Handler for Datasource Screen Creation |
|
|
|
|
|
const completeDatasourceScreenCreation = async () => { |
|
|
// // Handle template selection |
|
|
// // Handle template selection |
|
|
if (templates?.length > 1) { |
|
|
if (selectedTemplates?.length > 1) { |
|
|
// Autoscreens, so create immediately |
|
|
// Autoscreens, so create immediately |
|
|
const screens = templates.map(template => { |
|
|
const screens = selectedTemplates.map(template => { |
|
|
let screenTemplate = template.create() |
|
|
let screenTemplate = template.create() |
|
|
screenTemplate.datasource = template.datasource |
|
|
screenTemplate.datasource = template.datasource |
|
|
return screenTemplate |
|
|
return screenTemplate |
|
|
@ -128,14 +147,42 @@ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Handler for ScreenDetailsModal |
|
|
const confirmScreenBlank = async ({ screenUrl }) => { |
|
|
const confirmScreenDetails = async ({ screenUrl, screenAccessRole }) => { |
|
|
blankScreenUrl = screenUrl |
|
|
|
|
|
screenAccessRoleModal.show() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Submit request for a blank screen |
|
|
|
|
|
const confirmBlankScreenCreation = async ({ |
|
|
|
|
|
screenUrl, |
|
|
|
|
|
screenAccessRole, |
|
|
|
|
|
}) => { |
|
|
if (!pendingScreen) { |
|
|
if (!pendingScreen) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
pendingScreen.routing.route = screenUrl |
|
|
pendingScreen.routing.route = screenUrl |
|
|
await createScreens({ screens: [pendingScreen], screenAccessRole }) |
|
|
await createScreens({ screens: [pendingScreen], screenAccessRole }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Submit screen config for creation. |
|
|
|
|
|
const confirmScreenCreation = async () => { |
|
|
|
|
|
if (screenMode === "blankScreen") { |
|
|
|
|
|
confirmBlankScreenCreation({ |
|
|
|
|
|
screenUrl: blankScreenUrl, |
|
|
|
|
|
screenAccessRole, |
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
|
|
|
completeDatasourceScreenCreation() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const roleSelectBack = () => { |
|
|
|
|
|
if (screenMode === "blankScreen") { |
|
|
|
|
|
newScreenModal.show() |
|
|
|
|
|
} else { |
|
|
|
|
|
datasourceModal.show() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
</script> |
|
|
</script> |
|
|
|
|
|
|
|
|
<Modal bind:this={newScreenModal}> |
|
|
<Modal bind:this={newScreenModal}> |
|
|
@ -146,12 +193,39 @@ |
|
|
<DatasourceModal |
|
|
<DatasourceModal |
|
|
onConfirm={confirmScreenDatasources} |
|
|
onConfirm={confirmScreenDatasources} |
|
|
onCancel={() => newScreenModal.show()} |
|
|
onCancel={() => newScreenModal.show()} |
|
|
|
|
|
initalScreens={!selectedTemplates ? [] : [...selectedTemplates]} |
|
|
/> |
|
|
/> |
|
|
</Modal> |
|
|
</Modal> |
|
|
|
|
|
|
|
|
|
|
|
<Modal bind:this={screenAccessRoleModal}> |
|
|
|
|
|
<ModalContent |
|
|
|
|
|
title={"Create CRUD Screens"} |
|
|
|
|
|
confirmText={"Done"} |
|
|
|
|
|
cancelText={"Back"} |
|
|
|
|
|
onConfirm={confirmScreenCreation} |
|
|
|
|
|
onCancel={roleSelectBack} |
|
|
|
|
|
> |
|
|
|
|
|
Select which level of access you want your screens to have |
|
|
|
|
|
<Select |
|
|
|
|
|
bind:value={screenAccessRole} |
|
|
|
|
|
on:change={() => { |
|
|
|
|
|
analytics.captureEvent(Events.SCREEN.CREATE_ROLE_UPDATED, { |
|
|
|
|
|
screenAccessRole, |
|
|
|
|
|
}) |
|
|
|
|
|
}} |
|
|
|
|
|
label="Access" |
|
|
|
|
|
getOptionLabel={role => role.name} |
|
|
|
|
|
getOptionValue={role => role._id} |
|
|
|
|
|
getOptionColor={role => role.color} |
|
|
|
|
|
options={$roles} |
|
|
|
|
|
/> |
|
|
|
|
|
</ModalContent> |
|
|
|
|
|
</Modal> |
|
|
|
|
|
|
|
|
<Modal bind:this={screenDetailsModal}> |
|
|
<Modal bind:this={screenDetailsModal}> |
|
|
<ScreenDetailsModal |
|
|
<ScreenDetailsModal |
|
|
onConfirm={confirmScreenDetails} |
|
|
onConfirm={confirmScreenBlank} |
|
|
onCancel={() => newScreenModal.show()} |
|
|
onCancel={() => newScreenModal.show()} |
|
|
|
|
|
initialUrl={blankScreenUrl} |
|
|
/> |
|
|
/> |
|
|
</Modal> |
|
|
</Modal> |
|
|
|