group-form.component.ts (dspace-angular-dspace-7.0) | : | group-form.component.ts (dspace-angular-dspace-7.1) | ||
---|---|---|---|---|
skipping to change at line 17 | skipping to change at line 17 | |||
DynamicFormLayout, | DynamicFormLayout, | |||
DynamicInputModel, | DynamicInputModel, | |||
DynamicTextAreaModel | DynamicTextAreaModel | |||
} from '@ng-dynamic-forms/core'; | } from '@ng-dynamic-forms/core'; | |||
import { TranslateService } from '@ngx-translate/core'; | import { TranslateService } from '@ngx-translate/core'; | |||
import { | import { | |||
ObservedValueOf, | ObservedValueOf, | |||
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-pa ge-routing-paths'; | import { getCommunityEditRolesRoute } from '../../../community-page/community-pa ge-routing-paths'; | |||
import { DSpaceObjectDataService } from '../../../core/data/dspace-object-data.s ervice'; | import { DSpaceObjectDataService } from '../../../core/data/dspace-object-data.s ervice'; | |||
import { AuthorizationDataService } from '../../../core/data/feature-authorizati on/authorization-data.service'; | import { AuthorizationDataService } from '../../../core/data/feature-authorizati on/authorization-data.service'; | |||
import { FeatureID } from '../../../core/data/feature-authorization/feature-id'; | import { FeatureID } from '../../../core/data/feature-authorization/feature-id'; | |||
import { PaginatedList } from '../../../core/data/paginated-list.model'; | import { PaginatedList } from '../../../core/data/paginated-list.model'; | |||
import { RemoteData } from '../../../core/data/remote-data'; | import { RemoteData } from '../../../core/data/remote-data'; | |||
import { RequestService } from '../../../core/data/request.service'; | import { RequestService } from '../../../core/data/request.service'; | |||
import { EPersonDataService } from '../../../core/eperson/eperson-data.service'; | import { EPersonDataService } from '../../../core/eperson/eperson-data.service'; | |||
import { GroupDataService } from '../../../core/eperson/group-data.service'; | import { GroupDataService } from '../../../core/eperson/group-data.service'; | |||
import { Group } from '../../../core/eperson/models/group.model'; | import { Group } from '../../../core/eperson/models/group.model'; | |||
import { Collection } from '../../../core/shared/collection.model'; | import { Collection } from '../../../core/shared/collection.model'; | |||
import { Community } from '../../../core/shared/community.model'; | import { Community } from '../../../core/shared/community.model'; | |||
import { DSpaceObject } from '../../../core/shared/dspace-object.model'; | 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/c onfirmation-modal.component'; | import { ConfirmationModalComponent } from '../../../shared/confirmation-modal/c onfirmation-modal.component'; | |||
import { hasValue, isNotEmpty, hasValueOperator } from '../../../shared/empty.ut il'; | import { hasValue, isNotEmpty, hasValueOperator } from '../../../shared/empty.ut il'; | |||
import { FormBuilderService } from '../../../shared/form/builder/form-builder.se rvice'; | import { FormBuilderService } from '../../../shared/form/builder/form-builder.se rvice'; | |||
import { NotificationsService } from '../../../shared/notifications/notification s.service'; | import { NotificationsService } from '../../../shared/notifications/notification s.service'; | |||
import { followLink } from '../../../shared/utils/follow-link-config.model'; | import { followLink } from '../../../shared/utils/follow-link-config.model'; | |||
import { NoContent } from '../../../core/shared/NoContent.model'; | import { NoContent } from '../../../core/shared/NoContent.model'; | |||
import { Operation } from 'fast-json-patch'; | import { Operation } from 'fast-json-patch'; | |||
skipping to change at line 68 | skipping to change at line 69 | |||
/** | /** | |||
* A unique id used for ds-form | * A unique id used for ds-form | |||
*/ | */ | |||
formId = 'group-form'; | formId = 'group-form'; | |||
/** | /** | |||
* Dynamic models for the inputs of form | * Dynamic models for the inputs of form | |||
*/ | */ | |||
groupName: DynamicInputModel; | groupName: DynamicInputModel; | |||
groupCommunity: DynamicInputModel; | ||||
groupDescription: DynamicTextAreaModel; | groupDescription: DynamicTextAreaModel; | |||
/** | /** | |||
* A list of all dynamic input models | * A list of all dynamic input models | |||
*/ | */ | |||
formModel: DynamicFormControlModel[]; | formModel: DynamicFormControlModel[]; | |||
/** | /** | |||
* Layout used for structuring the form inputs | * Layout used for structuring the form inputs | |||
*/ | */ | |||
skipping to change at line 128 | skipping to change at line 130 | |||
*/ | */ | |||
canEdit$: Observable<boolean>; | canEdit$: Observable<boolean>; | |||
/** | /** | |||
* The AlertType enumeration | * The AlertType enumeration | |||
* @type {AlertType} | * @type {AlertType} | |||
*/ | */ | |||
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() { | |||
this.initialisePage(); | this.initialisePage(); | |||
} | } | |||
initialisePage() { | initialisePage() { | |||
this.subs.push(this.route.params.subscribe((params) => { | this.subs.push(this.route.params.subscribe((params) => { | |||
if (params.groupId !== 'newGroup') { | if (params.groupId !== 'newGroup') { | |||
this.setActiveGroup(params.groupId); | this.setActiveGroup(params.groupId); | |||
skipping to change at line 163 | skipping to change at line 165 | |||
return observableCombineLatest( | return observableCombineLatest( | |||
this.authorizationService.isAuthorized(FeatureID.CanDelete, isNotEmpty (group) ? group.self : undefined), | this.authorizationService.isAuthorized(FeatureID.CanDelete, isNotEmpty (group) ? group.self : undefined), | |||
this.hasLinkedDSO(group), | this.hasLinkedDSO(group), | |||
(isAuthorized: ObservedValueOf<Observable<boolean>>, hasLinkedDSO: Obs ervedValueOf<Observable<boolean>>) => { | (isAuthorized: ObservedValueOf<Observable<boolean>>, hasLinkedDSO: Obs ervedValueOf<Observable<boolean>>) => { | |||
return isAuthorized && !hasLinkedDSO; | return isAuthorized && !hasLinkedDSO; | |||
}); | }); | |||
}) | }) | |||
); | ); | |||
observableCombineLatest( | observableCombineLatest( | |||
this.translateService.get(`${this.messagePrefix}.groupName`), | this.translateService.get(`${this.messagePrefix}.groupName`), | |||
this.translateService.get(`${this.messagePrefix}.groupCommunity`), | ||||
this.translateService.get(`${this.messagePrefix}.groupDescription`) | this.translateService.get(`${this.messagePrefix}.groupDescription`) | |||
).subscribe(([groupName, groupDescription]) => { | ).subscribe(([groupName, groupCommunity, groupDescription]) => { | |||
this.groupName = new DynamicInputModel({ | this.groupName = new DynamicInputModel({ | |||
id: 'groupName', | id: 'groupName', | |||
label: groupName, | label: groupName, | |||
name: 'groupName', | name: 'groupName', | |||
validators: { | validators: { | |||
required: null, | required: null, | |||
}, | }, | |||
required: true, | required: true, | |||
}); | }); | |||
this.groupCommunity = new DynamicInputModel({ | ||||
id: 'groupCommunity', | ||||
label: groupCommunity, | ||||
name: 'groupCommunity', | ||||
required: false, | ||||
readOnly: true, | ||||
}); | ||||
this.groupDescription = new DynamicTextAreaModel({ | this.groupDescription = new DynamicTextAreaModel({ | |||
id: 'groupDescription', | id: 'groupDescription', | |||
label: groupDescription, | label: groupDescription, | |||
name: 'groupDescription', | name: 'groupDescription', | |||
required: false, | required: false, | |||
}); | }); | |||
this.formModel = [ | this.formModel = [ | |||
this.groupName, | this.groupName, | |||
this.groupDescription, | this.groupDescription, | |||
]; | ]; | |||
this.formGroup = this.formBuilderService.createFormGroup(this.formModel); | this.formGroup = this.formBuilderService.createFormGroup(this.formModel); | |||
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((acti | ||||
veGroup) => this.getLinkedDSO(activeGroup).pipe(getFirstSucceededRemoteDataPaylo | ||||
ad()))) | ||||
).subscribe(([activeGroup, canEdit, linkedObject]) => { | ||||
if (activeGroup != null) { | if (activeGroup != null) { | |||
this.groupBeingEdited = activeGroup; | this.groupBeingEdited = activeGroup; | |||
this.formGroup.patchValue({ | ||||
groupName: activeGroup != null ? activeGroup.name : '', | if (linkedObject?.name) { | |||
groupDescription: activeGroup != null ? activeGroup.firstMetadataV | this.formBuilderService.insertFormGroupControl(1, this.formGroup, | |||
alue('dc.description') : '', | this.formModel, this.groupCommunity); | |||
}); | this.formGroup.patchValue({ | |||
if (!canEdit || activeGroup.permanent) { | groupName: activeGroup.name, | |||
this.formGroup.disable(); | groupCommunity: linkedObject?.name ?? '', | |||
groupDescription: activeGroup.firstMetadataValue('dc.description | ||||
'), | ||||
}); | ||||
} else { | ||||
this.formModel = [ | ||||
this.groupName, | ||||
this.groupDescription, | ||||
]; | ||||
this.formGroup.patchValue({ | ||||
groupName: activeGroup.name, | ||||
groupDescription: activeGroup.firstMetadataValue('dc.description | ||||
'), | ||||
}); | ||||
} | } | |||
setTimeout(() => { | ||||
if (!canEdit || activeGroup.permanent) { | ||||
this.formGroup.disable(); | ||||
} | ||||
}, 200); | ||||
} | } | |||
}) | }) | |||
); | ); | |||
}); | }); | |||
} | } | |||
/** | /** | |||
* Stop editing the currently selected group | * Stop editing the currently selected group | |||
*/ | */ | |||
onCancel() { | onCancel() { | |||
skipping to change at line 420 | skipping to change at line 449 | |||
} | } | |||
/** | /** | |||
* Check if group has a linked object (community or collection linked to a wor kflow group) | * Check if group has a linked object (community or collection linked to a wor kflow group) | |||
* @param group | * @param group | |||
*/ | */ | |||
hasLinkedDSO(group: Group): Observable<boolean> { | hasLinkedDSO(group: Group): Observable<boolean> { | |||
if (hasValue(group) && hasValue(group._links.object.href)) { | if (hasValue(group) && hasValue(group._links.object.href)) { | |||
return this.getLinkedDSO(group).pipe( | return this.getLinkedDSO(group).pipe( | |||
map((rd: RemoteData<DSpaceObject>) => { | map((rd: RemoteData<DSpaceObject>) => { | |||
if (hasValue(rd) && hasValue(rd.payload)) { | return hasValue(rd) && hasValue(rd.payload); | |||
return true; | ||||
} else { | ||||
return false; | ||||
} | ||||
}), | }), | |||
catchError(() => observableOf(false)), | catchError(() => observableOf(false)), | |||
); | ); | |||
} | } | |||
} | } | |||
/** | /** | |||
* Get group's linked object if it has one (community or collection linked to a workflow group) | * Get group's linked object if it has one (community or collection linked to a workflow group) | |||
* @param group | * @param group | |||
*/ | */ | |||
End of changes. 12 change blocks. | ||||
28 lines changed or deleted | 57 lines changed or added |