mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
80195: Fix move request handling
This commit is contained in:
@@ -1,24 +1,18 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { first, map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
|
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
|
||||||
import { RemoteData } from '../../../core/data/remote-data';
|
import { RemoteData } from '../../../core/data/remote-data';
|
||||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
|
||||||
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
|
||||||
import { Item } from '../../../core/shared/item.model';
|
import { Item } from '../../../core/shared/item.model';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import {
|
import {
|
||||||
getFirstSucceededRemoteData,
|
getAllSucceededRemoteDataPayload, getFirstCompletedRemoteData, getFirstSucceededRemoteData,
|
||||||
getFirstCompletedRemoteData, getAllSucceededRemoteDataPayload
|
|
||||||
} from '../../../core/shared/operators';
|
} from '../../../core/shared/operators';
|
||||||
import { ItemDataService } from '../../../core/data/item-data.service';
|
import { ItemDataService } from '../../../core/data/item-data.service';
|
||||||
import { Observable, of as observableOf } from 'rxjs';
|
import { Observable, of as observableOf } from 'rxjs';
|
||||||
import { Collection } from '../../../core/shared/collection.model';
|
import { Collection } from '../../../core/shared/collection.model';
|
||||||
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
|
|
||||||
import { SearchService } from '../../../core/shared/search/search.service';
|
import { SearchService } from '../../../core/shared/search/search.service';
|
||||||
import { PaginatedSearchOptions } from '../../../shared/search/paginated-search-options.model';
|
|
||||||
import { SearchResult } from '../../../shared/search/search-result.model';
|
|
||||||
import { getItemEditRoute, getItemPageRoute } from '../../item-page-routing-paths';
|
import { getItemEditRoute, getItemPageRoute } from '../../item-page-routing-paths';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -46,8 +40,6 @@ export class ItemMoveComponent implements OnInit {
|
|||||||
item: Item;
|
item: Item;
|
||||||
processing = false;
|
processing = false;
|
||||||
|
|
||||||
pagination = new PaginationComponentOptions();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route to the item's page
|
* Route to the item's page
|
||||||
*/
|
*/
|
||||||
@@ -73,28 +65,6 @@ export class ItemMoveComponent implements OnInit {
|
|||||||
this.item = rd.payload;
|
this.item = rd.payload;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
this.pagination.pageSize = 5;
|
|
||||||
this.loadSuggestions('');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load all available collections to move the item to.
|
|
||||||
* TODO: When the API support it, only fetch collections where user has ADD rights to.
|
|
||||||
*/
|
|
||||||
loadSuggestions(query): void {
|
|
||||||
this.collectionSearchResults = this.searchService.search(new PaginatedSearchOptions({
|
|
||||||
pagination: this.pagination,
|
|
||||||
dsoTypes: [DSpaceObjectType.COLLECTION],
|
|
||||||
query: query
|
|
||||||
})).pipe(
|
|
||||||
first(),
|
|
||||||
map((rd: RemoteData<PaginatedList<SearchResult<DSpaceObject>>>) => {
|
|
||||||
return rd.payload.page.map((searchResult) => {
|
|
||||||
return searchResult.indexableObject;
|
|
||||||
});
|
|
||||||
}) ,
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -119,8 +89,10 @@ export class ItemMoveComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
moveCollection() {
|
moveCollection() {
|
||||||
this.processing = true;
|
this.processing = true;
|
||||||
this.itemDataService.moveToCollection(this.item.id, this.selectedCollection).pipe(getFirstCompletedRemoteData()).subscribe(
|
this.itemDataService.moveToCollection(this.item.id, this.selectedCollection)
|
||||||
(response: RemoteData<Collection>) => {
|
.pipe(getFirstCompletedRemoteData())
|
||||||
|
.subscribe(
|
||||||
|
(response: RemoteData<any>) => {
|
||||||
this.router.navigate([getItemEditRoute(this.item)]);
|
this.router.navigate([getItemEditRoute(this.item)]);
|
||||||
if (response.hasSucceeded) {
|
if (response.hasSucceeded) {
|
||||||
this.notificationsService.success(this.translateService.get('item.edit.move.success'));
|
this.notificationsService.success(this.translateService.get('item.edit.move.success'));
|
||||||
|
@@ -23,14 +23,7 @@ import { DataService } from './data.service';
|
|||||||
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
||||||
import { PaginatedList } from './paginated-list.model';
|
import { PaginatedList } from './paginated-list.model';
|
||||||
import { RemoteData } from './remote-data';
|
import { RemoteData } from './remote-data';
|
||||||
import {
|
import { DeleteRequest, FindListOptions, GetRequest, PostRequest, PutRequest, RestRequest } from './request.models';
|
||||||
DeleteRequest,
|
|
||||||
FindListOptions,
|
|
||||||
GetRequest,
|
|
||||||
PostRequest,
|
|
||||||
PutRequest,
|
|
||||||
RestRequest
|
|
||||||
} from './request.models';
|
|
||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
import { PaginatedSearchOptions } from '../../shared/search/paginated-search-options.model';
|
import { PaginatedSearchOptions } from '../../shared/search/paginated-search-options.model';
|
||||||
import { Bundle } from '../shared/bundle.model';
|
import { Bundle } from '../shared/bundle.model';
|
||||||
@@ -38,6 +31,9 @@ import { MetadataMap } from '../shared/metadata.models';
|
|||||||
import { BundleDataService } from './bundle-data.service';
|
import { BundleDataService } from './bundle-data.service';
|
||||||
import { Operation } from 'fast-json-patch';
|
import { Operation } from 'fast-json-patch';
|
||||||
import { NoContent } from '../shared/NoContent.model';
|
import { NoContent } from '../shared/NoContent.model';
|
||||||
|
import { GenericConstructor } from '../shared/generic-constructor';
|
||||||
|
import { ResponseParsingService } from './parsing.service';
|
||||||
|
import { StatusCodeOnlyResponseParsingService } from './status-code-only-response-parsing.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@dataService(ITEM)
|
@dataService(ITEM)
|
||||||
@@ -229,7 +225,7 @@ export class ItemDataService extends DataService<Item> {
|
|||||||
* @param itemId
|
* @param itemId
|
||||||
* @param collection
|
* @param collection
|
||||||
*/
|
*/
|
||||||
public moveToCollection(itemId: string, collection: Collection): Observable<RemoteData<Collection>> {
|
public moveToCollection(itemId: string, collection: Collection): Observable<RemoteData<any>> {
|
||||||
const options: HttpOptions = Object.create({});
|
const options: HttpOptions = Object.create({});
|
||||||
let headers = new HttpHeaders();
|
let headers = new HttpHeaders();
|
||||||
headers = headers.append('Content-Type', 'text/uri-list');
|
headers = headers.append('Content-Type', 'text/uri-list');
|
||||||
@@ -242,9 +238,17 @@ export class ItemDataService extends DataService<Item> {
|
|||||||
find((href: string) => hasValue(href)),
|
find((href: string) => hasValue(href)),
|
||||||
map((href: string) => {
|
map((href: string) => {
|
||||||
const request = new PutRequest(requestId, href, collection._links.self.href, options);
|
const request = new PutRequest(requestId, href, collection._links.self.href, options);
|
||||||
this.requestService.send(request);
|
Object.assign(request, {
|
||||||
|
// TODO: for now, the move Item endpoint returns a malformed collection -- only look at the status code
|
||||||
|
getResponseParser(): GenericConstructor<ResponseParsingService> {
|
||||||
|
return StatusCodeOnlyResponseParsingService;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return request;
|
||||||
})
|
})
|
||||||
).subscribe();
|
).subscribe((request) => {
|
||||||
|
this.requestService.send(request);
|
||||||
|
});
|
||||||
|
|
||||||
return this.rdbService.buildFromRequestUUID(requestId);
|
return this.rdbService.buildFromRequestUUID(requestId);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user