Commits

Davide Negretti authored cbbac013130
[CST-4058] bug fixed
No tags

src/app/access-control/group-registry/group-form/group-form.component.ts

Modified
7 7 DynamicFormLayout,
8 8 DynamicInputModel,
9 9 DynamicTextAreaModel
10 10 } from '@ng-dynamic-forms/core';
11 11 import { TranslateService } from '@ngx-translate/core';
12 12 import {
13 13 ObservedValueOf,
14 14 combineLatest as observableCombineLatest,
15 15 Observable,
16 16 of as observableOf,
17 - Subscription
17 + Subscription,
18 18 } from 'rxjs';
19 -import { catchError, map, switchMap, take } from 'rxjs/operators';
19 +import { catchError, map, switchMap, take, filter } from 'rxjs/operators';
20 20 import { getCollectionEditRolesRoute } from '../../../collection-page/collection-page-routing-paths';
21 21 import { getCommunityEditRolesRoute } from '../../../community-page/community-page-routing-paths';
22 22 import { DSpaceObjectDataService } from '../../../core/data/dspace-object-data.service';
23 23 import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
24 24 import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
25 25 import { PaginatedList } from '../../../core/data/paginated-list.model';
26 26 import { RemoteData } from '../../../core/data/remote-data';
27 27 import { RequestService } from '../../../core/data/request.service';
28 28 import { EPersonDataService } from '../../../core/eperson/eperson-data.service';
29 29 import { GroupDataService } from '../../../core/eperson/group-data.service';
30 30 import { Group } from '../../../core/eperson/models/group.model';
31 31 import { Collection } from '../../../core/shared/collection.model';
32 32 import { Community } from '../../../core/shared/community.model';
33 33 import { DSpaceObject } from '../../../core/shared/dspace-object.model';
34 34 import {
35 35 getRemoteDataPayload,
36 36 getFirstSucceededRemoteData,
37 - getFirstCompletedRemoteData
37 + getFirstCompletedRemoteData,
38 + getFirstSucceededRemoteDataPayload
38 39 } from '../../../core/shared/operators';
39 40 import { AlertType } from '../../../shared/alert/aletr-type';
40 41 import { ConfirmationModalComponent } from '../../../shared/confirmation-modal/confirmation-modal.component';
41 42 import { hasValue, isNotEmpty, hasValueOperator } from '../../../shared/empty.util';
42 43 import { FormBuilderService } from '../../../shared/form/builder/form-builder.service';
43 44 import { NotificationsService } from '../../../shared/notifications/notifications.service';
44 45 import { followLink } from '../../../shared/utils/follow-link-config.model';
45 46 import { NoContent } from '../../../core/shared/NoContent.model';
46 47 import { Operation } from 'fast-json-patch';
47 48
119 120 */
120 121 canEdit$: Observable<boolean>;
121 122
122 123 /**
123 124 * The AlertType enumeration
124 125 * @type {AlertType}
125 126 */
126 127 public AlertTypeEnum = AlertType;
127 128
128 129 constructor(public groupDataService: GroupDataService,
129 - private ePersonDataService: EPersonDataService,
130 - private dSpaceObjectDataService: DSpaceObjectDataService,
131 - private formBuilderService: FormBuilderService,
132 - private translateService: TranslateService,
133 - private notificationsService: NotificationsService,
134 - private route: ActivatedRoute,
135 - protected router: Router,
136 - private authorizationService: AuthorizationDataService,
137 - private modalService: NgbModal,
138 - public requestService: RequestService) {
130 + private ePersonDataService: EPersonDataService,
131 + private dSpaceObjectDataService: DSpaceObjectDataService,
132 + private formBuilderService: FormBuilderService,
133 + private translateService: TranslateService,
134 + private notificationsService: NotificationsService,
135 + private route: ActivatedRoute,
136 + protected router: Router,
137 + private authorizationService: AuthorizationDataService,
138 + private modalService: NgbModal,
139 + public requestService: RequestService) {
139 140 }
140 141
141 142 ngOnInit() {
142 143 this.initialisePage();
143 144 }
144 145
145 146 initialisePage() {
146 147 this.subs.push(this.route.params.subscribe((params) => {
147 148 if (params.groupId !== 'newGroup') {
148 149 this.setActiveGroup(params.groupId);
181 182 readOnly: true,
182 183 });
183 184 this.groupDescription = new DynamicTextAreaModel({
184 185 id: 'groupDescription',
185 186 label: groupDescription,
186 187 name: 'groupDescription',
187 188 required: false,
188 189 });
189 190 this.formModel = [
190 191 this.groupName,
191 - this.groupCommunity,
192 + // this.groupCommunity,
192 193 this.groupDescription,
193 194 ];
194 195 this.formGroup = this.formBuilderService.createFormGroup(this.formModel);
196 + debugger;
195 197 this.subs.push(
196 198 observableCombineLatest(
197 199 this.groupDataService.getActiveGroup(),
198 - this.canEdit$
199 - ).subscribe(([activeGroup, canEdit]) => {
200 + this.canEdit$,
201 + this.groupDataService.getActiveGroup()
202 + .pipe(filter((activeGroup) => hasValue(activeGroup)),switchMap((activeGroup) => this.getLinkedDSO(activeGroup).pipe(getFirstSucceededRemoteDataPayload())))
203 + ).subscribe(([activeGroup, canEdit, linkedObject]) => {
204 +
200 205 if (activeGroup != null) {
201 206 this.groupBeingEdited = activeGroup;
202 - this.getLinkedDSO(activeGroup).subscribe((res) => {
203 - if (res?.payload?.name) {
204 - this.formGroup.patchValue({
205 - groupName: activeGroup != null ? activeGroup.name : '',
206 - groupCommunity: res?.payload?.name ?? '',
207 - groupDescription: activeGroup != null ? activeGroup.firstMetadataValue('dc.description') : '',
208 - });
209 - } else {
210 - this.formModel = [
211 - this.groupName,
212 - this.groupDescription,
213 - ];
214 - this.formGroup.patchValue({
215 - groupName: activeGroup != null ? activeGroup.name : '',
216 - groupDescription: activeGroup != null ? activeGroup.firstMetadataValue('dc.description') : '',
217 - });
218 - }
207 +
208 + if (linkedObject?.name) {
209 + // this.formModel = [
210 + // this.groupName,
211 + // this.groupCommunity,
212 + // this.groupDescription,
213 + // ];
214 + this.formBuilderService.insertFormGroupControl(1, this.formGroup, this.formModel, this.groupCommunity);
215 + this.formGroup.patchValue({
216 + groupName: activeGroup != null ? activeGroup.name : '',
217 + groupCommunity: linkedObject?.name ?? '',
218 + groupDescription: activeGroup != null ? activeGroup.firstMetadataValue('dc.description') : '',
219 + });
220 + } else {
221 + this.formModel = [
222 + this.groupName,
223 + this.groupDescription,
224 + ];
225 + this.formGroup.patchValue({
226 + groupName: activeGroup != null ? activeGroup.name : '',
227 + groupDescription: activeGroup != null ? activeGroup.firstMetadataValue('dc.description') : '',
228 + });
229 + }
230 + setTimeout(() => {
219 231 if (!canEdit || activeGroup.permanent) {
220 232 this.formGroup.disable();
221 233 }
222 - });
234 + }, 200);
223 235 }
224 236 })
225 237 );
226 238 });
227 239 }
228 240
229 241 /**
230 242 * Stop editing the currently selected group
231 243 */
232 244 onCancel() {

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut