Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP : Advanced filters #702

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class="py-[37px] pl-[47px] rounded-lg border bg-white mb-5 card-shadow cursor-pointer"
[figure]="recordsCount$ | async"
[icon]="'folder_open'"
[title]="'catalog.figures.datasets'"
[title]="'catalog.figures.datasets' | translate"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is useless as the gn-ui-figure already does a translation.

[color]="'secondary'"
></gn-ui-figure>
</a>
Expand All @@ -13,7 +13,7 @@
class="py-[37px] pl-[47px] rounded-lg bg-white border card-shadow cursor-pointer"
[figure]="orgsCount$ | async"
[icon]="'corporate_fare'"
[title]="'catalog.figures.organisations'"
[title]="'catalog.figures.organisations' | translate"
[color]="'secondary'"
></gn-ui-figure>
</a>
Expand Down
135 changes: 135 additions & 0 deletions libs/data-access/gn4/src/custom-api/thesaurus.api.service.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The content of the commit has nothing to do with the commit message.

Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { Inject, Injectable, Optional } from '@angular/core'
import {
HttpClient,
HttpHeaders,
HttpParameterCodec,
} from '@angular/common/http'
import { Observable } from 'rxjs'
import { CustomHttpParameterCodec } from '../openapi/encoder'
import { Configuration } from '../openapi/configuration'

import { BASE_PATH } from '../openapi/variables'

export interface thesaurusResponse {
values: { [key: string]: string }
definitions: { [key: string]: string }
coordEast?: string
coordWest?: string
coordSouth?: string
coordNorth?: string
thesaurusKey: string
value: string
uri: string
definition?: string
}

