Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Summon to Discovery Showcase #7

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
432fa65
edit searchUrl to something we have access to as CDI team, on clariva…
amusick-endava Aug 21, 2024
edab904
Merge pull request #1 from amusick-endava/CDI-29393
amusick-endava Aug 21, 2024
2a64120
Refactor current code to make it generic
khateeb95 Aug 22, 2024
bce823e
Merge pull request #2 from amusick-endava/CDI-29432-Refactor-current-…
amusick-endava Aug 22, 2024
a3733b7
refactor document card to be more generic
amusick-endava Aug 23, 2024
f9f75b9
move pnx specific logic for document card to pnx service
amusick-endava Aug 26, 2024
a04a263
fix typo
amusick-endava Aug 26, 2024
8e3ea2e
Merge pull request #3 from amusick-endava/CDI-29326
khateeb95 Aug 27, 2024
d5c25bd
Implement summon service for carousel - snxService
khateeb95 Aug 28, 2024
e6be1bb
implementing a fallback mechanism for images
khateeb95 Aug 29, 2024
0240621
Merge pull request #4 from amusick-endava/CDI-29471-Implement-summon-…
amusick-endava Aug 30, 2024
5ef3230
Handle summon specific logic about default thumbnail in snx-service
amusick-endava Aug 30, 2024
9dd22cf
set up nvm version
amusick-endava Aug 30, 2024
8c3c722
use summon bookmarks as first choice for deep linking
amusick-endava Sep 9, 2024
d20d21a
Merge pull request #5 from amusick-endava/CDI-29326
amusick-endava Sep 10, 2024
bd822e6
CDI-29326 add font-style normal style to search-carousel
amusick-endava Sep 10, 2024
86fee7d
Merge branch 'develop' of github.com:amusick-endava/Discovery-Showcas…
amusick-endava Sep 10, 2024
497ae4e
Merge pull request #6 from amusick-endava/CDI-29326
amusick-endava Sep 10, 2024
0320a2c
for summon widget builder we need to dynamically repeat search when s…
amusick-endava Sep 19, 2024
ae6ea71
use fallback thumbnail url consistently for snx
amusick-endava Sep 23, 2024
1d45d89
Use default thumbnails via css classes like in results page
khateeb95 Sep 26, 2024
79faa33
clean code
khateeb95 Sep 26, 2024
468a0a8
Merge pull request #7 from amusick-endava/CDI-29637-Use-default-thumb…
amusick-endava Sep 27, 2024
93e81b6
Revert changes to handle default thumbnail styles for summon in disco…
amusick-endava Sep 27, 2024
ec8b53d
use jsonp to fetch data to avoid cors error for summon
amusick-endava Sep 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/hydrogen
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Run this command in order to create a minified and bundled file:
```bash
rollup -c
```
It will create a bundled js file called discovery-showcase.js inside the dist folder
It will create bundled js files called pnx-discovery-showcase.bundled.js (for primo users) and snx-discovery-showcase.bundled.js (for summon users) inside the dist folder. Separate bundles are created to minimize the size of both of them, and you likely only need one or the other depending on your use case.

## More information

Expand Down
33 changes: 24 additions & 9 deletions dev/index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8" />
<head>
<meta charset="utf-8"/>
<title>&lt;my-element> Demo</title>
<script type="module" src="../search-carousel.js"></script>
<script type="module" src="../pnx-search-carousel.js"></script>
<script type="module" src="../snx-search-carousel.js"></script>

</head>
<body>
</head>
<body>

