-
-
+ {#if loaded && enrichedApps.length}
+
+
+ Apps
+
+ Import app
+ Create new app
+
+
+
+
+
+
+
+ (layout = "grid")}
+ selected={layout === "grid"}
+ quiet
+ icon="ClassicGridView"
+ />
+ (layout = "table")}
+ selected={layout === "table"}
+ quiet
+ icon="ViewRow"
+ />
+
-
- (layout = "grid")}
- selected={layout === "grid"}
- quiet
- icon="ClassicGridView"
- />
- (layout = "table")}
- selected={layout === "table"}
- quiet
- icon="ViewRow"
- />
-
-
- {#if loaded && $apps.length}
- {#each $apps as app, idx (app.appId)}
+ {#each enrichedApps as app (app.appId)}
{/each}
- {/if}
-
- {#if !$apps.length && !creatingApp && loaded}
+
+ {/if}
+ {#if !enrichedApps.length && !creatingApp && loaded}
- Are you sure you want to delete the app {appToDelete?.name} ?
+ Are you sure you want to delete the app {selectedApp?.name} ?
+
+
+ Are you sure you want to unpublish the app {selectedApp?.name} ?
diff --git a/packages/builder/src/stores/portal/apps.js b/packages/builder/src/stores/portal/apps.js
index e0dfe112b5..f0cee6147c 100644
--- a/packages/builder/src/stores/portal/apps.js
+++ b/packages/builder/src/stores/portal/apps.js
@@ -1,15 +1,49 @@
import { writable } from "svelte/store"
import { get } from "builderStore/api"
+import { AppStatus } from "../../constants"
export function createAppStore() {
const store = writable([])
- async function load(status = "") {
+ async function load() {
try {
- const res = await get(`/api/applications?status=${status}`)
+ const res = await get(`/api/applications?status=all`)
const json = await res.json()
if (res.ok && Array.isArray(json)) {
- store.set(json)
+ // Merge apps into one sensible list
+ let appMap = {}
+ let devApps = json.filter(app => app.status === AppStatus.DEV)
+ let deployedApps = json.filter(app => app.status === AppStatus.DEPLOYED)
+
+ // First append all dev app version
+ devApps.forEach(app => {
+ const id = app.appId.substring(8)
+ appMap[id] = {
+ ...app,
+ devId: app.appId,
+ devRev: app._rev,
+ }
+ })
+
+ // Then merge with all prod app versions
+ deployedApps.forEach(app => {
+ const id = app.appId.substring(4)
+ appMap[id] = {
+ ...appMap[id],
+ ...app,
+ prodId: app.appId,
+ prodRev: app._rev,
+ }
+ })
+
+ // Transform into an array and clean up
+ const apps = Object.values(appMap)
+ apps.forEach(app => {
+ app.appId = app.devId.substring(8)
+ delete app._id
+ delete app._rev
+ })
+ store.set(apps)
} else {
store.set([])
}
diff --git a/packages/server/src/db/utils.js b/packages/server/src/db/utils.js
index 81686ea267..29617a7dff 100644
--- a/packages/server/src/db/utils.js
+++ b/packages/server/src/db/utils.js
@@ -18,9 +18,9 @@ const StaticDatabases = {
}
const AppStatus = {
- DEV: "dev",
+ DEV: "development",
ALL: "all",
- DEPLOYED: "PUBLISHED",
+ DEPLOYED: "published",
}
const DocumentTypes = {
diff --git a/packages/server/src/integrations/postgres.js b/packages/server/src/integrations/postgres.js
index c6a24577b3..d567db7ba0 100644
--- a/packages/server/src/integrations/postgres.js
+++ b/packages/server/src/integrations/postgres.js
@@ -1,4 +1,6 @@
-const { Client } = require("pg")
+const { Pool } = require("pg")
+
+let pool
const SCHEMA = {
docs: "https://node-postgres.com",
@@ -51,31 +53,39 @@ const SCHEMA = {
class PostgresIntegration {
constructor(config) {
this.config = config
- this.client = new Client(config)
- this.connect()
+ if (!pool) {
+ pool = new Pool(this.config)
+ }
}
- async connect() {
- return this.client.connect()
+ async query(sql) {
+ try {
+ this.client = await pool.connect()
+ return await this.client.query(sql)
+ } catch (err) {
+ throw new Error(err)
+ } finally {
+ this.client.release()
+ }
}
async create({ sql }) {
- const response = await this.client.query(sql)
+ const response = await this.query(sql)
return response.rows.length ? response.rows : [{ created: true }]
}
async read({ sql }) {
- const response = await this.client.query(sql)
+ const response = await this.query(sql)
return response.rows
}
async update({ sql }) {
- const response = await this.client.query(sql)
+ const response = await this.query(sql)
return response.rows.length ? response.rows : [{ updated: true }]
}
async delete({ sql }) {
- const response = await this.client.query(sql)
+ const response = await this.query(sql)
return response.rows.length ? response.rows : [{ deleted: true }]
}
}