mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
62571: Update item move method
This commit is contained in:
@@ -17,6 +17,7 @@ import {getItemEditPath} from '../../item-page-routing.module';
|
|||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import {of as observableOf} from 'rxjs';
|
import {of as observableOf} from 'rxjs';
|
||||||
import { RestResponse } from '../../../core/cache/response.models';
|
import { RestResponse } from '../../../core/cache/response.models';
|
||||||
|
import { Collection } from '../../../core/shared/collection.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-item-move',
|
selector: 'ds-item-move',
|
||||||
@@ -34,6 +35,7 @@ export class ItemMoveComponent implements OnInit {
|
|||||||
itemRD$: Observable<RemoteData<Item>>;
|
itemRD$: Observable<RemoteData<Item>>;
|
||||||
collectionSearchResults: Observable<any[]> = observableOf([]);
|
collectionSearchResults: Observable<any[]> = observableOf([]);
|
||||||
selectedCollection: string;
|
selectedCollection: string;
|
||||||
|
selectedCollectionObject: Collection;
|
||||||
|
|
||||||
selectedCollectionId: string;
|
selectedCollectionId: string;
|
||||||
itemId: string;
|
itemId: string;
|
||||||
@@ -92,6 +94,7 @@ export class ItemMoveComponent implements OnInit {
|
|||||||
onClick(data: any): void {
|
onClick(data: any): void {
|
||||||
this.selectedCollection = data.name;
|
this.selectedCollection = data.name;
|
||||||
this.selectedCollectionId = data.id;
|
this.selectedCollectionId = data.id;
|
||||||
|
this.selectedCollectionObject = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,7 +108,7 @@ export class ItemMoveComponent implements OnInit {
|
|||||||
* Moves the item to a new collection based on the selected collection
|
* Moves the item to a new collection based on the selected collection
|
||||||
*/
|
*/
|
||||||
moveCollection() {
|
moveCollection() {
|
||||||
this.itemDataService.moveToCollection(this.itemId, this.selectedCollectionId).pipe(first()).subscribe(
|
this.itemDataService.moveToCollection(this.itemId, this.selectedCollectionObject).pipe(first()).subscribe(
|
||||||
(response: RestResponse) => {
|
(response: RestResponse) => {
|
||||||
this.router.navigate([getItemEditPath(this.itemId)]);
|
this.router.navigate([getItemEditPath(this.itemId)]);
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
|
@@ -12,15 +12,17 @@ import { URLCombiner } from '../url-combiner/url-combiner';
|
|||||||
import { DataService } from './data.service';
|
import { DataService } from './data.service';
|
||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
import { DeleteByIDRequest, FindAllOptions, PatchRequest, PutRequest, RestRequest } from './request.models';
|
import { FindAllOptions, PatchRequest, PutRequest, RestRequest } from './request.models';
|
||||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
||||||
import { configureRequest, getRequestFromRequestHref } from '../shared/operators';
|
import { configureRequest, getRequestFromRequestHref } from '../shared/operators';
|
||||||
import { RequestEntry } from './request.reducer';
|
import { RequestEntry } from './request.reducer';
|
||||||
import { RestResponse } from '../cache/response.models';
|
import { RestResponse } from '../cache/response.models';
|
||||||
|
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
||||||
|
import { Collection } from '../shared/collection.model';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ItemDataService extends DataService<Item> {
|
export class ItemDataService extends DataService<Item> {
|
||||||
@@ -120,22 +122,26 @@ export class ItemDataService extends DataService<Item> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getMoveItemEndpoint(itemId: string, collectionId?: string): Observable<string> {
|
public getMoveItemEndpoint(itemId: string): Observable<string> {
|
||||||
return this.halService.getEndpoint(this.linkPath).pipe(
|
return this.halService.getEndpoint(this.linkPath).pipe(
|
||||||
map((endpoint: string) => this.getIDHref(endpoint, itemId)),
|
map((endpoint: string) => this.getIDHref(endpoint, itemId)),
|
||||||
map((endpoint: string) => `${endpoint}/owningCollection/move/${collectionId ? `/${collectionId}` : ''}`)
|
map((endpoint: string) => `${endpoint}/owningCollection`)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public moveToCollection(itemId: string, collectionId: string): Observable<RestResponse> {
|
public moveToCollection(itemId: string, collection: Collection): Observable<RestResponse> {
|
||||||
const requestId = this.requestService.generateRequestId();
|
const options: HttpOptions = Object.create({});
|
||||||
|
let headers = new HttpHeaders();
|
||||||
|
headers = headers.append('Content-Type', 'text/uri-list');
|
||||||
|
options.headers = headers;
|
||||||
|
|
||||||
const hrefObs = this.getMoveItemEndpoint(itemId, collectionId);
|
const requestId = this.requestService.generateRequestId();
|
||||||
|
const hrefObs = this.getMoveItemEndpoint(itemId);
|
||||||
|
|
||||||
hrefObs.pipe(
|
hrefObs.pipe(
|
||||||
find((href: string) => hasValue(href)),
|
find((href: string) => hasValue(href)),
|
||||||
map((href: string) => {
|
map((href: string) => {
|
||||||
const request = new PutRequest(requestId, href);
|
const request = new PutRequest(requestId, href, collection.self, options);
|
||||||
this.requestService.configure(request);
|
this.requestService.configure(request);
|
||||||
})
|
})
|
||||||
).subscribe();
|
).subscribe();
|
||||||
|
Reference in New Issue
Block a user