@Injectable({
providedIn: 'root',
})
export class ThesaurusApiService {
protected basePath = 'https://apps.titellus.net/geonetwork/srv/api'
public defaultHeaders = new HttpHeaders()
public configuration = new Configuration()
public encoder: HttpParameterCodec

constructor(
protected httpClient: HttpClient,
@Optional() @Inject(BASE_PATH) basePath: string,
@Optional() configuration: Configuration
) {
if (configuration) {
this.configuration = configuration
}
if (typeof this.configuration.basePath !== 'string') {
if (typeof basePath !== 'string') {
basePath = this.basePath
}
this.configuration.basePath = basePath
}
this.encoder = this.configuration.encoder || new CustomHttpParameterCodec()
}

/**
* List database translations (used to overrides client application translations).
* @param esFieldName set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param iso3 set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public getTranslationsFromThesaurus(
thesaurusName: string,
langIso3: string,
observe?: 'body',
reportProgress?: boolean,
options?: { httpHeaderAccept?: 'application/json' }
): Observable<any>
public getTranslationsFromThesaurus(
thesaurusName: string,
langIso3: string,
observe?: 'response',
reportProgress?: boolean,
options?: { httpHeaderAccept?: 'application/json' }
): Observable<thesaurusResponse[]>
public getTranslationsFromThesaurus(
thesaurusName: string,
langIso3: string,
observe?: 'events',
reportProgress?: boolean,
options?: { httpHeaderAccept?: 'application/json' }
): Observable<thesaurusResponse[]>
public getTranslationsFromThesaurus(
thesaurusName: string,
langIso3: string,
observe: any = 'body',
reportProgress: boolean = false,
options?: { httpHeaderAccept?: 'application/json' }
): Observable<any> {
if (
thesaurusName === null ||
thesaurusName === undefined ||
langIso3 === null ||
langIso3 === undefined
) {
throw new Error(
'Required parameter pack was null or undefined when calling getTranslationsFromThesaurus.'
)
}

let headers = this.defaultHeaders

let httpHeaderAcceptSelected: string | undefined =
options && options.httpHeaderAccept
if (httpHeaderAcceptSelected === undefined) {
// to determine the Accept header
const httpHeaderAccepts: string[] = ['application/json']
httpHeaderAcceptSelected =
this.configuration.selectHeaderAccept(httpHeaderAccepts)
}
if (httpHeaderAcceptSelected !== undefined) {
headers = headers.set('Accept', httpHeaderAcceptSelected)
}

let responseType_: 'text' | 'json' = 'json'
if (
httpHeaderAcceptSelected &&
httpHeaderAcceptSelected.startsWith('text')
) {
responseType_ = 'text'
}

return this.httpClient.get<thesaurusResponse[]>(
`${
this.configuration.basePath
}/registries/vocabularies/search?rows=1000&type=CONTAINS&sort=DESC&thesaurus=${encodeURIComponent(
String(thesaurusName)
)}&lang=${encodeURIComponent(langIso3)}`,
{
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress,
}
)
}
}
23 changes: 9 additions & 14 deletions libs/data-access/gn4/src/openapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
### Building

To install the required dependencies and to build the typescript sources run:

```
npm install
npm run build
```

### publishing

First build the package then run `npm publish dist` (don't forget to specify the `dist` folder!)
First build the package then run ```npm publish dist``` (don't forget to specify the `dist` folder!)

### consuming

Expand All @@ -34,25 +33,25 @@ _It's important to take the tgz file, otherwise you'll get trouble with links on
_using `npm link`:_

In PATH_TO_GENERATED_PACKAGE/dist:

```
npm link
```

In your project:

```
npm link
npm link
```

**Note for Windows users:** The Angular CLI has troubles to use linked npm packages.
__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages.
Please refer to this issue https://github.com/angular/angular-cli/issues/8284 for a solution / workaround.
Published packages are not effected by this issue.


#### General usage

In your Angular project:


```
// without configuring providers
import { ApiModule } from '';
Expand Down Expand Up @@ -129,11 +128,9 @@ Note: The ApiModule is restricted to being instantiated once app wide.
This is to ensure that all services are treated as singletons.

#### Using multiple OpenAPI files / APIs / ApiModules

In order to use multiple `ApiModules` generated from different OpenAPI files,
you can create an alias name when importing the modules
in order to avoid naming conflicts:

```
import { ApiModule } from 'my-api-path';
import { ApiModule as OtherApiModule } from 'my-other-api-path';
Expand All @@ -153,9 +150,9 @@ export class AppModule {
}
```

### Set service base path

If different than the generated base path, during app bootstrap, you can provide the base path to your service.
### Set service base path
If different than the generated base path, during app bootstrap, you can provide the base path to your service.

```
import { BASE_PATH } from '';
Expand All @@ -164,7 +161,6 @@ bootstrap(AppComponent, [
{ provide: BASE_PATH, useValue: 'https://your-web-service.com' },
]);
```

or

```
Expand All @@ -179,8 +175,8 @@ import { BASE_PATH } from '';
export class AppModule {}
```

#### Using @angular/cli

#### Using @angular/cli
First extend your `src/environments/*.ts` files by adding the corresponding base path:

```
Expand All @@ -191,7 +187,6 @@ export const environment = {
```

In the src/app/app.module.ts:

```
import { BASE_PATH } from '';
import { environment } from '../environments/environment';
Expand All @@ -205,4 +200,4 @@ import { environment } from '../environments/environment';
bootstrap: [ AppComponent ]
})
export class AppModule { }
```
```
6 changes: 3 additions & 3 deletions libs/data-access/gn4/src/openapi/api/tools.api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
import { Inject, Injectable, Optional } from '@angular/core'
import {
HttpClient,
HttpEvent,
HttpHeaders,
HttpParameterCodec,
HttpParams,
HttpResponse,
HttpEvent,
HttpParameterCodec,
} from '@angular/common/http'
import { CustomHttpParameterCodec } from '../encoder'
import { Observable } from 'rxjs'

import { BASE_PATH, COLLECTION_FORMATS } from '../variables'
import { BASE_PATH } from '../variables'
import { Configuration } from '../configuration'

@Injectable({
Expand Down
1 change: 1 addition & 0 deletions libs/data-access/gn4/src/openapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './model/models'
export * from './variables'
export * from './configuration'
export * from './api.module'
export * from '../custom-api/thesaurus.api.service'
16 changes: 15 additions & 1 deletion libs/feature/search/src/lib/utils/service/fields.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { TestBed } from '@angular/core/testing'
import { FieldsService } from './fields.service'
import { EMPTY, lastValueFrom, of } from 'rxjs'
import { ToolsApiService } from '@geonetwork-ui/data-access/gn4'
import {
ThesaurusApiService,
ToolsApiService,
} from '@geonetwork-ui/data-access/gn4'
import { TranslateModule } from '@ngx-translate/core'
import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface'
import { RecordsRepositoryInterface } from '@geonetwork-ui/common/domain/repository/records-repository.interface'
Expand All @@ -17,6 +20,11 @@ class ElasticsearchServiceMock {
class ToolsApiServiceMock {
getTranslationsPackage1 = jest.fn(() => EMPTY)
}

class ThesaurusApiServiceMock {
getTranslationsFromThesaurus = jest.fn(() => of([]))
}

class OrganisationsServiceMock {
organisations$ = of([{ name: 'orgA', recordCount: 10 }])
getOrgsFromFilters = jest.fn(() => of([{ name: 'orgB' }]))
Expand Down Expand Up @@ -50,6 +58,10 @@ describe('FieldsService', () => {
provide: OrganizationsServiceInterface,
useClass: OrganisationsServiceMock,
},
{
provide: ThesaurusApiService,
useClass: ThesaurusApiServiceMock,
},
],
})
})
Expand Down Expand Up @@ -78,6 +90,7 @@ describe('FieldsService', () => {
'q',
'license',
'owner',
'contact',
])
})
})
Expand Down Expand Up @@ -146,6 +159,7 @@ describe('FieldsService', () => {
})
it('calls the search api', () => {
expect(values).toEqual({
contact: [],
documentStandard: [],
format: ['ascii', 'png'],
inspireKeyword: [],
Expand Down
15 changes: 12 additions & 3 deletions libs/feature/search/src/lib/utils/service/fields.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Injectable, Injector } from '@angular/core'
import {
AbstractSearchField,
GnUiTranslationSearchField,
FieldValue,
FullTextSearchField,
GnUiTranslationSearchField,
IsSpatialSearchField,
LicenseSearchField,
OrganizationSearchField,
OwnerSearchField,
SimpleSearchField,
ThesaurusTranslationSearchField,
TranslatedSearchField,
} from './fields'
import { forkJoin, Observable, of } from 'rxjs'
import { map } from 'rxjs/operators'
Expand All @@ -28,6 +30,7 @@ marker('search.filters.representationType')
marker('search.filters.resourceType')
marker('search.filters.standard')
marker('search.filters.topic')
marker('search.filters.contact')

@Injectable({
providedIn: 'root',
Expand All @@ -52,8 +55,9 @@ export class FieldsService {
this.injector
),
topic: new GnUiTranslationSearchField('cl_topic.key', 'asc', this.injector),
inspireKeyword: new SimpleSearchField(
'th_httpinspireeceuropaeutheme-theme_tree.default',
inspireKeyword: new ThesaurusTranslationSearchField(
'th_httpinspireeceuropaeutheme-theme.link',
'external.theme.httpinspireeceuropaeutheme-theme',
'asc',
this.injector
),
Expand All @@ -66,6 +70,11 @@ export class FieldsService {
q: new FullTextSearchField(),
license: new LicenseSearchField(this.injector),
owner: new OwnerSearchField(this.injector),
contact: new TranslatedSearchField(
'contactForResource.organisationObject.default',
'asc',
this.injector
),
} as Record<string, AbstractSearchField>

get supportedFields() {
Expand Down
Loading
Loading