Commit 7827d113 authored by Matija Obreza's avatar Matija Obreza
Browse files

SortDirection as enum

- requires update in Services list methods for d parameter
- requires update in models for sort options
parent bcc1ae7f
...@@ -33,17 +33,22 @@ class Page<T> { ...@@ -33,17 +33,22 @@ class Page<T> {
} }
} }
export enum SortDirection {
ASC = 'ASC',
DESC = 'DESC',
}
export interface ISort { export interface ISort {
ascending: boolean; ascending?: boolean;
descending: boolean; descending?: boolean;
direction: string; direction: SortDirection;
property: string; property: string;
} }
export interface IPageRequest { export interface IPageRequest {
page?: number; // page number page?: number; // page number
size?: number; // page size size?: number; // page size
direction?: string; // direction direction?: SortDirection; // direction
properties?: string[]; // sort by properties properties?: string[]; // sort by properties
} }
......
...@@ -7,6 +7,7 @@ import Crop from 'model/genesys/Crop'; ...@@ -7,6 +7,7 @@ import Crop from 'model/genesys/Crop';
import FaoInstitute from 'model/genesys/FaoInstitute'; import FaoInstitute from 'model/genesys/FaoInstitute';
import PDCI from 'model/accession/PDCI'; import PDCI from 'model/accession/PDCI';
import Taxonomy2 from 'model/genesys/Taxonomy2'; import Taxonomy2 from 'model/genesys/Taxonomy2';
import { SortDirection } from 'model/Page';
/* /*
* Defined in Swagger as '#/definitions/Accession' * Defined in Swagger as '#/definitions/Accession'
...@@ -57,11 +58,11 @@ class Accession { ...@@ -57,11 +58,11 @@ class Accession {
public static DEFAULT_SORT = { public static DEFAULT_SORT = {
property: 'seqNo', property: 'seqNo',
direction: 'ASC', direction: SortDirection.ASC,
}; };
public static SORT_OPTIONS = { public static SORT_OPTIONS = {
seqNo: { label: 'Accession number', direction: 'ASC' }, seqNo: { label: 'Accession number', direction: SortDirection.ASC },
}; };
public static SAMPSTAT: { [key: number]: string; } = { public static SAMPSTAT: { [key: number]: string; } = {
......
import Country from 'model/geo/Country'; import Country from 'model/geo/Country';
import { SortDirection } from 'model/Page';
/* /*
* Defined in Swagger as '#/definitions/FaoInstitute' * Defined in Swagger as '#/definitions/FaoInstitute'
...@@ -28,7 +29,7 @@ class FaoInstitute { ...@@ -28,7 +29,7 @@ class FaoInstitute {
public static DEFAULT_SORT = { public static DEFAULT_SORT = {
property: 'code', property: 'code',
direction: 'ASC', direction: SortDirection.ASC,
}; };
public static SORT_OPTIONS = { public static SORT_OPTIONS = {
......
...@@ -7,6 +7,7 @@ import SubsetCreator from 'model/subset/SubsetCreator'; ...@@ -7,6 +7,7 @@ import SubsetCreator from 'model/subset/SubsetCreator';
import FaoInstitute from 'model/genesys/FaoInstitute'; import FaoInstitute from 'model/genesys/FaoInstitute';
import Crop from 'model/genesys/Crop'; import Crop from 'model/genesys/Crop';
import {AccessionRef} from 'model/accession/AccessionRef'; import {AccessionRef} from 'model/accession/AccessionRef';
import { SortDirection } from 'model/Page';
class Subset { class Subset {
public accessionCount: number; public accessionCount: number;
...@@ -33,7 +34,7 @@ class Subset { ...@@ -33,7 +34,7 @@ class Subset {
public static DEFAULT_SORT = { public static DEFAULT_SORT = {
property: 'title', property: 'title',
direction: 'ASC', direction: SortDirection.ASC,
}; };
public static SORT_OPTIONS = { public static SORT_OPTIONS = {
title: { label: 'Title', direction: 'ASC' }, title: { label: 'Title', direction: 'ASC' },
......
...@@ -67,7 +67,7 @@ export class UserService { ...@@ -67,7 +67,7 @@ export class UserService {
f: typeof filter === 'string' ? filter : undefined, f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined, p: page.page || undefined,
l: page.size || 100, l: page.size || 100,
d: page.direction && page.direction.length && page.direction || undefined, d: page.direction ? page.direction : undefined,
s: page.properties && page.properties.length && page.properties || undefined, s: page.properties && page.properties.length && page.properties || undefined,
}, {}); }, {});
const apiUrl = URL_LIST_USERS + (qs ? `?${qs}` : ''); const apiUrl = URL_LIST_USERS + (qs ? `?${qs}` : '');
......
...@@ -128,7 +128,7 @@ class AccessionService { ...@@ -128,7 +128,7 @@ class AccessionService {
f: typeof filter === 'string' ? filter : undefined, f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined, p: page.page || undefined,
l: page.size || 100, l: page.size || 100,
d: page.direction && page.direction.length && page.direction || Accession.DEFAULT_SORT.direction, d: page && page.direction ? page.direction : Accession.DEFAULT_SORT.direction,
s: page.properties || Accession.DEFAULT_SORT.property, s: page.properties || Accession.DEFAULT_SORT.property,
}, {}); }, {});
const apiUrl = URL_LIST + (qs ? `?${qs}` : ''); const apiUrl = URL_LIST + (qs ? `?${qs}` : '');
......
...@@ -26,12 +26,13 @@ class InstituteService { ...@@ -26,12 +26,13 @@ class InstituteService {
* @param s s * @param s s
*/ */
public static list(filter: string | FaoInstituteFilter, page: IPageRequest): Promise<FilteredPage<FaoInstitute>> { public static list(filter: string | FaoInstituteFilter, page: IPageRequest): Promise<FilteredPage<FaoInstitute>> {
console.log('Listing insts', filter, page);
const qs = QueryString.stringify({ const qs = QueryString.stringify({
f: typeof filter === 'string' ? filter : undefined, f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined, p: page.page || undefined,
l: page.size || undefined, l: page.size || undefined,
d: page.direction && page.direction.length && page.direction || FaoInstitute.DEFAULT_SORT.direction, d: page && page.direction ? page.direction : FaoInstitute.DEFAULT_SORT.direction,
s: page.properties || FaoInstitute.DEFAULT_SORT.property, s: page.properties || FaoInstitute.DEFAULT_SORT.property,
}, {}); }, {});
const apiUrl = URL_LIST + (qs ? `?${qs}` : ''); const apiUrl = URL_LIST + (qs ? `?${qs}` : '');
......
...@@ -112,7 +112,7 @@ class RequestService { ...@@ -112,7 +112,7 @@ class RequestService {
f: f || undefined, f: f || undefined,
p: page.page || undefined, p: page.page || undefined,
l: page.size || undefined, l: page.size || undefined,
d: page.direction && page.direction.length && page.direction || undefined, d: page.direction ? page.direction : undefined,
s: page.properties || undefined, s: page.properties || undefined,
}, {}); }, {});
const apiUrl = URL_LIST_INSTITUTE_REQUESTS.expand({instCode}) + (qs ? `?${qs}` : ''); const apiUrl = URL_LIST_INSTITUTE_REQUESTS.expand({instCode}) + (qs ? `?${qs}` : '');
...@@ -152,12 +152,12 @@ class RequestService { ...@@ -152,12 +152,12 @@ class RequestService {
* @param page undefined * @param page undefined
*/ */
public static list(filter: string | MaterialRequestFilter, page?: IPageRequest): Promise<FilteredPage<MaterialRequest>> { public static list(filter: string | MaterialRequestFilter, page?: IPageRequest): Promise<FilteredPage<MaterialRequest>> {
console.log(`Listing requests page=${page.page}`);
const qs = QueryString.stringify({ const qs = QueryString.stringify({
f: typeof filter === 'string' ? filter : undefined, f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined, p: page.page || undefined,
l: page.size || undefined, l: page.size || undefined,
d: page.direction && page.direction.length && page.direction || undefined, d: page.direction ? page.direction : undefined,
s: page.properties || undefined, s: page.properties || undefined,
}, {}); }, {});
const apiUrl = URL_LIST + (qs ? `?${qs}` : ''); const apiUrl = URL_LIST + (qs ? `?${qs}` : '');
......
...@@ -128,7 +128,7 @@ class SubsetService { ...@@ -128,7 +128,7 @@ class SubsetService {
f: typeof filter === 'string' ? filter : undefined, f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined, p: page.page || undefined,
l: page.size || undefined, l: page.size || undefined,
d: page.direction && page.direction.length && page.direction || undefined, d: page.direction && page.direction || undefined,
s: page.properties || undefined, s: page.properties || undefined,
}, {}); }, {});
const apiUrl = URL_LIST + (qs ? `?${qs}` : ''); const apiUrl = URL_LIST + (qs ? `?${qs}` : '');
...@@ -154,7 +154,7 @@ class SubsetService { ...@@ -154,7 +154,7 @@ class SubsetService {
f: typeof filter === 'string' ? filter : undefined, f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined, p: page.page || undefined,
l: page.size || undefined, l: page.size || undefined,
d: page.direction && page.direction.length && page.direction || undefined, d: page.direction ? page.direction : undefined,
s: page.properties || undefined, s: page.properties || undefined,
}, {}); }, {});
const apiUrl = URL_MY_SUBSETS + (qs ? `?${qs}` : ''); const apiUrl = URL_MY_SUBSETS + (qs ? `?${qs}` : '');
...@@ -336,7 +336,7 @@ class SubsetService { ...@@ -336,7 +336,7 @@ class SubsetService {
const qs = QueryString.stringify({ const qs = QueryString.stringify({
p: page.page || undefined, p: page.page || undefined,
l: page.size || undefined, l: page.size || undefined,
d: page.direction && page.direction.length && page.direction || undefined, d: page.direction ? page.direction : undefined,
s: page.properties || undefined, s: page.properties || undefined,
}, {}); }, {});
const apiUrl = URL_LIST_SUBSET_CREATORS.expand({UUID}) + (qs ? `?${qs}` : ''); const apiUrl = URL_LIST_SUBSET_CREATORS.expand({UUID}) + (qs ? `?${qs}` : '');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment