From bb12a21fe3ebd98e3a818f48cbf38688860f2aa2 Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Wed, 21 Dec 2016 16:34:35 +0000 Subject: [PATCH] Use vocabularies from APIs | apply uikit changes to advanced form git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@45022 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../advancedSearchForm.component.ts | 98 ++++++++------- .../advancedSearchPage.component.ts | 2 +- .../app/services/ISVocabularies.service.ts | 115 +++++++++--------- .../utils/entitiesAutoComplete.component.ts | 34 +++--- .../app/utils/staticAutoComplete.component.ts | 60 +++++---- portal-2/src/index.html | 22 ++++ 6 files changed, 177 insertions(+), 154 deletions(-) diff --git a/portal-2/src/app/searchPages/searchUtils/advancedSearchForm.component.ts b/portal-2/src/app/searchPages/searchUtils/advancedSearchForm.component.ts index 1a9cfc62..8cf634ea 100644 --- a/portal-2/src/app/searchPages/searchUtils/advancedSearchForm.component.ts +++ b/portal-2/src/app/searchPages/searchUtils/advancedSearchForm.component.ts @@ -1,4 +1,4 @@ -import {Component, Input, Output, EventEmitter} from '@angular/core'; +import {Component, Input, Output, EventEmitter, ElementRef} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import { Subject } from 'rxjs/Subject'; @@ -9,42 +9,40 @@ import {Dates} from '../../utils/string-utils.class'; @Component({ selector: 'advanced-search-form', template: ` -
-
-
- - -
-
-
- + +
+ + -
- - - - - -
- -
-
- -
-
- + + + + - + -
Yes
@@ -53,33 +51,33 @@ import {Dates} from '../../utils/string-utils.class'; No
-
- + -
-
-
- - -
- + +
+ + + -
+
+ +
-
` diff --git a/portal-2/src/app/searchPages/searchUtils/advancedSearchPage.component.ts b/portal-2/src/app/searchPages/searchUtils/advancedSearchPage.component.ts index 433bea6a..265fbc3c 100644 --- a/portal-2/src/app/searchPages/searchUtils/advancedSearchPage.component.ts +++ b/portal-2/src/app/searchPages/searchUtils/advancedSearchPage.component.ts @@ -10,7 +10,7 @@ import {SearchUtilsClass} from './searchUtils.class'; selector: 'advanced-search-page', template: ` -
+
diff --git a/portal-2/src/app/services/ISVocabularies.service.ts b/portal-2/src/app/services/ISVocabularies.service.ts index ebd7ef78..12dc23b3 100644 --- a/portal-2/src/app/services/ISVocabularies.service.ts +++ b/portal-2/src/app/services/ISVocabularies.service.ts @@ -10,88 +10,89 @@ import { CacheService } from '../shared/cache.service'; @Injectable() export class ISVocabulariesService { // private api ="https://beta.services.openaire.eu/provision/mvc/vocabularies/"; - private api = "http://api.openaire.eu/vocabularies/" + // private api = "http://api.openaire.eu/vocabularies/" + private api = "http://dev.openaire.research-infrastructures.eu/vocabularies/"; constructor(private http: Http, public _cache: CacheService) {} - getVocabularyByType(field:string,entity:string):AutoCompleteValue[]{ + getVocabularyByType(field:string,entity:string):any{ console.log("getVocabulary field: "+ field + " for entity: "+ entity); var file = ""; var vocabulary = ""; if( field == "lang"){ - file="languages.json"; - return this.getVocabularyFromFile(file); - // vocabulary = "dnet:languages.json"; - // return this.getVocabularyFromService(vocabulary); + // file="languages.json"; + // return this.getVocabularyFromFile(file); + vocabulary = "dnet:languages.json"; + return this.getVocabularyFromService(vocabulary); }else if ( field == "type" && (entity == "publication")){ - file = "publicationTypes.json"; - return this.getVocabularyFromFile(file); - // vocabulary = "dnet:publication_resource.json"; - // return this.getVocabularyFromService(vocabulary); + // file = "publicationTypes.json"; + // return this.getVocabularyFromFile(file); + vocabulary = "dnet:publication_resource.json"; + return this.getVocabularyFromService(vocabulary); }else if ( field == "type" && (entity == "dataset")){ - file = "dnet:dataCite_resource.json"; - return this.getVocabularyFromFile(file); - // vocabulary = "dnet:dataCite_resource.json"; - // return this.getVocabularyFromService(vocabulary); + // file = "dnet:dataCite_resource.json"; + // return this.getVocabularyFromFile(file); + vocabulary = "dnet:dataCite_resource.json"; + return this.getVocabularyFromService(vocabulary); }else if( field == "access" && (entity == "publication" || entity == "dataset")){ - file= "accessMode.json"; - return this.getVocabularyFromFile(file); - // vocabulary = "dnet:access_modes.json"; - // return this.getVocabularyFromService(vocabulary); + // file= "accessMode.json"; + // return this.getVocabularyFromFile(file); + vocabulary = "dnet:access_modes.json"; + return this.getVocabularyFromService(vocabulary); } else if( (field == "datasourcetype") && (entity == "dataprovider")){ - file = "dataProviderType.json"; - return this.getVocabularyFromFile(file); - // vocabulary = "dnet:datasource_typologies.json"; - // return this.getVocabularyFromService(vocabulary); + // file = "dataProviderType.json"; + // return this.getVocabularyFromFile(file); + vocabulary = "dnet:datasource_typologies.json"; + return this.getVocabularyFromService(vocabulary); } else if( field == "compatibility" && (entity == "dataprovider")){ - file = "dataProviderCompatibility.json"; - return this.getVocabularyFromFile(file); - // vocabulary = "dnet:datasourceCompatibilityLevel.json"; - // return this.getVocabularyFromService(vocabulary); + // file = "dataProviderCompatibility.json"; + // return this.getVocabularyFromFile(file); + vocabulary = "dnet:datasourceCompatibilityLevel.json"; + return this.getVocabularyFromService(vocabulary); } else if( field == "country" ){ - file = "countries.json"; - return this.getVocabularyFromFile(file); - // vocabulary = "dnet:countries.json"; - // return this.getVocabularyFromService(vocabulary); + // file = "countries.json"; + // return this.getVocabularyFromFile(file); + vocabulary = "dnet:countries.json"; + return this.getVocabularyFromService(vocabulary); } return null; } - getVocabularyFromFile (file:string):AutoCompleteValue[] { - var lang = JSON.parse(JSON.stringify(require('../utils/vocabularies/'+file))); - return this.parse(lang["terms"]); - } + // getVocabularyFromFile (file:string):AutoCompleteValue[] { + // var lang = JSON.parse(JSON.stringify(require('../utils/vocabularies/'+file))); + // return this.parse(lang["terms"]); + // } getVocabularyFromService (vocabularyName:string):any { let url = this.api + vocabularyName; console.log(url); - // let key = url; - // if (this._cache.has(key)) { - // return Observable.of(this._cache.get(key)); - // } - return this.http.get(url).toPromise() - .then(request => - { - request = request.json()['terms']; - var results:AutoCompleteValue[] = this.parse(request); - console.log("Get vocabulary : "+ vocabularyName+ " - get " +results.length+ "results"); - return results; - }); - // return this.http.get(url) - // .do(res => console.log(res)) - // .map(res => res.json()) - // .map(res => res['terms']) - // .do(res => console.log(res)) - // .map(res => this.parse(res)) - // .do(res => console.log(res)) - // .catch(this.handleError); - // // .do(res => { - // // this._cache.set(key, res); - // // }); + let key = url; + if (this._cache.has(key)) { + return Observable.of(this._cache.get(key)); + } + // return this.http.get(url).toPromise() + // .then(request => + // { + // request = request.json()['terms']; + // var results:AutoCompleteValue[] = this.parse(request); + // console.log("Get vocabulary : "+ vocabularyName+ " - get " +results.length+ "results"); + // return results; + // }); + return this.http.get(url) + .do(res => console.log(res)) + .map(res => res.json()) + .map(res => res['terms']) + .do(res => console.log(res)) + .map(res => this.parse(res)) + .do(res => console.log(res)) + .catch(this.handleError) + .do(res => { + this._cache.set(key, res); + }); } diff --git a/portal-2/src/app/utils/entitiesAutoComplete.component.ts b/portal-2/src/app/utils/entitiesAutoComplete.component.ts index 88afb460..22937f52 100644 --- a/portal-2/src/app/utils/entitiesAutoComplete.component.ts +++ b/portal-2/src/app/utils/entitiesAutoComplete.component.ts @@ -14,30 +14,25 @@ import {EntitiesSearchService} from '../services/entitySearch.service'; '(document:click)': 'handleClick($event)', }, template: ` -
-
-
- {{showItem(item)}} - -
-
+ + + {{showItem(item)}} + + + -
- -
    - -
  • + Loading... + {{warningMessage}} + -
    - - -
    -
+ +
` @@ -79,7 +74,6 @@ export class EntitiesAutocompleteComponent { } ngOnInit () { - console.info("init deposit org" +this.entityType +" "+this.depositType); if(this.entityType == "project" && this.funderId ){ this.filtered = this.searchTermStream diff --git a/portal-2/src/app/utils/staticAutoComplete.component.ts b/portal-2/src/app/utils/staticAutoComplete.component.ts index 83e974e4..4de93e58 100644 --- a/portal-2/src/app/utils/staticAutoComplete.component.ts +++ b/portal-2/src/app/utils/staticAutoComplete.component.ts @@ -12,30 +12,23 @@ import {RefineFieldResultsService} from '../services/refineFieldResults.service' '(document:click)': 'handleClick($event)', }, template: ` -
-
-
- {{showItem(item)}} - + + + {{showItem(item)}} + + + + + Loading... + {{warningMessage}} +
+
-
- -
- -
-
- - - -
-
+ ` }) @@ -78,10 +71,21 @@ export class StaticAutoCompleteComponent { this.showLoading = true; if(this.vocabularyId){ - this.list = this._vocabulariesService.getVocabularyByType(this.vocabularyId, this.entityName); - this.afterListFetchedActions(); + // this.list = this._vocabulariesService.getVocabularyByType(this.vocabularyId, this.entityName); + // this.afterListFetchedActions(); + this.sub = this._vocabulariesService.getVocabularyByType(this.vocabularyId, this.entityName).subscribe( + data => { + this.list = data; + this.afterListFetchedActions(); + + }, + err => { + console.log(err); + this.warningMessage = "An Error occured..." + } + ); }else if(this.fieldName && this.entityName){ - this.list = this._refineService.getRefineFieldResultsByFieldName(this.fieldName,this.entityName); + // this.list = this._refineService.getRefineFieldResultsByFieldName(this.fieldName,this.entityName); this.sub = this._refineService.getRefineFieldResultsByFieldName(this.fieldName,this.entityName).subscribe( data => { this.list = data; @@ -152,10 +156,14 @@ export class StaticAutoCompleteComponent { } remove(item:any){ var index:number =this.checkIfExists(item,this.selected); + console.info("try to remove: index = "+index + " length: "+this.selected.length); if (index > -1) { this.selected.splice(index, 1); } + console.info("after remove: length: "+this.selected.length); if(!this.multipleSelections && this.selected.length == 0 ){ + console.info("no multiselections "); + this.showInput = true; this.selectedValue = ""; this.selectedValueChanged.emit({ diff --git a/portal-2/src/index.html b/portal-2/src/index.html index 76cf7106..867b997f 100644 --- a/portal-2/src/index.html +++ b/portal-2/src/index.html @@ -72,6 +72,28 @@