openaire-library/claims/linking/linkingGeneric.component.ts

141 lines
5.0 KiB
TypeScript
Raw Normal View History

import {Component, Input, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {Meta, Title} from '@angular/platform-browser';
import {EnvProperties} from '../../utils/properties/env-properties';
import {ClaimEntity, ShowOptions} from '../claim-utils/claimHelper.class';
import {EntitiesSearchService} from '../../utils/entitiesAutoComplete/entitySearch.service';
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
import {AlertModal} from "../../utils/modal/alert";
import {HelperFunctions} from "../../utils/HelperFunctions.class";
import {HelperService} from "../../utils/helper/helper.service";
import {PiwikService} from "../../utils/piwik/piwik.service";
declare var UIkit:any;
@Component({
selector: 'linking-generic',
templateUrl: 'linkingGeneric.component.html'
})
export class LinkingGenericComponent {
@Input() piwikSiteId = null;
@Input() pageTitle: string = null;
piwiksub:any;
@Input() communityId:string= null;
sourceType:string;
targetType:string;
step:number = 1;
@Input() results:ClaimEntity[] = [];
@Input() inlineEntity:ClaimEntity = null;
basketLimit =100;
@Input() showOptions:ShowOptions = new ShowOptions();
//show values: source, result, project, context, claim
// linkTo /values: result, project, context
// show linkToEntities /values: result, project, context
@Input() sources:ClaimEntity[] =[];
sub:any =null;
properties:EnvProperties;
@Input() localStoragePrefix:string = "linking_";
url=null;
@ViewChild(AlertModal) alert;
public pageContents = null;
constructor (private _router: Router, private route: ActivatedRoute, private entitySearch:EntitiesSearchService,
private _meta: Meta, private _title: Title, private _piwikService:PiwikService,
private seoService: SEOService, private helper: HelperService ) {
}
ngOnInit() {
this.showOptions.show = 'source';
if(this.inlineEntity){
this.showOptions.basketShowSources = false;
this.showOptions.basketShowLinksTo = true;
this.showOptions.show = this.showOptions.linkTo;
}
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.url = data.envSpecific.baseLink+this._router.url;
var description = "Openaire, linking, claim, publication, research data, software, other research product, project, community";
this.updateTitle(this.pageTitle);
this.updateDescription(description);
this.updateUrl(this.url);
this.seoService.createLinkForCanonicalURL(this.url, false);
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe();
}
this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
this.pageContents = contents;
})
});
if( typeof localStorage !== 'undefined') {
this.localStoragePrefix +=(this.communityId?this.communityId+"_":"");
if(localStorage.getItem(this.localStoragePrefix + "results")){
this.results = JSON.parse(localStorage.getItem(this.localStoragePrefix + "results"));
}
if(localStorage.getItem(this.localStoragePrefix + "sources")){
this.sources = JSON.parse(localStorage.getItem(this.localStoragePrefix + "sources"));
}
}
}
ngOnDestroy() {
if(this.piwiksub){
this.piwiksub.unsubscribe();
}
}
openSelectionModal() {
this.alert.cancelButton = false;
this.alert.okButton = false;
this.alert.alertTitle = "Select the type of Entity to Link to your sources";
// this.alert.message = "<div>All the links you provided will be published in the OpenAIRE platform. " +
// "<br>Make sure you have checked all the information you provided. In some cases some links take more time to be published. " +
// "<br>For more information please check the linking status in My-Links page. " +
// "<br><br>Do you confirm the information you provide are valid?</div>";
this.alert.open();
}
closeSelectionModal(show:string=null) {
if(show){
this.showOptions.show = show;
this.showOptions.basketShowSources=false;
this.showOptions.basketShowLinksTo=true;
}
this.alert.cancel();
this.scrollUp();
}
scrollUp(){
HelperFunctions.scroll();
}
private updateDescription(description:string) {
this._meta.updateTag({content:description},"name='description'");
this._meta.updateTag({content:description},"property='og:description'");
}
private updateTitle(title:string) {
var _prefix ="";
if(!this.communityId) {
_prefix ="OpenAIRE | ";
}
var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
this._title.setTitle(_title);
this._meta.updateTag({content:_title},"property='og:title'");
}
private updateUrl(url:string) {
this._meta.updateTag({content:url},"property='og:url'");
}
}