Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion projects/iucn/src/app/iucn-shared/service/taxon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class TaxonService {
return ObservableOf(this.treeCache[lang]);
}
if (!this.treeRequest[lang]) {
this.treeRequest[lang] = this.redList.redListTaxonGroupsGetTree(lang).pipe(
this.treeRequest[lang] = this.redList.redListTaxonGroupsGetTree().pipe(
map(data => data.results),
share(),
tap(data => this.treeCache[lang] = data),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ export class InformalGroupSelectComponent implements OnInit, OnDestroy, OnChange
this.selectedInformalGroup = undefined;

if (!this.id) {
this.informalTaxonService.informalTaxonGroupFindRoots(this.translate.getCurrentLang())
this.informalTaxonService.informalTaxonGroupFindRoots()
.subscribe(data => this.informalGroups = data.results);
return;
}

combineLatest(
this.informalTaxonService.informalTaxonGroupGetChildren(this.id, this.translate.getCurrentLang()),
this.informalTaxonService.informalTaxonGroupFindById(this.id, this.translate.getCurrentLang())
this.informalTaxonService.informalTaxonGroupGetChildren(this.id),
this.informalTaxonService.informalTaxonGroupFindById(this.id)
).subscribe(data => {
this.informalGroups = data[0].results;
this.selectedInformalGroup = data[1];
});

this.informalTaxonService.informalTaxonGroupGetParent(this.id, this.translate.getCurrentLang())
this.informalTaxonService.informalTaxonGroupGetParent(this.id)
.subscribe(data => this.parentGroup = data, () => {});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,27 @@ export abstract class ExtendedGroupSelectComponent<T extends RedListTaxonGroup|I
) {}

ngOnInit() {
const lang = this.translate.getCurrentLang();
this.groupsTree$ = this.initGroupTree(lang).pipe(shareReplay(1));
this.groups$ = this.initSelectionGroups(lang, this.includedOptions, this.excludedOptions);
this.groupsTree$ = this.initGroupTree().pipe(shareReplay(1));
this.groups$ = this.initSelectionGroups(this.includedOptions, this.excludedOptions);
}

ngOnChanges() {
const [ includedOptions, excludedOptions ] = this.getOptions(this.query);
if (!Util.equalsArray(this.includedOptions, includedOptions) || !Util.equalsArray(this.excludedOptions, excludedOptions)) {
this.includedOptions = includedOptions;
this.excludedOptions = excludedOptions;
this.groups$ = this.initSelectionGroups(this.translate.getCurrentLang(), this.includedOptions, this.excludedOptions);
this.groups$ = this.initSelectionGroups(this.includedOptions, this.excludedOptions);
}
}

abstract findByIds(groupIds: string[], lang: string): Observable<PagedResult<T>>;
abstract findByIds(groupIds: string[]): Observable<PagedResult<T>>;
abstract convertToInformalTaxonGroup(group: T): InformalTaxonGroup;
abstract getTree(lang: string): Observable<ArrayResult<T>>;
abstract getTree(): Observable<ArrayResult<T>>;
abstract getOptions(query: Record<string, any>): string[][];
abstract prepareEmit(includedOptions: string[], excludedOptions?: string[]): InformalGroupEvent;

initGroupTree(lang: string): Observable<TreeOptionsNode[]> {
return this.getTree(lang).pipe(
initGroupTree(): Observable<TreeOptionsNode[]> {
return this.getTree().pipe(
map((data) => data.results),
map((trees) => this.buildGroupTree(trees))
);
Expand Down Expand Up @@ -113,13 +112,13 @@ export abstract class ExtendedGroupSelectComponent<T extends RedListTaxonGroup|I
}
}

initSelectionGroups(lang: string, includedOptions: string[], excludedOptions: string[]): Observable<SelectedOption[]> {
initSelectionGroups(includedOptions: string[], excludedOptions: string[]): Observable<SelectedOption[]> {
const selectedGroups = includedOptions.concat(excludedOptions);

if (selectedGroups.length === 0) {
return of([]);
} else {
return this.findByIds(selectedGroups, lang).pipe(
return this.findByIds(selectedGroups).pipe(
map(data => data.results),
map(data => {
const toReturn: SelectedOption[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { TranslateService } from '@ngx-translate/core';
import { ExtendedGroupSelectComponent, InformalGroupEvent } from './extended-group-select.component';
import { RedListTaxonGroup } from '../../shared/model/RedListTaxonGroup';
import { InformalTaxonGroup } from '../../shared/model/InformalTaxonGroup';
import { PagedResult } from '../../shared/model/PagedResult';
import { RedListTaxonGroupApi } from '../../shared/api/RedListTaxonGroupApi';
import { ArrayResult } from '../../shared/model/ArrayResult';
import { PagedResult } from '../../shared/model/PagedResult';

export const IUCN_GROUP_SELECT_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
Expand Down Expand Up @@ -40,16 +41,16 @@ export class IucnExtendedGroupSelectComponent extends ExtendedGroupSelectCompone
return [(this.query as any).redListGroup || [], []];
}

findByIds(groupIds: string[], lang: string): Observable<PagedResult<RedListTaxonGroup>> {
return this.redListTaxonGroupApi.redListTaxonGroupsFind(lang, undefined, undefined, {idIn: groupIds});
findByIds(groupIds: string[]): Observable<PagedResult<RedListTaxonGroup>> {
return this.redListTaxonGroupApi.redListTaxonGroupsFind(undefined, undefined, groupIds);
}

convertToInformalTaxonGroup(group: RedListTaxonGroup): InformalTaxonGroup {
return {id: group.id, name: group.name, hasSubGroup: group.hasIucnSubGroup};
}

getTree(lang: any): Observable<PagedResult<RedListTaxonGroup>> {
return this.redListTaxonGroupApi.redListTaxonGroupsGetTree(lang);
getTree(): Observable<ArrayResult<RedListTaxonGroup>> {
return this.redListTaxonGroupApi.redListTaxonGroupsGetTree();
}

prepareEmit(includedOptions: string[], excludedOptions?: string[]): InformalGroupEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ export class ObservationExtendedGroupSelectComponent extends ExtendedGroupSelect
return [this.query?.informalTaxonGroupId || [], this.query.informalTaxonGroupIdNot || []];
}

findByIds(groupIds: string[], lang: string): Observable<PagedResult<RedListTaxonGroup>> {
return this.informalTaxonService.informalTaxonGroupFind(lang, undefined, undefined, groupIds);
findByIds(groupIds: string[]): Observable<PagedResult<RedListTaxonGroup>> {
return this.informalTaxonService.informalTaxonGroupFind(undefined, undefined, groupIds);
}

convertToInformalTaxonGroup(group: InformalTaxonGroup): InformalTaxonGroup {
return {...group};
}

getTree(lang: string): Observable<ArrayResult<InformalTaxonGroup>> {
return this.informalTaxonService.informalTaxonGroupGetTree(lang);
getTree(): Observable<ArrayResult<InformalTaxonGroup>> {
return this.informalTaxonService.informalTaxonGroupGetTree();
}

prepareEmit(includedOptions: string[], excludedOptions?: string[]): InformalGroupEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ export class SpecialInformalTaxonGroupsComponent implements OnInit {

constructor(
private cdr: ChangeDetectorRef,
private userService: UserService,
private mappingService: MappingService,
private informalTaxonApi: InformalTaxonGroupApi,
private translateService: TranslateService
) { }

ngOnInit() {
this.informalTaxonApi.informalTaxonGroupGetTree(this.translateService.getCurrentLang()).pipe(
this.informalTaxonApi.informalTaxonGroupGetTree().pipe(
map(results => results.results))
.subscribe(groups => {
const list = Array.isArray(groups) ? MappingService.informalTaxonGroupsToList(groups) : [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class GeneratorService {
ObservableForkJoin(
this.userService.user$.pipe(take(1)),
this.excelToolService.getNamedPlacesList(formID),
this.informalTaxonApi.informalTaxonGroupGetTree(this.translateService.getCurrentLang()).pipe(map(result => result.results))
this.informalTaxonApi.informalTaxonGroupGetTree().pipe(map(result => result.results))
).pipe(
map((data) => ({person: data[0], namedPlaces: data[1], informalTaxonGroups: data[2]}))
)
Expand Down
55 changes: 22 additions & 33 deletions projects/laji/src/app/shared/api/InformalTaxonGroupApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,38 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { PagedResult } from '../model/PagedResult';
import { HttpClient } from '@angular/common/http';
import * as Util from '../utils';
import { InformalTaxonGroup } from '../model/InformalTaxonGroup';
import { environment } from '../../../environments/environment';
import { ArrayResult } from '../model/ArrayResult';
import { LajiApiClientBService } from 'projects/laji-api-client-b/src/laji-api-client-b.service';
import { components } from 'projects/laji-api-client-b/generated/api.d';

export type InformalTaxonGroup = components['schemas']['store-informalTaxonGroup'];

@Injectable({providedIn: 'root'})
export class InformalTaxonGroupApi {
protected basePath = `${environment.apiBase}/informal-taxon-groups`;

constructor(protected http: HttpClient) {
}
constructor(
private api: LajiApiClientBService
) { }

/**
* Get all InformalTaxonGroups
*
* @param lang Language of fields that have multiple languages. Return english if asked language not found. If multi is selected fields will contain language objects
* @param page Page number
* @param pageSize Page size
* @param idIn Array of ids to search by
*/
public informalTaxonGroupFind(lang?: string, page?: string, pageSize?: string, idIn?: string[]): Observable<PagedResult<InformalTaxonGroup>> {
return this.http.get<PagedResult<InformalTaxonGroup>>(this.basePath, { params: Util.withNonNullableValues({ lang, page, pageSize, idIn }) });
public informalTaxonGroupFind(page?: number, pageSize?: number, idIn?: string[]): Observable<PagedResult<InformalTaxonGroup>> {
return this.api.get('/informal-taxon-groups', { query: { idIn: idIn?.join(','), page, pageSize }});
}

/**
* Find InformalTaxonGroup by id
*
* @param id
* @param lang Language of fields that have multiple languages. Return english if asked language not found. If multi is selected fields will contain language objects
*/
public informalTaxonGroupFindById(id: string, lang?: string): Observable<InformalTaxonGroup> {
public informalTaxonGroupFindById(id: string): Observable<InformalTaxonGroup> {
if (!id.length) {
throw new Error('Required parameter id was empty when calling informalTaxonGroupFindById.');
}
return this.http.get<InformalTaxonGroup>(`${this.basePath}/${id}`, {params: Util.withNonNullableValues({ lang })});
return this.api.get('/informal-taxon-groups/{id}', { path: { id }});
}

/**
Expand All @@ -69,52 +66,44 @@ export class InformalTaxonGroupApi {
* @param page Page number
* @param pageSize Page size
*/
public informalTaxonGroupFindRoots(lang?: string): Observable<ArrayResult<InformalTaxonGroup>> {
return this.http.get<ArrayResult<InformalTaxonGroup>>(`${this.basePath}/roots`, { params: Util.withNonNullableValues({ lang }) });
public informalTaxonGroupFindRoots(): Observable<ArrayResult<InformalTaxonGroup>> {
return this.api.get('/informal-taxon-groups/roots');
}

/**
* Get immediate children of the informal group
*
* @param id
* @param lang Language of fields that have multiple languages. Return english if asked language not found.
* @param page Page number
* @param pageSize Page size
*/
public informalTaxonGroupGetChildren(id: string, lang?: string): Observable<ArrayResult<InformalTaxonGroup>> {
return this.http.get<ArrayResult<InformalTaxonGroup>>(`${this.basePath}/${id}/children`, { params: Util.withNonNullableValues({ lang }) } );
public informalTaxonGroupGetChildren(id: string): Observable<ArrayResult<InformalTaxonGroup>> {
return this.api.get('/informal-taxon-groups/{id}/children', { path: { id }});
}

/**
* Get parent for a informal group
*
* @param id
* @param lang Language of fields that have multiple languages. Return english if asked language not found.
*/
public informalTaxonGroupGetParent(id: string, lang?: string): Observable<InformalTaxonGroup> {
return this.http.get<InformalTaxonGroup>(`${this.basePath}/${id}/parent`, { params: Util.withNonNullableValues({ lang })});
public informalTaxonGroupGetParent(id: string): Observable<InformalTaxonGroup> {
return this.api.get('/informal-taxon-groups/{id}/parent', { path: { id }});
}

/**
* Get full tree of informal groups with hasSubGroup extended
*
* @param lang Language of fields that have multiple languages. Return english if asked language not found.
* @param page Page number
* @param pageSize Page size
*/
public informalTaxonGroupGetTree(lang?: string): Observable<ArrayResult<InformalTaxonGroup>> {
return this.http.get<ArrayResult<InformalTaxonGroup>>(`${this.basePath}/tree`, { params: Util.withNonNullableValues({ lang }) });
public informalTaxonGroupGetTree(): Observable<ArrayResult<InformalTaxonGroup>> {
return this.api.get('/informal-taxon-groups/tree');
}

/**
* Get current groups with it&#39;s siblings
*
* @param id
* @param lang Language of fields that have multiple languages. Return english if asked language not found.
* @param page Page number
* @param pageSize Page size
*/
public informalTaxonGroupGetWithSiblings(id: string, lang?: string): Observable<ArrayResult<InformalTaxonGroup>> {
return this.http.get<ArrayResult<InformalTaxonGroup>>(`${this.basePath}/${id}/siblings`, { params: Util.withNonNullableValues({ lang }) });
public informalTaxonGroupGetWithSiblings(id: string): Observable<ArrayResult<InformalTaxonGroup>> {
return this.api.get('/informal-taxon-groups/{id}/siblings', { path: { id }});
}
}
Loading
Loading