2020-04-06 16:49:38 +02:00
|
|
|
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
2020-02-07 14:05:07 +01:00
|
|
|
import {SearchResult} from '../../utils/entities/searchResult';
|
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
2020-03-12 14:49:10 +01:00
|
|
|
import {ResultPreview} from "../../utils/result-preview/result-preview";
|
2021-01-13 19:30:25 +01:00
|
|
|
import {OrcidService} from "../../orcid/orcid.service";
|
|
|
|
import {Session} from "../../login/utils/helper.class";
|
2021-02-24 21:33:37 +01:00
|
|
|
import {properties} from "../../../../environments/environment";
|
2023-02-16 15:33:40 +01:00
|
|
|
import {LayoutService} from "../../dashboard/sharedComponents/sidebar/layout.service";
|
|
|
|
import {Subscription} from "rxjs";
|
2020-02-07 14:05:07 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
@Component({
|
2020-02-07 14:05:07 +01:00
|
|
|
selector: 'search-result',
|
|
|
|
templateUrl: 'searchResult.component.html'
|
2017-12-19 13:53:46 +01:00
|
|
|
})
|
2023-02-16 15:33:40 +01:00
|
|
|
export class SearchResultComponent implements OnInit, OnChanges {
|
2023-04-20 19:06:53 +02:00
|
|
|
@Input() prevPath: string = "";
|
2020-02-07 14:05:07 +01:00
|
|
|
@Input() results: SearchResult[];
|
2023-02-16 15:33:40 +01:00
|
|
|
previewResults: ResultPreview[];
|
2020-02-07 14:05:07 +01:00
|
|
|
@Input() status: number;
|
|
|
|
@Input() type: string;
|
|
|
|
@Input() showLoading: boolean = false;
|
2020-03-12 11:44:51 +01:00
|
|
|
@Input() showSubjects: boolean = true;
|
2020-02-07 14:05:07 +01:00
|
|
|
@Input() showOrganizations: boolean = true;
|
2022-03-03 15:41:07 +01:00
|
|
|
@Input() custom_class: string = "";
|
2020-02-07 14:05:07 +01:00
|
|
|
@Input() properties: EnvProperties;
|
2021-04-02 11:17:00 +02:00
|
|
|
@Input() showEnermaps: boolean;
|
[develop | DONE | ADDED]: Added compact view functionality on search pages.
1. newSearchPage.component.html: Increase left margin of download button | Added button for compact view | In <search-result> added parameter "compactView".
2. newSearchPage.component.html: Added class fields "@Input() hasCompactView: boolean = false;", to show compact button or not and "public compactView: boolean = false;" to show compact or expanded view of each result.
3. searchDownload.component.ts: Changed download <button> to <a> with class "custom-view-button" | Set visuallyHidden to icon.
4. searchResult.component.ts: Added class field "@Input() compactView: boolean = false;".
5. searchResult.component.html: In <result-preview added parameter "compactView".
6. entity-actions.component.ts: Added class field "@Input() compactView: boolean = false;" | When compactView is true, hide action labels - show only icons.
7. result-preview.component.ts: Added class field "@Input() compactView: boolean = false;".
8. result-preview.component.html: When compactView is true, make margins smaller, show 1 line in title, hide funder budget, identifiers, website url, oai-pmh url, description, action oa routes and metrics labels, and added "compactView" parameter in <entity-actions>.
2024-07-09 16:11:55 +02:00
|
|
|
@Input() compactView: boolean = false; // if true, show less info (e.g. hide description) on each result
|
|
|
|
|
2024-07-23 01:17:45 +02:00
|
|
|
@Input() isLoggedIn: boolean = false;
|
|
|
|
|
2023-02-16 15:33:40 +01:00
|
|
|
public isMobile: boolean = false;
|
|
|
|
private subscriptions: any[] = [];
|
2020-05-19 17:59:20 +02:00
|
|
|
|
2023-02-16 15:33:40 +01:00
|
|
|
constructor(private orcidService: OrcidService,
|
|
|
|
private layoutService: LayoutService) {
|
2020-02-07 14:05:07 +01:00
|
|
|
}
|
2023-02-16 15:33:40 +01:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.subscriptions.push(this.layoutService.isMobile.subscribe(isMobile => {
|
|
|
|
this.isMobile = isMobile;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2020-11-11 15:43:13 +01:00
|
|
|
ngOnDestroy() {
|
2023-02-16 15:33:40 +01:00
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if(subscription instanceof Subscription) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
if (changes.results) {
|
|
|
|
this.initialize();
|
2020-11-11 15:43:13 +01:00
|
|
|
}
|
|
|
|
}
|
2023-02-16 15:33:40 +01:00
|
|
|
|
|
|
|
initialize() {
|
2020-04-06 16:49:38 +02:00
|
|
|
this.previewResults = [];
|
2023-02-16 15:33:40 +01:00
|
|
|
for (let result of this.results) {
|
2020-04-06 16:49:38 +02:00
|
|
|
this.previewResults.push(this.getResultPreview(result));
|
|
|
|
}
|
2021-01-13 19:30:25 +01:00
|
|
|
|
2024-04-03 15:16:09 +02:00
|
|
|
if ((properties.adminToolsPortalType == "explore" || properties.adminToolsPortalType == "community" || properties.adminToolsPortalType == "aggregator" || properties.dashboard == "irish")
|
2024-07-23 01:17:45 +02:00
|
|
|
&& this.isLoggedIn && this.results && this.results.length > 0
|
2022-02-16 10:40:05 +01:00
|
|
|
&& (this.type == "result" || this.type == "publication" || this.type == "dataset" || this.type == "software" || this.type == "other")
|
2023-02-16 15:33:40 +01:00
|
|
|
) {
|
2024-07-23 01:17:45 +02:00
|
|
|
this.subscriptions.push(this.orcidService.getPutCodes(
|
|
|
|
this.previewResults.map(previewResult => {return previewResult.relcanId}),
|
|
|
|
this.previewResults.map(
|
2023-02-16 15:33:40 +01:00
|
|
|
previewResult => {
|
|
|
|
if (previewResult.identifiers) {
|
2024-07-23 01:17:45 +02:00
|
|
|
let pidsArray: string[] = null;
|
|
|
|
if(previewResult.identifiers?.size > 0) {
|
|
|
|
pidsArray = [];
|
|
|
|
for (let key of Array.from(previewResult.identifiers.keys())) {
|
|
|
|
pidsArray = pidsArray.concat(previewResult.identifiers.get(key));
|
|
|
|
}
|
2023-02-16 15:33:40 +01:00
|
|
|
}
|
|
|
|
return pidsArray;//.join();
|
2021-01-13 19:30:25 +01:00
|
|
|
}
|
2023-02-16 15:33:40 +01:00
|
|
|
})).subscribe(
|
|
|
|
putCodes => {
|
|
|
|
for (let i = 0; i < this.previewResults.length; i++) {
|
2024-07-23 01:17:45 +02:00
|
|
|
//if (this.previewResults[i].identifiers) {
|
2023-02-16 15:33:40 +01:00
|
|
|
this.previewResults[i].orcidPutCodes = putCodes[i];
|
|
|
|
// console.debug(i, this.previewResults[i].orcidPutCodes);
|
2024-07-23 01:17:45 +02:00
|
|
|
//}
|
2021-01-13 19:30:25 +01:00
|
|
|
}
|
2024-04-16 09:23:07 +02:00
|
|
|
this.previewResults = JSON.parse(JSON.stringify(this.previewResults, this.replacer), this.reviver);
|
2023-02-16 15:33:40 +01:00
|
|
|
}, error => {
|
2021-01-13 19:30:25 +01:00
|
|
|
|
2023-02-16 15:33:40 +01:00
|
|
|
}
|
|
|
|
));
|
2021-01-13 19:30:25 +01:00
|
|
|
}
|
2020-04-06 16:49:38 +02:00
|
|
|
}
|
|
|
|
|
2024-04-15 16:11:38 +02:00
|
|
|
private replacer(key, value) {
|
|
|
|
if(value instanceof Map) {
|
|
|
|
return {
|
|
|
|
dataType: 'Map',
|
|
|
|
value: Array.from(value.entries()), // or with spread: value: [...value]
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private reviver(key, value) {
|
|
|
|
if(typeof value === 'object' && value !== null) {
|
|
|
|
if (value.dataType === 'Map') {
|
|
|
|
return new Map(value.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2020-03-12 14:49:10 +01:00
|
|
|
public getResultPreview(result: SearchResult): ResultPreview {
|
2023-02-16 15:33:40 +01:00
|
|
|
return ResultPreview.searchResultConvert(result, (result.entityType) ? result.entityType : this.type);
|
2020-02-07 14:05:07 +01:00
|
|
|
}
|
2023-02-16 15:33:40 +01:00
|
|
|
|
|
|
|
|
2020-02-07 14:05:07 +01:00
|
|
|
public quote(params: string): string {
|
|
|
|
return '"' + params + '"';
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|