[Library|Trunk]

Citations:
	- update library and use citation-js
	- allow download for bibtex and ris formats
	- update bibtext cls

Result landing: update checks for no index tag

 


git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60181 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
argiro.kokogiannaki 2020-12-23 15:25:11 +00:00
parent 83061f3f16
commit b7a67afeb2
3 changed files with 136 additions and 68 deletions

File diff suppressed because one or more lines are too long

View File

@ -10,11 +10,11 @@ import {
import {Citation, CitationData} from './citation.class';
import {ResultLandingInfo} from "../../../utils/entities/resultLandingInfo";
import {DOCUMENT} from "@angular/common";
import {EnvProperties} from "../../../utils/properties/env-properties";
import {properties} from "../../../../../environments/environment";
declare var CSL: any;
declare var Sys: any;
declare var UIkit: any;
declare var Cite: any;
// Based on https://citation.js.org/api/tutorial-getting_started.html browser release
//<citeThis ></citeThis>
@Component({
selector: 'citeThis',
@ -38,49 +38,80 @@ declare var UIkit: any;
<span class="uk-margin-small-left">COPY</span>
</button>
</div>
<div *ngIf="properties.environment == 'development'" class="uk-margin-small-top">
<mat-form-field class="matSelectionFormField uk-width-1-1">
<mat-label>Or select file format to download</mat-label>
<mat-select class="matSelection" id="fileformats" name="fileformatsSelect" [(ngModel)]="selectedFormat"
(ngModelChange)="formatChanged()"
[disableOptionCentering]="true"
panelClass="matSelectionPanel">
<mat-option *ngFor=" let format of citation.fileFormats let i = index"
[value]="format">{{format + " (" +citation.fileSuffix[i] + ")"}}</mat-option>
</mat-select>
</mat-form-field>
<!-- <div *ngIf="selectedFormat">
<div id="citation" class="box-content uk-margin-small-top uk-overflow-auto uk-padding-small" [innerHTML]="fileText"></div>
</div>-->
<button class=" uk-button uk-button-primary uk-button-small copy uk-margin-small-top uk-icon uk-float-right"
title="Copy to clipboard" [disabled]="!selectedFormat" (click)="downloadFile()">
<span class="custom-icon " uk-icon="download"></span>
<span class="uk-margin-small-left">Download</span>
</button>
</div>
</div>
`
})
export class CiteThisComponent implements OnInit, OnDestroy {
private sub: any;
public selectedStyle: string = null;
public selectedFormat: string = null;
public fileText: string;
properties:EnvProperties;
public citationText: string;
public citation: Citation = new Citation();
// public cite: any;
@Input() result: ResultLandingInfo;
@Input() id: string;
@Input() type: string = "article";
public citeproc;
public data;
public data:CitationData;
public clipboard;
timeout;
cite;citeConfig;
constructor( @Inject(DOCUMENT) private document, private rendererFactory: RendererFactory2){
}
ngOnInit() {
this.properties = properties;
try{
if (!this.document.getElementById('citeThisScript')) {
const renderer = this.rendererFactory.createRenderer(this.document, {
id: '-1',
encapsulation: ViewEncapsulation.None,
styles: [],
data: {}
});
const head = this.document.head;
if (head === null) {
throw new Error('<head> not found within DOCUMENT.');
if (!this.document.getElementById('citationjs')) {
const renderer = this.rendererFactory.createRenderer(this.document, {
id: '-1',
encapsulation: ViewEncapsulation.None,
styles: [],
data: {}
});
const head = this.document.head;
if (head === null) {
throw new Error('<head> not found within DOCUMENT.');
}
const script = renderer.createElement('script');
renderer.setAttribute(script, "id", "citationjs");
renderer.setAttribute(script, "src", "assets/common-assets/citation-0.4.0-9.min.js");
renderer.setAttribute(script, "type", "text/javascript");
renderer.appendChild(head, script);
this.timeout = setTimeout(() => {
const script2 = renderer.createElement('script');
renderer.setAttribute(script2, "type", "text/javascript");
renderer.setProperty(script2, "text","const Cite = require('citation-js')");
renderer.appendChild(head, script2);
}, 300);
}
const script = renderer.createElement('script');
renderer.setAttribute(script, "id", "citeThisScript");
renderer.setAttribute(script, "src", "assets/common-assets/citeproc.js");
renderer.setAttribute(script, "type", "text/javascript");
renderer.appendChild(head, script);
}
this.timeout = setTimeout(() => {
this.citeConfig = Cite.plugins.config.get('csl');
this.cite = new Cite();
this.parseData();
this.selectedStyle = this.citation.templates[0];
this.updateCitation();
this.selectedFormat = this.citation.fileFormats[0];
this.styleChanged();
this.formatChanged();
this.createClipboard();
}, 800);
@ -119,9 +150,7 @@ export class CiteThisComponent implements OnInit, OnDestroy {
}
}
citationData.id = this.id;
if (this.result.types != undefined && this.result.types.length > 0 && this.result.types[0]) {
citationData.type = this.result.types[0].toLowerCase();
}
citationData.type = this.mapTypes();
if (this.result.title) {
citationData.title = this.result.title;
}
@ -178,40 +207,79 @@ export class CiteThisComponent implements OnInit, OnDestroy {
this.data = citationData;
// console.log(this.data);
this.cite.set(this.data);
}
styleChanged() {
this.updateCitation();
}
updateCitation() {
var Sys =
function Sys(lang, data) {
this.lang = lang;
this.data = data;
this.changeName = function (name) {
this.lastName = name;
};
this.retrieveLocale = function (lang) {
return this.lang;
}
this.retrieveItem = function (id) {
return this.data;
}
};
try {
var citeproc = new CSL.Engine(new Sys(this.citation.locale, this.data), this.citation[(this.selectedStyle == "0") ? this.citation.templates[0] : this.selectedStyle]);
citeproc.updateItems([this.data.id]);
this.citationText = citeproc.makeBibliography();
this.citationText = ((this.citationText != null) && (this.citationText.length > 1) && (this.citationText[1].length > 0)) ? this.citationText[1][0] : '';
}catch (e) {
private mapTypes(){
if (this.result.types != undefined && this.result.types.length > 0) {
if(this.result.types.indexOf("Article") != -1) {
return "article";
}else if(this.result.types.indexOf("Conference object") != -1){
return "paper-conference";
}else if( this.result.types[0]){
return this.result.types[0].toLowerCase();
}
}
return "";
}
styleChanged() {
this.citationText = this.get(this.selectedStyle);
}
formatChanged() {
this.fileText = this.get(this.selectedFormat, false);
}
downloadFile(){
if (typeof document !== 'undefined') {
var url = window.URL.createObjectURL(new Blob([this.fileText]));
var a = window.document.createElement('a');
window.document.body.appendChild(a);
a.setAttribute('style', 'display: none');
a.href = url;
a.download = this.selectedFormat + this.citation.fileSuffix[this.citation.fileFormats.indexOf(this.selectedFormat)];
a.click();
window.URL.revokeObjectURL(url);
a.remove(); // remove the element
}
}
get(style:string, isBibliography:boolean = true){
try {
if (!isBibliography && style != "bibtex") {
return this.getFormat(style);
} else {
return this.getBibliography(style);
}
}catch (e) {
console.error(e);
return "";
}
}
/**
* Supports formats bibtex, bibtxt, ris
* @param format
*/
getFormat(format:string) {
return this.cite.format(format, {
format: 'text'
});
}
/**
* Based on this and citeproc library https://citation.js.org/api/tutorial-plugins.html
* if the template doesn;t exist add the CSL xml and the library will produce the citation
* @param template
*/
getBibliography(template:string) {
if (!this.citeConfig.templates.get(template)) {
this.citeConfig.templates.add(template, this.citation[template]);
}
return this.cite.format('bibliography', {
format: 'text',
template: template,
lang: 'en-US'
});
}
}

View File

@ -567,18 +567,17 @@ export class ResultLandingComponent {
this.citeThisClicked = true;
this.citeModal.cancelButton = false;
this.citeModal.okButton = false;
this.citeModal.alertTitle = "Cite this " + this.getTypeName() + " to";
this.citeModal.alertTitle = "Cite this " + this.getTypeName();
this.citeModal.open();
}
addNoIndexFilter() {
try {
if(this.properties.environment != "production") {
if(!(this.properties.environment == "production" || this.properties.environment == "development") ) {
return ;
}else {
let addFilter = !(!this.resultLandingInfo.underCurationMessage &&
let allow = !!(!this.resultLandingInfo.underCurationMessage &&
((this.resultLandingInfo.fundedByProjects && this.resultLandingInfo.fundedByProjects.length > 0)
|| this.resultLandingInfo.journal
|| (this.resultLandingInfo.otherSubjects && this.resultLandingInfo.otherSubjects.size > 0)
|| (this.resultLandingInfo.classifiedSubjects && this.resultLandingInfo.classifiedSubjects.size > 0)
|| (this.resultLandingInfo.organizations && this.resultLandingInfo.organizations.length > 0)
|| this.resultLandingInfo.bioentities || (this.resultLandingInfo.references && this.resultLandingInfo.references.length > 0)
@ -587,7 +586,7 @@ export class ResultLandingComponent {
|| (this.resultLandingInfo.supplementaryResearchResults && this.resultLandingInfo.supplementaryResearchResults.length > 0)
|| (this.resultLandingInfo.supplementedByResearchResults && this.resultLandingInfo.supplementedByResearchResults.length > 0)
));
if(addFilter) {
if(!allow) {
this._meta.updateTag({content: 'noindex'}, "name='robots'");
}
}