<search-carousel titleText="test!" titleLink="https://www.google.com" defaultThumbnailUrl="../dist/default.png"
searchUrl="http://il-urmsand01.corp.exlibrisgroup.com:1801/primaws/rest/external/pnxs?acTriggered=false&blendFacetsSeparately=false&citationTrailFilterByAvailability=true&disableCache=false&getMore=0&inst=TRAINING_1_INST&isCDSearch=false&lang=en&limit=10&newspapersActive=false&newspapersSearch=false&offset=0&otbRanking=false&pcAvailability=false&q=any,contains,history&qExclude=&qInclude=&rapido=false&refEntryActive=false&rtaLinks=true&scope=MyInst_and_CI&searchInFulltextUserSelection=true&skipDelivery=N&sort=rank&tab=Everything&vid=TRAINING_1_INST:Auto1">
<pnx-search-carousel titleText="Primo Carousel Test!"
titleLink="https://www.google.com"
defaultThumbnailUrl="../dist/default.png"
searchUrl="https://na02.primo.exlibrisgroup.com/primaws/rest/external/pnxs?acTriggered=false&blendFacetsSeparately=false&citationTrailFilterByAvailability=true&disableCache=false&getMore=0&inst=EXLDEV1_INST&isCDSearch=false&lang=en&limit=10&newspapersActive=true&newspapersSearch=false&offset=0&otbRanking=false&pcAvailability=true&q=any,contains,artificial+intelligence&qExclude=&qInclude=&rapido=false&refEntryActive=true&rtaLinks=true&scope=MyInstitution&searchInFulltextUserSelection=true&skipDelivery=Y&sort=rank&tab=LibraryCatalog&vid=EXLDEV1_INST:Alma">
</pnx-search-carousel>

</search-carousel>
</body>
<br>
<br>
<br>
<br>
<br>
<br>

<snx-search-carousel titleText="Summon Carousel Test!"
titleLink="https://www.google.com"
defaultThumbnailUrl="../dist/default.png"
searchUrl="https://demo.summon.serialssolutions.com/api/search?screen_res=W1486H382&__refererURL=&pn=1&ps=10&ho=t&include.ft.matches=t&fvf%5B%5D=IsOpenAccess%2Ctrue%2Cf&fvf%5B%5D=Language%2CEnglish%2Cf&l=en&q=artificial%20intelligence&print.books.only=true">
</snx-search-carousel>
</body>

</html>
69 changes: 44 additions & 25 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,49 @@ import {terser} from 'rollup-plugin-terser';
import resolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';

