Commit 637a033b authored by Matija Obreza's avatar Matija Obreza
Browse files

listXxxx methods accept filter object or filter code string

parent 57bb752c
......@@ -14,7 +14,6 @@ import {log} from 'utilities/debug';
import { CREATE_DATASET, RECEIVE_DATASET, RECEIVE_DATASET_PAGE, ADD_CREATOR_TO_DATASET, REMOVE_CREATOR_FROM_DATASET, UPDATE_DATASET_CREATOR, ADD_LOCATION, RECEIVE_LOCATION, REMOVE_LOCATION } from 'constants/datasets';
import {addFilterCode} from 'actions/filterCode';
import {cleanFilters} from 'utilities';
import steps from 'ui/pages/dataset/dataset-stepper/steps';
import { navigateTo } from 'actions/navigation';
import * as _ from 'lodash';
......@@ -44,13 +43,14 @@ export const applyDatasetFilters = (filters?: any) => (dispatch) => {
dispatch(listDatasetsRequest(undefined, undefined, undefined, filters));
};
function listMyDatasets(page?, results?, sortBy?, filter?, order?) {
function listMyDatasets(page?, results?, sortBy?, filter?: string | IDatasetFilter, order?) {
return (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.listMyDatasets(token, page, results, sortBy, filter, order)
.then((paged) => {
dispatch(receiveDatasetPage(paged, page, results, sortBy, filter, order));
dispatch(receiveDatasetPage(paged, page, results, sortBy, paged.filter, order));
return dispatch(addFilterCode(paged.filterCode, paged.filter));
})
.catch((error) => {
log('Error', error);
......@@ -89,8 +89,7 @@ function listDatasetsByCodeRequest(page?, results?, sortBy?, filterCode?, order?
return DatasetService.listDatasetsByCode(token, page, results, sortBy, filterCode, order)
.then((paged) => {
const filter = cleanFilters(paged.filter, ['published']);
dispatch(receiveDatasetPage(paged, page, results, sortBy, filter as IDatasetFilter, order));
dispatch(receiveDatasetPage(paged, page, results, sortBy, paged.filter, order));
return dispatch(addFilterCode(paged.filterCode, paged.filter));
})
.catch((error) => {
......
......@@ -54,7 +54,7 @@ export const loadDescriptorList = (uuid: string, success?: (d) => any, fail?: (e
};
// List current user's descriptor lists
export const listMyDescriptorLists = (page?, results?, sortBy?, filter?, order?) => (dispatch, getState) => {
export const listMyDescriptorLists = (page?, results?, sortBy?, filter?: string | IDescriptorListFilter, order?) => (dispatch, getState) => {
log('Loading my descriptor lists');
const token = getState().login.access_token;
......@@ -63,7 +63,8 @@ export const listMyDescriptorLists = (page?, results?, sortBy?, filter?, order?)
return DescriptorListService.listMyDescriptorLists(token, page, results, sortBy, filter, order)
// receive the current descriptor list
.then((descriptorLists) => {
return dispatch(receiveDescriptorLists(descriptorLists, page, results, sortBy, filter, order));
dispatch(receiveDescriptorLists(descriptorLists, page, results, sortBy, descriptorLists.filter, order));
return dispatch(addFilterCode(descriptorLists.filterCode, descriptorLists.filter));
}).catch((error) => {
log(`Error loading my descriptor lists`, error);
});
......
......@@ -125,7 +125,7 @@ export const deleteDescriptor = (descriptor: Descriptor) => (dispatch, getState)
});
};
export function listMyDescriptors(page?, results?, sortBy?, filter?, order?) {
export function listMyDescriptors(page?, results?, sortBy?, filter?: string | IDescriptorFilter, order?) {
return (dispatch, getState) => {
const token = getState().login.access_token;
......@@ -134,7 +134,8 @@ export function listMyDescriptors(page?, results?, sortBy?, filter?, order?) {
return DescriptorService.listMyDescriptors(token, page, results, sortBy, filter, order)
.then((paged) => {
dereferenceReferences(paged.content, 'owner', (o) => new Partner(o));
return dispatch(receiveDescriptorPage(paged, page, results, sortBy, filter, order));
dispatch(receiveDescriptorPage(paged, page, results, sortBy, paged.filter, order));
return dispatch(addFilterCode(paged.filterCode, paged.filter));
})
.catch((error) => {
log('Error', error);
......
import authenticatedRequest from 'utilities/requestUtils';
import { dereferenceReferences } from 'utilities';
import {log} from 'utilities/debug';
import { stringify } from 'query-string';
import { Page } from 'model/common.model';
import { Dataset, IDatasetFilter, AccessionIdentifier } from 'model/dataset.model';
......@@ -14,12 +15,19 @@ import {
export class DatasetService {
// List my datasets
public static listMyDatasets(token: string, page: number = 0, results: number = 10, sortBy: string = 'title', filter: IDatasetFilter = {}, order: string = 'ASC'): Promise<Page<Dataset>> {
public static listMyDatasets(token: string, page: number = 0, results: number = 10, sortBy: string = 'title', filter: string | IDatasetFilter = {}, order: string = 'ASC'): Promise<Page<Dataset>> {
const query = stringify({
p: page,
l: results,
d: order,
s: sortBy,
f: typeof filter === 'string' ? filter : null,
});
return authenticatedRequest(token, {
url: `${MY_DATASETS_LIST_URL}?p=${page}&l=${results}${order ? '&d=' + order : ''}${sortBy ? '&s=' + sortBy : ''}`,
url: `${MY_DATASETS_LIST_URL}?${query}`,
method: 'POST',
data: filter,
headers: {'Content-Type': 'application/json'},
data: typeof filter === 'string' ? null : filter,
})
.then(({ data }) => new Page<Dataset>(data, (d) => new Dataset(d)))
.then((paged) => {
......@@ -46,6 +54,7 @@ export class DatasetService {
}
// List published datasets by filter code
// TODO Remove
public static listDatasetsByCode(token: string, page: number = 0, results: number = 10, sortBy: string = 'title', filterCode: string, order: string = 'ASC'): Promise<Page<Dataset>> {
const code = filterCode ? `/${filterCode}` : '';
......
import authenticatedRequest from 'utilities/requestUtils';
import { dereferenceReferences } from 'utilities';
import {log} from 'utilities/debug';
import { stringify } from 'query-string';
import {
MY_LIST_DESCRIPTORSLISTS_URL, GET_DESCRIPTORLIST_URL, REMOVE_DESCRIPTORLIST_URL,
......@@ -16,16 +17,22 @@ import { Page } from 'model/common.model';
export class DescriptorListService {
// Lists my descriptor lists
public static listMyDescriptorLists(token: string, page: number = 0, results: number = 10, sortBy: string = 'lastModifiedDate', filter: IDescriptorListFilter = {}, order: string = 'ASC'): Promise<Page<DescriptorList>> {
const sortParam = sortBy ? `&s=${sortBy}` : '';
public static listMyDescriptorLists(token: string, page: number = 0, results: number = 10, sortBy: string = 'lastModifiedDate', filter: string | IDescriptorListFilter = {}, order: string = 'ASC'): Promise<Page<DescriptorList>> {
const query = stringify({
p: page,
l: results,
d: order,
s: sortBy,
f: typeof filter === 'string' ? filter : null,
});
// console.log('Query', query);
return authenticatedRequest(token, {
url: `${MY_LIST_DESCRIPTORSLISTS_URL}?p=${page}&l=${results}&d=${order}${sortParam}`,
url: `${MY_LIST_DESCRIPTORSLISTS_URL}?${query}`,
method: 'POST',
data: {
...filter,
},
headers: {'Content-Type': 'application/json'},
data: typeof filter === 'string' ? null : filter,
})
.then(({ data }) => new Page<DescriptorList>(data, (dl) => new DescriptorList(dl)))
.then((paged) => {
......@@ -54,6 +61,7 @@ export class DescriptorListService {
}
// Lists published descriptor lists by filter code
// TODO Remove
public static listDescriptorListsByCode(token: string, page: number = 0, results: number = 10, sortBy: string = 'title', filterCode: string, order: string = 'ASC'): Promise<Page<DescriptorList>> {
const sortParam = sortBy ? `&s=${sortBy}` : '';
const code = filterCode ? `/${filterCode}` : '';
......
import { dereferenceReferences } from 'utilities';
import authenticatedRequest from 'utilities/requestUtils';
import { log } from 'utilities/debug';
import { stringify } from 'query-string';
import {
MY_DESCRIPTORS_LIST_URL, LIST_DESCRIPTORS_URL, GET_DESCRIPTOR_URL, CREATE_DESCRIPTOR_URL, COPY_DESCRIPTOR_URL,
......@@ -25,12 +26,21 @@ import { Page } from 'model/common.model';
export class DescriptorService {
// Lists my descriptors
public static listMyDescriptors(token: string, page: number = 0, results: number = 10, sortBy?: string, filter: IDescriptorFilter = {}, order?: string): Promise<Page<Descriptor>> {
public static listMyDescriptors(token: string, page: number = 0, results: number = 10, sortBy?: string, filter: string | IDescriptorFilter = {}, order?: string): Promise<Page<Descriptor>> {
const query = stringify({
p: page,
l: results,
d: order,
s: sortBy,
f: typeof filter === 'string' ? filter : null,
});
// console.log('Query', query);
return authenticatedRequest(token, {
url: `${MY_DESCRIPTORS_LIST_URL}?p=${page}&l=${results}${order ? '&d=' + order : ''}${sortBy ? '&s=' + sortBy : ''}`,
url: `${MY_DESCRIPTORS_LIST_URL}?${query}`,
method: 'POST',
data: {
headers: {'Content-Type': 'application/json'},
data: typeof filter === 'string' ? null : {
...filter,
},
})
......@@ -59,6 +69,7 @@ export class DescriptorService {
}
// Lists published descriptors by filter code
// TODO Remove
public static listDescriptorsByCode(token: string, page: number = 0, results: number = 50, sortBy?: string, filterCode?: string, order?: string): Promise<Page<Descriptor>> {
const code = filterCode ? `/${filterCode}` : '';
......
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