return Promise.reject();
}
- async deleteFile(collectionUuid: string, filePath: string) {
- return this.webdavClient.delete(`/c=${collectionUuid}${filePath}`);
+ async deleteFiles(collectionUuid: string, filePaths: string[]) {
+ for (const path of filePaths) {
+ await this.webdavClient.delete(`/c=${collectionUuid}${path}`);
+ }
}
async uploadFiles(collectionUuid: string, files: File[], onProgress?: UploadProgress) {
import { ServiceRepository } from "~/services/services";
import { RootState } from "../../store";
import { snackbarActions } from "../../snackbar/snackbar-actions";
-import { dialogActions } from "../../dialog/dialog-actions";
-import { getNodeValue, getNodeDescendants } from "~/models/tree";
-import { CollectionPanelDirectory, CollectionPanelFile } from "./collection-panel-files-state";
+import { dialogActions } from '../../dialog/dialog-actions';
+import { getNodeValue } from "~/models/tree";
+import { filterCollectionFilesBySelection } from './collection-panel-files-state';
+import { startSubmit, initialize } from 'redux-form';
+import { loadProjectTreePickerProjects } from '../../../views-components/project-tree-picker/project-tree-picker';
export const collectionPanelFilesAction = unionize({
SET_COLLECTION_FILES: ofType<CollectionFilesTree>(),
export const removeCollectionFiles = (filePaths: string[]) =>
async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
- const { item } = getState().collectionPanel;
- if (item) {
+ const currentCollection = getState().collectionPanel.item;
+ if (currentCollection) {
dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...' }));
- const promises = filePaths.map(filePath => services.collectionService.deleteFile(item.uuid, filePath));
- await Promise.all(promises);
- dispatch<any>(loadCollectionFiles(item.uuid));
+ await services.collectionService.deleteFiles(currentCollection.uuid, filePaths);
+ dispatch<any>(loadCollectionFiles(currentCollection.uuid));
dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removed.', hideDuration: 2000 }));
}
};
export const removeCollectionsSelectedFiles = () =>
(dispatch: Dispatch, getState: () => RootState) => {
- const tree = getState().collectionPanelFiles;
- const allFiles = getNodeDescendants('')(tree)
- .map(id => getNodeValue(id)(tree))
- .filter(file => file !== undefined) as Array<CollectionPanelDirectory | CollectionPanelFile>;
-
- const selectedDirectories = allFiles.filter(file => file.selected && file.type === CollectionFileType.DIRECTORY);
- const selectedFiles = allFiles.filter(file => file.selected && !selectedDirectories.some(dir => dir.id === file.path));
- const paths = [...selectedDirectories, ...selectedFiles].map(file => file.id);
+ const paths = filterCollectionFilesBySelection(getState().collectionPanelFiles, true).map(file => file.id);
dispatch<any>(removeCollectionFiles(paths));
};
export const FILE_REMOVE_DIALOG = 'fileRemoveDialog';
+
export const openFileRemoveDialog = (filePath: string) =>
(dispatch: Dispatch, getState: () => RootState) => {
const file = getNodeValue(filePath)(getState().collectionPanelFiles);
};
export const MULTIPLE_FILES_REMOVE_DIALOG = 'multipleFilesRemoveDialog';
+
export const openMultipleFilesRemoveDialog = () =>
dialogActions.OPEN_DIALOG({
id: MULTIPLE_FILES_REMOVE_DIALOG,
confirmButtonLabel: 'Remove'
}
});
+
+export const COLLECTION_PARTIAL_COPY = 'COLLECTION_PARTIAL_COPY';
+
+export interface CollectionPartialCopyFormData {
+ name: string;
+ description: string;
+ projectUuid: string;
+}
+
+export const openCollectionPartialCopyDialog = () =>
+ (dispatch: Dispatch, getState: () => RootState) => {
+ const currentCollection = getState().collectionPanel.item;
+ if (currentCollection) {
+ const initialData = {
+ name: currentCollection.name,
+ description: currentCollection.description,
+ projectUuid: ''
+ };
+ dispatch(initialize(COLLECTION_PARTIAL_COPY, initialData));
+ dispatch<any>(loadProjectTreePickerProjects(''));
+ dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_COPY, data: {} }));
+ }
+ };
+
+export const doCollectionPartialCopy = ({ name, description, projectUuid }: CollectionPartialCopyFormData) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ dispatch(startSubmit(COLLECTION_PARTIAL_COPY));
+ const state = getState();
+ const currentCollection = state.collectionPanel.item;
+ if (currentCollection) {
+ const collection = await services.collectionService.get(currentCollection.uuid);
+ const collectionCopy = {
+ ...collection,
+ name,
+ description,
+ ownerUuid: projectUuid,
+ uuid: undefined
+ };
+ const newCollection = await services.collectionService.create(collectionCopy);
+ const paths = filterCollectionFilesBySelection(state.collectionPanelFiles, false).map(file => file.id);
+ await services.collectionService.deleteFiles(newCollection.uuid, paths);
+ dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_PARTIAL_COPY }));
+ dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'New collection created.', hideDuration: 2000 }));
+ }
+ };
+
//
// SPDX-License-Identifier: AGPL-3.0
-import { CollectionPanelFilesState, CollectionPanelFile, CollectionPanelDirectory, mapCollectionFileToCollectionPanelFile, mergeCollectionPanelFilesStates } from "./collection-panel-files-state";
+import { CollectionPanelFilesState, CollectionPanelFile, CollectionPanelDirectory, mapCollectionFileToCollectionPanelFile, mergeCollectionPanelFilesStates } from './collection-panel-files-state';
import { CollectionPanelFilesAction, collectionPanelFilesAction } from "./collection-panel-files-actions";
import { createTree, mapTreeValues, getNode, setNode, getNodeAncestors, getNodeDescendants, setNodeValueWith, mapTree } from "~/models/tree";
import { CollectionFileType } from "~/models/collection-file";
//
// SPDX-License-Identifier: AGPL-3.0
-import { Tree, TreeNode, mapTreeValues, getNodeValue } from '~/models/tree';
+import { Tree, TreeNode, mapTreeValues, getNodeValue, getNodeDescendants } from '~/models/tree';
import { CollectionFile, CollectionDirectory, CollectionFileType } from '~/models/collection-file';
export type CollectionPanelFilesState = Tree<CollectionPanelDirectory | CollectionPanelFile>;
: { ...value, selected: oldValue.selected }
: value;
})(newState);
-};
+};
+
+export const filterCollectionFilesBySelection = (tree: CollectionPanelFilesState, selected: boolean) => {
+ const allFiles = getNodeDescendants('')(tree)
+ .map(id => getNodeValue(id)(tree))
+ .filter(file => file !== undefined) as Array<CollectionPanelDirectory | CollectionPanelFile>;
+
+ const selectedDirectories = allFiles.filter(file => file.selected === selected && file.type === CollectionFileType.DIRECTORY);
+ const selectedFiles = allFiles.filter(file => file.selected === selected && !selectedDirectories.some(dir => dir.id === file.path));
+ return [...selectedDirectories, ...selectedFiles];
+};
//
// SPDX-License-Identifier: AGPL-3.0
-import { Dispatch, compose } from "redux";
-import { reduxForm, reset, startSubmit, stopSubmit } from "redux-form";
-import { withDialog } from "~/store/dialog/with-dialog";
-import { dialogActions } from "~/store/dialog/dialog-actions";
-import { loadProjectTreePickerProjects } from "../project-tree-picker/project-tree-picker";
-import { CollectionPartialCopyFormDialog } from "~/views-components/form-dialog/collection-form-dialog";
-
-export const COLLECTION_PARTIAL_COPY = 'COLLECTION_PARTIAL_COPY';
-
-export const openCollectionPartialCopyDialog = () =>
- (dispatch: Dispatch) => {
- dispatch(reset(COLLECTION_PARTIAL_COPY));
- dispatch<any>(loadProjectTreePickerProjects(''));
- dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_COPY, data: {} }));
- };
-
+import * as React from "react";
+import { compose } from "redux";
+import { reduxForm, InjectedFormProps } from 'redux-form';
+import { withDialog, WithDialogProps } from '~/store/dialog/with-dialog';
+import { CollectionPartialCopyFields } from '../form-dialog/collection-form-dialog';
+import { FormDialog } from '~/components/form-dialog/form-dialog';
+import { COLLECTION_PARTIAL_COPY, doCollectionPartialCopy, CollectionPartialCopyFormData } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions';
export const CollectionPartialCopyDialog = compose(
withDialog(COLLECTION_PARTIAL_COPY),
reduxForm({
form: COLLECTION_PARTIAL_COPY,
- onSubmit: (data, dispatch) => {
- dispatch(startSubmit(COLLECTION_PARTIAL_COPY));
- setTimeout(() => dispatch(stopSubmit(COLLECTION_PARTIAL_COPY, { name: 'Invalid name' })), 2000);
+ onSubmit: (data: CollectionPartialCopyFormData, dispatch) => {
+ dispatch(doCollectionPartialCopy(data));
}
- }))(CollectionPartialCopyFormDialog);
+ }))((props: WithDialogProps<string> & InjectedFormProps<CollectionPartialCopyFormData>) =>
+ <FormDialog
+ dialogTitle='Create a collection'
+ formFields={CollectionPartialCopyFields}
+ submitLabel='Create a collection'
+ {...props}
+ />);
import { ContextMenuActionSet } from "../context-menu-action-set";
import { collectionPanelFilesAction, openMultipleFilesRemoveDialog } from "~/store/collection-panel/collection-panel-files/collection-panel-files-actions";
-import { openCollectionPartialCopyDialog } from "~/views-components/collection-partial-copy-dialog/collection-partial-copy-dialog";
-
+import { openCollectionPartialCopyDialog } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions';
export const collectionFilesActionSet: ContextMenuActionSet = [[{
name: "Select all",
// SPDX-License-Identifier: AGPL-3.0
import * as React from "react";
-import { InjectedFormProps, Field, WrappedFieldProps } from "redux-form";
-import { WithDialogProps } from "~/store/dialog/with-dialog";
+import { Field, WrappedFieldProps } from "redux-form";
import { TextField } from "~/components/text-field/text-field";
import { COLLECTION_NAME_VALIDATION, COLLECTION_DESCRIPTION_VALIDATION, COLLECTION_PROJECT_VALIDATION } from "~/validators/validators";
import { ProjectTreePicker } from "../project-tree-picker/project-tree-picker";
-import { FormDialog } from '../../components/form-dialog/form-dialog';
-
-export const CollectionPartialCopyFormDialog = (props: WithDialogProps<string> & InjectedFormProps<{ name: string }>) =>
- <FormDialog
- dialogTitle='Create a collection'
- formFields={CollectionPartialCopyFields}
- submitLabel='Create a collection'
- {...props}
- />;
export const CollectionPartialCopyFields = () => <div style={{ display: 'flex' }}>
<div>