d2aura
v26.1.11
Published
D2 AURA - Advanced User Interface Resource Architecture
Downloads
5,204
Readme
d2aura
D2 AURA — Advanced User Interface Resource Architecture.
A TypeScript + React component and API library for building web front-ends on top of the
Ipesoft D2000 SCADA system. It wraps the low-level D2000 web API (d2jsapi) into D2000-aware
application scaffolding (connection lifecycle, authentication, RPC with the D2000 error contract,
CRUD over D2000 Event objects) and a set of Ant Design based components — data grids, editors,
charts, advanced filters, file pickers, web-push management and the full EDA Manager
(energy data bank vectors, groups, scenarios and the EDA-L editor).
Installation
yarn add d2aurareact and react-dom (18.x) must be provided by the application. The D2000 stack packages
d2jsapi, d2core, d2coreui, antd and @ant-design/pro-layout are regular dependencies of
d2aura and are installed with it.
Usage
Imports are bare subpath specifiers — the package has no barrel entry point, import exactly the module you need:
import "d2coreui/style/index.less"
import "flexlayout-react/style/light.scss"
import "d2coreui/style/flexLayout/flexLayout.scss"
import "d2coreui/style/splitPane/splitPane.css"
import AbstractApp, {AbstractAppProps, AbstractAppState} from "d2aura/coreui/abstractApp";
import AbstractApi from "d2aura/api/abstractApi";Application shell
Subclass AbstractApp. It creates the D2WebApiClient, wires the error / service-message /
password-change handlers, connects, and calls back when the connection is up — that is where the
application builds its API objects. It also provides the About and Change-Password modals and the
loading spinner.
export default class App extends AbstractApp<AbstractAppProps, AbstractAppState> {
// build API objects on connect, render ProLayout + routes
}User settings (AuraConfig)
Settings a user changes in the application and finds again on the next login - a common value per setting type, plus one of its own for a component the programmer gives a UUID.
core/auraConfig/auraSettings—defineSettingregisters a setting type (key, category, factory defaults, fields of the dialog);AuraSettingsStorecaches the user's records and writes them through anAuraSettingsBackend, or through a fallback backend once loading from it fails. The cache changes at once, the backend gets the changes together after a second without another one (at the latest after 5 s);AbstractAppflushes them when the page is hidden.api/d2000AuraSettingsBackend— a backend keeping the records on the D2000 server (E.AURA_SETTINGS, see AuraConfig — D2000 server-side storage).core/auraConfig/localStorageAuraSettingsBackend— a backend keeping the records in the browser'slocalStorage.coreui/components/auraConfig/auraConfig—AuraConfigProvider;useAuraSetting(descriptor, uuid, title, defaults?, fixed?)in a component (announces it to the dialogs),useResolvedSetting(store, descriptor, …)to only read a value,useAuraSettingsStore()(outside the provider a store kept in memory until the page reloads) and its deprecated hook-free twingetAuraSettingsStore()for class components only;AuraConfigButton(⚙ of one component) andAuraGlobalSettingsButton(global settings, for the header). The settings dialog writes the changes on Apply or OK, Cancel discards them after a confirmation.- Categories:
APP(an application setting),PREFERENCE(a preference the user sets in a dialog),DEFAULT(how a component opens - set in a dialog, read once, what the user changes in the component is not stored) andSTATE(what a component keeps itself - tabs, table layouts; the dialog can clear it). perInstanceof a type:true(default) a common value plus one per UUID,falsethe common value only,"only"per UUID only - no common value and not in the global dialog.- Layers of a value: factory values (
defaultsof the setting type <setSettingDefaults(descriptor, {...})for the whole application, once at the start, before the first render <defaultsof one component) < the user's common value < the user's value of the UUID <fixedof the component (read-only in the dialog). - The
/path of the key lays the global dialog out:ais an item of its menu,a/ba card of it,a/b/ca section of the card. A typea/bwithout fields that has types under it is a tab of the pageainstead, with the cardsa/b/c. The menu items are ordered by their translated title, the tabs, cards and sections byorderof the type (lower first), the ones without it by the title. Titles, labels andsections (headings of a group of fields) arei18nkeys.
AbstractApp creates the store as soon as the connection knows the user, and a new one when another user logs in
(state.auraSettings). By default it keeps the settings on the D2000 server; when loading from it fails (the objects
of d2configuration/auraConfig/ are not imported, the database is unavailable, …), the localStorage of the browser
takes over until the next login - override createAuraSettingsBackend / createAuraSettingsFallbackBackend for other
storages. The settings dialogs show in their title where the settings are kept, and the provider warns the user
with a message when the fallback took over. The application wraps its content in renderAuraConfig, inside its
ConfigProvider - without it the components keep their settings in memory only, until the page reloads; only
aura.app (the theme, the UTC offset) is still read from the store of AbstractApp:
<ConfigProvider locale={LocaleHolder.uiLocale} theme={this.getThemeConfig()}>
{this.renderAuraConfig(
<ProLayout actionsRender={() => <AuraGlobalSettingsButton/>}>
...
</ProLayout>
)}
</ConfigProvider>A setting type is typed by its value - inferred from defaults, or declared as an interface (required for a Color
field). fields has a field of a matching editor for every property, in the order of the dialog:
interface GraphSetting {
showLegend: boolean
background: Color
}
export const GRAPH_SETTING = defineSetting<GraphSetting>({
key: "consumption/graph",
title: "Graph",
category: Category.PREFERENCE,
defaults: {showLegend: true, background: ""},
fields: {
showLegend: {label: "Legend", type: FieldType.BOOLEAN},
background: {label: "Background", type: FieldType.COLOR},
},
});
const {showLegend} = useAuraSetting(GRAPH_SETTING, uuid, "Consumption").resolved.value; // booleanA field takes an optional description, shown under its label. A value none of the built-in editors fits gets an editor
of its own - {type: FieldType.CUSTOM, editor, isValid?}, where editor is a React component of FieldEditorProps
(value, disabled, onChange) and isValid checks a stored value; PageSizeEditor
(coreui/components/grid/pageSizeEditor) is one.
When the shape of a stored value changes (a renamed or restructured field, a changed meaning), raise version of the
type and add a step to every new version to migrations. A stored value of a lower version passes the steps one after
another as soon as it is loaded (1 → 2 → 3) and is saved back in the new version at once. A removed field or a value
its field no longer accepts needs no new version, it is skipped; a value of a higher version (a newer application on
the same server) is read as it is:
export const GRAPH_SETTING = defineSetting<GraphSetting>({
key: "consumption/graph",
version: 2,
migrations: {
2: ({legend, ...value}) => legend === undefined ? value : {...value, showLegend: legend},
},
...
});The global settings of the application are one setting type, aura.app (APP_SETTING,
coreui/components/appSettings/appSetting): the theme - changeTheme writes it and a change in the global settings
dialog switches the theme of the application - and the UTC offset mode of the date-time masks, which AbstractApp
passes to LocaleHolder.setUtcOffsetMode. An application changes their factory values with setSettingDefaults.
ThemeSelect is deprecated - the theme is changed in the global settings dialog.
The list panels have the common setting listPanel (LIST_PANEL_SETTING,
coreui/components/listPanel/listPanelSettings): labels of the toolbar buttons of AbstractListPanel and the advanced
filter button (off by default, never on a mobile screen) and its page title (shown by default). A subclass renders its
own buttons as ListPanelToolbarButton (coreui/components/listPanel/listPanelToolbarButton) to follow it - its
label is the short text next to the icon, the title stays the tooltip.
AuraExtendedDataGrid (coreui/components/grid/auraExtendedDataGrid) is an ExtendedDataGrid with its configuration
in the user settings (coreui/components/grid/gridSettings): grid (GRID_SETTING, common plus per UUID - font size,
line indentation, background of every other row), grid/header (GRID_HEADER_SETTING, common only - compact header:
no column menu button, the menu opens by a right click; off by default, the compactHeader prop of a grid overrides it),
the styles of its row style rules (rowStyleSetting, see below),
grid/dateTimeFormat (GRID_DATE_TIME_SETTING, common plus per UUID -
year, milliseconds; the UTC offset is that of aura.app), grid/layout (GRID_LAYOUT_SETTING, under the UUID only -
page size, column filter, columns) and grid/search (GRID_SEARCH_SETTING, under the UUID only - the search history,
unless search.searchHistory is given). defaultGridConfiguration is the factory configuration under them. With a uuid
its settings menu opens the settings dialog of the grid instead of the d2coreui table settings, without one the menu
has no advanced settings. The grid reads its
configuration only when it mounts, so a change from outside (the dialog, a reset) mounts it again - the selection and
the scroll position are lost.
The row style rules of a grid come with the setting type of their styles - defineRowStyleSetting(key, title, rules)
(coreui/components/grid/rowStyleSetting), called on the module level and passed as rowStyleSetting. It has a
field for every rule whose styleEditor allows something, edited as a row of the row styling of ExtendedDataGrid
(RowStyleEditor - text color, background, bold, font size, line indentation, whichever the rule allows), labelled
by the rule's name, grouped by its divider, its factory value from the rule's style; the rules table-font-size and table-line-indentation are
those of grid and the grid adds them when missing. A common value plus an exception per grid UUID; the key
grid/rowStyle/<name> makes it a card of Tables in the global dialog. Without rowStyleSetting the rules are
tableDefaultRowStyleRules; defaultGridConfiguration has no row style rules.
export const ALARM_ROW_STYLE_SETTING = defineRowStyleSetting("grid/rowStyle/alarm", "Alarms", alarmRowStyleRules);
<AuraExtendedDataGrid rowStyleSetting={ALARM_ROW_STYLE_SETTING} uuid="..." .../>AbstractListPanel renders the grid with its own uuid and AUDIT_ROW_STYLE_SETTING (grid/rowStyle/audit - the
valid and the deleted records; getRowStyleSetting to change it); its layout is no longer part of the
page configuration in localStorage. The history of the list keeps its layout under <uuid>/history,
AbstractSelectModalDialog under its uuid and AbstractEntitiesOnEntityList under its uuid prop (shared by its
fullscreen dialog); the condition list of the advanced filter has none.
The advanced filter settings live in coreui/components/advancedFilter/advancedFilterSettings. An AbstractListPanel /
AbstractSelectModalDialog with a uuid keeps its active filter under it (advancedFilter/active,
ADVANCED_FILTER_SETTING, perInstance: "only"); without one the filter lasts only as long as the component. The named
filters of the filter button (save, load, rename, delete) are kept under the uuid of the list as well
(advancedFilter/saved, ADVANCED_FILTER_SAVED_SETTING, perInstance: "only"); without one saving and loading are
disabled. Neither is in the global settings dialog, both are in the dialog of the list.
AdvancedFilterConfig.listName, AdvancedFilterListNameEnum, AdvancedFilterApi (E.AR_Filter) and the
advancedFilterApi props are deprecated and unused.
EDA Manager configuration
The EDA Manager components (EdaManager, EdaDetail, EdaNavigator, EdaSelect) take their configuration only
through their configuration prop - charts, column modifiers, page sizes, the default EDA-L prescription; a component
used inside another one inherits the outer configuration. What the user chooses or changes is kept in the user settings
under eda/… (the EDA manažér page of the global dialog): date-time formats, mouse zoom, how the detail and the
navigator open, table layouts, navigator tabs, saved intervals, the EDA-L workspace. An application changes their
factory values with setSettingDefaults (e.g. EDA_DATE_TIME_SETTING), one EdaDetail with
configuration.userDefaults / fixedSettings; an EdaDetail with a uuid keeps its own settings, edited in its ⚙.
The full reference is the D2000 documentation page D2 AURA - Konfigurácia EDA manažéra.
API layer
api/abstractApi— base for all API classes.callRpc()is the central RPC wrapper: it appends the D2000 convention trailing parametersisOk(BOOL) +errorMessage(TEXT), decodes them and automatically shows an error dialog unlessskipCheckError*is set. It also caches structure definitions and converts unival records. Call RPCs through this rather than throughd2jsapidirectly.api/abstractEntityApi— CRUD over a D2000 Event object: pass(entityClassName, eventName, structureDefinitionName, entityFields)and get create / list / subscribe helpers that marshal rows to and from D2000 unival structures.- Specialised APIs:
api/advancedFilterApi,api/eda/edaManagerApi,api/webPush/webPushApi;api/edaApiandapi/archiveApiare deprecated in favour ofapi/eda/edaManagerApi.
Conventions
- D2000 booleans are not JS booleans — convert with
D2BooleanUtils(api/util/d2Boolean). - Time uses
UnixTime(d2core/types/unixTime), notDate. - Mobile layout:
isMobile()(coreui/layout/responsiveUtils) andResponsiveCol(coreui/layout/responsiveCol) use the antdsmbreakpoint (576 px), the same asAbstractListPanel, so the code and the grid agree on what is mobile. - i18n: strings are wrapped with
i18n(...)fromd2core/i18n/i18n; the translation JSON ships incore/i18n/(d2aura.sk.json,d2aura.en.json, …) and is loaded dynamically by the app.
Build configuration of the application
The package is plain ES modules and builds with webpack 5 and vite alike. Its web workers (the EDA-L
analysis and monaco's editor.worker) are standard new Worker(new URL(..., import.meta.url)) entry points both
bundlers pick up on their own — no worker plugin and no Node polyfill is needed. An application that configures
monaco's workers itself (MonacoEnvironment) keeps its own setup.
webpack — emitting chunks into a subdirectory (chunkFilename: "scripts/[name].js") requires
output.publicPath: "auto"; with a relative "./" a worker looks for its chunks relative to itself. An existing
ThreadsPlugin / MonacoWebpackPlugin may stay, it is just no longer necessary.
vite — the dev server serves the workers of d2aura and d2coreui from node_modules as they are, so their
CommonJS dependencies (threads, pdfmake, lodash) have to be pre-bundled: add the worker files to optimizeDeps.entries
(node_modules/d2coreui/components/grid/export/worker/*.js, and for the EDA Manager
node_modules/d2aura/coreui/components/edaManagerComponent/dialogs/edaLanguage/{worker/edaWorker,monacoEditorWorker}.js).
A production build needs nothing. See app_template/vite.config.ts of the d2aura repository.
smartWebAppConfig from d2aura/vite.mjs provides this and the rest of the configuration of a SmartWeb application
(login.html + pages/index.html) — dev server in front of SmartWeb (SMARTWEB_URL in .env / .env.local), login
redirects, in-place updates of class components, build: defineConfig((env) => smartWebAppConfig(env, {root: 'app'})).
Dynamic imports of the translation JSON return a module namespace — pass its .default to i18n.translator.add.
EDA Manager — D2000 server-side prerequisites
d2configuration/edaManager/ contains the D2000 object XML exports (DB.*, DBC_*, E.*, EM.EVH,
I.*, SD.*, SV.*) for the EDA Manager's server-side objects. All six steps below are required —
the EDA Manager does not work with the import alone.
E.EDA_Connect_EM exists only to bring the EDA connection unit into EM.EVH, so that the EDA API is usable
from the EDA Manager's events.
1. The server must have EDA installed
The exports reference the standard D2000 EDA API — the EDA_* external functions (EDA_CreateVectorRec,
EDA_ReadValuesFromVektorRec, EDA_SetFunctionRec, …) and the SD.EDA_* parameter structures. These are not
shipped here; they must already exist on the target server, otherwise the import fails with object reference
can not be found. The EDA connection unit is not among them — its name is application-specific, see step 3.
2. Import the objects
Import the whole d2configuration/edaManager/ directory in D2000 CNF in one go — dependencies are
resolved against the objects in the same import, so no particular order is needed.
3. Point E.EDA_Connect_EM at the EDA connection unit
This is the one export you must edit, and it is easy to forget. E.EDA_Connect_EM ships with its UNIT
line commented out and the unit name left as a #…# placeholder — the unit that logs in to the EDA server is
application-specific, and no name can be guaranteed to exist on the target server, so the export carries no
reference to it. The #EDIT marker is the spot:
; @SUPPRESS unusedVariable
#EDIT
; UNIT (#E.EDA_Connect_Unit#) _UNITReplace the placeholder with the unit on your server that performs the EDA initialisation (login to the EDA
server), uncomment the UNIT line and remove the #EDIT line:
; @SUPPRESS unusedVariable
UNIT (E.My_EDA_Connect_Unit) _UNITKeep the @SUPPRESS unusedVariable line above it: the unit is included for its initialisation, _UNIT is
never referenced.
Left commented out, everything imports and starts cleanly, but no EDA call from the EDA Manager's events ever reaches the EDA server.
4. Configure and start EM.EVH
All E.* objects have EM.EVH as their parent and come up with it. The shipped export is deliberately
unconfigured — START is False, path and working directory are empty; the command line is
/F60 /FI0 /TP /DW /WEM. Configure it in CNF and start it.
5. Configure DBC_EM_EDA
DBC_EM_EDA is a DB_CONNECT under SELF.DBM and must be pointed at the EDA database — the same schema
the EDA server uses.
6. Implement I.EM_INTERFACE and fill SV.EM_INTERFACE
I.EM_INTERFACE is the seam between the EDA Manager and the hosting application. Everything the EDA Manager
cannot decide for itself — ID allocation and code generation for new vectors, groups and scenarios — goes
through it, so that the shipped objects carry no reference to any application object.
Implement it in an EVENT object of your own:
IMPLEMENTATION I.EM_INTERFACE
IMPLEMENTATION RPC PROCEDURE I.EM_INTERFACE^GetVectorID(INT _nextId, BOOL _isOk)
; allocate the next free EDA vector ID
EXCEPTION_HANDLER
_isOk := @FALSE
END GetVectorID
BEGIN
PRAGMA "ENABLE_INOUT_BY_REF"
ENDThe procedures return their results through INOUT parameters, so the implementing script needs
PRAGMA "ENABLE_INOUT_BY_REF".
All seven procedures must be implemented — GetVectorID, GetGroupID, GetScenarioID,
GetVectorScenarioID, GetVectorCode, GetGroupCode, GetScenarioCode. The full skeleton is in the interface's own text
(the <description> element of I.EM_INTERFACE.xml), not in the object description.
Then set the two columns of SV.EM_INTERFACE (shipped with no start values):
| Column | Value |
|---|---|
| Event | your implementing EVENT object |
| Process | the .EVH process that event runs on |
Without them the EDA Manager cannot create vectors, groups or scenarios.
Do not edit the exports
EM.EVH, DBC_EM_EDA, SV.EM_INTERFACE and the UNIT line of E.EDA_Connect_EM are the only
configuration points. Everything else (E.*, SD.*, DB.*, I.EM_INTERFACE)
is a static export that must be imported as-is: editing the E.* scripts forks the EDA Manager and the next
d2aura upgrade will overwrite it. Application-specific behaviour belongs in your I.EM_INTERFACE
implementation.
AuraConfig — D2000 server-side storage
d2configuration/auraConfig/ contains the D2000 objects that keep the user settings (AuraConfig) in a database
table, so that they follow the user to any computer:
| Object | Type | Purpose |
|---|---|---|
| AURA.EVH | process | runs E.AURA_SETTINGS |
| E.AURA_SETTINGS | event | RPC procedures Load and Save |
| DBC_AURA | DB_CONNECT under SELF.DBM | the database of the table |
| DB.AURA_UserSetting | DB_TABLE | the table AURA_USER_SETTINGS |
| SD.AURA_UserSetting | structure | a row of the table, also the RPC parameter |
| I.AURA_INTERFACE | ESL interface | decides whose settings a client loads and saves, implemented by the application |
| SV.AURA_INTERFACE, SD.AURA_INTERFACE | structured variable and its structure | the implementing event and its process |
AbstractApp uses them by default (D2000AuraSettingsBackend); on a server without them the settings are kept in
the localStorage of the browser and the settings dialogs show Server unavailable.
1. Create the table
The import does not create the table. Create AURA_USER_SETTINGS in the database DBC_AURA will point at - one row
per user, setting type and * / component UUID, the value is the JSON of the changed fields:
PostgreSQL:
CREATE TABLE AURA_USER_SETTINGS (
USER_NAME VARCHAR(255) NOT NULL,
SETTING_KEY VARCHAR(255) NOT NULL,
INSTANCE_ID VARCHAR(255) NOT NULL,
SETTING_VALUE TEXT NOT NULL,
DATE_CH TIMESTAMP(3),
SETTING_VERSION INTEGER,
CONSTRAINT PK_AURA_USER_SETTINGS PRIMARY KEY (USER_NAME, SETTING_KEY, INSTANCE_ID)
);Oracle:
CREATE TABLE AURA_USER_SETTINGS (
USER_NAME VARCHAR2(255 CHAR) NOT NULL,
SETTING_KEY VARCHAR2(255 CHAR) NOT NULL,
INSTANCE_ID VARCHAR2(255 CHAR) NOT NULL,
SETTING_VALUE CLOB NOT NULL,
DATE_CH TIMESTAMP(3),
SETTING_VERSION INTEGER,
CONSTRAINT PK_AURA_USER_SETTINGS PRIMARY KEY (USER_NAME, SETTING_KEY, INSTANCE_ID)
);Microsoft SQL Server:
CREATE TABLE AURA_USER_SETTINGS (
USER_NAME NVARCHAR(255) NOT NULL,
SETTING_KEY NVARCHAR(255) NOT NULL,
INSTANCE_ID NVARCHAR(255) NOT NULL,
SETTING_VALUE NVARCHAR(MAX) NOT NULL,
DATE_CH DATETIME2(3),
SETTING_VERSION INTEGER,
CONSTRAINT PK_AURA_USER_SETTINGS PRIMARY KEY (USER_NAME, SETTING_KEY, INSTANCE_ID)
);SETTING_VALUE must hold long texts - the layout of a table with many columns takes several kB.
2. Import the objects
Import the whole d2configuration/auraConfig/ directory in D2000 CNF in one go.
3. Configure DBC_AURA and start AURA.EVH
Point DBC_AURA at the database of the table. AURA.EVH is shipped unconfigured like EM.EVH - START is
False, the command line is /F60 /FI0 /TP /DW /WAURA; configure it in CNF and start it.
4. Implement I.AURA_INTERFACE and fill SV.AURA_INTERFACE
E.AURA_SETTINGS asks the application whose settings a client loads and saves. Implement the one procedure
GetUserName in an EVENT object of your own; it gets the D2000 user the client is logged in as and the HOBJ of the
client's process, and returns the USER_NAME of the table. Keeping the settings per D2000 user:
IMPLEMENTATION I.AURA_INTERFACE
IMPLEMENTATION RPC PROCEDURE I.AURA_INTERFACE^GetUserName(IN TEXT _d2UserName, IN INT _callerProcess, TEXT _userName, BOOL _isOk, TEXT _errorMsg)
_userName := _d2UserName
_isOk := @TRUE
EXCEPTION_HANDLER
_isOk := @FALSE
END GetUserName
BEGIN
PRAGMA "ENABLE_INOUT_BY_REF"
ENDAn empty _userName or _isOk = @FALSE rejects the call with _errorMsg. Then set the two columns of
SV.AURA_INTERFACE (shipped with no start values):
| Column | Value |
|---|---|
| Event | your implementing EVENT object |
| Process | the .EVH process that event runs on |
Without them Load fails and the settings are kept in the browser.
RPC procedures of E.AURA_SETTINGS
The user is decided on the server by the I.AURA_INTERFACE implementation, never a parameter. Both procedures end
with the isOk / errorMessage pair of AbstractApi.callRpc.
| Procedure | Parameters | |
|---|---|---|
| Load | RECORD (SD.AURA_UserSetting) records (out) | all records of the user |
| Save | IN RECORD (SD.AURA_UserSetting) changes | in one transaction, in order: a row replaces the record of its SETTING_KEY and INSTANCE_ID, an empty SETTING_VALUE deletes it; USER_NAME and DATE_CH are set by the server |
Package contents
The published package is the compiled output (lib/esm): JavaScript + .d.ts declarations plus the
.less/.scss/.css styles, coreui/images/ and d2configuration/. The TypeScript sources are
not published.
Versioning
26.x.y scheme — the major version tracks the D2000 platform / d2jsapi 26 line, the minor version rises with a
release that breaks compatibility. See
CHANGELOG.md.
