mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 12:33:07 +00:00
Merge remote-tracking branch 'remotes/origin/main' into upgrade_angular10
# Conflicts: # package.json # server.ts # src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.ts # src/app/+admin/admin-access-control/group-registry/group-form/group-form.component.ts # src/app/+admin/admin-access-control/group-registry/groups-registry.component.spec.ts # src/app/+admin/admin-access-control/group-registry/groups-registry.component.ts # src/app/+collection-page/collection-page.component.ts # src/app/+item-page/edit-item-page/item-page-reinstate.guard.ts # src/app/+item-page/edit-item-page/item-page-withdraw.guard.ts # src/app/+item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts # src/app/+item-page/edit-item-page/item-relationships/item-relationships.component.ts # src/app/+item-page/item-page-administrator.guard.ts # src/app/app-routing.module.ts # src/app/community-list-page/community-list-service.ts # src/app/core/data/entity-type.service.ts # src/app/core/data/feature-authorization/feature-authorization-guard/dso-page-feature.guard.spec.ts # src/app/core/data/feature-authorization/feature-authorization-guard/feature-authorization.guard.spec.ts # src/app/core/data/feature-authorization/feature-authorization-guard/feature-authorization.guard.ts # src/app/core/data/feature-authorization/feature-authorization-guard/site-administrator.guard.ts # src/app/core/data/feature-authorization/feature-authorization-guard/site-register.guard.ts # src/app/core/data/object-updates/object-updates.reducer.ts # src/app/core/shared/operators.ts # src/app/process-page/detail/process-detail.component.ts # src/app/shared/comcol-forms/delete-comcol-page/delete-comcol-page.component.ts # src/app/shared/dso-selector/dso-selector/dso-selector.component.ts # src/app/shared/input-suggestions/filter-suggestions/filter-input-suggestions.component.ts # src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.ts # src/app/shared/shared.module.ts # yarn.lock
This commit is contained in:
@@ -17,10 +17,9 @@ coverage:
|
||||
# Configuration for patch-level checks. This checks the relative coverage of the new PR code ONLY.
|
||||
patch:
|
||||
default:
|
||||
# For each PR, make sure the coverage of the new code is within 1% of current overall coverage.
|
||||
# We let 'patch' be more lenient as we only require *project* coverage to not drop significantly.
|
||||
target: auto
|
||||
threshold: 1%
|
||||
# Enable informational mode, which just provides info to reviewers & always passes
|
||||
# https://docs.codecov.io/docs/commit-status#section-informational
|
||||
informational: true
|
||||
|
||||
# Turn PR comments "off". This feature adds the code coverage summary as a
|
||||
# comment on each PR. See https://docs.codecov.io/docs/pull-request-comments
|
||||
|
@@ -12,3 +12,6 @@ trim_trailing_whitespace = true
|
||||
[*.md]
|
||||
insert_final_newline = false
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.ts]
|
||||
quote_type = single
|
||||
|
87
.github/workflows/build.yml
vendored
Normal file
87
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
# DSpace Continuous Integration/Build via GitHub Actions
|
||||
# Concepts borrowed from
|
||||
# https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-nodejs
|
||||
name: Build
|
||||
|
||||
# Run this Build for all pushes / PRs to current branch
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
# The ci step will test the dspace-angular code against DSpace REST.
|
||||
# Direct that step to utilize a DSpace REST service that has been started in docker.
|
||||
DSPACE_REST_HOST: localhost
|
||||
DSPACE_REST_PORT: 8080
|
||||
DSPACE_REST_NAMESPACE: '/server'
|
||||
DSPACE_REST_SSL: false
|
||||
strategy:
|
||||
# Create a matrix of Node versions to test against (in parallel)
|
||||
matrix:
|
||||
node-version: [10.x, 12.x]
|
||||
# Do NOT exit immediately if one matrix job fails
|
||||
fail-fast: false
|
||||
# These are the actual CI steps to perform per job
|
||||
steps:
|
||||
# https://github.com/actions/checkout
|
||||
- name: Checkout codebase
|
||||
uses: actions/checkout@v1
|
||||
|
||||
# https://github.com/actions/setup-node
|
||||
- name: Install Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Install latest Chrome (for e2e tests)
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get --only-upgrade install google-chrome-stable -y
|
||||
google-chrome --version
|
||||
|
||||
# https://github.com/actions/cache/blob/main/examples.md#node---yarn
|
||||
- name: Get Yarn cache directory
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
- name: Cache Yarn dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
# Cache entire Yarn cache directory (see previous step)
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
# Cache key is hash of yarn.lock. Therefore changes to yarn.lock will invalidate cache
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||
restore-keys: ${{ runner.os }}-yarn-
|
||||
|
||||
- name: Install Yarn dependencies
|
||||
run: yarn install --frozen-lockfile
|
||||
|
||||
- name: Run lint
|
||||
run: yarn run lint
|
||||
|
||||
- name: Run build
|
||||
run: yarn run build:prod
|
||||
|
||||
- name: Run specs (unit tests)
|
||||
run: yarn run test:headless
|
||||
|
||||
# Using docker-compose start backend using CI configuration
|
||||
# and load assetstore from a cached copy
|
||||
- name: Start DSpace REST Backend via Docker (for e2e tests)
|
||||
run: |
|
||||
docker-compose -f ./docker/docker-compose-ci.yml up -d
|
||||
docker-compose -f ./docker/cli.yml -f ./docker/cli.assetstore.yml run --rm dspace-cli
|
||||
docker container ls
|
||||
|
||||
- name: Run e2e tests (integration tests)
|
||||
run: yarn run e2e:ci
|
||||
|
||||
- name: Shutdown Docker containers
|
||||
run: docker-compose -f ./docker/docker-compose-ci.yml down
|
||||
|
||||
# NOTE: Angular CLI only supports code coverage for specs. See https://github.com/angular/angular-cli/issues/6286
|
||||
# Upload coverage reports to Codecov (for Node v12 only)
|
||||
# https://github.com/codecov/codecov-action
|
||||
- name: Upload coverage to Codecov.io
|
||||
uses: codecov/codecov-action@v1
|
||||
if: matrix.node-version == '12.x'
|
66
.travis.yml
66
.travis.yml
@@ -1,66 +0,0 @@
|
||||
os: linux
|
||||
dist: bionic
|
||||
language: node_js
|
||||
|
||||
# Enable caching for yarn & node_modules
|
||||
cache:
|
||||
yarn: true
|
||||
|
||||
node_js:
|
||||
- "10"
|
||||
- "12"
|
||||
|
||||
# Install latest chrome (for e2e headless testing). Run an update if needed.
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- google-chrome
|
||||
packages:
|
||||
- google-chrome-stable
|
||||
update: true
|
||||
|
||||
env:
|
||||
# The ci step will test the dspace-angular code against DSpace REST.
|
||||
# Direct that step to utilize a DSpace REST service that has been started in docker.
|
||||
DSPACE_REST_HOST: localhost
|
||||
DSPACE_REST_PORT: 8080
|
||||
DSPACE_REST_NAMESPACE: '/server'
|
||||
DSPACE_REST_SSL: false
|
||||
|
||||
before_install:
|
||||
# Check our versions of everything
|
||||
- echo "Check versions"
|
||||
- yarn -v
|
||||
- docker-compose -v
|
||||
- google-chrome-stable --version
|
||||
|
||||
install:
|
||||
# Start up a test DSpace 7 REST backend using the entities database dump
|
||||
- docker-compose -f ./docker/docker-compose-travis.yml up -d
|
||||
# Use the dspace-cli image to populate the assetstore. Triggers a discovery and oai update
|
||||
- docker-compose -f ./docker/cli.yml -f ./docker/cli.assetstore.yml run --rm dspace-cli
|
||||
# Install all local dependencies (retry if initially fails)
|
||||
- travis_retry yarn install
|
||||
|
||||
before_script:
|
||||
- echo "Check Docker containers"
|
||||
- docker container ls
|
||||
# The following line could be enabled to verify that the rest server is responding.
|
||||
#- echo "Check REST API available (via Docker)"
|
||||
#- curl http://localhost:8080/server/
|
||||
|
||||
script:
|
||||
# build app and run all tests
|
||||
- ng lint || travis_terminate 1;
|
||||
- travis_wait yarn run build:prod || travis_terminate 1;
|
||||
- yarn test:headless || travis_terminate 1;
|
||||
- yarn run e2e:ci || travis_terminate 1;
|
||||
|
||||
after_script:
|
||||
# Shutdown docker after everything runs
|
||||
- docker-compose -f ./docker/docker-compose-travis.yml down
|
||||
|
||||
# After a successful build and test (see 'script'), send code coverage reports to codecov.io
|
||||
# NOTE: As there's no need to send coverage multiple times, we only run this for one version of node.
|
||||
after_success:
|
||||
- if [ "$TRAVIS_NODE_VERSION" = "12" ]; then bash <(curl -s https://codecov.io/bash); fi
|
@@ -1,4 +1,4 @@
|
||||
[](https://travis-ci.com/DSpace/dspace-angular) [](https://codecov.io/gh/DSpace/dspace-angular) [](https://github.com/angular/universal)
|
||||
[](https://github.com/DSpace/dspace-angular/actions?query=workflow%3ABuild) [](https://codecov.io/gh/DSpace/dspace-angular) [](https://github.com/angular/universal)
|
||||
|
||||
dspace-angular
|
||||
==============
|
||||
|
@@ -1,3 +1,4 @@
|
||||
# Docker Compose for running the DSpace backend for e2e testing in CI
|
||||
networks:
|
||||
dspacenet:
|
||||
services:
|
@@ -42,7 +42,7 @@
|
||||
"clean:bld": "rimraf build",
|
||||
"clean:node": "rimraf node_modules",
|
||||
"clean:prod": "yarn run clean:coverage && yarn run clean:doc && yarn run clean:dist && yarn run clean:log && yarn run clean:json && yarn run clean:bld",
|
||||
"clean": "yarn run clean:prod && yarn run clean:node && yarn run clean:env",
|
||||
"clean": "yarn run clean:prod && yarn run clean:env && yarn run clean:node",
|
||||
"clean:env": "rimraf src/environments/environment.ts",
|
||||
"sync-i18n": "yarn run config:dev && ts-node --project ./tsconfig.ts-node.json scripts/sync-i18n-files.ts",
|
||||
"postinstall": "ngcc"
|
||||
@@ -91,6 +91,7 @@
|
||||
"debug-loader": "^0.0.1",
|
||||
"deepmerge": "^4.2.2",
|
||||
"express": "^4.17.1",
|
||||
"express-rate-limit": "^5.1.3",
|
||||
"fast-json-patch": "^2.0.7",
|
||||
"file-saver": "^1.3.8",
|
||||
"filesize": "^6.1.0",
|
||||
|
@@ -54,13 +54,6 @@ import(environmentFilePath)
|
||||
function generateEnvironmentFile(file: GlobalConfig): void {
|
||||
file.production = production;
|
||||
buildBaseUrls(file);
|
||||
|
||||
// TODO remove workaround in beta 5
|
||||
if (file.rest.nameSpace.match("(.*)/api/?$") !== null) {
|
||||
file.rest.nameSpace = getNameSpace(file.rest.nameSpace);
|
||||
console.log(colors.white.bgMagenta.bold(`The rest.nameSpace property in your environment file or in your DSPACE_REST_NAMESPACE environment variable ends with '/api'.\nThis is deprecated. As '/api' isn't configurable on the rest side, it shouldn't be repeated in every environment file.\nPlease change the rest nameSpace to '${file.rest.nameSpace}'`));
|
||||
}
|
||||
|
||||
const contents = `export const environment = ` + JSON.stringify(file);
|
||||
writeFile(targetPath, contents, (err) => {
|
||||
if (err) {
|
||||
@@ -119,16 +112,5 @@ function getPort(port: number): string {
|
||||
}
|
||||
|
||||
function getNameSpace(nameSpace: string): string {
|
||||
// TODO remove workaround in beta 5
|
||||
const apiMatches = nameSpace.match("(.*)/api/?$");
|
||||
if (apiMatches != null) {
|
||||
let newValue = '/'
|
||||
if (hasValue(apiMatches[1])) {
|
||||
newValue = apiMatches[1];
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
else {
|
||||
return nameSpace ? nameSpace.charAt(0) === '/' ? nameSpace : '/' + nameSpace : '';
|
||||
}
|
||||
}
|
||||
|
17
server.ts
17
server.ts
@@ -35,6 +35,7 @@ import { environment } from './src/environments/environment';
|
||||
import { createProxyMiddleware } from 'http-proxy-middleware';
|
||||
import { hasValue, hasNoValue } from './src/app/shared/empty.util';
|
||||
import { APP_BASE_HREF } from '@angular/common';
|
||||
import { UIServerConfig } from './src/config/ui-server-config.interface';
|
||||
|
||||
/*
|
||||
* Set path for the browser application's dist folder
|
||||
@@ -122,6 +123,19 @@ export function app() {
|
||||
res.status(404).send('data requests are not yet supported');
|
||||
});
|
||||
|
||||
/**
|
||||
* Checks if the rateLimiter property is present
|
||||
* When it is present, the rateLimiter will be enabled. When it is undefined, the rateLimiter will be disabled.
|
||||
*/
|
||||
if (hasValue((environment.ui as UIServerConfig).rateLimiter)) {
|
||||
const RateLimit = require('express-rate-limit');
|
||||
const limiter = new RateLimit({
|
||||
windowMs: (environment.ui as UIServerConfig).rateLimiter.windowMs,
|
||||
max: (environment.ui as UIServerConfig).rateLimiter.max
|
||||
});
|
||||
app.use(limiter);
|
||||
}
|
||||
|
||||
/*
|
||||
* Serve static resources (images, i18n messages, …)
|
||||
*/
|
||||
@@ -235,8 +249,9 @@ if (environment.ui.ssl) {
|
||||
certificate: certificate
|
||||
});
|
||||
} else {
|
||||
console.warn('Disabling certificate validation and proceeding with a self-signed certificate. If this is a production server, it is recommended that you configure a valid certificate instead.');
|
||||
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; // lgtm[js/disabling-certificate-validation]
|
||||
|
||||
pem.createCertificate({
|
||||
days: 1,
|
||||
|
@@ -13,12 +13,12 @@ import { GROUP_EDIT_PATH } from './admin-access-control-routing-paths';
|
||||
{
|
||||
path: `${GROUP_EDIT_PATH}/:groupId`,
|
||||
component: GroupFormComponent,
|
||||
data: {title: 'admin.registries.schema.title'}
|
||||
data: {title: 'admin.access-control.groups.title.singleGroup'}
|
||||
},
|
||||
{
|
||||
path: `${GROUP_EDIT_PATH}/newGroup`,
|
||||
component: GroupFormComponent,
|
||||
data: {title: 'admin.registries.schema.title'}
|
||||
data: {title: 'admin.access-control.groups.title.addGroup'}
|
||||
},
|
||||
])
|
||||
]
|
||||
|
@@ -40,7 +40,7 @@
|
||||
</form>
|
||||
|
||||
<ds-pagination
|
||||
*ngIf="(ePeopleDto$ | async)?.totalElements > 0"
|
||||
*ngIf="(pageInfoState$ | async)?.totalElements > 0"
|
||||
[paginationOptions]="config"
|
||||
[pageInfoState]="pageInfoState$"
|
||||
[collectionSize]="(pageInfoState$ | async)?.totalElements"
|
||||
|
@@ -44,7 +44,7 @@ describe('EPeopleRegistryComponent', () => {
|
||||
activeEPerson: null,
|
||||
allEpeople: mockEPeople,
|
||||
getEPeople(): Observable<RemoteData<PaginatedList<EPerson>>> {
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(null, this.allEpeople));
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: this.allEpeople.length, totalElements: this.allEpeople.length, totalPages: 1, currentPage: 1 }), this.allEpeople));
|
||||
},
|
||||
getActiveEPerson(): Observable<EPerson> {
|
||||
return observableOf(this.activeEPerson);
|
||||
@@ -54,18 +54,18 @@ describe('EPeopleRegistryComponent', () => {
|
||||
const result = this.allEpeople.find((ePerson: EPerson) => {
|
||||
return ePerson.email === query;
|
||||
});
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [result]));
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: [result].length, totalElements: [result].length, totalPages: 1, currentPage: 1 }), [result]));
|
||||
}
|
||||
if (scope === 'metadata') {
|
||||
if (query === '') {
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(null, this.allEpeople));
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: this.allEpeople.length, totalElements: this.allEpeople.length, totalPages: 1, currentPage: 1 }), this.allEpeople));
|
||||
}
|
||||
const result = this.allEpeople.find((ePerson: EPerson) => {
|
||||
return (ePerson.name.includes(query) || ePerson.email.includes(query));
|
||||
});
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [result]));
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: [result].length, totalElements: [result].length, totalPages: 1, currentPage: 1 }), [result]));
|
||||
}
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(null, this.allEpeople));
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: this.allEpeople.length, totalElements: this.allEpeople.length, totalPages: 1, currentPage: 1 }), this.allEpeople));
|
||||
},
|
||||
deleteEPerson(ePerson: EPerson): Observable<boolean> {
|
||||
this.allEpeople = this.allEpeople.filter((ePerson2: EPerson) => {
|
||||
|
@@ -140,6 +140,7 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
|
||||
elementsPerPage: this.config.pageSize
|
||||
}).subscribe((peopleRD) => {
|
||||
this.ePeople$.next(peopleRD);
|
||||
this.pageInfoState$.next(peopleRD.payload.pageInfo);
|
||||
}
|
||||
));
|
||||
|
||||
|
@@ -1,6 +1,11 @@
|
||||
<div class="container">
|
||||
<div class="group-form row">
|
||||
<div class="col-12">
|
||||
<ds-alert *ngIf="groupBeingEdited?.permanent" [type]="AlertTypeEnum.Warning"
|
||||
[content]="messagePrefix + '.alert.permanent'"></ds-alert>
|
||||
<ds-alert *ngIf="!(canEdit$ | async) && (groupDataService.getActiveGroup() | async)" [type]="AlertTypeEnum.Warning"
|
||||
[content]="(messagePrefix + '.alert.workflowGroup' | translate:{ name: (getLinkedDSO(groupBeingEdited) | async)?.payload?.name, comcol: (getLinkedDSO(groupBeingEdited) | async)?.payload?.type, comcolEditRolesRoute: (getLinkedEditRolesRoute(groupBeingEdited) | async) })">
|
||||
</ds-alert>
|
||||
|
||||
<div *ngIf="groupDataService.getActiveGroup() | async; then editheader; else createHeader"></div>
|
||||
|
||||
@@ -18,10 +23,18 @@
|
||||
[formLayout]="formLayout"
|
||||
(cancel)="onCancel()"
|
||||
(submitForm)="onSubmit()">
|
||||
<div *ngIf="groupBeingEdited != null" class="row">
|
||||
<button class="btn btn-light delete-button" [disabled]="!(canEdit$ | async) || groupBeingEdited.permanent"
|
||||
(click)="delete()">
|
||||
<i class="fa fa-trash"></i> {{ messagePrefix + '.actions.delete' | translate}}
|
||||
</button>
|
||||
</div>
|
||||
</ds-form>
|
||||
|
||||
<ds-members-list *ngIf="groupBeingEdited != null" [messagePrefix]="messagePrefix + '.members-list'"></ds-members-list>
|
||||
<ds-subgroups-list *ngIf="groupBeingEdited != null" [messagePrefix]="messagePrefix + '.subgroups-list'"></ds-subgroups-list>
|
||||
<ds-members-list *ngIf="groupBeingEdited != null"
|
||||
[messagePrefix]="messagePrefix + '.members-list'"></ds-members-list>
|
||||
<ds-subgroups-list *ngIf="groupBeingEdited != null"
|
||||
[messagePrefix]="messagePrefix + '.subgroups-list'"></ds-subgroups-list>
|
||||
|
||||
<div>
|
||||
<button [routerLink]="[this.groupDataService.getGroupRegistryRouterLink()]"
|
||||
|
@@ -13,11 +13,14 @@ import { RemoteDataBuildService } from '../../../../core/cache/builders/remote-d
|
||||
import { ObjectCacheService } from '../../../../core/cache/object-cache.service';
|
||||
import { RestResponse } from '../../../../core/cache/response.models';
|
||||
import { DSOChangeAnalyzer } from '../../../../core/data/dso-change-analyzer.service';
|
||||
import { DSpaceObjectDataService } from '../../../../core/data/dspace-object-data.service';
|
||||
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
|
||||
import { PaginatedList } from '../../../../core/data/paginated-list';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { EPersonDataService } from '../../../../core/eperson/eperson-data.service';
|
||||
import { GroupDataService } from '../../../../core/eperson/group-data.service';
|
||||
import { Group } from '../../../../core/eperson/models/group.model';
|
||||
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
|
||||
import { HALEndpointService } from '../../../../core/shared/hal-endpoint.service';
|
||||
import { PageInfo } from '../../../../core/shared/page-info.model';
|
||||
import { UUIDService } from '../../../../core/shared/uuid.service';
|
||||
@@ -39,6 +42,9 @@ describe('GroupFormComponent', () => {
|
||||
let builderService: FormBuilderService;
|
||||
let ePersonDataServiceStub: any;
|
||||
let groupsDataServiceStub: any;
|
||||
let dsoDataServiceStub: any;
|
||||
let authorizationService: AuthorizationDataService;
|
||||
let notificationService: NotificationsServiceStub;
|
||||
let router;
|
||||
|
||||
let groups;
|
||||
@@ -73,6 +79,9 @@ describe('GroupFormComponent', () => {
|
||||
editGroup(group: Group) {
|
||||
this.activeGroup = group;
|
||||
},
|
||||
updateGroup(group: Group) {
|
||||
return null;
|
||||
},
|
||||
cancelEditGroup(): void {
|
||||
this.activeGroup = null;
|
||||
},
|
||||
@@ -87,9 +96,18 @@ describe('GroupFormComponent', () => {
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), []));
|
||||
}
|
||||
};
|
||||
authorizationService = jasmine.createSpyObj('authorizationService', {
|
||||
isAuthorized: observableOf(true)
|
||||
});
|
||||
dsoDataServiceStub = {
|
||||
findByHref(href: string): Observable<RemoteData<DSpaceObject>> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
builderService = getMockFormBuilderService();
|
||||
translateService = getMockTranslateService();
|
||||
router = new RouterMock();
|
||||
notificationService = new NotificationsServiceStub();
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule,
|
||||
TranslateModule.forRoot({
|
||||
@@ -103,7 +121,8 @@ describe('GroupFormComponent', () => {
|
||||
providers: [GroupFormComponent,
|
||||
{ provide: EPersonDataService, useValue: ePersonDataServiceStub },
|
||||
{ provide: GroupDataService, useValue: groupsDataServiceStub },
|
||||
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
|
||||
{ provide: DSpaceObjectDataService, useValue: dsoDataServiceStub },
|
||||
{ provide: NotificationsService, useValue: notificationService },
|
||||
{ provide: FormBuilderService, useValue: builderService },
|
||||
{ provide: DSOChangeAnalyzer, useValue: {} },
|
||||
{ provide: HttpClient, useValue: {} },
|
||||
@@ -114,6 +133,7 @@ describe('GroupFormComponent', () => {
|
||||
{ provide: HALEndpointService, useValue: {} },
|
||||
{ provide: ActivatedRoute, useValue: { data: observableOf({ dso: { payload: {} } }), params: observableOf({}) } },
|
||||
{ provide: Router, useValue: router },
|
||||
{ provide: AuthorizationDataService, useValue: authorizationService },
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
@@ -147,6 +167,34 @@ describe('GroupFormComponent', () => {
|
||||
});
|
||||
}));
|
||||
});
|
||||
describe('with active Group', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(groupsDataServiceStub, 'getActiveGroup').and.returnValue(observableOf(expected));
|
||||
spyOn(groupsDataServiceStub, 'updateGroup').and.returnValue(observableOf(new RestResponse(true, 200, 'OK')));
|
||||
component.groupName.value = 'newGroupName';
|
||||
component.onSubmit();
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should emit the existing group using the correct new values', async(() => {
|
||||
const expected2 = Object.assign(new Group(), {
|
||||
name: 'newGroupName',
|
||||
metadata: {
|
||||
'dc.description': [
|
||||
{
|
||||
value: groupDescription
|
||||
}
|
||||
],
|
||||
},
|
||||
});
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.submitForm.emit).toHaveBeenCalledWith(expected2);
|
||||
});
|
||||
}));
|
||||
it('should emit success notification', () => {
|
||||
expect(notificationService.success).toHaveBeenCalled();
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { Component, EventEmitter, HostListener, OnDestroy, OnInit, Output } from '@angular/core';
|
||||
import { FormGroup } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import {
|
||||
DynamicFormControlModel,
|
||||
DynamicFormLayout,
|
||||
@@ -8,17 +9,30 @@ import {
|
||||
DynamicTextAreaModel
|
||||
} from '@ng-dynamic-forms/core';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { combineLatest, Subscription } from 'rxjs';
|
||||
import { take } from 'rxjs/operators';
|
||||
import { ObservedValueOf, combineLatest as observableCombineLatest, Observable, of as observableOf, Subscription } from 'rxjs';
|
||||
import { catchError, map, switchMap, take } from 'rxjs/operators';
|
||||
import { getCollectionEditRolesRoute } from '../../../../+collection-page/collection-page-routing-paths';
|
||||
import { getCommunityEditRolesRoute } from '../../../../+community-page/community-page-routing-paths';
|
||||
import { RestResponse } from '../../../../core/cache/response.models';
|
||||
import { DSpaceObjectDataService } from '../../../../core/data/dspace-object-data.service';
|
||||
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
|
||||
import { FeatureID } from '../../../../core/data/feature-authorization/feature-id';
|
||||
import { PaginatedList } from '../../../../core/data/paginated-list';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { RequestService } from '../../../../core/data/request.service';
|
||||
import { EPersonDataService } from '../../../../core/eperson/eperson-data.service';
|
||||
import { GroupDataService } from '../../../../core/eperson/group-data.service';
|
||||
import { Group } from '../../../../core/eperson/models/group.model';
|
||||
import { Collection } from '../../../../core/shared/collection.model';
|
||||
import { Community } from '../../../../core/shared/community.model';
|
||||
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
|
||||
import { getRemoteDataPayload, getSucceededRemoteData } from '../../../../core/shared/operators';
|
||||
import { AlertType } from '../../../../shared/alert/aletr-type';
|
||||
import { ConfirmationModalComponent } from '../../../../shared/confirmation-modal/confirmation-modal.component';
|
||||
import { hasValue, isNotEmpty } from '../../../../shared/empty.util';
|
||||
import { FormBuilderService } from '../../../../shared/form/builder/form-builder.service';
|
||||
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
||||
import { followLink } from '../../../../shared/utils/follow-link-config.model';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-group-form',
|
||||
@@ -88,22 +102,51 @@ export class GroupFormComponent implements OnInit, OnDestroy {
|
||||
*/
|
||||
groupBeingEdited: Group;
|
||||
|
||||
/**
|
||||
* Observable whether or not the logged in user is allowed to delete the Group & doesn't have a linked object (community / collection linked to workspace group
|
||||
*/
|
||||
canEdit$: Observable<boolean>;
|
||||
|
||||
/**
|
||||
* The AlertType enumeration
|
||||
* @type {AlertType}
|
||||
*/
|
||||
public AlertTypeEnum = AlertType;
|
||||
|
||||
constructor(public groupDataService: GroupDataService,
|
||||
private ePersonDataService: EPersonDataService,
|
||||
private dSpaceObjectDataService: DSpaceObjectDataService,
|
||||
private formBuilderService: FormBuilderService,
|
||||
private translateService: TranslateService,
|
||||
private notificationsService: NotificationsService,
|
||||
private route: ActivatedRoute,
|
||||
protected router: Router) {
|
||||
protected router: Router,
|
||||
private authorizationService: AuthorizationDataService,
|
||||
private modalService: NgbModal,
|
||||
public requestService: RequestService) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.initialisePage();
|
||||
}
|
||||
|
||||
initialisePage() {
|
||||
this.subs.push(this.route.params.subscribe((params) => {
|
||||
this.setActiveGroup(params.groupId);
|
||||
}));
|
||||
combineLatest(
|
||||
this.canEdit$ = this.groupDataService.getActiveGroup().pipe(
|
||||
switchMap((group: Group) => {
|
||||
return observableCombineLatest(
|
||||
this.authorizationService.isAuthorized(FeatureID.CanDelete, hasValue(group) ? group.self : undefined),
|
||||
this.hasLinkedDSO(group),
|
||||
(isAuthorized: ObservedValueOf<Observable<boolean>>, hasLinkedDSO: ObservedValueOf<Observable<boolean>>) => {
|
||||
return isAuthorized && !hasLinkedDSO;
|
||||
})
|
||||
})
|
||||
);
|
||||
observableCombineLatest(
|
||||
this.translateService.get(`${this.messagePrefix}.groupName`),
|
||||
this.translateService.get(`${this.messagePrefix}.groupDescription`),
|
||||
this.translateService.get(`${this.messagePrefix}.groupDescription`)
|
||||
).subscribe(([groupName, groupDescription]) => {
|
||||
this.groupName = new DynamicInputModel({
|
||||
id: 'groupName',
|
||||
@@ -122,21 +165,26 @@ export class GroupFormComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
this.formModel = [
|
||||
this.groupName,
|
||||
this.groupDescription
|
||||
this.groupDescription,
|
||||
];
|
||||
this.formGroup = this.formBuilderService.createFormGroup(this.formModel);
|
||||
this.subs.push(this.groupDataService.getActiveGroup().subscribe((activeGroup: Group) => {
|
||||
this.subs.push(
|
||||
observableCombineLatest(
|
||||
this.groupDataService.getActiveGroup(),
|
||||
this.canEdit$
|
||||
).subscribe(([activeGroup, canEdit]) => {
|
||||
if (activeGroup != null) {
|
||||
this.groupBeingEdited = activeGroup;
|
||||
this.formGroup.patchValue({
|
||||
groupName: activeGroup != null ? activeGroup.name : '',
|
||||
groupDescription: activeGroup != null ? activeGroup.firstMetadataValue('dc.description') : '',
|
||||
});
|
||||
if (activeGroup.permanent) {
|
||||
this.formGroup.get('groupName').disable();
|
||||
if (!canEdit || activeGroup.permanent) {
|
||||
this.formGroup.disable();
|
||||
}
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -171,7 +219,7 @@ export class GroupFormComponent implements OnInit, OnDestroy {
|
||||
if (group === null) {
|
||||
this.createNewGroup(values);
|
||||
} else {
|
||||
this.editGroup(group, values);
|
||||
this.editGroup(group);
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -192,6 +240,7 @@ export class GroupFormComponent implements OnInit, OnDestroy {
|
||||
if (isNotEmpty(resp.resourceSelfLinks)) {
|
||||
const groupSelfLink = resp.resourceSelfLinks[0];
|
||||
this.setActiveGroupWithLink(groupSelfLink);
|
||||
this.groupDataService.clearGroupsRequests();
|
||||
this.router.navigateByUrl(this.groupDataService.getGroupEditPageRouterLinkWithID(this.groupDataService.getUUIDFromString(groupSelfLink)));
|
||||
}
|
||||
} else {
|
||||
@@ -224,14 +273,32 @@ export class GroupFormComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
/**
|
||||
* // TODO
|
||||
* @param group
|
||||
* @param values
|
||||
* Edit existing Group based on given values from form and old Group
|
||||
* @param group Group to edit and old values contained within
|
||||
*/
|
||||
editGroup(group: Group, values) {
|
||||
// TODO (backend)
|
||||
console.log('TODO implement editGroup', values);
|
||||
this.notificationsService.error('TODO implement editGroup (not yet implemented in backend) ');
|
||||
editGroup(group: Group) {
|
||||
const editedGroup = Object.assign(new Group(), {
|
||||
id: group.id,
|
||||
metadata: {
|
||||
'dc.description': [
|
||||
{
|
||||
value: (hasValue(this.groupDescription.value) ? this.groupDescription.value : group.firstMetadataValue('dc.description'))
|
||||
}
|
||||
],
|
||||
},
|
||||
name: (hasValue(this.groupName.value) ? this.groupName.value : group.name),
|
||||
_links: group._links,
|
||||
});
|
||||
const response = this.groupDataService.updateGroup(editedGroup);
|
||||
response.pipe(take(1)).subscribe((restResponse: RestResponse) => {
|
||||
if (restResponse.isSuccessful) {
|
||||
this.notificationsService.success(this.translateService.get(this.messagePrefix + '.notification.edited.success', { name: editedGroup.name }));
|
||||
this.submitForm.emit(editedGroup);
|
||||
} else {
|
||||
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.edited.failure', { name: editedGroup.name }));
|
||||
this.cancelForm.emit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,7 +324,7 @@ export class GroupFormComponent implements OnInit, OnDestroy {
|
||||
this.groupDataService.getActiveGroup().pipe(take(1)).subscribe((activeGroup: Group) => {
|
||||
if (activeGroup === null) {
|
||||
this.groupDataService.cancelEditGroup();
|
||||
this.groupDataService.findByHref(groupSelfLink)
|
||||
this.groupDataService.findByHref(groupSelfLink, followLink('subgroups'), followLink('epersons'), followLink('object'))
|
||||
.pipe(
|
||||
getSucceededRemoteData(),
|
||||
getRemoteDataPayload())
|
||||
@@ -268,6 +335,48 @@ export class GroupFormComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the Group from the Repository. The Group will be the only that this form is showing.
|
||||
* It'll either show a success or error message depending on whether the delete was successful or not.
|
||||
*/
|
||||
delete() {
|
||||
this.groupDataService.getActiveGroup().pipe(take(1)).subscribe((group: Group) => {
|
||||
const modalRef = this.modalService.open(ConfirmationModalComponent);
|
||||
modalRef.componentInstance.dso = group;
|
||||
modalRef.componentInstance.headerLabel = this.messagePrefix + '.delete-group.modal.header';
|
||||
modalRef.componentInstance.infoLabel = this.messagePrefix + '.delete-group.modal.info';
|
||||
modalRef.componentInstance.cancelLabel = this.messagePrefix + '.delete-group.modal.cancel';
|
||||
modalRef.componentInstance.confirmLabel = this.messagePrefix + '.delete-group.modal.confirm';
|
||||
modalRef.componentInstance.response.pipe(take(1)).subscribe((confirm: boolean) => {
|
||||
if (confirm) {
|
||||
if (hasValue(group.id)) {
|
||||
this.groupDataService.deleteGroup(group).pipe(take(1))
|
||||
.subscribe(([success, optionalErrorMessage]: [boolean, string]) => {
|
||||
if (success) {
|
||||
this.notificationsService.success(this.translateService.get(this.messagePrefix + '.notification.deleted.success', { name: group.name }));
|
||||
this.reset();
|
||||
} else {
|
||||
this.notificationsService.error(
|
||||
this.translateService.get(this.messagePrefix + '.notification.deleted.failure.title', { name: group.name }),
|
||||
this.translateService.get(this.messagePrefix + '.notification.deleted.failure.content', { cause: optionalErrorMessage }));
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will ensure that the page gets reset and that the cache is cleared
|
||||
*/
|
||||
reset() {
|
||||
this.groupDataService.getBrowseEndpoint().pipe(take(1)).subscribe((href: string) => {
|
||||
this.requestService.removeByHrefSubstring(href);
|
||||
});
|
||||
this.onCancel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the current edit when component is destroyed & unsub all subscriptions
|
||||
*/
|
||||
@@ -276,4 +385,58 @@ export class GroupFormComponent implements OnInit, OnDestroy {
|
||||
this.onCancel();
|
||||
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if group has a linked object (community or collection linked to a workflow group)
|
||||
* @param group
|
||||
*/
|
||||
hasLinkedDSO(group: Group): Observable<boolean> {
|
||||
if (hasValue(group) && hasValue(group._links.object.href)) {
|
||||
return this.getLinkedDSO(group).pipe(
|
||||
map((rd: RemoteData<DSpaceObject>) => {
|
||||
if (hasValue(rd) && hasValue(rd.payload)) {
|
||||
return true;
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}),
|
||||
catchError(() => observableOf(false)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get group's linked object if it has one (community or collection linked to a workflow group)
|
||||
* @param group
|
||||
*/
|
||||
getLinkedDSO(group: Group): Observable<RemoteData<DSpaceObject>> {
|
||||
if (hasValue(group) && hasValue(group._links.object.href)) {
|
||||
if (group.object === undefined) {
|
||||
return this.dSpaceObjectDataService.findByHref(group._links.object.href);
|
||||
}
|
||||
return group.object;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the route to the edit roles tab of the group's linked object (community or collection linked to a workflow group) if it has one
|
||||
* @param group
|
||||
*/
|
||||
getLinkedEditRolesRoute(group: Group): Observable<string> {
|
||||
if (hasValue(group) && hasValue(group._links.object.href)) {
|
||||
return this.getLinkedDSO(group).pipe(
|
||||
map((rd: RemoteData<DSpaceObject>) => {
|
||||
if (hasValue(rd) && hasValue(rd.payload)) {
|
||||
const dso = rd.payload
|
||||
switch ((dso as any).type) {
|
||||
case Community.type.value:
|
||||
return getCommunityEditRolesRoute(rd.payload.id);
|
||||
case Collection.type.value:
|
||||
return getCollectionEditRolesRoute(rd.payload.id);
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,10 +30,10 @@
|
||||
</form>
|
||||
|
||||
<ds-pagination
|
||||
*ngIf="(groups | async)?.payload?.totalElements > 0"
|
||||
*ngIf="(pageInfoState$ | async)?.totalElements > 0"
|
||||
[paginationOptions]="config"
|
||||
[pageInfoState]="(groups | async)?.payload"
|
||||
[collectionSize]="(groups | async)?.payload?.totalElements"
|
||||
[pageInfoState]="pageInfoState$"
|
||||
[collectionSize]="(pageInfoState$ | async)?.totalElements"
|
||||
[hideGear]="true"
|
||||
[hidePagerWhenSinglePage]="true"
|
||||
(pageChange)="onPageChange($event)">
|
||||
@@ -50,21 +50,21 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let group of (groups | async)?.payload?.page">
|
||||
<td>{{group.id}}</td>
|
||||
<td>{{group.name}}</td>
|
||||
<td>{{(getMembers(group) | async)?.payload?.totalElements + (getSubgroups(group) | async)?.payload?.totalElements}}</td>
|
||||
<tr *ngFor="let groupDto of (groupsDto$ | async)?.page">
|
||||
<td>{{groupDto.group.id}}</td>
|
||||
<td>{{groupDto.group.name}}</td>
|
||||
<td>{{(getMembers(groupDto.group) | async)?.payload?.totalElements + (getSubgroups(groupDto.group) | async)?.payload?.totalElements}}</td>
|
||||
<!-- <td>{{getOptionalComColFromName(group.name)}}</td>-->
|
||||
<td>
|
||||
<div class="btn-group edit-field">
|
||||
<button [routerLink]="groupService.getGroupEditPageRouterLink(group)"
|
||||
<button [routerLink]="groupService.getGroupEditPageRouterLink(groupDto.group)"
|
||||
class="btn btn-outline-primary btn-sm"
|
||||
title="{{messagePrefix + 'table.edit.buttons.edit' | translate: {name: group.name} }}">
|
||||
title="{{messagePrefix + 'table.edit.buttons.edit' | translate: {name: groupDto.group.name} }}">
|
||||
<i class="fas fa-edit fa-fw"></i>
|
||||
</button>
|
||||
<button *ngIf="!group?.permanent" (click)="deleteGroup(group)"
|
||||
class="btn btn-outline-danger btn-sm"
|
||||
title="{{messagePrefix + 'table.edit.buttons.remove' | translate: {name: group.name} }}">
|
||||
<button *ngIf="!groupDto.group?.permanent && groupDto.ableToDelete"
|
||||
(click)="deleteGroup(groupDto.group)" class="btn btn-outline-danger btn-sm"
|
||||
title="{{messagePrefix + 'table.edit.buttons.remove' | translate: {name: groupDto.group.name} }}">
|
||||
<i class="fas fa-trash-alt fa-fw"></i>
|
||||
</button>
|
||||
</div>
|
||||
@@ -75,7 +75,7 @@
|
||||
</div>
|
||||
</ds-pagination>
|
||||
|
||||
<div *ngIf="(groups | async)?.payload?.totalElements == 0" class="alert alert-info w-100 mb-2" role="alert">
|
||||
<div *ngIf="(pageInfoState$ | async)?.totalElements == 0" class="alert alert-info w-100 mb-2" role="alert">
|
||||
{{messagePrefix + 'no-items' | translate}}
|
||||
</div>
|
||||
|
||||
|
@@ -6,14 +6,18 @@ import { BrowserModule, By } from '@angular/platform-browser';
|
||||
import { Router } from '@angular/router';
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { DSpaceObjectDataService } from '../../../core/data/dspace-object-data.service';
|
||||
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
|
||||
import { PaginatedList } from '../../../core/data/paginated-list';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { RequestService } from '../../../core/data/request.service';
|
||||
import { EPersonDataService } from '../../../core/eperson/eperson-data.service';
|
||||
import { GroupDataService } from '../../../core/eperson/group-data.service';
|
||||
import { EPerson } from '../../../core/eperson/models/eperson.model';
|
||||
import { Group } from '../../../core/eperson/models/group.model';
|
||||
import { RouteService } from '../../../core/services/route.service';
|
||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||
import { PageInfo } from '../../../core/shared/page-info.model';
|
||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||
import { GroupMock, GroupMock2 } from '../../../shared/testing/group-mock';
|
||||
@@ -30,6 +34,8 @@ describe('GroupRegistryComponent', () => {
|
||||
let fixture: ComponentFixture<GroupsRegistryComponent>;
|
||||
let ePersonDataServiceStub: any;
|
||||
let groupsDataServiceStub: any;
|
||||
let dsoDataServiceStub: any;
|
||||
let authorizationService: AuthorizationDataService;
|
||||
|
||||
let mockGroups;
|
||||
let mockEPeople;
|
||||
@@ -41,11 +47,11 @@ describe('GroupRegistryComponent', () => {
|
||||
findAllByHref(href: string): Observable<RemoteData<PaginatedList<EPerson>>> {
|
||||
switch (href) {
|
||||
case 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid2/epersons':
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(null, []));
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: 1, totalElements: 0, totalPages: 0, currentPage: 1 }), []));
|
||||
case 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid/epersons':
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(null, [EPersonMock]));
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: 1, totalElements: 1, totalPages: 1, currentPage: 1 }), [EPersonMock]));
|
||||
default:
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(null, []));
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: 1, totalElements: 0, totalPages: 0, currentPage: 1 }), []));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -54,11 +60,11 @@ describe('GroupRegistryComponent', () => {
|
||||
findAllByHref(href: string): Observable<RemoteData<PaginatedList<Group>>> {
|
||||
switch (href) {
|
||||
case 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid2/groups':
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(null, []));
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: 1, totalElements: 0, totalPages: 0, currentPage: 1 }), []));
|
||||
case 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid/groups':
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(null, [GroupMock2]));
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: 1, totalElements: 1, totalPages: 1, currentPage: 1 }), [GroupMock2]));
|
||||
default:
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(null, []));
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: 1, totalElements: 0, totalPages: 0, currentPage: 1 }), []));
|
||||
}
|
||||
},
|
||||
getGroupEditPageRouterLink(group: Group): string {
|
||||
@@ -69,14 +75,22 @@ describe('GroupRegistryComponent', () => {
|
||||
},
|
||||
searchGroups(query: string): Observable<RemoteData<PaginatedList<Group>>> {
|
||||
if (query === '') {
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(null, this.allGroups));
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: this.allGroups.length, totalElements: this.allGroups.length, totalPages: 1, currentPage: 1 }), this.allGroups));
|
||||
}
|
||||
const result = this.allGroups.find((group: Group) => {
|
||||
return (group.id.includes(query));
|
||||
});
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [result]));
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: [result].length, totalElements: [result].length, totalPages: 1, currentPage: 1 }), [result]));
|
||||
}
|
||||
};
|
||||
dsoDataServiceStub = {
|
||||
findByHref(href: string): Observable<RemoteData<DSpaceObject>> {
|
||||
return createSuccessfulRemoteDataObject$(undefined);
|
||||
}
|
||||
}
|
||||
authorizationService = jasmine.createSpyObj('authorizationService', {
|
||||
isAuthorized: observableOf(true)
|
||||
});
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule,
|
||||
TranslateModule.forRoot({
|
||||
@@ -90,9 +104,12 @@ describe('GroupRegistryComponent', () => {
|
||||
providers: [GroupsRegistryComponent,
|
||||
{ provide: EPersonDataService, useValue: ePersonDataServiceStub },
|
||||
{ provide: GroupDataService, useValue: groupsDataServiceStub },
|
||||
{ provide: DSpaceObjectDataService, useValue: dsoDataServiceStub },
|
||||
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
|
||||
{ provide: RouteService, useValue: routeServiceStub },
|
||||
{ provide: Router, useValue: new RouterMock() },
|
||||
{ provide: AuthorizationDataService, useValue: authorizationService },
|
||||
{ provide: RequestService, useValue: jasmine.createSpyObj('requestService', ['removeByHrefSubstring'])}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
|
@@ -1,16 +1,26 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { FormBuilder } from '@angular/forms';
|
||||
import { Router } from '@angular/router';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { take } from 'rxjs/operators';
|
||||
import { BehaviorSubject, combineLatest as observableCombineLatest, Subscription, Observable, of as observableOf } from 'rxjs';
|
||||
import { filter } from 'rxjs/internal/operators/filter';
|
||||
import { ObservedValueOf } from 'rxjs/internal/types';
|
||||
import { catchError, map, switchMap, take } from 'rxjs/operators';
|
||||
import { DSpaceObjectDataService } from '../../../core/data/dspace-object-data.service';
|
||||
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
|
||||
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
|
||||
import { PaginatedList } from '../../../core/data/paginated-list';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { RequestService } from '../../../core/data/request.service';
|
||||
import { EPersonDataService } from '../../../core/eperson/eperson-data.service';
|
||||
import { GroupDataService } from '../../../core/eperson/group-data.service';
|
||||
import { EPerson } from '../../../core/eperson/models/eperson.model';
|
||||
import { GroupDtoModel } from '../../../core/eperson/models/group-dto.model';
|
||||
import { Group } from '../../../core/eperson/models/group.model';
|
||||
import { RouteService } from '../../../core/services/route.service';
|
||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||
import { getAllSucceededRemoteDataPayload } from '../../../core/shared/operators';
|
||||
import { PageInfo } from '../../../core/shared/page-info.model';
|
||||
import { hasValue } from '../../../shared/empty.util';
|
||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
|
||||
@@ -23,7 +33,7 @@ import { PaginationComponentOptions } from '../../../shared/pagination/paginatio
|
||||
* A component used for managing all existing groups within the repository.
|
||||
* The admin can create, edit or delete groups here.
|
||||
*/
|
||||
export class GroupsRegistryComponent implements OnInit {
|
||||
export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
||||
|
||||
messagePrefix = 'admin.access-control.groups.';
|
||||
|
||||
@@ -37,9 +47,19 @@ export class GroupsRegistryComponent implements OnInit {
|
||||
});
|
||||
|
||||
/**
|
||||
* A list of all the current groups within the repository or the result of the search
|
||||
* A list of all the current Groups within the repository or the result of the search
|
||||
*/
|
||||
groups: Observable<RemoteData<PaginatedList<Group>>>;
|
||||
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
|
||||
* as the result of the search
|
||||
*/
|
||||
groupsDto$: BehaviorSubject<PaginatedList<GroupDtoModel>> = new BehaviorSubject<PaginatedList<GroupDtoModel>>({} as any);
|
||||
|
||||
/**
|
||||
* An observable for the pageInfo, needed to pass to the pagination component
|
||||
*/
|
||||
pageInfoState$: BehaviorSubject<PageInfo> = new BehaviorSubject<PageInfo>(undefined);
|
||||
|
||||
// The search form
|
||||
searchForm;
|
||||
@@ -47,13 +67,21 @@ export class GroupsRegistryComponent implements OnInit {
|
||||
// Current search in groups registry
|
||||
currentSearchQuery: string;
|
||||
|
||||
/**
|
||||
* List of subscriptions
|
||||
*/
|
||||
subs: Subscription[] = [];
|
||||
|
||||
constructor(public groupService: GroupDataService,
|
||||
private ePersonDataService: EPersonDataService,
|
||||
private dSpaceObjectDataService: DSpaceObjectDataService,
|
||||
private translateService: TranslateService,
|
||||
private notificationsService: NotificationsService,
|
||||
private formBuilder: FormBuilder,
|
||||
protected routeService: RouteService,
|
||||
private router: Router) {
|
||||
private router: Router,
|
||||
private authorizationService: AuthorizationDataService,
|
||||
public requestService: RequestService) {
|
||||
this.currentSearchQuery = '';
|
||||
this.searchForm = this.formBuilder.group(({
|
||||
query: this.currentSearchQuery,
|
||||
@@ -84,37 +112,69 @@ export class GroupsRegistryComponent implements OnInit {
|
||||
this.currentSearchQuery = query;
|
||||
this.config.currentPage = 1;
|
||||
}
|
||||
this.groups = this.groupService.searchGroups(this.currentSearchQuery.trim(), {
|
||||
this.subs.push(this.groupService.searchGroups(this.currentSearchQuery.trim(), {
|
||||
currentPage: this.config.currentPage,
|
||||
elementsPerPage: this.config.pageSize
|
||||
});
|
||||
}).subscribe((groupsRD: RemoteData<PaginatedList<Group>>) => {
|
||||
this.groups$.next(groupsRD);
|
||||
this.pageInfoState$.next(groupsRD.payload.pageInfo);
|
||||
}
|
||||
));
|
||||
|
||||
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),
|
||||
(isAuthorized: ObservedValueOf<Observable<boolean>>, hasLinkedDSO: ObservedValueOf<Observable<boolean>>) => {
|
||||
const groupDtoModel: GroupDtoModel = new GroupDtoModel();
|
||||
groupDtoModel.ableToDelete = isAuthorized && !hasLinkedDSO;
|
||||
groupDtoModel.group = group;
|
||||
return groupDtoModel;
|
||||
}
|
||||
)
|
||||
})).pipe(map((dtos: GroupDtoModel[]) => {
|
||||
return new PaginatedList(groups.pageInfo, dtos);
|
||||
}))
|
||||
})).subscribe((value: PaginatedList<GroupDtoModel>) => {
|
||||
this.groupsDto$.next(value);
|
||||
this.pageInfoState$.next(value.pageInfo);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Group
|
||||
*/
|
||||
deleteGroup(group: Group) {
|
||||
// TODO (backend)
|
||||
console.log('TODO implement editGroup', group);
|
||||
this.notificationsService.error('TODO implement deleteGroup (not yet implemented in backend)');
|
||||
if (hasValue(group.id)) {
|
||||
this.groupService.deleteGroup(group).pipe(take(1)).subscribe((success: boolean) => {
|
||||
this.groupService.deleteGroup(group).pipe(take(1))
|
||||
.subscribe(([success, optionalErrorMessage]: [boolean, string]) => {
|
||||
if (success) {
|
||||
this.notificationsService.success(this.translateService.get(this.messagePrefix + 'notification.deleted.success', { name: group.name }));
|
||||
this.forceUpdateGroup();
|
||||
this.reset();
|
||||
} else {
|
||||
this.notificationsService.error(this.translateService.get(this.messagePrefix + 'notification.deleted.failure', { name: group.name }));
|
||||
this.notificationsService.error(
|
||||
this.translateService.get(this.messagePrefix + 'notification.deleted.failure.title', { name: group.name }),
|
||||
this.translateService.get(this.messagePrefix + 'notification.deleted.failure.content', { cause: optionalErrorMessage }));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force-update the list of groups by first clearing the cache related to groups, then performing a new REST call
|
||||
* This method will ensure that the page gets reset and that the cache is cleared
|
||||
*/
|
||||
public forceUpdateGroup() {
|
||||
this.groupService.clearGroupsRequests();
|
||||
reset() {
|
||||
this.groupService.getBrowseEndpoint().pipe(
|
||||
switchMap((href) => this.requestService.removeByHrefSubstring(href)),
|
||||
filter((isCached) => isCached),
|
||||
take(1)
|
||||
).subscribe(() => {
|
||||
this.cleanupSubscribes();
|
||||
this.search({ query: this.currentSearchQuery });
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,6 +193,23 @@ export class GroupsRegistryComponent implements OnInit {
|
||||
return this.groupService.findAllByHref(group._links.subgroups.href);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if group has a linked object (community or collection linked to a workflow group)
|
||||
* @param group
|
||||
*/
|
||||
hasLinkedDSO(group: Group): Observable<boolean> {
|
||||
return this.dSpaceObjectDataService.findByHref(group._links.object.href).pipe(
|
||||
map((rd: RemoteData<DSpaceObject>) => {
|
||||
if (hasValue(rd) && hasValue(rd.payload)) {
|
||||
return true;
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}),
|
||||
catchError(() => observableOf(false)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all input-fields to be empty and search all search
|
||||
*/
|
||||
@@ -151,4 +228,15 @@ export class GroupsRegistryComponent implements OnInit {
|
||||
getOptionalComColFromName(groupName: string): string {
|
||||
return this.groupService.getUUIDFromString(groupName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsub all subscriptions
|
||||
*/
|
||||
ngOnDestroy(): void {
|
||||
this.cleanupSubscribes();
|
||||
}
|
||||
|
||||
cleanupSubscribes() {
|
||||
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
|
||||
}
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ import { Collection } from '../../../../../core/shared/collection.model';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { getCollectionEditRoute } from '../../../../../+collection-page/collection-page-routing-paths';
|
||||
import { LinkService } from '../../../../../core/cache/builders/link.service';
|
||||
|
||||
describe('CollectionAdminSearchResultGridElementComponent', () => {
|
||||
let component: CollectionAdminSearchResultGridElementComponent;
|
||||
@@ -26,6 +27,11 @@ describe('CollectionAdminSearchResultGridElementComponent', () => {
|
||||
searchResult.indexableObject = new Collection();
|
||||
searchResult.indexableObject.uuid = id;
|
||||
}
|
||||
|
||||
const linkService = jasmine.createSpyObj('linkService', {
|
||||
resolveLink: {}
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
init();
|
||||
TestBed.configureTestingModule({
|
||||
@@ -39,6 +45,7 @@ describe('CollectionAdminSearchResultGridElementComponent', () => {
|
||||
providers: [
|
||||
{ provide: TruncatableService, useValue: mockTruncatableService },
|
||||
{ provide: BitstreamDataService, useValue: {} },
|
||||
{ provide: LinkService, useValue: linkService}
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
|
@@ -14,8 +14,8 @@ import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { CommunityAdminSearchResultGridElementComponent } from './community-admin-search-result-grid-element.component';
|
||||
import { CommunitySearchResult } from '../../../../../shared/object-collection/shared/community-search-result.model';
|
||||
import { Community } from '../../../../../core/shared/community.model';
|
||||
import { CommunityAdminSearchResultListElementComponent } from '../../admin-search-result-list-element/community-search-result/community-admin-search-result-list-element.component';
|
||||
import { getCommunityEditRoute } from '../../../../../+community-page/community-page-routing-paths';
|
||||
import { LinkService } from '../../../../../core/cache/builders/link.service';
|
||||
|
||||
describe('CommunityAdminSearchResultGridElementComponent', () => {
|
||||
let component: CommunityAdminSearchResultGridElementComponent;
|
||||
@@ -29,6 +29,11 @@ describe('CommunityAdminSearchResultGridElementComponent', () => {
|
||||
searchResult.indexableObject = new Community();
|
||||
searchResult.indexableObject.uuid = id;
|
||||
}
|
||||
|
||||
const linkService = jasmine.createSpyObj('linkService', {
|
||||
resolveLink: {}
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
init();
|
||||
TestBed.configureTestingModule({
|
||||
@@ -42,6 +47,7 @@ describe('CommunityAdminSearchResultGridElementComponent', () => {
|
||||
providers: [
|
||||
{ provide: TruncatableService, useValue: mockTruncatableService },
|
||||
{ provide: BitstreamDataService, useValue: {} },
|
||||
{ provide: LinkService, useValue: linkService}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
})
|
||||
|
@@ -6,6 +6,7 @@ import { AuthorizationDataService } from '../core/data/feature-authorization/aut
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { DsoPageFeatureGuard } from '../core/data/feature-authorization/feature-authorization-guard/dso-page-feature.guard';
|
||||
import { FeatureID } from '../core/data/feature-authorization/feature-id';
|
||||
import { AuthService } from '../core/auth/auth.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -16,8 +17,9 @@ import { FeatureID } from '../core/data/feature-authorization/feature-id';
|
||||
export class CollectionPageAdministratorGuard extends DsoPageFeatureGuard<Collection> {
|
||||
constructor(protected resolver: CollectionPageResolver,
|
||||
protected authorizationService: AuthorizationDataService,
|
||||
protected router: Router) {
|
||||
super(resolver, authorizationService, router);
|
||||
protected router: Router,
|
||||
protected authService: AuthService) {
|
||||
super(resolver, authorizationService, router, authService);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -20,6 +20,11 @@ export function getCollectionCreateRoute() {
|
||||
return new URLCombiner(getCollectionModuleRoute(), COLLECTION_CREATE_PATH).toString();
|
||||
}
|
||||
|
||||
export function getCollectionEditRolesRoute(id) {
|
||||
return new URLCombiner(getCollectionPageRoute(id), COLLECTION_EDIT_PATH, COLLECTION_EDIT_ROLES_PATH).toString()
|
||||
}
|
||||
|
||||
export const COLLECTION_CREATE_PATH = 'create';
|
||||
export const COLLECTION_EDIT_PATH = 'edit';
|
||||
export const COLLECTION_EDIT_ROLES_PATH = 'roles';
|
||||
export const ITEMTEMPLATE_PATH = 'itemtemplate';
|
||||
|
@@ -4,7 +4,8 @@
|
||||
<div *ngIf="collectionRD?.hasSucceeded" @fadeInOut>
|
||||
<div *ngIf="collectionRD?.payload as collection">
|
||||
<ds-view-tracker [object]="collection"></ds-view-tracker>
|
||||
<header class="comcol-header border-bottom mb-4 pb-4">
|
||||
<div class="d-flex flex-row border-bottom mb-4 pb-4">
|
||||
<header class="comcol-header mr-auto">
|
||||
<!-- Collection Name -->
|
||||
<ds-comcol-page-header
|
||||
[name]="collection.name">
|
||||
@@ -32,8 +33,11 @@
|
||||
[hasInnerHtml]="true"
|
||||
[title]="'collection.page.news'">
|
||||
</ds-comcol-page-content>
|
||||
|
||||
</header>
|
||||
<div class="pl-2">
|
||||
<ds-dso-page-edit-button [pageRoutePrefix]="'collections'" [dso]="collection" [tooltipMsg]="'collection.page.edit'"></ds-dso-page-edit-button>
|
||||
</div>
|
||||
</div>
|
||||
<section class="comcol-page-browse-section">
|
||||
<!-- Browse-By Links -->
|
||||
<ds-comcol-page-browse-by
|
||||
|
@@ -15,11 +15,16 @@ import { Bitstream } from '../core/shared/bitstream.model';
|
||||
import { Collection } from '../core/shared/collection.model';
|
||||
import { DSpaceObjectType } from '../core/shared/dspace-object-type.model';
|
||||
import { Item } from '../core/shared/item.model';
|
||||
import { getSucceededRemoteData, redirectOn404Or401, toDSpaceObjectListRD } from '../core/shared/operators';
|
||||
import {
|
||||
getSucceededRemoteData,
|
||||
redirectOn4xx,
|
||||
toDSpaceObjectListRD
|
||||
} from '../core/shared/operators';
|
||||
|
||||
import { fadeIn, fadeInOut } from '../shared/animations/fade';
|
||||
import { hasValue, isNotEmpty } from '../shared/empty.util';
|
||||
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
|
||||
import { AuthService } from '../core/auth/auth.service';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-collection-page',
|
||||
@@ -47,7 +52,8 @@ export class CollectionPageComponent implements OnInit {
|
||||
private searchService: SearchService,
|
||||
private metadata: MetadataService,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router
|
||||
private router: Router,
|
||||
private authService: AuthService,
|
||||
) {
|
||||
this.paginationConfig = new PaginationComponentOptions();
|
||||
this.paginationConfig.id = 'collection-page-pagination';
|
||||
@@ -59,7 +65,7 @@ export class CollectionPageComponent implements OnInit {
|
||||
ngOnInit(): void {
|
||||
this.collectionRD$ = this.route.data.pipe(
|
||||
map((data) => data.dso as RemoteData<Collection>),
|
||||
redirectOn404Or401(this.router),
|
||||
redirectOn4xx(this.router, this.authService),
|
||||
take(1)
|
||||
);
|
||||
this.logoRD$ = this.collectionRD$.pipe(
|
||||
|
@@ -12,6 +12,7 @@ import { CommunityDataService } from '../../core/data/community-data.service';
|
||||
import { CreateCollectionPageComponent } from './create-collection-page.component';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
||||
import {RequestService} from '../../core/data/request.service';
|
||||
|
||||
describe('CreateCollectionPageComponent', () => {
|
||||
let comp: CreateCollectionPageComponent;
|
||||
@@ -29,7 +30,8 @@ describe('CreateCollectionPageComponent', () => {
|
||||
},
|
||||
{ provide: RouteService, useValue: { getQueryParameterValue: () => observableOf('1234') } },
|
||||
{ provide: Router, useValue: {} },
|
||||
{ provide: NotificationsService, useValue: new NotificationsServiceStub() }
|
||||
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
|
||||
{ provide: RequestService, useValue: {}}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
|
@@ -7,6 +7,7 @@ import { Collection } from '../../core/shared/collection.model';
|
||||
import { CollectionDataService } from '../../core/data/collection-data.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import {RequestService} from '../../core/data/request.service';
|
||||
|
||||
/**
|
||||
* Component that represents the page where a user can create a new Collection
|
||||
@@ -26,8 +27,9 @@ export class CreateCollectionPageComponent extends CreateComColPageComponent<Col
|
||||
protected routeService: RouteService,
|
||||
protected router: Router,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected translate: TranslateService
|
||||
protected translate: TranslateService,
|
||||
protected requestService: RequestService
|
||||
) {
|
||||
super(collectionDataService, communityDataService, routeService, router, notificationsService, translate);
|
||||
super(collectionDataService, communityDataService, routeService, router, notificationsService, translate, requestService);
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import { of as observableOf } from 'rxjs';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { DeleteCollectionPageComponent } from './delete-collection-page.component';
|
||||
import { CollectionDataService } from '../../core/data/collection-data.service';
|
||||
import {RequestService} from '../../core/data/request.service';
|
||||
|
||||
describe('DeleteCollectionPageComponent', () => {
|
||||
let comp: DeleteCollectionPageComponent;
|
||||
@@ -22,6 +23,7 @@ describe('DeleteCollectionPageComponent', () => {
|
||||
{ provide: CollectionDataService, useValue: {} },
|
||||
{ provide: ActivatedRoute, useValue: { data: observableOf({ dso: { payload: {} } }) } },
|
||||
{ provide: NotificationsService, useValue: {} },
|
||||
{ provide: RequestService, useValue: {} }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
|
@@ -5,6 +5,7 @@ import { NotificationsService } from '../../shared/notifications/notifications.s
|
||||
import { CollectionDataService } from '../../core/data/collection-data.service';
|
||||
import { Collection } from '../../core/shared/collection.model';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import {RequestService} from '../../core/data/request.service';
|
||||
|
||||
/**
|
||||
* Component that represents the page where a user can delete an existing Collection
|
||||
@@ -22,8 +23,9 @@ export class DeleteCollectionPageComponent extends DeleteComColPageComponent<Col
|
||||
protected router: Router,
|
||||
protected route: ActivatedRoute,
|
||||
protected notifications: NotificationsService,
|
||||
protected translate: TranslateService
|
||||
protected translate: TranslateService,
|
||||
protected requestService: RequestService
|
||||
) {
|
||||
super(dsoDataService, router, route, notifications, translate);
|
||||
super(dsoDataService, router, route, notifications, translate, requestService);
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ describe('CollectionCurateComponent', () => {
|
||||
let dsoNameService;
|
||||
|
||||
const collection = Object.assign(new Collection(), {
|
||||
handle: '123456789/1', metadata: {'dc.title': ['Collection Name']}
|
||||
metadata: {'dc.title': ['Collection Name'], 'dc.identifier.uri': [ { value: '123456789/1'}]}
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
|
@@ -6,6 +6,7 @@ import { AuthorizationDataService } from '../core/data/feature-authorization/aut
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { DsoPageFeatureGuard } from '../core/data/feature-authorization/feature-authorization-guard/dso-page-feature.guard';
|
||||
import { FeatureID } from '../core/data/feature-authorization/feature-id';
|
||||
import { AuthService } from '../core/auth/auth.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -16,8 +17,9 @@ import { FeatureID } from '../core/data/feature-authorization/feature-id';
|
||||
export class CommunityPageAdministratorGuard extends DsoPageFeatureGuard<Community> {
|
||||
constructor(protected resolver: CommunityPageResolver,
|
||||
protected authorizationService: AuthorizationDataService,
|
||||
protected router: Router) {
|
||||
super(resolver, authorizationService, router);
|
||||
protected router: Router,
|
||||
protected authService: AuthService) {
|
||||
super(resolver, authorizationService, router, authService);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import { getCollectionPageRoute } from '../+collection-page/collection-page-routing-paths';
|
||||
import { URLCombiner } from '../core/url-combiner/url-combiner';
|
||||
|
||||
export const COMMUNITY_PARENT_PARAMETER = 'parent';
|
||||
@@ -20,5 +21,10 @@ export function getCommunityCreateRoute() {
|
||||
return new URLCombiner(getCommunityModuleRoute(), COMMUNITY_CREATE_PATH).toString();
|
||||
}
|
||||
|
||||
export function getCommunityEditRolesRoute(id) {
|
||||
return new URLCombiner(getCollectionPageRoute(id), COMMUNITY_EDIT_PATH, COMMUNITY_EDIT_ROLES_PATH).toString()
|
||||
}
|
||||
|
||||
export const COMMUNITY_CREATE_PATH = 'create';
|
||||
export const COMMUNITY_EDIT_PATH = 'edit';
|
||||
export const COMMUNITY_EDIT_ROLES_PATH = 'roles';
|
||||
|
@@ -2,7 +2,8 @@
|
||||
<div class="community-page" *ngIf="communityRD?.hasSucceeded" @fadeInOut>
|
||||
<div *ngIf="communityRD?.payload; let communityPayload">
|
||||
<ds-view-tracker [object]="communityPayload"></ds-view-tracker>
|
||||
<header class="comcol-header border-bottom mb-4 pb-4">
|
||||
<div class="d-flex flex-row border-bottom mb-4 pb-4">
|
||||
<header class="comcol-header mr-auto">
|
||||
<!-- Community name -->
|
||||
<ds-comcol-page-header [name]="communityPayload.name"></ds-comcol-page-header>
|
||||
<!-- Community logo -->
|
||||
@@ -18,8 +19,11 @@
|
||||
<ds-comcol-page-content [content]="communityPayload.sidebarText" [hasInnerHtml]="true"
|
||||
[title]="'community.page.news'">
|
||||
</ds-comcol-page-content>
|
||||
|
||||
</header>
|
||||
<div class="pl-2">
|
||||
<ds-dso-page-edit-button [pageRoutePrefix]="'communities'" [dso]="communityPayload" [tooltipMsg]="'community.page.edit'"></ds-dso-page-edit-button>
|
||||
</div>
|
||||
</div>
|
||||
<section class="comcol-page-browse-section">
|
||||
<!-- Browse-By Links -->
|
||||
<ds-comcol-page-browse-by [id]="communityPayload.id" [contentType]="communityPayload.type">
|
||||
|
@@ -13,7 +13,8 @@ import { MetadataService } from '../core/metadata/metadata.service';
|
||||
|
||||
import { fadeInOut } from '../shared/animations/fade';
|
||||
import { hasValue } from '../shared/empty.util';
|
||||
import { redirectOn404Or401 } from '../core/shared/operators';
|
||||
import { redirectOn4xx } from '../core/shared/operators';
|
||||
import { AuthService } from '../core/auth/auth.service';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-community-page',
|
||||
@@ -39,7 +40,8 @@ export class CommunityPageComponent implements OnInit {
|
||||
private communityDataService: CommunityDataService,
|
||||
private metadata: MetadataService,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router
|
||||
private router: Router,
|
||||
private authService: AuthService,
|
||||
) {
|
||||
|
||||
}
|
||||
@@ -47,7 +49,7 @@ export class CommunityPageComponent implements OnInit {
|
||||
ngOnInit(): void {
|
||||
this.communityRD$ = this.route.data.pipe(
|
||||
map((data) => data.dso as RemoteData<Community>),
|
||||
redirectOn404Or401(this.router)
|
||||
redirectOn4xx(this.router, this.authService)
|
||||
);
|
||||
this.logoRD$ = this.communityRD$.pipe(
|
||||
map((rd: RemoteData<Community>) => rd.payload),
|
||||
|
@@ -12,6 +12,7 @@ import { CommunityDataService } from '../../core/data/community-data.service';
|
||||
import { CreateCommunityPageComponent } from './create-community-page.component';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
||||
import {RequestService} from '../../core/data/request.service';
|
||||
|
||||
describe('CreateCommunityPageComponent', () => {
|
||||
let comp: CreateCommunityPageComponent;
|
||||
@@ -25,7 +26,8 @@ describe('CreateCommunityPageComponent', () => {
|
||||
{ provide: CommunityDataService, useValue: { findById: () => observableOf({}) } },
|
||||
{ provide: RouteService, useValue: { getQueryParameterValue: () => observableOf('1234') } },
|
||||
{ provide: Router, useValue: {} },
|
||||
{ provide: NotificationsService, useValue: new NotificationsServiceStub() }
|
||||
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
|
||||
{ provide: RequestService, useValue: {} }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
|
@@ -6,6 +6,7 @@ import { Router } from '@angular/router';
|
||||
import { CreateComColPageComponent } from '../../shared/comcol-forms/create-comcol-page/create-comcol-page.component';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import {RequestService} from '../../core/data/request.service';
|
||||
|
||||
/**
|
||||
* Component that represents the page where a user can create a new Community
|
||||
@@ -24,8 +25,9 @@ export class CreateCommunityPageComponent extends CreateComColPageComponent<Comm
|
||||
protected routeService: RouteService,
|
||||
protected router: Router,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected translate: TranslateService
|
||||
protected translate: TranslateService,
|
||||
protected requestService: RequestService
|
||||
) {
|
||||
super(communityDataService, communityDataService, routeService, router, notificationsService, translate);
|
||||
super(communityDataService, communityDataService, routeService, router, notificationsService, translate, requestService);
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import { CommunityDataService } from '../../core/data/community-data.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { SharedModule } from '../../shared/shared.module';
|
||||
import { DeleteCommunityPageComponent } from './delete-community-page.component';
|
||||
import {RequestService} from '../../core/data/request.service';
|
||||
|
||||
describe('DeleteCommunityPageComponent', () => {
|
||||
let comp: DeleteCommunityPageComponent;
|
||||
@@ -22,6 +23,7 @@ describe('DeleteCommunityPageComponent', () => {
|
||||
{ provide: CommunityDataService, useValue: {} },
|
||||
{ provide: ActivatedRoute, useValue: { data: observableOf({ dso: { payload: {} } }) } },
|
||||
{ provide: NotificationsService, useValue: {} },
|
||||
{ provide: RequestService, useValue: {}}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
|
@@ -5,6 +5,7 @@ import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { DeleteComColPageComponent } from '../../shared/comcol-forms/delete-comcol-page/delete-comcol-page.component';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import {RequestService} from '../../core/data/request.service';
|
||||
|
||||
/**
|
||||
* Component that represents the page where a user can delete an existing Community
|
||||
@@ -22,8 +23,10 @@ export class DeleteCommunityPageComponent extends DeleteComColPageComponent<Comm
|
||||
protected router: Router,
|
||||
protected route: ActivatedRoute,
|
||||
protected notifications: NotificationsService,
|
||||
protected translate: TranslateService
|
||||
protected translate: TranslateService,
|
||||
protected requestService: RequestService
|
||||
) {
|
||||
super(dsoDataService, router, route, notifications, translate);
|
||||
super(dsoDataService, router, route, notifications, translate, requestService);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ describe('CommunityCurateComponent', () => {
|
||||
let dsoNameService;
|
||||
|
||||
const community = Object.assign(new Community(), {
|
||||
handle: '123456789/1', metadata: {'dc.title': ['Community Name']}
|
||||
metadata: {'dc.title': ['Community Name'], 'dc.identifier.uri': [ { value: '123456789/1'}]}
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
|
@@ -47,7 +47,7 @@ export class AbstractItemUpdateComponent extends AbstractTrackableComponent impl
|
||||
ngOnInit(): void {
|
||||
observableCombineLatest(this.route.data, this.route.parent.data).pipe(
|
||||
map(([data, parentData]) => Object.assign({}, data, parentData)),
|
||||
map((data) => data.item),
|
||||
map((data) => data.dso),
|
||||
first(),
|
||||
map((data: RemoteData<Item>) => data.payload)
|
||||
).subscribe((item: Item) => {
|
||||
|
@@ -47,7 +47,7 @@ export class EditItemPageComponent implements OnInit {
|
||||
this.pages = this.route.routeConfig.children
|
||||
.map((child: any) => child.path)
|
||||
.filter((path: string) => isNotEmpty(path)); // ignore reroutes
|
||||
this.itemRD$ = this.route.data.pipe(map((data) => data.item));
|
||||
this.itemRD$ = this.route.data.pipe(map((data) => data.dso));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -74,7 +74,7 @@ describe('ItemAuthorizationsComponent test suite', () => {
|
||||
|
||||
const routeStub = {
|
||||
data: observableOf({
|
||||
item: createSuccessfulRemoteDataObject(item)
|
||||
dso: createSuccessfulRemoteDataObject(item)
|
||||
})
|
||||
};
|
||||
|
||||
|
@@ -75,7 +75,7 @@ export class ItemAuthorizationsComponent implements OnInit, OnDestroy {
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
this.item$ = this.route.data.pipe(
|
||||
map((data) => data.item),
|
||||
map((data) => data.dso),
|
||||
getFirstSucceededRemoteDataWithNotEmptyPayload(),
|
||||
map((item: Item) => this.linkService.resolveLink(
|
||||
item,
|
||||
|
@@ -140,7 +140,7 @@ describe('ItemBitstreamsComponent', () => {
|
||||
});
|
||||
route = Object.assign({
|
||||
parent: {
|
||||
data: observableOf({ item: createMockRD(item) })
|
||||
data: observableOf({ dso: createMockRD(item) })
|
||||
},
|
||||
data: observableOf({}),
|
||||
url: url
|
||||
|
@@ -89,7 +89,7 @@ describe('ItemCollectionMapperComponent', () => {
|
||||
clearDiscoveryRequests: () => {}
|
||||
/* tslint:enable:no-empty */
|
||||
});
|
||||
const activatedRouteStub = new ActivatedRouteStub({}, { item: mockItemRD });
|
||||
const activatedRouteStub = new ActivatedRouteStub({}, { dso: mockItemRD });
|
||||
const translateServiceStub = {
|
||||
get: () => of('test-message of item ' + mockItem.name),
|
||||
onLangChange: new EventEmitter(),
|
||||
|
@@ -91,7 +91,7 @@ export class ItemCollectionMapperComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.itemRD$ = this.route.data.pipe(map((data) => data.item)).pipe(getSucceededRemoteData()) as Observable<RemoteData<Item>>;
|
||||
this.itemRD$ = this.route.data.pipe(map((data) => data.dso)).pipe(getSucceededRemoteData()) as Observable<RemoteData<Item>>;
|
||||
this.searchOptions$ = this.searchConfigService.paginatedSearchOptions;
|
||||
this.loadCollectionLists();
|
||||
}
|
||||
|
@@ -138,7 +138,7 @@ describe('ItemDeleteComponent', () => {
|
||||
|
||||
routeStub = {
|
||||
data: observableOf({
|
||||
item: createSuccessfulRemoteDataObject(mockItem)
|
||||
dso: createSuccessfulRemoteDataObject(mockItem)
|
||||
})
|
||||
};
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
<span>{{metadata?.key?.split('.').join('.​')}}</span>
|
||||
</div>
|
||||
<div *ngIf="(editable | async)" class="field-container">
|
||||
<ds-filter-input-suggestions [suggestions]="(metadataFieldSuggestions | async)"
|
||||
<ds-validation-suggestions [suggestions]="(metadataFieldSuggestions | async)"
|
||||
[(ngModel)]="metadata.key"
|
||||
[url]="this.url"
|
||||
[metadata]="this.metadata"
|
||||
@@ -17,7 +17,7 @@
|
||||
[valid]="(valid | async) !== false"
|
||||
dsAutoFocus autoFocusSelector=".suggestion_input"
|
||||
[ngModelOptions]="{standalone: true}"
|
||||
></ds-filter-input-suggestions>
|
||||
></ds-validation-suggestions>
|
||||
</div>
|
||||
<small class="text-danger"
|
||||
*ngIf="(valid | async) === false">{{"item.edit.metadata.metadatafield.invalid" | translate}}</small>
|
||||
|
@@ -20,9 +20,9 @@ import {
|
||||
} from '../../../../shared/remote-data.utils';
|
||||
import { followLink } from '../../../../shared/utils/follow-link-config.model';
|
||||
import { EditInPlaceFieldComponent } from './edit-in-place-field.component';
|
||||
import { FilterInputSuggestionsComponent } from '../../../../shared/input-suggestions/filter-suggestions/filter-input-suggestions.component';
|
||||
import { MockComponent, MockDirective } from 'ng-mocks';
|
||||
import { DebounceDirective } from '../../../../shared/utils/debounce.directive';
|
||||
import { ValidationSuggestionsComponent } from '../../../../shared/input-suggestions/validation-suggestions/validation-suggestions.component';
|
||||
|
||||
let comp: EditInPlaceFieldComponent;
|
||||
let fixture: ComponentFixture<EditInPlaceFieldComponent>;
|
||||
@@ -88,7 +88,7 @@ describe('EditInPlaceFieldComponent', () => {
|
||||
declarations: [
|
||||
EditInPlaceFieldComponent,
|
||||
MockDirective(DebounceDirective),
|
||||
MockComponent(FilterInputSuggestionsComponent)
|
||||
MockComponent(ValidationSuggestionsComponent)
|
||||
],
|
||||
providers: [
|
||||
{ provide: RegistryService, useValue: metadataFieldService },
|
||||
|
@@ -130,7 +130,7 @@ describe('ItemMetadataComponent', () => {
|
||||
routeStub = {
|
||||
data: observableOf({}),
|
||||
parent: {
|
||||
data: observableOf({ item: createSuccessfulRemoteDataObject(item) })
|
||||
data: observableOf({ dso: createSuccessfulRemoteDataObject(item) })
|
||||
}
|
||||
};
|
||||
paginatedMetadataFields = new PaginatedList(undefined, [mdField1, mdField2, mdField3]);
|
||||
|
@@ -44,7 +44,7 @@ describe('ItemMoveComponent', () => {
|
||||
|
||||
const routeStub = {
|
||||
data: observableOf({
|
||||
item: new RemoteData(false, false, true, null, {
|
||||
dso: new RemoteData(false, false, true, null, {
|
||||
id: 'item1'
|
||||
})
|
||||
})
|
||||
|
@@ -55,7 +55,7 @@ export class ItemMoveComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.itemRD$ = this.route.data.pipe(map((data) => data.item), getSucceededRemoteData()) as Observable<RemoteData<Item>>;
|
||||
this.itemRD$ = this.route.data.pipe(map((data) => data.dso), getSucceededRemoteData()) as Observable<RemoteData<Item>>;
|
||||
this.itemRD$.subscribe((rd) => {
|
||||
this.itemId = rd.payload.id;
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import { AuthorizationDataService } from '../../core/data/feature-authorization/
|
||||
import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
|
||||
import { AuthService } from '../../core/auth/auth.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -16,8 +17,9 @@ import { FeatureID } from '../../core/data/feature-authorization/feature-id';
|
||||
export class ItemPageReinstateGuard extends DsoPageFeatureGuard<Item> {
|
||||
constructor(protected resolver: ItemPageResolver,
|
||||
protected authorizationService: AuthorizationDataService,
|
||||
protected router: Router) {
|
||||
super(resolver, authorizationService, router);
|
||||
protected router: Router,
|
||||
protected authService: AuthService) {
|
||||
super(resolver, authorizationService, router, authService);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -6,6 +6,7 @@ import { AuthorizationDataService } from '../../core/data/feature-authorization/
|
||||
import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
|
||||
import { AuthService } from '../../core/auth/auth.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -16,8 +17,9 @@ import { FeatureID } from '../../core/data/feature-authorization/feature-id';
|
||||
export class ItemPageWithdrawGuard extends DsoPageFeatureGuard<Item> {
|
||||
constructor(protected resolver: ItemPageResolver,
|
||||
protected authorizationService: AuthorizationDataService,
|
||||
protected router: Router) {
|
||||
super(resolver, authorizationService, router);
|
||||
protected router: Router,
|
||||
protected authService: AuthService) {
|
||||
super(resolver, authorizationService, router, authService);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -51,7 +51,7 @@ describe('ItemPrivateComponent', () => {
|
||||
|
||||
routeStub = {
|
||||
data: observableOf({
|
||||
item: createSuccessfulRemoteDataObject({
|
||||
dso: createSuccessfulRemoteDataObject({
|
||||
id: 'fake-id'
|
||||
})
|
||||
})
|
||||
|
@@ -51,7 +51,7 @@ describe('ItemPublicComponent', () => {
|
||||
|
||||
routeStub = {
|
||||
data: observableOf({
|
||||
item: createSuccessfulRemoteDataObject({
|
||||
dso: createSuccessfulRemoteDataObject({
|
||||
id: 'fake-id'
|
||||
})
|
||||
})
|
||||
|
@@ -51,7 +51,7 @@ describe('ItemReinstateComponent', () => {
|
||||
|
||||
routeStub = {
|
||||
data: observableOf({
|
||||
item: createSuccessfulRemoteDataObject({
|
||||
dso: createSuccessfulRemoteDataObject({
|
||||
id: 'fake-id'
|
||||
})
|
||||
})
|
||||
|
@@ -1,15 +1,26 @@
|
||||
<h5>{{getRelationshipMessageKey() | async | translate}}</h5>
|
||||
<h5>
|
||||
{{getRelationshipMessageKey() | async | translate}}
|
||||
<button class="ml-2 btn btn-success" (click)="openLookup()">
|
||||
<i class="fas fa-plus"></i>
|
||||
<span class="d-none d-sm-inline"> {{"item.edit.relationships.edit.buttons.add" | translate}}</span>
|
||||
</button>
|
||||
</h5>
|
||||
<ng-container *ngVar="updates$ | async as updates">
|
||||
<ng-container *ngIf="updates">
|
||||
<ng-container *ngVar="updates | dsObjectValues as updateValues">
|
||||
<ds-edit-relationship *ngFor="let updateValue of updateValues; trackBy: trackUpdate"
|
||||
class="relationship-row d-block"
|
||||
[fieldUpdate]="updateValue"
|
||||
class="relationship-row d-block alert"
|
||||
[fieldUpdate]="updateValue || {}"
|
||||
[url]="url"
|
||||
[editItem]="item"
|
||||
[ngClass]="{'alert alert-danger': updateValue?.changeType === 2}">
|
||||
[ngClass]="{
|
||||
'alert-success': updateValue.changeType === 1,
|
||||
'alert-warning': updateValue.changeType === 0,
|
||||
'alert-danger': updateValue.changeType === 2
|
||||
}">
|
||||
</ds-edit-relationship>
|
||||
<div *ngIf="updateValues.length === 0">{{"item.edit.relationships.no-relationships" | translate}}</div>
|
||||
</ng-container>
|
||||
</ng-container>
|
||||
<div *ngIf="!updates">no relationships</div>
|
||||
<ds-loading *ngIf="!updates"></ds-loading>
|
||||
</ng-container>
|
||||
|
@@ -1,8 +1,8 @@
|
||||
.relationship-row:not(.alert-danger) {
|
||||
.relationship-row:not(.alert) {
|
||||
padding: $alert-padding-y 0;
|
||||
}
|
||||
|
||||
.relationship-row.alert-danger {
|
||||
.relationship-row.alert {
|
||||
margin-left: -$alert-padding-x;
|
||||
margin-right: -$alert-padding-x;
|
||||
margin-top: -1px;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
@@ -8,6 +8,7 @@ import { FieldChangeType } from '../../../../core/data/object-updates/object-upd
|
||||
import { ObjectUpdatesService } from '../../../../core/data/object-updates/object-updates.service';
|
||||
import { PaginatedList } from '../../../../core/data/paginated-list';
|
||||
import { RelationshipTypeService } from '../../../../core/data/relationship-type.service';
|
||||
import { RelationshipService } from '../../../../core/data/relationship.service';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { ItemType } from '../../../../core/shared/item-relationships/item-type.model';
|
||||
import { RelationshipType } from '../../../../core/shared/item-relationships/relationship-type.model';
|
||||
@@ -15,6 +16,7 @@ import { Relationship } from '../../../../core/shared/item-relationships/relatio
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { PageInfo } from '../../../../core/shared/page-info.model';
|
||||
import { getMockLinkService } from '../../../../shared/mocks/link-service.mock';
|
||||
import { SelectableListService } from '../../../../shared/object-list/selectable-list/selectable-list.service';
|
||||
import { SharedModule } from '../../../../shared/shared.module';
|
||||
import { EditRelationshipListComponent } from './edit-relationship-list.component';
|
||||
|
||||
@@ -22,72 +24,123 @@ let comp: EditRelationshipListComponent;
|
||||
let fixture: ComponentFixture<EditRelationshipListComponent>;
|
||||
let de: DebugElement;
|
||||
|
||||
let linkService;
|
||||
let objectUpdatesService;
|
||||
let entityTypeService;
|
||||
let relationshipService;
|
||||
let selectableListService;
|
||||
|
||||
const url = 'http://test-url.com/test-url';
|
||||
|
||||
let item;
|
||||
let entityType;
|
||||
let relatedEntityType;
|
||||
let author1;
|
||||
let author2;
|
||||
let fieldUpdate1;
|
||||
let fieldUpdate2;
|
||||
let relationship1;
|
||||
let relationship2;
|
||||
let relationships;
|
||||
let relationshipType;
|
||||
let entityType;
|
||||
let relatedEntityType;
|
||||
|
||||
describe('EditRelationshipListComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async(() => {
|
||||
|
||||
entityType = Object.assign(new ItemType(), {
|
||||
id: 'entityType',
|
||||
id: 'Publication',
|
||||
uuid: 'Publication',
|
||||
label: 'Publication',
|
||||
});
|
||||
|
||||
relatedEntityType = Object.assign(new ItemType(), {
|
||||
id: 'relatedEntityType',
|
||||
id: 'Author',
|
||||
uuid: 'Author',
|
||||
label: 'Author',
|
||||
});
|
||||
|
||||
relationshipType = Object.assign(new RelationshipType(), {
|
||||
id: '1',
|
||||
uuid: '1',
|
||||
leftType: observableOf(new RemoteData(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
undefined,
|
||||
entityType,
|
||||
)),
|
||||
rightType: observableOf(new RemoteData(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
undefined,
|
||||
relatedEntityType,
|
||||
)),
|
||||
leftwardType: 'isAuthorOfPublication',
|
||||
rightwardType: 'isPublicationOfAuthor',
|
||||
leftType: observableOf(new RemoteData(false, false, true, undefined, entityType)),
|
||||
rightType: observableOf(new RemoteData(false, false, true, undefined, relatedEntityType)),
|
||||
});
|
||||
|
||||
relationship1 = Object.assign(new Relationship(), {
|
||||
_links: {
|
||||
self: {
|
||||
href: url + '/2'
|
||||
}
|
||||
},
|
||||
author1 = Object.assign(new Item(), {
|
||||
id: 'author1',
|
||||
uuid: 'author1'
|
||||
});
|
||||
author2 = Object.assign(new Item(), {
|
||||
id: 'author2',
|
||||
uuid: 'author2'
|
||||
});
|
||||
|
||||
relationships = [
|
||||
Object.assign(new Relationship(), {
|
||||
self: url + '/2',
|
||||
id: '2',
|
||||
uuid: '2',
|
||||
leftId: 'author1',
|
||||
rightId: 'publication',
|
||||
leftItem: observableOf(new RemoteData(false, false, true, undefined, item)),
|
||||
rightItem: observableOf(new RemoteData(false, false, true, undefined, author1)),
|
||||
relationshipType: observableOf(new RemoteData(false, false, true, undefined, relationshipType))
|
||||
});
|
||||
|
||||
relationship2 = Object.assign(new Relationship(), {
|
||||
_links: {
|
||||
self: {
|
||||
href: url + '/3'
|
||||
}
|
||||
},
|
||||
relationshipType: observableOf(new RemoteData(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
undefined,
|
||||
relationshipType
|
||||
)),
|
||||
leftItem: observableOf(new RemoteData(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
undefined,
|
||||
item,
|
||||
)),
|
||||
rightItem: observableOf(new RemoteData(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
undefined,
|
||||
author1,
|
||||
)),
|
||||
}),
|
||||
Object.assign(new Relationship(), {
|
||||
self: url + '/3',
|
||||
id: '3',
|
||||
uuid: '3',
|
||||
leftId: 'author2',
|
||||
rightId: 'publication',
|
||||
leftItem: observableOf(new RemoteData(false, false, true, undefined, item)),
|
||||
rightItem: observableOf(new RemoteData(false, false, true, undefined, author2)),
|
||||
relationshipType: observableOf(new RemoteData(false, false, true, undefined, relationshipType))
|
||||
});
|
||||
relationshipType: observableOf(new RemoteData(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
undefined,
|
||||
relationshipType
|
||||
)),
|
||||
leftItem: observableOf(new RemoteData(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
undefined,
|
||||
item,
|
||||
)),
|
||||
rightItem: observableOf(new RemoteData(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
undefined,
|
||||
author2,
|
||||
)),
|
||||
})
|
||||
];
|
||||
|
||||
item = Object.assign(new Item(), {
|
||||
_links: {
|
||||
@@ -100,84 +153,82 @@ describe('EditRelationshipListComponent', () => {
|
||||
false,
|
||||
true,
|
||||
undefined,
|
||||
new PaginatedList(new PageInfo(), [relationship1, relationship2])
|
||||
new PaginatedList(new PageInfo(), relationships),
|
||||
))
|
||||
});
|
||||
|
||||
author1 = Object.assign(new Item(), {
|
||||
id: 'author1',
|
||||
uuid: 'author1'
|
||||
});
|
||||
author2 = Object.assign(new Item(), {
|
||||
id: 'author2',
|
||||
uuid: 'author2'
|
||||
});
|
||||
|
||||
fieldUpdate1 = {
|
||||
field: author1,
|
||||
field: {
|
||||
uuid: relationships[0].uuid,
|
||||
relationship: relationships[0],
|
||||
type: relationshipType,
|
||||
},
|
||||
changeType: undefined
|
||||
};
|
||||
fieldUpdate2 = {
|
||||
field: author2,
|
||||
field: {
|
||||
uuid: relationships[1].uuid,
|
||||
relationship: relationships[1],
|
||||
type: relationshipType,
|
||||
},
|
||||
changeType: FieldChangeType.REMOVE
|
||||
};
|
||||
|
||||
objectUpdatesService = jasmine.createSpyObj('objectUpdatesService',
|
||||
{
|
||||
getFieldUpdates: observableOf({
|
||||
[author1.uuid]: fieldUpdate1,
|
||||
[author2.uuid]: fieldUpdate2
|
||||
[relationships[0].uuid]: fieldUpdate1,
|
||||
[relationships[1].uuid]: fieldUpdate2
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
entityTypeService = jasmine.createSpyObj('entityTypeService',
|
||||
relationshipService = jasmine.createSpyObj('relationshipService',
|
||||
{
|
||||
getEntityTypeByLabel: observableOf(new RemoteData(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
null,
|
||||
entityType,
|
||||
)),
|
||||
getEntityTypeRelationships: observableOf(new RemoteData(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
null,
|
||||
new PaginatedList(new PageInfo(), [relationshipType]),
|
||||
)),
|
||||
getRelatedItemsByLabel: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), [author1, author2]))),
|
||||
getItemRelationshipsByLabel: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), relationships))),
|
||||
isLeftItem: observableOf(true),
|
||||
}
|
||||
);
|
||||
|
||||
selectableListService = {};
|
||||
|
||||
linkService = {
|
||||
resolveLink: () => null,
|
||||
resolveLinks: () => null,
|
||||
};
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [SharedModule, TranslateModule.forRoot()],
|
||||
declarations: [EditRelationshipListComponent],
|
||||
providers: [
|
||||
{ provide: ObjectUpdatesService, useValue: objectUpdatesService },
|
||||
{ provide: RelationshipTypeService, useValue: {} },
|
||||
{ provide: LinkService, useValue: getMockLinkService() },
|
||||
{ provide: RelationshipService, useValue: relationshipService },
|
||||
{ provide: SelectableListService, useValue: selectableListService },
|
||||
{ provide: LinkService, useValue: linkService },
|
||||
], schemas: [
|
||||
NO_ERRORS_SCHEMA
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(EditRelationshipListComponent);
|
||||
comp = fixture.componentInstance;
|
||||
de = fixture.debugElement;
|
||||
|
||||
comp.item = item;
|
||||
comp.itemType = entityType;
|
||||
comp.url = url;
|
||||
comp.relationshipType = relationshipType;
|
||||
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
describe('changeType is REMOVE', () => {
|
||||
it('the div should have class alert-danger', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
fieldUpdate1.changeType = FieldChangeType.REMOVE;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
it('the div should have class alert-danger', () => {
|
||||
const element = de.queryAll(By.css('.relationship-row'))[1].nativeElement;
|
||||
expect(element.classList).toContain('alert-danger');
|
||||
});
|
||||
|
@@ -1,8 +1,11 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { LinkService } from '../../../../core/cache/builders/link.service';
|
||||
import { FieldChangeType } from '../../../../core/data/object-updates/object-updates.actions';
|
||||
import { ObjectUpdatesService } from '../../../../core/data/object-updates/object-updates.service';
|
||||
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
|
||||
import { FieldUpdate, FieldUpdates } from '../../../../core/data/object-updates/object-updates.reducer';
|
||||
import { FieldUpdate, FieldUpdates, RelationshipIdentifiable } from '../../../../core/data/object-updates/object-updates.reducer';
|
||||
import { RelationshipService } from '../../../../core/data/relationship.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { hasValue } from '../../../../shared/empty.util';
|
||||
@@ -14,6 +17,11 @@ import {
|
||||
getSucceededRemoteData
|
||||
} from '../../../../core/shared/operators';
|
||||
import { ItemType } from '../../../../core/shared/item-relationships/item-type.model';
|
||||
import { DsDynamicLookupRelationModalComponent } from '../../../../shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component';
|
||||
import { RelationshipOptions } from '../../../../shared/form/builder/models/relationship-options.model';
|
||||
import { ItemSearchResult } from '../../../../shared/object-collection/shared/item-search-result.model';
|
||||
import { SelectableListService } from '../../../../shared/object-list/selectable-list/selectable-list.service';
|
||||
import { SearchResult } from '../../../../shared/search/search-result.model';
|
||||
import { followLink } from '../../../../shared/utils/follow-link-config.model';
|
||||
|
||||
@Component({
|
||||
@@ -45,14 +53,29 @@ export class EditRelationshipListComponent implements OnInit {
|
||||
*/
|
||||
@Input() relationshipType: RelationshipType;
|
||||
|
||||
private relatedEntityType$: Observable<ItemType>;
|
||||
|
||||
/**
|
||||
* The list ID to save selected entities under
|
||||
*/
|
||||
listId: string;
|
||||
|
||||
/**
|
||||
* The FieldUpdates for the relationships in question
|
||||
*/
|
||||
updates$: Observable<FieldUpdates>;
|
||||
|
||||
/**
|
||||
* A reference to the lookup window
|
||||
*/
|
||||
modalRef: NgbModalRef;
|
||||
|
||||
constructor(
|
||||
protected objectUpdatesService: ObjectUpdatesService,
|
||||
protected linkService: LinkService
|
||||
protected linkService: LinkService,
|
||||
protected relationshipService: RelationshipService,
|
||||
protected modalService: NgbModal,
|
||||
protected selectableListService: SelectableListService,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -61,10 +84,18 @@ export class EditRelationshipListComponent implements OnInit {
|
||||
*/
|
||||
public getRelationshipMessageKey(): Observable<string> {
|
||||
|
||||
return this.getLabel().pipe(
|
||||
map((label) => {
|
||||
if (hasValue(label) && label.indexOf('Of') > -1) {
|
||||
return `relationships.${label.substring(0, label.indexOf('Of') + 2)}`;
|
||||
return observableCombineLatest(
|
||||
this.getLabel(),
|
||||
this.relatedEntityType$,
|
||||
).pipe(
|
||||
map(([label, relatedEntityType]) => {
|
||||
if (hasValue(label) && label.indexOf('is') > -1 && label.indexOf('Of') > -1) {
|
||||
const relationshipLabel = `${label.substring(2, label.indexOf('Of'))}`;
|
||||
if (relationshipLabel !== relatedEntityType.label) {
|
||||
return `relationships.is${relationshipLabel}Of.${relatedEntityType.label}`
|
||||
} else {
|
||||
return `relationships.is${relationshipLabel}Of`
|
||||
}
|
||||
} else {
|
||||
return label;
|
||||
}
|
||||
@@ -76,7 +107,6 @@ export class EditRelationshipListComponent implements OnInit {
|
||||
* Get the relevant label for this relationship type
|
||||
*/
|
||||
private getLabel(): Observable<string> {
|
||||
|
||||
return observableCombineLatest([
|
||||
this.relationshipType.leftType,
|
||||
this.relationshipType.rightType,
|
||||
@@ -98,19 +128,197 @@ export class EditRelationshipListComponent implements OnInit {
|
||||
return update && update.field ? update.field.uuid : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the dynamic lookup modal to search for items to add as relationships
|
||||
*/
|
||||
openLookup() {
|
||||
|
||||
this.modalRef = this.modalService.open(DsDynamicLookupRelationModalComponent, {
|
||||
size: 'lg'
|
||||
});
|
||||
const modalComp: DsDynamicLookupRelationModalComponent = this.modalRef.componentInstance;
|
||||
modalComp.repeatable = true;
|
||||
modalComp.listId = this.listId;
|
||||
modalComp.item = this.item;
|
||||
modalComp.select = (...selectableObjects: Array<SearchResult<Item>>) => {
|
||||
selectableObjects.forEach((searchResult) => {
|
||||
const relatedItem: Item = searchResult.indexableObject;
|
||||
this.getFieldUpdatesForRelatedItem(relatedItem)
|
||||
.subscribe((identifiables) => {
|
||||
identifiables.forEach((identifiable) =>
|
||||
this.objectUpdatesService.removeSingleFieldUpdate(this.url, identifiable.uuid)
|
||||
);
|
||||
if (identifiables.length === 0) {
|
||||
this.relationshipService.getNameVariant(this.listId, relatedItem.uuid)
|
||||
.subscribe((nameVariant) => {
|
||||
const update = {
|
||||
uuid: this.relationshipType.id + '-' + relatedItem.uuid,
|
||||
nameVariant,
|
||||
type: this.relationshipType,
|
||||
relatedItem,
|
||||
} as RelationshipIdentifiable;
|
||||
this.objectUpdatesService.saveAddFieldUpdate(this.url, update);
|
||||
})
|
||||
}
|
||||
});
|
||||
})
|
||||
};
|
||||
modalComp.deselect = (...selectableObjects: Array<SearchResult<Item>>) => {
|
||||
selectableObjects.forEach((searchResult) => {
|
||||
const relatedItem: Item = searchResult.indexableObject;
|
||||
this.objectUpdatesService.removeSingleFieldUpdate(this.url, this.relationshipType.id + '-' + relatedItem.uuid);
|
||||
this.getFieldUpdatesForRelatedItem(relatedItem)
|
||||
.subscribe((identifiables) =>
|
||||
identifiables.forEach((identifiable) =>
|
||||
this.objectUpdatesService.saveRemoveFieldUpdate(this.url, identifiable)
|
||||
)
|
||||
);
|
||||
})
|
||||
};
|
||||
this.relatedEntityType$
|
||||
.pipe(take(1))
|
||||
.subscribe((relatedEntityType) => {
|
||||
modalComp.relationshipOptions = Object.assign(
|
||||
new RelationshipOptions(), {
|
||||
relationshipType: relatedEntityType.label,
|
||||
// filter: this.getRelationshipMessageKey(),
|
||||
searchConfiguration: relatedEntityType.label.toLowerCase(),
|
||||
nameVariants: true,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
this.selectableListService.deselectAll(this.listId);
|
||||
this.updates$.pipe(
|
||||
switchMap((updates) =>
|
||||
Object.values(updates).length > 0 ?
|
||||
observableCombineLatest(
|
||||
Object.values(updates)
|
||||
.filter((update) => update.changeType !== FieldChangeType.REMOVE)
|
||||
.map((update) => {
|
||||
const field = update.field as RelationshipIdentifiable;
|
||||
if (field.relationship) {
|
||||
return this.getRelatedItem(field.relationship);
|
||||
} else {
|
||||
return of(field.relatedItem);
|
||||
}
|
||||
})
|
||||
) : of([])
|
||||
),
|
||||
take(1),
|
||||
map((items) => items.map((item) => {
|
||||
const searchResult = new ItemSearchResult();
|
||||
searchResult.indexableObject = item;
|
||||
searchResult.hitHighlights = {};
|
||||
return searchResult;
|
||||
})),
|
||||
).subscribe((items) => {
|
||||
this.selectableListService.select(this.listId, items);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the existing field updates regarding a relationship with a given item
|
||||
* @param relatedItem The item for which to get the existing field updates
|
||||
*/
|
||||
private getFieldUpdatesForRelatedItem(relatedItem: Item): Observable<RelationshipIdentifiable[]> {
|
||||
|
||||
return this.updates$.pipe(
|
||||
take(1),
|
||||
map((updates) => Object.values(updates)
|
||||
.map((update) => update.field as RelationshipIdentifiable)
|
||||
.filter((field) => field.relationship)
|
||||
),
|
||||
flatMap((identifiables) =>
|
||||
observableCombineLatest(
|
||||
identifiables.map((identifiable) => this.getRelatedItem(identifiable.relationship))
|
||||
).pipe(
|
||||
defaultIfEmpty([]),
|
||||
map((relatedItems) =>
|
||||
identifiables.filter((identifiable, index) => relatedItems[index].uuid === relatedItem.uuid)
|
||||
),
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the related item for a given relationship
|
||||
* @param relationship The relationship for which to get the related item
|
||||
*/
|
||||
private getRelatedItem(relationship: Relationship): Observable<Item> {
|
||||
return this.relationshipService.isLeftItem(relationship, this.item).pipe(
|
||||
switchMap((isLeftItem) => isLeftItem ? relationship.rightItem : relationship.leftItem),
|
||||
getSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
)
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.updates$ = this.item.relationships.pipe(
|
||||
|
||||
this.relatedEntityType$ =
|
||||
observableCombineLatest([
|
||||
this.relationshipType.leftType,
|
||||
this.relationshipType.rightType,
|
||||
].map((type) => type.pipe(
|
||||
getSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
))).pipe(
|
||||
map((relatedTypes) => relatedTypes.find((relatedType) => relatedType.uuid !== this.itemType.uuid)),
|
||||
);
|
||||
|
||||
this.relatedEntityType$.pipe(
|
||||
take(1)
|
||||
).subscribe(
|
||||
(relatedEntityType) => this.listId = `edit-relationship-${this.itemType.id}-${relatedEntityType.id}`
|
||||
);
|
||||
|
||||
this.updates$ = this.getItemRelationships().pipe(
|
||||
switchMap((relationships) =>
|
||||
observableCombineLatest(
|
||||
relationships.map((relationship) => this.relationshipService.isLeftItem(relationship, this.item))
|
||||
).pipe(
|
||||
defaultIfEmpty([]),
|
||||
map((isLeftItemArray) => isLeftItemArray.map((isLeftItem, index) => {
|
||||
const relationship = relationships[index];
|
||||
const nameVariant = isLeftItem ? relationship.rightwardValue : relationship.leftwardValue;
|
||||
return {
|
||||
uuid: relationship.id,
|
||||
type: this.relationshipType,
|
||||
relationship,
|
||||
nameVariant,
|
||||
} as RelationshipIdentifiable
|
||||
})),
|
||||
)),
|
||||
switchMap((initialFields) => this.objectUpdatesService.getFieldUpdates(this.url, initialFields).pipe(
|
||||
map((fieldUpdates) => {
|
||||
const fieldUpdatesFiltered: FieldUpdates = {};
|
||||
Object.keys(fieldUpdates).forEach((uuid) => {
|
||||
const field = fieldUpdates[uuid].field;
|
||||
if ((field as RelationshipIdentifiable).type.id === this.relationshipType.id) {
|
||||
fieldUpdatesFiltered[uuid] = fieldUpdates[uuid];
|
||||
}
|
||||
});
|
||||
return fieldUpdatesFiltered;
|
||||
}),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
private getItemRelationships() {
|
||||
this.linkService.resolveLink(this.item, followLink('relationships'));
|
||||
return this.item.relationships.pipe(
|
||||
getAllSucceededRemoteData(),
|
||||
map((relationships) => relationships.payload.page.filter((relationship) => relationship)),
|
||||
map((relationships: Relationship[]) =>
|
||||
relationships.map((relationship: Relationship) => {
|
||||
filter((relationships) => relationships.every((relationship) => !!relationship)),
|
||||
tap((relationships: Relationship[]) =>
|
||||
relationships.forEach((relationship: Relationship) => {
|
||||
this.linkService.resolveLinks(
|
||||
relationship,
|
||||
followLink('relationshipType'),
|
||||
followLink('leftItem'),
|
||||
followLink('rightItem'),
|
||||
);
|
||||
return relationship;
|
||||
})
|
||||
),
|
||||
switchMap((itemRelationships: Relationship[]) =>
|
||||
@@ -121,15 +329,12 @@ export class EditRelationshipListComponent implements OnInit {
|
||||
getRemoteDataPayload(),
|
||||
))
|
||||
).pipe(
|
||||
defaultIfEmpty([]),
|
||||
map((relationshipTypes) => itemRelationships.filter(
|
||||
(relationship, index) => relationshipTypes[index].id === this.relationshipType.id)
|
||||
),
|
||||
map((relationships) => relationships.map((relationship) =>
|
||||
Object.assign(new Relationship(), relationship, {uuid: relationship.id})
|
||||
)),
|
||||
)
|
||||
),
|
||||
switchMap((initialFields) => this.objectUpdatesService.getFieldUpdates(this.url, initialFields)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,11 @@
|
||||
<div class="row" *ngIf="relatedItem$ | async">
|
||||
<div class="col-10 relationship">
|
||||
<ds-listable-object-component-loader [object]="relatedItem$ | async" [viewMode]="viewMode"></ds-listable-object-component-loader>
|
||||
<ds-listable-object-component-loader
|
||||
[object]="relatedItem$ | async"
|
||||
[viewMode]="viewMode"
|
||||
[value]="nameVariant"
|
||||
>
|
||||
</ds-listable-object-component-loader>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<div class="btn-group relationship-action-buttons">
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { FieldChangeType } from '../../../../core/data/object-updates/object-updates.actions';
|
||||
@@ -25,7 +25,7 @@ let fieldUpdate2;
|
||||
let relationships;
|
||||
let relationshipType;
|
||||
|
||||
let fixture;
|
||||
let fixture: ComponentFixture<EditRelationshipComponent>;
|
||||
let comp: EditRelationshipComponent;
|
||||
let de;
|
||||
let el;
|
||||
@@ -91,11 +91,17 @@ describe('EditRelationshipComponent', () => {
|
||||
});
|
||||
|
||||
fieldUpdate1 = {
|
||||
field: relationships[0],
|
||||
field: {
|
||||
uuid: relationships[0].uuid,
|
||||
relationship: relationships[0],
|
||||
},
|
||||
changeType: undefined
|
||||
};
|
||||
fieldUpdate2 = {
|
||||
field: relationships[1],
|
||||
field: {
|
||||
uuid: relationships[1].uuid,
|
||||
relationship: relationships[1],
|
||||
},
|
||||
changeType: FieldChangeType.REMOVE
|
||||
};
|
||||
|
||||
|
@@ -1,10 +1,13 @@
|
||||
import { Component, Input, OnChanges, OnInit } from '@angular/core';
|
||||
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
|
||||
import { combineLatest as observableCombineLatest, Observable, of } from 'rxjs';
|
||||
import { filter, map, switchMap, take, tap } from 'rxjs/operators';
|
||||
import { FieldChangeType } from '../../../../core/data/object-updates/object-updates.actions';
|
||||
import { DeleteRelationship, FieldUpdate } from '../../../../core/data/object-updates/object-updates.reducer';
|
||||
import {
|
||||
DeleteRelationship,
|
||||
FieldUpdate,
|
||||
RelationshipIdentifiable
|
||||
} from '../../../../core/data/object-updates/object-updates.reducer';
|
||||
import { ObjectUpdatesService } from '../../../../core/data/object-updates/object-updates.service';
|
||||
import { Relationship } from '../../../../core/shared/item-relationships/relationship.model';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { getRemoteDataPayload, getSucceededRemoteData } from '../../../../core/shared/operators';
|
||||
import { ViewMode } from '../../../../core/shared/view-mode.model';
|
||||
@@ -36,8 +39,16 @@ export class EditRelationshipComponent implements OnChanges {
|
||||
/**
|
||||
* The relationship being edited
|
||||
*/
|
||||
get relationship(): Relationship {
|
||||
return this.fieldUpdate.field as Relationship;
|
||||
get relationship() {
|
||||
return this.update.relationship;
|
||||
}
|
||||
|
||||
get update() {
|
||||
return this.fieldUpdate.field as RelationshipIdentifiable;
|
||||
}
|
||||
|
||||
get nameVariant() {
|
||||
return this.update.nameVariant;
|
||||
}
|
||||
|
||||
public leftItem$: Observable<Item>;
|
||||
@@ -68,6 +79,7 @@ export class EditRelationshipComponent implements OnChanges {
|
||||
* Sets the current relationship based on the fieldUpdate input field
|
||||
*/
|
||||
ngOnChanges(): void {
|
||||
if (this.relationship) {
|
||||
this.leftItem$ = this.relationship.leftItem.pipe(
|
||||
getSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
@@ -86,6 +98,9 @@ export class EditRelationshipComponent implements OnChanges {
|
||||
items.find((item) => item.uuid !== this.editItem.uuid)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
this.relatedItem$ = of(this.update.relatedItem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,7 +151,8 @@ export class EditRelationshipComponent implements OnChanges {
|
||||
* Check if a user should be allowed to remove this field
|
||||
*/
|
||||
canRemove(): boolean {
|
||||
return this.fieldUpdate.changeType !== FieldChangeType.REMOVE;
|
||||
return this.fieldUpdate.changeType !== FieldChangeType.REMOVE
|
||||
&& this.fieldUpdate.changeType !== FieldChangeType.ADD;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -19,14 +19,19 @@
|
||||
<span class="d-none d-sm-inline"> {{"item.edit.metadata.save-button" | translate}}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div *ngFor="let relationshipType of relationshipTypes$ | async" class="mb-4">
|
||||
<ng-container *ngVar="relationshipTypes$ | async as relationshipTypes">
|
||||
<ng-container *ngIf="relationshipTypes">
|
||||
<div *ngFor="let relationshipType of relationshipTypes" class="mb-4">
|
||||
<ds-edit-relationship-list
|
||||
[url]="url"
|
||||
[item]="item"
|
||||
[itemType]="entityType"
|
||||
[itemType]="entityType$ | async"
|
||||
[relationshipType]="relationshipType"
|
||||
></ds-edit-relationship-list>
|
||||
</div>
|
||||
</ng-container>
|
||||
<ds-loading *ngIf="!relationshipTypes"></ds-loading>
|
||||
</ng-container>
|
||||
<div class="button-row bottom">
|
||||
<div class="float-right">
|
||||
<button class="btn btn-danger" *ngIf="!(isReinstatable() | async)"
|
||||
|
@@ -142,7 +142,7 @@ describe('ItemRelationshipsComponent', () => {
|
||||
routeStub = {
|
||||
data: observableOf({}),
|
||||
parent: {
|
||||
data: observableOf({ item: new RemoteData(false, false, true, null, item) })
|
||||
data: observableOf({ dso: new RemoteData(false, false, true, null, item) })
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -3,10 +3,12 @@ import { Item } from '../../../core/shared/item.model';
|
||||
import {
|
||||
DeleteRelationship,
|
||||
FieldUpdate,
|
||||
FieldUpdates
|
||||
FieldUpdates,
|
||||
RelationshipIdentifiable,
|
||||
} from '../../../core/data/object-updates/object-updates.reducer';
|
||||
import { Observable, of as observableOf, Subscription, zip as observableZip } from 'rxjs';
|
||||
import { filter, map, switchMap, take } from 'rxjs/operators';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { filter, map, startWith, switchMap, take} from 'rxjs/operators';
|
||||
import { combineLatest as observableCombineLatest, of as observableOf, zip as observableZip} from 'rxjs';
|
||||
import { followLink } from '../../../shared/utils/follow-link-config.model';
|
||||
import { AbstractItemUpdateComponent } from '../abstract-item-update/abstract-item-update.component';
|
||||
import { ItemDataService } from '../../../core/data/item-data.service';
|
||||
@@ -23,7 +25,6 @@ import { RequestService } from '../../../core/data/request.service';
|
||||
import { RelationshipType } from '../../../core/shared/item-relationships/relationship-type.model';
|
||||
import { ItemType } from '../../../core/shared/item-relationships/item-type.model';
|
||||
import { EntityTypeService } from '../../../core/data/entity-type.service';
|
||||
import { isNotEmptyOperator } from '../../../shared/empty.util';
|
||||
import { FieldChangeType } from '../../../core/data/object-updates/object-updates.actions';
|
||||
import { Relationship } from '../../../core/shared/item-relationships/relationship.model';
|
||||
|
||||
@@ -35,18 +36,18 @@ import { Relationship } from '../../../core/shared/item-relationships/relationsh
|
||||
/**
|
||||
* Component for displaying an item's relationships edit page
|
||||
*/
|
||||
export class ItemRelationshipsComponent extends AbstractItemUpdateComponent implements OnDestroy {
|
||||
export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
||||
|
||||
itemRD$: Observable<RemoteData<Item>>;
|
||||
|
||||
/**
|
||||
* The labels of all different relations within this item
|
||||
* The allowed relationship types for this type of item as an observable list
|
||||
*/
|
||||
relationshipTypes$: Observable<RelationshipType[]>;
|
||||
|
||||
/**
|
||||
* A subscription that checks when the item is deleted in cache and reloads the item by sending a new request
|
||||
* This is used to update the item in cache after relationships are deleted
|
||||
* The item's entity type as an observable
|
||||
*/
|
||||
itemUpdateSubscription: Subscription;
|
||||
entityType$: Observable<ItemType>;
|
||||
|
||||
constructor(
|
||||
@@ -70,15 +71,29 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent impl
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
this.itemUpdateSubscription = this.requestService.hasByHrefObservable(this.item.self).pipe(
|
||||
this.initializeItemUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the item (and view) when it's removed in the request cache
|
||||
*/
|
||||
public initializeItemUpdate(): void {
|
||||
this.itemRD$ = this.requestService.hasByHrefObservable(this.item.self).pipe(
|
||||
filter((exists: boolean) => !exists),
|
||||
switchMap(() => this.itemService.findById(this.item.uuid,
|
||||
switchMap(() => this.itemService.findById(
|
||||
this.item.uuid,
|
||||
followLink('owningCollection'),
|
||||
followLink('bundles'),
|
||||
followLink('relationships'))),
|
||||
followLink('relationships')),
|
||||
),
|
||||
filter((itemRD) => !!itemRD.statusCode),
|
||||
);
|
||||
|
||||
this.itemRD$.pipe(
|
||||
getSucceededRemoteData(),
|
||||
).subscribe((itemRD: RemoteData<Item>) => {
|
||||
this.item = itemRD.payload;
|
||||
getRemoteDataPayload(),
|
||||
).subscribe((item) => {
|
||||
this.item = item;
|
||||
this.cdr.detectChanges();
|
||||
this.initializeUpdates();
|
||||
});
|
||||
@@ -127,8 +142,10 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent impl
|
||||
* Make sure the lists are refreshed afterwards and notifications are sent for success and errors
|
||||
*/
|
||||
public submit(): void {
|
||||
|
||||
// Get all the relationships that should be removed
|
||||
this.relationshipService.getItemRelationshipsArray(this.item).pipe(
|
||||
const removedRelationshipIDs$: Observable<DeleteRelationship[]> = this.relationshipService.getItemRelationshipsArray(this.item).pipe(
|
||||
startWith([]),
|
||||
map((relationships: Relationship[]) => relationships.map((relationship) =>
|
||||
Object.assign(new Relationship(), relationship, { uuid: relationship.id })
|
||||
)),
|
||||
@@ -140,10 +157,42 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent impl
|
||||
.filter((fieldUpdate: FieldUpdate) => fieldUpdate.changeType === FieldChangeType.REMOVE)
|
||||
.map((fieldUpdate: FieldUpdate) => fieldUpdate.field as DeleteRelationship)
|
||||
),
|
||||
isNotEmptyOperator(),
|
||||
);
|
||||
|
||||
const addRelatedItems$: Observable<RelationshipIdentifiable[]> = this.objectUpdatesService.getFieldUpdates(this.url, []).pipe(
|
||||
map((fieldUpdates: FieldUpdates) =>
|
||||
Object.values(fieldUpdates)
|
||||
.filter((fieldUpdate: FieldUpdate) => fieldUpdate.changeType === FieldChangeType.ADD)
|
||||
.map((fieldUpdate: FieldUpdate) => fieldUpdate.field as RelationshipIdentifiable)
|
||||
),
|
||||
);
|
||||
|
||||
observableCombineLatest(
|
||||
removedRelationshipIDs$,
|
||||
addRelatedItems$,
|
||||
).pipe(
|
||||
take(1),
|
||||
switchMap((deleteRelationships: DeleteRelationship[]) =>
|
||||
observableZip(...deleteRelationships.map((deleteRelationship) => {
|
||||
).subscribe(([removeRelationshipIDs, addRelatedItems]) => {
|
||||
const actions = [
|
||||
this.deleteRelationships(removeRelationshipIDs),
|
||||
this.addRelationships(addRelatedItems),
|
||||
];
|
||||
actions.forEach((action) =>
|
||||
action.subscribe((response) => {
|
||||
if (response.length > 0) {
|
||||
this.itemRD$.subscribe(() => {
|
||||
this.initializeOriginalFields();
|
||||
this.cdr.detectChanges();
|
||||
this.displayNotifications(response);
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
deleteRelationships(deleteRelationshipIDs: DeleteRelationship[]): Observable<RestResponse[]> {
|
||||
return observableZip(...deleteRelationshipIDs.map((deleteRelationship) => {
|
||||
let copyVirtualMetadata: string;
|
||||
if (deleteRelationship.keepLeftVirtualMetadata && deleteRelationship.keepRightVirtualMetadata) {
|
||||
copyVirtualMetadata = 'all';
|
||||
@@ -156,13 +205,33 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent impl
|
||||
}
|
||||
return this.relationshipService.deleteRelationship(deleteRelationship.uuid, copyVirtualMetadata);
|
||||
}
|
||||
))
|
||||
),
|
||||
).subscribe((responses: RestResponse[]) => {
|
||||
this.itemUpdateSubscription.add(() => {
|
||||
this.displayNotifications(responses);
|
||||
});
|
||||
});
|
||||
));
|
||||
}
|
||||
|
||||
addRelationships(addRelatedItems: RelationshipIdentifiable[]): Observable<RestResponse[]> {
|
||||
return observableZip(...addRelatedItems.map((addRelationship) =>
|
||||
this.entityType$.pipe(
|
||||
switchMap((entityType) => this.entityTypeService.isLeftType(addRelationship.type, entityType)),
|
||||
switchMap((isLeftType) => {
|
||||
let leftItem: Item;
|
||||
let rightItem: Item;
|
||||
let leftwardValue: string;
|
||||
let rightwardValue: string;
|
||||
if (isLeftType) {
|
||||
leftItem = this.item;
|
||||
rightItem = addRelationship.relatedItem;
|
||||
leftwardValue = null;
|
||||
rightwardValue = addRelationship.nameVariant;
|
||||
} else {
|
||||
leftItem = addRelationship.relatedItem;
|
||||
rightItem = this.item;
|
||||
leftwardValue = addRelationship.nameVariant;
|
||||
rightwardValue = null;
|
||||
}
|
||||
return this.relationshipService.addRelationship(addRelationship.type.id, leftItem, rightItem, leftwardValue, rightwardValue);
|
||||
}),
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,19 +251,14 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent impl
|
||||
this.notificationsService.success(this.getNotificationTitle('saved'), this.getNotificationContent('saved'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends all initial values of this item to the object updates service
|
||||
*/
|
||||
public initializeOriginalFields() {
|
||||
const initialFields = [];
|
||||
this.objectUpdatesService.initialize(this.url, initialFields, this.item.lastModified);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe from the item update when the component is destroyed
|
||||
*/
|
||||
ngOnDestroy(): void {
|
||||
this.itemUpdateSubscription.unsubscribe();
|
||||
return this.relationshipService.getRelatedItems(this.item).pipe(
|
||||
take(1),
|
||||
).subscribe((items: Item[]) => {
|
||||
this.objectUpdatesService.initialize(this.url, items, this.item.lastModified);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ describe('ItemStatusComponent', () => {
|
||||
|
||||
const routeStub = {
|
||||
parent: {
|
||||
data: observableOf({ item: createSuccessfulRemoteDataObject(mockItem) })
|
||||
data: observableOf({ dso: createSuccessfulRemoteDataObject(mockItem) })
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -55,7 +55,7 @@ export class ItemStatusComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.itemRD$ = this.route.parent.data.pipe(map((data) => data.item));
|
||||
this.itemRD$ = this.route.parent.data.pipe(map((data) => data.dso));
|
||||
this.itemRD$.pipe(
|
||||
first(),
|
||||
map((data: RemoteData<Item>) => data.payload)
|
||||
|
@@ -23,7 +23,7 @@ describe('ItemVersionHistoryComponent', () => {
|
||||
declarations: [ItemVersionHistoryComponent, VarDirective],
|
||||
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
|
||||
providers: [
|
||||
{ provide: ActivatedRoute, useValue: { parent: { data: observableOf({ item: createSuccessfulRemoteDataObject(item) }) } } }
|
||||
{ provide: ActivatedRoute, useValue: { parent: { data: observableOf({ dso: createSuccessfulRemoteDataObject(item) }) } } }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
|
@@ -30,6 +30,6 @@ export class ItemVersionHistoryComponent {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.itemRD$ = this.route.parent.data.pipe(map((data) => data.item)).pipe(getSucceededRemoteData()) as Observable<RemoteData<Item>>;
|
||||
this.itemRD$ = this.route.parent.data.pipe(map((data) => data.dso)).pipe(getSucceededRemoteData()) as Observable<RemoteData<Item>>;
|
||||
}
|
||||
}
|
||||
|
@@ -51,7 +51,7 @@ describe('ItemWithdrawComponent', () => {
|
||||
|
||||
routeStub = {
|
||||
data: observableOf({
|
||||
item: createSuccessfulRemoteDataObject({
|
||||
dso: createSuccessfulRemoteDataObject({
|
||||
id: 'fake-id'
|
||||
})
|
||||
})
|
||||
|
@@ -74,7 +74,7 @@ describe('AbstractSimpleItemActionComponent', () => {
|
||||
|
||||
routeStub = {
|
||||
data: observableOf({
|
||||
item: createSuccessfulRemoteDataObject({
|
||||
dso: createSuccessfulRemoteDataObject({
|
||||
id: 'fake-id'
|
||||
})
|
||||
})
|
||||
|
@@ -42,7 +42,7 @@ export class AbstractSimpleItemActionComponent implements OnInit {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.itemRD$ = this.route.data.pipe(
|
||||
map((data) => data.item),
|
||||
map((data) => data.dso),
|
||||
getSucceededRemoteData()
|
||||
)as Observable<RemoteData<Item>>;
|
||||
|
||||
|
@@ -3,7 +3,12 @@
|
||||
<div *ngIf="itemRD?.payload as item">
|
||||
<ds-item-versions-notice [item]="item"></ds-item-versions-notice>
|
||||
<ds-view-tracker [object]="item"></ds-view-tracker>
|
||||
<ds-item-page-title-field [item]="item"></ds-item-page-title-field>
|
||||
<div class="d-flex flex-row">
|
||||
<ds-item-page-title-field class="mr-auto" [item]="item"></ds-item-page-title-field>
|
||||
<div class="pl-2">
|
||||
<ds-dso-page-edit-button [pageRoutePrefix]="'items'" [dso]="item" [tooltipMsg]="'item.page.edit'"></ds-dso-page-edit-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="simple-view-link my-3">
|
||||
<a class="btn btn-outline-primary" [routerLink]="['/items/' + item.id]">
|
||||
{{"item.page.link.simple" | translate}}
|
||||
|
@@ -13,7 +13,6 @@ import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { Item } from '../../core/shared/item.model';
|
||||
import { PageInfo } from '../../core/shared/page-info.model';
|
||||
import { PaginatedList } from '../../core/data/paginated-list';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { By } from '@angular/platform-browser';
|
||||
@@ -21,6 +20,7 @@ import {
|
||||
createSuccessfulRemoteDataObject,
|
||||
createSuccessfulRemoteDataObject$
|
||||
} from '../../shared/remote-data.utils';
|
||||
import { AuthService } from '../../core/auth/auth.service';
|
||||
|
||||
const mockItem: Item = Object.assign(new Item(), {
|
||||
bundles: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
@@ -34,7 +34,7 @@ const mockItem: Item = Object.assign(new Item(), {
|
||||
}
|
||||
});
|
||||
const routeStub = Object.assign(new ActivatedRouteStub(), {
|
||||
data: observableOf({ item: createSuccessfulRemoteDataObject(mockItem) })
|
||||
data: observableOf({ dso: createSuccessfulRemoteDataObject(mockItem) })
|
||||
});
|
||||
const metadataServiceStub = {
|
||||
/* tslint:disable:no-empty */
|
||||
@@ -46,7 +46,14 @@ describe('FullItemPageComponent', () => {
|
||||
let comp: FullItemPageComponent;
|
||||
let fixture: ComponentFixture<FullItemPageComponent>;
|
||||
|
||||
let authService: AuthService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
authService = jasmine.createSpyObj('authService', {
|
||||
isAuthenticated: observableOf(true),
|
||||
setRedirectUrl: {}
|
||||
});
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot({
|
||||
loader: {
|
||||
@@ -58,7 +65,8 @@ describe('FullItemPageComponent', () => {
|
||||
providers: [
|
||||
{provide: ActivatedRoute, useValue: routeStub},
|
||||
{provide: ItemDataService, useValue: {}},
|
||||
{provide: MetadataService, useValue: metadataServiceStub}
|
||||
{provide: MetadataService, useValue: metadataServiceStub},
|
||||
{ provide: AuthService, useValue: authService },
|
||||
],
|
||||
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
|
@@ -15,6 +15,7 @@ import { MetadataService } from '../../core/metadata/metadata.service';
|
||||
|
||||
import { fadeInOut } from '../../shared/animations/fade';
|
||||
import { hasValue } from '../../shared/empty.util';
|
||||
import { AuthService } from '../../core/auth/auth.service';
|
||||
|
||||
/**
|
||||
* This component renders a simple item page.
|
||||
@@ -35,8 +36,8 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit {
|
||||
|
||||
metadata$: Observable<MetadataMap>;
|
||||
|
||||
constructor(route: ActivatedRoute, router: Router, items: ItemDataService, metadataService: MetadataService) {
|
||||
super(route, router, items, metadataService);
|
||||
constructor(route: ActivatedRoute, router: Router, items: ItemDataService, metadataService: MetadataService, authService: AuthService) {
|
||||
super(route, router, items, metadataService, authService);
|
||||
}
|
||||
|
||||
/*** AoT inheritance fix, will hopefully be resolved in the near future **/
|
||||
|
@@ -6,6 +6,8 @@ import { Item } from '../core/shared/item.model';
|
||||
import { DsoPageFeatureGuard } from '../core/data/feature-authorization/feature-authorization-guard/dso-page-feature.guard';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { FeatureID } from '../core/data/feature-authorization/feature-id';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { AuthService } from '../core/auth/auth.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -16,8 +18,9 @@ import { FeatureID } from '../core/data/feature-authorization/feature-id';
|
||||
export class ItemPageAdministratorGuard extends DsoPageFeatureGuard<Item> {
|
||||
constructor(protected resolver: ItemPageResolver,
|
||||
protected authorizationService: AuthorizationDataService,
|
||||
protected router: Router) {
|
||||
super(resolver, authorizationService, router);
|
||||
protected router: Router,
|
||||
protected authService: AuthService) {
|
||||
super(resolver, authorizationService, router, authService);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -20,7 +20,7 @@ import { LinkMenuItemModel } from '../shared/menu/menu-item/models/link.model';
|
||||
{
|
||||
path: ':id',
|
||||
resolve: {
|
||||
item: ItemPageResolver,
|
||||
dso: ItemPageResolver,
|
||||
breadcrumb: ItemBreadcrumbResolver
|
||||
},
|
||||
runGuardsAndResolvers: 'always',
|
||||
|
@@ -8,7 +8,6 @@ import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
|
||||
import { MetadataService } from '../../core/metadata/metadata.service';
|
||||
import { VarDirective } from '../../shared/utils/var.directive';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { Item } from '../../core/shared/item.model';
|
||||
import { PaginatedList } from '../../core/data/paginated-list';
|
||||
import { PageInfo } from '../../core/shared/page-info.model';
|
||||
@@ -20,6 +19,7 @@ import {
|
||||
createFailedRemoteDataObject$, createPendingRemoteDataObject$, createSuccessfulRemoteDataObject,
|
||||
createSuccessfulRemoteDataObject$
|
||||
} from '../../shared/remote-data.utils';
|
||||
import { AuthService } from '../../core/auth/auth.service';
|
||||
|
||||
const mockItem: Item = Object.assign(new Item(), {
|
||||
bundles: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
@@ -30,6 +30,7 @@ const mockItem: Item = Object.assign(new Item(), {
|
||||
describe('ItemPageComponent', () => {
|
||||
let comp: ItemPageComponent;
|
||||
let fixture: ComponentFixture<ItemPageComponent>;
|
||||
let authService: AuthService;
|
||||
|
||||
const mockMetadataService = {
|
||||
/* tslint:disable:no-empty */
|
||||
@@ -37,10 +38,15 @@ describe('ItemPageComponent', () => {
|
||||
/* tslint:enable:no-empty */
|
||||
};
|
||||
const mockRoute = Object.assign(new ActivatedRouteStub(), {
|
||||
data: observableOf({ item: createSuccessfulRemoteDataObject(mockItem) })
|
||||
data: observableOf({ dso: createSuccessfulRemoteDataObject(mockItem) })
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
authService = jasmine.createSpyObj('authService', {
|
||||
isAuthenticated: observableOf(true),
|
||||
setRedirectUrl: {}
|
||||
});
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot({
|
||||
loader: {
|
||||
@@ -53,7 +59,8 @@ describe('ItemPageComponent', () => {
|
||||
{provide: ActivatedRoute, useValue: mockRoute},
|
||||
{provide: ItemDataService, useValue: {}},
|
||||
{provide: MetadataService, useValue: mockMetadataService},
|
||||
{provide: Router, useValue: {}}
|
||||
{provide: Router, useValue: {}},
|
||||
{ provide: AuthService, useValue: authService },
|
||||
],
|
||||
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
|
@@ -11,8 +11,9 @@ import { Item } from '../../core/shared/item.model';
|
||||
import { MetadataService } from '../../core/metadata/metadata.service';
|
||||
|
||||
import { fadeInOut } from '../../shared/animations/fade';
|
||||
import { redirectOn404Or401 } from '../../core/shared/operators';
|
||||
import { redirectOn4xx } from '../../core/shared/operators';
|
||||
import { ViewMode } from '../../core/shared/view-mode.model';
|
||||
import { AuthService } from '../../core/auth/auth.service';
|
||||
|
||||
/**
|
||||
* This component renders a simple item page.
|
||||
@@ -48,6 +49,7 @@ export class ItemPageComponent implements OnInit {
|
||||
private router: Router,
|
||||
private items: ItemDataService,
|
||||
private metadataService: MetadataService,
|
||||
private authService: AuthService,
|
||||
) { }
|
||||
|
||||
/**
|
||||
@@ -55,8 +57,8 @@ export class ItemPageComponent implements OnInit {
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
this.itemRD$ = this.route.data.pipe(
|
||||
map((data) => data.item as RemoteData<Item>),
|
||||
redirectOn404Or401(this.router)
|
||||
map((data) => data.dso as RemoteData<Item>),
|
||||
redirectOn4xx(this.router, this.authService)
|
||||
);
|
||||
this.metadataService.processRemoteData(this.itemRD$);
|
||||
}
|
||||
|
@@ -1,6 +1,11 @@
|
||||
<h2 class="item-page-title-field">
|
||||
<div class="d-flex flex-row">
|
||||
<h2 class="item-page-title-field mr-auto">
|
||||
{{'publication.page.titleprefix' | translate}}<ds-metadata-values [mdValues]="object?.allMetadata(['dc.title'])"></ds-metadata-values>
|
||||
</h2>
|
||||
<div class="pl-2">
|
||||
<ds-dso-page-edit-button [pageRoutePrefix]="'items'" [dso]="object" [tooltipMsg]="'publication.page.edit'"></ds-dso-page-edit-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-md-4">
|
||||
<ds-metadata-field-wrapper>
|
||||
|
@@ -55,10 +55,10 @@ export function getDSORoute(dso: DSpaceObject): string {
|
||||
}
|
||||
}
|
||||
|
||||
export const UNAUTHORIZED_PATH = '401';
|
||||
export const FORBIDDEN_PATH = '403';
|
||||
|
||||
export function getUnauthorizedRoute() {
|
||||
return `/${UNAUTHORIZED_PATH}`;
|
||||
export function getForbiddenRoute() {
|
||||
return `/${FORBIDDEN_PATH}`;
|
||||
}
|
||||
|
||||
export const PAGE_NOT_FOUND_PATH = '404';
|
||||
|
@@ -5,15 +5,14 @@ import { AuthBlockingGuard } from './core/auth/auth-blocking.guard';
|
||||
import { PageNotFoundComponent } from './pagenotfound/pagenotfound.component';
|
||||
import { AuthenticatedGuard } from './core/auth/authenticated.guard';
|
||||
import { SiteAdministratorGuard } from './core/data/feature-authorization/feature-authorization-guard/site-administrator.guard';
|
||||
import { UnauthorizedComponent } from './unauthorized/unauthorized.component';
|
||||
import {
|
||||
ADMIN_MODULE_PATH,
|
||||
BITSTREAM_MODULE_PATH,
|
||||
FORBIDDEN_PATH
|
||||
FORGOT_PASSWORD_PATH,
|
||||
INFO_MODULE_PATH,
|
||||
PROFILE_MODULE_PATH,
|
||||
REGISTER_PATH,
|
||||
UNAUTHORIZED_PATH,
|
||||
WORKFLOW_ITEM_MODULE_PATH
|
||||
} from './app-routing-paths';
|
||||
import { COLLECTION_MODULE_PATH } from './+collection-page/collection-page-routing-paths';
|
||||
@@ -22,6 +21,7 @@ import { ITEM_MODULE_PATH } from './+item-page/item-page-routing-paths';
|
||||
import { ReloadGuard } from './core/reload/reload.guard';
|
||||
import { EndUserAgreementCurrentUserGuard } from './core/end-user-agreement/end-user-agreement-current-user.guard';
|
||||
import { SiteRegisterGuard } from './core/data/feature-authorization/feature-authorization-guard/site-register.guard';
|
||||
import { ForbiddenComponent } from './forbidden/forbidden.component';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -166,8 +166,8 @@ import { SiteRegisterGuard } from './core/data/feature-authorization/feature-aut
|
||||
loadChildren: () => import('./info/info.module').then((m) => m.InfoModule),
|
||||
},
|
||||
{
|
||||
path: UNAUTHORIZED_PATH,
|
||||
component: UnauthorizedComponent
|
||||
path: FORBIDDEN_PATH,
|
||||
component: ForbiddenComponent
|
||||
},
|
||||
{
|
||||
path: 'statistics',
|
||||
|
@@ -41,7 +41,7 @@ import { SharedModule } from './shared/shared.module';
|
||||
import { BreadcrumbsComponent } from './breadcrumbs/breadcrumbs.component';
|
||||
import { environment } from '../environments/environment';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { UnauthorizedComponent } from './unauthorized/unauthorized.component';
|
||||
import { ForbiddenComponent } from './forbidden/forbidden.component';
|
||||
|
||||
export function getBase() {
|
||||
return environment.ui.nameSpace;
|
||||
@@ -116,6 +116,8 @@ const DECLARATIONS = [
|
||||
NotificationComponent,
|
||||
NotificationsBoardComponent,
|
||||
SearchNavbarComponent,
|
||||
BreadcrumbsComponent,
|
||||
ForbiddenComponent,
|
||||
];
|
||||
|
||||
const EXPORTS = [
|
||||
@@ -133,8 +135,6 @@ const EXPORTS = [
|
||||
],
|
||||
declarations: [
|
||||
...DECLARATIONS,
|
||||
BreadcrumbsComponent,
|
||||
UnauthorizedComponent,
|
||||
],
|
||||
exports: [
|
||||
...EXPORTS
|
||||
|
@@ -2,7 +2,7 @@
|
||||
<nav *ngIf="showBreadcrumbs" aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<ng-container
|
||||
*ngTemplateOutlet="breadcrumbs?.length > 0 ? breadcrumb : activeBreadcrumb; context: {text: 'Home', url: '/'}"></ng-container>
|
||||
*ngTemplateOutlet="breadcrumbs?.length > 0 ? breadcrumb : activeBreadcrumb; context: {text: 'home.breadcrumbs', url: '/'}"></ng-container>
|
||||
<ng-container *ngFor="let bc of breadcrumbs; let last = last;">
|
||||
<ng-container *ngTemplateOutlet="!last ? breadcrumb : activeBreadcrumb; context: bc"></ng-container>
|
||||
</ng-container>
|
||||
|
@@ -1,9 +1,10 @@
|
||||
import { NgZone } from '@angular/core';
|
||||
import { Subscription } from 'rxjs/internal/Subscription';
|
||||
import { FindListOptions } from '../core/data/request.models';
|
||||
import { hasValue } from '../shared/empty.util';
|
||||
import { CommunityListService, FlatNode } from './community-list-service';
|
||||
import { CollectionViewer, DataSource } from '@angular/cdk/collections';
|
||||
import { BehaviorSubject, Observable, } from 'rxjs';
|
||||
import { finalize, take, } from 'rxjs/operators';
|
||||
import { finalize } from 'rxjs/operators';
|
||||
|
||||
/**
|
||||
* DataSource object needed by a CDK Tree to render its nodes.
|
||||
@@ -15,9 +16,9 @@ export class CommunityListDatasource implements DataSource<FlatNode> {
|
||||
|
||||
private communityList$ = new BehaviorSubject<FlatNode[]>([]);
|
||||
public loading$ = new BehaviorSubject<boolean>(false);
|
||||
private subLoadCommunities: Subscription;
|
||||
|
||||
constructor(private communityListService: CommunityListService,
|
||||
private zone: NgZone) {
|
||||
constructor(private communityListService: CommunityListService) {
|
||||
}
|
||||
|
||||
connect(collectionViewer: CollectionViewer): Observable<FlatNode[]> {
|
||||
@@ -26,13 +27,13 @@ export class CommunityListDatasource implements DataSource<FlatNode> {
|
||||
|
||||
loadCommunities(findOptions: FindListOptions, expandedNodes: FlatNode[]) {
|
||||
this.loading$.next(true);
|
||||
this.zone.runOutsideAngular(() => {
|
||||
this.communityListService.loadCommunities(findOptions, expandedNodes).pipe(
|
||||
take(1),
|
||||
finalize(() => this.zone.run(() => this.loading$.next(false))),
|
||||
if (hasValue(this.subLoadCommunities)) {
|
||||
this.subLoadCommunities.unsubscribe();
|
||||
}
|
||||
this.subLoadCommunities = this.communityListService.loadCommunities(findOptions, expandedNodes).pipe(
|
||||
finalize(() => this.loading$.next(false)),
|
||||
).subscribe((flatNodes: FlatNode[]) => {
|
||||
this.zone.run(() => this.communityList$.next(flatNodes));
|
||||
});
|
||||
this.communityList$.next(flatNodes);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { createSelector, Store } from '@ngrx/store';
|
||||
import { combineLatest as observableCombineLatest, Observable, of as observableOf } from 'rxjs';
|
||||
import { combineLatest as observableCombineLatest } from 'rxjs/internal/observable/combineLatest';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { AppState } from '../app.reducer';
|
||||
import { CommunityDataService } from '../core/data/community-data.service';
|
||||
import { FindListOptions } from '../core/data/request.models';
|
||||
import { map, mergeMap } from 'rxjs/operators';
|
||||
import { Community } from '../core/shared/community.model';
|
||||
import { Collection } from '../core/shared/collection.model';
|
||||
import { getSucceededRemoteData } from '../core/shared/operators';
|
||||
import { PageInfo } from '../core/shared/page-info.model';
|
||||
import { hasValue, isNotEmpty } from '../shared/empty.util';
|
||||
import { RemoteData } from '../core/data/remote-data';
|
||||
@@ -148,8 +148,8 @@ export class CommunityListService {
|
||||
return new PaginatedList(newPageInfo, newPage);
|
||||
})
|
||||
);
|
||||
return topComs$.pipe(mergeMap((topComs: PaginatedList<Community>) => this.transformListOfCommunities(topComs, 0, null, expandedNodes)));
|
||||
}
|
||||
return topComs$.pipe(switchMap((topComs: PaginatedList<Community>) => this.transformListOfCommunities(topComs, 0, null, expandedNodes)));
|
||||
};
|
||||
|
||||
/**
|
||||
* Puts the initial top level communities in a list to be called upon
|
||||
@@ -228,9 +228,13 @@ export class CommunityListService {
|
||||
currentPage: i
|
||||
})
|
||||
.pipe(
|
||||
getSucceededRemoteData(),
|
||||
mergeMap((rd: RemoteData<PaginatedList<Community>>) =>
|
||||
this.transformListOfCommunities(rd.payload, level + 1, communityFlatNode, expandedNodes))
|
||||
switchMap((rd: RemoteData<PaginatedList<Community>>) => {
|
||||
if (hasValue(rd) && hasValue(rd.payload)) {
|
||||
return this.transformListOfCommunities(rd.payload, level + 1, communityFlatNode, expandedNodes);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
subcoms = [...subcoms, nextSetOfSubcommunitiesPage];
|
||||
@@ -246,14 +250,17 @@ export class CommunityListService {
|
||||
currentPage: i
|
||||
})
|
||||
.pipe(
|
||||
getSucceededRemoteData(),
|
||||
map((rd: RemoteData<PaginatedList<Collection>>) => {
|
||||
if (hasValue(rd) && hasValue(rd.payload)) {
|
||||
let nodes = rd.payload.page
|
||||
.map((collection: Collection) => toFlatNode(collection, observableOf(false), level + 1, false, communityFlatNode));
|
||||
if (currentCollectionPage < rd.payload.totalPages && currentCollectionPage === rd.payload.currentPage) {
|
||||
nodes = [...nodes, showMoreFlatNode('collection', level + 1, communityFlatNode)];
|
||||
}
|
||||
return nodes;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}),
|
||||
);
|
||||
collections = [...collections, nextSetOfCollectionsPage];
|
||||
@@ -275,14 +282,24 @@ export class CommunityListService {
|
||||
let hasColls$: Observable<boolean>;
|
||||
hasSubcoms$ = this.communityDataService.findByParent(community.uuid, { elementsPerPage: 1 })
|
||||
.pipe(
|
||||
getSucceededRemoteData(),
|
||||
map((results) => results.payload.totalElements > 0),
|
||||
map((rd: RemoteData<PaginatedList<Community>>) => {
|
||||
if (hasValue(rd) && hasValue(rd.payload)) {
|
||||
return rd.payload.totalElements > 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
hasColls$ = this.collectionDataService.findByParent(community.uuid, { elementsPerPage: 1 })
|
||||
.pipe(
|
||||
getSucceededRemoteData(),
|
||||
map((results) => results.payload.totalElements > 0),
|
||||
map((rd: RemoteData<PaginatedList<Collection>>) => {
|
||||
if (hasValue(rd) && hasValue(rd.payload)) {
|
||||
return rd.payload.totalElements > 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
let hasChildren$: Observable<boolean>;
|
||||
|
@@ -28,7 +28,7 @@
|
||||
<button type="button" class="btn btn-default" cdkTreeNodeToggle
|
||||
[attr.aria-label]="'toggle ' + node.name"
|
||||
(click)="toggleExpanded(node)"
|
||||
[ngClass]="(node.isExpandable$ | async) ? 'visible' : 'invisible'">
|
||||
[ngClass]="(hasChild(null, node)| async) ? 'visible' : 'invisible'">
|
||||
<span class="{{node.isExpanded ? 'fa fa-chevron-down' : 'fa fa-chevron-right'}}"
|
||||
aria-hidden="true"></span>
|
||||
</button>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { Component, NgZone, OnDestroy, OnInit } from '@angular/core';
|
||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { take } from 'rxjs/operators';
|
||||
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
|
||||
import { FindListOptions } from '../../core/data/request.models';
|
||||
@@ -24,15 +24,14 @@ export class CommunityListComponent implements OnInit, OnDestroy {
|
||||
public loadingNode: FlatNode;
|
||||
|
||||
treeControl = new FlatTreeControl<FlatNode>(
|
||||
(node) => node.level, (node) => true
|
||||
(node: FlatNode) => node.level, (node: FlatNode) => true
|
||||
);
|
||||
|
||||
dataSource: CommunityListDatasource;
|
||||
|
||||
paginationConfig: FindListOptions;
|
||||
|
||||
constructor(private communityListService: CommunityListService,
|
||||
private zone: NgZone) {
|
||||
constructor(private communityListService: CommunityListService) {
|
||||
this.paginationConfig = new FindListOptions();
|
||||
this.paginationConfig.elementsPerPage = 2;
|
||||
this.paginationConfig.currentPage = 1;
|
||||
@@ -40,7 +39,7 @@ export class CommunityListComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.dataSource = new CommunityListDatasource(this.communityListService, this.zone);
|
||||
this.dataSource = new CommunityListDatasource(this.communityListService);
|
||||
this.communityListService.getLoadingNodeFromStore().pipe(take(1)).subscribe((result) => {
|
||||
this.loadingNode = result;
|
||||
});
|
||||
@@ -65,7 +64,7 @@ export class CommunityListComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the expanded variable of a node, adds it to the exapanded nodes list and reloads the tree so this node is expanded
|
||||
* Toggles the expanded variable of a node, adds it to the expanded nodes list and reloads the tree so this node is expanded
|
||||
* @param node Node we want to expand
|
||||
*/
|
||||
toggleExpanded(node: FlatNode) {
|
||||
|
@@ -453,7 +453,7 @@ export class AuthService {
|
||||
* Clear redirect url
|
||||
*/
|
||||
clearRedirectUrl() {
|
||||
this.store.dispatch(new SetRedirectUrlAction(''));
|
||||
this.store.dispatch(new SetRedirectUrlAction(undefined));
|
||||
this.storage.remove(REDIRECT_COOKIE);
|
||||
}
|
||||
|
||||
|
@@ -6,7 +6,6 @@ import { HALLink } from '../../shared/hal-link.model';
|
||||
import { HALResource } from '../../shared/hal-resource.model';
|
||||
import { ResourceType } from '../../shared/resource-type';
|
||||
import * as decorators from './build-decorators';
|
||||
import { getDataServiceFor } from './build-decorators';
|
||||
import { LinkService } from './link.service';
|
||||
|
||||
const spyOnFunction = <T>(obj: T, func: keyof T) => {
|
||||
|
@@ -17,6 +17,7 @@ import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
||||
import { FindByIDRequest, FindListOptions } from './request.models';
|
||||
import { RequestEntry } from './request.reducer';
|
||||
import { RequestService } from './request.service';
|
||||
import {createNoContentRemoteDataObject$, createSuccessfulRemoteDataObject$} from '../../shared/remote-data.utils';
|
||||
|
||||
const LINK_NAME = 'test';
|
||||
|
||||
@@ -51,7 +52,9 @@ describe('ComColDataService', () => {
|
||||
let objectCache: ObjectCacheService;
|
||||
let halService: any = {};
|
||||
|
||||
const rdbService = {} as RemoteDataBuildService;
|
||||
const rdbService = {
|
||||
buildSingle : () => null
|
||||
} as any;
|
||||
const store = {} as Store<CoreState>;
|
||||
const notificationsService = {} as NotificationsService;
|
||||
const http = {} as HttpClient;
|
||||
@@ -178,6 +181,90 @@ describe('ComColDataService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('cache refresh', () => {
|
||||
let communityWithoutParentHref;
|
||||
let data;
|
||||
|
||||
beforeEach(() => {
|
||||
scheduler = getTestScheduler();
|
||||
halService = {
|
||||
getEndpoint: (linkPath) => 'https://rest.api/core/' + linkPath
|
||||
};
|
||||
service = initTestService();
|
||||
|
||||
})
|
||||
describe('cache refreshed top level community', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(rdbService, 'buildSingle').and.returnValue(createNoContentRemoteDataObject$());
|
||||
data = {
|
||||
dso: Object.assign(new Community(), {
|
||||
metadata: [{
|
||||
key: 'dc.title',
|
||||
value: 'top level community'
|
||||
}]
|
||||
}),
|
||||
_links: {
|
||||
parentCommunity: {
|
||||
href: 'topLevel/parentCommunity'
|
||||
}
|
||||
}
|
||||
};
|
||||
communityWithoutParentHref = {
|
||||
dso: Object.assign(new Community(), {
|
||||
metadata: [{
|
||||
key: 'dc.title',
|
||||
value: 'top level community'
|
||||
}]
|
||||
}),
|
||||
_links: {}
|
||||
};
|
||||
});
|
||||
it('top level community cache refreshed', () => {
|
||||
scheduler.schedule(() => (service as any).refreshCache(data));
|
||||
scheduler.flush();
|
||||
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith('https://rest.api/core/communities/search/top');
|
||||
});
|
||||
it('top level community without parent link, cache not refreshed', () => {
|
||||
scheduler.schedule(() => (service as any).refreshCache(communityWithoutParentHref));
|
||||
scheduler.flush();
|
||||
expect(requestService.removeByHrefSubstring).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('cache refreshed child community', () => {
|
||||
beforeEach(() => {
|
||||
const parentCommunity = Object.assign(new Community(), {
|
||||
uuid: 'a20da287-e174-466a-9926-f66as300d399',
|
||||
id: 'a20da287-e174-466a-9926-f66as300d399',
|
||||
metadata: [{
|
||||
key: 'dc.title',
|
||||
value: 'parent community'
|
||||
}],
|
||||
_links: {}
|
||||
});
|
||||
spyOn(rdbService, 'buildSingle').and.returnValue(createSuccessfulRemoteDataObject$(parentCommunity));
|
||||
data = {
|
||||
dso: Object.assign(new Community(), {
|
||||
metadata: [{
|
||||
key: 'dc.title',
|
||||
value: 'child community'
|
||||
}]
|
||||
}),
|
||||
_links: {
|
||||
parentCommunity: {
|
||||
href: 'child/parentCommunity'
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
it('child level community cache refreshed', () => {
|
||||
scheduler.schedule(() => (service as any).refreshCache(data));
|
||||
scheduler.flush();
|
||||
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith('a20da287-e174-466a-9926-f66as300d399');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -21,12 +21,14 @@ import {
|
||||
configureRequest,
|
||||
getRemoteDataPayload,
|
||||
getResponseFromEntry,
|
||||
getSucceededOrNoContentResponse,
|
||||
getSucceededRemoteData
|
||||
} from '../shared/operators';
|
||||
import { CacheableObject } from '../cache/object-cache.reducer';
|
||||
import { RestResponse } from '../cache/response.models';
|
||||
import { Bitstream } from '../shared/bitstream.model';
|
||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||
import {Collection} from '../shared/collection.model';
|
||||
|
||||
export abstract class ComColDataService<T extends CacheableObject> extends DataService<T> {
|
||||
protected abstract cds: CommunityDataService;
|
||||
@@ -119,4 +121,23 @@ export abstract class ComColDataService<T extends CacheableObject> extends DataS
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public refreshCache(dso: T) {
|
||||
const parentCommunityUrl = this.parentCommunityUrlLookup(dso as any);
|
||||
if (!hasValue(parentCommunityUrl)) {
|
||||
return;
|
||||
}
|
||||
this.findByHref(parentCommunityUrl).pipe(
|
||||
getSucceededOrNoContentResponse(),
|
||||
take(1),
|
||||
).subscribe((rd: RemoteData<any>) => {
|
||||
const href = rd.hasSucceeded && !isEmpty(rd.payload.id) ? rd.payload.id : this.halService.getEndpoint('communities/search/top');
|
||||
this.requestService.removeByHrefSubstring(href)
|
||||
});
|
||||
}
|
||||
|
||||
private parentCommunityUrlLookup(dso: Collection | Community) {
|
||||
const parentCommunity = dso._links.parentCommunity;
|
||||
return isNotEmpty(parentCommunity) ? parentCommunity.href : null;
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { Observable } from 'rxjs';
|
||||
import { take, tap } from 'rxjs/operators';
|
||||
import { filter, take, tap } from 'rxjs/operators';
|
||||
import { hasValue } from '../../shared/empty.util';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
||||
@@ -11,7 +11,6 @@ import { RemoteDataBuildService } from '../cache/builders/remote-data-build.serv
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { CoreState } from '../core.reducers';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { getFinishedRemoteData } from '../shared/operators';
|
||||
import { DataService } from './data.service';
|
||||
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
||||
import { RemoteData } from './remote-data';
|
||||
@@ -56,7 +55,7 @@ export class DsoRedirectDataService extends DataService<any> {
|
||||
findByIdAndIDType(id: string, identifierType = IdentifierType.UUID): Observable<RemoteData<FindByIDRequest>> {
|
||||
this.setLinkPath(identifierType);
|
||||
return this.findById(id).pipe(
|
||||
getFinishedRemoteData(),
|
||||
filter((response) => hasValue(response.error) || hasValue(response.payload)),
|
||||
take(1),
|
||||
tap((response) => {
|
||||
if (response.hasSucceeded) {
|
||||
|
@@ -58,4 +58,8 @@ export class DSpaceObjectDataService {
|
||||
findById(uuid: string): Observable<RemoteData<DSpaceObject>> {
|
||||
return this.dataService.findById(uuid);
|
||||
}
|
||||
|
||||
findByHref(href: string): Observable<RemoteData<DSpaceObject>> {
|
||||
return this.dataService.findByHref(href);
|
||||
}
|
||||
}
|
||||
|
@@ -12,11 +12,12 @@ import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { GetRequest } from './request.models';
|
||||
import { Observable } from 'rxjs';
|
||||
import { switchMap, take } from 'rxjs/operators';
|
||||
import { switchMap, take, map } from 'rxjs/operators';
|
||||
import { RemoteData } from './remote-data';
|
||||
import { RelationshipType } from '../shared/item-relationships/relationship-type.model';
|
||||
import { PaginatedList } from './paginated-list';
|
||||
import { ItemType } from '../shared/item-relationships/item-type.model';
|
||||
import {getRemoteDataPayload, getSucceededRemoteData} from '../shared/operators';
|
||||
|
||||
/**
|
||||
* Service handling all ItemType requests
|
||||
@@ -51,6 +52,20 @@ export class EntityTypeService extends DataService<ItemType> {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given entity type is the left type of a given relationship type, as an observable boolean
|
||||
* @param relationshipType the relationship type for which to check whether the given entity type is the left type
|
||||
* @param entityType the entity type for which to check whether it is the left type of the given relationship type
|
||||
*/
|
||||
isLeftType(relationshipType: RelationshipType, itemType: ItemType): Observable<boolean> {
|
||||
|
||||
return relationshipType.leftType.pipe(
|
||||
getSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
map((leftType) => leftType.uuid === itemType.uuid),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the allowed relationship types for an entity type
|
||||
* @param entityTypeId
|
||||
|
@@ -19,7 +19,7 @@ import { FindListOptions, FindListRequest } from '../request.models';
|
||||
import { followLink, FollowLinkConfig } from '../../../shared/utils/follow-link-config.model';
|
||||
import { RemoteData } from '../remote-data';
|
||||
import { PaginatedList } from '../paginated-list';
|
||||
import { find, map, switchMap, tap } from 'rxjs/operators';
|
||||
import { catchError, find, map, switchMap, tap } from 'rxjs/operators';
|
||||
import { hasValue, isNotEmpty } from '../../../shared/empty.util';
|
||||
import { RequestParam } from '../../cache/models/request-param.model';
|
||||
import { AuthorizationSearchParams } from './authorization-search-params';
|
||||
@@ -67,6 +67,7 @@ export class AuthorizationDataService extends DataService<Authorization> {
|
||||
return [];
|
||||
}
|
||||
}),
|
||||
catchError(() => observableOf(false)),
|
||||
oneAuthorizationMatchesFeature(featureId)
|
||||
);
|
||||
}
|
||||
|
@@ -6,6 +6,8 @@ import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-dat
|
||||
import { DSpaceObject } from '../../../shared/dspace-object.model';
|
||||
import { DsoPageFeatureGuard } from './dso-page-feature.guard';
|
||||
import { FeatureID } from '../feature-id';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { AuthService } from '../../../auth/auth.service';
|
||||
|
||||
/**
|
||||
* Test implementation of abstract class DsoPageAdministratorGuard
|
||||
@@ -14,8 +16,9 @@ class DsoPageFeatureGuardImpl extends DsoPageFeatureGuard<any> {
|
||||
constructor(protected resolver: Resolve<RemoteData<any>>,
|
||||
protected authorizationService: AuthorizationDataService,
|
||||
protected router: Router,
|
||||
protected authService: AuthService,
|
||||
protected featureID: FeatureID) {
|
||||
super(resolver, authorizationService, router);
|
||||
super(resolver, authorizationService, router, authService);
|
||||
}
|
||||
|
||||
getFeatureID(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<FeatureID> {
|
||||
@@ -27,6 +30,7 @@ describe('DsoPageAdministratorGuard', () => {
|
||||
let guard: DsoPageFeatureGuard<any>;
|
||||
let authorizationService: AuthorizationDataService;
|
||||
let router: Router;
|
||||
let authService: AuthService;
|
||||
let resolver: Resolve<RemoteData<any>>;
|
||||
let object: DSpaceObject;
|
||||
|
||||
@@ -44,7 +48,10 @@ describe('DsoPageAdministratorGuard', () => {
|
||||
resolver = jasmine.createSpyObj('resolver', {
|
||||
resolve: createSuccessfulRemoteDataObject$(object)
|
||||
});
|
||||
guard = new DsoPageFeatureGuardImpl(resolver, authorizationService, router, undefined);
|
||||
authService = jasmine.createSpyObj('authService', {
|
||||
isAuthenticated: observableOf(true)
|
||||
});
|
||||
guard = new DsoPageFeatureGuardImpl(resolver, authorizationService, router, authService, undefined);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
|
@@ -6,6 +6,7 @@ import { getAllSucceededRemoteDataPayload } from '../../../shared/operators';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { DSpaceObject } from '../../../shared/dspace-object.model';
|
||||
import { FeatureAuthorizationGuard } from './feature-authorization.guard';
|
||||
import { AuthService } from '../../../auth/auth.service';
|
||||
|
||||
/**
|
||||
* Abstract Guard for preventing unauthorized access to {@link DSpaceObject} pages that require rights for a specific feature
|
||||
@@ -14,8 +15,9 @@ import { FeatureAuthorizationGuard } from './feature-authorization.guard';
|
||||
export abstract class DsoPageFeatureGuard<T extends DSpaceObject> extends FeatureAuthorizationGuard {
|
||||
constructor(protected resolver: Resolve<RemoteData<T>>,
|
||||
protected authorizationService: AuthorizationDataService,
|
||||
protected router: Router) {
|
||||
super(authorizationService, router);
|
||||
protected router: Router,
|
||||
protected authService: AuthService) {
|
||||
super(authorizationService, router, authService);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user