Admin screens (/bweb/…)

The administration of a BWEB site (dashboard, domain settings, pages, translations, groups, imports and exports, models, reconciliation, parameters) is made of ordinary blocks: wrapper, fieldText, listbox, button… They are rendered by the same engine as a site page.

What differs is where the blocks live. They are not in the BSPK_WEB_CONTENT table but in encrypted JSON templates shipped with the component, held in memory as shared objects. Most problems on an admin screen come from forgetting one of these two facts.

Access rights (ADMIN_<SLUG>, the system group, system-only screens, access without a licence) are covered in Users and rights.

The list of screens

The Get_Url_Admin method holds the single list of routed screens (their "slug"):

dashboard, domain, domain-new, domain-seo, domain-redirects, domain-menu, domain-header, domain-footer, domain-sbl, domain-sbr, domain-error-default, domain-403, domain-404, localize, models, domain-groups, imports-exports, reconcile, parameters.

The list is copied into Storage.vo_WebParam.vc_UrlAdmin. A URL is an admin screen when its first segment is bweb and its second is in the list. The request then carries, on $vo_POST:

KeyValue
vb_IsUrlAdminTrue
vt_AdminModuleNamethe slug
vb_IsParamUrlTrue (slug in vc_UrlAdmin and first segment bweb)

Admin screens are rendered in the connected user's language (WebUser.lang, otherwise the session's vo_UserInfo.lang), not in the site's.

Adding a slug to Get_Url_Admin creates a route and an ADMIN_<SLUG> right at the next startup (BSPK_INSTALL_ADMIN_RIGHTS, naming rule in BSPK_ADMIN_RIGHT_REF). That is why templates that are not screens stay out of it.

Where the templates live

  • Files: Contents/Resources/json/<slug> in the component, with no extension and encrypted. They cannot be read in a text editor and have no readable git diff.
  • Reading: BSPK_FILE_Get_JSON_Content(<name>). With a short name it reads the component file and a host file of the same name (<host>/Resources/json/<name>, then <host>/Resources/<name>) and merges them, the host winning. With a full path it reads only that path, as a host file.
  • Loading: at startup, BSPK_LoadTpl fills Storage.vo_Tpl.admin[<slug>] for every slug of Get_Url_Admin, plus DefaultHome, Home, menu, model-capture, model-edit and model-new. A missing or unreadable file is logged (BSPK_LoadTpl : gabarit illisible ou absent -> <name>) and skipped: the screen then renders empty, with no error page.
  • Shape: the blocks are in vo_Objects, a collection of block objects with the same fields as a BSPK_WEB_CONTENT record (uuidKey, parentUuid, sortOrder, type, properties, cssProperties, events…). The optional vt_TableName key sets the process variable vt_TableName for the screen.
TemplateRole
the 19 slugs aboveone screen each
menuthe admin side menu, rendered by bspk/adminMenu.html through WebTemplate.adminMenu
model-capture, model-edit, model-newwindows opened by openAdminModal (below)
DefaultHome, Homecontent imported into the database when a domain is created (BSPK_WEB_DOMAIN), never rendered from memory

ToolBarDev, Format and STRUCTURE share the folder but are not loaded into Storage.vo_Tpl.admin.

Rendering: the same engine, from memory

For an admin URL, GG_PROCESS_COMPONENTS walks Storage.vo_Tpl.admin[<slug>].vo_Objects: it takes the roots (parentUuid = Null), orders them by sortOrder and renders each one with the "admin" context. Events and reloads find the blocks through BSPK_GET_WEB_CONTENTS_FROM_PAGE, which returns vo_Objects.copy() when vb_IsUrlAdmin and vb_IsParamUrl are both true. The security check uses the same source.

