mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
64961: Intermediate commit
This commit is contained in:
@@ -41,6 +41,11 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
|
||||
*/
|
||||
bitstream: Bitstream;
|
||||
|
||||
/**
|
||||
* The ID of the originally selected format
|
||||
*/
|
||||
originalFormatID: string;
|
||||
|
||||
/**
|
||||
* @type {string} Key prefix used to generate form messages
|
||||
*/
|
||||
@@ -298,6 +303,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
|
||||
getRemoteDataPayload(),
|
||||
take(1)
|
||||
).subscribe((format: BitstreamFormat) => {
|
||||
this.originalFormatID = format.id;
|
||||
this.formGroup.patchValue({
|
||||
formatContainer: {
|
||||
selectedFormat: format.id
|
||||
@@ -364,6 +370,10 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired whenever the form receives an update and changes the layout of the "Other Format" input, depending on the selected format
|
||||
* @param event
|
||||
*/
|
||||
onChange(event) {
|
||||
const model = event.model;
|
||||
if (model.id === this.selectedFormatModel.id) {
|
||||
@@ -377,10 +387,16 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
|
||||
onSubmit() {
|
||||
const updatedValues = this.formGroup.getRawValue();
|
||||
const newBitstream = this.formToBitstream(updatedValues);
|
||||
this.bitstreamService.update(newBitstream).pipe(
|
||||
const selectedFormat = updatedValues.formatContainer.selectedFormat;
|
||||
|
||||
const updatedBitstream$ = this.bitstreamService.update(newBitstream).pipe(
|
||||
tap(() => this.bitstreamService.commitUpdates()),
|
||||
getSucceededRemoteData()
|
||||
).subscribe((bitstreamRD: RemoteData<Bitstream>) => {
|
||||
);
|
||||
const updatedFormatResponse$ = this.bitstreamService.updateFormat(newBitstream, selectedFormat);
|
||||
|
||||
observableCombineLatest(updatedBitstream$, updatedFormatResponse$).subscribe(([bitstreamRD, formatResponse]) => {
|
||||
console.log(formatResponse);
|
||||
this.bitstream = bitstreamRD.payload;
|
||||
this.updateForm(this.bitstream);
|
||||
this.notificationsService.success(
|
||||
|
@@ -107,7 +107,6 @@ export class ServerSyncBufferEffects {
|
||||
this.requestService.configure(new PatchRequest(this.requestService.generateRequestId(), href, flatPatch));
|
||||
return new ApplyPatchObjectCacheAction(href);
|
||||
}
|
||||
// this.requestService.configure(new PutRequest(this.requestService.generateRequestId(), href, serializedObject));
|
||||
})
|
||||
)
|
||||
}
|
||||
|
@@ -10,11 +10,16 @@ import { BrowseService } from '../browse/browse.service';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
||||
import { FindAllOptions } from './request.models';
|
||||
import { FindAllOptions, PutRequest } from './request.models';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { RestResponse } from '../cache/response.models';
|
||||
import { BitstreamFormatDataService } from './bitstream-format-data.service';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { combineLatest as observableCombineLatest } from 'rxjs';
|
||||
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
||||
import { configureRequest, getResponseFromEntry } from '../shared/operators';
|
||||
|
||||
/**
|
||||
* A service responsible for fetching/sending data from/to the REST API on the bitstreams endpoint
|
||||
@@ -34,7 +39,8 @@ export class BitstreamDataService extends DataService<Bitstream> {
|
||||
protected halService: HALEndpointService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DSOChangeAnalyzer<Bitstream>) {
|
||||
protected comparator: DSOChangeAnalyzer<Bitstream>,
|
||||
protected bitstreamFormatService: BitstreamFormatDataService) {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -60,4 +66,34 @@ export class BitstreamDataService extends DataService<Bitstream> {
|
||||
this.requestService.removeByHrefSubstring(bitstream.self);
|
||||
return response$;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the format of a bitstream by ID
|
||||
* @param bitstream
|
||||
* @param formatId
|
||||
*/
|
||||
updateFormat(bitstream: Bitstream, formatId: string): Observable<RestResponse> {
|
||||
const requestId = this.requestService.generateRequestId();
|
||||
const bitstreamHref$ = this.getBrowseEndpoint().pipe(
|
||||
map((href: string) => `${href}/${bitstream.id}`),
|
||||
switchMap((href: string) => this.halService.getEndpoint('format', href))
|
||||
);
|
||||
const formatHref$ = this.bitstreamFormatService.getBrowseEndpoint().pipe(
|
||||
map((href: string) => `${href}/${formatId}`)
|
||||
);
|
||||
observableCombineLatest(bitstreamHref$, formatHref$).pipe(
|
||||
map(([bitstreamHref, formatHref]) => {
|
||||
const options: HttpOptions = Object.create({});
|
||||
let headers = new HttpHeaders();
|
||||
headers = headers.append('Content-Type', 'text/uri-list');
|
||||
options.headers = headers;
|
||||
return new PutRequest(requestId, bitstreamHref, formatHref, options);
|
||||
}),
|
||||
configureRequest(this.requestService)
|
||||
).subscribe();
|
||||
|
||||
return this.requestService.getByUUID(requestId).pipe(
|
||||
getResponseFromEntry()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user