@@ -43,6 +43,9 @@ local currentRecordUri = "";
4343
4444local gridColumns = {};
4545
46+ local performedAutoSearch = false ;
47+ local transactionNumber = 0 ;
48+
4649local archiveSpaceAddonScript = [[
4750 function buildObjectUrl(currentTreeId) {
4851 var archivalObjectId = /archival_object_(\d+)/.exec(currentTreeId);
@@ -139,25 +142,16 @@ function Init()
139142 -- After we add all of our buttons and form elements, we can show the form.
140143 catalogSearchForm .Form :Show ();
141144 catalogSearchForm .Form :LoadLayout (" layout.xml" );
145+
146+ transactionNumber = GetFieldValue (" Transaction" , " TransactionNumber" );
142147
143- local transactionNumber = GetFieldValue (" Transaction" , " TransactionNumber" );
144148 -- set the pagehandler if the user manually searches on the Browser interface directly
145149 InitializeLoginPageHandler ();
146150
147- if ((settings .AutoSearch ) and (transactionNumber ~= nil ) and (transactionNumber > 0 )) then
148- LogDebug (" Performing AutoSearch" );
149- local autoSearchPriority = ParseCSVLine (settings .AutoSearchPriority , ' ,' );
150- for _ , v in ipairs (autoSearchPriority ) do
151- -- Keep performing searches until successful
152- if (PerformSuccessfulSearch (v )) then
153- return ;
154- end
155- end
156- else
157- LogDebug (" Navigating to BaseURL because AutoSearch is disabled or invalid." );
158- catalogSearchForm .Browser :Navigate (settings .BaseURL );
159- end
160-
151+ -- We need to navigate to the main page first to detect if the user is already signed in
152+ -- AutoSearch will occur after the initial sign in attempt
153+ LogDebug (" Navigating to BaseURL first" );
154+ catalogSearchForm .Browser :Navigate (settings .BaseURL );
161155end
162156
163157function ShowDevTools ()
167161function InitializeLoginPageHandler ()
168162 LogDebug (" Initializing Login Page Handler" );
169163 catalogSearchForm .Browser :RegisterPageHandler (" custom" , " LoginPageLoaded" , " PerformLogin" , true );
164+ catalogSearchForm .Browser :RegisterPageHandler (" custom" , " IsNotSignedIn" , " NavigateToLogin" , true );
165+ if (settings .AutoSearch ) then
166+ catalogSearchForm .Browser :RegisterPageHandler (" custom" , " IsSignedIn" , " AutoSearchAfterLogin" , true );
167+ else
168+ LogDebug (" AutoSearch is disabled. Skipping page page handler registration to perform autosearch functionality." )
169+ end
170170 catalogSearchForm .Browser :RegisterPageHandler (" custom" , " AlwaysTrue" , " InjectScriptBridge" , false );
171171end
172172
@@ -776,6 +776,52 @@ function WebClientGet(webClient, apiPath)
776776 return webClient :DownloadData (PathCombine (settings .ApiBaseURL , apiPath ));
777777end
778778
779+ function IsSignedIn ()
780+ return CheckIfUserSignedIn ();
781+ end
782+
783+ function IsNotSignedIn ()
784+ return not CheckIfUserSignedIn ();
785+ end
786+
787+ function CheckIfUserSignedIn ()
788+ LogDebug (" Checking if user is signed in" );
789+
790+ local jsResult = catalogSearchForm .Browser :EvaluateScript (10000 , [[ document.getElementsByClassName('user-container').length > 0]] );
791+
792+ if (jsResult .Success ) then
793+ LogDebug (" IsUserSignedIn() result: " .. tostring (jsResult .Result ));
794+ return jsResult .Result ;
795+ else
796+ LogDebug (" Error determining if user is signed in: " .. jsResult .Message );
797+ return false ;
798+ end
799+ end
800+
801+ function NavigateToLogin ()
802+ LogDebug (" Navigating to login page" );
803+ local loginUrl = PathCombine (settings .BaseURL ," ?login" )
804+ catalogSearchForm .Browser :Navigate (loginUrl );
805+ end
806+
807+ function AutoSearchAfterLogin ()
808+ LogDebug (" Checking if we need to autosearch" );
809+
810+ if ((settings .AutoSearch ) and (not performedAutoSearch ) and (transactionNumber ~= nil ) and (transactionNumber > 0 )) then
811+ LogDebug (" Performing AutoSearch" );
812+ local autoSearchPriority = ParseCSVLine (settings .AutoSearchPriority , ' ,' );
813+ for _ , v in ipairs (autoSearchPriority ) do
814+ -- Keep performing searches until successful
815+ if (PerformSuccessfulSearch (v )) then
816+ performedAutoSearch = true ;
817+ return ;
818+ end
819+ end
820+ else
821+ LogDebug (" AutoSearch is disabled or already perfored" );
822+ end
823+ end
824+
779825function LoginPageLoaded ()
780826 LogDebug (" Checking if Login Page is loaded" );
781827
793839function PerformLogin ()
794840 -- Reregister login page handler
795841 catalogSearchForm .Browser :RegisterPageHandler (" custom" , " LoginPageLoaded" , " PerformLogin" , true );
796-
842+
797843 LogDebug (" Attempting to log in." );
798844
799845 -- Anonymous function invoked with params
0 commit comments