[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:
parent
1d9b94431d
commit
eb2d232bb7
|
@ -1,11 +1,12 @@
|
||||||
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
||||||
import {OpenAireJsonldConverterService} from './service/open-aire-jsonld-converter.service';
|
import {OpenAireJsonldConverterService} from './service/open-aire-jsonld-converter.service';
|
||||||
import {JsonldDocumentSerializerService} from './service/jsonld-document-serializer.service';
|
import {JsonldDocumentSerializerService} from './service/jsonld-document-serializer.service';
|
||||||
|
import {DomSanitizer} from "@angular/platform-browser";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'schema2jsonld',
|
selector: 'schema2jsonld',
|
||||||
template: `
|
template: `
|
||||||
<ngx-json-ld [json]="json"></ngx-json-ld>
|
<div *ngIf="html" [innerHTML]="html"></div>
|
||||||
`
|
`
|
||||||
})
|
})
|
||||||
export class Schema2jsonldComponent implements OnInit, OnChanges {
|
export class Schema2jsonldComponent implements OnInit, OnChanges {
|
||||||
|
@ -19,9 +20,9 @@ export class Schema2jsonldComponent implements OnInit, OnChanges {
|
||||||
@Input() description = null;
|
@Input() description = null;
|
||||||
@Input() searchActionRoute = "/search/find/";
|
@Input() searchActionRoute = "/search/find/";
|
||||||
public json;
|
public json;
|
||||||
|
public html;
|
||||||
constructor(private documentParser: OpenAireJsonldConverterService,
|
constructor(private documentParser: OpenAireJsonldConverterService,
|
||||||
private documentSerializer: JsonldDocumentSerializerService) {
|
private documentSerializer: JsonldDocumentSerializerService, private sanitizer: DomSanitizer) {
|
||||||
|
|
||||||
}
|
}
|
||||||
ngOnChanges(changes: SimpleChanges): void {
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
@ -32,7 +33,11 @@ export class Schema2jsonldComponent implements OnInit, OnChanges {
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.createJson();
|
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(){
|
createJson(){
|
||||||
var docOvject;
|
var docOvject;
|
||||||
if (this.type == 'project') {
|
if (this.type == 'project') {
|
||||||
|
@ -54,5 +59,6 @@ export class Schema2jsonldComponent implements OnInit, OnChanges {
|
||||||
} else {
|
} else {
|
||||||
this.json = this.documentParser.createSimplePage(this.name, this.URL, this.description);
|
this.json = this.documentParser.createSimplePage(this.name, this.URL, this.description);
|
||||||
}
|
}
|
||||||
|
this.html = this.getSafeHTML(this.json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,8 @@ import { FormsModule } from '@angular/forms';
|
||||||
import { OpenAireJsonldConverterService } from './service/open-aire-jsonld-converter.service';
|
import { OpenAireJsonldConverterService } from './service/open-aire-jsonld-converter.service';
|
||||||
import { JsonldDocumentSerializerService } from './service/jsonld-document-serializer.service';
|
import { JsonldDocumentSerializerService } from './service/jsonld-document-serializer.service';
|
||||||
import {Schema2jsonldComponent} from './schema2jsonld.component';
|
import {Schema2jsonldComponent} from './schema2jsonld.component';
|
||||||
import { NgxJsonLdModule } from 'ngx-json-ld';
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [CommonModule, FormsModule, NgxJsonLdModule],
|
imports: [CommonModule, FormsModule],
|
||||||
declarations: [Schema2jsonldComponent],
|
declarations: [Schema2jsonldComponent],
|
||||||
providers:[OpenAireJsonldConverterService, JsonldDocumentSerializerService],
|
providers:[OpenAireJsonldConverterService, JsonldDocumentSerializerService],
|
||||||
exports: [Schema2jsonldComponent]
|
exports: [Schema2jsonldComponent]
|
||||||
|
|
|
@ -44,9 +44,10 @@ export class OpenAireJsonldConverterService {
|
||||||
searchPage["@type"] = "Website";
|
searchPage["@type"] = "Website";
|
||||||
searchPage["name"] = name;
|
searchPage["name"] = name;
|
||||||
searchPage["url"] = URL + searchRoute;
|
searchPage["url"] = URL + searchRoute;
|
||||||
|
/* no valid property for Website
|
||||||
if(logoURL && logoURL.length > 0 ) {
|
if(logoURL && logoURL.length > 0 ) {
|
||||||
searchPage["logo"] = logoURL;
|
searchPage["logo"] = logoURL;
|
||||||
}
|
}*/
|
||||||
if (description) {
|
if (description) {
|
||||||
searchPage["description"] = description;
|
searchPage["description"] = description;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue