Skip to content

Commit

Permalink
Migrate Status and Event to Universal API #8062
Browse files Browse the repository at this point in the history
  • Loading branch information
anatol-sialitski committed Nov 18, 2024
1 parent f6273cb commit 92a8b4b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions modules/app/src/main/resources/admin/tools/main/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<api>export</api>
<api>license</api>
<api>styles</api>
<api>com.enonic.xp.app.main:launcher</api>
<api>com.enonic.xp.app.main:i18n</api>
<api>admin:widget</api>
<api>admin:status</api>
<api>admin:event</api>
</apis>
</tool>
17 changes: 9 additions & 8 deletions modules/app/src/main/resources/assets/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function startLostConnectionDetector(): ConnectionDetector {
let readonlyMessageId: string;

const connectionDetector: ConnectionDetector =
ConnectionDetector.get()
ConnectionDetector.get(CONFIG.getString('statusApiUrl'))
.setAuthenticated(true)
.setSessionExpireRedirectUrl(CONFIG.getString('toolUri'))
.setNotificationMessage(i18n('notify.connection.loss'));
Expand Down Expand Up @@ -230,21 +230,22 @@ function preLoadApplication() {
}
}

function startServerEventListeners(application: Application) {
const serverEventsListener: AggregatedServerEventsListener = new AggregatedServerEventsListener([application]);
function startServerEventListeners(application: Application, eventApiUrl: string) {
const serverEventsListener: AggregatedServerEventsListener = new AggregatedServerEventsListener([application], eventApiUrl);
let wsConnectionErrorId: string;

serverEventsListener.onConnectionError(() => {
if (!wsConnectionErrorId) {
const connectionDetector: ConnectionDetector = ConnectionDetector.get(CONFIG.getString('statusApiUrl'));
const pollHandler: () => void = () => {
if (ConnectionDetector.get().isConnected()) {
if (connectionDetector.isConnected()) {
wsConnectionErrorId = showError(i18n('notify.websockets.error'), false);
}

ConnectionDetector.get().unPoll(pollHandler);
connectionDetector.unPoll(pollHandler);
};

ConnectionDetector.get().onPoll(pollHandler);
connectionDetector.onPoll(pollHandler);
}
});

Expand All @@ -257,7 +258,7 @@ function startServerEventListeners(application: Application) {

serverEventsListener.start();

new SettingsServerEventsListener([application]);
new SettingsServerEventsListener([application], eventApiUrl);
}

const handleProjectDeletedEvent = (projectName: string) => {
Expand Down Expand Up @@ -327,7 +328,7 @@ async function startApplication() {
connectionDetector = startLostConnectionDetector();
Store.instance().set('application', application);

startServerEventListeners(application);
startServerEventListeners(application, CONFIG.getString('eventApiUrl'));
initApplicationEventListener();

ProjectContext.get().onNoProjectsAvailable(() => handleNoProjectsAvailable());
Expand Down
8 changes: 8 additions & 0 deletions modules/app/src/main/resources/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ function getConfig() {
application: 'admin',
api: 'widget'
}),
statusApiUrl: portal.apiUrl({
application: 'admin',
api: 'status'
}),
eventApiUrl: portal.apiUrl({
application: 'admin',
api: 'event'
}),
phrasesAsJson: JSON.stringify(getPhrases()),
launcherUrl: admin.widgetUrl({
application: 'com.enonic.xp.app.main',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {ServerEventAggregator} from './ServerEventAggregator';
import {ServerEventsListener} from '@enonic/lib-admin-ui/event/ServerEventsListener';
import {Application} from '@enonic/lib-admin-ui/app/Application';
import {ObjectHelper} from '@enonic/lib-admin-ui/ObjectHelper';
import {ProjectContext} from '../project/ProjectContext';
import {ContentServerEventsTranslator} from './ContentServerEventsTranslator';
import {ContentServerEvent} from './ContentServerEvent';
import {ContentServerChangeItem} from './ContentServerChangeItem';
Expand All @@ -13,15 +12,14 @@ import {IssueServerEvent} from './IssueServerEvent';
import {NodeServerEvent} from '@enonic/lib-admin-ui/event/NodeServerEvent';
import {ArchiveServerEvent} from './ArchiveServerEvent';
import {NodeServerChangeType} from '@enonic/lib-admin-ui/event/NodeServerChange';
import {CollaborationServerEvent} from './CollaborationServerEvent';

export class AggregatedServerEventsListener
extends ServerEventsListener {

private aggregator: ServerEventAggregator;

constructor(applications: Application[]) {
super(applications);
constructor(applications: Application[], eventApiUrl: string) {
super(applications, eventApiUrl);

this.aggregator = new ServerEventAggregator();

Expand Down

0 comments on commit 92a8b4b

Please sign in to comment.