The shell is the domain's (tpl-page1 / tpl-page2), with three differences:

  • in bspk/head.html, only the admin stylesheet ($vo_R.vt_AdminCss, i.e. the component's assets/css/admin/bweb-admin.css) is injected; the site's own head HTML (custom CSS, domain CSS and JS) is not loaded;
  • no domain header, footer or sidebars: the admin menu replaces them;
  • the domain's header, footer and sidebar blocks are not added to the block list.

Overriding a screen from the host

A file <host>/Resources/json/<slug> wins over the component's template for that host, with no sign on screen. That is how you customise a screen for a project. If you did not mean it, delete the file.

  • Writing with BSPK_FILE_SET_JSON_CONTENT(<short name>; …) from your own code writes into the host resources: a local override that is never delivered with the component.
  • Templates are read at startup by BSPK_LoadTpl. A changed file is only served after the templates are reloaded or 4D restarts: until then Storage.vo_Tpl keeps the old text without telling you. The same goes for bspk/*.html files and schemas.
  • The component's templates are tracked by git: to recover a version, use git log / git show on Resources/json/<slug>.

Windows opened from the dev panel: openAdminModal

Templates listed in GG_ADMIN_MODAL_SLUGS (model-capture, model-edit, model-new) are rendered on demand into a window by WebFormController.openAdminModal:

  • opening is allowed from a site page if BSPK_CAN_EDIT_PAGE, or from any /bweb/* screen;
  • vo_Context.pk (or the trigger's vt_RowPk) together with vt_TableName sets Entity, which fields bound to the module entity read; without them the window opens with empty fields;
  • the action pushed to the browser is {vt_Action: "openAdminModal"; vt_Slug; vt_Html; vo_Context}.

A button inside such a window is not part of the page. It is only accepted if it exists in one of those templates and the requested class and function are the ones that template declares on that block's onClick (GG_ADMIN_MODAL_TRIGGER_OK). To add a window, add its slug to GG_ADMIN_MODAL_SLUGS and to the extra lists of BSPK_LoadTpl: these lists are kept aligned by hand.

The domain-menu template is also reused outside its screen: the Pages tab of the dev panel renders it on a site page and sends vt_AdminTplName: "domain-menu" (attribute data-admintpl), accepted only with BSPK_CAN_EDIT_PAGE.

Pitfalls

The blocks are shared objects

Storage.vo_Tpl is a shared object. Any code that modifies a block it received during an admin render raises "Un objet partagé a besoin d'un Utiliser…" and the whole screen fails. The engine copies before normalising; your code must do the same:

  • OB Copy a template before touching it (openAdminModal does);
  • .copy() a collection before query() or any change;
  • a vt_DynamicColumnsFunction receives the block's own vc_FieldDisplay: work on a .copy(). Changing it in place corrupts the in-memory template for every process, and a later write of the template saves that corruption to disk (columns missing or duplicated).

reloadBlock without $vo_POST reloads nothing

With no options, WebFormController.reloadBlock($name) looks the block up in the table. An admin block is not there: nothing is pushed, no error, the success toast still shows, and the screen stays stale until F5. Always pass the POST, which carries vb_IsUrlAdmin, vb_IsParamUrl and vt_AdminModuleName:

$vo_WebResponse.reloadBlock("myList"; $vo_POST)

No modal block on an admin screen

Use a fake modal: a wrapper with class bweb-admin-modal (fixed overlay, hidden), shown by adding the class is-open, containing a bweb-admin-modal-form card (styles in assets/css/admin/bweb-admin.css). It is opened and closed by a <script> in a text block. There is no native close cross: add a Close button. The domain-redirects template is the reference implementation. See also WebFormController.

customClass in a template

properties.customClass has no effect in a template. The class goes in cssProperties.<target>.default.default.customClass. It lands on the <bspk> wrapper, not on the rendered element (see Styling: CSS cube and Tailwind).

Labels: the translation key must exist in four files

Admin labels are translation keys (BSPK_…). The host's Resources/lang/<lg>/BSPK.json overrides the component's Resources/Misc/lang/<lg>/BSPK.json. A new key goes into the component and the host (fr and en), then BSPK_REFRESH_STORAGE. A missing key renders an empty label, with no error. See Translations.

See also