Add search Researcher component, initiate researcher routings, add menu, add basic properties

This commit is contained in:
argirok 2023-10-24 15:29:36 +03:00
parent e709d8729f
commit 865c7757f6
8 changed files with 330 additions and 7 deletions

View File

@ -1,7 +1,12 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
const routes: Routes = [];
const routes: Routes = [
{
path: 'researcher',
loadChildren: () => import('./researcher/researcher-routing.module').then(m => m.ResearcherRoutingModule)
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],

View File

@ -1,6 +1,7 @@
import { Component } from '@angular/core';
import {properties} from "../environments/environment";
import {ActivatedRoute, Router} from "@angular/router";
import {MenuItem} from "./openaireLibrary/sharedComponents/menu";
@Component({
selector: 'app-root',
@ -11,7 +12,7 @@ import {ActivatedRoute, Router} from "@angular/router";
<div *ngIf="!loading">
<div>
<div id="modal-container"></div>
<navbar *ngIf="hasHeader" portal="irish_monitor"></navbar>
<navbar *ngIf="hasHeader" portal="irish_monitor" [menuItems]="menuItems" [showMenu]="true" [header]="header"></navbar>
<div>
<main>
<router-outlet></router-outlet>
@ -31,9 +32,33 @@ export class AppComponent {
loading: boolean = false;
isFrontPage: boolean = false;
view: boolean = false;
hasHeader: boolean = false;
hasHeader: boolean = true;
properties = properties;
header = {
route: "/",
title: "Noami",
logoUrl: "",
logoSmallUrl: null,
position: 'left',
badge: true
};
menuItems:MenuItem[] = [
new MenuItem("national", "National Monitor",
"", "/", false, [], null, {}
, null, null, null, null),
new MenuItem("rpo", "RPO Monitors",
"", "/", false, [], null, {}
, null, null, null, null),
new MenuItem("rfo", "RFO Monitors",
"", "/", false, [], null, {}
, null, null, null, null),
new MenuItem("researcher", "Researcher Monitors",
"", "/researcher", false, [], null, {}
, null, null, null, null),
new MenuItem("repository", "Repository Monitors",
"", "/", false, [], null, {}
, null, null, null, null)
];
constructor(private route: ActivatedRoute,
private router: Router,) {
}

View File

@ -0,0 +1,15 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{
path: '',
loadChildren: () => import('./search-researcher/search-researcher.module').then(m => m.SearchResearcherModule)
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class ResearcherRoutingModule { }

View File

@ -0,0 +1,16 @@
import {NgModule} from "@angular/core";
import {RouterModule} from "@angular/router";
import {SearchResearcherComponent} from "./search-researcher.component";
@NgModule({
imports: [
RouterModule.forChild([
{
path: '',
component: SearchResearcherComponent
}
])
]
})
export class SearchResearcherRoutingModule {
}

View File

@ -0,0 +1,64 @@
<div search-input [(value)]="keyword" [placeholder]="'Search for author or ORCID...'"
[searchInputClass]="'inner background'" (searchEmitter)="search()"></div>
<div class="uk-margin-top">
<div *ngIf="orcidStatus == errorCodes.ERROR" class="uk-alert uk-alert-warning" role="alert">An Error Occured</div>
<div *ngIf="orcidStatus == errorCodes.NOT_AVAILABLE" class="uk-alert uk-alert-danger"
role="alert">Service not available
</div>
Orcid found:{{authors.length}} <br>
check for results: {{authorsRendered}} <br>
Authors found (with OpenAIRE results):{{authorsToShow.length}} <br>
page: {{page}}<br>
<ng-container *ngFor=" let author of authorsToShow.slice(0,page*size>authorsToShow.length?authorsToShow.length:page*size)">
<div *ngIf="author.resultsCount > 0" class="uk-margin-top">{{author.authorGivenName}} {{author.authorFamilyName}} : {{author.id}} <br>
<div>Research outcomes:{{author.resultsCount}}</div>
</div>
</ng-container>
<button *ngIf="authorsToShow.length > page*size || authors.length > authorsRendered" class="uk-button uk-button-primary" (click)="loadMore()" >Load more</button>
<div *ngIf="orcidStatus == errorCodes.NONE "
class="uk-alert uk-alert-primary "> No results found
</div>
<!--<div *ngIf="orcidResultsNum >= 0" class="panel-body">
<span><span class="uk-text-bold">Showing results for</span>
<a target="_blank" href="http://orcid.org/{{authorId}}"> <span
class="custom-external"></span> {{authorGivenName}} {{authorFamilyName}} - {{authorId}} </a> :
</span>
<div *ngIf="authors.length > 1" class=""> In Orcid you can search only by Author. Not the
author you are looking for?
<div class="dropdown">
<mat-select [(ngModel)]="selectAuthorId" name="select_author"
(ngModelChange)="getOrcidResultsById(selectAuthorId)" class="matSelection"
[disableOptionCentering]="true"
panelClass="matSelectionPanel">
<mat-option value="0">Choose another one:</mat-option>
<mat-option *ngFor=" let item of authors let i = index"
[value]="authors[i].id">{{authors[i].authorGivenName}} {{authors[i].authorFamilyName}} : {{authors[i].id}} </mat-option>
</mat-select>
</div>
</div>
<div>
<div *ngIf="orcidResultsNum == 0" class="uk-alert uk-alert-primary uk-margin-top"> No results found</div>
</div>
<div *ngIf=" ((orcidResultsNum >0) && (totalPages > 1) && ( 0 < page && page <= totalPages )) "
class="uk uk-flex uk-flex-center">
&lt;!&ndash;
<paging-no-load [currentPage]="orcidPage" [totalResults]="orcidResultsNum"
[term]="keyword" [size]="size"
(pageChange)="orcidPageChange($event)"></paging-no-load>
&ndash;&gt;
</div>
</div>-->
<div *ngIf="orcidStatus == errorCodes.LOADING" class="uk-animation-fade uk-margin-top uk-width-1-1" role="alert">
<span class="loading-gif uk-align-center"></span></div>
</div>

View File

@ -0,0 +1,166 @@
import {Component, OnInit} from '@angular/core';
import {Identifier, StringUtils} from "../../openaireLibrary/utils/string-utils.class";
import {EnvProperties} from "../../openaireLibrary/utils/properties/env-properties";
import {ErrorCodes} from "../../openaireLibrary/utils/properties/errorCodes";
import {SearchOrcidService} from "../../openaireLibrary/claims/claim-utils/service/searchOrcid.service";
import {SearchResearchResultsService} from "../../openaireLibrary/services/searchResearchResults.service";
import {forkJoin, Subscriber} from "rxjs";
import {properties} from "../../../environments/environment";
import {map} from "rxjs/operators";
@Component({
selector: 'search-researcher',
templateUrl: './search-researcher.component.html',
})
export class SearchResearcherComponent implements OnInit {
page: number = 1;
size: number = 10;
public keyword: string = "";//"paolo manghi";//'0000-0001-7291-3210';
properties: EnvProperties = properties;
public errorCodes: ErrorCodes = new ErrorCodes();
public warningMessage = "";
public infoMessage = "";
orcidStatus: number = this.errorCodes.NONE;
authors = [];
authorsToShow = [];
authorsRendered = 0;
subscriptions = [];
constructor(private _searchOrcidService: SearchOrcidService,
private _searchResearchResultsService: SearchResearchResultsService) {
}
ngOnInit() {
if (this.keyword != null && this.keyword.length > 0) {
this.search();
}
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => {
if (subscription instanceof Subscriber) {
subscription.unsubscribe();
}
});
}
search() {
//uncomment to disable search with no keyword
if (this.keyword.length == 0) {
return;
}
this.warningMessage = "";
this.infoMessage = "";
this.orcidStatus = this.errorCodes.LOADING;
this.authors = [];
this.authorsToShow = [];
this.page = 1;
this.authorsRendered = 0;
if(Identifier.isValidORCID(this.keyword)){
this.getOrcidAuthor(this.keyword, true);
}else{
this.getOrcidAuthors(this.keyword)
}
}
private getOrcidAuthor(term: string, addId, count = -1) {
//passing structures in order to fill them in service
this.subscriptions.push(this._searchOrcidService.searchOrcidSingleAuthor(StringUtils.URIEncode(term.replace(/\s/g, "")), this.properties, addId).subscribe(
data => {
if (data != null) {
this.orcidStatus = this.errorCodes.LOADING;
if(count ==-1) {
this.getOpenaireResultsFor(0,1);
}else{
data.resultsCount = count;
this.authors.push(data);
this.authorsToShow.push(data);
}
}else{
this.orcidStatus = this.errorCodes.NONE;
}
},
err => this.errorHandler(err, term)
));
}
private errorHandler(err: any, term: string) {
if (err.status == 404) {
this.getOrcidAuthors(term);
} else {
this.orcidStatus = this.errorCodes.ERROR;
//console.log(err.status);
}
}
private getOrcidAuthors(term: string) {
this.orcidStatus = this.errorCodes.LOADING;
this.subscriptions.push(this._searchOrcidService.searchOrcidAuthorsNew(StringUtils.URIEncode(term), this.properties, 100).subscribe(
data => {
this.authors = data;
if (data != null) {
this.getOpenaireResultsFor(0,this.size);
this.authorsRendered = this.size;
if (this.authors.length == 0) {
this.orcidStatus = this.errorCodes.NONE;
}
} else {
this.orcidStatus = this.errorCodes.ERROR;
}
},
err => {
this.orcidStatus = this.errorCodes.ERROR;
//console.log(err.status);
}
));
}
private getOpenaireResultsFor(start, end){
let obs = [];
for (let i = start; i < (this.authors.length>end?end:this.authors.length); i++) {
obs.push(this.getOpenaireResultsObs(this.authors[i]));
}
if(obs.length > 0) {
this.subscriptions.push(forkJoin(obs).subscribe(data => {
for (let author of data) {
if (author["resultsCount"] > 0) {
this.authorsToShow.push(author);
}
}
this.authorsRendered = (this.authors.length > end ? end : this.authors.length)
if (this.authorsToShow.length < this.page * this.size) {
this.getOpenaireResultsFor(end, end + (this.size));
}
}));
}else{
if(this.authorsToShow.length == 0){
this.orcidStatus = this.errorCodes.NONE;
}
}
}
private getOpenaireResultsObs(author){
let param = '(authorid="' + StringUtils.URIEncode(author.id) + '")';
// +' and (country exact "IE")';
return this._searchResearchResultsService.numOfResearchOutcomes(param, properties, null).pipe(map(res => {
author.resultsCount = res;
return author;
}));
}
loadMore(){
let page = this.page + 1;
if(page*this.size>this.authorsToShow.length) {
if (this.authorsRendered < this.authors.length) {
this.getOpenaireResultsFor(this.authorsRendered, this.authorsRendered + this.size*2);
}
}
this.page = page;
}
}

View File

@ -0,0 +1,20 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {SearchResearcherComponent} from "./search-researcher.component";
import {SearchResearcherRoutingModule} from "./search-researcher-routing.module";
import {SearchInputModule} from "../../openaireLibrary/sharedComponents/search-input/search-input.module";
import {MatSelectModule} from "@angular/material/select";
import {SearchOrcidServiceModule} from "../../openaireLibrary/claims/claim-utils/service/searchOrcidService.module";
import {SearchResearchResultsServiceModule} from "../../openaireLibrary/services/searchResearchResultsService.module";
import {PagingModule} from "../../openaireLibrary/utils/paging.module";
@NgModule({
declarations: [SearchResearcherComponent],
imports: [
CommonModule, SearchResearcherRoutingModule, SearchInputModule, MatSelectModule, SearchOrcidServiceModule, SearchResearchResultsServiceModule, PagingModule
]
})
export class SearchResearcherModule { }

View File

@ -3,8 +3,20 @@
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
import {EnvProperties} from "../app/openaireLibrary/utils/properties/env-properties";
import {EnvProperties} from "../app/openaireLibrary/utils/properties/env-properties";
import {common, commonDev} from "../app/openaireLibrary/utils/properties/environments/environment";
let props: EnvProperties = {
environment: "development",
searchAPIURLLAst: "http://beta.services.openaire.eu/search/v2/api/",
searchResourcesAPIURL: "https://beta.services.openaire.eu/search/v2/api/resources",
searchOrcidURL: "https://pub.orcid.org/v3.0/",
piwikSiteId: "407",
enablePiwikTrack:false,
piwikBaseUrl: 'https://beta.analytics.openaire.eu/piwik.php?idsite='
}
export let properties: EnvProperties = {
environment: "development"
};
...props, ...common, ...commonDev
}