gdcc/dataverse-external-vocab-support

ROR/Author Affiliation example doesn't seem to "just work" as of 5.12

Closed this issue ยท 6 comments

I picked up IQSS/dataverse#9150 but I've been a bit blocked by a working example of an external vocab script.

I tried getting the ROR/Author Affiliation script working, which I had tested early on when this (awesome) PR was created:

However, as of IQSS/dataverse@ecc23c0ebf (post 5.12.1 "develop" branch), the affiliation script doesn't seem to "just work" anymore.

I have a theory that it's breaking because an extra div was introduced in line 286 in this commit: IQSS/dataverse@8c4c3d3#diff-5ff0dd346b5d156cd409cd8a793e99ad72fbbe677bd1ec54e44406b2858cb2b4R286 . If that's right, the affiliation script doesn't work for 5.12 and newer.

Here's my ugly hack to get it working again:

-var authorSelector = "div#metadata_author ~ div.dataset-field-values div.edit-compound-field";
+var authorSelector = "#datasetForm\\:tabView\\:j_idt1619\\:0\\:j_idt1622\\:5\\:editCompoundValueFragment div.dataset-field-values div.edit-compound-field";

Obviously, we don't want those ugly and brittle j_idt1619 values that JSF injects into the pages. I'm not so good with CSS but I'm hoping someone (maybe even the original authors of PR #9, @Kris-LIBIS and @KaDee) might have a better, cleaner suggestion.

Or maybe we need to add more id's to divs in the JSF code? Someday we plan to move to React.

Anyway, with the hack above in place, I can see the magnifying glass and inserting values seems to work. Here are a couple screenshots:

Screen Shot 2023-01-23 at 3 08 34 PM
Screen Shot 2023-01-23 at 3 09 24 PM

There's an issue in this sprint that's even more related to all this:

One final thing I'll mention is that @qqmyers suggested not having "authorAffiliation" twice in examples/config/affiliation.json so I changed field-name to just "author" but I haven't tested this much, but he's right. As soon as I made this switch I was able to see the final HTML annotated with "data cvoc" here and there. So this seems important too as a prerequisite to the the hack above.

   {
-    "field-name": "authorAffiliation",
+    "field-name": "author",
     "term-uri-field": "authorAffiliation",

Yes, indeed. Some changes in the GUI of 5.12 broke the script and we had to change our script as well to make it work again. @ErykKul made these changes and unfortunately it was not as simple as changing the selector, but not that complex either. From the identifiable element (div#metadata_author), we now have to step up the DOM hierarchy and that cannot be done with just the CSS query syntax, so some Javascript needs to be added to navigate up and search back down to find the edit boxes to add the search icon to. I hope Eryk can explain better what changes are needed, but it does indeed not seem to be a good idea to use those generated identifiers in the selector.

BTW, @Kris-LIBIS and @KaDee both are me. The first is a work-account and the second one is my private one. I should have used only the first one.

@Kris-LIBIS described it correctly. Also, we have now a new way of adding a custom JavaScript to the dataset page:

:ControlledVocabularyCustomJavaScript allows a JavaScript file to be loaded into the dataset page for the purpose of showing controlled vocabulary as a list (with optionally translated values) such as author names.

To specify the URL for a custom script covoc.js to be loaded from an external site:

curl -X PUT -d 'https://example.com/js/covoc.js' http://localhost:8080/api/admin/settings/:ControlledVocabularyCustomJavaScript

Our relevant code looks something like this now:

let elements = $("#metadata_author")?.parent()?.parent()?.find(".dataset-field-values .edit-compound-field");
for(let i = 0; i < elements?.length; i++) {
  let metadataField = elements[i].children[0];
  ...
  metadataField.appendChild(...);
  ...
}

FWIW: There's an alternative script/config example in #14 that is compatible with Dataverse 5.14+

Closing in favor of this issue: