feat(hp callback): Add viewport ready callback (#3772)

Co-authored-by: Ouwen Huang <ouwen.huang@duke.edu>
This commit is contained in:
AlirezaandOuwen Huang authored and GitHub committed 2023-11-08 09:19:49 -05:00
1 parent 1a68c06c3b
commit bf252bcec2
10 files changed
+143 -44

No files matched your search

@@ -141,7 +141,9 @@ function checkHpsBestMatch(hps) {
describe('HangingProtocolService', () => {
const mockedFunction = jest.fn();
const commandsManager = {};
const commandsManager = {
run: mockedFunction,
};
const servicesManager = {
services: {
TestService: {
@@ -849,6 +849,8 @@ export default class HangingProtocolService extends PubSubService {
throw new Error(error);
}
this._commandsManager.run(this.protocol?.callbacks?.onProtocolEnter);
}
protected matchActivation(
@@ -956,6 +958,12 @@ export default class HangingProtocolService extends PubSubService {
if (!this.protocol || this.protocol.id !== protocol.id) {
this.stageIndex = options?.stageIndex || 0;
this._originalProtocol = this._copyProtocol(protocol);
// before reassigning the protocol, we need to check if there is a callback
// on the old protocol that needs to be called
// Send the notification about updating the state
this._commandsManager.run(this.protocol?.callbacks?.onProtocolExit);
this.protocol = protocol;
const { imageLoadStrategy } = protocol;
@@ -1120,6 +1128,13 @@ export default class HangingProtocolService extends PubSubService {
const { columns: numCols, rows: numRows, layoutOptions = [] } = layoutProps;
if (this.protocol?.callbacks?.onViewportDataInitialized) {
this._commandsManager.runCommand('attachProtocolViewportDataListener', {
protocol: this.protocol,
stageIndex: this.stageIndex,
});
}
this._broadcastEvent(this.EVENTS.NEW_LAYOUT, {
layoutType,
numRows,
@@ -1143,9 +1158,6 @@ export default class HangingProtocolService extends PubSubService {
} {
let matchedViewports = 0;
stageModel.viewports.forEach(viewport => {
// Todo: we should probably assign a random viewportId if not defined
// below, but it feels odd since viewportGrid should handle this kind
// of thing
const viewportId = viewport.viewportOptions.viewportId;
const matchDetails = this._matchViewport(
viewport,
@@ -90,7 +90,7 @@ function _broadcastEvent(eventName, callbackProps) {
/** Export a PubSubService class to be used instead of the individual items */
export class PubSubService {
EVENTS: any;
subscribe: (eventName: string, callback: Function) => { unsubscribe: () => any; };
subscribe: (eventName: string, callback: Function) => { unsubscribe: () => any };
_broadcastEvent: (eventName: string, callbackProps: any) => void;
_unsubscribe: (eventName: string, listenerId: string) => void;
_isValidEvent: (eventName: string) => boolean;
+4 -2
View File
@@ -241,15 +241,17 @@ export type ProtocolStage = {
export type ProtocolNotifications = {
// This set of commands is executed after the protocol is exited and the new one applied
onProtocolExit?: Command[];
// This set of commands is executed after the protocol is entered and applied
onProtocolEnter?: Command[];
// This set of commands is executed before the layout change is started.
// If it returns false, the layout change will be aborted.
// The numRows and numCols is included in the command params, so it is possible
// to apply a specific hanging protocol
onLayoutChange?: Command[];
// This set of commands is executed after the initial viewport grid data is set
// and all viewport data includes a designated display set. This command
// will run on every stage's initial layout.
onViewportDataInitialized?: Command[];
};
/**