export default {
input: 'search-carousel.js',
output: {
file: 'dist/discovery-showcase.bundled.js',
format: 'esm',
const commonPlugins = [
replace({'Reflect.decorate': 'undefined'}),
resolve(),
terser({
ecma: 2017,
module: true,
warnings: true,
mangle: {
properties: {
regex: /^__/,
},
},
}),
summary(),
]

export default [
{
// Configuration for pnx-search-carousel.js
input: 'pnx-search-carousel.js',
output: {
file: 'dist/pnx-discovery-showcase.bundled.js',
format: 'esm',
},
onwarn(warning) {
if (warning.code !== 'THIS_IS_UNDEFINED') {
console.error(`(!) ${warning.message}`);
}
},
plugins: commonPlugins,
},
onwarn(warning) {
if (warning.code !== 'THIS_IS_UNDEFINED') {
console.error(`(!) ${warning.message}`);
}
{
// Configuration for snx-search-carousel.js
input: 'snx-search-carousel.js',
output: {
file: 'dist/snx-discovery-showcase.bundled.js',
format: 'esm',
},
onwarn(warning) {
if (warning.code !== 'THIS_IS_UNDEFINED') {
console.error(`(!) ${warning.message}`);
}
},
plugins: commonPlugins,
},
plugins: [
replace({'Reflect.decorate': 'undefined'}),
resolve(),
terser({
ecma: 2017,
module: true,
warnings: true,
mangle: {
properties: {
regex: /^__/,
},
},
}),
summary(),
],
};
];
99 changes: 99 additions & 0 deletions src/Externals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// JSONP based on https://github.com/erikarenhill/Lightweight-JSONP
export class Externals {
config: any
counter: any
head: any
readyState: any
window: any
constructor(window: any, config = {}){
this.window = window
this.config = config
this.counter = 0
this.head = document.getElementsByTagName('head')[0]
}

load(url: any, pfnError: any) {
const script : any = document.createElement('script')
let done = false
script.src = url
script.async = true
const errorHandler = pfnError || this.config.error
if (typeof errorHandler === 'function') {
script.onerror = ( ex: any )=> errorHandler({
url,
event: ex
})
}

script.onload = (script.onreadystatechange = function() {
if (!done && (!this.readyState || (this.readyState === 'loaded') || (this.readyState === 'complete'))) {
done = true
script.onload = (script.onreadystatechange = null)
if (script && script.parentNode) {
return script.parentNode.removeChild(script)
}
}
})

return this.head.appendChild(script)
}

jsonp(url: string, params: Record<string, any> = {}, callbackName?: string): Promise<any> {
return new Promise((resolve, reject) => {
const query = url.includes('?') ? '&' : '?';
const cbName = callbackName || this.config['callbackName'] || 'callback';
const uniqueName = `${cbName}_json${++this.counter}`;

// Add the callback parameter to the request
params[cbName] = uniqueName;
const fullUrl = url + query + this.objToQ(params);

// Attach the callback to the window object
this.window[uniqueName] = (data: any) => {
try {
resolve(data);
} finally {
// Clean up the callback to avoid memory leaks
delete this.window[uniqueName];
}
};

// Handle script loading and errors
this.load(fullUrl, (error: any) => {
reject(error);
});
});
}


encode(str: any) {
return encodeURIComponent(str)
}

// Object to url Query
objToQ(obj: any, arrayMark = true, arraySeparator = '', includeEmpties = false) {
if ((typeof obj !== 'object') || !Object.keys(obj).length) {
return ''
}
const keys = Object.keys(obj)
const str = []
for (var key of keys) {
var value = obj[key]
if (!includeEmpties && (!value || (value.length === 0))) { continue }

if (value instanceof Array) {
if (!arraySeparator) {
for (var val of value) {
str.push(this.encode(key + (arrayMark ? '[]' : '')) + '=' + this.encode(val))
}
} else {
str.push(this.encode(key) + '=' + this.encode(value.join(arraySeparator)))
}
} else {
str.push(this.encode(key) + '=' + this.encode(value))
}
}
return str.join('&')
}
}

47 changes: 47 additions & 0 deletions src/document-card-style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {css} from 'lit';

export const styles = css`
:host {
--title-font-color: inherit;
--title-font-weight: 700;
--title-font-size: 13px;

--description-font-color: inherit;
--description-font-weight: 400;
--description-font-size: 12px;

--image-height: 210px;
}

a {
text-decoration: none;
color: black;
display: flex;
flex-direction: column;
}

.record-details {
text-align: center;
color: black;
margin-top: .5em;
}

.record-details h3 {
color: var(--title-font-color);
font-size: var(--title-font-size);
font-weight: var(--title-font-weight);
}

.record-details span {
font-size: var(--description-font-size);
font-weight: var(--description-font-weight);
color: var(--description-font-color);
}

img, .image-place-holder {
height: var(--image-height);
display: block;
object-fit: contain;
}
`;

53 changes: 53 additions & 0 deletions src/document-card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {html, LitElement} from "lit";
import {customElement, property} from "lit/decorators.js";
import {styles} from './document-card-style';
import {until} from 'lit-html/directives/until.js';


@customElement('document-card')
export class DocumentCard extends LitElement {

static override styles = styles;
@property()
thumbnail: any;
@property()
docTitle!: string;
@property()
publisher!: string;
@property()
deepLink!: string;

override render() {
const imagePlaceHolder = html`
<div style="background-color: ${this.getRandomColor()}"
class="image-place-holder"></div>`;
const imgPromise = this.thumbnail.then((url: string) => {
console.log(`getImageUrl returned ${url}`)
return html`
<img src=${url} alt="">`
}).catch(() => imagePlaceHolder); //on error or no thumbnail render the image placeholder

return html`
<a href="${this.deepLink}" target="_blank" aria-label="">
${until(imgPromise, imagePlaceHolder)}
<div class="record-details">
<h3>${this.docTitle}</h3>
<span>${this.publisher ?? ''}</span>
</div>
</a>

`
}

private getRandomColor() {
const letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
}



33 changes: 33 additions & 0 deletions src/image-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export class ImageService {
public async getImageLink(imageUrl: string) {
return new Promise((resolve, reject) => {
if (!imageUrl) {
reject('');
return;
}

const image = new Image();
image.onload = () => {
if (image.width > 1) {
resolve(imageUrl);
} else {
reject('');
}
};

image.onerror = () => {
reject('');
};

image.src = this.handleLink(imageUrl);
});
}

public handleLink(link: string) {
let newLink = link;
if (window.location.protocol === 'https:') {
newLink = link.replace('http://', 'https://');
}
return newLink;
}
}
Loading