Skip to content

Commit 6d1a9e9

Browse files
authored
Merge pull request #4 from AtlasSystems/feature/support-2.8.0
Feature/support 2.8.0
2 parents ac284e4 + 61f5bee commit 6d1a9e9

3 files changed

Lines changed: 66 additions & 18 deletions

File tree

Aeon-ArchivesSpace-Addon/Aeon-ArchivesSpace.lua

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ local currentRecordUri = "";
4343

4444
local gridColumns = {};
4545

46+
local performedAutoSearch = false;
47+
local transactionNumber = 0;
48+
4649
local 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);
161155
end
162156

163157
function ShowDevTools()
@@ -167,6 +161,12 @@ end
167161
function 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);
171171
end
172172

@@ -776,6 +776,52 @@ function WebClientGet(webClient, apiPath)
776776
return webClient:DownloadData(PathCombine(settings.ApiBaseURL, apiPath));
777777
end
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+
779825
function LoginPageLoaded()
780826
LogDebug("Checking if Login Page is loaded");
781827

@@ -793,7 +839,7 @@ end
793839
function 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

Aeon-ArchivesSpace-Addon/Config.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
33
<Name>ArchivesSpace Interface</Name>
44
<Author>Atlas Systems, Inc.</Author>
5-
<Version>2.0.0</Version>
5+
<Version>2.1.0</Version>
66
<Active>True</Active>
77
<Type>Addon</Type>
8-
<Description>This addon performs searches in ArchivesSpace using the staff interface. This addon supports ArchivesSpace versions v2.0.0 and later.</Description>
8+
<Description>This addon performs searches in ArchivesSpace using the staff interface. This addon supports ArchivesSpace versions v2.8.0 and later.</Description>
99
<Forms>
1010
<Form>FormRequest</Form>
1111
</Forms>

Readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Aeon ArchivesSpace Client Addon
22

33
## Version
4+
- 2.0:
5+
- Added support for staff logins in Archives Space v2.8.0.
46
- 2.0:
57
- Added support for importing the barcode from an instance's Top Container.
68
- Added support for importing the titles from each Location that is linked

0 commit comments

Comments
 (0)