mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
68346: Fixed moving objects within paginated list
This commit is contained in:
@@ -96,7 +96,7 @@ export class ItemEditBitstreamBundleComponent implements OnInit {
|
|||||||
// No updates have been initialized yet for this bundle, initialize the first page
|
// No updates have been initialized yet for this bundle, initialize the first page
|
||||||
this.objectUpdatesService.initializeWithCustomOrder(this.bundle.self, bitstreams, new Date(), this.batchSize, updatesPage);
|
this.objectUpdatesService.initializeWithCustomOrder(this.bundle.self, bitstreams, new Date(), this.batchSize, updatesPage);
|
||||||
this.initializedPages.push(updatesPage);
|
this.initializedPages.push(updatesPage);
|
||||||
} else if (this.initializedPages.indexOf(this.currentPage$.value) < 0) {
|
} else if (this.initializedPages.indexOf(updatesPage) < 0) {
|
||||||
// Updates were initialized for this bundle, but not the page we're on. Add the current page to the field-update store for this bundle
|
// Updates were initialized for this bundle, but not the page we're on. Add the current page to the field-update store for this bundle
|
||||||
this.objectUpdatesService.addPageToCustomOrder(this.bundle.self, bitstreams, updatesPage);
|
this.objectUpdatesService.addPageToCustomOrder(this.bundle.self, bitstreams, updatesPage);
|
||||||
this.initializedPages.push(updatesPage);
|
this.initializedPages.push(updatesPage);
|
||||||
@@ -121,6 +121,6 @@ export class ItemEditBitstreamBundleComponent implements OnInit {
|
|||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
drop(event: CdkDragDrop<any>) {
|
drop(event: CdkDragDrop<any>) {
|
||||||
this.objectUpdatesService.saveMoveFieldUpdate(this.bundle.self, event.previousIndex, event.currentIndex);
|
this.objectUpdatesService.saveMoveFieldUpdate(this.bundle.self, event.previousIndex, event.currentIndex, this.currentPage$.value - 1, this.currentPage$.value - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -169,7 +169,7 @@ function initializeFieldsUpdate(state: any, action: InitializeFieldsAction) {
|
|||||||
{ customOrder: {
|
{ customOrder: {
|
||||||
initialOrderPages: initialOrderPages,
|
initialOrderPages: initialOrderPages,
|
||||||
newOrderPages: initialOrderPages,
|
newOrderPages: initialOrderPages,
|
||||||
pageSize: 9999,
|
pageSize: pageSize,
|
||||||
changed: false }
|
changed: false }
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -184,11 +184,12 @@ function initializeFieldsUpdate(state: any, action: InitializeFieldsAction) {
|
|||||||
function addPageToCustomOrder(state: any, action: AddPageToCustomOrderAction) {
|
function addPageToCustomOrder(state: any, action: AddPageToCustomOrderAction) {
|
||||||
const url: string = action.payload.url;
|
const url: string = action.payload.url;
|
||||||
const fields: Identifiable[] = action.payload.fields;
|
const fields: Identifiable[] = action.payload.fields;
|
||||||
|
const fieldStates = createInitialFieldStates(fields);
|
||||||
const order = action.payload.order;
|
const order = action.payload.order;
|
||||||
const page = action.payload.page;
|
const page = action.payload.page;
|
||||||
const pageState: ObjectUpdatesEntry = state[url] || {};
|
const pageState: ObjectUpdatesEntry = state[url] || {};
|
||||||
const newPageState = Object.assign({}, pageState, {
|
const newPageState = Object.assign({}, pageState, {
|
||||||
fieldStates: Object.assign({}, pageState.fieldStates, fields),
|
fieldStates: Object.assign({}, pageState.fieldStates, fieldStates),
|
||||||
customOrder: Object.assign({}, pageState.customOrder, {
|
customOrder: Object.assign({}, pageState.customOrder, {
|
||||||
newOrderPages: addOrderToPages(pageState.customOrder.newOrderPages, order, pageState.customOrder.pageSize, page),
|
newOrderPages: addOrderToPages(pageState.customOrder.newOrderPages, order, pageState.customOrder.pageSize, page),
|
||||||
initialOrderPages: addOrderToPages(pageState.customOrder.initialOrderPages, order, pageState.customOrder.pageSize, page)
|
initialOrderPages: addOrderToPages(pageState.customOrder.initialOrderPages, order, pageState.customOrder.pageSize, page)
|
||||||
@@ -453,16 +454,39 @@ function moveFieldUpdate(state: any, action: MoveFieldUpdateAction) {
|
|||||||
const pageState: ObjectUpdatesEntry = state[url];
|
const pageState: ObjectUpdatesEntry = state[url];
|
||||||
const initialOrderPages = pageState.customOrder.initialOrderPages;
|
const initialOrderPages = pageState.customOrder.initialOrderPages;
|
||||||
const customOrderPages = [...pageState.customOrder.newOrderPages];
|
const customOrderPages = [...pageState.customOrder.newOrderPages];
|
||||||
|
|
||||||
|
// Create a copy of the custom orders for the from- and to-pages
|
||||||
|
const fromPageOrder = [...customOrderPages[fromPage].order];
|
||||||
|
const toPageOrder = [...customOrderPages[toPage].order];
|
||||||
if (fromPage === toPage) {
|
if (fromPage === toPage) {
|
||||||
if (isNotEmpty(customOrderPages[fromPage]) && isNotEmpty(customOrderPages[fromPage].order[fromIndex]) && isNotEmpty(customOrderPages[fromPage].order[toIndex])) {
|
if (isNotEmpty(customOrderPages[fromPage]) && isNotEmpty(customOrderPages[fromPage].order[fromIndex]) && isNotEmpty(customOrderPages[fromPage].order[toIndex])) {
|
||||||
moveItemInArray(customOrderPages[fromPage].order, fromIndex, toIndex);
|
// Move an item from one index to another within the same page
|
||||||
|
moveItemInArray(fromPageOrder, fromIndex, toIndex);
|
||||||
|
// Update the custom order for this page
|
||||||
|
customOrderPages[fromPage] = { order: fromPageOrder };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isNotEmpty(customOrderPages[fromPage]) && isNotEmpty(customOrderPages[toPage]) && isNotEmpty(customOrderPages[fromPage].order[fromIndex]) && isNotEmpty(customOrderPages[toPage].order[toIndex])) {
|
if (isNotEmpty(customOrderPages[fromPage]) && isNotEmpty(customOrderPages[toPage]) && isNotEmpty(customOrderPages[fromPage].order[fromIndex]) && isNotEmpty(customOrderPages[toPage].order[toIndex])) {
|
||||||
transferArrayItem(customOrderPages[fromPage].order, customOrderPages[toPage].order, fromIndex, toIndex);
|
// Move an item from one index of one page to an index in another page
|
||||||
|
transferArrayItem(fromPageOrder, toPageOrder, fromIndex, toIndex);
|
||||||
|
// Update the custom order for both pages
|
||||||
|
customOrderPages[fromPage] = { order: fromPageOrder };
|
||||||
|
customOrderPages[toPage] = { order: toPageOrder };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the store's state with new values and return
|
||||||
|
return Object.assign({}, state, { [url]: Object.assign({}, pageState, {
|
||||||
|
customOrder: Object.assign({}, pageState.customOrder, { newOrderPages: customOrderPages, changed: checkForOrderChanges(initialOrderPages, customOrderPages) })
|
||||||
|
})})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare two lists of OrderPage objects and return whether there's at least one change in the order of objects within
|
||||||
|
* @param initialOrderPages The initial list of OrderPages
|
||||||
|
* @param customOrderPages The changed list of OrderPages
|
||||||
|
*/
|
||||||
|
function checkForOrderChanges(initialOrderPages: OrderPage[], customOrderPages: OrderPage[]) {
|
||||||
let changed = false;
|
let changed = false;
|
||||||
initialOrderPages.forEach((orderPage: OrderPage, page: number) => {
|
initialOrderPages.forEach((orderPage: OrderPage, page: number) => {
|
||||||
if (isNotEmpty(orderPage) && isNotEmpty(orderPage.order) && isNotEmpty(customOrderPages[page]) && isNotEmpty(customOrderPages[page].order)) {
|
if (isNotEmpty(orderPage) && isNotEmpty(orderPage.order) && isNotEmpty(customOrderPages[page]) && isNotEmpty(customOrderPages[page].order)) {
|
||||||
@@ -477,8 +501,7 @@ function moveFieldUpdate(state: any, action: MoveFieldUpdateAction) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return changed;
|
||||||
return Object.assign({}, state, { [url]: Object.assign({}, pageState, { customOrder: Object.assign({}, pageState.customOrder, { newOrderPages: customOrderPages, changed: changed }) }) })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -162,7 +162,7 @@ export class ObjectUpdatesService {
|
|||||||
const objectUpdates = this.getObjectEntry(url);
|
const objectUpdates = this.getObjectEntry(url);
|
||||||
return objectUpdates.pipe(map((objectEntry) => {
|
return objectUpdates.pipe(map((objectEntry) => {
|
||||||
const fieldUpdates: FieldUpdates = {};
|
const fieldUpdates: FieldUpdates = {};
|
||||||
if (hasValue(objectEntry)) {
|
if (hasValue(objectEntry) && hasValue(objectEntry.customOrder) && isNotEmpty(objectEntry.customOrder.newOrderPages) && page < objectEntry.customOrder.newOrderPages.length) {
|
||||||
for (const uuid of objectEntry.customOrder.newOrderPages[page].order) {
|
for (const uuid of objectEntry.customOrder.newOrderPages[page].order) {
|
||||||
let fieldUpdate = objectEntry.fieldUpdates[uuid];
|
let fieldUpdate = objectEntry.fieldUpdates[uuid];
|
||||||
if (isEmpty(fieldUpdate)) {
|
if (isEmpty(fieldUpdate)) {
|
||||||
|
Reference in New Issue
Block a user