Skip to content
Snippets Groups Projects
Commit 1e31fadb authored by Kristof De Langhe's avatar Kristof De Langhe
Browse files

61142: Submit intermediate commit

parent 3d9b3c68
No related merge requests found
......@@ -733,6 +733,7 @@
"sub-communities": "Loading sub-communities...",
"recent-submissions": "Loading recent submissions...",
"item": "Loading item...",
"items": "Loading items...",
"objects": "Loading...",
"search-results": "Loading search results...",
"browse-by": "Loading items...",
......
......@@ -18,14 +18,21 @@
</button>
</div>
<div *ngFor="let label of relationLabels$ | async" class="mb-4">
<h5>{{getRelationshipMessageKey(label) | translate}}</h5>
<div *ngFor="let updateValue of ((getUpdatesByLabel(label) | async)| dsObjectValues); trackBy: trackUpdate"
ds-edit-relationship
class="relationship-row d-block"
[fieldUpdate]="updateValue || {}"
[url]="url"
[ngClass]="{'alert alert-danger': updateValue.changeType === 2}">
</div>
<ng-container *ngVar="(getUpdatesByLabel(label) | async) as updates">
<div *ngIf="updates">
<h5>{{getRelationshipMessageKey(label) | translate}}</h5>
<ng-container *ngVar="(updates | dsObjectValues) as updateValues">
<div *ngFor="let updateValue of updateValues; trackBy: trackUpdate"
ds-edit-relationship
class="relationship-row d-block"
[fieldUpdate]="updateValue || {}"
[url]="url"
[ngClass]="{'alert alert-danger': updateValue.changeType === 2}">
</div>
<ds-loading *ngIf="updateValues.length == 0" message="{{'loading.items' | translate}}"></ds-loading>
</ng-container>
</div>
</ng-container>
</div>
<div class="button-row bottom">
<div class="float-right">
......
......@@ -2,7 +2,8 @@ import { Component, Inject } from '@angular/core';
import { Item } from '../../../core/shared/item.model';
import { FieldUpdate, FieldUpdates } from '../../../core/data/object-updates/object-updates.reducer';
import { Observable } from 'rxjs/internal/Observable';
import { distinctUntilChanged, switchMap, take } from 'rxjs/operators';
import { map, switchMap, take, tap } from 'rxjs/operators';
import { combineLatest as observableCombineLatest, zip as observableZip } from 'rxjs';
import { AbstractItemUpdateComponent } from '../abstract-item-update/abstract-item-update.component';
import { ItemDataService } from '../../../core/data/item-data.service';
import { ObjectUpdatesService } from '../../../core/data/object-updates/object-updates.service';
......@@ -11,6 +12,10 @@ import { NotificationsService } from '../../../shared/notifications/notification
import { TranslateService } from '@ngx-translate/core';
import { GLOBAL_CONFIG, GlobalConfig } from '../../../../config';
import { RelationshipService } from '../../../core/data/relationship.service';
import { FieldChangeType } from '../../../core/data/object-updates/object-updates.actions';
import { Relationship } from '../../../core/shared/item-relationships/relationship.model';
import { RestResponse } from '../../../core/cache/response.models';
import { isNotEmptyOperator } from '../../../shared/empty.util';
@Component({
selector: 'ds-item-relationships',
......@@ -65,10 +70,32 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
}
public submit(): void {
const updatedItems$ = this.relationshipService.getRelatedItems(this.item).pipe(
switchMap((items: Item[]) => this.objectUpdatesService.getUpdatedFields(this.url, items) as Observable<Item[]>)
const removedItemIds$ = this.relationshipService.getRelatedItems(this.item).pipe(
switchMap((items: Item[]) => this.objectUpdatesService.getFieldUpdatesExclusive(this.url, items) as Observable<FieldUpdates>),
map((fieldUpdates: FieldUpdates) => Object.values(fieldUpdates).filter((fieldUpdate: FieldUpdate) => fieldUpdate.changeType === FieldChangeType.REMOVE)),
map((fieldUpdates: FieldUpdate[]) => fieldUpdates.map((fieldUpdate: FieldUpdate) => fieldUpdate.field.uuid) as string[]),
isNotEmptyOperator()
);
// TODO: Delete relationships
const allRelationshipsAndRemovedItemIds$ = observableCombineLatest(
this.relationshipService.getItemRelationshipsArray(this.item),
removedItemIds$
);
const removedRelationshipIds$ = allRelationshipsAndRemovedItemIds$.pipe(
map(([relationships, itemIds]) =>
relationships
.filter((relationship: Relationship) => itemIds.indexOf(relationship.leftId) > -1 || itemIds.indexOf(relationship.rightId) > -1)
.map((relationship: Relationship) => relationship.id))
);
removedRelationshipIds$.pipe(
take(1),
switchMap((removedIds: string[]) => observableZip(removedIds.map((uuid: string) => this.relationshipService.deleteRelationship(uuid)))),
map((responses: RestResponse[]) => responses.filter((response: RestResponse) => response.isSuccessful))
).subscribe((responses: RestResponse[]) => {
console.log(responses);
this.initializeOriginalFields();
this.initializeUpdates();
this.notificationsService.success(this.getNotificationTitle('saved'), this.getNotificationContent('saved'));
});
}
/**
......
......@@ -3,7 +3,7 @@ import { RequestService } from './request.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { hasValue, hasValueOperator, isNotEmptyOperator } from '../../shared/empty.util';
import { distinctUntilChanged, flatMap, map, take } from 'rxjs/operators';
import { distinctUntilChanged, flatMap, map, switchMap, take, tap } from 'rxjs/operators';
import {
configureRequest,
filterSuccessfulResponses,
......@@ -46,17 +46,12 @@ export class RelationshipService {
}
deleteRelationship(uuid: string): Observable<RestResponse> {
const requestUuid = this.requestService.generateRequestId();
this.getRelationshipEndpoint(uuid).pipe(
return this.getRelationshipEndpoint(uuid).pipe(
isNotEmptyOperator(),
distinctUntilChanged(),
map((endpointURL: string) => new DeleteRequest(requestUuid, endpointURL)),
map((endpointURL: string) => new DeleteRequest(this.requestService.generateRequestId(), endpointURL)),
configureRequest(this.requestService),
take(1)
).subscribe();
return this.requestService.getByUUID(requestUuid).pipe(
switchMap((restRequest: RestRequest) => this.requestService.getByUUID(restRequest.uuid)),
filterSuccessfulResponses()
);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment