[Library | develop]: resultLanding.component.ts: Added ContextsService and call to get public communities, and then filter out contexts (related to communities) of resultLandingInfo if they are hidden.

This commit is contained in:
Konstantina Galouni 2023-07-28 16:04:14 +03:00
parent 4e3df67f7e
commit a53c4e90d0
1 changed files with 50 additions and 16 deletions

View File

@ -28,6 +28,7 @@ import {NumberUtils} from '../../utils/number-utils.class';
import {FullScreenModalComponent} from "../../utils/modal/full-screen-modal/full-screen-modal.component";
import {SdgFosSuggestComponent} from '../landing-utils/sdg-fos-suggest/sdg-fos-suggest.component';
import {LayoutService} from "../../dashboard/sharedComponents/sidebar/layout.service";
import {ContextsService} from "../../claims/claim-utils/service/contexts.service";
declare var ResizeObserver;
@ -174,6 +175,8 @@ export class ResultLandingComponent {
@ViewChild('fosFsModal') fosFsModal: FullScreenModalComponent;
public noCommunities: boolean = false;
private promise: Promise<void> = null;
private publicCommunities: string[] = [];
public rightSidebarOffcanvasClicked: boolean = false;
public egiTransferModalOpen = false;
@ -192,7 +195,8 @@ export class ResultLandingComponent {
private _location: Location,
private indexInfoService: IndexInfoService,
private userManagementService: UserManagementService,
private layoutService: LayoutService) {
private layoutService: LayoutService,
private _contextService: ContextsService) {
}
ngOnInit() {
@ -256,6 +260,7 @@ export class ResultLandingComponent {
this.type="publication";
}
if ((this.id && StringUtils.isOpenAIREID(this.id)) || (this.identifier)) {
this.getPublicCommunities();
this.getVocabulariesAndResultLandingInfo();
} else {
this.showLoading = false;
@ -496,29 +501,32 @@ export class ResultLandingComponent {
this.resultLandingInfo = null;
this.hasAltMetrics = false;
this.subscriptions.push(this._resultLandingService.getResultLandingInfo(this.id, this.identifier, this.type, subjectsVocabulary, this.properties).subscribe(
data => {
async data => {
let contexts = data.contexts;
data.contexts = [];
this.resultLandingInfo = data;
this.id = this.resultLandingInfo.objIdentifier;
//old
// this.viewsFrameUrl = this.properties.framesAPIURL + 'merge.php?com=query&data=[{"query":"resRepoViews", "resTitle":"' + this.id + '", "table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":" ","color":"","type":"chart","size":200,"sort":"xaxis","xStyle":{"r":-30,"s":"6","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"Repository","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false';
// this.downloadsFrameUrl = this.properties.framesAPIURL + 'merge.php?com=query&data=[{"query":"resRepoDownloads", "resTitle":"' + this.id + '", "table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":" ","color":"","type":"chart","size":200,"sort":"xaxis","xStyle":{"r":-30,"s":"6","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"Repository","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false';
//new
this.viewsFrameUrl = this.properties.statisticsFrameNewAPIURL + 'chart?json=' + encodeURIComponent('{"library":"HighCharts","chartDescription":{"queries":[{"name":"Monthly views","type":"column","query":{"name":"usagestats.results.views.monthly", "parameters":["' + this.id + '"], "profile":"OpenAIRE All-inclusive" }}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"Monthly views"},"subtitle":{},"yAxis":{"title":{"text":""}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":false},"credits":{"href":null,"enabled":true,"text":""}}}');
this.downloadsFrameUrl = this.properties.statisticsFrameNewAPIURL + 'chart?json=' +
this.viewsFrameUrl = this.properties.statisticsFrameNewAPIURL + 'chart?json=' + encodeURIComponent('{"library":"HighCharts","chartDescription":{"queries":[{"name":"Monthly views","type":"column","query":{"name":"usagestats.results.views.monthly", "parameters":["' + this.id + '"], "profile":"OpenAIRE All-inclusive" }}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"Monthly views"},"subtitle":{},"yAxis":{"title":{"text":""}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":false},"credits":{"href":null,"enabled":true,"text":""}}}');
this.downloadsFrameUrl = this.properties.statisticsFrameNewAPIURL + 'chart?json=' +
encodeURIComponent('{"library":"HighCharts","chartDescription":{"queries":[{"name":"Monthly downloads","type":"column","query":{"name":"usagestats.results.downloads.monthly", "parameters":["' + this.id + '"], "profile":"OpenAIRE All-inclusive" }}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"Monthly downloads"},"subtitle":{},"yAxis":{"title":{"text":""}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":false},"credits":{"href":null,"enabled":true,"text":""}}}');
this.bipFrameUrl = this.properties.bipFrameAPIURL + this.id + (properties.environment == "beta" ? "&src=beta" : "");
let pid:Identifier = Identifier.getPIDFromIdentifiers(this.resultLandingInfo.identifiers);
this.bipFrameUrl = this.properties.bipFrameAPIURL + this.id + (properties.environment == "beta" ? "&src=beta" : "");
let pid: Identifier = Identifier.getPIDFromIdentifiers(this.resultLandingInfo.identifiers);
if (this.type == "result") { // no type was specified - update URL based this.resultLandingInfo.resultType
this.updateUrlWithType(pid);
}
this.canonicalUrl = this.properties.domain+ properties.baseLink + ( pid ? (this.linkToLandingPage.split("?")[0] + "?pid=" + encodeURIComponent(pid.id)):
this.canonicalUrl = this.properties.domain + properties.baseLink + (pid ? (this.linkToLandingPage.split("?")[0] + "?pid=" + encodeURIComponent(pid.id)) :
(this.linkToLandingPage + this.resultLandingInfo.relcanId));
this.seoService.createLinkForCanonicalURL(this.canonicalUrl);
this.updateUrl(this.canonicalUrl);
this.addNoIndexFilter();
if (this.resultLandingInfo.title) {
this.updateTitle(this.resultLandingInfo.title);
this.updateDescription((this.resultLandingInfo.description ? (this.resultLandingInfo.description.substr(0,157) + (this.resultLandingInfo.description.substr(0,157).length == 157?"...":"")) : (this.resultLandingInfo.title)));
this.updateDescription((this.resultLandingInfo.description ? (this.resultLandingInfo.description.substr(0, 157) + (this.resultLandingInfo.description.substr(0, 157).length == 157 ? "..." : "")) : (this.resultLandingInfo.title)));
}
this.subscriptions.push(this._piwikService.trackViewForCustomUrl(this.properties, this.resultLandingInfo.title, this.linkToLandingPage.split("?")[1] + this.id).subscribe());
let bioentitiesNum = 0;
@ -529,9 +537,9 @@ export class ResultLandingComponent {
}
this.bioentitiesNum = bioentitiesNum;
if (typeof document !== 'undefined') {
if(this.resultLandingInfo.identifiers) {
if (this.resultLandingInfo.identifiers) {
let pidsArray: string[] = [];
for(let key of Array.from(this.resultLandingInfo.identifiers.keys())) {
for (let key of Array.from(this.resultLandingInfo.identifiers.keys())) {
pidsArray = pidsArray.concat(this.resultLandingInfo.identifiers.get(key));
this.pidsArrayString = pidsArray.join();
}
@ -545,14 +553,17 @@ export class ResultLandingComponent {
}
}
}
if(this.communityId && this.communityId == "enermaps" && properties.enermapsURL){
if (this.communityId && this.communityId == "enermaps" && properties.enermapsURL) {
this.enermapsId = ParsingFunctions.getEnermapsConceptId(this.resultLandingInfo.contexts);
}
this.relatedClassFilters = [{"label": "All relations", "value": ""}];
if(this.resultLandingInfo.relatedClassFilters.size > 1) {
if (this.resultLandingInfo.relatedClassFilters.size > 1) {
for (let relClass of this.resultLandingInfo.relatedClassFilters) {
this.relatedClassFilters.push({"label": HelperFunctions.getVocabularyLabel(relClass, this.relationsVocabulary), "value": relClass});
this.relatedClassFilters.push({
"label": HelperFunctions.getVocabularyLabel(relClass, this.relationsVocabulary),
"value": relClass
});
}
} else {
this.relatedClassFilters.pop();
@ -562,12 +573,12 @@ export class ResultLandingComponent {
this.hasViews = false;
this.hasDownloads = false;
if(this.resultLandingInfo.measure && this.resultLandingInfo.measure.counts) {
if (this.resultLandingInfo.measure && this.resultLandingInfo.measure.counts) {
this.resultLandingInfo.measure.counts.forEach(measure => {
if(measure.name == "views" && measure.value > 0) {
if (measure.name == "views" && measure.value > 0) {
this.hasViews = true;
}
if(measure.name == "downloads" && measure.value > 0) {
if (measure.name == "downloads" && measure.value > 0) {
this.hasDownloads = true;
}
})
@ -577,6 +588,14 @@ export class ResultLandingComponent {
this.setActiveTab();
this.cdr.detectChanges();
if (contexts) {
await this.promise;
if(this.publicCommunities && this.publicCommunities.length > 0) {
this.resultLandingInfo.contexts = contexts.filter(context => this.publicCommunities.includes(context.idContext));
this.cdr.detectChanges();
}
}
},
err => {
this.handleError("Error getting " + this.type + " for " + (this.id ? ("id: " + this.id) : ("pid: " + this.identifier.id + " ("+this.identifier.class+")")), err);
@ -593,6 +612,21 @@ export class ResultLandingComponent {
));
}
public getPublicCommunities() {
this.promise = new Promise<void>(resolve => {
this._contextService.getPublicCommunitiesByState().subscribe(
data => {
this.publicCommunities = data.map(value => value.id);
// this.publicCommunities = data;
resolve();
},
error => {
this.handleError("Error getting communities status", error);
resolve();
});
});
}
public metricsResults($event) {
this.totalViews = $event.totalViews;
this.totalDownloads = $event.totalDownloads;