64961: Intermediate commit

This commit is contained in:
Kristof De Langhe
2019-09-16 11:29:44 +02:00
parent a00ceb3da5
commit 6230fef6b9
3 changed files with 57 additions and 6 deletions

View File

@@ -41,6 +41,11 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
*/ */
bitstream: Bitstream; bitstream: Bitstream;
/**
* The ID of the originally selected format
*/
originalFormatID: string;
/** /**
* @type {string} Key prefix used to generate form messages * @type {string} Key prefix used to generate form messages
*/ */
@@ -298,6 +303,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
getRemoteDataPayload(), getRemoteDataPayload(),
take(1) take(1)
).subscribe((format: BitstreamFormat) => { ).subscribe((format: BitstreamFormat) => {
this.originalFormatID = format.id;
this.formGroup.patchValue({ this.formGroup.patchValue({
formatContainer: { formatContainer: {
selectedFormat: format.id 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) { onChange(event) {
const model = event.model; const model = event.model;
if (model.id === this.selectedFormatModel.id) { if (model.id === this.selectedFormatModel.id) {
@@ -377,10 +387,16 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
onSubmit() { onSubmit() {
const updatedValues = this.formGroup.getRawValue(); const updatedValues = this.formGroup.getRawValue();
const newBitstream = this.formToBitstream(updatedValues); 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()), tap(() => this.bitstreamService.commitUpdates()),
getSucceededRemoteData() 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.bitstream = bitstreamRD.payload;
this.updateForm(this.bitstream); this.updateForm(this.bitstream);
this.notificationsService.success( this.notificationsService.success(

View File

@@ -107,7 +107,6 @@ export class ServerSyncBufferEffects {
this.requestService.configure(new PatchRequest(this.requestService.generateRequestId(), href, flatPatch)); this.requestService.configure(new PatchRequest(this.requestService.generateRequestId(), href, flatPatch));
return new ApplyPatchObjectCacheAction(href); return new ApplyPatchObjectCacheAction(href);
} }
// this.requestService.configure(new PutRequest(this.requestService.generateRequestId(), href, serializedObject));
}) })
) )
} }

View File

@@ -10,11 +10,16 @@ import { BrowseService } from '../browse/browse.service';
import { ObjectCacheService } from '../cache/object-cache.service'; import { ObjectCacheService } from '../cache/object-cache.service';
import { HALEndpointService } from '../shared/hal-endpoint.service'; import { HALEndpointService } from '../shared/hal-endpoint.service';
import { NotificationsService } from '../../shared/notifications/notifications.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 { DSOChangeAnalyzer } from './dso-change-analyzer.service';
import { FindAllOptions } from './request.models'; import { FindAllOptions, PutRequest } from './request.models';
import { Observable } from 'rxjs/internal/Observable'; import { Observable } from 'rxjs/internal/Observable';
import { RestResponse } from '../cache/response.models'; 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 * 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 halService: HALEndpointService,
protected notificationsService: NotificationsService, protected notificationsService: NotificationsService,
protected http: HttpClient, protected http: HttpClient,
protected comparator: DSOChangeAnalyzer<Bitstream>) { protected comparator: DSOChangeAnalyzer<Bitstream>,
protected bitstreamFormatService: BitstreamFormatDataService) {
super(); super();
} }
@@ -60,4 +66,34 @@ export class BitstreamDataService extends DataService<Bitstream> {
this.requestService.removeByHrefSubstring(bitstream.self); this.requestService.removeByHrefSubstring(bitstream.self);
return response$; 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()
);
}
} }