explore-services/explore/src/app/fos/fos.component.ts

189 lines
6.1 KiB
TypeScript
Raw Normal View History

import {HttpClient} from "@angular/common/http";
2022-04-14 17:05:47 +02:00
import {Component, OnDestroy, OnInit} from "@angular/core";
import {Subscription} from "rxjs";
import {Breadcrumb} from "../openaireLibrary/utils/breadcrumbs/breadcrumbs.component";
import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties";
import {properties} from "src/environments/environment";
2022-04-14 17:05:47 +02:00
import {FormBuilder, FormControl} from "@angular/forms";
2022-06-21 13:08:21 +02:00
import {ActivatedRoute, Router} from "@angular/router";
import {Meta, Title} from "@angular/platform-browser";
2022-04-14 17:05:47 +02:00
import {Location} from "@angular/common";
[Explore & Library & openaire-theme | new-theme]: Updated parsing of classified subjects by using a vocabulary | Added parsing of instance.license in Download from | Added feedback functionality for fos and sdgs in landing | #7509 Parsing both citations and references fields | In "view all/less" links added chervon-right icon with class "view-more-less-link". 1. fos.component.ts & sdg.component.ts: Added method "urlEncodeAndQuote()" to encode and then quote a string. 2. fos.component.html & sdg.component.html: a. "Beta" badge was updated to yellow uk-text-large. b. Link to the simple search page instead of the advanced and urlEncodeAndQuote the parameter used in url. 3. link.css: Added class "view-more-less-link" to set on ::after "chevron_right" icon (not underlined on hover) - used in "view all/more/less" links. 4. dataProvider.component.html & project.component.html & fundedBy.component.ts & relatedTo.component.ts & showIdentifiers.component.ts & showAuthors.component.ts: In "view all/less" links added class "view-more-less-link" | Renamed "view more" to "view all". 5. feedback.component.html: Rename wording to be more positive: issues -> feedback, issue -> comment, report -> feedback. 6. feedback.component.ts: Added @Input() preSelectedField: string = ""; and set with it "field" on "addIssue()" (fos/sdg preselected for feedback). 7. availableOn.component.ts: a. In "view all/less" links added class "view-more-less-link". b. #7833 - Show instance.license information (as link when recognized as url, string otherwise). 8. landing-utils/fos.component.ts & landing-utils/sdg.component.ts: a. "Beta" word was updated to yellow uk-text-xsmall. b. In "view all/less" links added class "view-more-less-link". c. Added feedback functionality: link to feedback form. 9. showSubjects.component.ts: a. In "view all/less" links added class "view-more-less-link". b. Added "view all" functionality for classified subjects too. 10. resultLanding.component.html: a. In "view all/less" links added class "view-more-less-link" | Renamed "view more" to "view all" b. Added feedback functionality: link to feedback form - preselect in feedback form fos/sdg. 11. resultLanding.component.ts: a. Added public feedbackPreSelectedField: string = ""; field. b. Added method "feedbackClicked()". c. [Bug fix] In hasPrimaryInfo() added check for classifiedSubjects. d. Renamed getProvenanceVocabularyAndResultLandingInfo() to getVocabulariesAndResultLandingInfo() and call also this._vocabulariesService.getSubjectsVocabulary(). 12. parsingFunctions.class.ts: a. #7196 - Updated parsing of subjects in method "parseAllSubjects()". b. #7833 - In method "parseHostedBy_collectedFrom()", added parsing for "license" field. 13. orcid-work.component.ts: On calling method "this.resultLandingService.getResultLandingInfo()", added null parameter for subject vocabulary. 14. searchFilter.module.ts: Import IconsModule. 15. searchFilter.component.html: Removed +/- form "view all/less" links and added class "view-more-less-link". 16. result-preview.ts: Added "licence?: string" in HostedByCollectedFrom. 17. ISVocabularies.service.ts: a. Added "private subjectsVocabulary: BehaviorSubject<any> = new BehaviorSubject<any>(null);" field and methods "getSubjectsVocabulary()", "getSubjectsVocabularyFromService()". b. Commented this.clearSubscriptions() from "getProvenanceActionVocabularyFromServiceAsync()". 18. resultLanding.service.ts: a. On subjects parsing, use subjectsVocabulary. b. #7509- Added if/then/else case for parsing citations (new name: references).
2022-06-09 15:45:39 +02:00
import {StringUtils} from "../openaireLibrary/utils/string-utils.class";
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
import {PiwikService} from "../openaireLibrary/utils/piwik/piwik.service";
import {debounceTime, distinctUntilChanged} from "rxjs/operators";
import Timeout = NodeJS.Timeout;
@Component({
selector: 'fos',
templateUrl: 'fos.component.html',
styleUrls: ['fos.component.less']
})
export class FosComponent implements OnInit, OnDestroy {
2022-06-21 13:08:21 +02:00
public url: string = null;
public pageTitle: string = "OpenAIRE | Fields of Science";
public pageDescription: string = "We have integrated a Field-of-Science (FoS) taxonomy into our dataset to organize and discover research more effectively. Using the full capabilities of the OpenAIRE Research Graph (full-texts, citations, references, venues) we apply AI and bring forward any multidisciplinarity potential.";
public fos: any[] = [];
public fosOptions: string[] = [];
public activeSection: string;
2022-04-07 15:20:10 +02:00
public keywordControl: FormControl;
public keyword: string;
2022-04-07 15:20:10 +02:00
2022-04-14 17:05:47 +02:00
public viewResults = [];
public result = [];
2022-04-07 15:20:10 +02:00
properties: EnvProperties = properties;
public breadcrumbs: Breadcrumb[] = [{name: 'home', route: '/'}, {name: 'Fields of Science'}];
private subscriptions: Subscription[] = [];
private observer: IntersectionObserver;
private timeout: Timeout;
constructor(
2022-04-07 15:20:10 +02:00
private httpClient: HttpClient,
2022-04-14 17:05:47 +02:00
private fb: FormBuilder,
private location: Location,
private route: ActivatedRoute,
2022-06-21 13:08:21 +02:00
private _router: Router,
private _meta: Meta,
private _title: Title,
private seoService: SEOService,
private _piwikService: PiwikService
) {}
ngOnInit() {
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.properties.piwikSiteId).subscribe());
}
2022-06-21 13:08:21 +02:00
this.url = this.properties.domain + this.properties.baseLink + this._router.url;
this.seoService.createLinkForCanonicalURL(this.url);
2022-06-21 13:08:21 +02:00
this.updateUrl(this.url);
this.updateTitle(this.pageTitle);
this.updateDescription(this.pageDescription);
this.httpClient.get(properties.domain+'/assets/vocabulary/fos.json').subscribe(data => {
2022-04-14 17:05:47 +02:00
this.fos = data['fos'];
this.convertFosToOptions();
this.subscriptions.push(this.route.fragment.subscribe(fragment => {
if(fragment) {
this.activeSection = fragment;
} else {
this.activeSection = this.fos[0].id;
2022-04-14 17:05:47 +02:00
}
}));
this.keywordControl = this.fb.control('');
this.subscriptions.push(this.keywordControl.valueChanges.pipe(debounceTime(500), distinctUntilChanged()).subscribe(value => {
this.keyword = value;
this.findMatches(this.keyword);
setTimeout(() => {
this.setObserver();
});
}));
});
}
public ngOnDestroy() {
for (let sub of this.subscriptions) {
sub.unsubscribe();
}
if(this.observer) {
this.observer.disconnect();
}
}
private setObserver() {
if(this.observer) {
this.observer.disconnect();
}
this.observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if(entry.isIntersecting) {
if(this.timeout) {
clearTimeout(this.timeout);
}
this.timeout = setTimeout(() => {
this._router.navigate(['./'], {fragment: entry.target.id, relativeTo: this.route, state: {disableScroll: true}});
}, 200);
}
});
}, {threshold: 0.25, rootMargin: '-100px'});
this.fos.forEach(fos => {
let element = document.getElementById(fos.id);
if(element) {
this.observer.observe(element);
}
});
}
convertFosToOptions() {
this.fosOptions = [];
this.fos.forEach(fos => {
this.fosOptions.push(fos.id);
if(fos.children) {
fos.children.forEach(child => {
this.fosOptions.push(child.id);
if(child.children) {
child.children.forEach(child2 => {
this.fosOptions.push(child2.id);
});
}
});
}
});
}
2022-04-07 15:20:10 +02:00
findMatches(value: string) {
2022-04-14 17:05:47 +02:00
this.viewResults = JSON.parse(JSON.stringify(this.fos));
let matchLevel1: boolean = false;
let matchLevel2: boolean = false;
2022-04-07 15:20:10 +02:00
// 1st level search
2022-04-14 17:05:47 +02:00
if(this.viewResults.length) {
this.viewResults = this.viewResults.filter(item => {
matchLevel1 = !!item.id.includes(value?.toLowerCase());
2022-04-14 17:05:47 +02:00
// // 2nd level search
if(item.children?.length && !matchLevel1) {
item.children = item.children.filter(subItem => {
matchLevel2 = !!subItem.id.includes(value?.toLowerCase());
2022-04-14 17:05:47 +02:00
// 3rd level search
if(subItem.children?.length && !matchLevel2) {
subItem.children = subItem.children.filter(subSubItem => subSubItem.id.includes(value?.toLowerCase()));
2022-04-14 17:05:47 +02:00
}
return subItem.children?.length > 0 || matchLevel2;
});
2022-04-07 15:20:10 +02:00
}
2022-04-14 17:05:47 +02:00
return item.children?.length > 0;
2022-04-07 15:20:10 +02:00
});
}
}
highlightKeyword(name) {
2022-04-14 17:05:47 +02:00
if(name.includes(this.keyword.toLowerCase())) {
return name.replace(new RegExp(this.keyword, "gi"), (matchedValue) => `<mark class="highlighted">${matchedValue}</mark>`);
} else {
return name;
}
}
[Explore & Library & openaire-theme | new-theme]: Updated parsing of classified subjects by using a vocabulary | Added parsing of instance.license in Download from | Added feedback functionality for fos and sdgs in landing | #7509 Parsing both citations and references fields | In "view all/less" links added chervon-right icon with class "view-more-less-link". 1. fos.component.ts & sdg.component.ts: Added method "urlEncodeAndQuote()" to encode and then quote a string. 2. fos.component.html & sdg.component.html: a. "Beta" badge was updated to yellow uk-text-large. b. Link to the simple search page instead of the advanced and urlEncodeAndQuote the parameter used in url. 3. link.css: Added class "view-more-less-link" to set on ::after "chevron_right" icon (not underlined on hover) - used in "view all/more/less" links. 4. dataProvider.component.html & project.component.html & fundedBy.component.ts & relatedTo.component.ts & showIdentifiers.component.ts & showAuthors.component.ts: In "view all/less" links added class "view-more-less-link" | Renamed "view more" to "view all". 5. feedback.component.html: Rename wording to be more positive: issues -> feedback, issue -> comment, report -> feedback. 6. feedback.component.ts: Added @Input() preSelectedField: string = ""; and set with it "field" on "addIssue()" (fos/sdg preselected for feedback). 7. availableOn.component.ts: a. In "view all/less" links added class "view-more-less-link". b. #7833 - Show instance.license information (as link when recognized as url, string otherwise). 8. landing-utils/fos.component.ts & landing-utils/sdg.component.ts: a. "Beta" word was updated to yellow uk-text-xsmall. b. In "view all/less" links added class "view-more-less-link". c. Added feedback functionality: link to feedback form. 9. showSubjects.component.ts: a. In "view all/less" links added class "view-more-less-link". b. Added "view all" functionality for classified subjects too. 10. resultLanding.component.html: a. In "view all/less" links added class "view-more-less-link" | Renamed "view more" to "view all" b. Added feedback functionality: link to feedback form - preselect in feedback form fos/sdg. 11. resultLanding.component.ts: a. Added public feedbackPreSelectedField: string = ""; field. b. Added method "feedbackClicked()". c. [Bug fix] In hasPrimaryInfo() added check for classifiedSubjects. d. Renamed getProvenanceVocabularyAndResultLandingInfo() to getVocabulariesAndResultLandingInfo() and call also this._vocabulariesService.getSubjectsVocabulary(). 12. parsingFunctions.class.ts: a. #7196 - Updated parsing of subjects in method "parseAllSubjects()". b. #7833 - In method "parseHostedBy_collectedFrom()", added parsing for "license" field. 13. orcid-work.component.ts: On calling method "this.resultLandingService.getResultLandingInfo()", added null parameter for subject vocabulary. 14. searchFilter.module.ts: Import IconsModule. 15. searchFilter.component.html: Removed +/- form "view all/less" links and added class "view-more-less-link". 16. result-preview.ts: Added "licence?: string" in HostedByCollectedFrom. 17. ISVocabularies.service.ts: a. Added "private subjectsVocabulary: BehaviorSubject<any> = new BehaviorSubject<any>(null);" field and methods "getSubjectsVocabulary()", "getSubjectsVocabularyFromService()". b. Commented this.clearSubscriptions() from "getProvenanceActionVocabularyFromServiceAsync()". 18. resultLanding.service.ts: a. On subjects parsing, use subjectsVocabulary. b. #7509- Added if/then/else case for parsing citations (new name: references).
2022-06-09 15:45:39 +02:00
public urlEncodeAndQuote(str: string): string {
return StringUtils.quote(StringUtils.URIEncode(str));
2022-06-21 13:08:21 +02:00
}
private updateUrl(url: string) {
this._meta.updateTag({content: url}, "property='og:url'");
}
private updateTitle(title: string) {
var _title = ((title.length > 50) ? title.substring(0, 50) : title);
this._title.setTitle(_title);
this._meta.updateTag({content: _title}, "property='og:title'");
}
private updateDescription(description: string) {
this._meta.updateTag({content: description}, "name='description'");
this._meta.updateTag({content: description}, "property='og:description'");
[Explore & Library & openaire-theme | new-theme]: Updated parsing of classified subjects by using a vocabulary | Added parsing of instance.license in Download from | Added feedback functionality for fos and sdgs in landing | #7509 Parsing both citations and references fields | In "view all/less" links added chervon-right icon with class "view-more-less-link". 1. fos.component.ts & sdg.component.ts: Added method "urlEncodeAndQuote()" to encode and then quote a string. 2. fos.component.html & sdg.component.html: a. "Beta" badge was updated to yellow uk-text-large. b. Link to the simple search page instead of the advanced and urlEncodeAndQuote the parameter used in url. 3. link.css: Added class "view-more-less-link" to set on ::after "chevron_right" icon (not underlined on hover) - used in "view all/more/less" links. 4. dataProvider.component.html & project.component.html & fundedBy.component.ts & relatedTo.component.ts & showIdentifiers.component.ts & showAuthors.component.ts: In "view all/less" links added class "view-more-less-link" | Renamed "view more" to "view all". 5. feedback.component.html: Rename wording to be more positive: issues -> feedback, issue -> comment, report -> feedback. 6. feedback.component.ts: Added @Input() preSelectedField: string = ""; and set with it "field" on "addIssue()" (fos/sdg preselected for feedback). 7. availableOn.component.ts: a. In "view all/less" links added class "view-more-less-link". b. #7833 - Show instance.license information (as link when recognized as url, string otherwise). 8. landing-utils/fos.component.ts & landing-utils/sdg.component.ts: a. "Beta" word was updated to yellow uk-text-xsmall. b. In "view all/less" links added class "view-more-less-link". c. Added feedback functionality: link to feedback form. 9. showSubjects.component.ts: a. In "view all/less" links added class "view-more-less-link". b. Added "view all" functionality for classified subjects too. 10. resultLanding.component.html: a. In "view all/less" links added class "view-more-less-link" | Renamed "view more" to "view all" b. Added feedback functionality: link to feedback form - preselect in feedback form fos/sdg. 11. resultLanding.component.ts: a. Added public feedbackPreSelectedField: string = ""; field. b. Added method "feedbackClicked()". c. [Bug fix] In hasPrimaryInfo() added check for classifiedSubjects. d. Renamed getProvenanceVocabularyAndResultLandingInfo() to getVocabulariesAndResultLandingInfo() and call also this._vocabulariesService.getSubjectsVocabulary(). 12. parsingFunctions.class.ts: a. #7196 - Updated parsing of subjects in method "parseAllSubjects()". b. #7833 - In method "parseHostedBy_collectedFrom()", added parsing for "license" field. 13. orcid-work.component.ts: On calling method "this.resultLandingService.getResultLandingInfo()", added null parameter for subject vocabulary. 14. searchFilter.module.ts: Import IconsModule. 15. searchFilter.component.html: Removed +/- form "view all/less" links and added class "view-more-less-link". 16. result-preview.ts: Added "licence?: string" in HostedByCollectedFrom. 17. ISVocabularies.service.ts: a. Added "private subjectsVocabulary: BehaviorSubject<any> = new BehaviorSubject<any>(null);" field and methods "getSubjectsVocabulary()", "getSubjectsVocabularyFromService()". b. Commented this.clearSubscriptions() from "getProvenanceActionVocabularyFromServiceAsync()". 18. resultLanding.service.ts: a. On subjects parsing, use subjectsVocabulary. b. #7509- Added if/then/else case for parsing citations (new name: references).
2022-06-09 15:45:39 +02:00
}
}