Add getFos and getSDGs in vocabulary service and use it in the related components.

This commit is contained in:
Konstantinos Triantafyllou 2023-04-03 12:53:40 +03:00
parent 9446b64efd
commit 7ecb56ec98
5 changed files with 28 additions and 17 deletions

View File

@ -1,4 +1,3 @@
import {HttpClient} from "@angular/common/http";
import {ChangeDetectorRef, Component, ElementRef, Input, ViewChild} from "@angular/core";
import {FormBuilder, FormControl, UntypedFormArray} from "@angular/forms";
import {ActivatedRoute, Router} from "@angular/router";
@ -8,6 +7,7 @@ import {properties} from "../../../../environments/environment";
import {StringUtils} from "../../utils/string-utils.class";
import {debounceTime, distinctUntilChanged} from "rxjs/operators";
import {HelperFunctions} from "../../utils/HelperFunctions.class";
import {ISVocabulariesService} from "../../utils/staticAutoComplete/ISVocabularies.service";
import Timeout = NodeJS.Timeout;
declare var UIkit;
@ -44,7 +44,7 @@ export class FosSelectionComponent {
public sliderInit: boolean = false;
constructor(
private httpClient: HttpClient,
private vocabulariesService: ISVocabulariesService,
private fb: FormBuilder,
private cdr: ChangeDetectorRef,
private route: ActivatedRoute,
@ -53,7 +53,7 @@ export class FosSelectionComponent {
ngOnInit() {
this.loading = true;
this.httpClient.get(this.properties.domain+'/assets/common-assets/vocabulary/fos.json').subscribe(data => {
this.vocabulariesService.getFos(properties).subscribe(data => {
this.fos = data['fos'];
this.convertFosToOptions();
if (typeof document !== 'undefined') {
@ -240,4 +240,4 @@ export class FosSelectionComponent {
return this.contentHeight - this.searchElement.nativeElement.offsetHeight - 100;
}
}
}
}

View File

@ -14,6 +14,7 @@ import {SEOService} from "../sharedComponents/SEO/SEO.service";
import {PiwikService} from "../utils/piwik/piwik.service";
import {debounceTime, distinctUntilChanged} from "rxjs/operators";
import Timeout = NodeJS.Timeout;
import {ISVocabulariesService} from "../utils/staticAutoComplete/ISVocabularies.service";
declare var UIkit;
@ -49,7 +50,7 @@ export class FosComponent implements OnInit, OnDestroy {
public sliderInit: boolean = false;
constructor(
private httpClient: HttpClient,
private vocabulariesService: ISVocabulariesService,
private fb: FormBuilder,
private location: Location,
private route: ActivatedRoute,
@ -70,7 +71,7 @@ export class FosComponent implements OnInit, OnDestroy {
this.updateUrl(this.url);
this.updateTitle(this.pageTitle);
this.updateDescription(this.pageDescription);
this.httpClient.get(properties.domain+'/assets/common-assets/vocabulary/fos.json').subscribe(data => {
this.vocabulariesService.getFos(properties).subscribe(data => {
this.fos = data['fos'];
this.convertFosToOptions();
if (typeof document !== 'undefined') {

View File

@ -4,6 +4,7 @@ import {UntypedFormArray, UntypedFormBuilder} from "@angular/forms";
import {properties} from "../../../../environments/environment";
import {EnvProperties} from "../../utils/properties/env-properties";
import {StringUtils} from "../../utils/string-utils.class";
import {ISVocabulariesService} from "../../utils/staticAutoComplete/ISVocabularies.service";
@Component({
selector: 'sdg-selection',
@ -20,14 +21,14 @@ export class SdgSelectionComponent {
public sdgs: UntypedFormArray;
constructor(
private httpClient: HttpClient,
private vocabulariesService: ISVocabulariesService,
private fb: UntypedFormBuilder
) {}
ngOnInit() {
this.loading = true;
this.sdgs = this.fb.array([]);
this.httpClient.get(this.properties.domain+'/assets/common-assets/vocabulary/sdg.json').subscribe(data => {
this.vocabulariesService.getSDGs(properties).subscribe(data => {
data['sdg'].forEach(element => {
// this.sdgs.push({code: element.code, id: element.id, label: element.label, html: element.html, checked: this.subjects?.includes(element.id)});
this.sdgs.push(this.fb.group({
@ -80,4 +81,4 @@ export class SdgSelectionComponent {
private getEntityName (entityType:string) {
return StringUtils.getEntityName(entityType, false);
}
}
}

View File

@ -11,6 +11,7 @@ import {Router} from '@angular/router';
import {Meta, Title} from "@angular/platform-browser";
import {SEOService} from "../sharedComponents/SEO/SEO.service";
import {PiwikService} from "../utils/piwik/piwik.service";
import {ISVocabulariesService} from "../utils/staticAutoComplete/ISVocabularies.service";
@Component({
selector: 'sdg',
@ -36,7 +37,7 @@ export class SdgComponent implements OnInit, OnDestroy {
subscriptions: Subscription[] = [];
constructor(
private httpClient: HttpClient, private refineFieldResultsService: RefineFieldResultsService,
private vocabulariesService: ISVocabulariesService, private refineFieldResultsService: RefineFieldResultsService,
private _router: Router,
private _meta: Meta,
private _title: Title,
@ -54,7 +55,7 @@ export class SdgComponent implements OnInit, OnDestroy {
this.updateUrl(this.url);
this.updateTitle(this.pageTitle);
this.updateDescription(this.pageDescription);
this.httpClient.get(properties.domain+'/assets/common-assets/vocabulary/sdg.json').subscribe(data => {
this.vocabulariesService.getSDGs(properties).subscribe(data => {
this.sdgs = data['sdg'];
});
let refineParams = null;

View File

@ -107,21 +107,28 @@ export class ISVocabulariesService {
getLocalVocabularyFromService(vocabularyName: string, properties: EnvProperties): Observable<AutoCompleteValue[]> {
if(vocabularyName == "sdg"){
let url = properties.domain+"/assets/common-assets/vocabulary/sdg.json";
return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
//.map(res => <any> res.json())
return this.getSDGs(properties)
.pipe(map(res => res['sdg']))
.pipe(map(res => this.parseSDGs(res)))
.pipe(catchError(this.handleError));
}else if( vocabularyName == "fos"){
let url = properties.domain+"/assets/common-assets/vocabulary/fos.json";
return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
//.map(res => <any> res.json())
return this.getFos(properties)
.pipe(map(res => res['fos']))
.pipe(map(res => this.parseFOS(res)))
.pipe(catchError(this.handleError));
}
}
getFos(properties: EnvProperties): Observable<any> {
let url = "/assets/common-assets/vocabulary/fos.json";
return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
}
getSDGs(properties: EnvProperties): Observable<any> {
let url = "/assets/common-assets/vocabulary/sdg.json";
return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
}
parseSDGs(data: any): AutoCompleteValue[] {
var array: AutoCompleteValue[] = []
@ -160,6 +167,7 @@ export class ISVocabulariesService {
}
return array;
}
parse(data: any, vocabularyName: string): AutoCompleteValue[] {
var array: AutoCompleteValue[] = []
for (var i = 0; i < data.length; i++) {