mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-17 18:32:35 +00:00
Resolve "Create initial application builder structure"
This commit is contained in:
parent
2a5dd65774
commit
5dc9cc8b75
22 changed files with 215 additions and 31 deletions
backend/src/baserow
config/settings
contrib/builder
web-frontend
config
locales
modules
|
@ -14,6 +14,21 @@ from corsheaders.defaults import default_headers
|
|||
|
||||
from baserow.version import VERSION
|
||||
|
||||
# A comma separated list of feature flags used to enable in-progress or not ready
|
||||
# features for developers. See docs/development/feature-flags.md for more info.
|
||||
FEATURE_FLAGS = [
|
||||
flag.strip().lower() for flag in os.getenv("FEATURE_FLAGS", "").split(",")
|
||||
]
|
||||
|
||||
|
||||
class Everything(object):
|
||||
def __contains__(self, other):
|
||||
return True
|
||||
|
||||
|
||||
if "*" in FEATURE_FLAGS:
|
||||
FEATURE_FLAGS = Everything()
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
BASEROW_PLUGIN_DIR_PATH = Path(os.environ.get("BASEROW_PLUGIN_DIR", "/baserow/plugins"))
|
||||
|
@ -64,6 +79,9 @@ INSTALLED_APPS = [
|
|||
*BASEROW_BUILT_IN_PLUGINS,
|
||||
]
|
||||
|
||||
if "builder" in FEATURE_FLAGS:
|
||||
INSTALLED_APPS.append("baserow.contrib.builder")
|
||||
|
||||
BASEROW_FULL_HEALTHCHECKS = os.getenv("BASEROW_FULL_HEALTHCHECKS", None)
|
||||
if BASEROW_FULL_HEALTHCHECKS is not None:
|
||||
INSTALLED_APPS += ["health_check.storage", "health_check.contrib.psutil"]
|
||||
|
@ -652,21 +670,6 @@ BASEROW_SNAPSHOT_EXPIRATION_TIME_DAYS = int(
|
|||
os.getenv("BASEROW_SNAPSHOT_EXPIRATION_TIME_DAYS", 360) # 360 days
|
||||
)
|
||||
|
||||
# A comma separated list of feature flags used to enable in-progress or not ready
|
||||
# features for developers. See docs/development/feature-flags.md for more info.
|
||||
FEATURE_FLAGS = [
|
||||
flag.strip().lower() for flag in os.getenv("FEATURE_FLAGS", "").split(",")
|
||||
]
|
||||
|
||||
|
||||
class Everything(object):
|
||||
def __contains__(self, other):
|
||||
return True
|
||||
|
||||
|
||||
if "*" in FEATURE_FLAGS:
|
||||
FEATURE_FLAGS = Everything()
|
||||
|
||||
PERMISSION_MANAGERS = [
|
||||
"view_ownership",
|
||||
"core",
|
||||
|
|
7
backend/src/baserow/contrib/builder/application_types.py
Executable file
7
backend/src/baserow/contrib/builder/application_types.py
Executable file
|
@ -0,0 +1,7 @@
|
|||
from baserow.contrib.builder.models import Builder
|
||||
from baserow.core.registries import ApplicationType
|
||||
|
||||
|
||||
class BuilderApplicationType(ApplicationType):
|
||||
type = "builder"
|
||||
model_class = Builder
|
12
backend/src/baserow/contrib/builder/apps.py
Normal file
12
backend/src/baserow/contrib/builder/apps.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class BuilderConfig(AppConfig):
|
||||
name = "baserow.contrib.builder"
|
||||
|
||||
def ready(self):
|
||||
from baserow.core.registries import application_type_registry
|
||||
|
||||
from .application_types import BuilderApplicationType
|
||||
|
||||
application_type_registry.register(BuilderApplicationType())
|
|
@ -0,0 +1,36 @@
|
|||
# Generated by Django 3.2.13 on 2023-02-03 16:20
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
("core", "0042_add_ip_address_to_jobs"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Builder",
|
||||
fields=[
|
||||
(
|
||||
"application_ptr",
|
||||
models.OneToOneField(
|
||||
auto_created=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
parent_link=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
to="core.application",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"abstract": False,
|
||||
},
|
||||
bases=("core.application",),
|
||||
),
|
||||
]
|
7
backend/src/baserow/contrib/builder/models.py
Normal file
7
backend/src/baserow/contrib/builder/models.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from baserow.core.models import Application
|
||||
|
||||
__all__ = ["Builder"]
|
||||
|
||||
|
||||
class Builder(Application):
|
||||
pass
|
|
@ -1,3 +1,8 @@
|
|||
import {
|
||||
featureFlagIsEnabled,
|
||||
getFeatureFlags,
|
||||
} from '../modules/core/utils/env'
|
||||
|
||||
export default function (
|
||||
base = '@',
|
||||
premiumBase = '@/../premium/web-frontend',
|
||||
|
@ -23,6 +28,12 @@ export default function (
|
|||
enterpriseBase + '/modules/baserow_enterprise/module.js',
|
||||
]
|
||||
|
||||
const featureFlags = getFeatureFlags()
|
||||
|
||||
if (featureFlagIsEnabled(featureFlags, 'builder')) {
|
||||
baseModules.push(base + '/modules/builder/module.js')
|
||||
}
|
||||
|
||||
const modules = baseModules.concat(additionalModules)
|
||||
return {
|
||||
modules,
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
"applicationType": {
|
||||
"database": "Database",
|
||||
"databaseDefaultName": "Untitled Database",
|
||||
"builder": "Application",
|
||||
"builderDefaultName": "Untitled Application",
|
||||
"cantSelectTableTitle": "Couldn't select the database.",
|
||||
"cantSelectTableDescription": "The database couldn't be selected because it doesn't have any tables. Use the sidebar to create one."
|
||||
},
|
||||
|
|
21
web-frontend/modules/builder/applicationTypes.js
Normal file
21
web-frontend/modules/builder/applicationTypes.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { ApplicationType } from '@baserow/modules/core/applicationTypes'
|
||||
|
||||
export class BuilderApplicationType extends ApplicationType {
|
||||
static getType() {
|
||||
return 'builder'
|
||||
}
|
||||
|
||||
getIconClass() {
|
||||
return 'desktop'
|
||||
}
|
||||
|
||||
getName() {
|
||||
const { i18n } = this.app
|
||||
return i18n.t('applicationType.builder')
|
||||
}
|
||||
|
||||
getDefaultName() {
|
||||
const { i18n } = this.app
|
||||
return i18n.t('applicationType.builderDefaultName')
|
||||
}
|
||||
}
|
1
web-frontend/modules/builder/locales/de.json
Normal file
1
web-frontend/modules/builder/locales/de.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
1
web-frontend/modules/builder/locales/en.json
Normal file
1
web-frontend/modules/builder/locales/en.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
1
web-frontend/modules/builder/locales/es.json
Normal file
1
web-frontend/modules/builder/locales/es.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
1
web-frontend/modules/builder/locales/fr.json
Normal file
1
web-frontend/modules/builder/locales/fr.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
1
web-frontend/modules/builder/locales/it.json
Normal file
1
web-frontend/modules/builder/locales/it.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
1
web-frontend/modules/builder/locales/nl.json
Normal file
1
web-frontend/modules/builder/locales/nl.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
1
web-frontend/modules/builder/locales/pl.json
Normal file
1
web-frontend/modules/builder/locales/pl.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
3
web-frontend/modules/builder/middleware.js
Normal file
3
web-frontend/modules/builder/middleware.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
/**
|
||||
* Nothing here yet
|
||||
*/
|
28
web-frontend/modules/builder/module.js
Normal file
28
web-frontend/modules/builder/module.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
import path from 'path'
|
||||
|
||||
import { routes } from './routes'
|
||||
import en from './locales/en.json'
|
||||
import fr from './locales/fr.json'
|
||||
import nl from './locales/nl.json'
|
||||
import de from './locales/de.json'
|
||||
import it from './locales/it.json'
|
||||
import es from './locales/es.json'
|
||||
import pl from './locales/pl.json'
|
||||
|
||||
export default function BuilderModule(options) {
|
||||
this.addPlugin({ src: path.resolve(__dirname, 'middleware.js') })
|
||||
|
||||
// Add the plugin to register the database application.
|
||||
this.appendPlugin({
|
||||
src: path.resolve(__dirname, 'plugin.js'),
|
||||
})
|
||||
|
||||
// Add all the related routes.
|
||||
this.extendRoutes((configRoutes) => {
|
||||
configRoutes.push(...routes)
|
||||
})
|
||||
|
||||
this.nuxt.hook('i18n:extend-messages', function (additionalMessages) {
|
||||
additionalMessages.push({ en, fr, nl, de, it, es, pl })
|
||||
})
|
||||
}
|
26
web-frontend/modules/builder/plugin.js
Normal file
26
web-frontend/modules/builder/plugin.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { BuilderApplicationType } from '@baserow/modules/builder/applicationTypes'
|
||||
import en from '@baserow/modules/builder/locales/en.json'
|
||||
import fr from '@baserow/modules/builder/locales/fr.json'
|
||||
import nl from '@baserow/modules/builder/locales/nl.json'
|
||||
import de from '@baserow/modules/builder/locales/de.json'
|
||||
import es from '@baserow/modules/builder/locales/es.json'
|
||||
import it from '@baserow/modules/builder/locales/it.json'
|
||||
import pl from '@baserow/modules/builder/locales/pl.json'
|
||||
|
||||
export default (context) => {
|
||||
const { app, isDev } = context
|
||||
|
||||
// Allow locale file hot reloading in dev
|
||||
if (isDev && app.i18n) {
|
||||
const { i18n } = app
|
||||
i18n.mergeLocaleMessage('en', en)
|
||||
i18n.mergeLocaleMessage('fr', fr)
|
||||
i18n.mergeLocaleMessage('nl', nl)
|
||||
i18n.mergeLocaleMessage('de', de)
|
||||
i18n.mergeLocaleMessage('es', es)
|
||||
i18n.mergeLocaleMessage('it', it)
|
||||
i18n.mergeLocaleMessage('pl', pl)
|
||||
}
|
||||
|
||||
app.$registry.register('application', new BuilderApplicationType(context))
|
||||
}
|
1
web-frontend/modules/builder/routes.js
Normal file
1
web-frontend/modules/builder/routes.js
Normal file
|
@ -0,0 +1 @@
|
|||
export const routes = []
|
|
@ -1,19 +1,12 @@
|
|||
import {
|
||||
featureFlagIsEnabled,
|
||||
getFeatureFlags,
|
||||
} from '@baserow/modules/core/utils/env'
|
||||
|
||||
export default function ({ app }, inject) {
|
||||
// A comma separated list of feature flags used to enable in-progress or not ready
|
||||
// features for developers. See docs/development/feature-flags.md for more info.
|
||||
const FEATURE_FLAGS = (app.$env.FEATURE_FLAGS || '')
|
||||
.split(',')
|
||||
.map((flag) => flag.trim().toLowerCase())
|
||||
const FEATURE_FLAGS = getFeatureFlags(app.$env)
|
||||
|
||||
const ENABLE_ALL_FLAG = '*'
|
||||
|
||||
function featureFlagIsEnabled(flag) {
|
||||
if (FEATURE_FLAGS.includes(ENABLE_ALL_FLAG)) {
|
||||
return true
|
||||
} else {
|
||||
return FEATURE_FLAGS.includes(flag.toLowerCase())
|
||||
}
|
||||
}
|
||||
|
||||
inject('featureFlagIsEnabled', featureFlagIsEnabled)
|
||||
inject('featureFlagIsEnabled', (flag) =>
|
||||
featureFlagIsEnabled(FEATURE_FLAGS, flag)
|
||||
)
|
||||
}
|
||||
|
|
27
web-frontend/modules/core/utils/env.js
Normal file
27
web-frontend/modules/core/utils/env.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* A comma separated list of feature flags used to enable in-progress or not ready
|
||||
* features for developers. See docs/development/feature-flags.md for more info
|
||||
* @param env: The environment that should be used to get the flags from
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export function getFeatureFlags(env = process.env) {
|
||||
return (env.FEATURE_FLAGS || '')
|
||||
.split(',')
|
||||
.map((flag) => flag.trim().toLowerCase())
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a feature is enabled
|
||||
* @param featureFlags: The list of feature flags
|
||||
* @param flag: The flag that is being checked for
|
||||
* @returns {boolean|*}
|
||||
*/
|
||||
export function featureFlagIsEnabled(featureFlags, flag) {
|
||||
const ENABLE_ALL_FLAG = '*'
|
||||
|
||||
if (featureFlags.includes(ENABLE_ALL_FLAG)) {
|
||||
return true
|
||||
} else {
|
||||
return featureFlags.includes(flag.toLowerCase())
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue