JavaScript hinzufügen

Fügen Sie über eine JavaScript Funktion neue Einträge zu ihrem Audit Trail hinzu. Hierdurch lassen sich sämtliche Interaktionen mit der Oberfläche protokollieren.

Hinzufügen eines JavaScripts in Visual Studio / TcXaeShell

1. Fügen Sie eine neue JavaScript Datei zum Projekt hinzu.
2. Öffnen Sie die erstellte JavaScript Datei.
3. Rufen Sie die Funktion TcHmi.Server.AuditTrail.createAuditLogEntryEx auf.
Durch die Funktion wird ein neuer Eintrag ins Audit Trail aufgenommen.

Funktion – JavaScript:

TcHmi.Server.AuditTrail.createAuditLogEntryEx(
    {
        name: string,
        contextDomain: string,
        comment: string,
        data: any
    },
    null,
    (data) => {
    }
);

Beispiel – JavaScript (Navigation Information):

(function (/** @type {globalThis.TcHmi} */ TcHmi) {
    // If you want to unregister an event outside the event code you need to use the return value of the method register()
    let destroyOnInitialized = TcHmi.EventProvider.register('onInitialized', (e, data) => {
        // This event will be raised only once, so we can free resources.
        // It's best practice to use destroy function of the event object within the callback function to avoid conflicts.
        e.destroy();

        let __this = this;
        let destroyNavigationRightonPressed;

        // Navigation_Right
        TcHmi.EventProvider.register('Navigation_Right.onAttached', function (e, data) {
            __this.controlNavigationRight = data;

            // create event listener
            destroyNavigationRightonPressed = TcHmi.EventProvider.register(`${data.__id}.onPressed`, function (e, data) {
                TcHmi.Server.AuditTrail.createAuditLogEntryEx(
                    {
                        name: `Control Id: ${__this.controlNavigationRight.getId()}`,
                        contextDomain: `TriggeredUserInteraction`,
                        comment: `Navigation changed to "${__this.controlNavigationRight.getBreadcrumbPath().join(" || ")}" on ip ${TcHmi.Server.getCurrentUserConfig().clientIp}`,
                        data: { data: "Test" }
                    },
                    null,
                    (data) => {
                    }
                );
            });
        });
        TcHmi.EventProvider.register('Navigation_Right.onDetached', function (e, data) {
            // destroy sub events
            if (destroyNavigationRightonPressed) {
                destroyNavigationRightonPressed();
                destroyNavigationRightonPressed = undefined;
            }
            __this.controlNavigationRight = undefined;
        });

    });
})(TcHmi);