[CST-4058] bug fixed

This commit is contained in:
Davide Negretti
2021-08-24 17:06:00 +02:00
parent dfae46d92e
commit cbbac01313

View File

@@ -14,9 +14,9 @@ import {
combineLatest as observableCombineLatest, combineLatest as observableCombineLatest,
Observable, Observable,
of as observableOf, of as observableOf,
Subscription Subscription,
} from 'rxjs'; } from 'rxjs';
import { catchError, map, switchMap, take } from 'rxjs/operators'; import { catchError, map, switchMap, take, filter } from 'rxjs/operators';
import { getCollectionEditRolesRoute } from '../../../collection-page/collection-page-routing-paths'; import { getCollectionEditRolesRoute } from '../../../collection-page/collection-page-routing-paths';
import { getCommunityEditRolesRoute } from '../../../community-page/community-page-routing-paths'; import { getCommunityEditRolesRoute } from '../../../community-page/community-page-routing-paths';
import { DSpaceObjectDataService } from '../../../core/data/dspace-object-data.service'; import { DSpaceObjectDataService } from '../../../core/data/dspace-object-data.service';
@@ -34,7 +34,8 @@ import { DSpaceObject } from '../../../core/shared/dspace-object.model';
import { import {
getRemoteDataPayload, getRemoteDataPayload,
getFirstSucceededRemoteData, getFirstSucceededRemoteData,
getFirstCompletedRemoteData getFirstCompletedRemoteData,
getFirstSucceededRemoteDataPayload
} from '../../../core/shared/operators'; } from '../../../core/shared/operators';
import { AlertType } from '../../../shared/alert/aletr-type'; import { AlertType } from '../../../shared/alert/aletr-type';
import { ConfirmationModalComponent } from '../../../shared/confirmation-modal/confirmation-modal.component'; import { ConfirmationModalComponent } from '../../../shared/confirmation-modal/confirmation-modal.component';
@@ -126,16 +127,16 @@ export class GroupFormComponent implements OnInit, OnDestroy {
public AlertTypeEnum = AlertType; public AlertTypeEnum = AlertType;
constructor(public groupDataService: GroupDataService, constructor(public groupDataService: GroupDataService,
private ePersonDataService: EPersonDataService, private ePersonDataService: EPersonDataService,
private dSpaceObjectDataService: DSpaceObjectDataService, private dSpaceObjectDataService: DSpaceObjectDataService,
private formBuilderService: FormBuilderService, private formBuilderService: FormBuilderService,
private translateService: TranslateService, private translateService: TranslateService,
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
private route: ActivatedRoute, private route: ActivatedRoute,
protected router: Router, protected router: Router,
private authorizationService: AuthorizationDataService, private authorizationService: AuthorizationDataService,
private modalService: NgbModal, private modalService: NgbModal,
public requestService: RequestService) { public requestService: RequestService) {
} }
ngOnInit() { ngOnInit() {
@@ -188,38 +189,49 @@ export class GroupFormComponent implements OnInit, OnDestroy {
}); });
this.formModel = [ this.formModel = [
this.groupName, this.groupName,
this.groupCommunity, // this.groupCommunity,
this.groupDescription, this.groupDescription,
]; ];
this.formGroup = this.formBuilderService.createFormGroup(this.formModel); this.formGroup = this.formBuilderService.createFormGroup(this.formModel);
debugger;
this.subs.push( this.subs.push(
observableCombineLatest( observableCombineLatest(
this.groupDataService.getActiveGroup(), this.groupDataService.getActiveGroup(),
this.canEdit$ this.canEdit$,
).subscribe(([activeGroup, canEdit]) => { this.groupDataService.getActiveGroup()
.pipe(filter((activeGroup) => hasValue(activeGroup)),switchMap((activeGroup) => this.getLinkedDSO(activeGroup).pipe(getFirstSucceededRemoteDataPayload())))
).subscribe(([activeGroup, canEdit, linkedObject]) => {
if (activeGroup != null) { if (activeGroup != null) {
this.groupBeingEdited = activeGroup; this.groupBeingEdited = activeGroup;
this.getLinkedDSO(activeGroup).subscribe((res) => {
if (res?.payload?.name) { if (linkedObject?.name) {
this.formGroup.patchValue({ // this.formModel = [
groupName: activeGroup != null ? activeGroup.name : '', // this.groupName,
groupCommunity: res?.payload?.name ?? '', // this.groupCommunity,
groupDescription: activeGroup != null ? activeGroup.firstMetadataValue('dc.description') : '', // this.groupDescription,
}); // ];
} else { this.formBuilderService.insertFormGroupControl(1, this.formGroup, this.formModel, this.groupCommunity);
this.formModel = [ this.formGroup.patchValue({
this.groupName, groupName: activeGroup != null ? activeGroup.name : '',
this.groupDescription, groupCommunity: linkedObject?.name ?? '',
]; groupDescription: activeGroup != null ? activeGroup.firstMetadataValue('dc.description') : '',
this.formGroup.patchValue({ });
groupName: activeGroup != null ? activeGroup.name : '', } else {
groupDescription: activeGroup != null ? activeGroup.firstMetadataValue('dc.description') : '', this.formModel = [
}); this.groupName,
} this.groupDescription,
];
this.formGroup.patchValue({
groupName: activeGroup != null ? activeGroup.name : '',
groupDescription: activeGroup != null ? activeGroup.firstMetadataValue('dc.description') : '',
});
}
setTimeout(() => {
if (!canEdit || activeGroup.permanent) { if (!canEdit || activeGroup.permanent) {
this.formGroup.disable(); this.formGroup.disable();
} }
}); }, 200);
} }
}) })
); );