Skip to content

Commit

Permalink
Added feature to reconcile artsdata entities
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-aravind committed Jun 18, 2024
1 parent ba6e0f2 commit 23b68c9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 15 deletions.
3 changes: 2 additions & 1 deletion appsscript.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"https://www.googleapis.com/auth/spreadsheets.currentonly"
],
"urlFetchWhitelist": [
"https://kg.artsdata.ca/"
"https://kg.artsdata.ca/",
"https://api.artsdata.ca/recon"
],
"addOns":{
"common": {
Expand Down
33 changes: 33 additions & 0 deletions src/artsdata_search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const artsdataSearch = () => {
const ui = SpreadsheetApp.getUi();
const cell = SpreadsheetApp.getActiveSpreadsheet()
.getActiveSheet()
.getActiveCell();
const value = cell.getValue();

const query = encodeURIComponent(`{"q0":{"query":"${value}"}}`);
const url = `https://api.artsdata.ca/recon?queries=${query}`;

try {
const response = JSON.parse(UrlFetchApp.fetch(url).getContentText());
const results = response?.q0?.result;

if (results && results.length > 0) {
const choices = results.map(result => `${result.id} - ${result.name}`).join('\n');
const userChoice = ui.prompt('Enter an ID from the list:', choices, ui.ButtonSet.OK_CANCEL);

if (userChoice.getSelectedButton() === ui.Button.OK) {
const chosenId = userChoice.getResponseText();
cell.setValue(`https://kg.artsdata.ca/resource/${chosenId}`);
} else {
ui.alert('No ID chosen.');
}
} else {
ui.alert('No results found.');
}
} catch (e) {
ui.alert(`An error occurred: ${e.message}`);
}
};

export default artsdataSearch;
11 changes: 8 additions & 3 deletions src/create_person_organization_card.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ const createPersonOrganizationCard = entityData => {
const entityName = getMultilingualFields(entityData?.name);
const entityType = entityData?.type || '';
const disambiguatingDescription = getMultilingualFields(entityData.disambiguatingDescription);
const entityImage = entityData?.image || '';

const previewHeader = CardService.newCardHeader()
.setTitle(entityName)
.setSubtitle(entityType);

const cardContent = CardService.newCardSection().addWidget(
CardService.newTextParagraph().setText(disambiguatingDescription)
);
const previewImage = CardService.newImage()
.setAltText('Image of entity')
.setImageUrl(entityImage);

const cardContent = CardService.newCardSection()
.addWidget(CardService.newTextParagraph().setText(disambiguatingDescription))
.addWidget(previewImage);

return CardService.newCardBuilder()
.setHeader(previewHeader)
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import artsdataPreview from './artsdata_preview';
import getEntityDetails from './get_entity_details';
import onOpen from './onOpen';
import menuItem from './menuItem';
import artsdataSearch from './artsdata_search';

global.artsdataPreview = artsdataPreview;
global.getEntityDetails = getEntityDetails;
global.onOpen = onOpen;
global.menuItem = menuItem;
global.artsdataSearch = artsdataSearch;
5 changes: 0 additions & 5 deletions src/menuItem.js

This file was deleted.

6 changes: 2 additions & 4 deletions src/onOpen.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const onOpen = () => {
SpreadsheetApp.getUi()
.createMenu('Custom Menu')
.addItem('First Item', 'menuItem')
.createMenu('Artsdata Reconciliation')
.addItem('Search', 'artsdataSearch')
.addToUi();


};

export default onOpen;

0 comments on commit 23b68c9

Please sign in to comment.