Commit b02335cd authored by Viacheslav Pavlov's avatar Viacheslav Pavlov Committed by Matija Obreza

Genesys Catalog code integrated

parent 432dc205
This diff is collapsed.
// constants
import { ADD_TO_EDIT_LIST, REMOVE_FROM_EDIT_LIST, RECEIVE_IS_EDIT_MODE, SELECT_ALL, UNSELECT_ALL } from 'constants/dashboard';
// Models
import Dataset from 'model/catalog/Dataset';
import Descriptor from 'model/catalog/Descriptor';
import DescriptorList from 'model/catalog/DescriptorList';
export const setEditMode = (payload: boolean) => (dispatch) => {
dispatch({ type: RECEIVE_IS_EDIT_MODE, payload });
};
export const selectAll = (tab: string) => (dispatch, getState) => {
let payload;
switch (tab) {
case 'descriptorlists':
payload = getState().descriptorList.dashboard.paged.content.map((item) => item.uuid);
break;
case 'descriptors':
payload = getState().descriptors.dashboard.paged.content.map((item) => item.uuid);
break;
case 'datasets':
default:
payload = getState().datasets.dashboard.paged.content.map((item) => item.uuid);
}
return dispatch({
type: SELECT_ALL,
payload,
});
};
export const unselectAll = () => ({
type: UNSELECT_ALL,
});
const addToList = (payload: Dataset | Descriptor | DescriptorList) => (dispatch) => {
dispatch({ type: ADD_TO_EDIT_LIST, payload: payload.uuid });
};
const removeFromList = (payload: Dataset | Descriptor | DescriptorList) => (dispatch) => {
dispatch({ type: REMOVE_FROM_EDIT_LIST, payload: payload.uuid });
};
export const onPageChange = () => (dispatch) => {
dispatch(setEditMode(false));
dispatch(unselectAll());
};
export const addToEditList = (item: Dataset | Descriptor | DescriptorList) => (dispatch, getState) => {
const list = getState().dashboard.selected;
if (!list.includes(item)) {
dispatch(addToList(item));
}
};
export const removeFromEditList = (item: Dataset | Descriptor | DescriptorList) => (dispatch, getState) => {
const list = getState().dashboard.selected;
if (list.includes(item)) {
dispatch(removeFromList(item));
}
};
/**
* Publish all items that are in dashboard.toEditList
* @param publishOne: (uuid: string) => Promise<any> action to publish one item
*/
export const publishAll = (publishOne) => (dispatch, getState) => {
const toPublishItems = getState().dashboard.selected;
toPublishItems.map((item) => {
publishOne(item);
dispatch(removeFromList(item));
});
dispatch(unselectAll());
};
/**
* Approve all items that are in dashboard.toEditList
* @param approveOne: (uuid: string) => Promise<any> action to approve one item
*/
export const approveAll = (approveOne) => (dispatch, getState) => {
const toApproveItems = getState().dashboard.selected;
toApproveItems.map((item) => {
approveOne(item);
dispatch(removeFromList(item));
});
dispatch(unselectAll());
};
/**
* Unpublish all items that are in dashboard.toEditList
* @param unPublishOne: (uuid: string) => Promise<any> action to unpublish one item
*/
export const unpublishAll = (unPublishOne) => (dispatch, getState) => {
const toUnpublishItems = getState().dashboard.selected;
toUnpublishItems.map((item) => {
unPublishOne(item);
dispatch(removeFromList(item));
});
dispatch(unselectAll());
};
/**
* Delete all items that are in dashboard.toEditList
* @param deleteOne: (uuid: string) => Promise<any> action to delete one item
*/
export const deleteAll = (deleteOne) => (dispatch, getState) => {
const toDeleteItems = getState().dashboard.selected;
toDeleteItems.map((item) => {
deleteOne(item);
dispatch(removeFromList(item));
});
dispatch(unselectAll());
};
import { ADD_UPDATE_DESCRIPTOR_FILTER } from 'constants/filter';
import IDescriptorFilter from 'model/catalog/DescriptorFilter';
function updateDescriptorFilterModel(filter: IDescriptorFilter) {
return (dispatch, getState) => {
return dispatch(updateDescriptor(filter));
};
}
function updateDescriptor(filter: IDescriptorFilter) {
return {
type: ADD_UPDATE_DESCRIPTOR_FILTER,
payload: {
filter,
},
};
}
export { updateDescriptorFilterModel };
import SearchService from 'service/catalog/SearchService';
import DescriptorService from 'service/catalog/DescriptorService';
import DatasetService from 'service/catalog/DatasetService';
import DescriptorListService from 'service/catalog/DescriptorListService';
import DescriptorList from 'model/catalog/DescriptorList';
import Descriptor from 'model/catalog/Descriptor';
import Page from 'model/Page';
import Dataset from 'model/catalog/Dataset';
import {
SEARCH_DATASET_PAGE,
SEARCH_DESCRIPTOR_PAGE,
SEARCH_DESCRIPTOR_LIST_PAGE,
NEW_SEARCH,
SEARCH_DATASET_SUGGESTIONS,
} from 'constants/search';
import { log } from 'utilities/debug';
const search = (search: string) => ({
type: NEW_SEARCH,
payload: { search },
});
const searchDatasetPage = (paged: Page<Dataset>) => ({
type: SEARCH_DATASET_PAGE,
payload: { paged },
});
const searchDescriptorPage = (paged: Page<Descriptor>) => ({
type: SEARCH_DESCRIPTOR_PAGE,
payload: { paged },
});
const searchDescriptorListPage = (paged: Page<DescriptorList>) => ({
type: SEARCH_DESCRIPTOR_LIST_PAGE,
payload: { paged },
});
const searchDatasetsSuggestions = (suggestions: any) => ({
type: SEARCH_DATASET_SUGGESTIONS,
payload: suggestions,
});
export function datasetSuggestions(searchQuery, filter?) {
return (dispatch, getState) => {
if (searchQuery && searchQuery.trim() !== '') {
return SearchService.datasets(searchQuery, filter)
.then((data) => {
return dispatch(searchDatasetsSuggestions(data));
})
.catch((error) => {
log('Error', error);
});
} else {
log('No search query for datasets');
return null;
}
};
}
export function searchDatasets(page?, results?, sortBy?: string[], filter?, order?) {
return (dispatch, getState) => {
dispatch(search(filter._text));
return DatasetService.datasetList(filter, { page, size: results, properties: sortBy, direction: order })
.then((paged) => {
return dispatch(searchDatasetPage(paged));
})
.catch((error) => {
log('Error', error);
});
};
}
export function searchDescriptors(page?, results?, sortBy?, filter?, order?) {
return (dispatch, getState) => {
dispatch(search(filter._text));
return DescriptorService.listDescriptors(filter, { page, size: results, properties: sortBy, direction: order })
.then((paged) => {
return dispatch(searchDescriptorPage(paged));
})
.catch((error) => {
log('Error', error);
});
};
}
export function searchDescriptorLists(page?, results?, sortBy?: string[], filter?, order?) {
return (dispatch, getState) => {
dispatch(search(filter._text));
return DescriptorListService.listDescriptorLists(filter, { page, size: results, properties: sortBy, direction: order })
.then((paged) => {
return dispatch(searchDescriptorListPage(paged));
})
.catch((error) => {
log('Error', error);
});
};
}
import * as _ from 'lodash';
import Partner from 'model/genesys/Partner';
import DescriptorList from 'model/catalog/DescriptorList';
import { RECEIVE_UUID_LABELS } from 'constants/uuidDecoder';
const receiveUuidLabels = (labels) => ({
type: RECEIVE_UUID_LABELS,
payload: labels,
});
export const loadPartnerNames = (partners: Partner[]) => (dispatch, getState) => {
const labels = _.isEmpty(getState().uuidDecoder.labels) ? new Map<string, string>() : new Map<string, string>(getState().uuidDecoder.labels);
partners.forEach((partner) => {
labels.set(partner.uuid, partner.shortName);
});
return dispatch(receiveUuidLabels(labels));
};
export const loadDescriptorListTitles = (lists: DescriptorList[]) => (dispatch, getState) => {
const labels = _.isEmpty(getState().uuidDecoder.labels) ? new Map<string, string>() : new Map<string, string>(getState().uuidDecoder.labels);
lists.forEach((list) => {
labels.set(list.uuid, list.title);
});
return dispatch(receiveUuidLabels(labels));
};
export const DASHBOARD_FILTERFORM = 'Form/DASHBOARD_FILTERFORM';
export const RECEIVE_IS_EDIT_MODE = 'dashboard/RECEIVE_IS_EDIT_MODE';
export const ADD_TO_EDIT_LIST = 'dashboard/ADD_TO_EDIT_LIST';
export const REMOVE_FROM_EDIT_LIST = 'dashboard/REMOVE_FROM_EDIT_LIST';
export const SELECT_ALL = 'dashboard/SELECT_ALL';
export const UNSELECT_ALL = 'dashboard/UNSELECT_ALL';
export const ADD_UPDATE_PARTNER_FILTER = 'App/ADD_UPDATE_PARTNER_FILTER';
export const ADD_UPDATE_DATASET_FILTER = 'App/ADD_UPDATE_DATASET_FILTER';
export const ADD_UPDATE_DESCRIPTOR_FILTER = 'App/ADD_UPDATE_DESCRIPTOR_FILTER';
export const DESCRIPTOR_FILTER_FORM = 'DESCRIPTOR_FILTER_FORM';
export const DATASET_FILTER_FORM = 'DATASET_FILTER_FORM';
export const PARTNER_FILTER_FORM = 'PARTNER_FILTER_FORM';
export const NEW_SEARCH = 'App/NEW_SEARCH';
export const SEARCH_DATASET_PAGE = 'App/SEARCH_DATASET_PAGE';
export const SEARCH_DESCRIPTOR_PAGE = 'App/SEARCH_DESCRIPTOR_PAGE';
export const SEARCH_DESCRIPTOR_LIST_PAGE = 'App/SEARCH_DESCRIPTOR_LIST_PAGE';
export const SEARCH_DATASET_SUGGESTIONS = 'App/SEARCH_DATASET_SUGGESTIONS';
export const SEARCHSUGGESTIONS_FORM = 'Form/SEARCH_SUGGESTIONS';
export const RECEIVE_UUID_LABELS = 'uuidDecoder/RECEIVE_UUID_LABELS';
import { push } from 'react-router-redux';
// Actions
import { addFilterCode } from 'actions/filterCode';
import navigateTo from 'actions/navigation';
// Constants
import { DASHBOARD_REMOVE_DATASET, DASHBOARD_RECEIVE_DATASET_PAGE, CREATE_DATASET, DASHBOARD_APPEND_DATASET_PAGE, RECEIVE_DATASET } from 'datasets/constants';
// Models
import Dataset from 'model/catalog/Dataset';
import { PublishState } from 'model/common.model';
import Page from 'model/Page';
import FilteredPage from 'model/FilteredPage';
// Service
import DatasetService from 'service/catalog/DatasetService';
// Utility
import { log } from 'utilities/debug';
import { dereferenceReferences } from 'utilities';
const removeDataset = (dataset: Dataset) => ({
type: DASHBOARD_REMOVE_DATASET, payload: dataset,
});
const receiveDataset = (dataset: Dataset) => ({
type: RECEIVE_DATASET, payload: dataset,
});
const appendDatasetPage = (paged: Page<Dataset>) => ({
type: DASHBOARD_APPEND_DATASET_PAGE,
payload: { paged },
});
const receiveDatasetPage = (paged: Page<Dataset>) => ({
type: DASHBOARD_RECEIVE_DATASET_PAGE,
payload: { paged },
});
const createDataset = () => (dispatch) => {
dispatch({ type: CREATE_DATASET });
return dispatch(push(`/dashboard/datasets/edit`));
};
export { createDataset };
const loadMoreDatasets = (paged?: FilteredPage<Dataset>) => (dispatch, getState) => {
return DatasetService.myDatasets(paged ? paged.filterCode : '', Page.nextPage(paged))
.then((paged) => {
dereferenceReferences(paged.content, 'owner');
if (paged.number === 0) {
dispatch(receiveDatasetPage(paged));
} else {
dispatch(appendDatasetPage(paged));
}
dispatch(updateRoute(paged));
return dispatch(addFilterCode(paged.filterCode, paged.filter));
})
.catch((error) => {
log('Error', error);
});
};
export const updateRoute = (paged: FilteredPage<Dataset>) => (dispatch) => {
const qs = {
s: paged.sort[0].property === Dataset.DEFAULT_SORT.property ? undefined : paged.sort[0].property,
d: paged.sort[0].direction === Dataset.DEFAULT_SORT.direction ? undefined : paged.sort[0].direction,
};
dispatch(navigateTo(paged.filterCode ? `/dashboard/datasets/${paged.filterCode}` : '/dashboard/datasets', qs));
};
export { loadMoreDatasets };
const getOneFromStateByUUID = (uuid: string, state): Dataset => {
return state.datasets.dashboard.paged.content.find((dataset) => dataset.uuid === uuid);
};
export const loadDataset = (uuid: string) => (dispatch) => {
return DatasetService.getDataset(uuid)
.then((dataset) => {
dispatch(receiveDataset(dataset));
}).catch((error) => {
console.log(`API error`, error);
dispatch(receiveDataset(null));
});
};
function publishDataset(datasetUuid: string) {
return (dispatch, getState) => {
const dataset = dispatch(getOneFromStateByUUID(datasetUuid, getState()));
return dataset.state === PublishState.DRAFT &&
DatasetService.reviewDataset(dataset.uuid, dataset.version)
.then((dataset) => dispatch(receiveDataset(dataset)))
.catch((error) => {
log('Error', error);
});
};
}
function unpublishDataset(datasetUuid: string) {
return (dispatch, getState) => {
const dataset = dispatch(getOneFromStateByUUID(datasetUuid, getState()));
return dataset.state !== PublishState.DRAFT &&
DatasetService.rejectDataset(dataset.uuid, dataset.version)
.then((dataset) => dispatch(receiveDataset(dataset)))
.catch((error) => {
log('Error', error);
});
};
}
function approveDataset(datasetUuid: string) {
return (dispatch, getState) => {
const dataset = dispatch(getOneFromStateByUUID(datasetUuid, getState()));
return dataset.state === PublishState.REVIEWING &&
DatasetService.approveDataset(dataset.uuid, dataset.version)
.then((dataset) => dispatch(receiveDataset(dataset)))
.catch((error) => {
log('Error', error);
});
};
}
function deleteDataset(datasetUuid: string) {
return (dispatch, getState) => {
const dataset = dispatch(getOneFromStateByUUID(datasetUuid, getState()));
return DatasetService.deleteDataset(dataset.uuid, dataset.version)
.then((deleted) => {
dispatch(removeDataset(deleted));
return deleted;
})
.catch((error) => {
log('Delete error', error);
});
};
}
// Dashboard action section exports
export { publishDataset, approveDataset, unpublishDataset, deleteDataset };
import { push } from 'react-router-redux';
import * as _ from 'lodash';
// Actions
import { navigateTo } from 'actions/navigation';
// Constants
import { ADD_CREATOR_TO_DATASET, ADD_LOCATION, RECEIVE_LOCATION, REMOVE_CREATOR_FROM_DATASET, REMOVE_LOCATION, UPDATE_DATASET_CREATOR, RECEIVE_DATASET, DASHBOARD_REMOVE_DATASET } from 'datasets/constants';
// Models
import Dataset from 'model/catalog/Dataset';
import { AccessionRef } from 'model/accession/AccessionRef';
import RepositoryFile from 'model/repository/RepositoryFile';
import DatasetCreator from 'model/catalog/DatasetCreator';
import DatasetLocation from 'model/catalog/DatasetLocation';
// Service
import DatasetService from 'service/catalog/DatasetService';
// Utility
import { log } from 'utilities/debug';
// UI
import steps from 'datasets/ui/dashboard/dataset-stepper/steps';
const removeDataset = (dataset: Dataset) => ({
type: DASHBOARD_REMOVE_DATASET, payload: dataset,
});
const receiveDataset = (dataset: Dataset) => ({
type: RECEIVE_DATASET, payload: dataset,
});
function showDataset(uuid: string) {
return (dispatch) => {
dispatch(push(`/datasets/${uuid}`));
};
}
export const createDataset = () => (dispatch) => {
return dispatch(receiveDataset(new Dataset()));
};
// Review step
function rejectDataset(dataset: Dataset, needToRedirect: boolean = true) {
return (dispatch, getState) => {
return DatasetService.rejectDataset(dataset.uuid, dataset.version)
.then((saved) => {
dispatch(receiveDataset(saved));
if (needToRedirect) {
dispatch(navigateTo(`/dashboard/datasets/${saved.uuid}/edit`));
}
}).catch((error) => {
log('Error', error);
});
};
}
function approveDataset(dataset: Dataset) {
return (dispatch, getState) => {
return DatasetService.approveDataset(dataset.uuid, dataset.version)
.then((saved) => {
dispatch(receiveDataset(saved));
}).catch((error) => {
log('Error', error);
});
};
}
function publishDataset(dataset: Dataset, needToRedirect: boolean = false) {