Change piwik service methods in order to get the piwik from portal configuration

This commit is contained in:
Konstantinos Triantafyllou 2023-04-26 14:10:45 +03:00
parent c547dfa945
commit 49e2edfe84
19 changed files with 101 additions and 164 deletions

View File

@ -111,7 +111,7 @@ export class DisplayClaimsComponent implements OnInit, OnDestroy {
this.updateDescription(description);
this.updateUrl(this.url);
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe());
this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe());
}
this.subscriptions.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {

View File

@ -75,7 +75,7 @@ export class LinkingGenericComponent {
this.seoService.createLinkForCanonicalURL(this.url, false);
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe());
this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe());
}
this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {

View File

@ -203,7 +203,7 @@ export class DepositFirstPageComponent {
}
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
this.subscriptions.push(this._piwikService.trackView(this.properties, this.title, this.piwikSiteId).subscribe());
this.subscriptions.push(this._piwikService.trackView(this.properties, this.title).subscribe());
}
this.breadcrumbs.push({name: 'home', route: '/'}, {name: "Deposit", route: null});
}

View File

@ -23,7 +23,7 @@ export class IsRouteEnabled implements CanActivate {
if (!community) {
community = properties.adminToolsCommunity;
}
return this.config.isPageEnabledByState(properties, community, '/' + path).pipe(take(1), tap((enabled) => {
return this.config.isPageEnabled(properties, community, '/' + path).pipe(take(1), tap((enabled) => {
if (!enabled) {
this.router.navigate([redirect], {queryParams: {'page': path}});
}

View File

@ -64,7 +64,7 @@ export class FosComponent implements OnInit, OnDestroy {
ngOnInit() {
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe());
this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe());
}
this.url = this.properties.domain + this.properties.baseLink + this._router.url;
this.seoService.createLinkForCanonicalURL(this.url);

View File

@ -377,7 +377,7 @@ export class DataProviderComponent {
this.updateTitle(this.dataProviderInfo.title.name?this.dataProviderInfo.title.name:this.dataProviderInfo.officialName);
this.updateDescription((this.dataProviderInfo.description ? (this.dataProviderInfo.description.substr(0,157) + (this.dataProviderInfo.description.substr(0,157).length == 157?"...":"")) : (this.dataProviderInfo.title.name?this.dataProviderInfo.title.name:this.dataProviderInfo.officialName)));
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subscriptions.push(this._piwikService.trackView(this.properties, this.dataProviderInfo.title.name, this.piwikSiteId).subscribe());
this.subscriptions.push(this._piwikService.trackView(this.properties, this.dataProviderInfo.title.name).subscribe());
}
this.showLoading = false;

View File

@ -171,7 +171,7 @@ export class HtmlProjectReportComponent {
this.updateTitle(data.title + " " + this.resultsType + " report");
}
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subscriptions.push(this._piwikService.trackView(this.properties, ((data.acronym) ? data.acronym : data.title) + " " + this.resultsType + " report", this.piwikSiteId).subscribe());
this.subscriptions.push(this._piwikService.trackView(this.properties, ((data.acronym) ? data.acronym : data.title) + " " + this.resultsType + " report").subscribe());
}
},
err => {

View File

@ -395,7 +395,7 @@ export class OrganizationComponent {
((this.organizationInfo.title.name && this.organizationInfo.title.name != this.organizationInfo.name) ? (', ') : '') +
(this.organizationInfo.name?this.organizationInfo.name:''));
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subscriptions.push(this._piwikService.trackView(this.properties, this.organizationInfo.title.name, this.piwikSiteId).subscribe());
this.subscriptions.push(this._piwikService.trackView(this.properties, this.organizationInfo.title.name).subscribe());
}
var refineFields: string [] = ["funder"];

View File

@ -498,7 +498,7 @@ export class ProjectComponent {
// this.updateDescription(this.projectInfo.description?this.projectInfo.description: ("project" + (this.projectInfo.title?"," + this.projectInfo.title:"") + (this.projectInfo.funding && this.projectInfo.funding.funderName?", funder: " + this.projectInfo.funding.funderName:"") + (this.projectInfo.acronym?"," + this.projectInfo.acronym:"")));
this.updateDescription((this.projectInfo.description ? (this.projectInfo.description.substr(0,157) + (this.projectInfo.description.substr(0,157).length == 157?"...":"")) : (this.projectInfo.title)));
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subscriptions.push(this._piwikService.trackView(this.properties, this.projectName, this.piwikSiteId).subscribe());
this.subscriptions.push(this._piwikService.trackView(this.properties, this.projectName).subscribe());
}
this.project = {

View File

@ -485,7 +485,7 @@ export class ResultLandingComponent {
this.updateDescription((this.resultLandingInfo.description ? (this.resultLandingInfo.description.substr(0,157) + (this.resultLandingInfo.description.substr(0,157).length == 157?"...":"")) : (this.resultLandingInfo.title)));
}
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subscriptions.push(this._piwikService.trackViewForCustomUrl(this.properties, this.resultLandingInfo.title, this.linkToLandingPage.split("?")[1] + this.id ,this.piwikSiteId).subscribe());
this.subscriptions.push(this._piwikService.trackViewForCustomUrl(this.properties, this.resultLandingInfo.title, this.linkToLandingPage.split("?")[1] + this.id).subscribe());
}
let bioentitiesNum = 0;

View File

@ -188,7 +188,7 @@ export class MyOrcidLinksComponent {
this.updateUrl( properties.domain + properties.baseLink + this.route.url);
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
this.subscriptions.push(this._piwikService.trackView(this.properties, "My ORCID links", this.piwikSiteId).subscribe());
this.subscriptions.push(this._piwikService.trackView(this.properties, "My ORCID links").subscribe());
}
this.typeQuery = "&type=results";

View File

@ -48,7 +48,7 @@ export class SdgComponent implements OnInit, OnDestroy {
ngOnInit() {
this.loading = true;
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe());
this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe());
}
this.url = this.properties.domain + this.properties.baseLink + this._router.url;
this.seoService.createLinkForCanonicalURL(this.url);

View File

@ -153,14 +153,14 @@ export class SearchAllComponent {
this._meta.updateTag({content: url}, "property='og:url'");
this.seoService.createLinkForCanonicalURL(this.properties.domain +this.properties.baseLink + this._router.url, false);
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subs.push(this._piwikService.trackView(this.properties, title, this.piwikSiteId).subscribe());
this.subs.push(this._piwikService.trackView(this.properties, title).subscribe());
}
if ((this.customFilter && this.customFilter.queryFieldName == "communityId") || this.properties.adminToolsCommunity) {
//this.config.getCommunityInformation(this.properties, (this.customFilter && this.customFilter.queryFieldName == "communityId") ? this.customFilter.valueId : this.properties.adminToolsCommunity).subscribe(data => {
this.subs.push(this.config.communityInformationState.subscribe(data => {
this.subs.push(this.config.portalAsObservable.subscribe(data => {
if(data && data['entities']) {
var showEntity = {};
for (var i = 0; i < data['entities'].length; i++) {

View File

@ -41,7 +41,7 @@ export class EntitiesSelectionComponent {
/** TODO change conditions base on PortalType instead of customFilter */
ngOnInit() {
if ((this.customFilter && this.customFilter.queryFieldName == "communityId") || (['explore', 'aggregator', 'eosc'].includes(this.properties.adminToolsPortalType))) {
this.subscriptions.push(this.config.communityInformationState.subscribe(data => {
this.subscriptions.push(this.config.portalAsObservable.subscribe(data => {
if (data) {
let showEntity = {};
let showPage = {};

View File

@ -176,7 +176,7 @@ export class NewSearchPageComponent implements OnInit, OnDestroy, OnChanges {
this.updateUrl(this.properties.domain + this.properties.baseLink + this.router.url);
this.url = this.properties.domain + this.properties.baseLink + this.router.url;
if (typeof document !== 'undefined' && this.isPiwikEnabled && !this.includeOnlyResultsAndFilter && this.piwikSiteId) {
this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe());
this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe());
}
this.layoutService.isMobile.subscribe(isMobile => {
this.isMobile = isMobile;
@ -353,7 +353,7 @@ export class NewSearchPageComponent implements OnInit, OnDestroy, OnChanges {
localStorage.setItem('previousRoute', this.router.url);
}
if (this.isPiwikEnabled && (typeof document !== 'undefined') && this.piwikSiteId) {
this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe());
this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe());
}
/* End Piwik Code */
}

View File

@ -41,7 +41,7 @@ export class BottomComponent {
if (this.showMenuItems) {
if (this.properties.adminToolsAPIURL && this.communityId) {
//this.subs.push(this.config.getCommunityInformation(this.properties, this.communityId ).subscribe(data => {
this.subs.push(this.config.communityInformationState.subscribe(data => {
this.subs.push(this.config.portalAsObservable.subscribe(data => {
if (data) {
for (var i = 0; i < data['pages'].length; i++) {
this.showPage[data['pages'][i]["route"]] = data['pages'][i]["isEnabled"];

View File

@ -106,7 +106,7 @@ export class NavigationBarComponent implements OnInit, OnDestroy, OnChanges {
this.isAuthorized = Session.isClaimsCurator(this.user) || Session.isPortalAdministrator(this.user);
if ((this.properties.adminToolsAPIURL && this.communityId) || properties.adminToolsPortalType == "community") {
//this.config.getCommunityInformation(this.properties, this.communityId).subscribe(data => {
this.subs.push(this.config.communityInformationState.subscribe(data => {
this.subs.push(this.config.portalAsObservable.subscribe(data => {
if (data) {
this.showEntity = {};
this.showPage = {};

View File

@ -1,15 +1,15 @@
import {Injectable, OnDestroy} from '@angular/core';
import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {BehaviorSubject, from, Observable, of, Subscription} from 'rxjs';
import {map} from 'rxjs/operators';
import {from, Observable, Subscription} from 'rxjs';
import {EnvProperties} from "../properties/env-properties";
import {Portal} from "../entities/adminTool/portal";
import {Page} from "../entities/adminTool/page";
import {properties} from "../../../../environments/environment";
import {AdvancedAsyncSubject} from "../AdvancedAsyncSubject";
@Injectable({providedIn: 'root'})
export class ConfigurationService {
private communityInformation: BehaviorSubject<Portal> = new BehaviorSubject(null);
private portal: AdvancedAsyncSubject<Portal> = new AdvancedAsyncSubject<Portal>();
private sub: Subscription = null;
private promise: Promise<void> = null;
@ -26,73 +26,34 @@ export class ConfigurationService {
}
}
/**
* @deprecated
*/
getCommunityInformation(properties: EnvProperties, community: string) {
let url = properties.adminToolsAPIURL + "/" + properties.adminToolsPortalType + "/" + community + '/full';
return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
//.map(res => res.json());
}
public initStaticCommunityInformation(communityInformation: Portal) {
this.promise = new Promise<void>((resolve => {
this.communityInformation.next(communityInformation);
resolve();
}));
}
public initCommunityInformation(properties: EnvProperties, community: string) {
if (community == null) return;
let url = properties.adminToolsAPIURL + "/" + properties.adminToolsPortalType + "/" + community + "/full";
public initPortal(properties: EnvProperties, pid: string) {
if (pid == null) return;
let url = properties.adminToolsAPIURL + "/" + properties.adminToolsPortalType + "/" + pid + "/full";
this.promise = new Promise<void>((resolve => {
this.sub = this.http.get<Portal>((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url).subscribe(
(communityInformation: Portal) => {
this.communityInformation.next(communityInformation);
this.portal.next(communityInformation);
resolve();
},
error => {
this.communityInformation.error(error);
this.portal.error(error);
resolve();
});
}));
}
public get communityInformationState(): Observable<Portal> {
return this.communityInformation.asObservable();
public get portalAsObservable(): Observable<Portal> {
return this.portal.asObservable();
}
/**
* @deprecated
*/
isEntityEnabled(APIUrl: string, community: string, entity: string) {
//console.log("isEntityEnabled: "+entity);
let url = "isEntityEnabled-" + entity;
// if(entity == "publication" || entity == "dataset" || entity == "datasource"){
// return Observable.of(new Object()).mapTo(false);
// }
// return Observable.of(new Object()).mapTo(true);
return this.http.get(APIUrl + "/page")
.pipe(map(res => true));
get piwik() {
return this.portal.value?.piwik ? this.portal.value.piwik : properties.piwikSiteId;
}
isPageEnabled(portal: string, route: string, portalType = properties.adminToolsPortalType) {
let url = properties.adminToolsAPIURL + "/" + portalType + "/" + portal + "/pages?page_route=" + route;
return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
.pipe(map(res => {
let result = false;
if (res['length'] > 0 && res[0].route == route) {
result = res[0].isEnabled;
}
return result;
}));
}
async isPageEnabledByStateAsync(properties: EnvProperties, portal: string, page_route: string) {
if (!this.promise || (this.communityInformation && this.communityInformation.getValue() && portal !== this.communityInformation.getValue().pid)) {
this.initCommunityInformation(properties, portal);
async isPageEnabledAsync(properties: EnvProperties, portal: string, page_route: string) {
if (!this.promise || (this.portal && this.portal.getValue() && portal !== this.portal.getValue().pid)) {
this.initPortal(properties, portal);
}
await this.promise;
@ -102,13 +63,13 @@ export class ConfigurationService {
return this.filtering(page_route);
}
isPageEnabledByState(properties: EnvProperties, portal: string, router: string): Observable<boolean> {
isPageEnabled(properties: EnvProperties, portal: string, router: string): Observable<boolean> {
let page_route: string = router.split('?')[0].substring(1);
return from(this.isPageEnabledByStateAsync(properties, portal, page_route));
return from(this.isPageEnabledAsync(properties, portal, page_route));
}
filtering(page_route: string) {
let community: Portal = this.communityInformation.getValue();
let community: Portal = this.portal.getValue();
let pages: Page[] = <Page[]>community.pages;
if (pages) {
let page = pages.find((page: Page) => page.route == page_route);
@ -117,38 +78,4 @@ export class ConfigurationService {
return false;
}
}
/**
* @deprecated
*/
getMainPageContent(APIUrl: string, community: string,) {
return this.http.get(APIUrl + "/page")
.pipe(map(res => true));
}
/**
* @deprecated
*/
getSpecialAnouncementContent(APIUrl: string, community: string,) {
return this.http.get(APIUrl + "/page")
.pipe(map(res => ""));
}
/**
* @deprecated
*/
getHelpPageContent(APIUrl: string, community: string, router: string) {
return this.http.get(APIUrl + "/page")
.pipe(map(res => true));
}
// private handleError (error: Response) {
// // in a real world app, we may send the error to some remote logging infrastructure
// // instead of just logging it to the console
// console.log(error);
// return this.http.get(this.APIUrl + "/page")
// .map(res => true);
// }
}

View File

@ -4,75 +4,85 @@ import {HttpClient} from "@angular/common/http";
import {StringUtils} from '../string-utils.class';
import {EnvProperties} from '../properties/env-properties';
import {Observable} from "rxjs";
import {ConfigurationService} from "../configuration/configuration.service";
@Injectable()
export class PiwikService {
constructor(private http: HttpClient ) {}
trackViewForCustomUrl (properties:EnvProperties, title, pageparams, siteId = null):any {
let piwikId= ((siteId!=null)?siteId:properties.piwikSiteId);
if(typeof location !== 'undefined' && piwikId){
return this.doTrackView(properties,title,piwikId,location.href.split("?")[0] + "?" + pageparams);
constructor(private http: HttpClient, private configurationService: ConfigurationService) {
}
trackViewForCustomUrl(properties: EnvProperties, title, pageparams): any {
let piwikId = this.configurationService.piwik;
if (typeof location !== 'undefined' && piwikId) {
return this.doTrackView(properties, title, piwikId, location.href.split("?")[0] + "?" + pageparams);
}
}
trackView (properties:EnvProperties, title, siteId = null):any {
let piwikId= ((siteId!=null)?siteId:properties.piwikSiteId);
if(typeof location !== 'undefined' && piwikId){
return this.doTrackView(properties,title,piwikId,location.href);
}
trackView(properties: EnvProperties, title): any {
let piwikId = this.configurationService.piwik;
console.log(piwikId);
if (typeof location !== 'undefined' && piwikId) {
return this.doTrackView(properties, title, piwikId, location.href);
}
private doTrackView (properties:EnvProperties, title, siteId, pageURL):any {
}
private doTrackView(properties: EnvProperties, title, siteId, pageURL): any {
let ua = this.getUserAgent();
let referrer = this.getReferrer();
let piwikId= ((siteId!=null)?siteId:properties.piwikSiteId);
if(typeof location !== 'undefined' && piwikId){
let piwikId = ((siteId != null) ? siteId : properties.piwikSiteId);
if (typeof location !== 'undefined' && piwikId) {
// console.log("Piwik - View: " + pageURL, title);
var url = properties.piwikBaseUrl+piwikId+"&rec=1&url="+StringUtils.URIEncode(pageURL)+"&action_name="+StringUtils.URIEncode(title)+
((ua != null && ua.length > 0)?('&ua='+StringUtils.URIEncode(ua)):'')+
((referrer != null && referrer.length > 0)?('&urlref='+StringUtils.URIEncode(referrer)):'');
var url = properties.piwikBaseUrl + piwikId + "&rec=1&url=" + StringUtils.URIEncode(pageURL) + "&action_name=" + StringUtils.URIEncode(title) +
((ua != null && ua.length > 0) ? ('&ua=' + StringUtils.URIEncode(ua)) : '') +
((referrer != null && referrer.length > 0) ? ('&urlref=' + StringUtils.URIEncode(referrer)) : '');
// console.log("Piwik - View: " + url);
// return Observable.of(new Object()); // for testing
return this.http.get( url, {responseType: 'blob'});
return this.http.get(url, {responseType: 'blob'});
// .do(request => console.info("Piwik request completed" ));
}
}
trackDownload (properties:EnvProperties, type = "", siteId = null):any {
var ua = this.getUserAgent();
var referrer = this.getReferrer();
var url = properties.piwikBaseUrl+((siteId!=null)?siteId:properties.piwikSiteId)+"&rec=1&url="+StringUtils.URIEncode(location.href)+"&download="+StringUtils.URIEncode(location.href+"#"+type)+
((ua != null && ua.length > 0)?('&ua='+StringUtils.URIEncode(ua)):'')+
((referrer != null && referrer.length > 0)?('&urlref='+StringUtils.URIEncode(referrer)):'');
//console.log("Piwik - trackDownload: "+url);
return this.http.get( url, {responseType: 'blob'});
//.do(request => console.info("Piwik request completed" ));
trackDownload(properties: EnvProperties, type = "", siteId = null): any {
var ua = this.getUserAgent();
var referrer = this.getReferrer();
var url = properties.piwikBaseUrl + ((siteId != null) ? siteId : properties.piwikSiteId) + "&rec=1&url=" + StringUtils.URIEncode(location.href) + "&download=" + StringUtils.URIEncode(location.href + "#" + type) +
((ua != null && ua.length > 0) ? ('&ua=' + StringUtils.URIEncode(ua)) : '') +
((referrer != null && referrer.length > 0) ? ('&urlref=' + StringUtils.URIEncode(referrer)) : '');
//console.log("Piwik - trackDownload: "+url);
return this.http.get(url, {responseType: 'blob'});
//.do(request => console.info("Piwik request completed" ));
}
private getUserAgent() {
if (typeof navigator !== 'undefined') {
//console.log("navigator.userAgent:" + navigator.userAgent);
return navigator.userAgent;
} else {
return null;
}
}
private getReferrer() {
var referrer = "";
if (typeof document !== 'undefined') {
//console.log("document.referrer:" + document.referrer);
referrer = document.referrer;
}
private getUserAgent(){
if (typeof navigator !== 'undefined') {
//console.log("navigator.userAgent:" + navigator.userAgent);
return navigator.userAgent;
if ((referrer == null || referrer.length == 0) && typeof localStorage !== 'undefined') {
}else{
return null;
}
referrer = localStorage.getItem('previousRoute');
}
private getReferrer(){
var referrer = "";
if (typeof document !== 'undefined') {
//console.log("document.referrer:" + document.referrer);
referrer = document.referrer;
return referrer;
}
}
if((referrer == null || referrer.length == 0)&&typeof localStorage !== 'undefined'){
referrer =localStorage.getItem('previousRoute');
}
return referrer;
}
parse(data:any){
}
parse(data: any) {
}
}