diff --git a/lerna.json b/lerna.json
index 2febd9ce70..360bc19a6a 100644
--- a/lerna.json
+++ b/lerna.json
@@ -4,7 +4,6 @@
"packages": [
"packages/*"
],
- "useWorkspaces": true,
"command": {
"publish": {
"ignoreChanges": [
diff --git a/package.json b/package.json
index 4b253e395d..278a91a8f6 100644
--- a/package.json
+++ b/package.json
@@ -1,9 +1,6 @@
{
"name": "root",
"private": true,
- "workspaces": [
- "packages/*"
- ],
"devDependencies": {
"babel-eslint": "^10.0.3",
"eslint": "^6.8.0",
diff --git a/packages/builder/rollup.config.js b/packages/builder/rollup.config.js
index 38a1a42a34..8552401356 100644
--- a/packages/builder/rollup.config.js
+++ b/packages/builder/rollup.config.js
@@ -118,7 +118,7 @@ const coreExternal = [
]
const customResolver = resolve({
- extensions: [".mjs", ".js", ".jsx", ".json", ".sass", ".scss", ".svelte"]
+ extensions: [".mjs", ".js", ".jsx", ".json", ".sass", ".scss", ".svelte", ".css"]
})
const projectRootDir = path.resolve(__dirname)
diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js
index 34b3212a58..3005eaf659 100644
--- a/packages/builder/src/builderStore/store/backend.js
+++ b/packages/builder/src/builderStore/store/backend.js
@@ -19,6 +19,7 @@ export const getBackendUiStore = () => {
name: "",
},
breadcrumbs: [],
+ models: [],
selectedDatabase: {},
selectedModel: {},
}
@@ -27,12 +28,16 @@ export const getBackendUiStore = () => {
store.actions = {
database: {
- select: db =>
+ select: async db => {
+ const response = await api.get(`/api/${db.id}/models`)
+ const models = await response.json()
store.update(state => {
state.selectedDatabase = db
state.breadcrumbs = [db.name]
+ state.models = models
return state
- }),
+ })
+ }
},
records: {
delete: () =>
@@ -51,6 +56,13 @@ export const getBackendUiStore = () => {
return state
}),
},
+ models: {
+ create: model => store.update(state => {
+ state.models.push(model)
+ state.models = state.models
+ return state
+ })
+ },
views: {
select: view =>
store.update(state => {
diff --git a/packages/builder/src/builderStore/store/index.js b/packages/builder/src/builderStore/store/index.js
index f135ceb070..d5675f953f 100644
--- a/packages/builder/src/builderStore/store/index.js
+++ b/packages/builder/src/builderStore/store/index.js
@@ -42,7 +42,8 @@ export const getStore = () => {
currentNode: null,
libraries: null,
showSettings: false,
- useAnalytics: true
+ useAnalytics: true,
+ neoAppId: "84a14e3065c5f15ef8410a5e4c000d68"
}
const store = writable(initial)
diff --git a/packages/builder/src/components/common/NumberBox.svelte b/packages/builder/src/components/common/NumberBox.svelte
index ca7443ba48..f3a348dbef 100644
--- a/packages/builder/src/components/common/NumberBox.svelte
+++ b/packages/builder/src/components/common/NumberBox.svelte
@@ -16,6 +16,6 @@
diff --git a/packages/builder/src/components/database/FieldView.svelte b/packages/builder/src/components/database/FieldView.svelte
deleted file mode 100644
index 3bf2ed4b93..0000000000
--- a/packages/builder/src/components/database/FieldView.svelte
+++ /dev/null
@@ -1,156 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
diff --git a/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte b/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte
index 971afcf3b0..23d16ab483 100644
--- a/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte
+++ b/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte
@@ -27,7 +27,7 @@
CreateEditRecordModal,
{
onClosed: close,
- record: await selectRecord(row),
+ record: row,
},
{ styleContent: { padding: "0" } }
)
@@ -38,7 +38,7 @@
DeleteRecordModal,
{
onClosed: close,
- record: await selectRecord(row),
+ record: row,
},
{ styleContent: { padding: "0" } }
)
@@ -53,7 +53,7 @@
const ITEMS_PER_PAGE = 10
// Internal headers we want to hide from the user
- const INTERNAL_HEADERS = ["key", "sortKey", "type", "id", "isNew"]
+ const INTERNAL_HEADERS = ["_id", "_rev", "modelId", "type"]
let modalOpen = false
let data = []
@@ -61,50 +61,25 @@
let views = []
let currentPage = 0
- $: views = $backendUiStore.selectedRecord
- ? childViewsForRecord($store.hierarchy)
- : $store.hierarchy.indexes
+ $: instanceId = $backendUiStore.selectedDatabase.id
- $: currentAppInfo = {
- appname: $store.appname,
- instanceId: $backendUiStore.selectedDatabase.id,
+ $: {
+ if ($backendUiStore.selectedView) {
+ api.fetchDataForView($backendUiStore.selectedView, instanceId).then(records => {
+ data = records || []
+ headers = Object.keys($backendUiStore.selectedModel.schema).filter(key => !INTERNAL_HEADERS.includes(key));
+ })
+ }
}
- $: fetchRecordsForView(
- $backendUiStore.selectedView,
- $backendUiStore.selectedDatabase
- ).then(records => {
- data = records || []
- headers = hideInternalHeaders($backendUiStore.selectedView)
- })
-
$: paginatedData = data.slice(
currentPage * ITEMS_PER_PAGE,
currentPage * ITEMS_PER_PAGE + ITEMS_PER_PAGE
)
- const getSchema = getIndexSchema($store.hierarchy)
-
- const childViewsForRecord = compose(flatten, map("indexes"), get("children"))
-
- const hideInternalHeaders = compose(
- remove(headerName => INTERNAL_HEADERS.includes(headerName)),
- map(get("name")),
- getSchema
- )
-
- async function fetchRecordsForView(view, instance) {
- if (!view || !view.name) return
-
- const viewName = $backendUiStore.selectedRecord
- ? `${$backendUiStore.selectedRecord.key}/${view.name}`
- : view.name
-
- return await api.fetchDataForView(viewName, {
- appname: $store.appname,
- instanceId: instance.id,
- })
- }
+ // async function fetchRecordsForView(view, instance) {
+ // return await api.fetchDataForView($backendUiStore.selectedView)
+ // }
function drillIntoRecord(record) {
backendUiStore.update(state => {
@@ -127,11 +102,6 @@
{takeRight(2, $backendUiStore.breadcrumbs).join(' / ')}
-
diff --git a/packages/builder/src/components/database/ModelDataTable/api.js b/packages/builder/src/components/database/ModelDataTable/api.js
index b7a19801df..596b3f695e 100644
--- a/packages/builder/src/components/database/ModelDataTable/api.js
+++ b/packages/builder/src/components/database/ModelDataTable/api.js
@@ -14,8 +14,8 @@ export async function createDatabase(appname, instanceName) {
return await response.json()
}
-export async function deleteRecord(record, { appname, instanceId }) {
- const DELETE_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/record${record.key}`
+export async function deleteRecord(record, instanceId) {
+ const DELETE_RECORDS_URL = `/api/${instanceId}/records/${record._id}/${record._rev}`
const response = await api.delete(DELETE_RECORDS_URL)
return response
}
@@ -26,34 +26,16 @@ export async function loadRecord(key, { appname, instanceId }) {
return await response.json()
}
-export async function saveRecord(record, { appname, instanceId }) {
- let recordBase = { ...record }
-
- // brand new record
- // car-model-id or name/specific-car-id/manus
- if (record.collectionName) {
- const collectionKey = `/${record.collectionName}`
- recordBase = getNewRecord(recordBase, collectionKey)
- recordBase = overwritePresentProperties(recordBase, record)
- }
-
- const SAVE_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/record/`
- const response = await api.post(SAVE_RECORDS_URL, recordBase)
+export async function saveRecord({ record, instanceId, modelId }) {
+ const SAVE_RECORDS_URL = `/api/${instanceId}/${modelId}/records`
+ const response = await api.post(SAVE_RECORDS_URL, record)
return await response.json()
}
-export async function fetchDataForView(viewName, { appname, instanceId }) {
- const FETCH_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/listRecords/${viewName}`
+export async function fetchDataForView(viewName, instanceId) {
+ // const FETCH_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/listRecords/${viewName}`
+ const FETCH_RECORDS_URL = `/api/${instanceId}/${viewName}/records`
const response = await api.get(FETCH_RECORDS_URL)
return await response.json()
-}
-
-function overwritePresentProperties(baseObj, overwrites) {
- const base = { ...baseObj }
-
- for (let key in base) {
- if (overwrites[key]) base[key] = overwrites[key]
- }
- return base
-}
+}
\ No newline at end of file
diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel.old.svelte
similarity index 100%
rename from packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel.svelte
rename to packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel.old.svelte
diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/CreateEditModel.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/CreateEditModel.svelte
new file mode 100644
index 0000000000..af190c7c61
--- /dev/null
+++ b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/CreateEditModel.svelte
@@ -0,0 +1,156 @@
+
+
+
+ {#if !showFieldView}
+
+ Create / Edit Model
+ {:else}
+
+ Create / Edit Field
+ {/if}
+
+{#if !showFieldView}
+
+
Settings
+
+ {#if $store.errors && $store.errors.length > 0}
+
+ {/if}
+
+
+
+
+ Fields
+
(showFieldView = true)}>
+ Add new field
+
+
+
+
+
+
+ Edit |
+ Name |
+ Type |
+ Values |
+ |
+
+
+
+ {#each modelFields as [key, meta]}
+
+
+ editField(meta)} />
+ |
+
+ {key}
+ |
+ {meta.type} |
+
+
+ deleteField(meta)} />
+ |
+
+ {/each}
+
+
+
+
+{:else}
+ showFieldView = false}
+ />
+{/if}
+
+
diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/FieldView.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/FieldView.svelte
new file mode 100644
index 0000000000..c8f4abcd5a
--- /dev/null
+++ b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/FieldView.svelte
@@ -0,0 +1,102 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte
index d8eec31859..380442fa71 100644
--- a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte
+++ b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte
@@ -13,63 +13,57 @@
import * as api from "../api"
import ErrorsBox from "components/common/ErrorsBox.svelte"
- export let record
+ export let record = {}
export let onClosed
let errors = []
let selectedModel
- const childModelsForModel = compose(flatten, map("children"), get("children"))
+ $: instanceId = $backendUiStore.selectedDatabase.id
- $: currentAppInfo = {
- appname: $store.appname,
- instanceId: $backendUiStore.selectedDatabase.id,
- }
$: models = $backendUiStore.selectedRecord
? childModelsForModel($store.hierarchy)
: $store.hierarchy.children
- $: {
- if (record) {
- selectedModel = getExactNodeForKey($store.hierarchy)(record.key)
- } else {
- selectedModel = selectedModel || models[0]
- }
- }
-
- $: modelFields = selectedModel ? selectedModel.fields : []
-
- function getCurrentCollectionKey(selectedRecord) {
- return selectedRecord
- ? joinKey(selectedRecord.key, selectedModel.collectionName)
- : joinKey(selectedModel.collectionName)
- }
-
- $: editingRecord =
- record ||
- getNewRecord(
- selectedModel,
- getCurrentCollectionKey($backendUiStore.selectedRecord)
- )
+ $: modelSchema = $backendUiStore.selectedModel
+ ? Object.entries($backendUiStore.selectedModel.schema)
+ : []
function closed() {
- editingRecord = null
+ // editingRecord = null
onClosed()
}
+ function determineInputType(meta) {
+ if (meta.type === "datetime") return "date"
+ if (meta.type === "number") return "number"
+ if (meta.type === "boolean") return "checkbox"
+
+ return "text"
+ }
+
async function saveRecord() {
- const recordResponse = await api.saveRecord(editingRecord, currentAppInfo)
+ const recordResponse = await api.saveRecord({
+ record,
+ instanceId,
+ modelId: $backendUiStore.selectedModel._id
+ })
+ if (recordResponse.errors) {
+ errors = recordResponse.errors;
+ return;
+ }
+
backendUiStore.update(state => {
state.selectedView = state.selectedView
return state
})
- closed()
}
Create / Edit Record
-
+
+ {JSON.stringify(errors)}
diff --git a/packages/builder/src/components/database/ModelDataTable/modals/DeleteRecord.svelte b/packages/builder/src/components/database/ModelDataTable/modals/DeleteRecord.svelte
index fc27c6566f..d771a32da8 100644
--- a/packages/builder/src/components/database/ModelDataTable/modals/DeleteRecord.svelte
+++ b/packages/builder/src/components/database/ModelDataTable/modals/DeleteRecord.svelte
@@ -6,10 +6,7 @@
export let record
export let onClosed
- $: currentAppInfo = {
- appname: $store.appname,
- instanceId: $backendUiStore.selectedDatabase.id,
- }
+ $: instanceId = $backendUiStore.selectedDatabase.id
@@ -28,7 +25,7 @@
{
- await api.deleteRecord(record, currentAppInfo)
+ await api.deleteRecord(record, instanceId)
backendUiStore.actions.records.delete(record)
onClosed()
}}>
diff --git a/packages/builder/src/components/database/ModelDataTable/modals/RecordFieldControl.old.svelte b/packages/builder/src/components/database/ModelDataTable/modals/RecordFieldControl.old.svelte
new file mode 100644
index 0000000000..1491f7878f
--- /dev/null
+++ b/packages/builder/src/components/database/ModelDataTable/modals/RecordFieldControl.old.svelte
@@ -0,0 +1,66 @@
+
+
+
diff --git a/packages/builder/src/components/database/ModelDataTable/modals/RecordFieldControl.svelte b/packages/builder/src/components/database/ModelDataTable/modals/RecordFieldControl.svelte
index 1491f7878f..1c7692d464 100644
--- a/packages/builder/src/components/database/ModelDataTable/modals/RecordFieldControl.svelte
+++ b/packages/builder/src/components/database/ModelDataTable/modals/RecordFieldControl.svelte
@@ -1,66 +1,29 @@
-
+
+ 0}
+ {type}
+ {value}
+ on:input={handleInput}
+ on:change={handleInput} />
diff --git a/packages/builder/src/components/database/ModelDataTable/modals/index.js b/packages/builder/src/components/database/ModelDataTable/modals/index.js
index c986160961..dc0e1a42d3 100644
--- a/packages/builder/src/components/database/ModelDataTable/modals/index.js
+++ b/packages/builder/src/components/database/ModelDataTable/modals/index.js
@@ -1,6 +1,6 @@
export { default as DeleteRecordModal } from "./DeleteRecord.svelte"
export { default as CreateEditRecordModal } from "./CreateEditRecord.svelte"
-export { default as CreateEditModelModal } from "./CreateEditModel.svelte"
+export { default as CreateEditModelModal } from "./CreateEditModel/CreateEditModel.svelte"
export { default as CreateEditViewModal } from "./CreateEditView.svelte"
export { default as CreateDatabaseModal } from "./CreateDatabase.svelte"
export { default as CreateUserModal } from "./CreateUser.svelte"
diff --git a/packages/builder/src/components/nav/DatabasesList.svelte b/packages/builder/src/components/nav/DatabasesList.svelte
index b24a0c2d9a..4da787808a 100644
--- a/packages/builder/src/components/nav/DatabasesList.svelte
+++ b/packages/builder/src/components/nav/DatabasesList.svelte
@@ -6,16 +6,14 @@
import { CheckIcon } from "../common/Icons"
$: instances = $store.appInstances
- $: views = $store.hierarchy.indexes
+ // $: views = $store.hierarchy.indexes
async function selectDatabase(database) {
- backendUiStore.actions.records.select(null)
- backendUiStore.actions.views.select(views[0])
backendUiStore.actions.database.select(database)
}
async function deleteDatabase(database) {
- const DELETE_DATABASE_URL = `/_builder/instance/_master/0/api/record/applications/${$store.appId}/instances/${database.id}`
+ const DELETE_DATABASE_URL = `/api/instances/${database.id}`
const response = await api.delete(DELETE_DATABASE_URL)
store.update(state => {
state.appInstances = state.appInstances.filter(
diff --git a/packages/builder/src/components/nav/HierarchyRow.svelte b/packages/builder/src/components/nav/HierarchyRow.svelte
index c19f7f8cd7..db16275b33 100644
--- a/packages/builder/src/components/nav/HierarchyRow.svelte
+++ b/packages/builder/src/components/nav/HierarchyRow.svelte
@@ -10,7 +10,7 @@
const { open, close } = getContext("simple-modal")
- export let level = 0
+ // export let level = 0
export let node
export let type
@@ -27,31 +27,35 @@
}
})
- function selectHierarchyItem(node) {
- store.selectExistingNode(node.nodeId)
- const modalType =
- node.type === "index" ? CreateEditViewModal : CreateEditModelModal
- open(
- modalType,
- {
- onClosed: close,
- },
- { styleContent: { padding: "0" } }
- )
+ function selectModel(model) {
+ backendUiStore.update(state => {
+ state.selectedModel = model
+ state.selectedView = `all_${model._id}`
+ return state;
+ })
+ // store.selectExistingNode(node.nodeId)
+ // const modalType =
+ // node.type === "index" ? CreateEditViewModal : CreateEditModelModal
+ // open(
+ // modalType,
+ // {
+ // onClosed: close,
+ // },
+ // { styleContent: { padding: "0" } }
+ // )
}
selectHierarchyItem(node)}
+ on:click={() => selectModel(node)}
class="budibase__nav-item hierarchy-item"
class:capitalized={type === 'model'}
- style="padding-left: {20 + level * 20}px"
- class:selected={navActive}>
+ class:selected={$backendUiStore.selectedModel._id === node._id}>
{node.name}
- {#if node.children}
+