Skip to content

Commit

Permalink
Merge pull request #4 from AtlasSystems/feature/support-2.8.0
Browse files Browse the repository at this point in the history
Feature/support 2.8.0
  • Loading branch information
asmith-atlas authored Oct 30, 2020
2 parents ac284e4 + 61f5bee commit 6d1a9e9
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 18 deletions.
78 changes: 62 additions & 16 deletions Aeon-ArchivesSpace-Addon/Aeon-ArchivesSpace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ local currentRecordUri = "";

local gridColumns = {};

local performedAutoSearch = false;
local transactionNumber = 0;

local archiveSpaceAddonScript = [[
function buildObjectUrl(currentTreeId) {
var archivalObjectId = /archival_object_(\d+)/.exec(currentTreeId);
Expand Down Expand Up @@ -139,25 +142,16 @@ function Init()
-- After we add all of our buttons and form elements, we can show the form.
catalogSearchForm.Form:Show();
catalogSearchForm.Form:LoadLayout("layout.xml");

transactionNumber = GetFieldValue("Transaction", "TransactionNumber");

local transactionNumber = GetFieldValue("Transaction", "TransactionNumber");
--set the pagehandler if the user manually searches on the Browser interface directly
InitializeLoginPageHandler();

if ((settings.AutoSearch) and (transactionNumber ~= nil) and (transactionNumber > 0)) then
LogDebug("Performing AutoSearch");
local autoSearchPriority = ParseCSVLine(settings.AutoSearchPriority, ',');
for _, v in ipairs(autoSearchPriority) do
-- Keep performing searches until successful
if(PerformSuccessfulSearch(v)) then
return;
end
end
else
LogDebug("Navigating to BaseURL because AutoSearch is disabled or invalid.");
catalogSearchForm.Browser:Navigate(settings.BaseURL);
end

--We need to navigate to the main page first to detect if the user is already signed in
--AutoSearch will occur after the initial sign in attempt
LogDebug("Navigating to BaseURL first");
catalogSearchForm.Browser:Navigate(settings.BaseURL);
end

function ShowDevTools()
Expand All @@ -167,6 +161,12 @@ end
function InitializeLoginPageHandler()
LogDebug("Initializing Login Page Handler");
catalogSearchForm.Browser:RegisterPageHandler("custom", "LoginPageLoaded", "PerformLogin", true);
catalogSearchForm.Browser:RegisterPageHandler("custom", "IsNotSignedIn", "NavigateToLogin", true);
if (settings.AutoSearch) then
catalogSearchForm.Browser:RegisterPageHandler("custom", "IsSignedIn", "AutoSearchAfterLogin", true);
else
LogDebug("AutoSearch is disabled. Skipping page page handler registration to perform autosearch functionality.")
end
catalogSearchForm.Browser:RegisterPageHandler("custom", "AlwaysTrue", "InjectScriptBridge", false);
end

Expand Down Expand Up @@ -776,6 +776,52 @@ function WebClientGet(webClient, apiPath)
return webClient:DownloadData(PathCombine(settings.ApiBaseURL, apiPath));
end

function IsSignedIn()
return CheckIfUserSignedIn();
end

function IsNotSignedIn()
return not CheckIfUserSignedIn();
end

function CheckIfUserSignedIn()
LogDebug("Checking if user is signed in");

local jsResult = catalogSearchForm.Browser:EvaluateScript(10000, [[document.getElementsByClassName('user-container').length > 0]]);

if (jsResult.Success) then
LogDebug("IsUserSignedIn() result: " .. tostring(jsResult.Result));
return jsResult.Result;
else
LogDebug("Error determining if user is signed in: " .. jsResult.Message);
return false;
end
end

function NavigateToLogin()
LogDebug("Navigating to login page");
local loginUrl = PathCombine(settings.BaseURL,"?login")
catalogSearchForm.Browser:Navigate(loginUrl);
end

function AutoSearchAfterLogin()
LogDebug("Checking if we need to autosearch");

if ((settings.AutoSearch) and (not performedAutoSearch) and (transactionNumber ~= nil) and (transactionNumber > 0)) then
LogDebug("Performing AutoSearch");
local autoSearchPriority = ParseCSVLine(settings.AutoSearchPriority, ',');
for _, v in ipairs(autoSearchPriority) do
-- Keep performing searches until successful
if(PerformSuccessfulSearch(v)) then
performedAutoSearch = true;
return;
end
end
else
LogDebug("AutoSearch is disabled or already perfored");
end
end

function LoginPageLoaded()
LogDebug("Checking if Login Page is loaded");

Expand All @@ -793,7 +839,7 @@ end
function PerformLogin()
--Reregister login page handler
catalogSearchForm.Browser:RegisterPageHandler("custom", "LoginPageLoaded", "PerformLogin", true);

LogDebug("Attempting to log in.");

--Anonymous function invoked with params
Expand Down
4 changes: 2 additions & 2 deletions Aeon-ArchivesSpace-Addon/Config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name>ArchivesSpace Interface</Name>
<Author>Atlas Systems, Inc.</Author>
<Version>2.0.0</Version>
<Version>2.1.0</Version>
<Active>True</Active>
<Type>Addon</Type>
<Description>This addon performs searches in ArchivesSpace using the staff interface. This addon supports ArchivesSpace versions v2.0.0 and later.</Description>
<Description>This addon performs searches in ArchivesSpace using the staff interface. This addon supports ArchivesSpace versions v2.8.0 and later.</Description>
<Forms>
<Form>FormRequest</Form>
</Forms>
Expand Down
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Aeon ArchivesSpace Client Addon

## Version
- 2.0:
- Added support for staff logins in Archives Space v2.8.0.
- 2.0:
- Added support for importing the barcode from an instance's Top Container.
- Added support for importing the titles from each Location that is linked
Expand Down

0 comments on commit 6d1a9e9

Please sign in to comment.