Global Message upon User Login

I’ve been looking for a way to display a global message upon login. An example would be “Scheduled Maintenance, System will be offline between x and y…” that all users will be able to see upon login. My initial thought was to put something on the dashboard. The requirement is that it can be updated/modified without re-deploying the application an users will see it upon login. Does the platform support anything for this? I’ve tried looking around and haven’t found anything. Let me know of any ideas.

Thanks.

Hi,

The easiest way to implement this is to extend Main window.

You can add a simple label to the top of the screen as follows:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        class="com.company.demo.web.screens.ExtAppMainWindow"
        extends="/com/haulmont/cuba/web/app/mainwindow/mainwindow.xml"
        messagesPack="com.company.demo.web.screens"
        xmlns:ext="http://schemas.haulmont.com/cuba/window-ext.xsd">
    <layout>
        <label id="alertLabel"
               visible="false"
               ext:index="0"
               stylename="h2 global-alert"
               width="100%"/>
    </layout>
</window>

Then load global message from the database, for instance, from database-stored config:

public class ExtAppMainWindow extends AppMainWindow {
    @Inject
    private MaintenanceConfig maintenanceConfig;
    @Inject
    private Label alertLabel;

    @Override
    public void ready() {
        super.ready();

        String globalAlert = maintenanceConfig.getGlobalAlert();
        if (!Strings.isNullOrEmpty(globalAlert)) {
            alertLabel.setVisible(true);
            alertLabel.setValue(globalAlert);
        }
    }
}

Config interface (note: SourceType.DATABASE):

@Source(type = SourceType.DATABASE)
public interface MaintenanceConfig extends Config {

    @Property("maintenance.globalAlert")
    String getGlobalAlert();
    void setGlobalAlert(String alert);
}

And implement simple configuration screen where administrators will be able to set this global alert:

public class MaintenanceConfigWindow extends AbstractWindow {
    @Inject
    private MaintenanceConfig maintenanceConfig;
    @Inject
    private TextArea alertTextArea;

    @Override
    public void init(Map<String, Object> params) {
        super.init(params);

        alertTextArea.setValue(maintenanceConfig.getGlobalAlert());
    }

    public void apply() {
        maintenanceConfig.setGlobalAlert(alertTextArea.getValue());

        close(COMMIT_ACTION_ID);

        showNotification("New global alert applied");
    }

    public void close() {
        close(CLOSE_ACTION_ID);
    }
}

Voila:
image

See this sample project: GitHub - cuba-labs/global-alert-banner

1 Like