[Library|Trunk]

remove dependency for ngx-json-ld from schema2jsonld component and module



git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@61087 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
argiro.kokogiannaki 2021-06-04 08:18:01 +00:00
parent 1d9b94431d
commit eb2d232bb7
3 changed files with 13 additions and 7 deletions

View File

@ -1,11 +1,12 @@
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
import {OpenAireJsonldConverterService} from './service/open-aire-jsonld-converter.service';
import {JsonldDocumentSerializerService} from './service/jsonld-document-serializer.service';
import {DomSanitizer} from "@angular/platform-browser";
@Component({
selector: 'schema2jsonld',
template: `
<ngx-json-ld [json]="json"></ngx-json-ld>
<div *ngIf="html" [innerHTML]="html"></div>
`
})
export class Schema2jsonldComponent implements OnInit, OnChanges {
@ -19,9 +20,9 @@ export class Schema2jsonldComponent implements OnInit, OnChanges {
@Input() description = null;
@Input() searchActionRoute = "/search/find/";
public json;
public html;
constructor(private documentParser: OpenAireJsonldConverterService,
private documentSerializer: JsonldDocumentSerializerService) {
private documentSerializer: JsonldDocumentSerializerService, private sanitizer: DomSanitizer) {
}
ngOnChanges(changes: SimpleChanges): void {
@ -32,7 +33,11 @@ export class Schema2jsonldComponent implements OnInit, OnChanges {
ngOnInit() {
this.createJson();
}
getSafeHTML(value) {
let json = JSON.stringify(value, null, 2);
let html = "<script type=\"application/ld+json\">" + json + "</script>";
return this.sanitizer.bypassSecurityTrustHtml(html);
};
createJson(){
var docOvject;
if (this.type == 'project') {
@ -54,5 +59,6 @@ export class Schema2jsonldComponent implements OnInit, OnChanges {
} else {
this.json = this.documentParser.createSimplePage(this.name, this.URL, this.description);
}
this.html = this.getSafeHTML(this.json);
}
}

View File

@ -4,9 +4,8 @@ import { FormsModule } from '@angular/forms';
import { OpenAireJsonldConverterService } from './service/open-aire-jsonld-converter.service';
import { JsonldDocumentSerializerService } from './service/jsonld-document-serializer.service';
import {Schema2jsonldComponent} from './schema2jsonld.component';
import { NgxJsonLdModule } from 'ngx-json-ld';
@NgModule({
imports: [CommonModule, FormsModule, NgxJsonLdModule],
imports: [CommonModule, FormsModule],
declarations: [Schema2jsonldComponent],
providers:[OpenAireJsonldConverterService, JsonldDocumentSerializerService],
exports: [Schema2jsonldComponent]

View File

@ -44,9 +44,10 @@ export class OpenAireJsonldConverterService {
searchPage["@type"] = "Website";
searchPage["name"] = name;
searchPage["url"] = URL + searchRoute;
/* no valid property for Website
if(logoURL && logoURL.length > 0 ) {
searchPage["logo"] = logoURL;
}
}*/
if (description) {
searchPage["description"] = description;
}