mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Merge remote-tracking branch 'origin/main' into CST-3782-fix-repeatable-fields
# Conflicts: # src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.spec.ts # src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts
This commit is contained in:
@@ -143,7 +143,9 @@ export class GroupFormComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
initialisePage() {
|
initialisePage() {
|
||||||
this.subs.push(this.route.params.subscribe((params) => {
|
this.subs.push(this.route.params.subscribe((params) => {
|
||||||
|
if (params.groupId !== 'newGroup') {
|
||||||
this.setActiveGroup(params.groupId);
|
this.setActiveGroup(params.groupId);
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
this.canEdit$ = this.groupDataService.getActiveGroup().pipe(
|
this.canEdit$ = this.groupDataService.getActiveGroup().pipe(
|
||||||
hasValueOperator(),
|
hasValueOperator(),
|
||||||
@@ -225,14 +227,12 @@ export class GroupFormComponent implements OnInit, OnDestroy {
|
|||||||
{
|
{
|
||||||
value: this.groupDescription.value
|
value: this.groupDescription.value
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if (group === null) {
|
if (group === null) {
|
||||||
console.log('createNewGroup', values);
|
|
||||||
this.createNewGroup(values);
|
this.createNewGroup(values);
|
||||||
} else {
|
} else {
|
||||||
console.log('editGroup', group);
|
|
||||||
this.editGroup(group);
|
this.editGroup(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,10 +24,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<ds-pagination *ngIf="(searchResults$ | async)?.payload?.totalElements > 0"
|
<ds-pagination *ngIf="(ePeopleSearchDtos | async)?.totalElements > 0"
|
||||||
[paginationOptions]="configSearch"
|
[paginationOptions]="configSearch"
|
||||||
[pageInfoState]="(searchResults$ | async)?.payload"
|
[pageInfoState]="(ePeopleSearchDtos | async)"
|
||||||
[collectionSize]="(searchResults$ | async)?.payload?.totalElements"
|
[collectionSize]="(ePeopleSearchDtos | async)?.totalElements"
|
||||||
[hideGear]="true"
|
[hideGear]="true"
|
||||||
[hidePagerWhenSinglePage]="true"
|
[hidePagerWhenSinglePage]="true"
|
||||||
(pageChange)="onPageChangeSearch($event)">
|
(pageChange)="onPageChangeSearch($event)">
|
||||||
@@ -42,23 +42,23 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr *ngFor="let ePerson of (searchResults$ | async)?.payload?.page">
|
<tr *ngFor="let ePerson of (ePeopleSearchDtos | async)?.page">
|
||||||
<td>{{ePerson.id}}</td>
|
<td>{{ePerson.eperson.id}}</td>
|
||||||
<td><a (click)="ePersonDataService.startEditingNewEPerson(ePerson)"
|
<td><a (click)="ePersonDataService.startEditingNewEPerson(ePerson.eperson)"
|
||||||
[routerLink]="[ePersonDataService.getEPeoplePageRouterLink()]">{{ePerson.name}}</a></td>
|
[routerLink]="[ePersonDataService.getEPeoplePageRouterLink()]">{{ePerson.eperson.name}}</a></td>
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-group edit-field">
|
<div class="btn-group edit-field">
|
||||||
<button *ngIf="(isMemberOfGroup(ePerson) | async)"
|
<button *ngIf="(ePerson.memberOfGroup)"
|
||||||
(click)="deleteMemberFromGroup(ePerson)"
|
(click)="deleteMemberFromGroup(ePerson)"
|
||||||
class="btn btn-outline-danger btn-sm"
|
class="btn btn-outline-danger btn-sm"
|
||||||
title="{{messagePrefix + '.table.edit.buttons.remove' | translate: {name: ePerson.name} }}">
|
title="{{messagePrefix + '.table.edit.buttons.remove' | translate: {name: ePerson.eperson.name} }}">
|
||||||
<i class="fas fa-trash-alt fa-fw"></i>
|
<i class="fas fa-trash-alt fa-fw"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button *ngIf="!(isMemberOfGroup(ePerson) | async)"
|
<button *ngIf="!(ePerson.memberOfGroup)"
|
||||||
(click)="addMemberToGroup(ePerson)"
|
(click)="addMemberToGroup(ePerson)"
|
||||||
class="btn btn-outline-primary btn-sm"
|
class="btn btn-outline-primary btn-sm"
|
||||||
title="{{messagePrefix + '.table.edit.buttons.add' | translate: {name: ePerson.name} }}">
|
title="{{messagePrefix + '.table.edit.buttons.add' | translate: {name: ePerson.eperson.name} }}">
|
||||||
<i class="fas fa-plus fa-fw"></i>
|
<i class="fas fa-plus fa-fw"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
|
|
||||||
</ds-pagination>
|
</ds-pagination>
|
||||||
|
|
||||||
<div *ngIf="(searchResults$ | async)?.payload?.totalElements == 0 && searchDone"
|
<div *ngIf="(ePeopleSearchDtos | async)?.totalElements == 0 && searchDone"
|
||||||
class="alert alert-info w-100 mb-2"
|
class="alert alert-info w-100 mb-2"
|
||||||
role="alert">
|
role="alert">
|
||||||
{{messagePrefix + '.no-items' | translate}}
|
{{messagePrefix + '.no-items' | translate}}
|
||||||
@@ -78,10 +78,10 @@
|
|||||||
|
|
||||||
<h4>{{messagePrefix + '.headMembers' | translate}}</h4>
|
<h4>{{messagePrefix + '.headMembers' | translate}}</h4>
|
||||||
|
|
||||||
<ds-pagination *ngIf="(members$ | async)?.payload?.totalElements > 0"
|
<ds-pagination *ngIf="(ePeopleMembersOfGroupDtos | async)?.totalElements > 0"
|
||||||
[paginationOptions]="config"
|
[paginationOptions]="config"
|
||||||
[pageInfoState]="(members$ | async)?.payload"
|
[pageInfoState]="(ePeopleMembersOfGroupDtos | async)"
|
||||||
[collectionSize]="(members$ | async)?.payload?.totalElements"
|
[collectionSize]="(ePeopleMembersOfGroupDtos | async)?.totalElements"
|
||||||
[hideGear]="true"
|
[hideGear]="true"
|
||||||
[hidePagerWhenSinglePage]="true"
|
[hidePagerWhenSinglePage]="true"
|
||||||
(pageChange)="onPageChange($event)">
|
(pageChange)="onPageChange($event)">
|
||||||
@@ -96,15 +96,15 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr *ngFor="let ePerson of (members$ | async)?.payload?.page">
|
<tr *ngFor="let ePerson of (ePeopleMembersOfGroupDtos | async)?.page">
|
||||||
<td>{{ePerson.id}}</td>
|
<td>{{ePerson.eperson.id}}</td>
|
||||||
<td><a (click)="ePersonDataService.startEditingNewEPerson(ePerson)"
|
<td><a (click)="ePersonDataService.startEditingNewEPerson(ePerson.eperson)"
|
||||||
[routerLink]="[ePersonDataService.getEPeoplePageRouterLink()]">{{ePerson.name}}</a></td>
|
[routerLink]="[ePersonDataService.getEPeoplePageRouterLink()]">{{ePerson.eperson.name}}</a></td>
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-group edit-field">
|
<div class="btn-group edit-field">
|
||||||
<button (click)="deleteMemberFromGroup(ePerson)"
|
<button (click)="deleteMemberFromGroup(ePerson)"
|
||||||
class="btn btn-outline-danger btn-sm"
|
class="btn btn-outline-danger btn-sm"
|
||||||
title="{{messagePrefix + '.table.edit.buttons.remove' | translate: {name: ePerson.name} }}">
|
title="{{messagePrefix + '.table.edit.buttons.remove' | translate: {name: ePerson.eperson.name} }}">
|
||||||
<i class="fas fa-trash-alt fa-fw"></i>
|
<i class="fas fa-trash-alt fa-fw"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -116,7 +116,7 @@
|
|||||||
|
|
||||||
</ds-pagination>
|
</ds-pagination>
|
||||||
|
|
||||||
<div *ngIf="(members$ | async)?.payload?.totalElements == 0" class="alert alert-info w-100 mb-2"
|
<div *ngIf="(ePeopleMembersOfGroupDtos | async) == undefined || (ePeopleMembersOfGroupDtos | async)?.totalElements == 0" class="alert alert-info w-100 mb-2"
|
||||||
role="alert">
|
role="alert">
|
||||||
{{messagePrefix + '.no-members-yet' | translate}}
|
{{messagePrefix + '.no-members-yet' | translate}}
|
||||||
</div>
|
</div>
|
||||||
|
@@ -2,9 +2,15 @@ import { Component, Input, OnDestroy, OnInit } from '@angular/core';
|
|||||||
import { FormBuilder } from '@angular/forms';
|
import { FormBuilder } from '@angular/forms';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { Observable, of as observableOf, Subscription, BehaviorSubject } from 'rxjs';
|
import {
|
||||||
import { map, mergeMap, take } from 'rxjs/operators';
|
Observable,
|
||||||
import { PaginatedList } from '../../../../../core/data/paginated-list.model';
|
of as observableOf,
|
||||||
|
Subscription,
|
||||||
|
BehaviorSubject,
|
||||||
|
combineLatest as observableCombineLatest, ObservedValueOf,
|
||||||
|
} from 'rxjs';
|
||||||
|
import { map, mergeMap, switchMap, take } from 'rxjs/operators';
|
||||||
|
import {buildPaginatedList, PaginatedList} from '../../../../../core/data/paginated-list.model';
|
||||||
import { RemoteData } from '../../../../../core/data/remote-data';
|
import { RemoteData } from '../../../../../core/data/remote-data';
|
||||||
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';
|
||||||
@@ -13,18 +19,19 @@ import { Group } from '../../../../../core/eperson/models/group.model';
|
|||||||
import {
|
import {
|
||||||
getRemoteDataPayload,
|
getRemoteDataPayload,
|
||||||
getFirstSucceededRemoteData,
|
getFirstSucceededRemoteData,
|
||||||
getFirstCompletedRemoteData
|
getFirstCompletedRemoteData, getAllCompletedRemoteData
|
||||||
} from '../../../../../core/shared/operators';
|
} from '../../../../../core/shared/operators';
|
||||||
import { NotificationsService } from '../../../../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../../../../shared/notifications/notifications.service';
|
||||||
import { PaginationComponentOptions } from '../../../../../shared/pagination/pagination-component-options.model';
|
import { PaginationComponentOptions } from '../../../../../shared/pagination/pagination-component-options.model';
|
||||||
|
import {EpersonDtoModel} from '../../../../../core/eperson/models/eperson-dto.model';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keys to keep track of specific subscriptions
|
* Keys to keep track of specific subscriptions
|
||||||
*/
|
*/
|
||||||
enum SubKey {
|
enum SubKey {
|
||||||
Members,
|
|
||||||
ActiveGroup,
|
ActiveGroup,
|
||||||
SearchResults,
|
MembersDTO,
|
||||||
|
SearchResultsDTO,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -42,11 +49,11 @@ export class MembersListComponent implements OnInit, OnDestroy {
|
|||||||
/**
|
/**
|
||||||
* EPeople being displayed in search result, initially all members, after search result of search
|
* EPeople being displayed in search result, initially all members, after search result of search
|
||||||
*/
|
*/
|
||||||
searchResults$: BehaviorSubject<RemoteData<PaginatedList<EPerson>>> = new BehaviorSubject(undefined);
|
ePeopleSearchDtos: BehaviorSubject<PaginatedList<EpersonDtoModel>> = new BehaviorSubject<PaginatedList<EpersonDtoModel>>(undefined);
|
||||||
/**
|
/**
|
||||||
* List of EPeople members of currently active group being edited
|
* List of EPeople members of currently active group being edited
|
||||||
*/
|
*/
|
||||||
members$: BehaviorSubject<RemoteData<PaginatedList<EPerson>>> = new BehaviorSubject(undefined);
|
ePeopleMembersOfGroupDtos: BehaviorSubject<PaginatedList<EpersonDtoModel>> = new BehaviorSubject<PaginatedList<EpersonDtoModel>>(undefined);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pagination config used to display the list of EPeople that are result of EPeople search
|
* Pagination config used to display the list of EPeople that are result of EPeople search
|
||||||
@@ -130,15 +137,59 @@ export class MembersListComponent implements OnInit, OnDestroy {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
private retrieveMembers(page: number) {
|
private retrieveMembers(page: number) {
|
||||||
this.unsubFrom(SubKey.Members);
|
this.unsubFrom(SubKey.MembersDTO);
|
||||||
this.subs.set(
|
this.subs.set(SubKey.MembersDTO, this.ePersonDataService.findAllByHref(this.groupBeingEdited._links.epersons.href, {
|
||||||
SubKey.Members,
|
|
||||||
this.ePersonDataService.findAllByHref(this.groupBeingEdited._links.epersons.href, {
|
|
||||||
currentPage: page,
|
currentPage: page,
|
||||||
elementsPerPage: this.config.pageSize
|
elementsPerPage: this.config.pageSize
|
||||||
|
}).pipe(
|
||||||
|
getAllCompletedRemoteData(),
|
||||||
|
map((rd: RemoteData<any>) => {
|
||||||
|
if (rd.hasFailed) {
|
||||||
|
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure', {cause: rd.errorMessage}));
|
||||||
|
} else {
|
||||||
|
return rd;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
switchMap((epersonListRD: RemoteData<PaginatedList<EPerson>>) => {
|
||||||
|
const dtos$ = observableCombineLatest(...epersonListRD.payload.page.map((member: EPerson) => {
|
||||||
|
const dto$: Observable<EpersonDtoModel> = observableCombineLatest(
|
||||||
|
this.isMemberOfGroup(member), (isMember: ObservedValueOf<Observable<boolean>>) => {
|
||||||
|
const epersonDtoModel: EpersonDtoModel = new EpersonDtoModel();
|
||||||
|
epersonDtoModel.eperson = member;
|
||||||
|
epersonDtoModel.memberOfGroup = isMember;
|
||||||
|
return epersonDtoModel;
|
||||||
|
});
|
||||||
|
return dto$;
|
||||||
|
}));
|
||||||
|
return dtos$.pipe(map((dtos: EpersonDtoModel[]) => {
|
||||||
|
return buildPaginatedList(epersonListRD.payload.pageInfo, dtos);
|
||||||
|
}));
|
||||||
|
}))
|
||||||
|
.subscribe((paginatedListOfDTOs: PaginatedList<EpersonDtoModel>) => {
|
||||||
|
this.ePeopleMembersOfGroupDtos.next(paginatedListOfDTOs);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not the given ePerson is a member of the group currently being edited
|
||||||
|
* @param possibleMember EPerson that is a possible member (being tested) of the group currently being edited
|
||||||
|
*/
|
||||||
|
isMemberOfGroup(possibleMember: EPerson): Observable<boolean> {
|
||||||
|
return this.groupDataService.getActiveGroup().pipe(take(1),
|
||||||
|
mergeMap((group: Group) => {
|
||||||
|
if (group != null) {
|
||||||
|
return this.ePersonDataService.findAllByHref(group._links.epersons.href, {
|
||||||
|
currentPage: 1,
|
||||||
|
elementsPerPage: 9999
|
||||||
|
}, false)
|
||||||
|
.pipe(
|
||||||
|
getFirstSucceededRemoteData(),
|
||||||
|
getRemoteDataPayload(),
|
||||||
|
map((listEPeopleInGroup: PaginatedList<EPerson>) => listEPeopleInGroup.page.filter((ePersonInList: EPerson) => ePersonInList.id === possibleMember.id)),
|
||||||
|
map((epeople: EPerson[]) => epeople.length > 0));
|
||||||
|
} else {
|
||||||
|
return observableOf(false);
|
||||||
}
|
}
|
||||||
).subscribe((rd: RemoteData<PaginatedList<EPerson>>) => {
|
|
||||||
this.members$.next(rd);
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,11 +211,12 @@ export class MembersListComponent implements OnInit, OnDestroy {
|
|||||||
* Deletes a given EPerson from the members list of the group currently being edited
|
* Deletes a given EPerson from the members list of the group currently being edited
|
||||||
* @param ePerson EPerson we want to delete as member from group that is currently being edited
|
* @param ePerson EPerson we want to delete as member from group that is currently being edited
|
||||||
*/
|
*/
|
||||||
deleteMemberFromGroup(ePerson: EPerson) {
|
deleteMemberFromGroup(ePerson: EpersonDtoModel) {
|
||||||
this.groupDataService.getActiveGroup().pipe(take(1)).subscribe((activeGroup: Group) => {
|
this.groupDataService.getActiveGroup().pipe(take(1)).subscribe((activeGroup: Group) => {
|
||||||
if (activeGroup != null) {
|
if (activeGroup != null) {
|
||||||
const response = this.groupDataService.deleteMemberFromGroup(activeGroup, ePerson);
|
const response = this.groupDataService.deleteMemberFromGroup(activeGroup, ePerson.eperson);
|
||||||
this.showNotifications('deleteMember', response, ePerson.name, activeGroup);
|
this.showNotifications('deleteMember', response, ePerson.eperson.name, activeGroup);
|
||||||
|
this.search({ scope: this.currentSearchScope, query: this.currentSearchQuery });
|
||||||
} else {
|
} else {
|
||||||
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure.noActiveGroup'));
|
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure.noActiveGroup'));
|
||||||
}
|
}
|
||||||
@@ -175,40 +227,18 @@ export class MembersListComponent implements OnInit, OnDestroy {
|
|||||||
* Adds a given EPerson to the members list of the group currently being edited
|
* Adds a given EPerson to the members list of the group currently being edited
|
||||||
* @param ePerson EPerson we want to add as member to group that is currently being edited
|
* @param ePerson EPerson we want to add as member to group that is currently being edited
|
||||||
*/
|
*/
|
||||||
addMemberToGroup(ePerson: EPerson) {
|
addMemberToGroup(ePerson: EpersonDtoModel) {
|
||||||
|
ePerson.memberOfGroup = true;
|
||||||
this.groupDataService.getActiveGroup().pipe(take(1)).subscribe((activeGroup: Group) => {
|
this.groupDataService.getActiveGroup().pipe(take(1)).subscribe((activeGroup: Group) => {
|
||||||
if (activeGroup != null) {
|
if (activeGroup != null) {
|
||||||
const response = this.groupDataService.addMemberToGroup(activeGroup, ePerson);
|
const response = this.groupDataService.addMemberToGroup(activeGroup, ePerson.eperson);
|
||||||
this.showNotifications('addMember', response, ePerson.name, activeGroup);
|
this.showNotifications('addMember', response, ePerson.eperson.name, activeGroup);
|
||||||
} else {
|
} else {
|
||||||
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure.noActiveGroup'));
|
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure.noActiveGroup'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether or not the given ePerson is a member of the group currently being edited
|
|
||||||
* @param possibleMember EPerson that is a possible member (being tested) of the group currently being edited
|
|
||||||
*/
|
|
||||||
isMemberOfGroup(possibleMember: EPerson): Observable<boolean> {
|
|
||||||
return this.groupDataService.getActiveGroup().pipe(take(1),
|
|
||||||
mergeMap((group: Group) => {
|
|
||||||
if (group != null) {
|
|
||||||
return this.ePersonDataService.findAllByHref(group._links.epersons.href, {
|
|
||||||
currentPage: 1,
|
|
||||||
elementsPerPage: 9999
|
|
||||||
})
|
|
||||||
.pipe(
|
|
||||||
getFirstSucceededRemoteData(),
|
|
||||||
getRemoteDataPayload(),
|
|
||||||
map((listEPeopleInGroup: PaginatedList<EPerson>) => listEPeopleInGroup.page.filter((ePersonInList: EPerson) => ePersonInList.id === possibleMember.id)),
|
|
||||||
map((epeople: EPerson[]) => epeople.length > 0));
|
|
||||||
} else {
|
|
||||||
return observableOf(false);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search in the EPeople by name, email or metadata
|
* Search in the EPeople by name, email or metadata
|
||||||
* @param data Contains scope and query param
|
* @param data Contains scope and query param
|
||||||
@@ -228,12 +258,37 @@ export class MembersListComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
this.searchDone = true;
|
this.searchDone = true;
|
||||||
|
|
||||||
this.unsubFrom(SubKey.SearchResults);
|
this.unsubFrom(SubKey.SearchResultsDTO);
|
||||||
this.subs.set(SubKey.SearchResults, this.ePersonDataService.searchByScope(this.currentSearchScope, this.currentSearchQuery, {
|
this.subs.set(SubKey.SearchResultsDTO,
|
||||||
|
this.ePersonDataService.searchByScope(this.currentSearchScope, this.currentSearchQuery, {
|
||||||
currentPage: this.configSearch.currentPage,
|
currentPage: this.configSearch.currentPage,
|
||||||
elementsPerPage: this.configSearch.pageSize
|
elementsPerPage: this.configSearch.pageSize
|
||||||
}).subscribe((rd: RemoteData<PaginatedList<EPerson>>) => {
|
}, false).pipe(
|
||||||
this.searchResults$.next(rd);
|
getAllCompletedRemoteData(),
|
||||||
|
map((rd: RemoteData<any>) => {
|
||||||
|
if (rd.hasFailed) {
|
||||||
|
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure', {cause: rd.errorMessage}));
|
||||||
|
} else {
|
||||||
|
return rd;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
switchMap((epersonListRD: RemoteData<PaginatedList<EPerson>>) => {
|
||||||
|
const dtos$ = observableCombineLatest(...epersonListRD.payload.page.map((member: EPerson) => {
|
||||||
|
const dto$: Observable<EpersonDtoModel> = observableCombineLatest(
|
||||||
|
this.isMemberOfGroup(member), (isMember: ObservedValueOf<Observable<boolean>>) => {
|
||||||
|
const epersonDtoModel: EpersonDtoModel = new EpersonDtoModel();
|
||||||
|
epersonDtoModel.eperson = member;
|
||||||
|
epersonDtoModel.memberOfGroup = isMember;
|
||||||
|
return epersonDtoModel;
|
||||||
|
});
|
||||||
|
return dto$;
|
||||||
|
}));
|
||||||
|
return dtos$.pipe(map((dtos: EpersonDtoModel[]) => {
|
||||||
|
return buildPaginatedList(epersonListRD.payload.pageInfo, dtos);
|
||||||
|
}));
|
||||||
|
}))
|
||||||
|
.subscribe((paginatedListOfDTOs: PaginatedList<EpersonDtoModel>) => {
|
||||||
|
this.ePeopleSearchDtos.next(paginatedListOfDTOs);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
<button class="mr-auto btn btn-success"
|
<button class="mr-auto btn btn-success"
|
||||||
[routerLink]="['newGroup']">
|
[routerLink]="['newGroup']">
|
||||||
<i class="fas fa-plus"></i>
|
<i class="fas fa-plus"></i>
|
||||||
<span class="d-none d-sm-inline"> {{messagePrefix + 'button.add' | translate}}</span>
|
<span class="d-none d-sm-inline">{{messagePrefix + 'button.add' | translate}}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -45,7 +45,6 @@
|
|||||||
<th scope="col">{{messagePrefix + 'table.id' | translate}}</th>
|
<th scope="col">{{messagePrefix + 'table.id' | translate}}</th>
|
||||||
<th scope="col">{{messagePrefix + 'table.name' | translate}}</th>
|
<th scope="col">{{messagePrefix + 'table.name' | translate}}</th>
|
||||||
<th scope="col">{{messagePrefix + 'table.members' | translate}}</th>
|
<th scope="col">{{messagePrefix + 'table.members' | translate}}</th>
|
||||||
<!-- <th scope="col">{{messagePrefix + 'table.comcol' | translate}}</th>-->
|
|
||||||
<th>{{messagePrefix + 'table.edit' | translate}}</th>
|
<th>{{messagePrefix + 'table.edit' | translate}}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -53,8 +52,7 @@
|
|||||||
<tr *ngFor="let groupDto of (groupsDto$ | async)?.page">
|
<tr *ngFor="let groupDto of (groupsDto$ | async)?.page">
|
||||||
<td>{{groupDto.group.id}}</td>
|
<td>{{groupDto.group.id}}</td>
|
||||||
<td>{{groupDto.group.name}}</td>
|
<td>{{groupDto.group.name}}</td>
|
||||||
<td>{{(getMembers(groupDto.group) | async)?.payload?.totalElements + (getSubgroups(groupDto.group) | async)?.payload?.totalElements}}</td>
|
<td>{{groupDto.epersons?.totalElements + groupDto.subgroups?.totalElements}}</td>
|
||||||
<!-- <td>{{getOptionalComColFromName(group.name)}}</td>-->
|
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-group edit-field">
|
<div class="btn-group edit-field">
|
||||||
<button [routerLink]="groupService.getGroupEditPageRouterLink(groupDto.group)"
|
<button [routerLink]="groupService.getGroupEditPageRouterLink(groupDto.group)"
|
||||||
@@ -63,7 +61,7 @@
|
|||||||
<i class="fas fa-edit fa-fw"></i>
|
<i class="fas fa-edit fa-fw"></i>
|
||||||
</button>
|
</button>
|
||||||
<button *ngIf="!groupDto.group?.permanent && groupDto.ableToDelete"
|
<button *ngIf="!groupDto.group?.permanent && groupDto.ableToDelete"
|
||||||
(click)="deleteGroup(groupDto.group)" class="btn btn-outline-danger btn-sm"
|
(click)="deleteGroup(groupDto)" class="btn btn-outline-danger btn-sm"
|
||||||
title="{{messagePrefix + 'table.edit.buttons.remove' | translate: {name: groupDto.group.name} }}">
|
title="{{messagePrefix + 'table.edit.buttons.remove' | translate: {name: groupDto.group.name} }}">
|
||||||
<i class="fas fa-trash-alt fa-fw"></i>
|
<i class="fas fa-trash-alt fa-fw"></i>
|
||||||
</button>
|
</button>
|
||||||
|
@@ -26,7 +26,7 @@ import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
|||||||
import {
|
import {
|
||||||
getAllSucceededRemoteDataPayload,
|
getAllSucceededRemoteDataPayload,
|
||||||
getFirstCompletedRemoteData,
|
getFirstCompletedRemoteData,
|
||||||
getAllSucceededRemoteData
|
getFirstSucceededRemoteData
|
||||||
} from '../../../core/shared/operators';
|
} from '../../../core/shared/operators';
|
||||||
import { PageInfo } from '../../../core/shared/page-info.model';
|
import { PageInfo } from '../../../core/shared/page-info.model';
|
||||||
import { hasValue } from '../../../shared/empty.util';
|
import { hasValue } from '../../../shared/empty.util';
|
||||||
@@ -55,15 +55,12 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
|||||||
currentPage: 1
|
currentPage: 1
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* A list of all the current Groups within the repository or the result of the search
|
|
||||||
*/
|
|
||||||
groups$: BehaviorSubject<RemoteData<PaginatedList<Group>>> = new BehaviorSubject<RemoteData<PaginatedList<Group>>>({} as any);
|
|
||||||
/**
|
/**
|
||||||
* A BehaviorSubject with the list of GroupDtoModel objects made from the Groups in the repository or
|
* A BehaviorSubject with the list of GroupDtoModel objects made from the Groups in the repository or
|
||||||
* as the result of the search
|
* as the result of the search
|
||||||
*/
|
*/
|
||||||
groupsDto$: BehaviorSubject<PaginatedList<GroupDtoModel>> = new BehaviorSubject<PaginatedList<GroupDtoModel>>({} as any);
|
groupsDto$: BehaviorSubject<PaginatedList<GroupDtoModel>> = new BehaviorSubject<PaginatedList<GroupDtoModel>>({} as any);
|
||||||
|
deletedGroupsIds: string[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An observable for the pageInfo, needed to pass to the pagination component
|
* An observable for the pageInfo, needed to pass to the pagination component
|
||||||
@@ -104,30 +101,6 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.search({ query: this.currentSearchQuery });
|
this.search({ query: this.currentSearchQuery });
|
||||||
|
|
||||||
this.subs.push(this.groups$.pipe(
|
|
||||||
getAllSucceededRemoteDataPayload(),
|
|
||||||
switchMap((groups: PaginatedList<Group>) => {
|
|
||||||
return observableCombineLatest(groups.page.map((group: Group) => {
|
|
||||||
return observableCombineLatest([
|
|
||||||
this.authorizationService.isAuthorized(FeatureID.CanDelete, hasValue(group) ? group.self : undefined),
|
|
||||||
this.hasLinkedDSO(group)
|
|
||||||
]).pipe(
|
|
||||||
map(([isAuthorized, hasLinkedDSO]: boolean[]) => {
|
|
||||||
const groupDtoModel: GroupDtoModel = new GroupDtoModel();
|
|
||||||
groupDtoModel.ableToDelete = isAuthorized && !hasLinkedDSO;
|
|
||||||
groupDtoModel.group = group;
|
|
||||||
return groupDtoModel;
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
})).pipe(map((dtos: GroupDtoModel[]) => {
|
|
||||||
return buildPaginatedList(groups.pageInfo, dtos);
|
|
||||||
}));
|
|
||||||
})).subscribe((value: PaginatedList<GroupDtoModel>) => {
|
|
||||||
this.groupsDto$.next(value);
|
|
||||||
this.pageInfoState$.next(value.pageInfo);
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -154,14 +127,42 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
|||||||
this.searchSub.unsubscribe();
|
this.searchSub.unsubscribe();
|
||||||
this.subs = this.subs.filter((sub: Subscription) => sub !== this.searchSub);
|
this.subs = this.subs.filter((sub: Subscription) => sub !== this.searchSub);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.searchSub = this.groupService.searchGroups(this.currentSearchQuery.trim(), {
|
this.searchSub = this.groupService.searchGroups(this.currentSearchQuery.trim(), {
|
||||||
currentPage: this.config.currentPage,
|
currentPage: this.config.currentPage,
|
||||||
elementsPerPage: this.config.pageSize
|
elementsPerPage: this.config.pageSize
|
||||||
}).pipe(
|
}).pipe(
|
||||||
getAllSucceededRemoteData()
|
getAllSucceededRemoteDataPayload(),
|
||||||
).subscribe((groupsRD: RemoteData<PaginatedList<Group>>) => {
|
switchMap((groups: PaginatedList<Group>) => {
|
||||||
this.groups$.next(groupsRD);
|
if (groups.page.length === 0) {
|
||||||
this.pageInfoState$.next(groupsRD.payload.pageInfo);
|
return observableOf(buildPaginatedList(groups.pageInfo, []));
|
||||||
|
}
|
||||||
|
return observableCombineLatest(groups.page.map((group: Group) => {
|
||||||
|
if (!this.deletedGroupsIds.includes(group.id)) {
|
||||||
|
return observableCombineLatest([
|
||||||
|
this.authorizationService.isAuthorized(FeatureID.CanDelete, hasValue(group) ? group.self : undefined),
|
||||||
|
this.hasLinkedDSO(group),
|
||||||
|
this.getSubgroups(group),
|
||||||
|
this.getMembers(group)
|
||||||
|
]).pipe(
|
||||||
|
map(([isAuthorized, hasLinkedDSO, subgroups, members]:
|
||||||
|
[boolean, boolean, RemoteData<PaginatedList<Group>>, RemoteData<PaginatedList<EPerson>>]) => {
|
||||||
|
const groupDtoModel: GroupDtoModel = new GroupDtoModel();
|
||||||
|
groupDtoModel.ableToDelete = isAuthorized && !hasLinkedDSO;
|
||||||
|
groupDtoModel.group = group;
|
||||||
|
groupDtoModel.subgroups = subgroups.payload;
|
||||||
|
groupDtoModel.epersons = members.payload;
|
||||||
|
return groupDtoModel;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})).pipe(map((dtos: GroupDtoModel[]) => {
|
||||||
|
return buildPaginatedList(groups.pageInfo, dtos);
|
||||||
|
}));
|
||||||
|
})).subscribe((value: PaginatedList<GroupDtoModel>) => {
|
||||||
|
this.groupsDto$.next(value);
|
||||||
|
this.pageInfoState$.next(value.pageInfo);
|
||||||
});
|
});
|
||||||
this.subs.push(this.searchSub);
|
this.subs.push(this.searchSub);
|
||||||
}
|
}
|
||||||
@@ -169,16 +170,17 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
|||||||
/**
|
/**
|
||||||
* Delete Group
|
* Delete Group
|
||||||
*/
|
*/
|
||||||
deleteGroup(group: Group) {
|
deleteGroup(group: GroupDtoModel) {
|
||||||
if (hasValue(group.id)) {
|
if (hasValue(group.group.id)) {
|
||||||
this.groupService.delete(group.id).pipe(getFirstCompletedRemoteData())
|
this.groupService.delete(group.group.id).pipe(getFirstCompletedRemoteData())
|
||||||
.subscribe((rd: RemoteData<NoContent>) => {
|
.subscribe((rd: RemoteData<NoContent>) => {
|
||||||
if (rd.hasSucceeded) {
|
if (rd.hasSucceeded) {
|
||||||
this.notificationsService.success(this.translateService.get(this.messagePrefix + 'notification.deleted.success', { name: group.name }));
|
this.deletedGroupsIds = [...this.deletedGroupsIds, group.group.id];
|
||||||
|
this.notificationsService.success(this.translateService.get(this.messagePrefix + 'notification.deleted.success', { name: group.group.name }));
|
||||||
this.reset();
|
this.reset();
|
||||||
} else {
|
} else {
|
||||||
this.notificationsService.error(
|
this.notificationsService.error(
|
||||||
this.translateService.get(this.messagePrefix + 'notification.deleted.failure.title', { name: group.name }),
|
this.translateService.get(this.messagePrefix + 'notification.deleted.failure.title', { name: group.group.name }),
|
||||||
this.translateService.get(this.messagePrefix + 'notification.deleted.failure.content', { cause: rd.errorMessage }));
|
this.translateService.get(this.messagePrefix + 'notification.deleted.failure.content', { cause: rd.errorMessage }));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -201,7 +203,7 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
|||||||
* @param group
|
* @param group
|
||||||
*/
|
*/
|
||||||
getMembers(group: Group): Observable<RemoteData<PaginatedList<EPerson>>> {
|
getMembers(group: Group): Observable<RemoteData<PaginatedList<EPerson>>> {
|
||||||
return this.ePersonDataService.findAllByHref(group._links.epersons.href);
|
return this.ePersonDataService.findAllByHref(group._links.epersons.href).pipe(getFirstSucceededRemoteData());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -209,7 +211,7 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
|||||||
* @param group
|
* @param group
|
||||||
*/
|
*/
|
||||||
getSubgroups(group: Group): Observable<RemoteData<PaginatedList<Group>>> {
|
getSubgroups(group: Group): Observable<RemoteData<PaginatedList<Group>>> {
|
||||||
return this.groupService.findAllByHref(group._links.subgroups.href);
|
return this.groupService.findAllByHref(group._links.subgroups.href).pipe(getFirstSucceededRemoteData());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -218,6 +220,7 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
|||||||
*/
|
*/
|
||||||
hasLinkedDSO(group: Group): Observable<boolean> {
|
hasLinkedDSO(group: Group): Observable<boolean> {
|
||||||
return this.dSpaceObjectDataService.findByHref(group._links.object.href).pipe(
|
return this.dSpaceObjectDataService.findByHref(group._links.object.href).pipe(
|
||||||
|
getFirstSucceededRemoteData(),
|
||||||
map((rd: RemoteData<DSpaceObject>) => hasValue(rd) && hasValue(rd.payload)),
|
map((rd: RemoteData<DSpaceObject>) => hasValue(rd) && hasValue(rd.payload)),
|
||||||
catchError(() => observableOf(false)),
|
catchError(() => observableOf(false)),
|
||||||
);
|
);
|
||||||
@@ -233,15 +236,6 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
|||||||
this.search({ query: '' });
|
this.search({ query: '' });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract optional UUID from a group name => To be resolved to community or collection with link
|
|
||||||
* (Or will be resolved in backend and added to group object, tbd) //TODO
|
|
||||||
* @param groupName
|
|
||||||
*/
|
|
||||||
getOptionalComColFromName(groupName: string): string {
|
|
||||||
return this.groupService.getUUIDFromString(groupName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unsub all subscriptions
|
* Unsub all subscriptions
|
||||||
*/
|
*/
|
||||||
|
@@ -32,6 +32,7 @@ import { storeModuleConfig } from './app.reducer';
|
|||||||
import { LocaleService } from './core/locale/locale.service';
|
import { LocaleService } from './core/locale/locale.service';
|
||||||
import { authReducer } from './core/auth/auth.reducer';
|
import { authReducer } from './core/auth/auth.reducer';
|
||||||
import { provideMockStore } from '@ngrx/store/testing';
|
import { provideMockStore } from '@ngrx/store/testing';
|
||||||
|
import {GoogleAnalyticsService} from './statistics/google-analytics.service';
|
||||||
|
|
||||||
let comp: AppComponent;
|
let comp: AppComponent;
|
||||||
let fixture: ComponentFixture<AppComponent>;
|
let fixture: ComponentFixture<AppComponent>;
|
||||||
@@ -48,9 +49,7 @@ describe('App component', () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitForAsync beforeEach
|
const defaultTestBedConf = {
|
||||||
beforeEach(waitForAsync(() => {
|
|
||||||
return TestBed.configureTestingModule({
|
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
StoreModule.forRoot(authReducer, storeModuleConfig),
|
StoreModule.forRoot(authReducer, storeModuleConfig),
|
||||||
@@ -79,7 +78,11 @@ describe('App component', () => {
|
|||||||
RouteService
|
RouteService
|
||||||
],
|
],
|
||||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||||
});
|
};
|
||||||
|
|
||||||
|
// waitForAsync beforeEach
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
return TestBed.configureTestingModule(defaultTestBedConf);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// synchronous beforeEach
|
// synchronous beforeEach
|
||||||
@@ -113,4 +116,31 @@ describe('App component', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when GoogleAnalyticsService is provided', () => {
|
||||||
|
let googleAnalyticsSpy;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
// NOTE: Cannot override providers once components have been compiled, so TestBed needs to be reset
|
||||||
|
TestBed.resetTestingModule();
|
||||||
|
TestBed.configureTestingModule(defaultTestBedConf);
|
||||||
|
googleAnalyticsSpy = jasmine.createSpyObj('googleAnalyticsService', [
|
||||||
|
'addTrackingIdToPage',
|
||||||
|
]);
|
||||||
|
TestBed.overrideProvider(GoogleAnalyticsService, {useValue: googleAnalyticsSpy});
|
||||||
|
fixture = TestBed.createComponent(AppComponent);
|
||||||
|
comp = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create component', () => {
|
||||||
|
expect(comp).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('the constructor', () => {
|
||||||
|
it('should call googleAnalyticsService.addTrackingIdToPage()', () => {
|
||||||
|
expect(googleAnalyticsSpy.addTrackingIdToPage).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -33,6 +33,7 @@ import { models } from './core/core.module';
|
|||||||
import { LocaleService } from './core/locale/locale.service';
|
import { LocaleService } from './core/locale/locale.service';
|
||||||
import { hasValue } from './shared/empty.util';
|
import { hasValue } from './shared/empty.util';
|
||||||
import { KlaroService } from './shared/cookies/klaro.service';
|
import { KlaroService } from './shared/cookies/klaro.service';
|
||||||
|
import {GoogleAnalyticsService} from './statistics/google-analytics.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-app',
|
selector: 'ds-app',
|
||||||
@@ -70,7 +71,8 @@ export class AppComponent implements OnInit, AfterViewInit {
|
|||||||
private menuService: MenuService,
|
private menuService: MenuService,
|
||||||
private windowService: HostWindowService,
|
private windowService: HostWindowService,
|
||||||
private localeService: LocaleService,
|
private localeService: LocaleService,
|
||||||
@Optional() private cookiesService: KlaroService
|
@Optional() private cookiesService: KlaroService,
|
||||||
|
@Optional() private googleAnalyticsService: GoogleAnalyticsService,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
/* Use models object so all decorators are actually called */
|
/* Use models object so all decorators are actually called */
|
||||||
@@ -84,7 +86,10 @@ export class AppComponent implements OnInit, AfterViewInit {
|
|||||||
// set the current language code
|
// set the current language code
|
||||||
this.localeService.setCurrentLanguageCode();
|
this.localeService.setCurrentLanguageCode();
|
||||||
|
|
||||||
angulartics2GoogleAnalytics.startTracking();
|
// analytics
|
||||||
|
if (hasValue(googleAnalyticsService)) {
|
||||||
|
googleAnalyticsService.addTrackingIdToPage();
|
||||||
|
}
|
||||||
angulartics2DSpace.startTracking();
|
angulartics2DSpace.startTracking();
|
||||||
|
|
||||||
metadata.listenForRouteChange();
|
metadata.listenForRouteChange();
|
||||||
|
@@ -9,10 +9,10 @@ import {
|
|||||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||||
import { ItemType } from '../shared/item-relationships/item-type.model';
|
import { ItemType } from '../shared/item-relationships/item-type.model';
|
||||||
import { RelationshipType } from '../shared/item-relationships/relationship-type.model';
|
import { RelationshipType } from '../shared/item-relationships/relationship-type.model';
|
||||||
import { PageInfo } from '../shared/page-info.model';
|
|
||||||
import { buildPaginatedList } from './paginated-list.model';
|
|
||||||
import { RelationshipTypeService } from './relationship-type.service';
|
import { RelationshipTypeService } from './relationship-type.service';
|
||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
|
import { createPaginatedList } from '../../shared/testing/utils.test';
|
||||||
|
import { hasValueOperator } from '../../shared/empty.util';
|
||||||
|
|
||||||
describe('RelationshipTypeService', () => {
|
describe('RelationshipTypeService', () => {
|
||||||
let service: RelationshipTypeService;
|
let service: RelationshipTypeService;
|
||||||
@@ -62,7 +62,7 @@ describe('RelationshipTypeService', () => {
|
|||||||
rightType: createSuccessfulRemoteDataObject$(orgUnitType)
|
rightType: createSuccessfulRemoteDataObject$(orgUnitType)
|
||||||
});
|
});
|
||||||
|
|
||||||
buildList = createSuccessfulRemoteDataObject(buildPaginatedList(new PageInfo(), [relationshipType1, relationshipType2]));
|
buildList = createSuccessfulRemoteDataObject(createPaginatedList([relationshipType1, relationshipType2]));
|
||||||
rdbService = getMockRemoteDataBuildService(undefined, observableOf(buildList));
|
rdbService = getMockRemoteDataBuildService(undefined, observableOf(buildList));
|
||||||
objectCache = Object.assign({
|
objectCache = Object.assign({
|
||||||
/* tslint:disable:no-empty */
|
/* tslint:disable:no-empty */
|
||||||
@@ -100,9 +100,10 @@ describe('RelationshipTypeService', () => {
|
|||||||
describe('getRelationshipTypeByLabelAndTypes', () => {
|
describe('getRelationshipTypeByLabelAndTypes', () => {
|
||||||
|
|
||||||
it('should return the type filtered by label and type strings', (done) => {
|
it('should return the type filtered by label and type strings', (done) => {
|
||||||
const expected = service.getRelationshipTypeByLabelAndTypes(relationshipType1.leftwardType, publicationTypeString, personTypeString);
|
service.getRelationshipTypeByLabelAndTypes(relationshipType1.leftwardType, publicationTypeString, personTypeString).pipe(
|
||||||
expected.subscribe((e) => {
|
hasValueOperator()
|
||||||
expect(e).toBe(relationshipType1);
|
).subscribe((e) => {
|
||||||
|
expect(e.id).toEqual(relationshipType1.id);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -2,9 +2,9 @@ import { HttpClient } from '@angular/common/http';
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
|
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
|
||||||
import { filter, find, map, mergeMap, switchMap } from 'rxjs/operators';
|
import { map, mergeMap, switchMap, toArray } from 'rxjs/operators';
|
||||||
import { AppState } from '../../app.reducer';
|
import { AppState } from '../../app.reducer';
|
||||||
import { isNotUndefined } from '../../shared/empty.util';
|
import { hasValue } from '../../shared/empty.util';
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { followLink } from '../../shared/utils/follow-link-config.model';
|
import { followLink } from '../../shared/utils/follow-link-config.model';
|
||||||
import { dataService } from '../cache/builders/build-decorators';
|
import { dataService } from '../cache/builders/build-decorators';
|
||||||
@@ -15,7 +15,7 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
|
|||||||
import { ItemType } from '../shared/item-relationships/item-type.model';
|
import { ItemType } from '../shared/item-relationships/item-type.model';
|
||||||
import { RelationshipType } from '../shared/item-relationships/relationship-type.model';
|
import { RelationshipType } from '../shared/item-relationships/relationship-type.model';
|
||||||
import { RELATIONSHIP_TYPE } from '../shared/item-relationships/relationship-type.resource-type';
|
import { RELATIONSHIP_TYPE } from '../shared/item-relationships/relationship-type.resource-type';
|
||||||
import { getFirstSucceededRemoteData } from '../shared/operators';
|
import { getFirstSucceededRemoteData, getFirstCompletedRemoteData } from '../shared/operators';
|
||||||
import { DataService } from './data.service';
|
import { DataService } from './data.service';
|
||||||
import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
|
import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
|
||||||
import { ItemDataService } from './item-data.service';
|
import { ItemDataService } from './item-data.service';
|
||||||
@@ -23,6 +23,15 @@ import { PaginatedList } from './paginated-list.model';
|
|||||||
import { RemoteData } from './remote-data';
|
import { RemoteData } from './remote-data';
|
||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if one side of a RelationshipType is the ItemType with the given label
|
||||||
|
*
|
||||||
|
* @param typeRd the RemoteData for an ItemType
|
||||||
|
* @param label the label to check. e.g. Author
|
||||||
|
*/
|
||||||
|
const checkSide = (typeRd: RemoteData<ItemType>, label: string): boolean =>
|
||||||
|
typeRd.hasSucceeded && typeRd.payload.label === label;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The service handling all relationship type requests
|
* The service handling all relationship type requests
|
||||||
*/
|
*/
|
||||||
@@ -45,36 +54,70 @@ export class RelationshipTypeService extends DataService<RelationshipType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the RelationshipType for a relationship type by label
|
* Find a RelationshipType object by its label, and the types of the items on either side.
|
||||||
* @param label
|
*
|
||||||
|
* TODO this should be implemented as a rest endpoint, we shouldn't have logic on the client that
|
||||||
|
* requires using a huge page-size in order to process "everything".
|
||||||
|
*
|
||||||
|
* @param relationshipTypeLabel The name of the relationType we're looking for
|
||||||
|
* e.g. isAuthorOfPublication
|
||||||
|
* @param firstItemType The type of one of the sides of the relationship e.g. Publication
|
||||||
|
* @param secondItemType The type of the other side of the relationship e.g. Author
|
||||||
*/
|
*/
|
||||||
getRelationshipTypeByLabelAndTypes(label: string, firstType: string, secondType: string): Observable<RelationshipType> {
|
getRelationshipTypeByLabelAndTypes(relationshipTypeLabel: string, firstItemType: string, secondItemType: string): Observable<RelationshipType> {
|
||||||
|
// Retrieve all relationship types from the server in a single page
|
||||||
return this.findAll({ currentPage: 1, elementsPerPage: 9999 }, true, true, followLink('leftType'), followLink('rightType'))
|
return this.findAll({ currentPage: 1, elementsPerPage: 9999 }, true, true, followLink('leftType'), followLink('rightType'))
|
||||||
.pipe(
|
.pipe(
|
||||||
getFirstSucceededRemoteData(),
|
getFirstSucceededRemoteData(),
|
||||||
/* Flatten the page so we can treat it like an observable */
|
// Emit each type in the page array separately
|
||||||
switchMap((typeListRD: RemoteData<PaginatedList<RelationshipType>>) => typeListRD.payload.page),
|
switchMap((typeListRD: RemoteData<PaginatedList<RelationshipType>>) => typeListRD.payload.page),
|
||||||
mergeMap((type: RelationshipType) => {
|
// Check each type individually, to see if it matches the provided types
|
||||||
if (type.leftwardType === label) {
|
mergeMap((relationshipType: RelationshipType) => {
|
||||||
return this.checkType(type, firstType, secondType);
|
if (relationshipType.leftwardType === relationshipTypeLabel) {
|
||||||
} else if (type.rightwardType === label) {
|
return this.checkType(relationshipType, firstItemType, secondItemType);
|
||||||
return this.checkType(type, secondType, firstType);
|
} else if (relationshipType.rightwardType === relationshipTypeLabel) {
|
||||||
|
return this.checkType(relationshipType, secondItemType, firstItemType);
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return [null];
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
// Wait for all types to be checked and emit once, with the results combined back into an
|
||||||
|
// array
|
||||||
|
toArray(),
|
||||||
|
// Look for a match in the array and emit it if found, or null if one isn't found
|
||||||
|
map((types: RelationshipType[]) => {
|
||||||
|
const match = types.find((type: RelationshipType) => hasValue(type));
|
||||||
|
if (hasValue(match)) {
|
||||||
|
return match;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if relationship type matches the given types
|
/**
|
||||||
// returns a void observable if there's not match
|
* Check if the given RelationshipType has the given itemTypes on its left and right sides.
|
||||||
// returns an observable that emits the relationship type when there is a match
|
* Returns an observable of the given RelationshipType if it matches, null if it doesn't
|
||||||
private checkType(type: RelationshipType, firstType: string, secondType: string): Observable<RelationshipType> {
|
*
|
||||||
const entityTypes = observableCombineLatest([type.leftType.pipe(getFirstSucceededRemoteData()), type.rightType.pipe(getFirstSucceededRemoteData())]);
|
* @param type The RelationshipType to check
|
||||||
return entityTypes.pipe(
|
* @param leftItemType The item type that should be on the left side
|
||||||
find(([leftTypeRD, rightTypeRD]: [RemoteData<ItemType>, RemoteData<ItemType>]) => leftTypeRD.payload.label === firstType && rightTypeRD.payload.label === secondType),
|
* @param rightItemType The item type that should be on the right side
|
||||||
filter((types) => isNotUndefined(types)),
|
* @private
|
||||||
map(() => type)
|
*/
|
||||||
|
private checkType(type: RelationshipType, leftItemType: string, rightItemType: string): Observable<RelationshipType> {
|
||||||
|
return observableCombineLatest([
|
||||||
|
type.leftType.pipe(getFirstCompletedRemoteData()),
|
||||||
|
type.rightType.pipe(getFirstCompletedRemoteData())
|
||||||
|
]).pipe(
|
||||||
|
map(([leftTypeRD, rightTypeRD]: [RemoteData<ItemType>, RemoteData<ItemType>]) => {
|
||||||
|
if (checkSide(leftTypeRD, leftItemType) && checkSide(rightTypeRD, rightItemType)
|
||||||
|
) {
|
||||||
|
return type;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -63,10 +63,10 @@ export class EPersonDataService extends DataService<EPerson> {
|
|||||||
* @param query Query of search
|
* @param query Query of search
|
||||||
* @param options Options of search request
|
* @param options Options of search request
|
||||||
*/
|
*/
|
||||||
public searchByScope(scope: string, query: string, options: FindListOptions = {}): Observable<RemoteData<PaginatedList<EPerson>>> {
|
public searchByScope(scope: string, query: string, options: FindListOptions = {}, useCachedVersionIfAvailable?: boolean): Observable<RemoteData<PaginatedList<EPerson>>> {
|
||||||
switch (scope) {
|
switch (scope) {
|
||||||
case 'metadata':
|
case 'metadata':
|
||||||
return this.getEpeopleByMetadata(query.trim(), options);
|
return this.getEpeopleByMetadata(query.trim(), options, useCachedVersionIfAvailable);
|
||||||
case 'email':
|
case 'email':
|
||||||
return this.getEPersonByEmail(query.trim()).pipe(
|
return this.getEPersonByEmail(query.trim()).pipe(
|
||||||
map((rd: RemoteData<EPerson | NoContent>) => {
|
map((rd: RemoteData<EPerson | NoContent>) => {
|
||||||
@@ -100,7 +100,7 @@ export class EPersonDataService extends DataService<EPerson> {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return this.getEpeopleByMetadata(query.trim(), options);
|
return this.getEpeopleByMetadata(query.trim(), options, useCachedVersionIfAvailable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -13,5 +13,9 @@ export class EpersonDtoModel {
|
|||||||
* Whether or not the linked EPerson is able to be deleted
|
* Whether or not the linked EPerson is able to be deleted
|
||||||
*/
|
*/
|
||||||
public ableToDelete: boolean;
|
public ableToDelete: boolean;
|
||||||
|
/**
|
||||||
|
* Whether or not this EPerson is member of group on page it is being used on
|
||||||
|
*/
|
||||||
|
public memberOfGroup: boolean;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
|
import { PaginatedList } from '../../data/paginated-list.model';
|
||||||
|
import { EPerson } from './eperson.model';
|
||||||
import { Group } from './group.model';
|
import { Group } from './group.model';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class serves as a Data Transfer Model that contains the Group and whether or not it's able to be deleted
|
* This class serves as a Data Transfer Model that contains the Group, whether or not it's able to be deleted and its members
|
||||||
*/
|
*/
|
||||||
export class GroupDtoModel {
|
export class GroupDtoModel {
|
||||||
|
|
||||||
@@ -9,9 +11,20 @@ export class GroupDtoModel {
|
|||||||
* The Group linked to this object
|
* The Group linked to this object
|
||||||
*/
|
*/
|
||||||
public group: Group;
|
public group: Group;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the linked Group is able to be deleted
|
* Whether or not the linked Group is able to be deleted
|
||||||
*/
|
*/
|
||||||
public ableToDelete: boolean;
|
public ableToDelete: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of subgroups of this group
|
||||||
|
*/
|
||||||
|
public subgroups: PaginatedList<Group>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of members of this group
|
||||||
|
*/
|
||||||
|
public epersons: PaginatedList<EPerson>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { autoserialize, deserialize, inheritSerialization } from 'cerialize';
|
import { autoserialize, autoserializeAs, deserialize, inheritSerialization } from 'cerialize';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { link, typedObject } from '../../cache/builders/build-decorators';
|
import { link, typedObject } from '../../cache/builders/build-decorators';
|
||||||
import { PaginatedList } from '../../data/paginated-list.model';
|
import { PaginatedList } from '../../data/paginated-list.model';
|
||||||
@@ -10,12 +10,20 @@ import { HALLink } from '../../shared/hal-link.model';
|
|||||||
import { EPerson } from './eperson.model';
|
import { EPerson } from './eperson.model';
|
||||||
import { EPERSON } from './eperson.resource-type';
|
import { EPERSON } from './eperson.resource-type';
|
||||||
import { GROUP } from './group.resource-type';
|
import { GROUP } from './group.resource-type';
|
||||||
|
import { excludeFromEquals } from '../../utilities/equals.decorators';
|
||||||
|
|
||||||
@typedObject
|
@typedObject
|
||||||
@inheritSerialization(DSpaceObject)
|
@inheritSerialization(DSpaceObject)
|
||||||
export class Group extends DSpaceObject {
|
export class Group extends DSpaceObject {
|
||||||
static type = GROUP;
|
static type = GROUP;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A string representing the unique name of this Group
|
||||||
|
*/
|
||||||
|
@excludeFromEquals
|
||||||
|
@autoserializeAs('name')
|
||||||
|
protected _name: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A string representing the unique handle of this Group
|
* A string representing the unique handle of this Group
|
||||||
*/
|
*/
|
||||||
|
@@ -29,7 +29,7 @@ export class DSpaceObject extends ListableObject implements CacheableObject {
|
|||||||
|
|
||||||
@excludeFromEquals
|
@excludeFromEquals
|
||||||
@deserializeAs('name')
|
@deserializeAs('name')
|
||||||
private _name: string;
|
protected _name: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The human-readable identifier of this DSpaceObject
|
* The human-readable identifier of this DSpaceObject
|
||||||
|
@@ -23,7 +23,7 @@
|
|||||||
</ds-dynamic-lookup-relation-search-tab>
|
</ds-dynamic-lookup-relation-search-tab>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</ngb-tab>
|
</ngb-tab>
|
||||||
<ngb-tab *ngFor="let source of (externalSourcesRD$ | async)?.payload?.page; let idx = index"
|
<ngb-tab *ngFor="let source of (externalSourcesRD$ | async); let idx = index"
|
||||||
[title]="'submission.sections.describe.relationship-lookup.search-tab.tab-title.' + source.id | translate : {count: (totalExternal$ | async)[idx]}">
|
[title]="'submission.sections.describe.relationship-lookup.search-tab.tab-title.' + source.id | translate : {count: (totalExternal$ | async)[idx]}">
|
||||||
<ng-template ngbTabContent>
|
<ng-template ngbTabContent>
|
||||||
<ds-dynamic-lookup-relation-external-source-tab
|
<ds-dynamic-lookup-relation-external-source-tab
|
||||||
|
@@ -20,6 +20,7 @@ import { createSuccessfulRemoteDataObject$ } from '../../../../remote-data.utils
|
|||||||
import { createPaginatedList } from '../../../../testing/utils.test';
|
import { createPaginatedList } from '../../../../testing/utils.test';
|
||||||
import { ExternalSourceService } from '../../../../../core/data/external-source.service';
|
import { ExternalSourceService } from '../../../../../core/data/external-source.service';
|
||||||
import { LookupRelationService } from '../../../../../core/data/lookup-relation.service';
|
import { LookupRelationService } from '../../../../../core/data/lookup-relation.service';
|
||||||
|
import { RemoteDataBuildService } from '../../../../../core/cache/builders/remote-data-build.service';
|
||||||
import { SubmissionService } from '../../../../../submission/submission.service';
|
import { SubmissionService } from '../../../../../submission/submission.service';
|
||||||
import { SubmissionObjectDataService } from '../../../../../core/submission/submission-object-data.service';
|
import { SubmissionObjectDataService } from '../../../../../core/submission/submission-object-data.service';
|
||||||
import { WorkspaceItem } from '../../../../../core/submission/models/workspaceitem.model';
|
import { WorkspaceItem } from '../../../../../core/submission/models/workspaceitem.model';
|
||||||
@@ -43,6 +44,7 @@ describe('DsDynamicLookupRelationModalComponent', () => {
|
|||||||
let pSearchOptions;
|
let pSearchOptions;
|
||||||
let externalSourceService;
|
let externalSourceService;
|
||||||
let lookupRelationService;
|
let lookupRelationService;
|
||||||
|
let rdbService;
|
||||||
let submissionId;
|
let submissionId;
|
||||||
let submissionService;
|
let submissionService;
|
||||||
let submissionObjectDataService;
|
let submissionObjectDataService;
|
||||||
@@ -80,18 +82,23 @@ describe('DsDynamicLookupRelationModalComponent', () => {
|
|||||||
filter: 'filter',
|
filter: 'filter',
|
||||||
relationshipType: 'isAuthorOfPublication',
|
relationshipType: 'isAuthorOfPublication',
|
||||||
nameVariants: true,
|
nameVariants: true,
|
||||||
searchConfiguration: 'personConfig'
|
searchConfiguration: 'personConfig',
|
||||||
|
externalSources: ['orcidV2', 'sherpaPublisher']
|
||||||
});
|
});
|
||||||
nameVariant = 'Doe, J.';
|
nameVariant = 'Doe, J.';
|
||||||
metadataField = 'dc.contributor.author';
|
metadataField = 'dc.contributor.author';
|
||||||
pSearchOptions = new PaginatedSearchOptions({});
|
pSearchOptions = new PaginatedSearchOptions({});
|
||||||
externalSourceService = jasmine.createSpyObj('externalSourceService', {
|
externalSourceService = jasmine.createSpyObj('externalSourceService', {
|
||||||
findAll: createSuccessfulRemoteDataObject$(createPaginatedList(externalSources))
|
findAll: createSuccessfulRemoteDataObject$(createPaginatedList(externalSources)),
|
||||||
|
findById: createSuccessfulRemoteDataObject$(externalSources[0])
|
||||||
});
|
});
|
||||||
lookupRelationService = jasmine.createSpyObj('lookupRelationService', {
|
lookupRelationService = jasmine.createSpyObj('lookupRelationService', {
|
||||||
getTotalLocalResults: observableOf(totalLocal),
|
getTotalLocalResults: observableOf(totalLocal),
|
||||||
getTotalExternalResults: observableOf(totalExternal)
|
getTotalExternalResults: observableOf(totalExternal)
|
||||||
});
|
});
|
||||||
|
rdbService = jasmine.createSpyObj('rdbService', {
|
||||||
|
aggregate: createSuccessfulRemoteDataObject$(externalSources)
|
||||||
|
});
|
||||||
submissionService = jasmine.createSpyObj('SubmissionService', {
|
submissionService = jasmine.createSpyObj('SubmissionService', {
|
||||||
dispatchSave: jasmine.createSpy('dispatchSave')
|
dispatchSave: jasmine.createSpy('dispatchSave')
|
||||||
});
|
});
|
||||||
@@ -121,6 +128,7 @@ describe('DsDynamicLookupRelationModalComponent', () => {
|
|||||||
provide: RelationshipService, useValue: { getNameVariant: () => observableOf(nameVariant) }
|
provide: RelationshipService, useValue: { getNameVariant: () => observableOf(nameVariant) }
|
||||||
},
|
},
|
||||||
{ provide: RelationshipTypeService, useValue: {} },
|
{ provide: RelationshipTypeService, useValue: {} },
|
||||||
|
{ provide: RemoteDataBuildService, useValue: rdbService },
|
||||||
{ provide: SubmissionService, useValue: submissionService },
|
{ provide: SubmissionService, useValue: submissionService },
|
||||||
{ provide: SubmissionObjectDataService, useValue: submissionObjectDataService },
|
{ provide: SubmissionObjectDataService, useValue: submissionObjectDataService },
|
||||||
{
|
{
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { Component, EventEmitter, NgZone, OnDestroy, OnInit, Output } from '@angular/core';
|
import { Component, EventEmitter, NgZone, OnDestroy, OnInit, Output } from '@angular/core';
|
||||||
import { combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
|
import { combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
|
||||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { hasValue } from '../../../../empty.util';
|
import { hasValue, isNotEmpty } from '../../../../empty.util';
|
||||||
import { map, skip, switchMap, take } from 'rxjs/operators';
|
import { map, skip, switchMap, take } from 'rxjs/operators';
|
||||||
import { SEARCH_CONFIG_SERVICE } from '../../../../../+my-dspace-page/my-dspace-page.component';
|
import { SEARCH_CONFIG_SERVICE } from '../../../../../+my-dspace-page/my-dspace-page.component';
|
||||||
import { SearchConfigurationService } from '../../../../../core/shared/search/search-configuration.service';
|
import { SearchConfigurationService } from '../../../../../core/shared/search/search-configuration.service';
|
||||||
@@ -11,7 +11,7 @@ import { ListableObject } from '../../../../object-collection/shared/listable-ob
|
|||||||
import { RelationshipOptions } from '../../models/relationship-options.model';
|
import { RelationshipOptions } from '../../models/relationship-options.model';
|
||||||
import { SearchResult } from '../../../../search/search-result.model';
|
import { SearchResult } from '../../../../search/search-result.model';
|
||||||
import { Item } from '../../../../../core/shared/item.model';
|
import { Item } from '../../../../../core/shared/item.model';
|
||||||
import { getAllSucceededRemoteData, getRemoteDataPayload } from '../../../../../core/shared/operators';
|
import { getAllSucceededRemoteDataPayload } from '../../../../../core/shared/operators';
|
||||||
import { AddRelationshipAction, RemoveRelationshipAction, UpdateRelationshipNameVariantAction } from './relationship.actions';
|
import { AddRelationshipAction, RemoveRelationshipAction, UpdateRelationshipNameVariantAction } from './relationship.actions';
|
||||||
import { RelationshipService } from '../../../../../core/data/relationship.service';
|
import { RelationshipService } from '../../../../../core/data/relationship.service';
|
||||||
import { RelationshipTypeService } from '../../../../../core/data/relationship-type.service';
|
import { RelationshipTypeService } from '../../../../../core/data/relationship-type.service';
|
||||||
@@ -19,11 +19,10 @@ import { Store } from '@ngrx/store';
|
|||||||
import { AppState } from '../../../../../app.reducer';
|
import { AppState } from '../../../../../app.reducer';
|
||||||
import { Context } from '../../../../../core/shared/context.model';
|
import { Context } from '../../../../../core/shared/context.model';
|
||||||
import { LookupRelationService } from '../../../../../core/data/lookup-relation.service';
|
import { LookupRelationService } from '../../../../../core/data/lookup-relation.service';
|
||||||
import { RemoteData } from '../../../../../core/data/remote-data';
|
|
||||||
import { PaginatedList } from '../../../../../core/data/paginated-list.model';
|
|
||||||
import { ExternalSource } from '../../../../../core/shared/external-source.model';
|
import { ExternalSource } from '../../../../../core/shared/external-source.model';
|
||||||
import { ExternalSourceService } from '../../../../../core/data/external-source.service';
|
import { ExternalSourceService } from '../../../../../core/data/external-source.service';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
import { RemoteDataBuildService } from '../../../../../core/cache/builders/remote-data-build.service';
|
||||||
import { followLink } from '../../../../utils/follow-link-config.model';
|
import { followLink } from '../../../../utils/follow-link-config.model';
|
||||||
import { SubmissionObject } from '../../../../../core/submission/models/submission-object.model';
|
import { SubmissionObject } from '../../../../../core/submission/models/submission-object.model';
|
||||||
import { Collection } from '../../../../../core/shared/collection.model';
|
import { Collection } from '../../../../../core/shared/collection.model';
|
||||||
@@ -106,7 +105,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
/**
|
/**
|
||||||
* A list of the available external sources configured for this relationship
|
* A list of the available external sources configured for this relationship
|
||||||
*/
|
*/
|
||||||
externalSourcesRD$: Observable<RemoteData<PaginatedList<ExternalSource>>>;
|
externalSourcesRD$: Observable<ExternalSource[]>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The total amount of internal items for the current options
|
* The total amount of internal items for the current options
|
||||||
@@ -131,6 +130,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
private externalSourceService: ExternalSourceService,
|
private externalSourceService: ExternalSourceService,
|
||||||
private lookupRelationService: LookupRelationService,
|
private lookupRelationService: LookupRelationService,
|
||||||
private searchConfigService: SearchConfigurationService,
|
private searchConfigService: SearchConfigurationService,
|
||||||
|
private rdbService: RemoteDataBuildService,
|
||||||
private submissionService: SubmissionService,
|
private submissionService: SubmissionService,
|
||||||
private submissionObjectService: SubmissionObjectDataService,
|
private submissionObjectService: SubmissionObjectDataService,
|
||||||
private zone: NgZone,
|
private zone: NgZone,
|
||||||
@@ -155,7 +155,13 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
this.context = Context.EntitySearchModal;
|
this.context = Context.EntitySearchModal;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.externalSourcesRD$ = this.externalSourceService.findAll();
|
if (isNotEmpty(this.relationshipOptions.externalSources)) {
|
||||||
|
this.externalSourcesRD$ = this.rdbService.aggregate(
|
||||||
|
this.relationshipOptions.externalSources.map((source) => this.externalSourceService.findById(source))
|
||||||
|
).pipe(
|
||||||
|
getAllSucceededRemoteDataPayload()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.setTotals();
|
this.setTotals();
|
||||||
}
|
}
|
||||||
@@ -256,16 +262,13 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
|||||||
);
|
);
|
||||||
|
|
||||||
const externalSourcesAndOptions$ = observableCombineLatest(
|
const externalSourcesAndOptions$ = observableCombineLatest(
|
||||||
this.externalSourcesRD$.pipe(
|
this.externalSourcesRD$,
|
||||||
getAllSucceededRemoteData(),
|
|
||||||
getRemoteDataPayload()
|
|
||||||
),
|
|
||||||
this.searchConfigService.paginatedSearchOptions
|
this.searchConfigService.paginatedSearchOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
this.totalExternal$ = externalSourcesAndOptions$.pipe(
|
this.totalExternal$ = externalSourcesAndOptions$.pipe(
|
||||||
switchMap(([sources, options]) =>
|
switchMap(([sources, options]) =>
|
||||||
observableCombineLatest(...sources.page.map((source: ExternalSource) => this.lookupRelationService.getTotalExternalResults(source, options))))
|
observableCombineLatest(...sources.map((source: ExternalSource) => this.lookupRelationService.getTotalExternalResults(source, options))))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,6 +20,9 @@ import { SubmissionObjectDataService } from '../../../../../core/submission/subm
|
|||||||
import { WorkspaceItem } from '../../../../../core/submission/models/workspaceitem.model';
|
import { WorkspaceItem } from '../../../../../core/submission/models/workspaceitem.model';
|
||||||
import { ObjectCacheService } from '../../../../../core/cache/object-cache.service';
|
import { ObjectCacheService } from '../../../../../core/cache/object-cache.service';
|
||||||
import { RequestService } from '../../../../../core/data/request.service';
|
import { RequestService } from '../../../../../core/data/request.service';
|
||||||
|
import { NotificationsService } from '../../../../notifications/notifications.service';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import { SelectableListService } from '../../../../object-list/selectable-list/selectable-list.service';
|
||||||
|
|
||||||
describe('RelationshipEffects', () => {
|
describe('RelationshipEffects', () => {
|
||||||
let relationEffects: RelationshipEffects;
|
let relationEffects: RelationshipEffects;
|
||||||
@@ -45,6 +48,9 @@ describe('RelationshipEffects', () => {
|
|||||||
let relationship;
|
let relationship;
|
||||||
let mockRelationshipService;
|
let mockRelationshipService;
|
||||||
let mockRelationshipTypeService;
|
let mockRelationshipTypeService;
|
||||||
|
let notificationsService;
|
||||||
|
let translateService;
|
||||||
|
let selectableListService;
|
||||||
let testScheduler: TestScheduler;
|
let testScheduler: TestScheduler;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
@@ -95,6 +101,14 @@ describe('RelationshipEffects', () => {
|
|||||||
getRelationshipTypeByLabelAndTypes:
|
getRelationshipTypeByLabelAndTypes:
|
||||||
() => observableOf(relationshipType)
|
() => observableOf(relationshipType)
|
||||||
};
|
};
|
||||||
|
notificationsService = jasmine.createSpyObj('notificationsService', ['error']);
|
||||||
|
translateService = jasmine.createSpyObj('translateService', {
|
||||||
|
instant: 'translated-message'
|
||||||
|
});
|
||||||
|
selectableListService = jasmine.createSpyObj('selectableListService', {
|
||||||
|
findSelectedByCondition: observableOf({}),
|
||||||
|
deselectSingle: {}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
@@ -114,6 +128,9 @@ describe('RelationshipEffects', () => {
|
|||||||
{ provide: Store, useValue: jasmine.createSpyObj('store', ['dispatch']) },
|
{ provide: Store, useValue: jasmine.createSpyObj('store', ['dispatch']) },
|
||||||
{ provide: ObjectCacheService, useValue: {} },
|
{ provide: ObjectCacheService, useValue: {} },
|
||||||
{ provide: RequestService, useValue: {} },
|
{ provide: RequestService, useValue: {} },
|
||||||
|
{ provide: NotificationsService, useValue: notificationsService },
|
||||||
|
{ provide: TranslateService, useValue: translateService },
|
||||||
|
{ provide: SelectableListService, useValue: selectableListService },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
@@ -15,7 +15,7 @@ import {
|
|||||||
UpdateRelationshipNameVariantAction
|
UpdateRelationshipNameVariantAction
|
||||||
} from './relationship.actions';
|
} from './relationship.actions';
|
||||||
import { Item } from '../../../../../core/shared/item.model';
|
import { Item } from '../../../../../core/shared/item.model';
|
||||||
import { hasNoValue, hasValue } from '../../../../empty.util';
|
import { hasNoValue, hasValue, hasValueOperator } from '../../../../empty.util';
|
||||||
import { Relationship } from '../../../../../core/shared/item-relationships/relationship.model';
|
import { Relationship } from '../../../../../core/shared/item-relationships/relationship.model';
|
||||||
import { RelationshipType } from '../../../../../core/shared/item-relationships/relationship-type.model';
|
import { RelationshipType } from '../../../../../core/shared/item-relationships/relationship-type.model';
|
||||||
import { RelationshipTypeService } from '../../../../../core/data/relationship-type.service';
|
import { RelationshipTypeService } from '../../../../../core/data/relationship-type.service';
|
||||||
@@ -30,6 +30,9 @@ import { ServerSyncBufferActionTypes } from '../../../../../core/cache/server-sy
|
|||||||
import { JsonPatchOperationsActionTypes } from '../../../../../core/json-patch/json-patch-operations.actions';
|
import { JsonPatchOperationsActionTypes } from '../../../../../core/json-patch/json-patch-operations.actions';
|
||||||
import { followLink } from '../../../../utils/follow-link-config.model';
|
import { followLink } from '../../../../utils/follow-link-config.model';
|
||||||
import { RemoteData } from '../../../../../core/data/remote-data';
|
import { RemoteData } from '../../../../../core/data/remote-data';
|
||||||
|
import { NotificationsService } from '../../../../notifications/notifications.service';
|
||||||
|
import { SelectableListService } from '../../../../object-list/selectable-list/selectable-list.service';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
const DEBOUNCE_TIME = 500;
|
const DEBOUNCE_TIME = 500;
|
||||||
|
|
||||||
@@ -152,7 +155,10 @@ export class RelationshipEffects {
|
|||||||
private submissionObjectService: SubmissionObjectDataService,
|
private submissionObjectService: SubmissionObjectDataService,
|
||||||
private store: Store<SubmissionState>,
|
private store: Store<SubmissionState>,
|
||||||
private objectCache: ObjectCacheService,
|
private objectCache: ObjectCacheService,
|
||||||
private requestService: RequestService
|
private requestService: RequestService,
|
||||||
|
private notificationsService: NotificationsService,
|
||||||
|
private translateService: TranslateService,
|
||||||
|
private selectableListService: SelectableListService,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,6 +172,9 @@ export class RelationshipEffects {
|
|||||||
return this.relationshipTypeService.getRelationshipTypeByLabelAndTypes(relationshipType, type1, type2)
|
return this.relationshipTypeService.getRelationshipTypeByLabelAndTypes(relationshipType, type1, type2)
|
||||||
.pipe(
|
.pipe(
|
||||||
mergeMap((type: RelationshipType) => {
|
mergeMap((type: RelationshipType) => {
|
||||||
|
if (type === null) {
|
||||||
|
return [null];
|
||||||
|
} else {
|
||||||
const isSwitched = type.rightwardType === relationshipType;
|
const isSwitched = type.rightwardType === relationshipType;
|
||||||
if (isSwitched) {
|
if (isSwitched) {
|
||||||
return this.relationshipService.addRelationship(type.id, item2, item1, nameVariant, undefined);
|
return this.relationshipService.addRelationship(type.id, item2, item1, nameVariant, undefined);
|
||||||
@@ -173,9 +182,28 @@ export class RelationshipEffects {
|
|||||||
return this.relationshipService.addRelationship(type.id, item1, item2, undefined, nameVariant);
|
return this.relationshipService.addRelationship(type.id, item1, item2, undefined, nameVariant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
),
|
}),
|
||||||
take(1),
|
take(1),
|
||||||
switchMap(() => this.refreshWorkspaceItemInCache(submissionId)),
|
switchMap((rd: RemoteData<Relationship>) => {
|
||||||
|
if (hasNoValue(rd) || rd.hasFailed) {
|
||||||
|
// An error occurred, deselect the object from the selectable list and display an error notification
|
||||||
|
const listId = `list-${submissionId}-${relationshipType}`;
|
||||||
|
this.selectableListService.findSelectedByCondition(listId, (object: any) => hasValue(object.indexableObject) && object.indexableObject.uuid === item2.uuid).pipe(
|
||||||
|
take(1),
|
||||||
|
hasValueOperator()
|
||||||
|
).subscribe((selected) => {
|
||||||
|
this.selectableListService.deselectSingle(listId, selected);
|
||||||
|
});
|
||||||
|
let errorContent;
|
||||||
|
if (hasNoValue(rd)) {
|
||||||
|
errorContent = this.translateService.instant('relationships.add.error.relationship-type.content', { type: relationshipType });
|
||||||
|
} else {
|
||||||
|
errorContent = this.translateService.instant('relationships.add.error.server.content');
|
||||||
|
}
|
||||||
|
this.notificationsService.error(this.translateService.instant('relationships.add.error.title'), errorContent);
|
||||||
|
}
|
||||||
|
return this.refreshWorkspaceItemInCache(submissionId);
|
||||||
|
}),
|
||||||
).subscribe((submissionObject: SubmissionObject) => this.store.dispatch(new SaveSubmissionSectionFormSuccessAction(submissionId, [submissionObject], false)));
|
).subscribe((submissionObject: SubmissionObject) => this.store.dispatch(new SaveSubmissionSectionFormSuccessAction(submissionId, [submissionObject], false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@ export class RelationshipOptions {
|
|||||||
filter: string;
|
filter: string;
|
||||||
searchConfiguration: string;
|
searchConfiguration: string;
|
||||||
nameVariants: string;
|
nameVariants: string;
|
||||||
|
externalSources: string[];
|
||||||
|
|
||||||
get metadataField() {
|
get metadataField() {
|
||||||
return RELATION_METADATA_PREFIX + this.relationshipType;
|
return RELATION_METADATA_PREFIX + this.relationshipType;
|
||||||
|
@@ -91,4 +91,15 @@ export class SelectableListService {
|
|||||||
distinctUntilChanged()
|
distinctUntilChanged()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a selected object by a custom condition
|
||||||
|
* @param id The ID of the selectable list to search in
|
||||||
|
* @param condition The condition that the required object has to match
|
||||||
|
*/
|
||||||
|
findSelectedByCondition(id: string, condition: (object: ListableObject) => boolean): Observable<ListableObject> {
|
||||||
|
return this.getSelectableList(id).pipe(
|
||||||
|
map((state: SelectableListState) => (hasValue(state) && isNotEmpty(state.selection)) ? state.selection.find((selected) => condition(selected)) : undefined)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
128
src/app/statistics/google-analytics.service.spec.ts
Normal file
128
src/app/statistics/google-analytics.service.spec.ts
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
import { GoogleAnalyticsService } from './google-analytics.service';
|
||||||
|
import {Angulartics2GoogleAnalytics} from 'angulartics2/ga';
|
||||||
|
import {ConfigurationDataService} from '../core/data/configuration-data.service';
|
||||||
|
import {createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$} from '../shared/remote-data.utils';
|
||||||
|
import {ConfigurationProperty} from '../core/shared/configuration-property.model';
|
||||||
|
|
||||||
|
describe('GoogleAnalyticsService', () => {
|
||||||
|
const trackingIdProp = 'google.analytics.key';
|
||||||
|
const trackingIdTestValue = 'mock-tracking-id';
|
||||||
|
const innerHTMLTestValue = 'mock-script-inner-html';
|
||||||
|
let service: GoogleAnalyticsService;
|
||||||
|
let angularticsSpy: Angulartics2GoogleAnalytics;
|
||||||
|
let configSpy: ConfigurationDataService;
|
||||||
|
let scriptElementMock: any;
|
||||||
|
let innerHTMLSpy: any;
|
||||||
|
let bodyElementSpy: HTMLBodyElement;
|
||||||
|
let documentSpy: Document;
|
||||||
|
|
||||||
|
const createConfigSuccessSpy = (...values: string[]) => jasmine.createSpyObj('configurationDataService', {
|
||||||
|
findByPropertyName: createSuccessfulRemoteDataObject$({
|
||||||
|
... new ConfigurationProperty(),
|
||||||
|
name: trackingIdProp,
|
||||||
|
values: values,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
angularticsSpy = jasmine.createSpyObj('angulartics2GoogleAnalytics', [
|
||||||
|
'startTracking',
|
||||||
|
]);
|
||||||
|
|
||||||
|
configSpy = createConfigSuccessSpy(trackingIdTestValue);
|
||||||
|
|
||||||
|
scriptElementMock = {
|
||||||
|
set innerHTML(newVal) { /* noop */ },
|
||||||
|
get innerHTML() { return innerHTMLTestValue; }
|
||||||
|
};
|
||||||
|
|
||||||
|
innerHTMLSpy = spyOnProperty(scriptElementMock, 'innerHTML', 'set');
|
||||||
|
|
||||||
|
bodyElementSpy = jasmine.createSpyObj('body', {
|
||||||
|
appendChild: scriptElementMock,
|
||||||
|
});
|
||||||
|
|
||||||
|
documentSpy = jasmine.createSpyObj('document', {
|
||||||
|
createElement: scriptElementMock,
|
||||||
|
}, {
|
||||||
|
body: bodyElementSpy,
|
||||||
|
});
|
||||||
|
|
||||||
|
service = new GoogleAnalyticsService(angularticsSpy, configSpy, documentSpy);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('addTrackingIdToPage()', () => {
|
||||||
|
it(`should request the ${trackingIdProp} property`, () => {
|
||||||
|
service.addTrackingIdToPage();
|
||||||
|
expect(configSpy.findByPropertyName).toHaveBeenCalledTimes(1);
|
||||||
|
expect(configSpy.findByPropertyName).toHaveBeenCalledWith(trackingIdProp);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the request fails', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
configSpy = jasmine.createSpyObj('configurationDataService', {
|
||||||
|
findByPropertyName: createFailedRemoteDataObject$(),
|
||||||
|
});
|
||||||
|
|
||||||
|
service = new GoogleAnalyticsService(angularticsSpy, configSpy, documentSpy);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should NOT add a script to the body', () => {
|
||||||
|
service.addTrackingIdToPage();
|
||||||
|
expect(bodyElementSpy.appendChild).toHaveBeenCalledTimes(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should NOT start tracking', () => {
|
||||||
|
service.addTrackingIdToPage();
|
||||||
|
expect(angularticsSpy.startTracking).toHaveBeenCalledTimes(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the request succeeds', () => {
|
||||||
|
describe('when the tracking id is empty', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
configSpy = createConfigSuccessSpy();
|
||||||
|
service = new GoogleAnalyticsService(angularticsSpy, configSpy, documentSpy);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should NOT add a script to the body', () => {
|
||||||
|
service.addTrackingIdToPage();
|
||||||
|
expect(bodyElementSpy.appendChild).toHaveBeenCalledTimes(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should NOT start tracking', () => {
|
||||||
|
service.addTrackingIdToPage();
|
||||||
|
expect(angularticsSpy.startTracking).toHaveBeenCalledTimes(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the tracking id is non-empty', () => {
|
||||||
|
it('should create a script tag whose innerHTML contains the tracking id', () => {
|
||||||
|
service.addTrackingIdToPage();
|
||||||
|
expect(documentSpy.createElement).toHaveBeenCalledTimes(1);
|
||||||
|
expect(documentSpy.createElement).toHaveBeenCalledWith('script');
|
||||||
|
|
||||||
|
// sanity check
|
||||||
|
expect(documentSpy.createElement('script')).toBe(scriptElementMock);
|
||||||
|
|
||||||
|
expect(innerHTMLSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(innerHTMLSpy.calls.argsFor(0)[0]).toContain(trackingIdTestValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add a script to the body', () => {
|
||||||
|
service.addTrackingIdToPage();
|
||||||
|
expect(bodyElementSpy.appendChild).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should start tracking', () => {
|
||||||
|
service.addTrackingIdToPage();
|
||||||
|
expect(angularticsSpy.startTracking).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
52
src/app/statistics/google-analytics.service.ts
Normal file
52
src/app/statistics/google-analytics.service.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import {Inject, Injectable} from '@angular/core';
|
||||||
|
import {Angulartics2GoogleAnalytics} from 'angulartics2/ga';
|
||||||
|
import {ConfigurationDataService} from '../core/data/configuration-data.service';
|
||||||
|
import {getFirstCompletedRemoteData} from '../core/shared/operators';
|
||||||
|
import {isEmpty} from '../shared/empty.util';
|
||||||
|
import {DOCUMENT} from '@angular/common';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up Google Analytics on the client side.
|
||||||
|
* See: {@link addTrackingIdToPage}.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class GoogleAnalyticsService {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private angulartics: Angulartics2GoogleAnalytics,
|
||||||
|
private configService: ConfigurationDataService,
|
||||||
|
@Inject(DOCUMENT) private document: any,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call this method once when Angular initializes on the client side.
|
||||||
|
* It requests a Google Analytics tracking id from the rest backend
|
||||||
|
* (property: google.analytics.key), adds the tracking snippet to the
|
||||||
|
* page and starts tracking.
|
||||||
|
*/
|
||||||
|
addTrackingIdToPage(): void {
|
||||||
|
this.configService.findByPropertyName('google.analytics.key').pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
).subscribe((remoteData) => {
|
||||||
|
// make sure we got a success response from the backend
|
||||||
|
if (!remoteData.hasSucceeded) { return; }
|
||||||
|
|
||||||
|
const trackingId = remoteData.payload.values[0];
|
||||||
|
|
||||||
|
// make sure we received a tracking id
|
||||||
|
if (isEmpty(trackingId)) { return; }
|
||||||
|
|
||||||
|
// add trackingId snippet to page
|
||||||
|
const keyScript = this.document.createElement('script');
|
||||||
|
keyScript.innerHTML = `(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||||
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||||
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||||
|
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
||||||
|
ga('create', '${trackingId}', 'auto');`;
|
||||||
|
this.document.body.appendChild(keyScript);
|
||||||
|
|
||||||
|
// start tracking
|
||||||
|
this.angulartics.startTracking();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -32,6 +32,8 @@ import { SubmissionImportExternalSearchbarComponent } from './import-external/im
|
|||||||
import { SubmissionImportExternalPreviewComponent } from './import-external/import-external-preview/submission-import-external-preview.component';
|
import { SubmissionImportExternalPreviewComponent } from './import-external/import-external-preview/submission-import-external-preview.component';
|
||||||
import { SubmissionImportExternalCollectionComponent } from './import-external/import-external-collection/submission-import-external-collection.component';
|
import { SubmissionImportExternalCollectionComponent } from './import-external/import-external-collection/submission-import-external-collection.component';
|
||||||
import { SubmissionSectionCcLicensesComponent } from './sections/cc-license/submission-section-cc-licenses.component';
|
import { SubmissionSectionCcLicensesComponent } from './sections/cc-license/submission-section-cc-licenses.component';
|
||||||
|
import { JournalEntitiesModule } from '../entity-groups/journal-entities/journal-entities.module';
|
||||||
|
import { ResearchEntitiesModule } from '../entity-groups/research-entities/research-entities.module';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -39,7 +41,9 @@ import { SubmissionSectionCcLicensesComponent } from './sections/cc-license/subm
|
|||||||
CoreModule.forRoot(),
|
CoreModule.forRoot(),
|
||||||
SharedModule,
|
SharedModule,
|
||||||
StoreModule.forFeature('submission', submissionReducers, storeModuleConfig as StoreConfig<SubmissionState, Action>),
|
StoreModule.forFeature('submission', submissionReducers, storeModuleConfig as StoreConfig<SubmissionState, Action>),
|
||||||
EffectsModule.forFeature(submissionEffects)
|
EffectsModule.forFeature(submissionEffects),
|
||||||
|
JournalEntitiesModule.withEntryComponents(),
|
||||||
|
ResearchEntitiesModule.withEntryComponents(),
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
SubmissionSectionUploadAccessConditionsComponent,
|
SubmissionSectionUploadAccessConditionsComponent,
|
||||||
|
@@ -308,8 +308,6 @@
|
|||||||
|
|
||||||
"admin.access-control.groups.table.members": "Members",
|
"admin.access-control.groups.table.members": "Members",
|
||||||
|
|
||||||
"admin.access-control.groups.table.comcol": "Community / Collection",
|
|
||||||
|
|
||||||
"admin.access-control.groups.table.edit": "Edit",
|
"admin.access-control.groups.table.edit": "Edit",
|
||||||
|
|
||||||
"admin.access-control.groups.table.edit.buttons.edit": "Edit \"{{name}}\"",
|
"admin.access-control.groups.table.edit.buttons.edit": "Edit \"{{name}}\"",
|
||||||
@@ -404,6 +402,8 @@
|
|||||||
|
|
||||||
"admin.access-control.groups.form.members-list.no-items": "No EPeople found in that search",
|
"admin.access-control.groups.form.members-list.no-items": "No EPeople found in that search",
|
||||||
|
|
||||||
|
"admin.access-control.groups.form.subgroups-list.notification.failure": "Something went wrong: \"{{cause}}\"",
|
||||||
|
|
||||||
"admin.access-control.groups.form.subgroups-list.head": "Groups",
|
"admin.access-control.groups.form.subgroups-list.head": "Groups",
|
||||||
|
|
||||||
"admin.access-control.groups.form.subgroups-list.search.head": "Add Subgroup",
|
"admin.access-control.groups.form.subgroups-list.search.head": "Add Subgroup",
|
||||||
@@ -2663,6 +2663,12 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
"relationships.add.error.relationship-type.content": "No suitable match could be found for relationship type {{ type }} between the two items",
|
||||||
|
|
||||||
|
"relationships.add.error.server.content": "The server returned an error",
|
||||||
|
|
||||||
|
"relationships.add.error.title": "Unable to add relationship",
|
||||||
|
|
||||||
"relationships.isAuthorOf": "Authors",
|
"relationships.isAuthorOf": "Authors",
|
||||||
|
|
||||||
"relationships.isAuthorOf.Person": "Authors (persons)",
|
"relationships.isAuthorOf.Person": "Authors (persons)",
|
||||||
|
@@ -23,7 +23,6 @@ export interface GlobalConfig extends Config {
|
|||||||
notifications: INotificationBoardOptions;
|
notifications: INotificationBoardOptions;
|
||||||
submission: SubmissionConfig;
|
submission: SubmissionConfig;
|
||||||
universal: UniversalConfig;
|
universal: UniversalConfig;
|
||||||
gaTrackingId: string;
|
|
||||||
logDirectory: string;
|
logDirectory: string;
|
||||||
debug: boolean;
|
debug: boolean;
|
||||||
defaultLanguage: string;
|
defaultLanguage: string;
|
||||||
|
@@ -132,8 +132,6 @@ export const environment: GlobalConfig = {
|
|||||||
async: true,
|
async: true,
|
||||||
time: false
|
time: false
|
||||||
},
|
},
|
||||||
// Google Analytics tracking id
|
|
||||||
gaTrackingId: '',
|
|
||||||
// Log directory
|
// Log directory
|
||||||
logDirectory: '.',
|
logDirectory: '.',
|
||||||
// NOTE: will log all redux actions and transfers in console
|
// NOTE: will log all redux actions and transfers in console
|
||||||
|
@@ -110,8 +110,6 @@ export const environment: Partial<GlobalConfig> = {
|
|||||||
async: true,
|
async: true,
|
||||||
time: false
|
time: false
|
||||||
},
|
},
|
||||||
// Google Analytics tracking id
|
|
||||||
gaTrackingId: '',
|
|
||||||
// Log directory
|
// Log directory
|
||||||
logDirectory: '.',
|
logDirectory: '.',
|
||||||
// NOTE: will log all redux actions and transfers in console
|
// NOTE: will log all redux actions and transfers in console
|
||||||
|
@@ -6,7 +6,7 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
|||||||
import { bootloader } from '@angularclass/bootloader';
|
import { bootloader } from '@angularclass/bootloader';
|
||||||
|
|
||||||
import { load as loadWebFont } from 'webfontloader';
|
import { load as loadWebFont } from 'webfontloader';
|
||||||
import { hasValue, isNotEmpty } from './app/shared/empty.util';
|
import { hasValue } from './app/shared/empty.util';
|
||||||
|
|
||||||
import { BrowserAppModule } from './modules/app/browser-app.module';
|
import { BrowserAppModule } from './modules/app/browser-app.module';
|
||||||
|
|
||||||
@@ -25,25 +25,9 @@ export function main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addGoogleAnalytics();
|
|
||||||
|
|
||||||
return platformBrowserDynamic().bootstrapModule(BrowserAppModule, {preserveWhitespaces:true});
|
return platformBrowserDynamic().bootstrapModule(BrowserAppModule, {preserveWhitespaces:true});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addGoogleAnalytics() {
|
|
||||||
// Add google analytics if key is present in config
|
|
||||||
const trackingId = environment.gaTrackingId;
|
|
||||||
if (isNotEmpty(trackingId)) {
|
|
||||||
const keyScript = document.createElement('script');
|
|
||||||
keyScript.innerHTML = `(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
||||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
||||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
||||||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');`
|
|
||||||
+ 'ga(\'create\', \'' + environment.gaTrackingId + '\', \'auto\');';
|
|
||||||
document.body.appendChild(keyScript);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// support async tag or hmr
|
// support async tag or hmr
|
||||||
if (hasValue(environment.universal) && environment.universal.preboot === false) {
|
if (hasValue(environment.universal) && environment.universal.preboot === false) {
|
||||||
bootloader(main);
|
bootloader(main);
|
||||||
|
@@ -30,6 +30,7 @@ import {
|
|||||||
LocationToken
|
LocationToken
|
||||||
} from '../../app/core/services/browser-hard-redirect.service';
|
} from '../../app/core/services/browser-hard-redirect.service';
|
||||||
import { LocaleService } from '../../app/core/locale/locale.service';
|
import { LocaleService } from '../../app/core/locale/locale.service';
|
||||||
|
import {GoogleAnalyticsService} from '../../app/statistics/google-analytics.service';
|
||||||
|
|
||||||
export const REQ_KEY = makeStateKey<string>('req');
|
export const REQ_KEY = makeStateKey<string>('req');
|
||||||
|
|
||||||
@@ -99,6 +100,10 @@ export function getRequest(transferState: TransferState): any {
|
|||||||
provide: HardRedirectService,
|
provide: HardRedirectService,
|
||||||
useClass: BrowserHardRedirectService,
|
useClass: BrowserHardRedirectService,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: GoogleAnalyticsService,
|
||||||
|
useClass: GoogleAnalyticsService,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
provide: LocationToken,
|
provide: LocationToken,
|
||||||
useFactory: locationProvider,
|
useFactory: locationProvider,
|
||||||
|
Reference in New Issue
Block a user