Show a popup in perspective on all clients if a value changes

@mcgheeiv has supplied one route, but the problem is that session properties have no insight into the page in use, which is required when opening a Popup. Your logs would supply an exception or error along the lines of “No perspective page attached to thread.”

There are some important things to consider when planning this: Each browser session could have multiple pages open, so which page gets the Popup? The first page found for a session, or all pages? What conditions would warrant closing the popup across across any pages it is opened on? Would sessions opened AFTER the opening condition becomes true instantly open the popup, or would they be exempt?

I’m going to make some assumptions, and you can manipulate the logic as you see fit. Let’s assume this is a boolean tag, and you want the Popup to be opened for all pages in all sessions when the tag becomes true, and you want the Popup to close for all pages in all sessions when the tag becomes false. Pages/Sessions opened after the tag has become true will be exempt from the Popup.

I think the best solution is going to be to have tag change script.

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	popupId = "SomeUniqueValue"
	viewPath = "PopupViews/SmallPopup"  # insert your view path here
	logger = system.util.getLogger("POPUP")
	sessions = system.perspective.getSessionInfo()
	for session in sessions:
		for pageId in session.pageIds:
			logger.info("{0} | {1}".format(session.id, pageId))
			if currentValue.value:
				system.perspective.openPopup(popupId, viewPath, sessionId=session.id, pageId=pageId)
			else:
				# note no viewPath arg
				system.perspective.closePopup(popupId, sessionId=session.id, pageId=pageId)
5 Likes