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> {
}
}
export enum SortDirection {
ASC = 'ASC',
DESC = 'DESC',
}
export interface ISort {
ascending: boolean;
descending: boolean;
direction: string;
ascending?: boolean;
descending?: boolean;
direction: SortDirection;
property: string;
}
export interface IPageRequest {
page?: number; // page number
size?: number; // page size
direction?: string; // direction
direction?: SortDirection; // direction
properties?: string[]; // sort by properties
}
......
......@@ -7,6 +7,7 @@ import Crop from 'model/genesys/Crop';
import FaoInstitute from 'model/genesys/FaoInstitute';
import PDCI from 'model/accession/PDCI';
import Taxonomy2 from 'model/genesys/Taxonomy2';
import { SortDirection } from 'model/Page';
/*
* Defined in Swagger as '#/definitions/Accession'
......@@ -57,11 +58,11 @@ class Accession {
public static DEFAULT_SORT = {
property: 'seqNo',
direction: 'ASC',
direction: SortDirection.ASC,
};
public static SORT_OPTIONS = {
seqNo: { label: 'Accession number', direction: 'ASC' },
seqNo: { label: 'Accession number', direction: SortDirection.ASC },
};
public static SAMPSTAT: { [key: number]: string; } = {
......
import Country from 'model/geo/Country';
import { SortDirection } from 'model/Page';
/*
* Defined in Swagger as '#/definitions/FaoInstitute'
......@@ -28,7 +29,7 @@ class FaoInstitute {
public static DEFAULT_SORT = {
property: 'code',
direction: 'ASC',
direction: SortDirection.ASC,
};
public static SORT_OPTIONS = {
......
......@@ -7,6 +7,7 @@ import SubsetCreator from 'model/subset/SubsetCreator';
import FaoInstitute from 'model/genesys/FaoInstitute';
import Crop from 'model/genesys/Crop';
import {AccessionRef} from 'model/accession/AccessionRef';
import { SortDirection } from 'model/Page';
class Subset {
public accessionCount: number;
......@@ -33,7 +34,7 @@ class Subset {
public static DEFAULT_SORT = {
property: 'title',
direction: 'ASC',
direction: SortDirection.ASC,
};
public static SORT_OPTIONS = {
title: { label: 'Title', direction: 'ASC' },
......
......@@ -67,7 +67,7 @@ export class UserService {
f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined,
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,
}, {});
const apiUrl = URL_LIST_USERS + (qs ? `?${qs}` : '');
......
......@@ -128,7 +128,7 @@ class AccessionService {
f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined,
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,
}, {});
const apiUrl = URL_LIST + (qs ? `?${qs}` : '');
......
......@@ -26,12 +26,13 @@ class InstituteService {
* @param s s
*/
public static list(filter: string | FaoInstituteFilter, page: IPageRequest): Promise<FilteredPage<FaoInstitute>> {
console.log('Listing insts', filter, page);
const qs = QueryString.stringify({
f: typeof filter === 'string' ? filter : undefined,
p: page.page || 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,
}, {});
const apiUrl = URL_LIST + (qs ? `?${qs}` : '');
......
......@@ -112,7 +112,7 @@ class RequestService {
f: f || undefined,
p: page.page || undefined,
l: page.size || undefined,
d: page.direction && page.direction.length && page.direction || undefined,
d: page.direction ? page.direction : undefined,
s: page.properties || undefined,
}, {});
const apiUrl = URL_LIST_INSTITUTE_REQUESTS.expand({instCode}) + (qs ? `?${qs}` : '');
......@@ -152,12 +152,12 @@ class RequestService {
* @param page undefined
*/
public static list(filter: string | MaterialRequestFilter, page?: IPageRequest): Promise<FilteredPage<MaterialRequest>> {
console.log(`Listing requests page=${page.page}`);
const qs = QueryString.stringify({
f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined,
l: page.size || undefined,
d: page.direction && page.direction.length && page.direction || undefined,
d: page.direction ? page.direction : undefined,
s: page.properties || undefined,
}, {});
const apiUrl = URL_LIST + (qs ? `?${qs}` : '');
......
......@@ -128,7 +128,7 @@ class SubsetService {
f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined,
l: page.size || undefined,
d: page.direction && page.direction.length && page.direction || undefined,
d: page.direction && page.direction || undefined,
s: page.properties || undefined,
}, {});
const apiUrl = URL_LIST + (qs ? `?${qs}` : '');
......@@ -154,7 +154,7 @@ class SubsetService {
f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined,
l: page.size || undefined,
d: page.direction && page.direction.length && page.direction || undefined,
d: page.direction ? page.direction : undefined,
s: page.properties || undefined,
}, {});
const apiUrl = URL_MY_SUBSETS + (qs ? `?${qs}` : '');
......@@ -336,7 +336,7 @@ class SubsetService {
const qs = QueryString.stringify({
p: page.page || undefined,
l: page.size || undefined,
d: page.direction && page.direction.length && page.direction || undefined,
d: page.direction ? page.direction : undefined,
s: page.properties || undefined,
}, {});
const apiUrl = URL_LIST_SUBSET_CREATORS.expand({UUID}) + (qs ? `?${qs}` : '');
......
Markdown is supported
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