diff --git a/src/app/community/community.component.html b/src/app/community/community.component.html index ec63acd..6e1cd2b 100644 --- a/src/app/community/community.component.html +++ b/src/app/community/community.component.html @@ -8,14 +8,13 @@ + let-resultType="resultType" let-fetch="fetch" let-searchLinkToAdvancedPage="searchLinkToAdvancedPage" + let-params="params" let-type="type" let-typeName="typeName">
- - + +
-
-
-
+ + + + + +
@@ -256,69 +255,24 @@
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/app/community/community.component.ts b/src/app/community/community.component.ts index 2f4ae93..ca7515a 100644 --- a/src/app/community/community.component.ts +++ b/src/app/community/community.component.ts @@ -23,6 +23,8 @@ import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service"; import {UserManagementService} from "../openaireLibrary/services/user-management.service"; import {SubscribeComponent} from "../utils/subscribe/subscribe.component"; import {SearchCustomFilter} from "../openaireLibrary/searchPages/searchUtils/searchUtils.class"; +import {FetchResearchResults} from "../openaireLibrary/utils/fetchEntitiesClasses/fetchResearchResults.class"; +import {ErrorCodes} from "../openaireLibrary/utils/properties/errorCodes"; @Component({ selector: 'community', @@ -36,10 +38,10 @@ export class CommunityComponent { public piwiksub: any; public subfunders: any; - public publicationTotal = null; - public researchDataTotal = null; - public softwareTotal = null; - public orpTotal = null; + // public publicationTotal = null; + // public researchDataTotal = null; + // public softwareTotal = null; + // public orpTotal = null; public projectTotal = null; public contentProviderTotal = null; public organizationTotal = null; @@ -50,10 +52,25 @@ export class CommunityComponent { params: any = {}; properties: EnvProperties; - public publicationResults = null; - public researchDataResults = null; - public softwareResults = null; - public orpResults = null; + public errorCodes: ErrorCodes = new ErrorCodes(); + + // public publicationResults = null; + // public researchDataResults = null; + // public softwareResults = null; + // public orpResults = null; + + // Request results of each tab only the one time (first time tab is clicked) + private reloadPublications: boolean = true; + private reloadDatasets: boolean = true; + private reloadSoftware: boolean = true; + private reloadOrps: boolean = true; + + // Variables for publications, research data, projects, content providers, related content providers tabs + public fetchPublications: FetchResearchResults; + public fetchDatasets: FetchResearchResults; + public fetchSoftware: FetchResearchResults; + public fetchOrps: FetchResearchResults; + public searchNumber: number = 5; @Input() communityId = null; public community = null; @@ -124,6 +141,10 @@ export class CommunityComponent { this._meta.updateTag({content: title}, "property='og:title'"); this._title.setTitle(title); + this.fetchPublications = new FetchResearchResults(this._searchResearchResultsService); + this.fetchDatasets = new FetchResearchResults(this._searchResearchResultsService); + this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService); + this.fetchOrps = new FetchResearchResults(this._searchResearchResultsService); } public ngOnInit() { @@ -247,38 +268,107 @@ export class CommunityComponent { }); } - public countResearchResults(resultType: string) { - this._searchResearchResultsService.countTotalResults(resultType, this.properties, "&fq=communityid=" + this.communityId).subscribe( - researchResultsTotal => { - this.setTotal(resultType, researchResultsTotal); - if (resultType == "publication") { - //this.searchResearchResults(resultType, this.publicationTotal, this.publicationResults); - } - }, - error => { - this.handleError("Error getting number of " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error); - } - ); - } + private searchPublications(page: number, size: number) { + this.setActiveTab("publication"); - public searchResearchResults(resultType: string, resultsTotal: number, results: Array) { - this.setActiveTab(resultType); - - if (resultsTotal > 0 && results == null) { - this.showLoading = true; - - this._searchResearchResultsService.search(resultType, "", "&fq=communityid=" + this.communityId, 1, 5, "resultdateofacceptance,descending", [], this.properties).subscribe( - researchResults => { - this.setResults(resultType, researchResults[1]); - this.showLoading = false; - }, - error => { - this.handleError("Error getting " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error); - } - ); + if (this.reloadPublications && + (this.fetchPublications.searchUtils.status == this.errorCodes.LOADING || + (this.fetchPublications.searchUtils.status == this.errorCodes.DONE && this.fetchPublications.searchUtils.totalResults > 0) + ) + ) { + this.fetchPublications.getResultsForCommunity("publication", this.communityId, page, size, this.properties); } + this.reloadPublications = false; } + private searchDatasets(page: number, size: number) { + this.setActiveTab("dataset"); + + if (this.reloadDatasets && + (this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING || + (this.fetchDatasets.searchUtils.status == this.errorCodes.DONE && this.fetchDatasets.searchUtils.totalResults > 0) + ) + ) { + this.fetchDatasets.getResultsForCommunity("dataset", this.communityId, page, size, this.properties); + } + this.reloadDatasets = false; + } + + private searchSoftware(page: number, size: number) { + this.setActiveTab("software"); + + if (this.reloadSoftware && + (this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING || + (this.fetchSoftware.searchUtils.status == this.errorCodes.DONE && this.fetchSoftware.searchUtils.totalResults > 0) + ) + ) { + this.fetchSoftware.getResultsForCommunity("software", this.communityId, page, size, this.properties); + } + this.reloadSoftware = false; + } + + private searchOrps(page: number, size: number) { + this.setActiveTab("other"); + + if (this.reloadOrps && + (this.fetchOrps.searchUtils.status == this.errorCodes.LOADING || + (this.fetchOrps.searchUtils.status == this.errorCodes.DONE && this.fetchOrps.searchUtils.totalResults > 0) + ) + ) { + this.fetchOrps.getResultsForCommunity("other", this.communityId, page, size, this.properties); + } + this.reloadOrps = false; + } + + private countResearchResults(resultType: string) { + let fetch: FetchResearchResults; + + if (resultType == "publication") { + fetch = this.fetchPublications; + } else if (resultType == "dataset") { + fetch = this.fetchDatasets; + } else if (resultType == "software") { + fetch = this.fetchSoftware; + } else if (resultType == "other") { + fetch = this.fetchOrps; + } + + fetch.getNumForCommunity(resultType, this.communityId, this.properties); + } + + + // public countResearchResults(resultType: string) { + // this._searchResearchResultsService.countTotalResults(resultType, this.properties, "&fq=communityid=" + this.communityId).subscribe( + // researchResultsTotal => { + // this.setTotal(resultType, researchResultsTotal); + // if (resultType == "publication") { + // //this.searchResearchResults(resultType, this.publicationTotal, this.publicationResults); + // } + // }, + // error => { + // this.handleError("Error getting number of " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error); + // } + // ); + // } + // + // public searchResearchResults(resultType: string, resultsTotal: number, results: Array) { + // this.setActiveTab(resultType); + // + // if (resultsTotal > 0 && results == null) { + // this.showLoading = true; + // + // this._searchResearchResultsService.search(resultType, "", "&fq=communityid=" + this.communityId, 1, 5, "resultdateofacceptance,descending", [], this.properties).subscribe( + // researchResults => { + // this.setResults(resultType, researchResults[1]); + // this.showLoading = false; + // }, + // error => { + // this.handleError("Error getting " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error); + // } + // ); + // } + // } + public ngOnDestroy() { if (this.piwiksub) { this.piwiksub.unsubscribe(); @@ -354,27 +444,37 @@ export class CommunityComponent { } } - private setResults(entityType: string, results: Array) { - if (entityType == "publication") { - this.publicationResults = results; - } else if (entityType == "dataset") { - this.researchDataResults = results; - } else if (entityType == "software") { - this.softwareResults = results; - } else if (entityType == "other") { - this.orpResults = results; - } - } + // private setResults(entityType: string, results: Array) { + // if (entityType == "publication") { + // this.publicationResults = results; + // } else if (entityType == "dataset") { + // this.researchDataResults = results; + // } else if (entityType == "software") { + // this.softwareResults = results; + // } else if (entityType == "other") { + // this.orpResults = results; + // } + // } + // + // private setTotal(entityType: string, total: number) { + // if (entityType == "publication") { + // this.publicationTotal = total; + // console.log(this.publicationTotal); + // } else if (entityType == "dataset") { + // this.researchDataTotal = total; + // } else if (entityType == "software") { + // this.softwareTotal = total; + // } else if (entityType == "other") { + // this.orpTotal = total; + // } + // } - private setTotal(entityType: string, total: number) { - if (entityType == "publication") { - this.publicationTotal = total; - } else if (entityType == "dataset") { - this.researchDataTotal = total; - } else if (entityType == "software") { - this.softwareTotal = total; - } else if (entityType == "other") { - this.orpTotal = total; + + public getParamsForSearchLink(type: string = "") { + if(type) { + return this.routerHelper.createQueryParams(['type', 'qf', 'sortBy'], [type, 'false', 'resultdateofacceptance,descending']); + } else { + return {}; } } @@ -536,4 +636,28 @@ export class CommunityComponent { return true; } } + + public onSelectActiveTab(activeTabId) { + if(this.activeTab != "activaTabId") { // tab really changed + if (activeTabId == 'summary') { + this.activeTab = 'summary'; + } else if (activeTabId == 'publications') { + this.show = 'overview'; + this.searchPublications(1, this.searchNumber); + } else if (activeTabId == 'datasets') { + this.show = 'overview'; + this.searchDatasets(1, this.searchNumber); + } else if (activeTabId == 'software') { + this.show = 'overview'; + this.searchSoftware(1, this.searchNumber); + } else if (activeTabId == 'other') { + this.show='overview'; + this.searchOrps(1, this.searchNumber); + } else if (activeTabId == 'analytics') { + this.show = 'analysis'; + this.activeTab = 'analytics'; + this.analyticsChecked = true; + } + } + } } diff --git a/src/app/community/community.module.ts b/src/app/community/community.module.ts index b7e130f..c6ce168 100644 --- a/src/app/community/community.module.ts +++ b/src/app/community/community.module.ts @@ -3,7 +3,7 @@ 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 {SearchTabComponent} from '../openaireLibrary/utils/tabs/contents/search-tab.component'; import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service'; import {CommunityService} from '../openaireLibrary/connect/community/community.service'; @@ -28,6 +28,9 @@ import {Schema2jsonldModule} from "../openaireLibrary/sharedComponents/schema2js import {SEOServiceModule} from "../openaireLibrary/sharedComponents/SEO/SEOService.module"; import {MatSelectModule} from "@angular/material"; import {EntitiesSelectionModule} from "../openaireLibrary/searchPages/searchUtils/entitiesSelection.module"; +import {TabsModule} from "../openaireLibrary/utils/tabs/tabs.module"; +import {SearchTabModule} from "../openaireLibrary/utils/tabs/contents/search-tab.module"; +import {ErrorMessagesModule} from "../openaireLibrary/utils/errorMessages.module"; @NgModule({ imports: [ @@ -35,10 +38,11 @@ import {EntitiesSelectionModule} from "../openaireLibrary/searchPages/searchUtil SubscribeModule, StatisticsModule, ManageModule, InviteModule, SearchZenodoCommunitiesServiceModule, ZenodoCommunitiesServiceModule, SearchFormModule, SearchDataprovidersServiceModule, SearchProjectsServiceModule, SearchResearchResultsServiceModule, SearchResultsModule, CuratorsModule, AffiliationsModule, - Schema2jsonldModule, SEOServiceModule, MatSelectModule, EntitiesSelectionModule + Schema2jsonldModule, SEOServiceModule, MatSelectModule, EntitiesSelectionModule, + TabsModule, SearchTabModule, ErrorMessagesModule ], declarations: [ - CommunityComponent, ResultsComponent + CommunityComponent ], providers:[ FreeGuard, PreviousRouteRecorder,