closePopup script not working

Hello, I am trying to close a popup when a user is logged in or after they log in using the popup window. Currently the setup is as follows:

When trying to login using our Ignition program, a popup appears that contains an inline frame that immediately goes to the login page. There you can login as normal, and then in theory (although it isn't happening yet) once you are logged in the popup will close and allow you to never have had to leave the page you were on to login and causing a delay in trying to do what you were doing before trying to login.

auth.authenticated in the session props has an on change script with the following:

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
    if currentValue:
        system.perspective.closePopup('loginPLEASE')

The popup has the identifier of 'loginPLEASE' as a way to easily find it when trying to use inspect element on chrome to double check that the id is correct and every time as far as I can see it retains that id even after being redirected to the login page.

So far every time it has failed to close the popup when I login using the popup, although I know I am authenticated as in my header it shows my authentication status with an icon and my username when I am logged in.

Unsure of what would be the cause of this, I have plenty of other pages that have a closePopup function and they work as they should but this is the only one that doesn't want to work, and of course this is the most frequently used popup at the moment since being logged in allows you to actually make edits to tags and such. Any help would be appreciated, thank you!

currentValue is a Qualified Value object and will never be None. Why the if statement, you're not comparing it to anything.

currentValue.value might be None though.

Correct me if I am wrong but I'm not comparing it to None though, I'm asking if it's true and if so then closePopup.

forget what I said here.

@dkhayes117 is correct. currentValue is a qualified value so you need to assess the value of the value via currentValue.value

What's the purpose of the inline frame? That is, what login page are you talking about?

Are you aware of the authentication challange?
system.perspective.authenticationChallenge | Ignition User Manual

It was a feature that was requested by some of the workers to have a popup instead of loading a new page to login so that they wouldn't have to lose the progress of what they were doing before they had to load a new page to log in. So we have a popup that has an inline frame that redirects to the login page automatically if they aren't logged in. This way the workers can keep their in progress changes in the background and log in without losing it.

1 Like

I changed the onChange script to be the following:

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
    if currentValue.value:
    	system.tag.writeBlocking('[default]isSuccess', True)
    	system.perspective.closePopup('loginPLEASE')

and I can see the tag I made as a debug is being written over when the authentication is done, but the popup still doesn't close. Even though the id is still 'loginPLEASE'.

Have you tried passing an empty string just to see if that works?

system.perspective.closePopup('')

Unfortunately, I have. Not sure why it doesn't close the popup when requested to. Perhaps it somehow changes the id to be unique after logging in? Or maybe the script runs too fast before the popup can load and catch it?

Like you said I am sure there is a better way to achieve what I want to do, but after looking at this so long I fear I have blinders on. Do you have another suggestion?

Might be a long shot but any errors in your gateway log?

Did you try

system.perspective.closePopup('popup-loginPLEASE')

Go into the Session Events on the project, and put the closePopup script under the Authentication Challenge event. This should run once a user logs in.

Also, note that system.perspective.authenticationChallenge has a framing argument that might be interesting to you.

This is what was in there when trying it with an empty string of ('')

	Error running property change script on session.props.auth.authenticated: Traceback (most recent call last): File "<function:valueChanged>", line 4, in valueChanged at com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.lambda$operateOnPage$0(AbstractScriptingFunctions.java:64) at com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.operateOnSession(AbstractScriptingFunctions.java:120) at com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.operateOnPage(AbstractScriptingFunctions.java:47) at com.inductiveautomation.perspective.gateway.script.PerspectiveScriptingFunctions.popupAction(PerspectiveScriptingFunctions.java:758) at com.inductiveautomation.perspective.gateway.script.PerspectiveScriptingFunctions.closePopup(PerspectiveScriptingFunctions.java:258) at jdk.internal.reflect.GeneratedMethodAccessor1071.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: No perspective page attached to this thread.

Unfortunately I did, I have both 'loginPLEASE' and 'popup-loginPLEASE' in separate closePopup commands one line after the other.

This means that you must also supply the pageId as an argument for closePopup.

system.perspective.closePopup | Ignition User Manual

EDIT:
Since you are using a change script on a session property, this is probably what you need

for pageId in self.info.pageIds:
    system.perspective.closePopup('loginPLEASE', pageId=pageId)

This seems to be the underlying flaw. Don't allow any "progress" on anything until after login. :man_shrugging:

3 Likes

I think the idea would be to be able to log back into the session if a user was away long enough for it to time out and logged the user out while they were in the middle or something.

Or potentially allow someone to view pages certain without being logged in, but then allow them or a different user to log in without having to take the time to reload the current page, but load the popup with the login instead.

Why is this a problem just for this case? If a page takes long to load, it is a problem anyways, not just with login.

If a page loses information when reloading, there's something wrong with the data flow among the page and view properties that should be investigated.