mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 23:43:01 +00:00
added typedoc
This commit is contained in:
@@ -19,6 +19,9 @@ export const SelectableListActionTypes = {
|
||||
DESELECT_ALL: type('dspace/selectable-lists/DESELECT_ALL')
|
||||
};
|
||||
|
||||
/**
|
||||
* Abstract action class for actions on selectable lists
|
||||
*/
|
||||
/* tslint:disable:max-classes-per-file */
|
||||
export abstract class SelectableListAction implements Action {
|
||||
// tslint:disable-next-line:no-shadowed-variable
|
||||
@@ -27,7 +30,7 @@ export abstract class SelectableListAction implements Action {
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to select an item in a the selectable list
|
||||
* Action to select objects in a the selectable list
|
||||
*/
|
||||
export class SelectableListSelectAction extends SelectableListAction {
|
||||
payload: ListableObject[];
|
||||
@@ -37,7 +40,9 @@ export class SelectableListSelectAction extends SelectableListAction {
|
||||
this.payload = objects;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action to select a single object in a the selectable list
|
||||
*/
|
||||
export class SelectableListSelectSingleAction extends SelectableListAction {
|
||||
payload: {
|
||||
object: ListableObject,
|
||||
@@ -49,6 +54,9 @@ export class SelectableListSelectSingleAction extends SelectableListAction {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action to deselect objects in a the selectable list
|
||||
*/
|
||||
export class SelectableListDeselectSingleAction extends SelectableListAction {
|
||||
payload: ListableObject;
|
||||
|
||||
@@ -58,6 +66,9 @@ export class SelectableListDeselectSingleAction extends SelectableListAction {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action to deselect a single object in a the selectable list
|
||||
*/
|
||||
export class SelectableListDeselectAction extends SelectableListAction {
|
||||
payload: ListableObject[];
|
||||
|
||||
@@ -67,6 +78,9 @@ export class SelectableListDeselectAction extends SelectableListAction {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action to set a new or overwrite an existing selection
|
||||
*/
|
||||
export class SelectableListSetSelectionAction extends SelectableListAction {
|
||||
payload: ListableObject[];
|
||||
|
||||
@@ -76,6 +90,9 @@ export class SelectableListSetSelectionAction extends SelectableListAction {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action to deselect all currently selected objects
|
||||
*/
|
||||
export class SelectableListDeselectAllAction extends SelectableListAction {
|
||||
constructor(id: string) {
|
||||
super(SelectableListActionTypes.DESELECT_ALL, id);
|
||||
|
@@ -63,12 +63,22 @@ export function selectableListReducer(state: SelectableListsState = {}, action:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds multiple objects to the existing selection state
|
||||
* @param state The current state
|
||||
* @param action The action to perform
|
||||
*/
|
||||
function select(state: SelectableListState, action: SelectableListSelectAction) {
|
||||
const filteredNewObjects = action.payload.filter((object) => !isObjectInSelection(state.selection, object));
|
||||
const newSelection = [...state.selection, ...filteredNewObjects];
|
||||
return Object.assign({}, state, { selection: newSelection });
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a single object to the existing selection state
|
||||
* @param state The current state
|
||||
* @param action The action to perform
|
||||
*/
|
||||
function selectSingle(state: SelectableListState, action: SelectableListSelectSingleAction) {
|
||||
let newSelection = state.selection;
|
||||
if (!isObjectInSelection(state.selection, action.payload.object)) {
|
||||
@@ -77,11 +87,21 @@ function selectSingle(state: SelectableListState, action: SelectableListSelectSi
|
||||
return Object.assign({}, state, { selection: newSelection });
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes multiple objects in the existing selection state
|
||||
* @param state The current state
|
||||
* @param action The action to perform
|
||||
*/
|
||||
function deselect(state: SelectableListState, action: SelectableListDeselectAction) {
|
||||
const newSelection = state.selection.filter((selected) => hasNoValue(action.payload.find((object) => object.equals(selected))));
|
||||
return Object.assign({}, state, { selection: newSelection });
|
||||
}
|
||||
|
||||
/** Removes a single object from the existing selection state
|
||||
*
|
||||
* @param state The current state
|
||||
* @param action The action to perform
|
||||
*/
|
||||
function deselectSingle(state: SelectableListState, action: SelectableListDeselectSingleAction) {
|
||||
const newSelection = state.selection.filter((selected) => {
|
||||
return !selected.equals(action.payload);
|
||||
@@ -89,14 +109,29 @@ function deselectSingle(state: SelectableListState, action: SelectableListDesele
|
||||
return Object.assign({}, state, { selection: newSelection });
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selection state of the list
|
||||
* @param state The current state
|
||||
* @param action The action to perform
|
||||
*/
|
||||
function setList(state: SelectableListState, action: SelectableListSetSelectionAction) {
|
||||
return Object.assign({}, state, { selection: action.payload });
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the selection
|
||||
* @param state The current state
|
||||
* @param action The action to perform
|
||||
*/
|
||||
function clearSelection(id: string) {
|
||||
return { id: id, selection: [] };
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the object is in currently in the selection
|
||||
* @param state The current state
|
||||
* @param action The action to perform
|
||||
*/
|
||||
function isObjectInSelection(selection: ListableObject[], object: ListableObject) {
|
||||
return selection.findIndex((selected) => selected.equals(object)) >= 0
|
||||
}
|
||||
|
Reference in New Issue
Block a user