From 4288d49e36dbe4e35cf72d08e28730dc35e2e8aa Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Wed, 5 Jun 2019 13:39:02 +0000 Subject: [PATCH] [Connect|Trunk] pass properties as parameter in services in order to use cache add properties parameter in navbar/bottom and clean up other attributes Community page: use existing services and remove searchEntries.service.ts use search results component git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@55996 d315682c-612b-4755-9ff5-7f18f6832af3 --- src/app/app.component.ts | 23 +++-- src/app/communities/communities.component.ts | 26 +++-- src/app/community/community.component.html | 14 ++- src/app/community/community.component.ts | 45 +++++---- src/app/community/community.module.ts | 24 +++-- .../results/results.component.ts | 76 +++++++------- .../searchEntries/searchEntries.service.ts | 98 ------------------- .../searchCommunities.component.ts | 2 +- src/app/statistics/statistics.component.ts | 6 +- src/app/utils/services/statistics.service.ts | 13 +-- .../utils/subscribe/subscribe.component.ts | 11 +-- src/assets/env-properties.json | 2 +- 12 files changed, 123 insertions(+), 217 deletions(-) delete mode 100644 src/app/searchEntries/searchEntries.service.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 8e1f3ca..d142987 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,10 +1,9 @@ -import { Component, Directive, ElementRef, Renderer, ChangeDetectionStrategy, ViewEncapsulation, Injector } from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Component} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; -import { EnvProperties} from './openaireLibrary/utils/properties/env-properties'; -import{MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu'; -import { EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service'; +import {EnvProperties} from './openaireLibrary/utils/properties/env-properties'; +import {MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu'; +import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service'; import {CommunitiesService} from "./openaireLibrary/connect/communities/communities.service"; import {Session} from './openaireLibrary/login/utils/helper.class'; import {ConnectHelper} from './openaireLibrary/connect/connectHelper'; @@ -20,10 +19,10 @@ import {SubscribeService} from './openaireLibrary/utils/subscribe/subscribe.serv `], template: ` - - + +
@@ -38,8 +37,8 @@ import {SubscribeService} from './openaireLibrary/utils/subscribe/subscribe.serv - - + + ` @@ -323,7 +322,7 @@ export class AppComponent { myCommunities.push( new MenuItem("","Managing communities","","/search/find/communities",false,[],[],{role:"%22manager%22"})) } if(Session.isLoggedIn()){ - this._subscribeService.getCommunitiesSubscribedTo(Session.getUserEmail(), this.properties.adminToolsAPIURL).subscribe ( + this._subscribeService.getCommunitiesSubscribedTo(this.properties, Session.getUserEmail()).subscribe ( pids => { if(pids.length > 0 ) { myCommunities.push( new MenuItem("","Subscribed to communities","","/search/find/communities",false,[],[],{status:"%22subscribed%22"})) diff --git a/src/app/communities/communities.component.ts b/src/app/communities/communities.component.ts index fc3c71c..250a7b9 100644 --- a/src/app/communities/communities.component.ts +++ b/src/app/communities/communities.component.ts @@ -1,19 +1,17 @@ import {Component} from '@angular/core'; -import {ActivatedRoute, Router} from '@angular/router'; -import {Title, Meta} from '@angular/platform-browser'; +import {ActivatedRoute, Router} from '@angular/router'; +import {Meta, Title} from '@angular/platform-browser'; +import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties'; +import {CommunitiesService} from '../openaireLibrary/connect/communities/communities.service'; +import {SubscribeService} from '../openaireLibrary/utils/subscribe/subscribe.service'; +import {CommunityInfo} from '../openaireLibrary/connect/community/communityInfo'; -import "rxjs/add/observable/zip"; -import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties'; -import {CommunitiesService} from '../openaireLibrary/connect/communities/communities.service'; -import {SubscribeService} from '../openaireLibrary/utils/subscribe/subscribe.service'; -import {CommunityInfo} from '../openaireLibrary/connect/community/communityInfo'; +import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service'; +import {Session} from '../openaireLibrary/login/utils/helper.class'; +import {StringUtils} from '../openaireLibrary/utils/string-utils.class'; -import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service'; -import {Session} from '../openaireLibrary/login/utils/helper.class'; -import {StringUtils} from '../openaireLibrary/utils/string-utils.class'; - -import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes'; -import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component'; +import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes'; +import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component'; @Component({ selector: 'communities', @@ -129,7 +127,7 @@ export class CommunitiesComponent { this.status = this.errorCodes.DONE; if(mail != null && showCommunity) { - this._subscribeService.isSubscribedToCommunity(community.communityId, mail, this.properties.adminToolsAPIURL).subscribe ( + this._subscribeService.isSubscribedToCommunity( this.properties, community.communityId, mail).subscribe ( res => { isSubscriber = res; if(isSubscriber) { diff --git a/src/app/community/community.component.html b/src/app/community/community.component.html index ea3b69a..aad6849 100644 --- a/src/app/community/community.component.html +++ b/src/app/community/community.component.html @@ -178,7 +178,9 @@
  • - +
    - +
    @@ -207,7 +210,8 @@
  • - +
    @@ -221,7 +225,9 @@
  • - +
    { this.publicationTotal = publicationTotal; this.showLoading = true; @@ -154,7 +155,7 @@ export class CommunityComponent { } ); - this._searchEntriesService.getTotal(this.properties.searchAPIURLLAst + 'datasets/count?format=json&fq=communityid=' + this.communityId).subscribe( + this._searchResearchResultsService.countTotalResults("dataset", this.properties,"&fq=communityid=" + this.communityId).subscribe( researchDataTotal => { this.researchDataTotal = researchDataTotal; }, @@ -163,7 +164,7 @@ export class CommunityComponent { } ); - this._searchEntriesService.getTotal(this.properties.searchAPIURLLAst + 'software/count?format=json&fq=communityid=' + this.communityId).subscribe( + this._searchResearchResultsService.countTotalResults("software", this.properties,"&fq=communityid=" + this.communityId).subscribe( softwareTotal => { this.softwareTotal = softwareTotal; }, @@ -172,7 +173,7 @@ export class CommunityComponent { } ); - this._searchEntriesService.getTotal(this.properties.searchAPIURLLAst + 'other/count?format=json&fq=communityid=' + this.communityId).subscribe( + this._searchResearchResultsService.countTotalResults("other", this.properties,"&fq=communityid=" + this.communityId).subscribe( orpTotal => { this.orpTotal = orpTotal; }, @@ -181,7 +182,7 @@ export class CommunityComponent { } ); - this._searchEntriesService.countTotal(this.properties.communityAPI + this.communityId + '/projects').subscribe( + this._searchCommunityProjectsService.countTotalProjects(this.properties, this.communityId ).subscribe( projectTotal => { this.projectTotal = projectTotal; //console.log(projectTotal); @@ -191,7 +192,7 @@ export class CommunityComponent { } ); - this._searchEntriesService.countTotal(this.properties.communityAPI + this.communityId + '/contentproviders').subscribe( + this._searchCommunityDataprovidersService.countTotalDataproviders(this.properties, this.communityId ).subscribe( contentProviderTotal => { this.contentProviderTotal = contentProviderTotal; //console.log(contentProviderTotal); @@ -209,7 +210,7 @@ export class CommunityComponent { /**/ - this.config.getCommunityInformation(this.properties.adminToolsAPIURL, this.communityId).subscribe( + this.config.getCommunityInformation(this.properties, this.communityId).subscribe( res => { this.communityInfo = res; }, @@ -225,12 +226,14 @@ export class CommunityComponent { public searchPublications() { this.activeTab = "publication"; if (this.publicationTotal > 0 && this.publicationResults == null) { - this._searchEntriesService.getResults(this.properties.searchAPIURLLAst + 'publications?fq=communityid%20exact%20%22' + this.communityId + '%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe( + //this._searchEntriesService.getResults(this.properties.searchAPIURLLAst + 'publications?fq=communityid%20exact%20%22' + this.communityId + '%22&sortBy=resultdateofacceptance,descending&format=json&size=5') + this._searchResearchResultsService.search("publication","","&fq=communityid=" + this.communityId,1,5,"resultdateofacceptance,descending",[],this.properties) + .subscribe( publicationResults => { - this.publicationResults = publicationResults; + this.publicationResults = publicationResults[1]; this.showLoading = false; //console.log(publicationResults); - }, + }, error => { this.handleError("Error getting publications for community with id: " + this.communityId, error); } @@ -241,9 +244,9 @@ export class CommunityComponent { public searchResearchData() { this.activeTab = "dataset"; if (this.researchDataTotal > 0 && this.researchDataResults == null) { - this._searchEntriesService.getResults(this.properties.searchAPIURLLAst + 'datasets?fq=communityid%20exact%20%22' + this.communityId + '%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe( + this._searchResearchResultsService.search("dataset","","&fq=communityid=" + this.communityId,1,5,"resultdateofacceptance,descending",[],this.properties).subscribe( researchDataResults => { - this.researchDataResults = researchDataResults; + this.researchDataResults = researchDataResults[1]; this.showLoading = false; }, error => { @@ -256,9 +259,9 @@ export class CommunityComponent { public searchSoftware() { this.activeTab = "software"; if (this.softwareTotal > 0 && this.softwareResults == null) { - this._searchEntriesService.getResults(this.properties.searchAPIURLLAst + 'software?fq=communityid%20exact%20%22' + this.communityId + '%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe( + this._searchResearchResultsService.search("software","","&fq=communityid=" + this.communityId,1,5,"resultdateofacceptance,descending",[],this.properties).subscribe( softwareResults => { - this.softwareResults = softwareResults; + this.softwareResults = softwareResults[1]; this.showLoading = false; }, error => { @@ -271,9 +274,9 @@ export class CommunityComponent { public searchOrps() { this.activeTab = "orp"; if (this.orpTotal > 0 && this.orpResults == null) { - this._searchEntriesService.getResults(this.properties.searchAPIURLLAst + 'other?fq=communityid%20exact%20%22' + this.communityId + '%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe( + this._searchResearchResultsService.search("other","","&fq=communityid=" + this.communityId,1,5,"resultdateofacceptance,descending",[],this.properties).subscribe( orpResults => { - this.orpResults = orpResults; + this.orpResults = orpResults[1]; this.showLoading = false; }, error => { diff --git a/src/app/community/community.module.ts b/src/app/community/community.module.ts index dbd7303..eed6979 100644 --- a/src/app/community/community.module.ts +++ b/src/app/community/community.module.ts @@ -1,13 +1,11 @@ -import { NgModule} from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { FormsModule } from '@angular/forms'; -import { RouterModule } from '@angular/router'; -import{CommunityComponent} from './community.component'; +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {FormsModule} from '@angular/forms'; +import {RouterModule} from '@angular/router'; +import {CommunityComponent} from './community.component'; import {ResultsComponent} from '../searchEntries/results/results.component'; import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service'; -import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service'; -import {SearchEntriesService} from '../searchEntries/searchEntries.service'; import {CommunityService} from '../openaireLibrary/connect/community/community.service'; import {FreeGuard} from '../openaireLibrary/login/freeGuard.guard'; @@ -19,20 +17,26 @@ import {ManageModule} from '../openaireLibrary/utils/manage/manage.module'; import {StatisticsModule} from "../statistics/statistics.module"; import {SearchZenodoCommunitiesServiceModule} from '../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunitiesService.module'; import {ZenodoCommunitiesServiceModule} from '../openaireLibrary/connect/zenodoCommunities/zenodo-communitiesService.module'; -import {SearchFormModule} from '../openaireLibrary/searchPages/searchUtils/searchForm.module'; +import {SearchFormModule} from '../openaireLibrary/searchPages/searchUtils/searchForm.module'; +import {SearchDataprovidersServiceModule} from "../openaireLibrary/connect/contentProviders/searchDataprovidersService.module"; +import {SearchProjectsServiceModule} from '../openaireLibrary/connect/projects/searchProjectsService.module'; +import {SearchResearchResultsServiceModule} from "../openaireLibrary/services/searchResearchResultsService.module"; +import {SearchResultsModule} from "../openaireLibrary/searchPages/searchUtils/searchResults.module"; @NgModule({ imports: [ CommonModule, FormsModule, RouterModule, SubscribeModule, StatisticsModule, ManageModule, InviteModule, - SearchZenodoCommunitiesServiceModule, ZenodoCommunitiesServiceModule, SearchFormModule + SearchZenodoCommunitiesServiceModule, ZenodoCommunitiesServiceModule, SearchFormModule, SearchDataprovidersServiceModule, SearchProjectsServiceModule, + SearchResearchResultsServiceModule, SearchResultsModule + ], declarations: [ CommunityComponent, ResultsComponent ], providers:[ FreeGuard, PreviousRouteRecorder, - PiwikService, CommunityService, SearchEntriesService + PiwikService, CommunityService ], exports: [ CommunityComponent diff --git a/src/app/searchEntries/results/results.component.ts b/src/app/searchEntries/results/results.component.ts index 5705fe5..d542c2e 100644 --- a/src/app/searchEntries/results/results.component.ts +++ b/src/app/searchEntries/results/results.component.ts @@ -1,6 +1,7 @@ import {Component, Input} from '@angular/core'; -import { ResultInfo } from '../../openaireLibrary/connect/results/resultInfo'; -import { CommunityInfo } from '../../openaireLibrary/connect/community/communityInfo'; +import {CommunityInfo} from '../../openaireLibrary/connect/community/communityInfo'; +import {EnvProperties} from "../../openaireLibrary/utils/properties/env-properties"; +import {SearchResult} from "../../openaireLibrary/utils/entities/searchResult"; @Component({ selector: 'results-comp', @@ -10,54 +11,24 @@ import { CommunityInfo } from '../../openaireLibrary/connect/community/community
    -
    -
    +
    + + +
    No results available
    @@ -86,9 +60,29 @@ import { CommunityInfo } from '../../openaireLibrary/connect/community/community export class ResultsComponent { - @Input() public results : ResultInfo[]; + @Input() public results : SearchResult[]; @Input() public resultType: string; @Input() public params: any; @Input() public community: CommunityInfo; @Input() public total: any; + @Input() showLoading: boolean = true; + @Input() properties: EnvProperties; + + getresultTypeLink(type:string, plural:boolean){ + if((type == "publication" || type == "dataset") && plural){ + return type + "s"; + } + return type; + } + /* getParamId(type:string){ + let param =""; + if(type == "publication"){ + param="article"; + }else if(type == "other"){ + param="other"; + }else{ + param=type; + } + return param+"Id"; + }*/ } diff --git a/src/app/searchEntries/searchEntries.service.ts b/src/app/searchEntries/searchEntries.service.ts deleted file mode 100644 index 1889703..0000000 --- a/src/app/searchEntries/searchEntries.service.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { Injectable } from '@angular/core'; -import {HttpClient} from "@angular/common/http"; -import { Observable } from 'rxjs/Rx'; - -import { ResultInfo } from '../openaireLibrary/connect/results/resultInfo'; -import { CommunityInfo } from '../openaireLibrary/connect/community/communityInfo'; -import {map} from "rxjs/operators"; - -@Injectable() -export class SearchEntriesService { - - private sizeOfDescription: number = 135; - - constructor(private http:HttpClient) { - } - - getTotal(url: string) { - return this.http.get(url) - //.map(res => res.json()) - .pipe(map(res => res['total'])); - //.do(res => {console.log(res)}); - } - - countTotal(url:string) { - return this.http.get(url) - //.map(res => res.json()) - .pipe(map(res => res['length'])); - } - - getResults(url: string) { - return this.http.get(url) - //.map(res => res.json()) - .pipe(map(res => this.parseResults(res['results']))); - } - - parseResults(data: any): ResultInfo[] { - let results: ResultInfo[] = []; - - let length = Array.isArray(data) ? data.length :1; - - for (let i=0; i(); - } - - let authors = resData['creator']; - let length = Array.isArray(authors) ? authors.length : 1; - - for(let i=0; i this.sizeOfDescription) { - result.description = result.description.substring(0, this.sizeOfDescription) + "..."; - } - - results.push(result); - } - return results; - } -} diff --git a/src/app/searchPages/communities/searchCommunities.component.ts b/src/app/searchPages/communities/searchCommunities.component.ts index 17251a1..7b10d78 100644 --- a/src/app/searchPages/communities/searchCommunities.component.ts +++ b/src/app/searchPages/communities/searchCommunities.component.ts @@ -113,7 +113,7 @@ export class SearchCommunitiesComponent { } } if(Session.isLoggedIn()) { - this._subscribeService.getCommunitiesSubscribedTo(Session.getUserEmail(), this.properties["adminToolsAPIURL"]).subscribe( + this._subscribeService.getCommunitiesSubscribedTo(this.properties, Session.getUserEmail()).subscribe( res => { for (let i = 0; i < this.totalResults.length; i++) { this.totalResults[i].isSubscribed = (res.indexOf(this.totalResults[i].communityId) != -1); diff --git a/src/app/statistics/statistics.component.ts b/src/app/statistics/statistics.component.ts index 0045f28..726a518 100644 --- a/src/app/statistics/statistics.component.ts +++ b/src/app/statistics/statistics.component.ts @@ -115,7 +115,7 @@ export class StatisticsComponent { createStatisticsObjects() { // console.log(" Stats! "+ this.properties.statisticsAPIURL); this.status = this.errorCodes.LOADING; - this._statisticsService.getCommunityStatistics(this.properties.statisticsAPIURL,this.communityId).subscribe ( + this._statisticsService.getCommunityStatistics(this.properties,this.communityId).subscribe ( res => { this.statisticsSum = res; if(res["other"]){ //hack because in stats API the entity name is "other" while in admin API is "orp". This component uses also "orp" name @@ -131,7 +131,7 @@ export class StatisticsComponent { } getDisplayOptions() { - this._statisticsService.getCommunityAdminStatisticsChoices(this.properties.adminToolsAPIURL,this.communityId) + this._statisticsService.getCommunityAdminStatisticsChoices(this.properties,this.communityId) .subscribe( res => { this.statisticsDisplay = res; @@ -151,7 +151,7 @@ export class StatisticsComponent { getCommunityInfo() { // console.log(`calling ${this.properties.adminToolsAPIURL}/communityFull/${this.communityId}`); - this._configService.getCommunityInformation(this.properties.adminToolsAPIURL, this.communityId).subscribe( + this._configService.getCommunityInformation(this.properties, this.communityId).subscribe( res => { this.communityInfo = res; /*for(let i=0; i { - let url = `${apiUrl}communities/${communityId}`; + getCommunityStatistics(properties:EnvProperties, communityId: string): Observable { + let url = properties.statisticsAPIURL+"/communities/"+communityId; //console.log(`getting statistics summary from: ${url}`); - return this.http.get(url) + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) //.map(res => res.json()) .pipe(map(res => res['statistics'])); } - getCommunityAdminStatisticsChoices(apiUrl: string, communityId: string): Observable { - let url = `${apiUrl}/statistics/${communityId}`; + getCommunityAdminStatisticsChoices(properties: EnvProperties, communityId: string): Observable { + let url = properties.adminToolsAPIURL+"/statistics/"+communityId; //console.log(`getting admin choices for statistics from: ${url}`); - return this.http.get(url) + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) //.map(stats => stats.json()) .pipe(catchError(this.handleError)); } diff --git a/src/app/utils/subscribe/subscribe.component.ts b/src/app/utils/subscribe/subscribe.component.ts index 61e57b6..e612002 100644 --- a/src/app/utils/subscribe/subscribe.component.ts +++ b/src/app/utils/subscribe/subscribe.component.ts @@ -1,7 +1,6 @@ -import { Component, Input, Output, ViewChild, EventEmitter } from '@angular/core'; -import { Location } from '@angular/common'; +import {Component, EventEmitter, Input, Output, ViewChild} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; -import { EnvProperties} from '../../openaireLibrary/utils/properties/env-properties'; +import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties'; import {AlertModal} from '../../openaireLibrary/utils/modal/alert'; import {CommunityService} from '../../openaireLibrary/connect/community/community.service'; @@ -64,12 +63,12 @@ export class SubscribeComponent { .subscribe((data: { envSpecific: EnvProperties }) => { this.properties = data.envSpecific; if(!this.showNumbers){ - var email = Session.getUserEmail(); + let email = Session.getUserEmail(); if(email == null){ this.subscribed = false; }else{ if(this.communityId){ - this._subscribeService.isSubscribedToCommunity(this.communityId, email,this.properties.adminToolsAPIURL).subscribe ( + this._subscribeService.isSubscribedToCommunity(this.properties, this.communityId, email).subscribe ( res => { this.subscribed = res; }, @@ -80,7 +79,7 @@ export class SubscribeComponent { } }else{ if(this.communityId){ - this._subscribeService.getCommunitySubscribers(this.communityId, this.properties.adminToolsAPIURL).subscribe ( + this._subscribeService.getCommunitySubscribers(this.properties, this.communityId).subscribe ( res => { this.subscribers = (res && res.subscribers && res.subscribers.length )?res.subscribers.length:0; }, diff --git a/src/assets/env-properties.json b/src/assets/env-properties.json index 38d6e63..2659b0e 100644 --- a/src/assets/env-properties.json +++ b/src/assets/env-properties.json @@ -2,7 +2,7 @@ "environment" : "development", "enablePiwikTrack" : false, "enableHelper" : true, - "useCache" : false, + "useCache" : true, "showContent" : true, "metricsAPIURL" : "https://beta.services.openaire.eu/usagestats/", "framesAPIURL" : "https://beta.openaire.eu/stats3/",