mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Merge remote-tracking branch '4Science-bitbucket/main' into CST-5668
This commit is contained in:
@@ -148,6 +148,9 @@ languages:
|
|||||||
- code: fi
|
- code: fi
|
||||||
label: Suomi
|
label: Suomi
|
||||||
active: true
|
active: true
|
||||||
|
- code: tr
|
||||||
|
label: Türkçe
|
||||||
|
active: true
|
||||||
- code: bn
|
- code: bn
|
||||||
label: বাংলা
|
label: বাংলা
|
||||||
active: true
|
active: true
|
||||||
@@ -161,10 +164,12 @@ browseBy:
|
|||||||
# The absolute lowest year to display in the dropdown (only used when no lowest date can be found for all items)
|
# The absolute lowest year to display in the dropdown (only used when no lowest date can be found for all items)
|
||||||
defaultLowerLimit: 1900
|
defaultLowerLimit: 1900
|
||||||
|
|
||||||
# Item Page Config
|
# Item Config
|
||||||
item:
|
item:
|
||||||
edit:
|
edit:
|
||||||
undoTimeout: 10000 # 10 seconds
|
undoTimeout: 10000 # 10 seconds
|
||||||
|
# Show the item access status label in items lists
|
||||||
|
showAccessStatuses: false
|
||||||
|
|
||||||
# Collection Page Config
|
# Collection Page Config
|
||||||
collection:
|
collection:
|
||||||
@@ -231,6 +236,10 @@ themes:
|
|||||||
rel: manifest
|
rel: manifest
|
||||||
href: assets/dspace/images/favicons/manifest.webmanifest
|
href: assets/dspace/images/favicons/manifest.webmanifest
|
||||||
|
|
||||||
|
# The default bundles that should always be displayed as suggestions when you upload a new bundle
|
||||||
|
bundle:
|
||||||
|
- standardBundles: [ ORIGINAL, THUMBNAIL, LICENSE ]
|
||||||
|
|
||||||
# Whether to enable media viewer for image and/or video Bitstreams (i.e. Bitstreams whose MIME type starts with 'image' or 'video').
|
# Whether to enable media viewer for image and/or video Bitstreams (i.e. Bitstreams whose MIME type starts with 'image' or 'video').
|
||||||
# For images, this enables a gallery viewer where you can zoom or page through images.
|
# For images, this enables a gallery viewer where you can zoom or page through images.
|
||||||
# For videos, this enables embedded video streaming
|
# For videos, this enables embedded video streaming
|
||||||
|
16
package.json
16
package.json
@@ -68,8 +68,8 @@
|
|||||||
"@material-ui/core": "^4.11.0",
|
"@material-ui/core": "^4.11.0",
|
||||||
"@material-ui/icons": "^4.9.1",
|
"@material-ui/icons": "^4.9.1",
|
||||||
"@ng-bootstrap/ng-bootstrap": "^11.0.0",
|
"@ng-bootstrap/ng-bootstrap": "^11.0.0",
|
||||||
"@ng-dynamic-forms/core": "^14.0.1",
|
"@ng-dynamic-forms/core": "^15.0.0",
|
||||||
"@ng-dynamic-forms/ui-ng-bootstrap": "^14.0.1",
|
"@ng-dynamic-forms/ui-ng-bootstrap": "^15.0.0",
|
||||||
"@ngrx/effects": "^13.0.2",
|
"@ngrx/effects": "^13.0.2",
|
||||||
"@ngrx/router-store": "^13.0.2",
|
"@ngrx/router-store": "^13.0.2",
|
||||||
"@ngrx/store": "^13.0.2",
|
"@ngrx/store": "^13.0.2",
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
"@ngx-translate/core": "^13.0.0",
|
"@ngx-translate/core": "^13.0.0",
|
||||||
"@nicky-lenaers/ngx-scroll-to": "^9.0.0",
|
"@nicky-lenaers/ngx-scroll-to": "^9.0.0",
|
||||||
"angular-idle-preload": "3.0.0",
|
"angular-idle-preload": "3.0.0",
|
||||||
"angulartics2": "^10.0.0",
|
"angulartics2": "^12.0.0",
|
||||||
"bootstrap": "4.3.1",
|
"bootstrap": "4.3.1",
|
||||||
"caniuse-lite": "^1.0.30001165",
|
"caniuse-lite": "^1.0.30001165",
|
||||||
"cerialize": "0.1.18",
|
"cerialize": "0.1.18",
|
||||||
@@ -119,7 +119,7 @@
|
|||||||
"prop-types": "^15.7.2",
|
"prop-types": "^15.7.2",
|
||||||
"react-copy-to-clipboard": "^5.0.1",
|
"react-copy-to-clipboard": "^5.0.1",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rxjs": "^6.6.3",
|
"rxjs": "^7.5.5",
|
||||||
"sortablejs": "1.13.0",
|
"sortablejs": "1.13.0",
|
||||||
"tslib": "^2.0.0",
|
"tslib": "^2.0.0",
|
||||||
"url-parse": "^1.5.6",
|
"url-parse": "^1.5.6",
|
||||||
@@ -162,7 +162,7 @@
|
|||||||
"css-minimizer-webpack-plugin": "^3.4.1",
|
"css-minimizer-webpack-plugin": "^3.4.1",
|
||||||
"cssnano": "^5.0.6",
|
"cssnano": "^5.0.6",
|
||||||
"cypress": "9.5.1",
|
"cypress": "9.5.1",
|
||||||
"cypress-axe": "^0.13.0",
|
"cypress-axe": "^0.14.0",
|
||||||
"debug-loader": "^0.0.1",
|
"debug-loader": "^0.0.1",
|
||||||
"deep-freeze": "0.0.1",
|
"deep-freeze": "0.0.1",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
@@ -174,7 +174,7 @@
|
|||||||
"fork-ts-checker-webpack-plugin": "^6.0.3",
|
"fork-ts-checker-webpack-plugin": "^6.0.3",
|
||||||
"html-loader": "^1.3.2",
|
"html-loader": "^1.3.2",
|
||||||
"jasmine-core": "^3.8.0",
|
"jasmine-core": "^3.8.0",
|
||||||
"jasmine-marbles": "0.6.0",
|
"jasmine-marbles": "0.9.2",
|
||||||
"jasmine-spec-reporter": "~5.0.0",
|
"jasmine-spec-reporter": "~5.0.0",
|
||||||
"karma": "^6.3.14",
|
"karma": "^6.3.14",
|
||||||
"karma-chrome-launcher": "~3.1.0",
|
"karma-chrome-launcher": "~3.1.0",
|
||||||
@@ -182,7 +182,7 @@
|
|||||||
"karma-jasmine": "~4.0.0",
|
"karma-jasmine": "~4.0.0",
|
||||||
"karma-jasmine-html-reporter": "^1.5.0",
|
"karma-jasmine-html-reporter": "^1.5.0",
|
||||||
"karma-mocha-reporter": "2.2.5",
|
"karma-mocha-reporter": "2.2.5",
|
||||||
"ngx-mask": "^12.0.0",
|
"ngx-mask": "^13.1.7",
|
||||||
"nodemon": "^2.0.15",
|
"nodemon": "^2.0.15",
|
||||||
"postcss": "^8.1",
|
"postcss": "^8.1",
|
||||||
"postcss-apply": "0.12.0",
|
"postcss-apply": "0.12.0",
|
||||||
@@ -196,7 +196,7 @@
|
|||||||
"react": "^16.14.0",
|
"react": "^16.14.0",
|
||||||
"react-dom": "^16.14.0",
|
"react-dom": "^16.14.0",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"rxjs-spy": "^7.5.3",
|
"rxjs-spy": "^8.0.2",
|
||||||
"sass": "~1.32.6",
|
"sass": "~1.32.6",
|
||||||
"sass-loader": "^12.6.0",
|
"sass-loader": "^12.6.0",
|
||||||
"sass-resources-loader": "^2.1.1",
|
"sass-resources-loader": "^2.1.1",
|
||||||
|
@@ -1,6 +1,17 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<h2 id="header">{{'admin.metadata-import.page.header' | translate}}</h2>
|
<h2 id="header">{{'admin.metadata-import.page.header' | translate}}</h2>
|
||||||
<p>{{'admin.metadata-import.page.help' | translate}}</p>
|
<p>{{'admin.metadata-import.page.help' | translate}}</p>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" id="validateOnly" [(ngModel)]="validateOnly">
|
||||||
|
<label class="form-check-label" for="validateOnly">
|
||||||
|
{{'admin.metadata-import.page.validateOnly' | translate}}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<small id="validateOnlyHelpBlock" class="form-text text-muted">
|
||||||
|
{{'admin.metadata-import.page.validateOnly.hint' | translate}}
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
<ds-file-dropzone-no-uploader
|
<ds-file-dropzone-no-uploader
|
||||||
(onFileAdded)="setFile($event)"
|
(onFileAdded)="setFile($event)"
|
||||||
@@ -8,8 +19,10 @@
|
|||||||
[dropMessageLabelReplacement]="'admin.metadata-import.page.dropMsgReplace'">
|
[dropMessageLabelReplacement]="'admin.metadata-import.page.dropMsgReplace'">
|
||||||
</ds-file-dropzone-no-uploader>
|
</ds-file-dropzone-no-uploader>
|
||||||
|
|
||||||
|
<div class="space-children-mr">
|
||||||
<button class="btn btn-secondary" id="backButton"
|
<button class="btn btn-secondary" id="backButton"
|
||||||
(click)="this.onReturn();">{{'admin.metadata-import.page.button.return' | translate}}</button>
|
(click)="this.onReturn();">{{'admin.metadata-import.page.button.return' | translate}}</button>
|
||||||
<button class="btn btn-primary" id="proceedButton"
|
<button class="btn btn-primary" id="proceedButton"
|
||||||
(click)="this.importMetadata();">{{'admin.metadata-import.page.button.proceed' | translate}}</button>
|
(click)="this.importMetadata();">{{'admin.metadata-import.page.button.proceed' | translate}}</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
@@ -87,8 +87,9 @@ describe('MetadataImportPageComponent', () => {
|
|||||||
comp.setFile(fileMock);
|
comp.setFile(fileMock);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('if proceed button is pressed', () => {
|
describe('if proceed button is pressed without validate only', () => {
|
||||||
beforeEach(fakeAsync(() => {
|
beforeEach(fakeAsync(() => {
|
||||||
|
comp.validateOnly = false;
|
||||||
const proceed = fixture.debugElement.query(By.css('#proceedButton')).nativeElement;
|
const proceed = fixture.debugElement.query(By.css('#proceedButton')).nativeElement;
|
||||||
proceed.click();
|
proceed.click();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -107,6 +108,28 @@ describe('MetadataImportPageComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('if proceed button is pressed with validate only', () => {
|
||||||
|
beforeEach(fakeAsync(() => {
|
||||||
|
comp.validateOnly = true;
|
||||||
|
const proceed = fixture.debugElement.query(By.css('#proceedButton')).nativeElement;
|
||||||
|
proceed.click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
it('metadata-import script is invoked with -f fileName and the mockFile and -v validate-only', () => {
|
||||||
|
const parameterValues: ProcessParameter[] = [
|
||||||
|
Object.assign(new ProcessParameter(), { name: '-f', value: 'filename.txt' }),
|
||||||
|
Object.assign(new ProcessParameter(), { name: '-v', value: true }),
|
||||||
|
];
|
||||||
|
expect(scriptService.invoke).toHaveBeenCalledWith(METADATA_IMPORT_SCRIPT_NAME, parameterValues, [fileMock]);
|
||||||
|
});
|
||||||
|
it('success notification is shown', () => {
|
||||||
|
expect(notificationService.success).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
it('redirected to process page', () => {
|
||||||
|
expect(router.navigateByUrl).toHaveBeenCalledWith('/processes/45');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('if proceed is pressed; but script invoke fails', () => {
|
describe('if proceed is pressed; but script invoke fails', () => {
|
||||||
beforeEach(fakeAsync(() => {
|
beforeEach(fakeAsync(() => {
|
||||||
jasmine.getEnv().allowRespy(true);
|
jasmine.getEnv().allowRespy(true);
|
||||||
|
@@ -30,6 +30,11 @@ export class MetadataImportPageComponent {
|
|||||||
*/
|
*/
|
||||||
fileObject: File;
|
fileObject: File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The validate only flag
|
||||||
|
*/
|
||||||
|
validateOnly = true;
|
||||||
|
|
||||||
public constructor(private location: Location,
|
public constructor(private location: Location,
|
||||||
protected translate: TranslateService,
|
protected translate: TranslateService,
|
||||||
protected notificationsService: NotificationsService,
|
protected notificationsService: NotificationsService,
|
||||||
@@ -62,6 +67,9 @@ export class MetadataImportPageComponent {
|
|||||||
const parameterValues: ProcessParameter[] = [
|
const parameterValues: ProcessParameter[] = [
|
||||||
Object.assign(new ProcessParameter(), { name: '-f', value: this.fileObject.name }),
|
Object.assign(new ProcessParameter(), { name: '-f', value: this.fileObject.name }),
|
||||||
];
|
];
|
||||||
|
if (this.validateOnly) {
|
||||||
|
parameterValues.push(Object.assign(new ProcessParameter(), { name: '-v', value: true }));
|
||||||
|
}
|
||||||
|
|
||||||
this.scriptDataService.invoke(METADATA_IMPORT_SCRIPT_NAME, parameterValues, [this.fileObject]).pipe(
|
this.scriptDataService.invoke(METADATA_IMPORT_SCRIPT_NAME, parameterValues, [this.fileObject]).pipe(
|
||||||
getFirstCompletedRemoteData(),
|
getFirstCompletedRemoteData(),
|
||||||
|
@@ -18,6 +18,8 @@ import { ItemAdminSearchResultGridElementComponent } from './item-admin-search-r
|
|||||||
import { createSuccessfulRemoteDataObject$ } from '../../../../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject$ } from '../../../../../shared/remote-data.utils';
|
||||||
import { getMockThemeService } from '../../../../../shared/mocks/theme-service.mock';
|
import { getMockThemeService } from '../../../../../shared/mocks/theme-service.mock';
|
||||||
import { ThemeService } from '../../../../../shared/theme-support/theme.service';
|
import { ThemeService } from '../../../../../shared/theme-support/theme.service';
|
||||||
|
import { AccessStatusDataService } from 'src/app/core/data/access-status-data.service';
|
||||||
|
import { AccessStatusObject } from 'src/app/shared/object-list/access-status-badge/access-status.model';
|
||||||
|
|
||||||
describe('ItemAdminSearchResultGridElementComponent', () => {
|
describe('ItemAdminSearchResultGridElementComponent', () => {
|
||||||
let component: ItemAdminSearchResultGridElementComponent;
|
let component: ItemAdminSearchResultGridElementComponent;
|
||||||
@@ -31,6 +33,12 @@ describe('ItemAdminSearchResultGridElementComponent', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mockAccessStatusDataService = {
|
||||||
|
findAccessStatusFor(item: Item): Observable<RemoteData<AccessStatusObject>> {
|
||||||
|
return createSuccessfulRemoteDataObject$(new AccessStatusObject());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const mockThemeService = getMockThemeService();
|
const mockThemeService = getMockThemeService();
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
@@ -55,6 +63,7 @@ describe('ItemAdminSearchResultGridElementComponent', () => {
|
|||||||
{ provide: TruncatableService, useValue: mockTruncatableService },
|
{ provide: TruncatableService, useValue: mockTruncatableService },
|
||||||
{ provide: BitstreamDataService, useValue: mockBitstreamDataService },
|
{ provide: BitstreamDataService, useValue: mockBitstreamDataService },
|
||||||
{ provide: ThemeService, useValue: mockThemeService },
|
{ provide: ThemeService, useValue: mockThemeService },
|
||||||
|
{ provide: AccessStatusDataService, useValue: mockAccessStatusDataService },
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
})
|
})
|
||||||
|
@@ -70,6 +70,12 @@ export function getWorkflowItemModuleRoute() {
|
|||||||
return `/${WORKFLOW_ITEM_MODULE_PATH}`;
|
return `/${WORKFLOW_ITEM_MODULE_PATH}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const WORKSPACE_ITEM_MODULE_PATH = 'workspaceitems';
|
||||||
|
|
||||||
|
export function getWorkspaceItemModuleRoute() {
|
||||||
|
return `/${WORKSPACE_ITEM_MODULE_PATH}`;
|
||||||
|
}
|
||||||
|
|
||||||
export function getDSORoute(dso: DSpaceObject): string {
|
export function getDSORoute(dso: DSpaceObject): string {
|
||||||
if (hasValue(dso)) {
|
if (hasValue(dso)) {
|
||||||
switch ((dso as any).type) {
|
switch ((dso as any).type) {
|
||||||
|
@@ -4,7 +4,7 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
|||||||
import { CommonModule, DOCUMENT } from '@angular/common';
|
import { CommonModule, DOCUMENT } from '@angular/common';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
|
import { Angulartics2GoogleAnalytics } from 'angulartics2';
|
||||||
|
|
||||||
// Load the implementations that should be tested
|
// Load the implementations that should be tested
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
@@ -23,7 +23,7 @@ import { BehaviorSubject, Observable, of } from 'rxjs';
|
|||||||
import { select, Store } from '@ngrx/store';
|
import { select, Store } from '@ngrx/store';
|
||||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
|
import { Angulartics2GoogleAnalytics } from 'angulartics2';
|
||||||
|
|
||||||
import { MetadataService } from './core/metadata/metadata.service';
|
import { MetadataService } from './core/metadata/metadata.service';
|
||||||
import { HostWindowResizeAction } from './shared/host-window.actions';
|
import { HostWindowResizeAction } from './shared/host-window.actions';
|
||||||
|
@@ -10,6 +10,9 @@ import { ResourcePolicyResolver } from '../shared/resource-policies/resolvers/re
|
|||||||
import { ResourcePolicyEditComponent } from '../shared/resource-policies/edit/resource-policy-edit.component';
|
import { ResourcePolicyEditComponent } from '../shared/resource-policies/edit/resource-policy-edit.component';
|
||||||
import { BitstreamAuthorizationsComponent } from './bitstream-authorizations/bitstream-authorizations.component';
|
import { BitstreamAuthorizationsComponent } from './bitstream-authorizations/bitstream-authorizations.component';
|
||||||
import { LegacyBitstreamUrlResolver } from './legacy-bitstream-url.resolver';
|
import { LegacyBitstreamUrlResolver } from './legacy-bitstream-url.resolver';
|
||||||
|
import { BitstreamBreadcrumbResolver } from '../core/breadcrumbs/bitstream-breadcrumb.resolver';
|
||||||
|
import { BitstreamBreadcrumbsService } from '../core/breadcrumbs/bitstream-breadcrumbs.service';
|
||||||
|
import { I18nBreadcrumbResolver } from '../core/breadcrumbs/i18n-breadcrumb.resolver';
|
||||||
|
|
||||||
const EDIT_BITSTREAM_PATH = ':id/edit';
|
const EDIT_BITSTREAM_PATH = ':id/edit';
|
||||||
const EDIT_BITSTREAM_AUTHORIZATIONS_PATH = ':id/authorizations';
|
const EDIT_BITSTREAM_AUTHORIZATIONS_PATH = ':id/authorizations';
|
||||||
@@ -48,7 +51,8 @@ const EDIT_BITSTREAM_AUTHORIZATIONS_PATH = ':id/authorizations';
|
|||||||
path: EDIT_BITSTREAM_PATH,
|
path: EDIT_BITSTREAM_PATH,
|
||||||
component: EditBitstreamPageComponent,
|
component: EditBitstreamPageComponent,
|
||||||
resolve: {
|
resolve: {
|
||||||
bitstream: BitstreamPageResolver
|
bitstream: BitstreamPageResolver,
|
||||||
|
breadcrumb: BitstreamBreadcrumbResolver,
|
||||||
},
|
},
|
||||||
canActivate: [AuthenticatedGuard]
|
canActivate: [AuthenticatedGuard]
|
||||||
},
|
},
|
||||||
@@ -67,15 +71,17 @@ const EDIT_BITSTREAM_AUTHORIZATIONS_PATH = ':id/authorizations';
|
|||||||
{
|
{
|
||||||
path: 'edit',
|
path: 'edit',
|
||||||
resolve: {
|
resolve: {
|
||||||
|
breadcrumb: I18nBreadcrumbResolver,
|
||||||
resourcePolicy: ResourcePolicyResolver
|
resourcePolicy: ResourcePolicyResolver
|
||||||
},
|
},
|
||||||
component: ResourcePolicyEditComponent,
|
component: ResourcePolicyEditComponent,
|
||||||
data: { title: 'resource-policies.edit.page.title', showBreadcrumbs: true }
|
data: { breadcrumbKey: 'item.edit', title: 'resource-policies.edit.page.title', showBreadcrumbs: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
resolve: {
|
resolve: {
|
||||||
bitstream: BitstreamPageResolver
|
bitstream: BitstreamPageResolver,
|
||||||
|
breadcrumb: BitstreamBreadcrumbResolver,
|
||||||
},
|
},
|
||||||
component: BitstreamAuthorizationsComponent,
|
component: BitstreamAuthorizationsComponent,
|
||||||
data: { title: 'bitstream.edit.authorizations.title', showBreadcrumbs: true }
|
data: { title: 'bitstream.edit.authorizations.title', showBreadcrumbs: true }
|
||||||
@@ -86,6 +92,8 @@ const EDIT_BITSTREAM_AUTHORIZATIONS_PATH = ':id/authorizations';
|
|||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
BitstreamPageResolver,
|
BitstreamPageResolver,
|
||||||
|
BitstreamBreadcrumbResolver,
|
||||||
|
BitstreamBreadcrumbsService
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class BitstreamPageRoutingModule {
|
export class BitstreamPageRoutingModule {
|
||||||
|
@@ -7,6 +7,15 @@ import { BitstreamDataService } from '../core/data/bitstream-data.service';
|
|||||||
import { followLink, FollowLinkConfig } from '../shared/utils/follow-link-config.model';
|
import { followLink, FollowLinkConfig } from '../shared/utils/follow-link-config.model';
|
||||||
import { getFirstCompletedRemoteData } from '../core/shared/operators';
|
import { getFirstCompletedRemoteData } from '../core/shared/operators';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The self links defined in this list are expected to be requested somewhere in the near future
|
||||||
|
* Requesting them as embeds will limit the number of requests
|
||||||
|
*/
|
||||||
|
export const BITSTREAM_PAGE_LINKS_TO_FOLLOW: FollowLinkConfig<Bitstream>[] = [
|
||||||
|
followLink('bundle', {}, followLink('item')),
|
||||||
|
followLink('format')
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a resolver that requests a specific bitstream before the route is activated
|
* This class represents a resolver that requests a specific bitstream before the route is activated
|
||||||
*/
|
*/
|
||||||
@@ -34,9 +43,6 @@ export class BitstreamPageResolver implements Resolve<RemoteData<Bitstream>> {
|
|||||||
* Requesting them as embeds will limit the number of requests
|
* Requesting them as embeds will limit the number of requests
|
||||||
*/
|
*/
|
||||||
get followLinks(): FollowLinkConfig<Bitstream>[] {
|
get followLinks(): FollowLinkConfig<Bitstream>[] {
|
||||||
return [
|
return BITSTREAM_PAGE_LINKS_TO_FOLLOW;
|
||||||
followLink('bundle', {}, followLink('item')),
|
|
||||||
followLink('format')
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,13 @@
|
|||||||
<section class="comcol-page-browse-section">
|
<section class="comcol-page-browse-section">
|
||||||
<div class="browse-by-metadata w-100">
|
<div class="browse-by-metadata w-100">
|
||||||
<ds-browse-by *ngIf="startsWithOptions" class="col-xs-12 w-100"
|
<ds-browse-by *ngIf="startsWithOptions" class="col-xs-12 w-100"
|
||||||
title="{{'browse.title' | translate:{collection: (parent$ | async)?.payload?.name || '', field: 'browse.metadata.' + browseId | translate, value: (value)? '"' + value + '"': ''} }}"
|
title="{{'browse.title' | translate:
|
||||||
|
{
|
||||||
|
collection: (parent$ | async)?.payload?.name || '',
|
||||||
|
field: 'browse.metadata.' + browseId | translate,
|
||||||
|
startsWith: (startsWith)? ('browse.startsWith' | translate: { startsWith: '"' + startsWith + '"' }) : '',
|
||||||
|
value: (value)? '"' + value + '"': ''
|
||||||
|
} }}"
|
||||||
parentname="{{(parent$ | async)?.payload?.name || ''}}"
|
parentname="{{(parent$ | async)?.payload?.name || ''}}"
|
||||||
[objects$]="(items$ !== undefined)? items$ : browseEntries$"
|
[objects$]="(items$ !== undefined)? items$ : browseEntries$"
|
||||||
[paginationConfig]="(currentPagination$ |async)"
|
[paginationConfig]="(currentPagination$ |async)"
|
||||||
|
@@ -17,7 +17,7 @@ import { ThemedBrowseBySwitcherComponent } from './browse-by-switcher/themed-bro
|
|||||||
component: ThemedBrowseBySwitcherComponent,
|
component: ThemedBrowseBySwitcherComponent,
|
||||||
canActivate: [BrowseByGuard],
|
canActivate: [BrowseByGuard],
|
||||||
resolve: { breadcrumb: BrowseByI18nBreadcrumbResolver },
|
resolve: { breadcrumb: BrowseByI18nBreadcrumbResolver },
|
||||||
data: { title: 'browse.title', breadcrumbKey: 'browse.metadata' }
|
data: { title: 'browse.title.page', breadcrumbKey: 'browse.metadata' }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}])
|
}])
|
||||||
|
@@ -45,6 +45,7 @@ export class BrowseByTitlePageComponent extends BrowseByMetadataPageComponent {
|
|||||||
return [Object.assign({}, routeParams, queryParams),currentPage,currentSort];
|
return [Object.assign({}, routeParams, queryParams),currentPage,currentSort];
|
||||||
})
|
})
|
||||||
).subscribe(([params, currentPage, currentSort]: [Params, PaginationComponentOptions, SortOptions]) => {
|
).subscribe(([params, currentPage, currentSort]: [Params, PaginationComponentOptions, SortOptions]) => {
|
||||||
|
this.startsWith = +params.startsWith || params.startsWith;
|
||||||
this.browseId = params.id || this.defaultBrowseId;
|
this.browseId = params.id || this.defaultBrowseId;
|
||||||
this.updatePageWithItems(browseParamsToOptions(params, currentPage, currentSort, this.browseId), undefined, undefined);
|
this.updatePageWithItems(browseParamsToOptions(params, currentPage, currentSort, this.browseId), undefined, undefined);
|
||||||
this.updateParent(params.scope);
|
this.updateParent(params.scope);
|
||||||
|
@@ -43,6 +43,10 @@ import { createPaginatedList } from '../../shared/testing/utils.test';
|
|||||||
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
||||||
import { MyDSpacePageComponent, SEARCH_CONFIG_SERVICE } from '../../my-dspace-page/my-dspace-page.component';
|
import { MyDSpacePageComponent, SEARCH_CONFIG_SERVICE } from '../../my-dspace-page/my-dspace-page.component';
|
||||||
import { SearchConfigurationServiceStub } from '../../shared/testing/search-configuration-service.stub';
|
import { SearchConfigurationServiceStub } from '../../shared/testing/search-configuration-service.stub';
|
||||||
|
import { GroupDataService } from '../../core/eperson/group-data.service';
|
||||||
|
import { LinkHeadService } from '../../core/services/link-head.service';
|
||||||
|
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
|
||||||
|
import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
|
||||||
|
|
||||||
describe('CollectionItemMapperComponent', () => {
|
describe('CollectionItemMapperComponent', () => {
|
||||||
let comp: CollectionItemMapperComponent;
|
let comp: CollectionItemMapperComponent;
|
||||||
@@ -143,6 +147,25 @@ describe('CollectionItemMapperComponent', () => {
|
|||||||
isAuthorized: observableOf(true)
|
isAuthorized: observableOf(true)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const linkHeadService = jasmine.createSpyObj('linkHeadService', {
|
||||||
|
addTag: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const groupDataService = jasmine.createSpyObj('groupsDataService', {
|
||||||
|
findAllByHref: createSuccessfulRemoteDataObject$(createPaginatedList([])),
|
||||||
|
getGroupRegistryRouterLink: '',
|
||||||
|
getUUIDFromString: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const configurationDataService = jasmine.createSpyObj('configurationDataService', {
|
||||||
|
findByPropertyName: createSuccessfulRemoteDataObject$(Object.assign(new ConfigurationProperty(), {
|
||||||
|
name: 'test',
|
||||||
|
values: [
|
||||||
|
'org.dspace.ctask.general.ProfileFormats = test'
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [CommonModule, FormsModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
|
imports: [CommonModule, FormsModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
|
||||||
@@ -159,7 +182,10 @@ describe('CollectionItemMapperComponent', () => {
|
|||||||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) },
|
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) },
|
||||||
{ provide: ObjectSelectService, useValue: new ObjectSelectServiceStub() },
|
{ provide: ObjectSelectService, useValue: new ObjectSelectServiceStub() },
|
||||||
{ provide: RouteService, useValue: routeServiceStub },
|
{ provide: RouteService, useValue: routeServiceStub },
|
||||||
{ provide: AuthorizationDataService, useValue: authorizationDataService }
|
{ provide: AuthorizationDataService, useValue: authorizationDataService },
|
||||||
|
{ provide: GroupDataService, useValue: groupDataService },
|
||||||
|
{ provide: LinkHeadService, useValue: linkHeadService },
|
||||||
|
{ provide: ConfigurationDataService, useValue: configurationDataService },
|
||||||
]
|
]
|
||||||
}).overrideComponent(CollectionItemMapperComponent, {
|
}).overrideComponent(CollectionItemMapperComponent, {
|
||||||
set: {
|
set: {
|
||||||
|
@@ -13,7 +13,6 @@
|
|||||||
<!-- Collection logo -->
|
<!-- Collection logo -->
|
||||||
<ds-comcol-page-logo *ngIf="logoRD$"
|
<ds-comcol-page-logo *ngIf="logoRD$"
|
||||||
[logo]="(logoRD$ | async)?.payload"
|
[logo]="(logoRD$ | async)?.payload"
|
||||||
[alternateText]="'Collection Logo'"
|
|
||||||
[alternateText]="'Collection Logo'">
|
[alternateText]="'Collection Logo'">
|
||||||
</ds-comcol-page-logo>
|
</ds-comcol-page-logo>
|
||||||
|
|
||||||
|
@@ -6,7 +6,7 @@ import { CollectionPageComponent } from './collection-page.component';
|
|||||||
* Themed wrapper for CollectionPageComponent
|
* Themed wrapper for CollectionPageComponent
|
||||||
*/
|
*/
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-themed-community-page',
|
selector: 'ds-themed-collection-page',
|
||||||
styleUrls: [],
|
styleUrls: [],
|
||||||
templateUrl: '../shared/theme-support/themed.component.html',
|
templateUrl: '../shared/theme-support/themed.component.html',
|
||||||
})
|
})
|
||||||
|
@@ -25,6 +25,14 @@ import { getMockThemeService } from '../../shared/mocks/theme-service.mock';
|
|||||||
import { ThemeService } from '../../shared/theme-support/theme.service';
|
import { ThemeService } from '../../shared/theme-support/theme.service';
|
||||||
import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub';
|
import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub';
|
||||||
import { FindListOptions } from '../../core/data/find-list-options.model';
|
import { FindListOptions } from '../../core/data/find-list-options.model';
|
||||||
|
import { GroupDataService } from '../../core/eperson/group-data.service';
|
||||||
|
import { LinkHeadService } from '../../core/services/link-head.service';
|
||||||
|
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
|
||||||
|
import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service';
|
||||||
|
import { SearchServiceStub } from '../../shared/testing/search-service.stub';
|
||||||
|
import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
|
||||||
|
import { createPaginatedList } from '../../shared/testing/utils.test';
|
||||||
|
import { SearchConfigurationServiceStub } from '../../shared/testing/search-configuration-service.stub';
|
||||||
|
|
||||||
describe('CommunityPageSubCollectionList Component', () => {
|
describe('CommunityPageSubCollectionList Component', () => {
|
||||||
let comp: CommunityPageSubCollectionListComponent;
|
let comp: CommunityPageSubCollectionListComponent;
|
||||||
@@ -122,6 +130,25 @@ describe('CommunityPageSubCollectionList Component', () => {
|
|||||||
|
|
||||||
themeService = getMockThemeService();
|
themeService = getMockThemeService();
|
||||||
|
|
||||||
|
const linkHeadService = jasmine.createSpyObj('linkHeadService', {
|
||||||
|
addTag: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const groupDataService = jasmine.createSpyObj('groupsDataService', {
|
||||||
|
findAllByHref: createSuccessfulRemoteDataObject$(createPaginatedList([])),
|
||||||
|
getGroupRegistryRouterLink: '',
|
||||||
|
getUUIDFromString: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const configurationDataService = jasmine.createSpyObj('configurationDataService', {
|
||||||
|
findByPropertyName: createSuccessfulRemoteDataObject$(Object.assign(new ConfigurationProperty(), {
|
||||||
|
name: 'test',
|
||||||
|
values: [
|
||||||
|
'org.dspace.ctask.general.ProfileFormats = test'
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -138,6 +165,10 @@ describe('CommunityPageSubCollectionList Component', () => {
|
|||||||
{ provide: PaginationService, useValue: paginationService },
|
{ provide: PaginationService, useValue: paginationService },
|
||||||
{ provide: SelectableListService, useValue: {} },
|
{ provide: SelectableListService, useValue: {} },
|
||||||
{ provide: ThemeService, useValue: themeService },
|
{ provide: ThemeService, useValue: themeService },
|
||||||
|
{ provide: GroupDataService, useValue: groupDataService },
|
||||||
|
{ provide: LinkHeadService, useValue: linkHeadService },
|
||||||
|
{ provide: ConfigurationDataService, useValue: configurationDataService },
|
||||||
|
{ provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() },
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
@@ -25,6 +25,13 @@ import { getMockThemeService } from '../../shared/mocks/theme-service.mock';
|
|||||||
import { ThemeService } from '../../shared/theme-support/theme.service';
|
import { ThemeService } from '../../shared/theme-support/theme.service';
|
||||||
import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub';
|
import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub';
|
||||||
import { FindListOptions } from '../../core/data/find-list-options.model';
|
import { FindListOptions } from '../../core/data/find-list-options.model';
|
||||||
|
import { GroupDataService } from '../../core/eperson/group-data.service';
|
||||||
|
import { LinkHeadService } from '../../core/services/link-head.service';
|
||||||
|
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
|
||||||
|
import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service';
|
||||||
|
import { SearchConfigurationServiceStub } from '../../shared/testing/search-configuration-service.stub';
|
||||||
|
import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
|
||||||
|
import { createPaginatedList } from '../../shared/testing/utils.test';
|
||||||
|
|
||||||
describe('CommunityPageSubCommunityListComponent Component', () => {
|
describe('CommunityPageSubCommunityListComponent Component', () => {
|
||||||
let comp: CommunityPageSubCommunityListComponent;
|
let comp: CommunityPageSubCommunityListComponent;
|
||||||
@@ -119,6 +126,25 @@ describe('CommunityPageSubCommunityListComponent Component', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const linkHeadService = jasmine.createSpyObj('linkHeadService', {
|
||||||
|
addTag: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const groupDataService = jasmine.createSpyObj('groupsDataService', {
|
||||||
|
findAllByHref: createSuccessfulRemoteDataObject$(createPaginatedList([])),
|
||||||
|
getGroupRegistryRouterLink: '',
|
||||||
|
getUUIDFromString: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const configurationDataService = jasmine.createSpyObj('configurationDataService', {
|
||||||
|
findByPropertyName: createSuccessfulRemoteDataObject$(Object.assign(new ConfigurationProperty(), {
|
||||||
|
name: 'test',
|
||||||
|
values: [
|
||||||
|
'org.dspace.ctask.general.ProfileFormats = test'
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
|
||||||
const paginationService = new PaginationServiceStub();
|
const paginationService = new PaginationServiceStub();
|
||||||
|
|
||||||
themeService = getMockThemeService();
|
themeService = getMockThemeService();
|
||||||
@@ -139,6 +165,10 @@ describe('CommunityPageSubCommunityListComponent Component', () => {
|
|||||||
{ provide: PaginationService, useValue: paginationService },
|
{ provide: PaginationService, useValue: paginationService },
|
||||||
{ provide: SelectableListService, useValue: {} },
|
{ provide: SelectableListService, useValue: {} },
|
||||||
{ provide: ThemeService, useValue: themeService },
|
{ provide: ThemeService, useValue: themeService },
|
||||||
|
{ provide: GroupDataService, useValue: groupDataService },
|
||||||
|
{ provide: LinkHeadService, useValue: linkHeadService },
|
||||||
|
{ provide: ConfigurationDataService, useValue: configurationDataService },
|
||||||
|
{ provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() },
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
31
src/app/core/breadcrumbs/bitstream-breadcrumb.resolver.ts
Normal file
31
src/app/core/breadcrumbs/bitstream-breadcrumb.resolver.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
||||||
|
import { Bitstream } from '../shared/bitstream.model';
|
||||||
|
import { BitstreamDataService } from '../data/bitstream-data.service';
|
||||||
|
import { BITSTREAM_PAGE_LINKS_TO_FOLLOW } from '../../bitstream-page/bitstream-page.resolver';
|
||||||
|
import { DSOBreadcrumbResolver } from './dso-breadcrumb.resolver';
|
||||||
|
import { BitstreamBreadcrumbsService } from './bitstream-breadcrumbs.service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The class that resolves the BreadcrumbConfig object for an Item
|
||||||
|
*/
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class BitstreamBreadcrumbResolver extends DSOBreadcrumbResolver<Bitstream> {
|
||||||
|
constructor(
|
||||||
|
protected breadcrumbService: BitstreamBreadcrumbsService, protected dataService: BitstreamDataService) {
|
||||||
|
super(breadcrumbService, dataService);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that returns the follow links to already resolve
|
||||||
|
* The self links defined in this list are expected to be requested somewhere in the near future
|
||||||
|
* Requesting them as embeds will limit the number of requests
|
||||||
|
*/
|
||||||
|
get followLinks(): FollowLinkConfig<Bitstream>[] {
|
||||||
|
return BITSTREAM_PAGE_LINKS_TO_FOLLOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
85
src/app/core/breadcrumbs/bitstream-breadcrumbs.service.ts
Normal file
85
src/app/core/breadcrumbs/bitstream-breadcrumbs.service.ts
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
import { Observable, of as observableOf } from 'rxjs';
|
||||||
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
|
|
||||||
|
import { Breadcrumb } from '../../breadcrumbs/breadcrumb/breadcrumb.model';
|
||||||
|
import { DSONameService } from './dso-name.service';
|
||||||
|
import { ChildHALResource } from '../shared/child-hal-resource.model';
|
||||||
|
import { LinkService } from '../cache/builders/link.service';
|
||||||
|
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||||
|
import { RemoteData } from '../data/remote-data';
|
||||||
|
import { hasValue, isNotEmpty } from '../../shared/empty.util';
|
||||||
|
import { getDSORoute } from '../../app-routing-paths';
|
||||||
|
import { DSOBreadcrumbsService } from './dso-breadcrumbs.service';
|
||||||
|
import { BitstreamDataService } from '../data/bitstream-data.service';
|
||||||
|
import { getFirstCompletedRemoteData, getRemoteDataPayload } from '../shared/operators';
|
||||||
|
import { Bitstream } from '../shared/bitstream.model';
|
||||||
|
import { Bundle } from '../shared/bundle.model';
|
||||||
|
import { Item } from '../shared/item.model';
|
||||||
|
import { BITSTREAM_PAGE_LINKS_TO_FOLLOW } from '../../bitstream-page/bitstream-page.resolver';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service to calculate DSpaceObject breadcrumbs for a single part of the route
|
||||||
|
*/
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class BitstreamBreadcrumbsService extends DSOBreadcrumbsService {
|
||||||
|
constructor(
|
||||||
|
protected bitstreamService: BitstreamDataService,
|
||||||
|
protected linkService: LinkService,
|
||||||
|
protected dsoNameService: DSONameService
|
||||||
|
) {
|
||||||
|
super(linkService, dsoNameService);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to recursively calculate the breadcrumbs
|
||||||
|
* This method returns the name and url of the key and all its parent DSOs recursively, top down
|
||||||
|
* @param key The key (a DSpaceObject) used to resolve the breadcrumb
|
||||||
|
* @param url The url to use as a link for this breadcrumb
|
||||||
|
*/
|
||||||
|
getBreadcrumbs(key: ChildHALResource & DSpaceObject, url: string): Observable<Breadcrumb[]> {
|
||||||
|
const label = this.dsoNameService.getName(key);
|
||||||
|
const crumb = new Breadcrumb(label, url);
|
||||||
|
|
||||||
|
return this.getOwningItem(key.uuid).pipe(
|
||||||
|
switchMap((parentRD: RemoteData<ChildHALResource & DSpaceObject>) => {
|
||||||
|
if (isNotEmpty(parentRD) && hasValue(parentRD.payload)) {
|
||||||
|
const parent = parentRD.payload;
|
||||||
|
return super.getBreadcrumbs(parent, getDSORoute(parent));
|
||||||
|
}
|
||||||
|
return observableOf([]);
|
||||||
|
|
||||||
|
}),
|
||||||
|
map((breadcrumbs: Breadcrumb[]) => [...breadcrumbs, crumb])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getOwningItem(uuid: string): Observable<RemoteData<Item>> {
|
||||||
|
return this.bitstreamService.findById(uuid, true, true, ...BITSTREAM_PAGE_LINKS_TO_FOLLOW).pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
getRemoteDataPayload(),
|
||||||
|
switchMap((bitstream: Bitstream) => {
|
||||||
|
if (hasValue(bitstream)) {
|
||||||
|
return bitstream.bundle.pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
getRemoteDataPayload(),
|
||||||
|
switchMap((bundle: Bundle) => {
|
||||||
|
if (hasValue(bundle)) {
|
||||||
|
return bundle.item.pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return observableOf(undefined);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return observableOf(undefined);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@@ -20,8 +20,8 @@ import { getDSORoute } from '../../app-routing-paths';
|
|||||||
})
|
})
|
||||||
export class DSOBreadcrumbsService implements BreadcrumbsProviderService<ChildHALResource & DSpaceObject> {
|
export class DSOBreadcrumbsService implements BreadcrumbsProviderService<ChildHALResource & DSpaceObject> {
|
||||||
constructor(
|
constructor(
|
||||||
private linkService: LinkService,
|
protected linkService: LinkService,
|
||||||
private dsoNameService: DSONameService
|
protected dsoNameService: DSONameService
|
||||||
) {
|
) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -137,6 +137,7 @@ import { SiteAdministratorGuard } from './data/feature-authorization/feature-aut
|
|||||||
import { Registration } from './shared/registration.model';
|
import { Registration } from './shared/registration.model';
|
||||||
import { MetadataSchemaDataService } from './data/metadata-schema-data.service';
|
import { MetadataSchemaDataService } from './data/metadata-schema-data.service';
|
||||||
import { MetadataFieldDataService } from './data/metadata-field-data.service';
|
import { MetadataFieldDataService } from './data/metadata-field-data.service';
|
||||||
|
import { DsDynamicTypeBindRelationService } from '../shared/form/builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service';
|
||||||
import { TokenResponseParsingService } from './auth/token-response-parsing.service';
|
import { TokenResponseParsingService } from './auth/token-response-parsing.service';
|
||||||
import { SubmissionCcLicenseDataService } from './submission/submission-cc-license-data.service';
|
import { SubmissionCcLicenseDataService } from './submission/submission-cc-license-data.service';
|
||||||
import { SubmissionCcLicence } from './submission/models/submission-cc-license.model';
|
import { SubmissionCcLicence } from './submission/models/submission-cc-license.model';
|
||||||
@@ -166,6 +167,9 @@ import { SubmissionAccessesModel } from './config/models/config-submission-acces
|
|||||||
import { ResearcherProfileService } from './profile/researcher-profile.service';
|
import { ResearcherProfileService } from './profile/researcher-profile.service';
|
||||||
import { ProfileClaimService } from '../profile-page/profile-claim/profile-claim.service';
|
import { ProfileClaimService } from '../profile-page/profile-claim/profile-claim.service';
|
||||||
import { ResearcherProfile } from './profile/model/researcher-profile.model';
|
import { ResearcherProfile } from './profile/model/researcher-profile.model';
|
||||||
|
import { AccessStatusObject } from '../shared/object-list/access-status-badge/access-status.model';
|
||||||
|
import { AccessStatusDataService } from './data/access-status-data.service';
|
||||||
|
import { LinkHeadService } from './services/link-head.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When not in production, endpoint responses can be mocked for testing purposes
|
* When not in production, endpoint responses can be mocked for testing purposes
|
||||||
@@ -205,6 +209,7 @@ const PROVIDERS = [
|
|||||||
SectionFormOperationsService,
|
SectionFormOperationsService,
|
||||||
FormService,
|
FormService,
|
||||||
EPersonDataService,
|
EPersonDataService,
|
||||||
|
LinkHeadService,
|
||||||
HALEndpointService,
|
HALEndpointService,
|
||||||
HostWindowService,
|
HostWindowService,
|
||||||
ItemDataService,
|
ItemDataService,
|
||||||
@@ -223,6 +228,7 @@ const PROVIDERS = [
|
|||||||
MyDSpaceResponseParsingService,
|
MyDSpaceResponseParsingService,
|
||||||
ServerResponseService,
|
ServerResponseService,
|
||||||
BrowseService,
|
BrowseService,
|
||||||
|
AccessStatusDataService,
|
||||||
SubmissionCcLicenseDataService,
|
SubmissionCcLicenseDataService,
|
||||||
SubmissionCcLicenseUrlDataService,
|
SubmissionCcLicenseUrlDataService,
|
||||||
SubmissionFormsConfigService,
|
SubmissionFormsConfigService,
|
||||||
@@ -253,6 +259,7 @@ const PROVIDERS = [
|
|||||||
ClaimedTaskDataService,
|
ClaimedTaskDataService,
|
||||||
PoolTaskDataService,
|
PoolTaskDataService,
|
||||||
BitstreamDataService,
|
BitstreamDataService,
|
||||||
|
DsDynamicTypeBindRelationService,
|
||||||
EntityTypeService,
|
EntityTypeService,
|
||||||
ContentSourceResponseParsingService,
|
ContentSourceResponseParsingService,
|
||||||
ItemTemplateDataService,
|
ItemTemplateDataService,
|
||||||
@@ -352,7 +359,8 @@ export const models =
|
|||||||
Root,
|
Root,
|
||||||
SearchConfig,
|
SearchConfig,
|
||||||
SubmissionAccessesModel,
|
SubmissionAccessesModel,
|
||||||
ResearcherProfile
|
ResearcherProfile,
|
||||||
|
AccessStatusObject
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
81
src/app/core/data/access-status-data.service.spec.ts
Normal file
81
src/app/core/data/access-status-data.service.spec.ts
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import { RequestService } from './request.service';
|
||||||
|
import { getMockRequestService } from '../../shared/mocks/request.service.mock';
|
||||||
|
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub';
|
||||||
|
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
||||||
|
import { fakeAsync, tick } from '@angular/core/testing';
|
||||||
|
import { GetRequest } from './request.models';
|
||||||
|
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||||
|
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||||
|
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { RemoteData } from './remote-data';
|
||||||
|
import { hasNoValue } from '../../shared/empty.util';
|
||||||
|
import { AccessStatusDataService } from './access-status-data.service';
|
||||||
|
import { Item } from '../shared/item.model';
|
||||||
|
|
||||||
|
const url = 'fake-url';
|
||||||
|
|
||||||
|
describe('AccessStatusDataService', () => {
|
||||||
|
let service: AccessStatusDataService;
|
||||||
|
let requestService: RequestService;
|
||||||
|
let notificationsService: any;
|
||||||
|
let rdbService: RemoteDataBuildService;
|
||||||
|
let objectCache: ObjectCacheService;
|
||||||
|
let halService: any;
|
||||||
|
|
||||||
|
const itemId = '8b3c613a-5a4b-438b-9686-be1d5b4a1c5a';
|
||||||
|
const mockItem: Item = Object.assign(new Item(), {
|
||||||
|
id: itemId,
|
||||||
|
name: 'test-item',
|
||||||
|
_links: {
|
||||||
|
accessStatus: {
|
||||||
|
href: `https://rest.api/items/${itemId}/accessStatus`
|
||||||
|
},
|
||||||
|
self: {
|
||||||
|
href: `https://rest.api/items/${itemId}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the requests are successful', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
createService();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when calling findAccessStatusFor', () => {
|
||||||
|
let contentSource$;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
contentSource$ = service.findAccessStatusFor(mockItem);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should send a new GetRequest', fakeAsync(() => {
|
||||||
|
contentSource$.subscribe();
|
||||||
|
tick();
|
||||||
|
expect(requestService.send).toHaveBeenCalledWith(jasmine.any(GetRequest), true);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an AccessStatusDataService used for testing
|
||||||
|
* @param reponse$ Supply a RemoteData to be returned by the REST API (optional)
|
||||||
|
*/
|
||||||
|
function createService(reponse$?: Observable<RemoteData<any>>) {
|
||||||
|
requestService = getMockRequestService();
|
||||||
|
let buildResponse$ = reponse$;
|
||||||
|
if (hasNoValue(reponse$)) {
|
||||||
|
buildResponse$ = createSuccessfulRemoteDataObject$({});
|
||||||
|
}
|
||||||
|
rdbService = jasmine.createSpyObj('rdbService', {
|
||||||
|
buildFromRequestUUID: buildResponse$,
|
||||||
|
buildSingle: buildResponse$
|
||||||
|
});
|
||||||
|
objectCache = jasmine.createSpyObj('objectCache', {
|
||||||
|
remove: jasmine.createSpy('remove')
|
||||||
|
});
|
||||||
|
halService = new HALEndpointServiceStub(url);
|
||||||
|
notificationsService = new NotificationsServiceStub();
|
||||||
|
service = new AccessStatusDataService(null, halService, null, notificationsService, objectCache, rdbService, requestService, null);
|
||||||
|
}
|
||||||
|
});
|
45
src/app/core/data/access-status-data.service.ts
Normal file
45
src/app/core/data/access-status-data.service.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Store } from '@ngrx/store';
|
||||||
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
|
import { dataService } from '../cache/builders/build-decorators';
|
||||||
|
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||||
|
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||||
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
|
import { DataService } from './data.service';
|
||||||
|
import { RequestService } from './request.service';
|
||||||
|
import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
|
||||||
|
import { CoreState } from '../core-state.model';
|
||||||
|
import { AccessStatusObject } from 'src/app/shared/object-list/access-status-badge/access-status.model';
|
||||||
|
import { ACCESS_STATUS } from 'src/app/shared/object-list/access-status-badge/access-status.resource-type';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { RemoteData } from './remote-data';
|
||||||
|
import { Item } from '../shared/item.model';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
@dataService(ACCESS_STATUS)
|
||||||
|
export class AccessStatusDataService extends DataService<AccessStatusObject> {
|
||||||
|
|
||||||
|
protected linkPath = 'accessStatus';
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
protected comparator: DefaultChangeAnalyzer<AccessStatusObject>,
|
||||||
|
protected halService: HALEndpointService,
|
||||||
|
protected http: HttpClient,
|
||||||
|
protected notificationsService: NotificationsService,
|
||||||
|
protected objectCache: ObjectCacheService,
|
||||||
|
protected rdbService: RemoteDataBuildService,
|
||||||
|
protected requestService: RequestService,
|
||||||
|
protected store: Store<CoreState>,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@link RemoteData} of {@link AccessStatusObject} that is the access status of the given item
|
||||||
|
* @param item Item we want the access status of
|
||||||
|
*/
|
||||||
|
findAccessStatusFor(item: Item): Observable<RemoteData<AccessStatusObject>> {
|
||||||
|
return this.findByHref(item._links.accessStatus.href);
|
||||||
|
}
|
||||||
|
}
|
@@ -10,12 +10,13 @@ import { ObjectCacheService } from '../cache/object-cache.service';
|
|||||||
import { RestResponse } from '../cache/response.models';
|
import { RestResponse } from '../cache/response.models';
|
||||||
import { ExternalSourceEntry } from '../shared/external-source-entry.model';
|
import { ExternalSourceEntry } from '../shared/external-source-entry.model';
|
||||||
import { ItemDataService } from './item-data.service';
|
import { ItemDataService } from './item-data.service';
|
||||||
import { DeleteRequest, PostRequest } from './request.models';
|
import { DeleteRequest, GetRequest, PostRequest } from './request.models';
|
||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
import { getMockRemoteDataBuildService } from '../../shared/mocks/remote-data-build.service.mock';
|
import { getMockRemoteDataBuildService } from '../../shared/mocks/remote-data-build.service.mock';
|
||||||
import { CoreState } from '../core-state.model';
|
import { CoreState } from '../core-state.model';
|
||||||
import { RequestEntry } from './request-entry.model';
|
import { RequestEntry } from './request-entry.model';
|
||||||
import { FindListOptions } from './find-list-options.model';
|
import { FindListOptions } from './find-list-options.model';
|
||||||
|
import { HALEndpointServiceStub } from 'src/app/shared/testing/hal-endpoint-service.stub';
|
||||||
|
|
||||||
describe('ItemDataService', () => {
|
describe('ItemDataService', () => {
|
||||||
let scheduler: TestScheduler;
|
let scheduler: TestScheduler;
|
||||||
@@ -36,13 +37,11 @@ describe('ItemDataService', () => {
|
|||||||
}) as RequestService;
|
}) as RequestService;
|
||||||
const rdbService = getMockRemoteDataBuildService();
|
const rdbService = getMockRemoteDataBuildService();
|
||||||
|
|
||||||
const itemEndpoint = 'https://rest.api/core/items';
|
const itemEndpoint = 'https://rest.api/core';
|
||||||
|
|
||||||
const store = {} as Store<CoreState>;
|
const store = {} as Store<CoreState>;
|
||||||
const objectCache = {} as ObjectCacheService;
|
const objectCache = {} as ObjectCacheService;
|
||||||
const halEndpointService = jasmine.createSpyObj('halService', {
|
const halEndpointService: any = new HALEndpointServiceStub(itemEndpoint);
|
||||||
getEndpoint: observableOf(itemEndpoint)
|
|
||||||
});
|
|
||||||
const bundleService = jasmine.createSpyObj('bundleService', {
|
const bundleService = jasmine.createSpyObj('bundleService', {
|
||||||
findByHref: {}
|
findByHref: {}
|
||||||
});
|
});
|
||||||
|
@@ -151,7 +151,7 @@ describe('VersionHistoryDataService', () => {
|
|||||||
describe('when getVersionsEndpoint is called', () => {
|
describe('when getVersionsEndpoint is called', () => {
|
||||||
it('should return the correct value', () => {
|
it('should return the correct value', () => {
|
||||||
service.getVersionsEndpoint(versionHistoryId).subscribe((res) => {
|
service.getVersionsEndpoint(versionHistoryId).subscribe((res) => {
|
||||||
expect(res).toBe(url + '/versions');
|
expect(res).toBe(url + '/versionhistories/version-history-id/versions');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -163,6 +163,22 @@ describe('MetadataService', () => {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('route titles should overwrite dso titles', fakeAsync(() => {
|
||||||
|
(translateService.get as jasmine.Spy).and.returnValues(of('DSpace :: '), of('Translated Route Title'));
|
||||||
|
(metadataService as any).processRouteChange({
|
||||||
|
data: {
|
||||||
|
value: {
|
||||||
|
dso: createSuccessfulRemoteDataObject(ItemMock),
|
||||||
|
title: 'route.title.key',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tick();
|
||||||
|
expect(title.setTitle).toHaveBeenCalledTimes(2);
|
||||||
|
expect((title.setTitle as jasmine.Spy).calls.argsFor(0)).toEqual(['Test PowerPoint Document']);
|
||||||
|
expect((title.setTitle as jasmine.Spy).calls.argsFor(1)).toEqual(['DSpace :: Translated Route Title']);
|
||||||
|
}));
|
||||||
|
|
||||||
it('other navigation should add title and description', fakeAsync(() => {
|
it('other navigation should add title and description', fakeAsync(() => {
|
||||||
(translateService.get as jasmine.Spy).and.returnValues(of('DSpace :: '), of('Dummy Title'), of('This is a dummy item component for testing!'));
|
(translateService.get as jasmine.Spy).and.returnValues(of('DSpace :: '), of('Dummy Title'), of('This is a dummy item component for testing!'));
|
||||||
(metadataService as any).processRouteChange({
|
(metadataService as any).processRouteChange({
|
||||||
|
@@ -109,6 +109,11 @@ export class MetadataService {
|
|||||||
private processRouteChange(routeInfo: any): void {
|
private processRouteChange(routeInfo: any): void {
|
||||||
this.clearMetaTags();
|
this.clearMetaTags();
|
||||||
|
|
||||||
|
if (hasValue(routeInfo.data.value.dso) && hasValue(routeInfo.data.value.dso.payload)) {
|
||||||
|
this.currentObject.next(routeInfo.data.value.dso.payload);
|
||||||
|
this.setDSOMetaTags();
|
||||||
|
}
|
||||||
|
|
||||||
if (routeInfo.data.value.title) {
|
if (routeInfo.data.value.title) {
|
||||||
const titlePrefix = this.translate.get('repository.title.prefix');
|
const titlePrefix = this.translate.get('repository.title.prefix');
|
||||||
const title = this.translate.get(routeInfo.data.value.title, routeInfo.data.value);
|
const title = this.translate.get(routeInfo.data.value.title, routeInfo.data.value);
|
||||||
@@ -122,11 +127,6 @@ export class MetadataService {
|
|||||||
this.addMetaTag('description', translatedDescription);
|
this.addMetaTag('description', translatedDescription);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasValue(routeInfo.data.value.dso) && hasValue(routeInfo.data.value.dso.payload)) {
|
|
||||||
this.currentObject.next(routeInfo.data.value.dso.payload);
|
|
||||||
this.setDSOMetaTags();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getCurrentRoute(route: ActivatedRoute): ActivatedRoute {
|
private getCurrentRoute(route: ActivatedRoute): ActivatedRoute {
|
||||||
|
@@ -7,8 +7,8 @@ import { filter, map, take } from 'rxjs/operators';
|
|||||||
import { SortDirection, SortOptions } from '../cache/models/sort-options.model';
|
import { SortDirection, SortOptions } from '../cache/models/sort-options.model';
|
||||||
import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util';
|
import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util';
|
||||||
import { difference } from '../../shared/object.util';
|
import { difference } from '../../shared/object.util';
|
||||||
import { isNumeric } from 'rxjs/internal-compatibility';
|
|
||||||
import { FindListOptions } from '../data/find-list-options.model';
|
import { FindListOptions } from '../data/find-list-options.model';
|
||||||
|
import { isNumeric } from '../../shared/numeric.util';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
|
45
src/app/core/services/link-head.service.spec.ts
Normal file
45
src/app/core/services/link-head.service.spec.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { DOCUMENT } from '@angular/common';
|
||||||
|
import { Renderer2, RendererFactory2 } from '@angular/core';
|
||||||
|
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
|
import { MockProvider } from 'ng-mocks';
|
||||||
|
import { LinkHeadService } from './link-head.service';
|
||||||
|
|
||||||
|
describe('LinkHeadService', () => {
|
||||||
|
|
||||||
|
let service: LinkHeadService;
|
||||||
|
|
||||||
|
const renderer2: Renderer2 = {
|
||||||
|
createRenderer: jasmine.createSpy('createRenderer'),
|
||||||
|
createElement: jasmine.createSpy('createElement'),
|
||||||
|
setAttribute: jasmine.createSpy('setAttribute'),
|
||||||
|
appendChild: jasmine.createSpy('appendChild')
|
||||||
|
} as unknown as Renderer2;
|
||||||
|
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
return TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
MockProvider(RendererFactory2, {
|
||||||
|
createRenderer: () => renderer2
|
||||||
|
}),
|
||||||
|
{ provide: Document, useExisting: DOCUMENT },
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
service = new LinkHeadService(TestBed.inject(RendererFactory2), TestBed.inject(DOCUMENT));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('link', () => {
|
||||||
|
it('should create a link tag', () => {
|
||||||
|
const link = service.addTag({
|
||||||
|
href: 'test',
|
||||||
|
type: 'application/atom+xml',
|
||||||
|
rel: 'alternate',
|
||||||
|
title: 'Sitewide Atom feed'
|
||||||
|
});
|
||||||
|
expect(link).not.toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
90
src/app/core/services/link-head.service.ts
Normal file
90
src/app/core/services/link-head.service.ts
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
import { Injectable, RendererFactory2, ViewEncapsulation, Inject } from '@angular/core';
|
||||||
|
import { DOCUMENT } from '@angular/common';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LinkHead Service injects <link> tag into the head element during runtime.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class LinkHeadService {
|
||||||
|
constructor(
|
||||||
|
private rendererFactory: RendererFactory2,
|
||||||
|
@Inject(DOCUMENT) private document
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to create a Link tag in the HEAD of the html.
|
||||||
|
* @param tag LinkDefition is the paramaters to define a link tag.
|
||||||
|
* @returns Link tag that was created
|
||||||
|
*/
|
||||||
|
addTag(tag: LinkDefinition) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
const renderer = this.rendererFactory.createRenderer(this.document, {
|
||||||
|
id: '-1',
|
||||||
|
encapsulation: ViewEncapsulation.None,
|
||||||
|
styles: [],
|
||||||
|
data: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const link = renderer.createElement('link');
|
||||||
|
const head = this.document.head;
|
||||||
|
|
||||||
|
if (head === null) {
|
||||||
|
throw new Error('<head> not found within DOCUMENT.');
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.keys(tag).forEach((prop: string) => {
|
||||||
|
return renderer.setAttribute(link, prop, tag[prop]);
|
||||||
|
});
|
||||||
|
|
||||||
|
renderer.appendChild(head, link);
|
||||||
|
return renderer;
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error within linkService : ', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a link tag in header based on the given attrSelector.
|
||||||
|
* @param attrSelector The attr assigned to a link tag which will be used to determine what link to remove.
|
||||||
|
*/
|
||||||
|
removeTag(attrSelector: string) {
|
||||||
|
if (attrSelector) {
|
||||||
|
try {
|
||||||
|
const renderer = this.rendererFactory.createRenderer(this.document, {
|
||||||
|
id: '-1',
|
||||||
|
encapsulation: ViewEncapsulation.None,
|
||||||
|
styles: [],
|
||||||
|
data: {}
|
||||||
|
});
|
||||||
|
const head = this.document.head;
|
||||||
|
if (head === null) {
|
||||||
|
throw new Error('<head> not found within DOCUMENT.');
|
||||||
|
}
|
||||||
|
const linkTags = this.document.querySelectorAll('link[' + attrSelector + ']');
|
||||||
|
for (const link of linkTags) {
|
||||||
|
renderer.removeChild(head, link);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Error while removing tag ' + e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export declare type LinkDefinition = {
|
||||||
|
charset?: string;
|
||||||
|
crossorigin?: string;
|
||||||
|
href?: string;
|
||||||
|
hreflang?: string;
|
||||||
|
media?: string;
|
||||||
|
rel?: string;
|
||||||
|
rev?: string;
|
||||||
|
sizes?: string;
|
||||||
|
target?: string;
|
||||||
|
type?: string;
|
||||||
|
} & {
|
||||||
|
[prop: string]: string;
|
||||||
|
};
|
@@ -7,13 +7,13 @@ import { BITSTREAM_FORMAT } from './bitstream-format.resource-type';
|
|||||||
import { BITSTREAM } from './bitstream.resource-type';
|
import { BITSTREAM } from './bitstream.resource-type';
|
||||||
import { DSpaceObject } from './dspace-object.model';
|
import { DSpaceObject } from './dspace-object.model';
|
||||||
import { HALLink } from './hal-link.model';
|
import { HALLink } from './hal-link.model';
|
||||||
import { HALResource } from './hal-resource.model';
|
|
||||||
import {BUNDLE} from './bundle.resource-type';
|
import {BUNDLE} from './bundle.resource-type';
|
||||||
import {Bundle} from './bundle.model';
|
import {Bundle} from './bundle.model';
|
||||||
|
import { ChildHALResource } from './child-hal-resource.model';
|
||||||
|
|
||||||
@typedObject
|
@typedObject
|
||||||
@inheritSerialization(DSpaceObject)
|
@inheritSerialization(DSpaceObject)
|
||||||
export class Bitstream extends DSpaceObject implements HALResource {
|
export class Bitstream extends DSpaceObject implements ChildHALResource {
|
||||||
static type = BITSTREAM;
|
static type = BITSTREAM;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,4 +66,8 @@ export class Bitstream extends DSpaceObject implements HALResource {
|
|||||||
*/
|
*/
|
||||||
@link(BUNDLE)
|
@link(BUNDLE)
|
||||||
bundle?: Observable<RemoteData<Bundle>>;
|
bundle?: Observable<RemoteData<Bundle>>;
|
||||||
|
|
||||||
|
getParentLinkKey(): keyof this['_links'] {
|
||||||
|
return 'format';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,7 @@ import { getMockRequestService } from '../../shared/mocks/request.service.mock';
|
|||||||
import { RequestService } from '../data/request.service';
|
import { RequestService } from '../data/request.service';
|
||||||
import { HALEndpointService } from './hal-endpoint.service';
|
import { HALEndpointService } from './hal-endpoint.service';
|
||||||
import { EndpointMapRequest } from '../data/request.models';
|
import { EndpointMapRequest } from '../data/request.models';
|
||||||
import { combineLatest as observableCombineLatest, of as observableOf } from 'rxjs';
|
import { combineLatest as observableCombineLatest, Observable, of as observableOf } from 'rxjs';
|
||||||
import { environment } from '../../../environments/environment';
|
import { environment } from '../../../environments/environment';
|
||||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||||
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||||
@@ -162,9 +162,9 @@ describe('HALEndpointService', () => {
|
|||||||
return observableOf(endpointMaps[param]);
|
return observableOf(endpointMaps[param]);
|
||||||
});
|
});
|
||||||
|
|
||||||
observableCombineLatest([
|
observableCombineLatest<string[]>([
|
||||||
(service as any).getEndpointAt(start, 'one'),
|
(service as any).getEndpointAt(start, 'one'),
|
||||||
(service as any).getEndpointAt(start, 'one', 'two')
|
(service as any).getEndpointAt(start, 'one', 'two'),
|
||||||
]).subscribe(([endpoint1, endpoint2]) => {
|
]).subscribe(([endpoint1, endpoint2]) => {
|
||||||
expect(endpoint1).toEqual(one);
|
expect(endpoint1).toEqual(one);
|
||||||
expect(endpoint2).toEqual(two);
|
expect(endpoint2).toEqual(two);
|
||||||
|
@@ -21,6 +21,8 @@ import { Version } from './version.model';
|
|||||||
import { VERSION } from './version.resource-type';
|
import { VERSION } from './version.resource-type';
|
||||||
import { BITSTREAM } from './bitstream.resource-type';
|
import { BITSTREAM } from './bitstream.resource-type';
|
||||||
import { Bitstream } from './bitstream.model';
|
import { Bitstream } from './bitstream.model';
|
||||||
|
import { ACCESS_STATUS } from 'src/app/shared/object-list/access-status-badge/access-status.resource-type';
|
||||||
|
import { AccessStatusObject } from 'src/app/shared/object-list/access-status-badge/access-status.model';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing a DSpace Item
|
* Class representing a DSpace Item
|
||||||
@@ -72,6 +74,7 @@ export class Item extends DSpaceObject implements ChildHALResource {
|
|||||||
templateItemOf: HALLink;
|
templateItemOf: HALLink;
|
||||||
version: HALLink;
|
version: HALLink;
|
||||||
thumbnail: HALLink;
|
thumbnail: HALLink;
|
||||||
|
accessStatus: HALLink;
|
||||||
self: HALLink;
|
self: HALLink;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -110,6 +113,13 @@ export class Item extends DSpaceObject implements ChildHALResource {
|
|||||||
@link(BITSTREAM, false, 'thumbnail')
|
@link(BITSTREAM, false, 'thumbnail')
|
||||||
thumbnail?: Observable<RemoteData<Bitstream>>;
|
thumbnail?: Observable<RemoteData<Bitstream>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The access status for this Item
|
||||||
|
* Will be undefined unless the access status {@link HALLink} has been resolved.
|
||||||
|
*/
|
||||||
|
@link(ACCESS_STATUS)
|
||||||
|
accessStatus?: Observable<RemoteData<AccessStatusObject>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method that returns as which type of object this object should be rendered
|
* Method that returns as which type of object this object should be rendered
|
||||||
*/
|
*/
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
|
import { combineLatest as observableCombineLatest, Observable, interval } from 'rxjs';
|
||||||
import { debounceTime, filter, find, map, switchMap, take, takeWhile } from 'rxjs/operators';
|
import { filter, find, map, switchMap, take, takeWhile, debounce, debounceTime } from 'rxjs/operators';
|
||||||
import { hasNoValue, hasValue, hasValueOperator, isNotEmpty } from '../../shared/empty.util';
|
import { hasNoValue, hasValue, hasValueOperator, isNotEmpty } from '../../shared/empty.util';
|
||||||
import { SearchResult } from '../../shared/search/models/search-result.model';
|
import { SearchResult } from '../../shared/search/models/search-result.model';
|
||||||
import { PaginatedList } from '../data/paginated-list.model';
|
import { PaginatedList } from '../data/paginated-list.model';
|
||||||
@@ -9,6 +9,17 @@ import { MetadataSchema } from '../metadata/metadata-schema.model';
|
|||||||
import { BrowseDefinition } from './browse-definition.model';
|
import { BrowseDefinition } from './browse-definition.model';
|
||||||
import { DSpaceObject } from './dspace-object.model';
|
import { DSpaceObject } from './dspace-object.model';
|
||||||
import { InjectionToken } from '@angular/core';
|
import { InjectionToken } from '@angular/core';
|
||||||
|
import { MonoTypeOperatorFunction, SchedulerLike } from 'rxjs/internal/types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this method instead of the RxJs debounceTime if you're waiting for debouncing in tests;
|
||||||
|
* debounceTime doesn't work with fakeAsync/tick anymore as of Angular 13.2.6 & RxJs 7.5.5
|
||||||
|
* Workaround suggested in https://github.com/angular/angular/issues/44351#issuecomment-1107454054
|
||||||
|
* todo: remove once the above issue is fixed
|
||||||
|
*/
|
||||||
|
export const debounceTimeWorkaround = <T>(dueTime: number, scheduler?: SchedulerLike): MonoTypeOperatorFunction<T> => {
|
||||||
|
return debounce(() => interval(dueTime, scheduler));
|
||||||
|
};
|
||||||
|
|
||||||
export const DEBOUNCE_TIME_OPERATOR = new InjectionToken<<T>(dueTime: number) => (source: Observable<T>) => Observable<T>>('debounceTime', {
|
export const DEBOUNCE_TIME_OPERATOR = new InjectionToken<<T>(dueTime: number) => (source: Observable<T>) => Observable<T>>('debounceTime', {
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
|
@@ -0,0 +1,43 @@
|
|||||||
|
import { DSpaceObject } from './../../shared/dspace-object.model';
|
||||||
|
import { followLink } from './../../../shared/utils/follow-link-config.model';
|
||||||
|
import { ChildHALResource } from './../../shared/child-hal-resource.model';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { Store } from '@ngrx/store';
|
||||||
|
import { switchMap } from 'rxjs/operators';
|
||||||
|
import { DataService } from '../../data/data.service';
|
||||||
|
import { RemoteData } from '../../data/remote-data';
|
||||||
|
import { getFirstCompletedRemoteData } from '../../shared/operators';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents a resolver that requests a specific item before the route is activated
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class SubmissionObjectResolver<T> implements Resolve<RemoteData<T>> {
|
||||||
|
constructor(
|
||||||
|
protected dataService: DataService<any>,
|
||||||
|
protected store: Store<any>
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for resolving an item based on the parameters in the current route
|
||||||
|
* @param {ActivatedRouteSnapshot} route The current ActivatedRouteSnapshot
|
||||||
|
* @param {RouterStateSnapshot} state The current RouterStateSnapshot
|
||||||
|
* @returns Observable<<RemoteData<Item>> Emits the found item based on the parameters in the current route,
|
||||||
|
* or an error if something went wrong
|
||||||
|
*/
|
||||||
|
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<T>> {
|
||||||
|
const itemRD$ = this.dataService.findById(route.params.id,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
followLink('item'),
|
||||||
|
).pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
switchMap((wfiRD: RemoteData<any>) => wfiRD.payload.item as Observable<RemoteData<T>>),
|
||||||
|
getFirstCompletedRemoteData()
|
||||||
|
);
|
||||||
|
return itemRD$;
|
||||||
|
}
|
||||||
|
}
|
@@ -25,6 +25,13 @@ import { getMockThemeService } from '../../shared/mocks/theme-service.mock';
|
|||||||
import { ThemeService } from '../../shared/theme-support/theme.service';
|
import { ThemeService } from '../../shared/theme-support/theme.service';
|
||||||
import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub';
|
import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub';
|
||||||
import { FindListOptions } from '../../core/data/find-list-options.model';
|
import { FindListOptions } from '../../core/data/find-list-options.model';
|
||||||
|
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
|
||||||
|
import { GroupDataService } from '../../core/eperson/group-data.service';
|
||||||
|
import { LinkHeadService } from '../../core/services/link-head.service';
|
||||||
|
import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service';
|
||||||
|
import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
|
||||||
|
import { createPaginatedList } from '../../shared/testing/utils.test';
|
||||||
|
import { SearchConfigurationServiceStub } from '../../shared/testing/search-configuration-service.stub';
|
||||||
|
|
||||||
describe('TopLevelCommunityList Component', () => {
|
describe('TopLevelCommunityList Component', () => {
|
||||||
let comp: TopLevelCommunityListComponent;
|
let comp: TopLevelCommunityListComponent;
|
||||||
@@ -114,6 +121,25 @@ describe('TopLevelCommunityList Component', () => {
|
|||||||
|
|
||||||
themeService = getMockThemeService();
|
themeService = getMockThemeService();
|
||||||
|
|
||||||
|
const linkHeadService = jasmine.createSpyObj('linkHeadService', {
|
||||||
|
addTag: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const groupDataService = jasmine.createSpyObj('groupsDataService', {
|
||||||
|
findAllByHref: createSuccessfulRemoteDataObject$(createPaginatedList([])),
|
||||||
|
getGroupRegistryRouterLink: '',
|
||||||
|
getUUIDFromString: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const configurationDataService = jasmine.createSpyObj('configurationDataService', {
|
||||||
|
findByPropertyName: createSuccessfulRemoteDataObject$(Object.assign(new ConfigurationProperty(), {
|
||||||
|
name: 'test',
|
||||||
|
values: [
|
||||||
|
'org.dspace.ctask.general.ProfileFormats = test'
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -130,6 +156,10 @@ describe('TopLevelCommunityList Component', () => {
|
|||||||
{ provide: PaginationService, useValue: paginationService },
|
{ provide: PaginationService, useValue: paginationService },
|
||||||
{ provide: SelectableListService, useValue: {} },
|
{ provide: SelectableListService, useValue: {} },
|
||||||
{ provide: ThemeService, useValue: themeService },
|
{ provide: ThemeService, useValue: themeService },
|
||||||
|
{ provide: GroupDataService, useValue: groupDataService },
|
||||||
|
{ provide: LinkHeadService, useValue: linkHeadService },
|
||||||
|
{ provide: ConfigurationDataService, useValue: configurationDataService },
|
||||||
|
{ provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() },
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<div class="container" *ngVar="(bundlesRD$ | async)?.payload?.page as bundles">
|
<div class="container">
|
||||||
<ng-container *ngIf="bundles">
|
<ng-container *ngIf="bundles">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12 mb-4">
|
<div class="col-12 mb-4">
|
||||||
|
@@ -21,19 +21,23 @@ import { createPaginatedList } from '../../../shared/testing/utils.test';
|
|||||||
import { RouterStub } from '../../../shared/testing/router.stub';
|
import { RouterStub } from '../../../shared/testing/router.stub';
|
||||||
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
|
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
|
||||||
import { AuthServiceStub } from '../../../shared/testing/auth-service.stub';
|
import { AuthServiceStub } from '../../../shared/testing/auth-service.stub';
|
||||||
import { getTestScheduler } from 'jasmine-marbles';
|
import { environment } from '../../../../environments/environment';
|
||||||
|
import { buildPaginatedList } from '../../../core/data/paginated-list.model';
|
||||||
|
import { PageInfo } from '../../../core/shared/page-info.model';
|
||||||
|
|
||||||
describe('UploadBistreamComponent', () => {
|
describe('UploadBitstreamComponent', () => {
|
||||||
let comp: UploadBitstreamComponent;
|
let comp: UploadBitstreamComponent;
|
||||||
let fixture: ComponentFixture<UploadBitstreamComponent>;
|
let fixture: ComponentFixture<UploadBitstreamComponent>;
|
||||||
|
|
||||||
|
const customName = 'customBundleName';
|
||||||
const bundle = Object.assign(new Bundle(), {
|
const bundle = Object.assign(new Bundle(), {
|
||||||
id: 'bundle',
|
id: 'bundle',
|
||||||
uuid: 'bundle',
|
uuid: 'bundle',
|
||||||
|
name: customName,
|
||||||
metadata: {
|
metadata: {
|
||||||
'dc.title': [
|
'dc.title': [
|
||||||
{
|
{
|
||||||
value: 'bundleName',
|
value: customName,
|
||||||
language: null
|
language: null
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -42,14 +46,15 @@ describe('UploadBistreamComponent', () => {
|
|||||||
self: { href: 'bundle-selflink' }
|
self: { href: 'bundle-selflink' }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const customName = 'Custom Name';
|
const customCreatedName = 'customCreatedBundleName';
|
||||||
const createdBundle = Object.assign(new Bundle(), {
|
const createdBundle = Object.assign(new Bundle(), {
|
||||||
id: 'created-bundle',
|
id: 'created-bundle',
|
||||||
uuid: 'created-bundle',
|
uuid: 'created-bundle',
|
||||||
|
name: customCreatedName,
|
||||||
metadata: {
|
metadata: {
|
||||||
'dc.title': [
|
'dc.title': [
|
||||||
{
|
{
|
||||||
value: customName,
|
value: customCreatedName,
|
||||||
language: null
|
language: null
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -72,13 +77,14 @@ describe('UploadBistreamComponent', () => {
|
|||||||
},
|
},
|
||||||
bundles: createSuccessfulRemoteDataObject$(createPaginatedList([bundle]))
|
bundles: createSuccessfulRemoteDataObject$(createPaginatedList([bundle]))
|
||||||
});
|
});
|
||||||
|
const standardBundleSuggestions = environment.bundle.standardBundles;
|
||||||
let routeStub;
|
let routeStub;
|
||||||
const routerStub = new RouterStub();
|
const routerStub = new RouterStub();
|
||||||
const restEndpoint = 'fake-rest-endpoint';
|
const restEndpoint = 'fake-rest-endpoint';
|
||||||
const mockItemDataService = jasmine.createSpyObj('mockItemDataService', {
|
const mockItemDataService = jasmine.createSpyObj('mockItemDataService', {
|
||||||
getBitstreamsEndpoint: observableOf(restEndpoint),
|
getBitstreamsEndpoint: observableOf(restEndpoint),
|
||||||
createBundle: createSuccessfulRemoteDataObject$(createdBundle),
|
createBundle: createSuccessfulRemoteDataObject$(createdBundle),
|
||||||
getBundles: createSuccessfulRemoteDataObject$([bundle])
|
getBundles: createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [bundle])),
|
||||||
});
|
});
|
||||||
const bundleService = jasmine.createSpyObj('bundleService', {
|
const bundleService = jasmine.createSpyObj('bundleService', {
|
||||||
getBitstreamsEndpoint: observableOf(restEndpoint),
|
getBitstreamsEndpoint: observableOf(restEndpoint),
|
||||||
@@ -94,22 +100,6 @@ describe('UploadBistreamComponent', () => {
|
|||||||
removeByHrefSubstring: {}
|
removeByHrefSubstring: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('on init', () => {
|
|
||||||
beforeEach(waitForAsync(() => {
|
|
||||||
createUploadBitstreamTestingModule({
|
|
||||||
bundle: bundle.id
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
beforeEach(() => {
|
|
||||||
loadFixtureAndComp();
|
|
||||||
});
|
|
||||||
it('should initialize the bundles', () => {
|
|
||||||
expect(comp.bundlesRD$).toBeDefined();
|
|
||||||
getTestScheduler().expectObservable(comp.bundlesRD$).toBe('(a|)', {a: createSuccessfulRemoteDataObject([bundle])});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when a file is uploaded', () => {
|
describe('when a file is uploaded', () => {
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
createUploadBitstreamTestingModule({});
|
createUploadBitstreamTestingModule({});
|
||||||
@@ -164,12 +154,24 @@ describe('UploadBistreamComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('and bundle name changed', () => {
|
describe('and bundle name changed', () => {
|
||||||
beforeEach(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
|
jasmine.getEnv().allowRespy(true);
|
||||||
|
mockItemDataService.getBundles.and.returnValue(createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [bundle])));
|
||||||
|
loadFixtureAndComp();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should clear out the selected id if the name doesn\'t exist', () => {
|
||||||
|
comp.selectedBundleName = '';
|
||||||
comp.bundleNameChange();
|
comp.bundleNameChange();
|
||||||
|
|
||||||
|
expect(comp.selectedBundleId).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should clear out the selected id', () => {
|
it('should select the correct id if the name exist', () => {
|
||||||
expect(comp.selectedBundleId).toBeUndefined();
|
comp.selectedBundleName = customName;
|
||||||
|
comp.bundleNameChange();
|
||||||
|
|
||||||
|
expect(comp.selectedBundleId).toEqual(bundle.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -203,6 +205,69 @@ describe('UploadBistreamComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when item has no bundles yet', () => {
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
createUploadBitstreamTestingModule({
|
||||||
|
bundle: bundle.id
|
||||||
|
});
|
||||||
|
jasmine.getEnv().allowRespy(true);
|
||||||
|
mockItemDataService.getBundles.and.returnValue(createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [])));
|
||||||
|
loadFixtureAndComp();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should display only the standard bundles in dropdown', () => {
|
||||||
|
expect(comp.bundles.length).toEqual(standardBundleSuggestions.length);
|
||||||
|
for (let i = 0; i < standardBundleSuggestions.length; i++) {
|
||||||
|
// noinspection JSDeprecatedSymbols
|
||||||
|
expect(comp.bundles[i].name).toEqual(standardBundleSuggestions[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when item has a custom bundle', () => {
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
createUploadBitstreamTestingModule({
|
||||||
|
bundle: bundle.id
|
||||||
|
});
|
||||||
|
jasmine.getEnv().allowRespy(true);
|
||||||
|
mockItemDataService.getBundles.and.returnValue(createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [bundle])));
|
||||||
|
loadFixtureAndComp();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should still display existing bitstream bundles if the bitstream has bundles', () => {
|
||||||
|
const expectedSuggestions = [bundle.name, ...standardBundleSuggestions];
|
||||||
|
expect(comp.bundles.length).toEqual(expectedSuggestions.length);
|
||||||
|
for (let i = 0; i < expectedSuggestions.length; i++) {
|
||||||
|
// noinspection JSDeprecatedSymbols
|
||||||
|
expect(comp.bundles[i].name).toEqual(expectedSuggestions[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when item has a standard bundle', () => {
|
||||||
|
let clonedBundle;
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
clonedBundle = { ...bundle };
|
||||||
|
expect(standardBundleSuggestions.length).toBeGreaterThan(0);
|
||||||
|
clonedBundle.name = standardBundleSuggestions[0];
|
||||||
|
createUploadBitstreamTestingModule({
|
||||||
|
bundle: clonedBundle.id
|
||||||
|
});
|
||||||
|
jasmine.getEnv().allowRespy(true);
|
||||||
|
mockItemDataService.getBundles.and.returnValue(createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [clonedBundle])));
|
||||||
|
loadFixtureAndComp();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not show duplicate bundle names', () => {
|
||||||
|
const expectedSuggestions = [clonedBundle.name, ...standardBundleSuggestions.filter((standardBundleSuggestion: string) => standardBundleSuggestion !== clonedBundle.name)];
|
||||||
|
expect(comp.bundles.length).toEqual(expectedSuggestions.length);
|
||||||
|
for (let i = 0; i < expectedSuggestions.length; i++) {
|
||||||
|
// noinspection JSDeprecatedSymbols
|
||||||
|
expect(comp.bundles[i].name).toEqual(expectedSuggestions[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup an UploadBitstreamComponent testing module with custom queryParams for the route
|
* Setup an UploadBitstreamComponent testing module with custom queryParams for the route
|
||||||
* @param queryParams
|
* @param queryParams
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
||||||
import { Observable, Subscription } from 'rxjs';
|
import { Observable, Subscription, of as observableOf } from 'rxjs';
|
||||||
import { RemoteData } from '../../../core/data/remote-data';
|
import { RemoteData } from '../../../core/data/remote-data';
|
||||||
import { Item } from '../../../core/shared/item.model';
|
import { Item } from '../../../core/shared/item.model';
|
||||||
import { map, take } from 'rxjs/operators';
|
import { map, take, switchMap } from 'rxjs/operators';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { UploaderOptions } from '../../../shared/uploader/uploader-options.model';
|
import { UploaderOptions } from '../../../shared/uploader/uploader-options.model';
|
||||||
import { hasValue, isEmpty, isNotEmpty } from '../../../shared/empty.util';
|
import { hasValue, isEmpty, isNotEmpty } from '../../../shared/empty.util';
|
||||||
@@ -13,11 +13,12 @@ import { TranslateService } from '@ngx-translate/core';
|
|||||||
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
||||||
import { Bundle } from '../../../core/shared/bundle.model';
|
import { Bundle } from '../../../core/shared/bundle.model';
|
||||||
import { BundleDataService } from '../../../core/data/bundle-data.service';
|
import { BundleDataService } from '../../../core/data/bundle-data.service';
|
||||||
import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators';
|
import { getFirstSucceededRemoteDataPayload, getFirstCompletedRemoteData } from '../../../core/shared/operators';
|
||||||
import { UploaderComponent } from '../../../shared/uploader/uploader.component';
|
import { UploaderComponent } from '../../../shared/uploader/uploader.component';
|
||||||
import { RequestService } from '../../../core/data/request.service';
|
import { RequestService } from '../../../core/data/request.service';
|
||||||
import { getBitstreamModuleRoute } from '../../../app-routing-paths';
|
import { getBitstreamModuleRoute } from '../../../app-routing-paths';
|
||||||
import { getEntityEditRoute } from '../../item-page-routing-paths';
|
import { getEntityEditRoute } from '../../item-page-routing-paths';
|
||||||
|
import { environment } from '../../../../environments/environment';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-upload-bitstream',
|
selector: 'ds-upload-bitstream',
|
||||||
@@ -49,9 +50,9 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy {
|
|||||||
itemRD$: Observable<RemoteData<Item>>;
|
itemRD$: Observable<RemoteData<Item>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The item's bundles
|
* The item's bundles and default the default bundles that should be suggested (defined in environment)
|
||||||
*/
|
*/
|
||||||
bundlesRD$: Observable<RemoteData<PaginatedList<Bundle>>>;
|
bundles: Bundle[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ID of the currently selected bundle to upload a bitstream to
|
* The ID of the currently selected bundle to upload a bitstream to
|
||||||
@@ -99,7 +100,6 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy {
|
|||||||
/**
|
/**
|
||||||
* Initialize component properties:
|
* Initialize component properties:
|
||||||
* itemRD$ Fetched from the current route data (populated by BitstreamPageResolver)
|
* itemRD$ Fetched from the current route data (populated by BitstreamPageResolver)
|
||||||
* bundlesRD$ List of bundles on the item
|
|
||||||
* selectedBundleId Starts off by checking if the route's queryParams contain a "bundle" parameter. If none is found,
|
* selectedBundleId Starts off by checking if the route's queryParams contain a "bundle" parameter. If none is found,
|
||||||
* the ID of the first bundle in the list is selected.
|
* the ID of the first bundle in the list is selected.
|
||||||
* Calls setUploadUrl after setting the selected bundle
|
* Calls setUploadUrl after setting the selected bundle
|
||||||
@@ -108,16 +108,47 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy {
|
|||||||
this.itemId = this.route.snapshot.params.id;
|
this.itemId = this.route.snapshot.params.id;
|
||||||
this.entityType = this.route.snapshot.params['entity-type'];
|
this.entityType = this.route.snapshot.params['entity-type'];
|
||||||
this.itemRD$ = this.route.data.pipe(map((data) => data.dso));
|
this.itemRD$ = this.route.data.pipe(map((data) => data.dso));
|
||||||
this.bundlesRD$ = this.itemService.getBundles(this.itemId);
|
const bundlesRD$ = this.itemService.getBundles(this.itemId).pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
switchMap((remoteData: RemoteData<PaginatedList<Bundle>>) => {
|
||||||
|
if (remoteData.hasSucceeded) {
|
||||||
|
if (remoteData.payload.page) {
|
||||||
|
this.bundles = remoteData.payload.page;
|
||||||
|
for (const defaultBundle of environment.bundle.standardBundles) {
|
||||||
|
let check = true;
|
||||||
|
remoteData.payload.page.forEach((bundle: Bundle) => {
|
||||||
|
// noinspection JSDeprecatedSymbols
|
||||||
|
if (defaultBundle === bundle.name) {
|
||||||
|
check = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (check) {
|
||||||
|
this.bundles.push(Object.assign(new Bundle(), {
|
||||||
|
_name: defaultBundle,
|
||||||
|
type: 'bundle'
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.bundles = environment.bundle.standardBundles.map((defaultBundle: string) => Object.assign(new Bundle(), {
|
||||||
|
_name: defaultBundle,
|
||||||
|
type: 'bundle'
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return observableOf(remoteData.payload.page);
|
||||||
|
}
|
||||||
|
}));
|
||||||
this.selectedBundleId = this.route.snapshot.queryParams.bundle;
|
this.selectedBundleId = this.route.snapshot.queryParams.bundle;
|
||||||
if (isNotEmpty(this.selectedBundleId)) {
|
if (isNotEmpty(this.selectedBundleId)) {
|
||||||
this.bundleService.findById(this.selectedBundleId).pipe(
|
this.subs.push(this.bundleService.findById(this.selectedBundleId).pipe(
|
||||||
getFirstSucceededRemoteDataPayload()
|
getFirstSucceededRemoteDataPayload()
|
||||||
).subscribe((bundle: Bundle) => {
|
).subscribe((bundle: Bundle) => {
|
||||||
this.selectedBundleName = bundle.name;
|
this.selectedBundleName = bundle.name;
|
||||||
});
|
}));
|
||||||
this.setUploadUrl();
|
this.setUploadUrl();
|
||||||
}
|
}
|
||||||
|
this.subs.push(bundlesRD$.subscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,6 +173,13 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy {
|
|||||||
*/
|
*/
|
||||||
bundleNameChange() {
|
bundleNameChange() {
|
||||||
this.selectedBundleId = undefined;
|
this.selectedBundleId = undefined;
|
||||||
|
for (const bundle of this.bundles) {
|
||||||
|
// noinspection JSDeprecatedSymbols
|
||||||
|
if (this.selectedBundleName === bundle.name) {
|
||||||
|
this.selectedBundleId = bundle.id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -191,8 +229,10 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy {
|
|||||||
onClick(bundle: Bundle) {
|
onClick(bundle: Bundle) {
|
||||||
this.selectedBundleId = bundle.id;
|
this.selectedBundleId = bundle.id;
|
||||||
this.selectedBundleName = bundle.name;
|
this.selectedBundleName = bundle.name;
|
||||||
|
if (bundle.id) {
|
||||||
this.setUploadUrl();
|
this.setUploadUrl();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When cancel is clicked, navigate back to the item's edit bitstreams page
|
* When cancel is clicked, navigate back to the item's edit bitstreams page
|
||||||
|
@@ -23,6 +23,14 @@ import { PaginationComponent } from '../../../../shared/pagination/pagination.co
|
|||||||
import { PaginationComponentOptions } from '../../../../shared/pagination/pagination-component-options.model';
|
import { PaginationComponentOptions } from '../../../../shared/pagination/pagination-component-options.model';
|
||||||
import { RelationshipTypeService } from '../../../../core/data/relationship-type.service';
|
import { RelationshipTypeService } from '../../../../core/data/relationship-type.service';
|
||||||
import { FieldChangeType } from '../../../../core/data/object-updates/field-change-type.model';
|
import { FieldChangeType } from '../../../../core/data/object-updates/field-change-type.model';
|
||||||
|
import { GroupDataService } from '../../../../core/eperson/group-data.service';
|
||||||
|
import { ConfigurationDataService } from '../../../../core/data/configuration-data.service';
|
||||||
|
import { LinkHeadService } from '../../../../core/services/link-head.service';
|
||||||
|
import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service';
|
||||||
|
import { SearchConfigurationServiceStub } from '../../../../shared/testing/search-configuration-service.stub';
|
||||||
|
import { ConfigurationProperty } from '../../../../core/shared/configuration-property.model';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { RouterMock } from '../../../../shared/mocks/router.mock';
|
||||||
|
|
||||||
let comp: EditRelationshipListComponent;
|
let comp: EditRelationshipListComponent;
|
||||||
let fixture: ComponentFixture<EditRelationshipListComponent>;
|
let fixture: ComponentFixture<EditRelationshipListComponent>;
|
||||||
@@ -174,6 +182,25 @@ describe('EditRelationshipListComponent', () => {
|
|||||||
|
|
||||||
hostWindowService = new HostWindowServiceStub(1200);
|
hostWindowService = new HostWindowServiceStub(1200);
|
||||||
|
|
||||||
|
const linkHeadService = jasmine.createSpyObj('linkHeadService', {
|
||||||
|
addTag: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const groupDataService = jasmine.createSpyObj('groupsDataService', {
|
||||||
|
findAllByHref: createSuccessfulRemoteDataObject$(createPaginatedList([])),
|
||||||
|
getGroupRegistryRouterLink: '',
|
||||||
|
getUUIDFromString: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const configurationDataService = jasmine.createSpyObj('configurationDataService', {
|
||||||
|
findByPropertyName: createSuccessfulRemoteDataObject$(Object.assign(new ConfigurationProperty(), {
|
||||||
|
name: 'test',
|
||||||
|
values: [
|
||||||
|
'org.dspace.ctask.general.ProfileFormats = test'
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [SharedModule, TranslateModule.forRoot()],
|
imports: [SharedModule, TranslateModule.forRoot()],
|
||||||
declarations: [EditRelationshipListComponent],
|
declarations: [EditRelationshipListComponent],
|
||||||
@@ -185,6 +212,11 @@ describe('EditRelationshipListComponent', () => {
|
|||||||
{ provide: PaginationService, useValue: paginationService },
|
{ provide: PaginationService, useValue: paginationService },
|
||||||
{ provide: HostWindowService, useValue: hostWindowService },
|
{ provide: HostWindowService, useValue: hostWindowService },
|
||||||
{ provide: RelationshipTypeService, useValue: relationshipTypeService },
|
{ provide: RelationshipTypeService, useValue: relationshipTypeService },
|
||||||
|
{ provide: GroupDataService, useValue: groupDataService },
|
||||||
|
{ provide: Router, useValue: new RouterMock() },
|
||||||
|
{ provide: LinkHeadService, useValue: linkHeadService },
|
||||||
|
{ provide: ConfigurationDataService, useValue: configurationDataService },
|
||||||
|
{ provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() },
|
||||||
], schemas: [
|
], schemas: [
|
||||||
NO_ERRORS_SCHEMA
|
NO_ERRORS_SCHEMA
|
||||||
]
|
]
|
||||||
|
@@ -12,12 +12,13 @@
|
|||||||
[tooltipMsg]="'item.page.edit'"></ds-dso-page-edit-button>
|
[tooltipMsg]="'item.page.edit'"></ds-dso-page-edit-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="simple-view-link my-3" *ngIf="!fromWfi">
|
<div class="simple-view-link my-3" *ngIf="!fromSubmissionObject">
|
||||||
<a class="btn btn-outline-primary" [routerLink]="[(itemPageRoute$ | async)]">
|
<a class="btn btn-outline-primary" [routerLink]="[(itemPageRoute$ | async)]">
|
||||||
{{"item.page.link.simple" | translate}}
|
{{"item.page.link.simple" | translate}}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<table class="table table-responsive table-striped">
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped">
|
||||||
<tbody>
|
<tbody>
|
||||||
<ng-container *ngFor="let mdEntry of (metadata$ | async) | keyvalue">
|
<ng-container *ngFor="let mdEntry of (metadata$ | async) | keyvalue">
|
||||||
<tr *ngFor="let mdValue of mdEntry.value">
|
<tr *ngFor="let mdValue of mdEntry.value">
|
||||||
@@ -28,10 +29,11 @@
|
|||||||
</ng-container>
|
</ng-container>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
<ds-item-page-full-file-section [item]="item"></ds-item-page-full-file-section>
|
<ds-item-page-full-file-section [item]="item"></ds-item-page-full-file-section>
|
||||||
<ds-item-page-collections [item]="item"></ds-item-page-collections>
|
<ds-item-page-collections [item]="item"></ds-item-page-collections>
|
||||||
<ds-item-versions class="mt-2" [item]="item"></ds-item-versions>
|
<ds-item-versions class="mt-2" [item]="item"></ds-item-versions>
|
||||||
<div class="button-row bottom" *ngIf="fromWfi">
|
<div class="button-row bottom" *ngIf="fromSubmissionObject">
|
||||||
<div class="text-right">
|
<div class="text-right">
|
||||||
<button class="btn btn-outline-secondary mr-1" (click)="back()"><i
|
<button class="btn btn-outline-secondary mr-1" (click)="back()"><i
|
||||||
class="fas fa-arrow-left"></i> {{'item.page.return' | translate}}</button>
|
class="fas fa-arrow-left"></i> {{'item.page.return' | translate}}</button>
|
||||||
|
@@ -112,7 +112,7 @@ describe('FullItemPageComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should show simple view button when not originated from workflow item', () => {
|
it('should show simple view button when not originated from workflow item', () => {
|
||||||
expect(comp.fromWfi).toBe(false);
|
expect(comp.fromSubmissionObject).toBe(false);
|
||||||
const simpleViewBtn = fixture.debugElement.query(By.css('.simple-view-link'));
|
const simpleViewBtn = fixture.debugElement.query(By.css('.simple-view-link'));
|
||||||
expect(simpleViewBtn).toBeTruthy();
|
expect(simpleViewBtn).toBeTruthy();
|
||||||
});
|
});
|
||||||
@@ -122,7 +122,7 @@ describe('FullItemPageComponent', () => {
|
|||||||
comp.ngOnInit();
|
comp.ngOnInit();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
expect(comp.fromWfi).toBe(true);
|
expect(comp.fromSubmissionObject).toBe(true);
|
||||||
const simpleViewBtn = fixture.debugElement.query(By.css('.simple-view-link'));
|
const simpleViewBtn = fixture.debugElement.query(By.css('.simple-view-link'));
|
||||||
expect(simpleViewBtn).toBeFalsy();
|
expect(simpleViewBtn).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
@@ -2,7 +2,7 @@ import { filter, map } from 'rxjs/operators';
|
|||||||
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
|
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute, Data, Router } from '@angular/router';
|
import { ActivatedRoute, Data, Router } from '@angular/router';
|
||||||
|
|
||||||
import { Observable , BehaviorSubject } from 'rxjs';
|
import { BehaviorSubject, Observable } from 'rxjs';
|
||||||
|
|
||||||
import { ItemPageComponent } from '../simple/item-page.component';
|
import { ItemPageComponent } from '../simple/item-page.component';
|
||||||
import { MetadataMap } from '../../core/shared/metadata.models';
|
import { MetadataMap } from '../../core/shared/metadata.models';
|
||||||
@@ -37,9 +37,9 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit,
|
|||||||
metadata$: Observable<MetadataMap>;
|
metadata$: Observable<MetadataMap>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True when the itemRD has been originated from its workflowitem, false otherwise.
|
* True when the itemRD has been originated from its workspaceite/workflowitem, false otherwise.
|
||||||
*/
|
*/
|
||||||
fromWfi = false;
|
fromSubmissionObject = false;
|
||||||
|
|
||||||
subs = [];
|
subs = [];
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit,
|
|||||||
map((item: Item) => item.metadata),);
|
map((item: Item) => item.metadata),);
|
||||||
|
|
||||||
this.subs.push(this.route.data.subscribe((data: Data) => {
|
this.subs.push(this.route.data.subscribe((data: Data) => {
|
||||||
this.fromWfi = hasValue(data.wfi);
|
this.fromSubmissionObject = hasValue(data.wfi) || hasValue(data.wsi);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -5,8 +5,9 @@ import { FormGroup } from '@angular/forms';
|
|||||||
import { hasValue, isEmpty } from '../../shared/empty.util';
|
import { hasValue, isEmpty } from '../../shared/empty.util';
|
||||||
import { EPersonDataService } from '../../core/eperson/eperson-data.service';
|
import { EPersonDataService } from '../../core/eperson/eperson-data.service';
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { debounceTime, map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
|
import { debounceTimeWorkaround as debounceTime } from '../../core/shared/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-profile-page-security-form',
|
selector: 'ds-profile-page-security-form',
|
||||||
|
@@ -9,7 +9,7 @@ import { TranslateLoaderMock } from '../shared/mocks/translate-loader.mock';
|
|||||||
import { NativeWindowRef, NativeWindowService } from '../core/services/window.service';
|
import { NativeWindowRef, NativeWindowService } from '../core/services/window.service';
|
||||||
import { MetadataService } from '../core/metadata/metadata.service';
|
import { MetadataService } from '../core/metadata/metadata.service';
|
||||||
import { MetadataServiceMock } from '../shared/mocks/metadata-service.mock';
|
import { MetadataServiceMock } from '../shared/mocks/metadata-service.mock';
|
||||||
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
|
import { Angulartics2GoogleAnalytics } from 'angulartics2';
|
||||||
import { AngularticsProviderMock } from '../shared/mocks/angulartics-provider.service.mock';
|
import { AngularticsProviderMock } from '../shared/mocks/angulartics-provider.service.mock';
|
||||||
import { Angulartics2DSpace } from '../statistics/angulartics/dspace-provider';
|
import { Angulartics2DSpace } from '../statistics/angulartics/dspace-provider';
|
||||||
import { AuthService } from '../core/auth/auth.service';
|
import { AuthService } from '../core/auth/auth.service';
|
||||||
|
@@ -5,7 +5,7 @@ import { Router } from '@angular/router';
|
|||||||
import { combineLatest as combineLatestObservable, Observable, of } from 'rxjs';
|
import { combineLatest as combineLatestObservable, Observable, of } from 'rxjs';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
|
import { Angulartics2GoogleAnalytics } from 'angulartics2';
|
||||||
|
|
||||||
import { MetadataService } from '../core/metadata/metadata.service';
|
import { MetadataService } from '../core/metadata/metadata.service';
|
||||||
import { HostWindowState } from '../shared/search/host-window.reducer';
|
import { HostWindowState } from '../shared/search/host-window.reducer';
|
||||||
|
@@ -2,6 +2,9 @@
|
|||||||
<h3 [ngClass]="{'sr-only': parentname }">{{title | translate}}</h3>
|
<h3 [ngClass]="{'sr-only': parentname }">{{title | translate}}</h3>
|
||||||
<ng-container *ngComponentOutlet="getStartsWithComponent(); injector: objectInjector;"></ng-container>
|
<ng-container *ngComponentOutlet="getStartsWithComponent(); injector: objectInjector;"></ng-container>
|
||||||
<div *ngIf="objects?.hasSucceeded && !objects?.isLoading && objects?.payload?.page.length > 0" @fadeIn>
|
<div *ngIf="objects?.hasSucceeded && !objects?.isLoading && objects?.payload?.page.length > 0" @fadeIn>
|
||||||
|
<div *ngIf="shouldDisplayResetButton$ |async" class="mb-2 reset">
|
||||||
|
<button class="btn btn-secondary" (click)="back()"><i class="fas fa-arrow-left"></i> {{'browse.back.all-results' | translate}}</button>
|
||||||
|
</div>
|
||||||
<ds-viewable-collection
|
<ds-viewable-collection
|
||||||
[config]="paginationConfig"
|
[config]="paginationConfig"
|
||||||
[sortConfig]="sortConfig"
|
[sortConfig]="sortConfig"
|
||||||
@@ -13,8 +16,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<ds-loading *ngIf="!objects || objects?.isLoading" message="{{'loading.browse-by' | translate}}"></ds-loading>
|
<ds-loading *ngIf="!objects || objects?.isLoading" message="{{'loading.browse-by' | translate}}"></ds-loading>
|
||||||
<ds-error *ngIf="objects?.hasFailed" message="{{'error.browse-by' | translate}}"></ds-error>
|
<ds-error *ngIf="objects?.hasFailed" message="{{'error.browse-by' | translate}}"></ds-error>
|
||||||
<div *ngIf="!objects?.isLoading && objects?.payload?.page.length === 0" class="alert alert-info w-100" role="alert">
|
<div *ngIf="!objects?.isLoading && objects?.payload?.page.length === 0">
|
||||||
|
<div *ngIf="shouldDisplayResetButton$ |async" class="d-inline-block mb-4 reset">
|
||||||
|
<button class="btn btn-secondary" (click)="back()"><i class="fas fa-arrow-left"></i> {{'browse.back.all-results' | translate}}</button>
|
||||||
|
</div>
|
||||||
|
<div class="alert alert-info w-100" role="alert">
|
||||||
{{'browse.empty' | translate}}
|
{{'browse.empty' | translate}}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
|
@@ -18,9 +18,13 @@ import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils';
|
|||||||
import { PaginationService } from '../../core/pagination/pagination.service';
|
import { PaginationService } from '../../core/pagination/pagination.service';
|
||||||
import { PaginationServiceStub } from '../testing/pagination-service.stub';
|
import { PaginationServiceStub } from '../testing/pagination-service.stub';
|
||||||
import { FindListOptions } from '../../core/data/find-list-options.model';
|
import { FindListOptions } from '../../core/data/find-list-options.model';
|
||||||
import { ListableObjectComponentLoaderComponent } from '../object-collection/shared/listable-object/listable-object-component-loader.component';
|
import {
|
||||||
|
ListableObjectComponentLoaderComponent
|
||||||
|
} from '../object-collection/shared/listable-object/listable-object-component-loader.component';
|
||||||
import { ViewMode } from '../../core/shared/view-mode.model';
|
import { ViewMode } from '../../core/shared/view-mode.model';
|
||||||
import { BrowseEntryListElementComponent } from '../object-list/browse-entry-list-element/browse-entry-list-element.component';
|
import {
|
||||||
|
BrowseEntryListElementComponent
|
||||||
|
} from '../object-list/browse-entry-list-element/browse-entry-list-element.component';
|
||||||
import {
|
import {
|
||||||
DEFAULT_CONTEXT,
|
DEFAULT_CONTEXT,
|
||||||
listableObjectComponent,
|
listableObjectComponent,
|
||||||
@@ -31,7 +35,16 @@ import { ThemeService } from '../theme-support/theme.service';
|
|||||||
import { SelectableListService } from '../object-list/selectable-list/selectable-list.service';
|
import { SelectableListService } from '../object-list/selectable-list/selectable-list.service';
|
||||||
import { HostWindowServiceStub } from '../testing/host-window-service.stub';
|
import { HostWindowServiceStub } from '../testing/host-window-service.stub';
|
||||||
import { HostWindowService } from '../host-window.service';
|
import { HostWindowService } from '../host-window.service';
|
||||||
|
import { RouteService } from '../../core/services/route.service';
|
||||||
|
import { routeServiceStub } from '../testing/route-service.stub';
|
||||||
import SpyObj = jasmine.SpyObj;
|
import SpyObj = jasmine.SpyObj;
|
||||||
|
import { GroupDataService } from '../../core/eperson/group-data.service';
|
||||||
|
import { createPaginatedList } from '../testing/utils.test';
|
||||||
|
import { LinkHeadService } from '../../core/services/link-head.service';
|
||||||
|
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
|
||||||
|
import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
|
||||||
|
import { SearchConfigurationServiceStub } from '../testing/search-configuration-service.stub';
|
||||||
|
import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service';
|
||||||
|
|
||||||
@listableObjectComponent(BrowseEntry, ViewMode.ListElement, DEFAULT_CONTEXT, 'custom')
|
@listableObjectComponent(BrowseEntry, ViewMode.ListElement, DEFAULT_CONTEXT, 'custom')
|
||||||
@Component({
|
@Component({
|
||||||
@@ -67,6 +80,25 @@ describe('BrowseByComponent', () => {
|
|||||||
];
|
];
|
||||||
const mockItemsRD$ = createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), mockItems));
|
const mockItemsRD$ = createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), mockItems));
|
||||||
|
|
||||||
|
const groupDataService = jasmine.createSpyObj('groupsDataService', {
|
||||||
|
findAllByHref: createSuccessfulRemoteDataObject$(createPaginatedList([])),
|
||||||
|
getGroupRegistryRouterLink: '',
|
||||||
|
getUUIDFromString: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const linkHeadService = jasmine.createSpyObj('linkHeadService', {
|
||||||
|
addTag: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const configurationDataService = jasmine.createSpyObj('configurationDataService', {
|
||||||
|
findByPropertyName: createSuccessfulRemoteDataObject$(Object.assign(new ConfigurationProperty(), {
|
||||||
|
name: 'test',
|
||||||
|
values: [
|
||||||
|
'org.dspace.ctask.general.ProfileFormats = test'
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
|
||||||
const paginationConfig = Object.assign(new PaginationComponentOptions(), {
|
const paginationConfig = Object.assign(new PaginationComponentOptions(), {
|
||||||
id: 'test-pagination',
|
id: 'test-pagination',
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
@@ -97,9 +129,14 @@ describe('BrowseByComponent', () => {
|
|||||||
],
|
],
|
||||||
declarations: [],
|
declarations: [],
|
||||||
providers: [
|
providers: [
|
||||||
|
{ provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() },
|
||||||
|
{ provide: ConfigurationDataService, useValue: configurationDataService },
|
||||||
|
{ provide: LinkHeadService, useValue: linkHeadService },
|
||||||
|
{ provide: GroupDataService, useValue: groupDataService },
|
||||||
{ provide: PaginationService, useValue: paginationService },
|
{ provide: PaginationService, useValue: paginationService },
|
||||||
{ provide: MockThemedBrowseEntryListElementComponent },
|
{ provide: MockThemedBrowseEntryListElementComponent },
|
||||||
{ provide: ThemeService, useValue: themeService },
|
{ provide: ThemeService, useValue: themeService },
|
||||||
|
{provide: RouteService, useValue: routeServiceStub},
|
||||||
{ provide: SelectableListService, useValue: {} },
|
{ provide: SelectableListService, useValue: {} },
|
||||||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(800) },
|
{ provide: HostWindowService, useValue: new HostWindowServiceStub(800) },
|
||||||
],
|
],
|
||||||
@@ -110,6 +147,8 @@ describe('BrowseByComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(BrowseByComponent);
|
fixture = TestBed.createComponent(BrowseByComponent);
|
||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
|
comp.paginationConfig = paginationConfig;
|
||||||
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display a loading message when objects is empty', () => {
|
it('should display a loading message when objects is empty', () => {
|
||||||
@@ -193,4 +232,27 @@ describe('BrowseByComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('reset filters button', () => {
|
||||||
|
it('should not be present when no startsWith or value is present ', () => {
|
||||||
|
const button = fixture.debugElement.query(By.css('reset'));
|
||||||
|
expect(button).toBeNull();
|
||||||
|
});
|
||||||
|
it('should be present when a startsWith or value is present ', () => {
|
||||||
|
comp.shouldDisplayResetButton$ = observableOf(true);
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
const button = fixture.debugElement.query(By.css('reset'));
|
||||||
|
expect(button).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('back', () => {
|
||||||
|
it('should navigate back to the main browse page', () => {
|
||||||
|
comp.back();
|
||||||
|
expect(paginationService.updateRoute).toHaveBeenCalledWith('test-pagination', {page: 1}, {
|
||||||
|
value: null,
|
||||||
|
startsWith: null
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -4,11 +4,14 @@ import { PaginatedList } from '../../core/data/paginated-list.model';
|
|||||||
import { PaginationComponentOptions } from '../pagination/pagination-component-options.model';
|
import { PaginationComponentOptions } from '../pagination/pagination-component-options.model';
|
||||||
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
|
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
|
||||||
import { fadeIn, fadeInOut } from '../animations/fade';
|
import { fadeIn, fadeInOut } from '../animations/fade';
|
||||||
import { Observable } from 'rxjs';
|
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
|
||||||
import { ListableObject } from '../object-collection/shared/listable-object.model';
|
import { ListableObject } from '../object-collection/shared/listable-object.model';
|
||||||
import { getStartsWithComponent, StartsWithType } from '../starts-with/starts-with-decorator';
|
import { getStartsWithComponent, StartsWithType } from '../starts-with/starts-with-decorator';
|
||||||
import { PaginationService } from '../../core/pagination/pagination.service';
|
import { PaginationService } from '../../core/pagination/pagination.service';
|
||||||
import { ViewMode } from '../../core/shared/view-mode.model';
|
import { ViewMode } from '../../core/shared/view-mode.model';
|
||||||
|
import { RouteService } from '../../core/services/route.service';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
import { hasValue } from '../empty.util';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-browse-by',
|
selector: 'ds-browse-by',
|
||||||
@@ -67,7 +70,7 @@ export class BrowseByComponent implements OnInit {
|
|||||||
/**
|
/**
|
||||||
* Whether or not the pagination should be rendered as simple previous and next buttons instead of the normal pagination
|
* Whether or not the pagination should be rendered as simple previous and next buttons instead of the normal pagination
|
||||||
*/
|
*/
|
||||||
@Input() showPaginator = false;
|
@Input() showPaginator = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It is used to hide or show gear
|
* It is used to hide or show gear
|
||||||
@@ -104,8 +107,14 @@ export class BrowseByComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
public sortDirections = SortDirection;
|
public sortDirections = SortDirection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Observable that tracks if the back button should be displayed based on the path parameters
|
||||||
|
*/
|
||||||
|
shouldDisplayResetButton$: Observable<boolean>;
|
||||||
|
|
||||||
public constructor(private injector: Injector,
|
public constructor(private injector: Injector,
|
||||||
protected paginationService: PaginationService,
|
protected paginationService: PaginationService,
|
||||||
|
private routeService: RouteService,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -155,6 +164,16 @@ export class BrowseByComponent implements OnInit {
|
|||||||
],
|
],
|
||||||
parent: this.injector
|
parent: this.injector
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const startsWith$ = this.routeService.getQueryParameterValue('startsWith');
|
||||||
|
const value$ = this.routeService.getQueryParameterValue('value');
|
||||||
|
|
||||||
|
this.shouldDisplayResetButton$ = observableCombineLatest([startsWith$, value$]).pipe(
|
||||||
|
map(([startsWith, value]) => hasValue(startsWith) || hasValue(value))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
back() {
|
||||||
|
this.paginationService.updateRoute(this.paginationConfig.id, {page: 1}, {value: null, startsWith: null});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -143,7 +143,7 @@ export class DSOSelectorComponent implements OnInit, OnDestroy {
|
|||||||
this.typesString = this.types.map((type: string) => type.toString().toLowerCase()).join(', ');
|
this.typesString = this.types.map((type: string) => type.toString().toLowerCase()).join(', ');
|
||||||
|
|
||||||
// Create an observable searching for the current DSO (return empty list if there's no current DSO)
|
// Create an observable searching for the current DSO (return empty list if there's no current DSO)
|
||||||
let currentDSOResult$;
|
let currentDSOResult$: Observable<PaginatedList<SearchResult<DSpaceObject>>>;
|
||||||
if (isNotEmpty(this.currentDSOId)) {
|
if (isNotEmpty(this.currentDSOId)) {
|
||||||
currentDSOResult$ = this.search(this.getCurrentDSOQuery(), 1).pipe(getFirstSucceededRemoteDataPayload());
|
currentDSOResult$ = this.search(this.getCurrentDSOQuery(), 1).pipe(getFirstSucceededRemoteDataPayload());
|
||||||
} else {
|
} else {
|
||||||
|
@@ -9,7 +9,7 @@ import {
|
|||||||
isNotEmptyOperator,
|
isNotEmptyOperator,
|
||||||
isNotNull,
|
isNotNull,
|
||||||
isNotUndefined,
|
isNotUndefined,
|
||||||
isNull,
|
isNull, isObjectEmpty,
|
||||||
isUndefined
|
isUndefined
|
||||||
} from './empty.util';
|
} from './empty.util';
|
||||||
|
|
||||||
@@ -444,6 +444,43 @@ describe('Empty Utils', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isObjectEmpty', () => {
|
||||||
|
/*
|
||||||
|
isObjectEmpty(); // true
|
||||||
|
isObjectEmpty(null); // true
|
||||||
|
isObjectEmpty(undefined); // true
|
||||||
|
isObjectEmpty(''); // true
|
||||||
|
isObjectEmpty([]); // true
|
||||||
|
isObjectEmpty({}); // true
|
||||||
|
isObjectEmpty({name: null}); // true
|
||||||
|
isObjectEmpty({ name: 'Adam Hawkins', surname : null}); // false
|
||||||
|
*/
|
||||||
|
it('should be empty if no parameter passed', () => {
|
||||||
|
expect(isObjectEmpty()).toBeTrue();
|
||||||
|
});
|
||||||
|
it('should be empty if null parameter passed', () => {
|
||||||
|
expect(isObjectEmpty(null)).toBeTrue();
|
||||||
|
});
|
||||||
|
it('should be empty if undefined parameter passed', () => {
|
||||||
|
expect(isObjectEmpty(undefined)).toBeTrue();
|
||||||
|
});
|
||||||
|
it('should be empty if empty string passed', () => {
|
||||||
|
expect(isObjectEmpty('')).toBeTrue();
|
||||||
|
});
|
||||||
|
it('should be empty if empty array passed', () => {
|
||||||
|
expect(isObjectEmpty([])).toBeTrue();
|
||||||
|
});
|
||||||
|
it('should be empty if empty object passed', () => {
|
||||||
|
expect(isObjectEmpty({})).toBeTrue();
|
||||||
|
});
|
||||||
|
it('should be empty if single key with null value passed', () => {
|
||||||
|
expect(isObjectEmpty({ name: null })).toBeTrue();
|
||||||
|
});
|
||||||
|
it('should NOT be empty if object with at least one non-null value passed', () => {
|
||||||
|
expect(isObjectEmpty({ name: 'Adam Hawkins', surname : null })).toBeFalse();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('ensureArrayHasValue', () => {
|
describe('ensureArrayHasValue', () => {
|
||||||
it('should let all arrays pass unchanged, and turn everything else in to empty arrays', () => {
|
it('should let all arrays pass unchanged, and turn everything else in to empty arrays', () => {
|
||||||
const sourceData = {
|
const sourceData = {
|
||||||
|
@@ -177,3 +177,29 @@ export const isNotEmptyOperator = () =>
|
|||||||
export const ensureArrayHasValue = () =>
|
export const ensureArrayHasValue = () =>
|
||||||
<T>(source: Observable<T[]>): Observable<T[]> =>
|
<T>(source: Observable<T[]>): Observable<T[]> =>
|
||||||
source.pipe(map((arr: T[]): T[] => Array.isArray(arr) ? arr : []));
|
source.pipe(map((arr: T[]): T[] => Array.isArray(arr) ? arr : []));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies that a object keys are all empty or not.
|
||||||
|
* isObjectEmpty(); // true
|
||||||
|
* isObjectEmpty(null); // true
|
||||||
|
* isObjectEmpty(undefined); // true
|
||||||
|
* isObjectEmpty(''); // true
|
||||||
|
* isObjectEmpty([]); // true
|
||||||
|
* isObjectEmpty({}); // true
|
||||||
|
* isObjectEmpty({name: null}); // true
|
||||||
|
* isObjectEmpty({ name: 'Adam Hawkins', surname : null}); // false
|
||||||
|
*/
|
||||||
|
export function isObjectEmpty(obj?: any): boolean {
|
||||||
|
|
||||||
|
if (typeof(obj) !== 'object') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const key in obj) {
|
||||||
|
if (obj.hasOwnProperty(key) && isNotEmpty(obj[key])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
<div [class.form-group]="(model.type !== 'GROUP' && asBootstrapFormGroup) || getClass('element', 'container').includes('form-group')"
|
<div [class.form-group]="(model.type !== 'GROUP' && asBootstrapFormGroup) || getClass('element', 'container').includes('form-group')"
|
||||||
|
[class.d-none]="model.hidden"
|
||||||
[formGroup]="group"
|
[formGroup]="group"
|
||||||
[ngClass]="[getClass('element', 'container'), getClass('grid', 'container')]">
|
[ngClass]="[getClass('element', 'container'), getClass('grid', 'container')]">
|
||||||
<label *ngIf="!isCheckbox && hasLabel"
|
<label *ngIf="!isCheckbox && hasLabel"
|
||||||
@@ -6,7 +7,7 @@
|
|||||||
[for]="id"
|
[for]="id"
|
||||||
[innerHTML]="(model.required && model.label) ? (model.label | translate) + ' *' : (model.label | translate)"
|
[innerHTML]="(model.required && model.label) ? (model.label | translate) + ' *' : (model.label | translate)"
|
||||||
[ngClass]="[getClass('element', 'label'), getClass('grid', 'label')]"></label>
|
[ngClass]="[getClass('element', 'label'), getClass('grid', 'label')]"></label>
|
||||||
<ng-container *ngTemplateOutlet="startTemplate?.templateRef; context: model"></ng-container>
|
<ng-container *ngTemplateOutlet="startTemplate?.templateRef; context: { $implicit: model };"></ng-container>
|
||||||
<!-- Should be *ngIf instead of class d-none, but that breaks the #componentViewContainer reference-->
|
<!-- Should be *ngIf instead of class d-none, but that breaks the #componentViewContainer reference-->
|
||||||
<div [ngClass]="{'form-row': model.hasLanguages || isRelationship,
|
<div [ngClass]="{'form-row': model.hasLanguages || isRelationship,
|
||||||
'd-none': value?.isVirtual && (model.hasSelectableMetadata || context?.index > 0)}">
|
'd-none': value?.isVirtual && (model.hasSelectableMetadata || context?.index > 0)}">
|
||||||
|
@@ -25,7 +25,7 @@ import {
|
|||||||
DynamicSliderModel,
|
DynamicSliderModel,
|
||||||
DynamicSwitchModel,
|
DynamicSwitchModel,
|
||||||
DynamicTextAreaModel,
|
DynamicTextAreaModel,
|
||||||
DynamicTimePickerModel
|
DynamicTimePickerModel, MATCH_VISIBLE, OR_OPERATOR
|
||||||
} from '@ng-dynamic-forms/core';
|
} from '@ng-dynamic-forms/core';
|
||||||
import {
|
import {
|
||||||
DynamicNGBootstrapCalendarComponent,
|
DynamicNGBootstrapCalendarComponent,
|
||||||
@@ -65,6 +65,7 @@ import { DsDynamicFormArrayComponent } from './models/array-group/dynamic-form-a
|
|||||||
import { DsDynamicFormGroupComponent } from './models/form-group/dynamic-form-group.component';
|
import { DsDynamicFormGroupComponent } from './models/form-group/dynamic-form-group.component';
|
||||||
import { DsDynamicRelationGroupComponent } from './models/relation-group/dynamic-relation-group.components';
|
import { DsDynamicRelationGroupComponent } from './models/relation-group/dynamic-relation-group.components';
|
||||||
import { DsDatePickerInlineComponent } from './models/date-picker-inline/dynamic-date-picker-inline.component';
|
import { DsDatePickerInlineComponent } from './models/date-picker-inline/dynamic-date-picker-inline.component';
|
||||||
|
import { DsDynamicTypeBindRelationService } from './ds-dynamic-type-bind-relation.service';
|
||||||
import { RelationshipService } from '../../../../core/data/relationship.service';
|
import { RelationshipService } from '../../../../core/data/relationship.service';
|
||||||
import { SelectableListService } from '../../../object-list/selectable-list/selectable-list.service';
|
import { SelectableListService } from '../../../object-list/selectable-list/selectable-list.service';
|
||||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||||
@@ -79,6 +80,14 @@ import { SubmissionService } from '../../../../submission/submission.service';
|
|||||||
import { FormBuilderService } from '../form-builder.service';
|
import { FormBuilderService } from '../form-builder.service';
|
||||||
import { NgxMaskModule } from 'ngx-mask';
|
import { NgxMaskModule } from 'ngx-mask';
|
||||||
|
|
||||||
|
function getMockDsDynamicTypeBindRelationService(): DsDynamicTypeBindRelationService {
|
||||||
|
return jasmine.createSpyObj('DsDynamicTypeBindRelationService', {
|
||||||
|
getRelatedFormModel: jasmine.createSpy('getRelatedFormModel'),
|
||||||
|
matchesCondition: jasmine.createSpy('matchesCondition'),
|
||||||
|
subscribeRelations: jasmine.createSpy('subscribeRelations')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
describe('DsDynamicFormControlContainerComponent test suite', () => {
|
describe('DsDynamicFormControlContainerComponent test suite', () => {
|
||||||
|
|
||||||
const vocabularyOptions: VocabularyOptions = {
|
const vocabularyOptions: VocabularyOptions = {
|
||||||
@@ -111,7 +120,12 @@ describe('DsDynamicFormControlContainerComponent test suite', () => {
|
|||||||
metadataFields: [],
|
metadataFields: [],
|
||||||
repeatable: false,
|
repeatable: false,
|
||||||
submissionId: '1234',
|
submissionId: '1234',
|
||||||
hasSelectableMetadata: false
|
hasSelectableMetadata: false,
|
||||||
|
typeBindRelations: [{
|
||||||
|
match: MATCH_VISIBLE,
|
||||||
|
operator: OR_OPERATOR,
|
||||||
|
when: [{id: 'dc.type', value: 'Book'}]
|
||||||
|
}]
|
||||||
}),
|
}),
|
||||||
new DynamicScrollableDropdownModel({
|
new DynamicScrollableDropdownModel({
|
||||||
id: 'scrollableDropdown',
|
id: 'scrollableDropdown',
|
||||||
@@ -200,6 +214,7 @@ describe('DsDynamicFormControlContainerComponent test suite', () => {
|
|||||||
providers: [
|
providers: [
|
||||||
DsDynamicFormControlContainerComponent,
|
DsDynamicFormControlContainerComponent,
|
||||||
DynamicFormService,
|
DynamicFormService,
|
||||||
|
{ provide: DsDynamicTypeBindRelationService, useValue: getMockDsDynamicTypeBindRelationService() },
|
||||||
{ provide: RelationshipService, useValue: {} },
|
{ provide: RelationshipService, useValue: {} },
|
||||||
{ provide: SelectableListService, useValue: {} },
|
{ provide: SelectableListService, useValue: {} },
|
||||||
{ provide: ItemDataService, useValue: {} },
|
{ provide: ItemDataService, useValue: {} },
|
||||||
@@ -231,7 +246,7 @@ describe('DsDynamicFormControlContainerComponent test suite', () => {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeEach(inject([DynamicFormService], (service: DynamicFormService) => {
|
beforeEach(inject([DynamicFormService, FormBuilderService], (service: DynamicFormService, formBuilderService: FormBuilderService) => {
|
||||||
|
|
||||||
formGroup = service.createFormGroup(formModel);
|
formGroup = service.createFormGroup(formModel);
|
||||||
|
|
||||||
|
@@ -81,6 +81,7 @@ import { DYNAMIC_FORM_CONTROL_TYPE_CUSTOM_SWITCH } from './models/custom-switch/
|
|||||||
import { CustomSwitchComponent } from './models/custom-switch/custom-switch.component';
|
import { CustomSwitchComponent } from './models/custom-switch/custom-switch.component';
|
||||||
import { find, map, startWith, switchMap, take } from 'rxjs/operators';
|
import { find, map, startWith, switchMap, take } from 'rxjs/operators';
|
||||||
import { combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
|
import { combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
|
||||||
|
import { DsDynamicTypeBindRelationService } from './ds-dynamic-type-bind-relation.service';
|
||||||
import { SearchResult } from '../../../search/models/search-result.model';
|
import { SearchResult } from '../../../search/models/search-result.model';
|
||||||
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
|
||||||
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
|
||||||
@@ -194,8 +195,10 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
|||||||
@ContentChildren(DynamicTemplateDirective) contentTemplateList: QueryList<DynamicTemplateDirective>;
|
@ContentChildren(DynamicTemplateDirective) contentTemplateList: QueryList<DynamicTemplateDirective>;
|
||||||
// eslint-disable-next-line @angular-eslint/no-input-rename
|
// eslint-disable-next-line @angular-eslint/no-input-rename
|
||||||
@Input('templates') inputTemplateList: QueryList<DynamicTemplateDirective>;
|
@Input('templates') inputTemplateList: QueryList<DynamicTemplateDirective>;
|
||||||
|
@Input() hasMetadataModel: any;
|
||||||
@Input() formId: string;
|
@Input() formId: string;
|
||||||
|
@Input() formGroup: FormGroup;
|
||||||
|
@Input() formModel: DynamicFormControlModel[];
|
||||||
@Input() asBootstrapFormGroup = false;
|
@Input() asBootstrapFormGroup = false;
|
||||||
@Input() bindId = true;
|
@Input() bindId = true;
|
||||||
@Input() context: any | null = null;
|
@Input() context: any | null = null;
|
||||||
@@ -237,6 +240,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
|||||||
protected dynamicFormComponentService: DynamicFormComponentService,
|
protected dynamicFormComponentService: DynamicFormComponentService,
|
||||||
protected layoutService: DynamicFormLayoutService,
|
protected layoutService: DynamicFormLayoutService,
|
||||||
protected validationService: DynamicFormValidationService,
|
protected validationService: DynamicFormValidationService,
|
||||||
|
protected typeBindRelationService: DsDynamicTypeBindRelationService,
|
||||||
protected translateService: TranslateService,
|
protected translateService: TranslateService,
|
||||||
protected relationService: DynamicFormRelationService,
|
protected relationService: DynamicFormRelationService,
|
||||||
private modalService: NgbModal,
|
private modalService: NgbModal,
|
||||||
@@ -343,6 +347,9 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
|||||||
if (this.model && this.model.placeholder) {
|
if (this.model && this.model.placeholder) {
|
||||||
this.model.placeholder = this.translateService.instant(this.model.placeholder);
|
this.model.placeholder = this.translateService.instant(this.model.placeholder);
|
||||||
}
|
}
|
||||||
|
if (this.model.typeBindRelations && this.model.typeBindRelations.length > 0) {
|
||||||
|
this.subscriptions.push(...this.typeBindRelationService.subscribeRelations(this.model, this.control));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,6 +364,22 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
|||||||
this.showErrorMessagesPreviousStage = this.showErrorMessages;
|
this.showErrorMessagesPreviousStage = this.showErrorMessages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected createFormControlComponent(): void {
|
||||||
|
super.createFormControlComponent();
|
||||||
|
if (this.componentType !== null) {
|
||||||
|
let index;
|
||||||
|
|
||||||
|
if (this.context && this.context instanceof DynamicFormArrayGroupModel) {
|
||||||
|
index = this.context.index;
|
||||||
|
}
|
||||||
|
const instance = this.dynamicFormComponentService.getFormControlRef(this.model, index);
|
||||||
|
if (instance) {
|
||||||
|
(instance as any).formModel = this.formModel;
|
||||||
|
(instance as any).formGroup = this.formGroup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Since Form Control Components created dynamically have 'OnPush' change detection strategy,
|
* Since Form Control Components created dynamically have 'OnPush' change detection strategy,
|
||||||
* changes are not propagated. So use this method to force an update
|
* changes are not propagated. So use this method to force an update
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
[group]="formGroup"
|
[group]="formGroup"
|
||||||
[hasErrorMessaging]="model.hasErrorMessages"
|
[hasErrorMessaging]="model.hasErrorMessages"
|
||||||
[hidden]="model.hidden"
|
[hidden]="model.hidden"
|
||||||
|
[class.d-none]="model.hidden"
|
||||||
[layout]="formLayout"
|
[layout]="formLayout"
|
||||||
[model]="model"
|
[model]="model"
|
||||||
[templates]="templates"
|
[templates]="templates"
|
||||||
|
@@ -0,0 +1,143 @@
|
|||||||
|
import {inject, TestBed} from '@angular/core/testing';
|
||||||
|
|
||||||
|
import {
|
||||||
|
DynamicFormControlRelation,
|
||||||
|
DynamicFormRelationService,
|
||||||
|
MATCH_VISIBLE,
|
||||||
|
OR_OPERATOR,
|
||||||
|
HIDDEN_MATCHER,
|
||||||
|
HIDDEN_MATCHER_PROVIDER, REQUIRED_MATCHER_PROVIDER, DISABLED_MATCHER_PROVIDER,
|
||||||
|
} from '@ng-dynamic-forms/core';
|
||||||
|
|
||||||
|
import {
|
||||||
|
mockInputWithTypeBindModel, MockRelationModel, mockDcTypeInputModel
|
||||||
|
} from '../../../mocks/form-models.mock';
|
||||||
|
import {DsDynamicTypeBindRelationService} from './ds-dynamic-type-bind-relation.service';
|
||||||
|
import {FormFieldMetadataValueObject} from '../models/form-field-metadata-value.model';
|
||||||
|
import {FormControl, ReactiveFormsModule} from '@angular/forms';
|
||||||
|
import {FormBuilderService} from '../form-builder.service';
|
||||||
|
import {getMockFormBuilderService} from '../../../mocks/form-builder-service.mock';
|
||||||
|
import {Injector} from '@angular/core';
|
||||||
|
|
||||||
|
describe('DSDynamicTypeBindRelationService test suite', () => {
|
||||||
|
let service: DsDynamicTypeBindRelationService;
|
||||||
|
let dynamicFormRelationService: DynamicFormRelationService;
|
||||||
|
let injector: Injector;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [ReactiveFormsModule],
|
||||||
|
providers: [
|
||||||
|
{ provide: FormBuilderService, useValue: getMockFormBuilderService() },
|
||||||
|
{ provide: DsDynamicTypeBindRelationService, useClass: DsDynamicTypeBindRelationService },
|
||||||
|
{ provide: DynamicFormRelationService },
|
||||||
|
DISABLED_MATCHER_PROVIDER, HIDDEN_MATCHER_PROVIDER, REQUIRED_MATCHER_PROVIDER
|
||||||
|
]
|
||||||
|
}).compileComponents().then();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(inject([DsDynamicTypeBindRelationService, DynamicFormRelationService],
|
||||||
|
(relationService: DsDynamicTypeBindRelationService,
|
||||||
|
formRelationService: DynamicFormRelationService,
|
||||||
|
) => {
|
||||||
|
service = relationService;
|
||||||
|
dynamicFormRelationService = formRelationService;
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('Test getTypeBindValue method', () => {
|
||||||
|
it('Should get type bind "boundType" from the given metadata object value', () => {
|
||||||
|
const mockMetadataValueObject: FormFieldMetadataValueObject = new FormFieldMetadataValueObject(
|
||||||
|
'boundType', null, null, 'Bound Type'
|
||||||
|
);
|
||||||
|
const bindType = service.getTypeBindValue(mockMetadataValueObject);
|
||||||
|
expect(bindType).toBe('boundType');
|
||||||
|
});
|
||||||
|
it('Should get type authority key "bound-auth-key" from the given metadata object value', () => {
|
||||||
|
const mockMetadataValueObject: FormFieldMetadataValueObject = new FormFieldMetadataValueObject(
|
||||||
|
'boundType', null, 'bound-auth-key', 'Bound Type'
|
||||||
|
);
|
||||||
|
const bindType = service.getTypeBindValue(mockMetadataValueObject);
|
||||||
|
expect(bindType).toBe('bound-auth-key');
|
||||||
|
});
|
||||||
|
it('Should get passed string returned directly as string passed instead of metadata', () => {
|
||||||
|
const bindType = service.getTypeBindValue('rawString');
|
||||||
|
expect(bindType).toBe('rawString');
|
||||||
|
});
|
||||||
|
it('Should get "undefined" returned directly as no object given', () => {
|
||||||
|
const bindType = service.getTypeBindValue(undefined);
|
||||||
|
expect(bindType).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Test getRelatedFormModel method', () => {
|
||||||
|
it('Should get 0 related form models for simple type bind mock data', () => {
|
||||||
|
const testModel = MockRelationModel;
|
||||||
|
const relatedModels = service.getRelatedFormModel(testModel);
|
||||||
|
expect(relatedModels).toHaveSize(0);
|
||||||
|
});
|
||||||
|
it('Should get 1 related form models for mock relation model data', () => {
|
||||||
|
const testModel = mockInputWithTypeBindModel;
|
||||||
|
testModel.typeBindRelations = getTypeBindRelations(['boundType']);
|
||||||
|
const relatedModels = service.getRelatedFormModel(testModel);
|
||||||
|
expect(relatedModels).toHaveSize(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Test matchesCondition method', () => {
|
||||||
|
it('Should receive one subscription to dc.type type binding"', () => {
|
||||||
|
const testModel = mockInputWithTypeBindModel;
|
||||||
|
testModel.typeBindRelations = getTypeBindRelations(['boundType']);
|
||||||
|
const dcTypeControl = new FormControl();
|
||||||
|
dcTypeControl.setValue('boundType');
|
||||||
|
let subscriptions = service.subscribeRelations(testModel, dcTypeControl);
|
||||||
|
expect(subscriptions).toHaveSize(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Expect hasMatch to be true (ie. this should be hidden)', () => {
|
||||||
|
const testModel = mockInputWithTypeBindModel;
|
||||||
|
testModel.typeBindRelations = getTypeBindRelations(['boundType']);
|
||||||
|
const dcTypeControl = new FormControl();
|
||||||
|
dcTypeControl.setValue('boundType');
|
||||||
|
testModel.typeBindRelations[0].when[0].value = 'anotherType';
|
||||||
|
const relation = dynamicFormRelationService.findRelationByMatcher((testModel as any).typeBindRelations, HIDDEN_MATCHER);
|
||||||
|
const matcher = HIDDEN_MATCHER;
|
||||||
|
if (relation !== undefined) {
|
||||||
|
const hasMatch = service.matchesCondition(relation, matcher);
|
||||||
|
matcher.onChange(hasMatch, testModel, dcTypeControl, injector);
|
||||||
|
expect(hasMatch).toBeTruthy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Expect hasMatch to be false (ie. this should NOT be hidden)', () => {
|
||||||
|
const testModel = mockInputWithTypeBindModel;
|
||||||
|
testModel.typeBindRelations = getTypeBindRelations(['boundType']);
|
||||||
|
const dcTypeControl = new FormControl();
|
||||||
|
dcTypeControl.setValue('boundType');
|
||||||
|
testModel.typeBindRelations[0].when[0].value = 'boundType';
|
||||||
|
const relation = dynamicFormRelationService.findRelationByMatcher((testModel as any).typeBindRelations, HIDDEN_MATCHER);
|
||||||
|
const matcher = HIDDEN_MATCHER;
|
||||||
|
if (relation !== undefined) {
|
||||||
|
const hasMatch = service.matchesCondition(relation, matcher);
|
||||||
|
matcher.onChange(hasMatch, testModel, dcTypeControl, injector);
|
||||||
|
expect(hasMatch).toBeFalsy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
function getTypeBindRelations(configuredTypeBindValues: string[]): DynamicFormControlRelation[] {
|
||||||
|
const bindValues = [];
|
||||||
|
configuredTypeBindValues.forEach((value) => {
|
||||||
|
bindValues.push({
|
||||||
|
id: 'dc.type',
|
||||||
|
value: value
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return [{
|
||||||
|
match: MATCH_VISIBLE,
|
||||||
|
operator: OR_OPERATOR,
|
||||||
|
when: bindValues
|
||||||
|
}];
|
||||||
|
}
|
@@ -0,0 +1,230 @@
|
|||||||
|
import { Inject, Injectable, Injector, Optional } from '@angular/core';
|
||||||
|
import { FormControl } from '@angular/forms';
|
||||||
|
|
||||||
|
import { Subscription } from 'rxjs';
|
||||||
|
import { startWith } from 'rxjs/operators';
|
||||||
|
|
||||||
|
import {
|
||||||
|
AND_OPERATOR,
|
||||||
|
DYNAMIC_MATCHERS,
|
||||||
|
DynamicFormControlCondition,
|
||||||
|
DynamicFormControlMatcher,
|
||||||
|
DynamicFormControlModel,
|
||||||
|
DynamicFormControlRelation,
|
||||||
|
DynamicFormRelationService, MATCH_VISIBLE,
|
||||||
|
OR_OPERATOR
|
||||||
|
} from '@ng-dynamic-forms/core';
|
||||||
|
|
||||||
|
import {hasNoValue, hasValue} from '../../../empty.util';
|
||||||
|
import { FormBuilderService } from '../form-builder.service';
|
||||||
|
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||||
|
import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from './ds-dynamic-form-constants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service to manage type binding for submission input fields
|
||||||
|
* Any form component with the typeBindRelations DynamicFormControlRelation property can be controlled this way
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class DsDynamicTypeBindRelationService {
|
||||||
|
|
||||||
|
constructor(@Optional() @Inject(DYNAMIC_MATCHERS) private dynamicMatchers: DynamicFormControlMatcher[],
|
||||||
|
protected dynamicFormRelationService: DynamicFormRelationService,
|
||||||
|
protected formBuilderService: FormBuilderService,
|
||||||
|
protected injector: Injector) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the string value of the type bind model
|
||||||
|
* @param bindModelValue
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
public getTypeBindValue(bindModelValue: string | FormFieldMetadataValueObject): string {
|
||||||
|
let value;
|
||||||
|
if (hasNoValue(bindModelValue) || typeof bindModelValue === 'string') {
|
||||||
|
value = bindModelValue;
|
||||||
|
} else if (bindModelValue instanceof FormFieldMetadataValueObject
|
||||||
|
&& bindModelValue.hasAuthority()) {
|
||||||
|
value = bindModelValue.authority;
|
||||||
|
} else {
|
||||||
|
value = bindModelValue.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get models for this bind type
|
||||||
|
* @param model
|
||||||
|
*/
|
||||||
|
public getRelatedFormModel(model: DynamicFormControlModel): DynamicFormControlModel[] {
|
||||||
|
|
||||||
|
const models: DynamicFormControlModel[] = [];
|
||||||
|
|
||||||
|
(model as any).typeBindRelations.forEach((relGroup) => relGroup.when.forEach((rel) => {
|
||||||
|
|
||||||
|
if (model.id === rel.id) {
|
||||||
|
throw new Error(`FormControl ${model.id} cannot depend on itself`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const bindModel: DynamicFormControlModel = this.formBuilderService.getTypeBindModel();
|
||||||
|
|
||||||
|
if (model && !models.some((modelElement) => modelElement === bindModel)) {
|
||||||
|
models.push(bindModel);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
return models;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return false if the type bind relation (eg. {MATCH_VISIBLE, OR, ['book', 'book part']}) matches the value in
|
||||||
|
* matcher.match or true if the opposite match. Since this is called with regard to actively *hiding* a form
|
||||||
|
* component, the negation of the comparison is returned.
|
||||||
|
* @param relation type bind relation (eg. {MATCH_VISIBLE, OR, ['book', 'book part']})
|
||||||
|
* @param matcher contains 'match' value and an onChange() event listener
|
||||||
|
*/
|
||||||
|
public matchesCondition(relation: DynamicFormControlRelation, matcher: DynamicFormControlMatcher): boolean {
|
||||||
|
|
||||||
|
// Default to OR for operator (OR is explicitly set in field-parser.ts anyway)
|
||||||
|
const operator = relation.operator || OR_OPERATOR;
|
||||||
|
|
||||||
|
|
||||||
|
return relation.when.reduce((hasAlreadyMatched: boolean, condition: DynamicFormControlCondition, index: number) => {
|
||||||
|
// Get the DynamicFormControlModel (typeBindModel) from the form builder service, set in the form builder
|
||||||
|
// in the form model at init time in formBuilderService.modelFromConfiguration (called by other form components
|
||||||
|
// like relation group component and submission section form component).
|
||||||
|
// This model (DynamicRelationGroupModel) contains eg. mandatory field, formConfiguration, relationFields,
|
||||||
|
// submission scope, form/section type and other high level properties
|
||||||
|
const bindModel: any = this.formBuilderService.getTypeBindModel();
|
||||||
|
|
||||||
|
let values: string[];
|
||||||
|
let bindModelValue = bindModel.value;
|
||||||
|
|
||||||
|
// If the form type is RELATION, set bindModelValue to the mandatory field for this model, otherwise leave
|
||||||
|
// as plain value
|
||||||
|
if (bindModel.type === DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP) {
|
||||||
|
bindModelValue = bindModel.value.map((entry) => entry[bindModel.mandatoryField]);
|
||||||
|
}
|
||||||
|
// Support multiple bind models
|
||||||
|
if (Array.isArray(bindModelValue)) {
|
||||||
|
values = [...bindModelValue.map((entry) => this.getTypeBindValue(entry))];
|
||||||
|
} else {
|
||||||
|
values = [this.getTypeBindValue(bindModelValue)];
|
||||||
|
}
|
||||||
|
|
||||||
|
// If bind model evaluates to 'true' (is not undefined, is not null, is not false etc,
|
||||||
|
// AND the relation match (type bind) is equal to the matcher match (item publication type), then the return
|
||||||
|
// value is initialised as false.
|
||||||
|
let returnValue = (!(bindModel && relation.match === matcher.match));
|
||||||
|
|
||||||
|
// Iterate the type bind values parsed and mapped from our form/relation group model
|
||||||
|
for (const value of values) {
|
||||||
|
if (bindModel && relation.match === matcher.match) {
|
||||||
|
// If we're not at the first array element, and we're using the AND operator, and we have not
|
||||||
|
// yet matched anything, return false.
|
||||||
|
if (index > 0 && operator === AND_OPERATOR && !hasAlreadyMatched) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// If we're not at the first array element, and we're using the OR operator (almost always the case)
|
||||||
|
// and we've already matched then there is no need to continue, just return true.
|
||||||
|
if (index > 0 && operator === OR_OPERATOR && hasAlreadyMatched) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do the actual match. Does condition.value (the item publication type) match the field model
|
||||||
|
// type bind currently being inspected?
|
||||||
|
returnValue = condition.value === value;
|
||||||
|
|
||||||
|
// If return value is already true, break.
|
||||||
|
if (returnValue) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test opposingMatch (eg. if match is VISIBLE, opposingMatch will be HIDDEN)
|
||||||
|
if (bindModel && relation.match === matcher.opposingMatch) {
|
||||||
|
// If we're not at the first element, using AND, and already matched, just return true here
|
||||||
|
if (index > 0 && operator === AND_OPERATOR && hasAlreadyMatched) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we're not at the first element, using OR, and we have NOT already matched, return false
|
||||||
|
if (index > 0 && operator === OR_OPERATOR && !hasAlreadyMatched) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Negated comparison for return value since this is expected to be in the context of a HIDDEN_MATCHER
|
||||||
|
returnValue = !(condition.value === value);
|
||||||
|
|
||||||
|
// Break if already false
|
||||||
|
if (!returnValue) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnValue;
|
||||||
|
}, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of subscriptions to a calling component
|
||||||
|
* @param model
|
||||||
|
* @param control
|
||||||
|
*/
|
||||||
|
subscribeRelations(model: DynamicFormControlModel, control: FormControl): Subscription[] {
|
||||||
|
|
||||||
|
const relatedModels = this.getRelatedFormModel(model);
|
||||||
|
const subscriptions: Subscription[] = [];
|
||||||
|
|
||||||
|
Object.values(relatedModels).forEach((relatedModel: any) => {
|
||||||
|
|
||||||
|
if (hasValue(relatedModel)) {
|
||||||
|
const initValue = (hasNoValue(relatedModel.value) || typeof relatedModel.value === 'string') ? relatedModel.value :
|
||||||
|
(Array.isArray(relatedModel.value) ? relatedModel.value : relatedModel.value.value);
|
||||||
|
|
||||||
|
const valueChanges = relatedModel.valueChanges.pipe(
|
||||||
|
startWith(initValue)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Build up the subscriptions to watch for changes;
|
||||||
|
subscriptions.push(valueChanges.subscribe(() => {
|
||||||
|
// Iterate each matcher
|
||||||
|
if (hasValue(this.dynamicMatchers)) {
|
||||||
|
this.dynamicMatchers.forEach((matcher) => {
|
||||||
|
// Find the relation
|
||||||
|
const relation = this.dynamicFormRelationService.findRelationByMatcher((model as any).typeBindRelations, matcher);
|
||||||
|
// If the relation is defined, get matchesCondition result and pass it to the onChange event listener
|
||||||
|
if (relation !== undefined) {
|
||||||
|
const hasMatch = this.matchesCondition(relation, matcher);
|
||||||
|
matcher.onChange(hasMatch, model, control, this.injector);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return subscriptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to construct a typeBindRelations array
|
||||||
|
* @param configuredTypeBindValues
|
||||||
|
*/
|
||||||
|
public getTypeBindRelations(configuredTypeBindValues: string[]): DynamicFormControlRelation[] {
|
||||||
|
const bindValues = [];
|
||||||
|
configuredTypeBindValues.forEach((value) => {
|
||||||
|
bindValues.push({
|
||||||
|
id: 'dc.type',
|
||||||
|
value: value
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return [{
|
||||||
|
match: MATCH_VISIBLE,
|
||||||
|
operator: OR_OPERATOR,
|
||||||
|
when: bindValues
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,6 +1,7 @@
|
|||||||
<ng-container [formGroup]="group">
|
<ng-container [formGroup]="group">
|
||||||
<div [id]="id"
|
<div [id]="id"
|
||||||
[formArrayName]="model.id"
|
[formArrayName]="model.id"
|
||||||
|
[class.d-none]="model.hidden"
|
||||||
[ngClass]="getClass('element', 'control')">
|
[ngClass]="getClass('element', 'control')">
|
||||||
|
|
||||||
<!-- Draggable Container -->
|
<!-- Draggable Container -->
|
||||||
@@ -13,7 +14,8 @@
|
|||||||
cdkDrag
|
cdkDrag
|
||||||
cdkDragHandle
|
cdkDragHandle
|
||||||
[cdkDragDisabled]="dragDisabled"
|
[cdkDragDisabled]="dragDisabled"
|
||||||
[cdkDragPreviewClass]="'ds-submission-reorder-dragging'">
|
[cdkDragPreviewClass]="'ds-submission-reorder-dragging'"
|
||||||
|
[class.grey-background]="model.isInlineGroupArray">
|
||||||
<!-- Item content -->
|
<!-- Item content -->
|
||||||
<div class="drag-handle" [class.drag-disable]="dragDisabled" tabindex="0">
|
<div class="drag-handle" [class.drag-disable]="dragDisabled" tabindex="0">
|
||||||
<i class="drag-icon fas fa-grip-vertical fa-fw" [class.drag-disable]="dragDisabled" ></i>
|
<i class="drag-icon fas fa-grip-vertical fa-fw" [class.drag-disable]="dragDisabled" ></i>
|
||||||
@@ -22,9 +24,11 @@
|
|||||||
<ds-dynamic-form-control-container *ngFor="let _model of groupModel.group"
|
<ds-dynamic-form-control-container *ngFor="let _model of groupModel.group"
|
||||||
[bindId]="false"
|
[bindId]="false"
|
||||||
[formGroup]="group"
|
[formGroup]="group"
|
||||||
|
[formModel]="formModel"
|
||||||
[context]="groupModel"
|
[context]="groupModel"
|
||||||
[group]="control.get([idx])"
|
[group]="control.get([idx])"
|
||||||
[hidden]="_model.hidden"
|
[hidden]="_model.hidden"
|
||||||
|
[class.d-none]="_model.hidden"
|
||||||
[layout]="formLayout"
|
[layout]="formLayout"
|
||||||
[model]="_model"
|
[model]="_model"
|
||||||
[templates]="templates"
|
[templates]="templates"
|
||||||
@@ -37,9 +41,6 @@
|
|||||||
<ng-container *ngTemplateOutlet="endTemplate?.templateRef; context: groupModel"></ng-container>
|
<ng-container *ngTemplateOutlet="endTemplate?.templateRef; context: groupModel"></ng-container>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
@@ -6,6 +6,7 @@ import {
|
|||||||
DynamicFormControlCustomEvent,
|
DynamicFormControlCustomEvent,
|
||||||
DynamicFormControlEvent,
|
DynamicFormControlEvent,
|
||||||
DynamicFormControlLayout,
|
DynamicFormControlLayout,
|
||||||
|
DynamicFormControlModel,
|
||||||
DynamicFormLayout,
|
DynamicFormLayout,
|
||||||
DynamicFormLayoutService,
|
DynamicFormLayoutService,
|
||||||
DynamicFormValidationService,
|
DynamicFormValidationService,
|
||||||
@@ -22,6 +23,8 @@ import { DynamicRowArrayModel } from '../ds-dynamic-row-array-model';
|
|||||||
})
|
})
|
||||||
export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent {
|
export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent {
|
||||||
|
|
||||||
|
@Input() bindId = true;
|
||||||
|
@Input() formModel: DynamicFormControlModel[];
|
||||||
@Input() formLayout: DynamicFormLayout;
|
@Input() formLayout: DynamicFormLayout;
|
||||||
@Input() group: FormGroup;
|
@Input() group: FormGroup;
|
||||||
@Input() layout: DynamicFormControlLayout;
|
@Input() layout: DynamicFormControlLayout;
|
||||||
|
@@ -2,20 +2,29 @@ import {
|
|||||||
DynamicDateControlModel,
|
DynamicDateControlModel,
|
||||||
DynamicDatePickerModelConfig,
|
DynamicDatePickerModelConfig,
|
||||||
DynamicFormControlLayout,
|
DynamicFormControlLayout,
|
||||||
|
DynamicFormControlModel,
|
||||||
|
DynamicFormControlRelation,
|
||||||
serializable
|
serializable
|
||||||
} from '@ng-dynamic-forms/core';
|
} from '@ng-dynamic-forms/core';
|
||||||
|
import {BehaviorSubject, Subject} from 'rxjs';
|
||||||
|
import {isEmpty, isNotUndefined} from '../../../../../empty.util';
|
||||||
|
import {MetadataValue} from '../../../../../../core/shared/metadata.models';
|
||||||
|
|
||||||
export const DYNAMIC_FORM_CONTROL_TYPE_DSDATEPICKER = 'DATE';
|
export const DYNAMIC_FORM_CONTROL_TYPE_DSDATEPICKER = 'DATE';
|
||||||
|
|
||||||
export interface DynamicDsDateControlModelConfig extends DynamicDatePickerModelConfig {
|
export interface DynamicDsDateControlModelConfig extends DynamicDatePickerModelConfig {
|
||||||
legend?: string;
|
legend?: string;
|
||||||
|
typeBindRelations?: DynamicFormControlRelation[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dynamic Date Picker Model class
|
* Dynamic Date Picker Model class
|
||||||
*/
|
*/
|
||||||
export class DynamicDsDatePickerModel extends DynamicDateControlModel {
|
export class DynamicDsDatePickerModel extends DynamicDateControlModel {
|
||||||
|
@serializable() hiddenUpdates: Subject<boolean>;
|
||||||
|
@serializable() typeBindRelations: DynamicFormControlRelation[];
|
||||||
@serializable() readonly type: string = DYNAMIC_FORM_CONTROL_TYPE_DSDATEPICKER;
|
@serializable() readonly type: string = DYNAMIC_FORM_CONTROL_TYPE_DSDATEPICKER;
|
||||||
|
@serializable() metadataValue: MetadataValue;
|
||||||
malformedDate: boolean;
|
malformedDate: boolean;
|
||||||
legend: string;
|
legend: string;
|
||||||
hasLanguages = false;
|
hasLanguages = false;
|
||||||
@@ -25,6 +34,23 @@ export class DynamicDsDatePickerModel extends DynamicDateControlModel {
|
|||||||
super(config, layout);
|
super(config, layout);
|
||||||
this.malformedDate = false;
|
this.malformedDate = false;
|
||||||
this.legend = config.legend;
|
this.legend = config.legend;
|
||||||
|
this.metadataValue = (config as any).metadataValue;
|
||||||
|
this.typeBindRelations = config.typeBindRelations ? config.typeBindRelations : [];
|
||||||
|
this.hiddenUpdates = new BehaviorSubject<boolean>(this.hidden);
|
||||||
|
|
||||||
|
// This was a subscription, then an async setTimeout, but it seems unnecessary
|
||||||
|
const parentModel = this.getRootParent(this);
|
||||||
|
if (parentModel && isNotUndefined(parentModel.hidden)) {
|
||||||
|
parentModel.hidden = this.hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private getRootParent(model: any): DynamicFormControlModel {
|
||||||
|
if (isEmpty(model) || isEmpty(model.parent)) {
|
||||||
|
return model;
|
||||||
|
} else {
|
||||||
|
return this.getRootParent(model.parent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
DynamicFormControlLayout,
|
DynamicFormControlLayout,
|
||||||
|
DynamicFormControlRelation,
|
||||||
DynamicInputModel,
|
DynamicInputModel,
|
||||||
DynamicInputModelConfig,
|
DynamicInputModelConfig,
|
||||||
serializable
|
serializable
|
||||||
@@ -18,12 +19,14 @@ export interface DsDynamicInputModelConfig extends DynamicInputModelConfig {
|
|||||||
language?: string;
|
language?: string;
|
||||||
place?: number;
|
place?: number;
|
||||||
value?: any;
|
value?: any;
|
||||||
|
typeBindRelations?: DynamicFormControlRelation[];
|
||||||
relationship?: RelationshipOptions;
|
relationship?: RelationshipOptions;
|
||||||
repeatable: boolean;
|
repeatable: boolean;
|
||||||
metadataFields: string[];
|
metadataFields: string[];
|
||||||
submissionId: string;
|
submissionId: string;
|
||||||
hasSelectableMetadata: boolean;
|
hasSelectableMetadata: boolean;
|
||||||
metadataValue?: FormFieldMetadataValueObject;
|
metadataValue?: FormFieldMetadataValueObject;
|
||||||
|
isModelOfInnerForm?: boolean;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,12 +36,17 @@ export class DsDynamicInputModel extends DynamicInputModel {
|
|||||||
@serializable() private _languageCodes: LanguageCode[];
|
@serializable() private _languageCodes: LanguageCode[];
|
||||||
@serializable() private _language: string;
|
@serializable() private _language: string;
|
||||||
@serializable() languageUpdates: Subject<string>;
|
@serializable() languageUpdates: Subject<string>;
|
||||||
|
@serializable() place: number;
|
||||||
|
@serializable() typeBindRelations: DynamicFormControlRelation[];
|
||||||
|
@serializable() typeBindHidden = false;
|
||||||
@serializable() relationship?: RelationshipOptions;
|
@serializable() relationship?: RelationshipOptions;
|
||||||
@serializable() repeatable?: boolean;
|
@serializable() repeatable?: boolean;
|
||||||
@serializable() metadataFields: string[];
|
@serializable() metadataFields: string[];
|
||||||
@serializable() submissionId: string;
|
@serializable() submissionId: string;
|
||||||
@serializable() hasSelectableMetadata: boolean;
|
@serializable() hasSelectableMetadata: boolean;
|
||||||
@serializable() metadataValue: FormFieldMetadataValueObject;
|
@serializable() metadataValue: FormFieldMetadataValueObject;
|
||||||
|
@serializable() isModelOfInnerForm: boolean;
|
||||||
|
|
||||||
|
|
||||||
constructor(config: DsDynamicInputModelConfig, layout?: DynamicFormControlLayout) {
|
constructor(config: DsDynamicInputModelConfig, layout?: DynamicFormControlLayout) {
|
||||||
super(config, layout);
|
super(config, layout);
|
||||||
@@ -51,6 +59,8 @@ export class DsDynamicInputModel extends DynamicInputModel {
|
|||||||
this.submissionId = config.submissionId;
|
this.submissionId = config.submissionId;
|
||||||
this.hasSelectableMetadata = config.hasSelectableMetadata;
|
this.hasSelectableMetadata = config.hasSelectableMetadata;
|
||||||
this.metadataValue = config.metadataValue;
|
this.metadataValue = config.metadataValue;
|
||||||
|
this.place = config.place;
|
||||||
|
this.isModelOfInnerForm = (hasValue(config.isModelOfInnerForm) ? config.isModelOfInnerForm : false);
|
||||||
|
|
||||||
this.language = config.language;
|
this.language = config.language;
|
||||||
if (!this.language) {
|
if (!this.language) {
|
||||||
@@ -71,6 +81,8 @@ export class DsDynamicInputModel extends DynamicInputModel {
|
|||||||
this.language = lang;
|
this.language = lang;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.typeBindRelations = config.typeBindRelations ? config.typeBindRelations : [];
|
||||||
|
|
||||||
this.vocabularyOptions = config.vocabularyOptions;
|
this.vocabularyOptions = config.vocabularyOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
import { DynamicFormArrayModel, DynamicFormArrayModelConfig, DynamicFormControlLayout, serializable } from '@ng-dynamic-forms/core';
|
import {
|
||||||
|
DynamicFormArrayModel,
|
||||||
|
DynamicFormArrayModelConfig,
|
||||||
|
DynamicFormControlLayout,
|
||||||
|
DynamicFormControlRelation,
|
||||||
|
serializable
|
||||||
|
} from '@ng-dynamic-forms/core';
|
||||||
import { RelationshipOptions } from '../../models/relationship-options.model';
|
import { RelationshipOptions } from '../../models/relationship-options.model';
|
||||||
|
import { hasValue } from '../../../../empty.util';
|
||||||
|
|
||||||
export interface DynamicRowArrayModelConfig extends DynamicFormArrayModelConfig {
|
export interface DynamicRowArrayModelConfig extends DynamicFormArrayModelConfig {
|
||||||
notRepeatable: boolean;
|
notRepeatable: boolean;
|
||||||
@@ -10,6 +17,9 @@ export interface DynamicRowArrayModelConfig extends DynamicFormArrayModelConfig
|
|||||||
metadataFields: string[];
|
metadataFields: string[];
|
||||||
hasSelectableMetadata: boolean;
|
hasSelectableMetadata: boolean;
|
||||||
isDraggable: boolean;
|
isDraggable: boolean;
|
||||||
|
showButtons: boolean;
|
||||||
|
typeBindRelations?: DynamicFormControlRelation[];
|
||||||
|
isInlineGroupArray?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DynamicRowArrayModel extends DynamicFormArrayModel {
|
export class DynamicRowArrayModel extends DynamicFormArrayModel {
|
||||||
@@ -21,17 +31,29 @@ export class DynamicRowArrayModel extends DynamicFormArrayModel {
|
|||||||
@serializable() metadataFields: string[];
|
@serializable() metadataFields: string[];
|
||||||
@serializable() hasSelectableMetadata: boolean;
|
@serializable() hasSelectableMetadata: boolean;
|
||||||
@serializable() isDraggable: boolean;
|
@serializable() isDraggable: boolean;
|
||||||
|
@serializable() showButtons = true;
|
||||||
|
@serializable() typeBindRelations: DynamicFormControlRelation[];
|
||||||
isRowArray = true;
|
isRowArray = true;
|
||||||
|
isInlineGroupArray = false;
|
||||||
|
|
||||||
constructor(config: DynamicRowArrayModelConfig, layout?: DynamicFormControlLayout) {
|
constructor(config: DynamicRowArrayModelConfig, layout?: DynamicFormControlLayout) {
|
||||||
super(config, layout);
|
super(config, layout);
|
||||||
|
if (hasValue(config.notRepeatable)) {
|
||||||
this.notRepeatable = config.notRepeatable;
|
this.notRepeatable = config.notRepeatable;
|
||||||
|
}
|
||||||
|
if (hasValue(config.required)) {
|
||||||
this.required = config.required;
|
this.required = config.required;
|
||||||
|
}
|
||||||
|
if (hasValue(config.showButtons)) {
|
||||||
|
this.showButtons = config.showButtons;
|
||||||
|
}
|
||||||
this.submissionId = config.submissionId;
|
this.submissionId = config.submissionId;
|
||||||
this.relationshipConfig = config.relationshipConfig;
|
this.relationshipConfig = config.relationshipConfig;
|
||||||
this.metadataKey = config.metadataKey;
|
this.metadataKey = config.metadataKey;
|
||||||
this.metadataFields = config.metadataFields;
|
this.metadataFields = config.metadataFields;
|
||||||
this.hasSelectableMetadata = config.hasSelectableMetadata;
|
this.hasSelectableMetadata = config.hasSelectableMetadata;
|
||||||
this.isDraggable = config.isDraggable;
|
this.isDraggable = config.isDraggable;
|
||||||
|
this.typeBindRelations = config.typeBindRelations ? config.typeBindRelations : [];
|
||||||
|
this.isInlineGroupArray = config.isInlineGroupArray ? config.isInlineGroupArray : false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,17 @@
|
|||||||
|
<div style="width: 100%">
|
||||||
<ng-container [formGroup]="group">
|
<ng-container [formGroup]="group">
|
||||||
|
|
||||||
<div role="group" [formGroupName]="model.id" [id]="id" [ngClass]="getClass('element','control')">
|
<div role="group" [formGroupName]="model.id"
|
||||||
|
[id]="id"
|
||||||
|
[class.d-none]="model.hidden"
|
||||||
|
[ngClass]="getClass('element','control')">
|
||||||
<ds-dynamic-form-control-container *ngFor="let _model of model.group"
|
<ds-dynamic-form-control-container *ngFor="let _model of model.group"
|
||||||
|
[formGroup]="group"
|
||||||
|
[formModel]="formModel"
|
||||||
[group]="control"
|
[group]="control"
|
||||||
[hasErrorMessaging]="model.hasErrorMessages"
|
[hasErrorMessaging]="model.hasErrorMessages"
|
||||||
[hidden]="_model.hidden"
|
[hidden]="_model.hidden"
|
||||||
|
[class.d-none]="_model.hidden"
|
||||||
[layout]="formLayout"
|
[layout]="formLayout"
|
||||||
[model]="_model"
|
[model]="_model"
|
||||||
[templates]="templates"
|
[templates]="templates"
|
||||||
@@ -16,3 +22,4 @@
|
|||||||
(ngbEvent)="onCustomEvent($event, null, true)"></ds-dynamic-form-control-container>
|
(ngbEvent)="onCustomEvent($event, null, true)"></ds-dynamic-form-control-container>
|
||||||
</div>
|
</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
</div>
|
||||||
|
@@ -5,7 +5,9 @@ import {
|
|||||||
DynamicFormControlCustomEvent,
|
DynamicFormControlCustomEvent,
|
||||||
DynamicFormControlEvent,
|
DynamicFormControlEvent,
|
||||||
DynamicFormControlLayout,
|
DynamicFormControlLayout,
|
||||||
DynamicFormGroupModel, DynamicFormLayout,
|
DynamicFormControlModel,
|
||||||
|
DynamicFormGroupModel,
|
||||||
|
DynamicFormLayout,
|
||||||
DynamicFormLayoutService,
|
DynamicFormLayoutService,
|
||||||
DynamicFormValidationService,
|
DynamicFormValidationService,
|
||||||
DynamicTemplateDirective
|
DynamicTemplateDirective
|
||||||
@@ -18,6 +20,7 @@ import {
|
|||||||
})
|
})
|
||||||
export class DsDynamicFormGroupComponent extends DynamicFormControlComponent {
|
export class DsDynamicFormGroupComponent extends DynamicFormControlComponent {
|
||||||
|
|
||||||
|
@Input() formModel: DynamicFormControlModel[];
|
||||||
@Input() formLayout: DynamicFormLayout;
|
@Input() formLayout: DynamicFormLayout;
|
||||||
@Input() group: FormGroup;
|
@Input() group: FormGroup;
|
||||||
@Input() layout: DynamicFormControlLayout;
|
@Input() layout: DynamicFormControlLayout;
|
||||||
|
@@ -45,9 +45,6 @@
|
|||||||
<div *ngFor="let columnItems of items" class="col-sm ml-3">
|
<div *ngFor="let columnItems of items" class="col-sm ml-3">
|
||||||
|
|
||||||
<div *ngFor="let item of columnItems" class="custom-control custom-radio">
|
<div *ngFor="let item of columnItems" class="custom-control custom-radio">
|
||||||
<label class="custom-control-label"
|
|
||||||
[class.disabled]="model.disabled"
|
|
||||||
[ngClass]="model.layout.element?.control">
|
|
||||||
<input type="radio" class="custom-control-input"
|
<input type="radio" class="custom-control-input"
|
||||||
[checked]="item.value"
|
[checked]="item.value"
|
||||||
[id]="item.id"
|
[id]="item.id"
|
||||||
@@ -56,6 +53,11 @@
|
|||||||
[value]="item.index"
|
[value]="item.index"
|
||||||
(blur)="onBlur($event)"
|
(blur)="onBlur($event)"
|
||||||
(focus)="onFocus($event)"/>
|
(focus)="onFocus($event)"/>
|
||||||
|
<label class="custom-control-label"
|
||||||
|
[class.disabled]="model.disabled"
|
||||||
|
[ngClass]="model.layout.element?.control"
|
||||||
|
[for]="item.id">
|
||||||
|
|
||||||
<span [ngClass]="model.layout.element?.label" [innerHTML]="item.label"></span>
|
<span [ngClass]="model.layout.element?.label" [innerHTML]="item.label"></span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
[searchFormPlaceholder]="'submission.sections.describe.relationship-lookup.search-tab.search-form.placeholder'"
|
[searchFormPlaceholder]="'submission.sections.describe.relationship-lookup.search-tab.search-form.placeholder'"
|
||||||
[selectable]="true"
|
[selectable]="true"
|
||||||
[selectionConfig]="{ repeatable: repeatable, listId: listId }"
|
[selectionConfig]="{ repeatable: repeatable, listId: listId }"
|
||||||
|
[showScopeSelector]="false"
|
||||||
[showViewModes]="false"
|
[showViewModes]="false"
|
||||||
(resultFound)="onResultFound($event)"
|
(resultFound)="onResultFound($event)"
|
||||||
(deselectObject)="deselectObject.emit($event)"
|
(deselectObject)="deselectObject.emit($event)"
|
||||||
|
@@ -26,7 +26,7 @@ import {
|
|||||||
DynamicSliderModel,
|
DynamicSliderModel,
|
||||||
DynamicSwitchModel,
|
DynamicSwitchModel,
|
||||||
DynamicTextAreaModel,
|
DynamicTextAreaModel,
|
||||||
DynamicTimePickerModel
|
DynamicTimePickerModel,
|
||||||
} from '@ng-dynamic-forms/core';
|
} from '@ng-dynamic-forms/core';
|
||||||
import { DynamicTagModel } from './ds-dynamic-form-ui/models/tag/dynamic-tag.model';
|
import { DynamicTagModel } from './ds-dynamic-form-ui/models/tag/dynamic-tag.model';
|
||||||
import { DynamicListCheckboxGroupModel } from './ds-dynamic-form-ui/models/list/dynamic-list-checkbox-group.model';
|
import { DynamicListCheckboxGroupModel } from './ds-dynamic-form-ui/models/list/dynamic-list-checkbox-group.model';
|
||||||
@@ -48,12 +48,18 @@ import { DynamicConcatModel } from './ds-dynamic-form-ui/models/ds-dynamic-conca
|
|||||||
import { DynamicLookupNameModel } from './ds-dynamic-form-ui/models/lookup/dynamic-lookup-name.model';
|
import { DynamicLookupNameModel } from './ds-dynamic-form-ui/models/lookup/dynamic-lookup-name.model';
|
||||||
import { DynamicRowArrayModel } from './ds-dynamic-form-ui/models/ds-dynamic-row-array-model';
|
import { DynamicRowArrayModel } from './ds-dynamic-form-ui/models/ds-dynamic-row-array-model';
|
||||||
import { FormRowModel } from '../../../core/config/models/config-submission-form.model';
|
import { FormRowModel } from '../../../core/config/models/config-submission-form.model';
|
||||||
|
import {ConfigurationDataService} from '../../../core/data/configuration-data.service';
|
||||||
|
import {createSuccessfulRemoteDataObject$} from '../../remote-data.utils';
|
||||||
|
import {ConfigurationProperty} from '../../../core/shared/configuration-property.model';
|
||||||
|
|
||||||
describe('FormBuilderService test suite', () => {
|
describe('FormBuilderService test suite', () => {
|
||||||
|
|
||||||
let testModel: DynamicFormControlModel[];
|
let testModel: DynamicFormControlModel[];
|
||||||
let testFormConfiguration: SubmissionFormsModel;
|
let testFormConfiguration: SubmissionFormsModel;
|
||||||
let service: FormBuilderService;
|
let service: FormBuilderService;
|
||||||
|
let configSpy: ConfigurationDataService;
|
||||||
|
const typeFieldProp = 'submit.type-bind.field';
|
||||||
|
const typeFieldTestValue = 'dc.type';
|
||||||
|
|
||||||
const submissionId = '1234';
|
const submissionId = '1234';
|
||||||
|
|
||||||
@@ -65,15 +71,24 @@ describe('FormBuilderService test suite', () => {
|
|||||||
return new Promise<boolean>((resolve) => setTimeout(() => resolve(true), 0));
|
return new Promise<boolean>((resolve) => setTimeout(() => resolve(true), 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
const createConfigSuccessSpy = (...values: string[]) => jasmine.createSpyObj('configurationDataService', {
|
||||||
|
findByPropertyName: createSuccessfulRemoteDataObject$({
|
||||||
|
... new ConfigurationProperty(),
|
||||||
|
name: typeFieldProp,
|
||||||
|
values: values,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
configSpy = createConfigSuccessSpy(typeFieldTestValue);
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [ReactiveFormsModule],
|
imports: [ReactiveFormsModule],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: FormBuilderService, useClass: FormBuilderService },
|
{ provide: FormBuilderService, useClass: FormBuilderService },
|
||||||
{ provide: DynamicFormValidationService, useValue: {} },
|
{ provide: DynamicFormValidationService, useValue: {} },
|
||||||
{ provide: NG_VALIDATORS, useValue: testValidator, multi: true },
|
{ provide: NG_VALIDATORS, useValue: testValidator, multi: true },
|
||||||
{ provide: NG_ASYNC_VALIDATORS, useValue: testAsyncValidator, multi: true }
|
{ provide: NG_ASYNC_VALIDATORS, useValue: testAsyncValidator, multi: true },
|
||||||
|
{ provide: ConfigurationDataService, useValue: configSpy }
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -197,7 +212,7 @@ describe('FormBuilderService test suite', () => {
|
|||||||
repeatable: false,
|
repeatable: false,
|
||||||
metadataFields: [],
|
metadataFields: [],
|
||||||
submissionId: '1234',
|
submissionId: '1234',
|
||||||
hasSelectableMetadata: false
|
hasSelectableMetadata: false,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
new DynamicScrollableDropdownModel({
|
new DynamicScrollableDropdownModel({
|
||||||
@@ -233,6 +248,7 @@ describe('FormBuilderService test suite', () => {
|
|||||||
hints: 'Enter the name of the author.',
|
hints: 'Enter the name of the author.',
|
||||||
input: { type: 'onebox' },
|
input: { type: 'onebox' },
|
||||||
label: 'Authors',
|
label: 'Authors',
|
||||||
|
typeBind: [],
|
||||||
languageCodes: [],
|
languageCodes: [],
|
||||||
mandatory: 'true',
|
mandatory: 'true',
|
||||||
mandatoryMessage: 'Required field!',
|
mandatoryMessage: 'Required field!',
|
||||||
@@ -304,7 +320,9 @@ describe('FormBuilderService test suite', () => {
|
|||||||
required: false,
|
required: false,
|
||||||
metadataKey: 'dc.contributor.author',
|
metadataKey: 'dc.contributor.author',
|
||||||
metadataFields: ['dc.contributor.author'],
|
metadataFields: ['dc.contributor.author'],
|
||||||
hasSelectableMetadata: true
|
hasSelectableMetadata: true,
|
||||||
|
showButtons: true,
|
||||||
|
typeBindRelations: [{ match: 'VISIBLE', operator: 'OR', when: [{id: 'dc.type', value: 'Book' }]}]
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
@@ -424,7 +442,9 @@ describe('FormBuilderService test suite', () => {
|
|||||||
} as any;
|
} as any;
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(inject([FormBuilderService], (formService: FormBuilderService) => service = formService));
|
beforeEach(inject([FormBuilderService], (formService: FormBuilderService) => {
|
||||||
|
service = formService;
|
||||||
|
}));
|
||||||
|
|
||||||
it('should find a dynamic form control model by id', () => {
|
it('should find a dynamic form control model by id', () => {
|
||||||
|
|
||||||
@@ -875,4 +895,12 @@ describe('FormBuilderService test suite', () => {
|
|||||||
|
|
||||||
expect(formArray.length === 0).toBe(true);
|
expect(formArray.length === 0).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it(`should request the ${typeFieldProp} property and set value "dc_type"`, () => {
|
||||||
|
const typeValue = service.getTypeField();
|
||||||
|
expect(configSpy.findByPropertyName).toHaveBeenCalledTimes(1);
|
||||||
|
expect(configSpy.findByPropertyName).toHaveBeenCalledWith(typeFieldProp);
|
||||||
|
expect(typeValue).toEqual('dc_type');
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import {Injectable, Optional} from '@angular/core';
|
||||||
import { AbstractControl, FormGroup } from '@angular/forms';
|
import { AbstractControl, FormControl, FormGroup } from '@angular/forms';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DYNAMIC_FORM_CONTROL_TYPE_ARRAY,
|
DYNAMIC_FORM_CONTROL_TYPE_ARRAY,
|
||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
DYNAMIC_FORM_CONTROL_TYPE_GROUP,
|
DYNAMIC_FORM_CONTROL_TYPE_GROUP,
|
||||||
DYNAMIC_FORM_CONTROL_TYPE_INPUT,
|
DYNAMIC_FORM_CONTROL_TYPE_INPUT,
|
||||||
DYNAMIC_FORM_CONTROL_TYPE_RADIO_GROUP,
|
DYNAMIC_FORM_CONTROL_TYPE_RADIO_GROUP,
|
||||||
|
DynamicFormArrayGroupModel,
|
||||||
DynamicFormArrayModel,
|
DynamicFormArrayModel,
|
||||||
DynamicFormComponentService,
|
DynamicFormComponentService,
|
||||||
DynamicFormControlEvent,
|
DynamicFormControlEvent,
|
||||||
@@ -19,7 +20,15 @@ import {
|
|||||||
} from '@ng-dynamic-forms/core';
|
} from '@ng-dynamic-forms/core';
|
||||||
import { isObject, isString, mergeWith } from 'lodash';
|
import { isObject, isString, mergeWith } from 'lodash';
|
||||||
|
|
||||||
import { hasValue, isEmpty, isNotEmpty, isNotNull, isNotUndefined, isNull } from '../../empty.util';
|
import {
|
||||||
|
hasNoValue,
|
||||||
|
hasValue,
|
||||||
|
isEmpty,
|
||||||
|
isNotEmpty,
|
||||||
|
isNotNull,
|
||||||
|
isNotUndefined,
|
||||||
|
isNull
|
||||||
|
} from '../../empty.util';
|
||||||
import { DynamicQualdropModel } from './ds-dynamic-form-ui/models/ds-dynamic-qualdrop.model';
|
import { DynamicQualdropModel } from './ds-dynamic-form-ui/models/ds-dynamic-qualdrop.model';
|
||||||
import { SubmissionFormsModel } from '../../../core/config/models/config-submission-forms.model';
|
import { SubmissionFormsModel } from '../../../core/config/models/config-submission-forms.model';
|
||||||
import { DYNAMIC_FORM_CONTROL_TYPE_TAG } from './ds-dynamic-form-ui/models/tag/dynamic-tag.model';
|
import { DYNAMIC_FORM_CONTROL_TYPE_TAG } from './ds-dynamic-form-ui/models/tag/dynamic-tag.model';
|
||||||
@@ -32,16 +41,61 @@ import { dateToString, isNgbDateStruct } from '../../date.util';
|
|||||||
import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from './ds-dynamic-form-ui/ds-dynamic-form-constants';
|
import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from './ds-dynamic-form-ui/ds-dynamic-form-constants';
|
||||||
import { CONCAT_GROUP_SUFFIX, DynamicConcatModel } from './ds-dynamic-form-ui/models/ds-dynamic-concat.model';
|
import { CONCAT_GROUP_SUFFIX, DynamicConcatModel } from './ds-dynamic-form-ui/models/ds-dynamic-concat.model';
|
||||||
import { VIRTUAL_METADATA_PREFIX } from '../../../core/shared/metadata.models';
|
import { VIRTUAL_METADATA_PREFIX } from '../../../core/shared/metadata.models';
|
||||||
|
import { ConfigurationDataService } from '../../../core/data/configuration-data.service';
|
||||||
|
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FormBuilderService extends DynamicFormService {
|
export class FormBuilderService extends DynamicFormService {
|
||||||
|
|
||||||
|
private typeBindModel: DynamicFormControlModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This map contains the active forms model
|
||||||
|
*/
|
||||||
|
private formModels: Map<string, DynamicFormControlModel[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This map contains the active forms control groups
|
||||||
|
*/
|
||||||
|
private formGroups: Map<string, FormGroup>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the field to use for type binding
|
||||||
|
*/
|
||||||
|
private typeField: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
componentService: DynamicFormComponentService,
|
componentService: DynamicFormComponentService,
|
||||||
validationService: DynamicFormValidationService,
|
validationService: DynamicFormValidationService,
|
||||||
protected rowParser: RowParser
|
protected rowParser: RowParser,
|
||||||
|
@Optional() protected configService: ConfigurationDataService,
|
||||||
) {
|
) {
|
||||||
super(componentService, validationService);
|
super(componentService, validationService);
|
||||||
|
this.formModels = new Map();
|
||||||
|
this.formGroups = new Map();
|
||||||
|
// If optional config service was passed, perform an initial set of type field (default dc_type) for type binds
|
||||||
|
if (hasValue(this.configService)) {
|
||||||
|
this.setTypeBindFieldFromConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
createDynamicFormControlEvent(control: FormControl, group: FormGroup, model: DynamicFormControlModel, type: string): DynamicFormControlEvent {
|
||||||
|
const $event = {
|
||||||
|
value: (model as any).value,
|
||||||
|
autoSave: false
|
||||||
|
};
|
||||||
|
const context: DynamicFormArrayGroupModel = (model?.parent instanceof DynamicFormArrayGroupModel) ? model?.parent : null;
|
||||||
|
return {$event, context, control: control, group: group, model: model, type};
|
||||||
|
}
|
||||||
|
|
||||||
|
getTypeBindModel() {
|
||||||
|
return this.typeBindModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTypeBindModel(model: DynamicFormControlModel) {
|
||||||
|
this.typeBindModel = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
findById(id: string, groupModel: DynamicFormControlModel[], arrayIndex = null): DynamicFormControlModel | null {
|
findById(id: string, groupModel: DynamicFormControlModel[], arrayIndex = null): DynamicFormControlModel | null {
|
||||||
@@ -223,13 +277,15 @@ export class FormBuilderService extends DynamicFormService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
modelFromConfiguration(submissionId: string, json: string | SubmissionFormsModel, scopeUUID: string, sectionData: any = {}, submissionScope?: string, readOnly = false): DynamicFormControlModel[] | never {
|
modelFromConfiguration(submissionId: string, json: string | SubmissionFormsModel, scopeUUID: string, sectionData: any = {},
|
||||||
|
submissionScope?: string, readOnly = false, typeBindModel = null,
|
||||||
|
isInnerForm = false): DynamicFormControlModel[] | never {
|
||||||
let rows: DynamicFormControlModel[] = [];
|
let rows: DynamicFormControlModel[] = [];
|
||||||
const rawData = typeof json === 'string' ? JSON.parse(json, parseReviver) : json;
|
const rawData = typeof json === 'string' ? JSON.parse(json, parseReviver) : json;
|
||||||
|
|
||||||
if (rawData.rows && !isEmpty(rawData.rows)) {
|
if (rawData.rows && !isEmpty(rawData.rows)) {
|
||||||
rawData.rows.forEach((currentRow) => {
|
rawData.rows.forEach((currentRow) => {
|
||||||
const rowParsed = this.rowParser.parse(submissionId, currentRow, scopeUUID, sectionData, submissionScope, readOnly);
|
const rowParsed = this.rowParser.parse(submissionId, currentRow, scopeUUID, sectionData, submissionScope,
|
||||||
|
readOnly, this.getTypeField());
|
||||||
if (isNotNull(rowParsed)) {
|
if (isNotNull(rowParsed)) {
|
||||||
if (Array.isArray(rowParsed)) {
|
if (Array.isArray(rowParsed)) {
|
||||||
rows = rows.concat(rowParsed);
|
rows = rows.concat(rowParsed);
|
||||||
@@ -240,6 +296,13 @@ export class FormBuilderService extends DynamicFormService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasNoValue(typeBindModel)) {
|
||||||
|
typeBindModel = this.findById(this.typeField, rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasValue(typeBindModel)) {
|
||||||
|
this.setTypeBindModel(typeBindModel);
|
||||||
|
}
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,6 +372,10 @@ export class FormBuilderService extends DynamicFormService {
|
|||||||
return isNotEmpty(fieldModel) ? formGroup.get(this.getPath(fieldModel)) : null;
|
return isNotEmpty(fieldModel) ? formGroup.get(this.getPath(fieldModel)) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFormControlByModel(formGroup: FormGroup, fieldModel: DynamicFormControlModel): AbstractControl {
|
||||||
|
return isNotEmpty(fieldModel) ? formGroup.get(this.getPath(fieldModel)) : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note (discovered while debugging) this is not the ID as used in the form,
|
* Note (discovered while debugging) this is not the ID as used in the form,
|
||||||
* but the first part of the path needed in a patch operation:
|
* but the first part of the path needed in a patch operation:
|
||||||
@@ -328,6 +395,35 @@ export class FormBuilderService extends DynamicFormService {
|
|||||||
return (tempModel.id !== tempModel.name) ? tempModel.name : tempModel.id;
|
return (tempModel.id !== tempModel.name) ? tempModel.name : tempModel.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If present, remove form model from formModels map
|
||||||
|
* @param id id of model
|
||||||
|
*/
|
||||||
|
removeFormModel(id: string): void {
|
||||||
|
if (this.formModels.has(id)) {
|
||||||
|
this.formModels.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new form model to formModels map
|
||||||
|
* @param id id of model
|
||||||
|
* @param formGroup FormGroup
|
||||||
|
*/
|
||||||
|
addFormGroups(id: string, formGroup: FormGroup): void {
|
||||||
|
this.formGroups.set(id, formGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If present, remove form model from formModels map
|
||||||
|
* @param id id of model
|
||||||
|
*/
|
||||||
|
removeFormGroup(id: string): void {
|
||||||
|
if (this.formGroups.has(id)) {
|
||||||
|
this.formGroups.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the metadata list related to the event.
|
* Calculate the metadata list related to the event.
|
||||||
* @param event
|
* @param event
|
||||||
@@ -400,4 +496,39 @@ export class FormBuilderService extends DynamicFormService {
|
|||||||
return Object.keys(result);
|
return Object.keys(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the type bind field from config
|
||||||
|
*/
|
||||||
|
setTypeBindFieldFromConfig(): void {
|
||||||
|
this.configService.findByPropertyName('submit.type-bind.field').pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
).subscribe((remoteData: any) => {
|
||||||
|
// make sure we got a success response from the backend
|
||||||
|
if (!remoteData.hasSucceeded) {
|
||||||
|
this.typeField = 'dc_type';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Read type bind value from response and set if non-empty
|
||||||
|
const typeFieldConfig = remoteData.payload.values[0];
|
||||||
|
if (isEmpty(typeFieldConfig)) {
|
||||||
|
this.typeField = 'dc_type';
|
||||||
|
} else {
|
||||||
|
this.typeField = typeFieldConfig.replace(/\./g, '_');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get type field. If the type isn't already set, and a ConfigurationDataService is provided, set (with subscribe)
|
||||||
|
* from back end. Otherwise, get/set a default "dc_type" value
|
||||||
|
*/
|
||||||
|
getTypeField(): string {
|
||||||
|
if (hasValue(this.configService) && hasNoValue(this.typeField)) {
|
||||||
|
this.setTypeBindFieldFromConfig();
|
||||||
|
} else if (hasNoValue(this.typeField)) {
|
||||||
|
this.typeField = 'dc_type';
|
||||||
|
}
|
||||||
|
return this.typeField;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -113,6 +113,12 @@ export class FormFieldModel {
|
|||||||
@autoserialize
|
@autoserialize
|
||||||
style: string;
|
style: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Containing types to bind for this field
|
||||||
|
*/
|
||||||
|
@autoserialize
|
||||||
|
typeBind: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Containing the value for this metadata field
|
* Containing the value for this metadata field
|
||||||
*/
|
*/
|
||||||
|
@@ -12,7 +12,8 @@ describe('DateFieldParser test suite', () => {
|
|||||||
const parserOptions: ParserOptions = {
|
const parserOptions: ParserOptions = {
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
submissionScope: null,
|
submissionScope: null,
|
||||||
collectionUUID: null
|
collectionUUID: null,
|
||||||
|
typeField: 'dc_type'
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { FieldParser } from './field-parser';
|
import { FieldParser } from './field-parser';
|
||||||
import {
|
import {
|
||||||
DynamicDsDateControlModelConfig,
|
DynamicDsDatePickerModel,
|
||||||
DynamicDsDatePickerModel
|
DynamicDsDateControlModelConfig
|
||||||
} from '../ds-dynamic-form-ui/models/date-picker/date-picker.model';
|
} from '../ds-dynamic-form-ui/models/date-picker/date-picker.model';
|
||||||
import { isNotEmpty } from '../../../empty.util';
|
import { isNotEmpty } from '../../../empty.util';
|
||||||
import { DS_DATE_PICKER_SEPARATOR } from '../ds-dynamic-form-ui/models/date-picker/date-picker.component';
|
import { DS_DATE_PICKER_SEPARATOR } from '../ds-dynamic-form-ui/models/date-picker/date-picker.component';
|
||||||
@@ -13,7 +13,7 @@ export class DateFieldParser extends FieldParser {
|
|||||||
let malformedDate = false;
|
let malformedDate = false;
|
||||||
const inputDateModelConfig: DynamicDsDateControlModelConfig = this.initModel(null, false, true);
|
const inputDateModelConfig: DynamicDsDateControlModelConfig = this.initModel(null, false, true);
|
||||||
inputDateModelConfig.legend = this.configData.label;
|
inputDateModelConfig.legend = this.configData.label;
|
||||||
|
inputDateModelConfig.disabled = inputDateModelConfig.readOnly;
|
||||||
inputDateModelConfig.toggleIcon = 'fas fa-calendar';
|
inputDateModelConfig.toggleIcon = 'fas fa-calendar';
|
||||||
this.setValues(inputDateModelConfig as any, fieldValue);
|
this.setValues(inputDateModelConfig as any, fieldValue);
|
||||||
// Init Data and validity check
|
// Init Data and validity check
|
||||||
|
@@ -11,7 +11,8 @@ describe('DisabledFieldParser test suite', () => {
|
|||||||
const parserOptions: ParserOptions = {
|
const parserOptions: ParserOptions = {
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
submissionScope: null,
|
submissionScope: null,
|
||||||
collectionUUID: null
|
collectionUUID: null,
|
||||||
|
typeField: 'dc_type'
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -11,7 +11,8 @@ describe('DropdownFieldParser test suite', () => {
|
|||||||
const parserOptions: ParserOptions = {
|
const parserOptions: ParserOptions = {
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
submissionScope: 'testScopeUUID',
|
submissionScope: 'testScopeUUID',
|
||||||
collectionUUID: null
|
collectionUUID: null,
|
||||||
|
typeField: 'dc_type'
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -22,7 +22,7 @@ export class DropdownFieldParser extends FieldParser {
|
|||||||
@Inject(SUBMISSION_ID) submissionId: string,
|
@Inject(SUBMISSION_ID) submissionId: string,
|
||||||
@Inject(CONFIG_DATA) configData: FormFieldModel,
|
@Inject(CONFIG_DATA) configData: FormFieldModel,
|
||||||
@Inject(INIT_FORM_VALUES) initFormValues,
|
@Inject(INIT_FORM_VALUES) initFormValues,
|
||||||
@Inject(PARSER_OPTIONS) parserOptions: ParserOptions
|
@Inject(PARSER_OPTIONS) parserOptions: ParserOptions,
|
||||||
) {
|
) {
|
||||||
super(submissionId, configData, initFormValues, parserOptions);
|
super(submissionId, configData, initFormValues, parserOptions);
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import {Inject, InjectionToken} from '@angular/core';
|
import {Inject, InjectionToken} from '@angular/core';
|
||||||
|
|
||||||
import { uniqueId } from 'lodash';
|
import { uniqueId } from 'lodash';
|
||||||
import { DynamicFormControlLayout } from '@ng-dynamic-forms/core';
|
import {DynamicFormControlLayout, DynamicFormControlRelation, MATCH_VISIBLE, OR_OPERATOR} from '@ng-dynamic-forms/core';
|
||||||
|
|
||||||
import { hasValue, isNotEmpty, isNotNull, isNotUndefined } from '../../../empty.util';
|
import { hasValue, isNotEmpty, isNotNull, isNotUndefined } from '../../../empty.util';
|
||||||
import { FormFieldModel } from '../models/form-field.model';
|
import { FormFieldModel } from '../models/form-field.model';
|
||||||
@@ -26,6 +26,11 @@ export const PARSER_OPTIONS: InjectionToken<ParserOptions> = new InjectionToken<
|
|||||||
export abstract class FieldParser {
|
export abstract class FieldParser {
|
||||||
|
|
||||||
protected fieldId: string;
|
protected fieldId: string;
|
||||||
|
/**
|
||||||
|
* This is the field to use for type binding
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
protected typeField: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(SUBMISSION_ID) protected submissionId: string,
|
@Inject(SUBMISSION_ID) protected submissionId: string,
|
||||||
@@ -67,6 +72,8 @@ export abstract class FieldParser {
|
|||||||
metadataFields: this.getAllFieldIds(),
|
metadataFields: this.getAllFieldIds(),
|
||||||
hasSelectableMetadata: isNotEmpty(this.configData.selectableMetadata),
|
hasSelectableMetadata: isNotEmpty(this.configData.selectableMetadata),
|
||||||
isDraggable,
|
isDraggable,
|
||||||
|
typeBindRelations: isNotEmpty(this.configData.typeBind) ? this.getTypeBindRelations(this.configData.typeBind,
|
||||||
|
this.parserOptions.typeField) : null,
|
||||||
groupFactory: () => {
|
groupFactory: () => {
|
||||||
let model;
|
let model;
|
||||||
if ((arrayCounter === 0)) {
|
if ((arrayCounter === 0)) {
|
||||||
@@ -275,7 +282,7 @@ export abstract class FieldParser {
|
|||||||
// Set label
|
// Set label
|
||||||
this.setLabel(controlModel, label);
|
this.setLabel(controlModel, label);
|
||||||
if (hint) {
|
if (hint) {
|
||||||
controlModel.hint = this.configData.hints;
|
controlModel.hint = this.configData.hints || ' ';
|
||||||
}
|
}
|
||||||
controlModel.placeholder = this.configData.label;
|
controlModel.placeholder = this.configData.label;
|
||||||
|
|
||||||
@@ -292,9 +299,46 @@ export abstract class FieldParser {
|
|||||||
(controlModel as DsDynamicInputModel).languageCodes = this.configData.languageCodes;
|
(controlModel as DsDynamicInputModel).languageCodes = this.configData.languageCodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If typeBind is configured
|
||||||
|
if (isNotEmpty(this.configData.typeBind)) {
|
||||||
|
(controlModel as DsDynamicInputModel).typeBindRelations = this.getTypeBindRelations(this.configData.typeBind,
|
||||||
|
this.parserOptions.typeField);
|
||||||
|
}
|
||||||
|
|
||||||
return controlModel;
|
return controlModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the type bind values from the REST data for a specific field
|
||||||
|
* The return value is any[] in the method signature but in reality it's
|
||||||
|
* returning the 'relation' that'll be used for a dynamic matcher when filtering
|
||||||
|
* fields in type bind, made up of a 'match' outcome (make this field visible), an 'operator'
|
||||||
|
* (OR) and a 'when' condition (the bindValues array).
|
||||||
|
* @param configuredTypeBindValues array of types from the submission definition (CONFIG_DATA)
|
||||||
|
* @private
|
||||||
|
* @return DynamicFormControlRelation[] array with one relation in it, for type bind matching to show a field
|
||||||
|
*/
|
||||||
|
private getTypeBindRelations(configuredTypeBindValues: string[], typeField: string): DynamicFormControlRelation[] {
|
||||||
|
const bindValues = [];
|
||||||
|
configuredTypeBindValues.forEach((value) => {
|
||||||
|
bindValues.push({
|
||||||
|
id: typeField,
|
||||||
|
value: value
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// match: MATCH_VISIBLE means that if true, the field / component will be visible
|
||||||
|
// operator: OR means that all the values in the 'when' condition will be compared with OR, not AND
|
||||||
|
// when: the list of values to match against, in this case the list of strings from <type-bind>...</type-bind>
|
||||||
|
// Example: Field [x] will be VISIBLE if item type = book OR item type = book_part
|
||||||
|
//
|
||||||
|
// The opposing match value will be the dc.type for the workspace item
|
||||||
|
return [{
|
||||||
|
match: MATCH_VISIBLE,
|
||||||
|
operator: OR_OPERATOR,
|
||||||
|
when: bindValues
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
protected hasRegex() {
|
protected hasRegex() {
|
||||||
return hasValue(this.configData.input.regex);
|
return hasValue(this.configData.input.regex);
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,8 @@ describe('ListFieldParser test suite', () => {
|
|||||||
const parserOptions: ParserOptions = {
|
const parserOptions: ParserOptions = {
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
submissionScope: 'testScopeUUID',
|
submissionScope: 'testScopeUUID',
|
||||||
collectionUUID: null
|
collectionUUID: null,
|
||||||
|
typeField: 'dc_type'
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -12,7 +12,8 @@ describe('LookupFieldParser test suite', () => {
|
|||||||
const parserOptions: ParserOptions = {
|
const parserOptions: ParserOptions = {
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
submissionScope: 'testScopeUUID',
|
submissionScope: 'testScopeUUID',
|
||||||
collectionUUID: null
|
collectionUUID: null,
|
||||||
|
typeField: 'dc_type'
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -12,7 +12,8 @@ describe('LookupNameFieldParser test suite', () => {
|
|||||||
const parserOptions: ParserOptions = {
|
const parserOptions: ParserOptions = {
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
submissionScope: 'testScopeUUID',
|
submissionScope: 'testScopeUUID',
|
||||||
collectionUUID: null
|
collectionUUID: null,
|
||||||
|
typeField: 'dc_type'
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -14,7 +14,8 @@ describe('NameFieldParser test suite', () => {
|
|||||||
const parserOptions: ParserOptions = {
|
const parserOptions: ParserOptions = {
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
submissionScope: 'testScopeUUID',
|
submissionScope: 'testScopeUUID',
|
||||||
collectionUUID: null
|
collectionUUID: null,
|
||||||
|
typeField: 'dc_type'
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -15,7 +15,8 @@ describe('OneboxFieldParser test suite', () => {
|
|||||||
const parserOptions: ParserOptions = {
|
const parserOptions: ParserOptions = {
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
submissionScope: 'testScopeUUID',
|
submissionScope: 'testScopeUUID',
|
||||||
collectionUUID: null
|
collectionUUID: null,
|
||||||
|
typeField: 'dc_type'
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -2,4 +2,5 @@ export interface ParserOptions {
|
|||||||
readOnly: boolean;
|
readOnly: boolean;
|
||||||
submissionScope: string;
|
submissionScope: string;
|
||||||
collectionUUID: string;
|
collectionUUID: string;
|
||||||
|
typeField: string;
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,8 @@ describe('RelationGroupFieldParser test suite', () => {
|
|||||||
const parserOptions: ParserOptions = {
|
const parserOptions: ParserOptions = {
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
submissionScope: 'testScopeUUID',
|
submissionScope: 'testScopeUUID',
|
||||||
collectionUUID: 'WORKSPACE'
|
collectionUUID: 'WORKSPACE',
|
||||||
|
typeField: 'dc_type'
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -22,6 +22,7 @@ describe('RowParser test suite', () => {
|
|||||||
const initFormValues = {};
|
const initFormValues = {};
|
||||||
const submissionScope = 'WORKSPACE';
|
const submissionScope = 'WORKSPACE';
|
||||||
const readOnly = false;
|
const readOnly = false;
|
||||||
|
const typeField = 'dc_type';
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
row1 = {
|
row1 = {
|
||||||
@@ -338,7 +339,7 @@ describe('RowParser test suite', () => {
|
|||||||
it('should return a DynamicRowGroupModel object', () => {
|
it('should return a DynamicRowGroupModel object', () => {
|
||||||
const parser = new RowParser(undefined);
|
const parser = new RowParser(undefined);
|
||||||
|
|
||||||
const rowModel = parser.parse(submissionId, row1, scopeUUID, initFormValues, submissionScope, readOnly);
|
const rowModel = parser.parse(submissionId, row1, scopeUUID, initFormValues, submissionScope, readOnly, typeField);
|
||||||
|
|
||||||
expect(rowModel instanceof DynamicRowGroupModel).toBe(true);
|
expect(rowModel instanceof DynamicRowGroupModel).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -346,7 +347,7 @@ describe('RowParser test suite', () => {
|
|||||||
it('should return a row with three fields', () => {
|
it('should return a row with three fields', () => {
|
||||||
const parser = new RowParser(undefined);
|
const parser = new RowParser(undefined);
|
||||||
|
|
||||||
const rowModel = parser.parse(submissionId, row1, scopeUUID, initFormValues, submissionScope, readOnly);
|
const rowModel = parser.parse(submissionId, row1, scopeUUID, initFormValues, submissionScope, readOnly, typeField);
|
||||||
|
|
||||||
expect((rowModel as DynamicRowGroupModel).group.length).toBe(3);
|
expect((rowModel as DynamicRowGroupModel).group.length).toBe(3);
|
||||||
});
|
});
|
||||||
@@ -354,7 +355,7 @@ describe('RowParser test suite', () => {
|
|||||||
it('should return a DynamicRowArrayModel object', () => {
|
it('should return a DynamicRowArrayModel object', () => {
|
||||||
const parser = new RowParser(undefined);
|
const parser = new RowParser(undefined);
|
||||||
|
|
||||||
const rowModel = parser.parse(submissionId, row2, scopeUUID, initFormValues, submissionScope, readOnly);
|
const rowModel = parser.parse(submissionId, row2, scopeUUID, initFormValues, submissionScope, readOnly, typeField);
|
||||||
|
|
||||||
expect(rowModel instanceof DynamicRowArrayModel).toBe(true);
|
expect(rowModel instanceof DynamicRowArrayModel).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -362,7 +363,7 @@ describe('RowParser test suite', () => {
|
|||||||
it('should return a row that contains only scoped fields', () => {
|
it('should return a row that contains only scoped fields', () => {
|
||||||
const parser = new RowParser(undefined);
|
const parser = new RowParser(undefined);
|
||||||
|
|
||||||
const rowModel = parser.parse(submissionId, row3, scopeUUID, initFormValues, submissionScope, readOnly);
|
const rowModel = parser.parse(submissionId, row3, scopeUUID, initFormValues, submissionScope, readOnly, typeField);
|
||||||
|
|
||||||
expect((rowModel as DynamicRowGroupModel).group.length).toBe(1);
|
expect((rowModel as DynamicRowGroupModel).group.length).toBe(1);
|
||||||
});
|
});
|
||||||
@@ -370,7 +371,7 @@ describe('RowParser test suite', () => {
|
|||||||
it('should be able to parse a dropdown combo field', () => {
|
it('should be able to parse a dropdown combo field', () => {
|
||||||
const parser = new RowParser(undefined);
|
const parser = new RowParser(undefined);
|
||||||
|
|
||||||
const rowModel = parser.parse(submissionId, row4, scopeUUID, initFormValues, submissionScope, readOnly);
|
const rowModel = parser.parse(submissionId, row4, scopeUUID, initFormValues, submissionScope, readOnly, typeField);
|
||||||
|
|
||||||
expect(rowModel).toBeDefined();
|
expect(rowModel).toBeDefined();
|
||||||
});
|
});
|
||||||
@@ -378,7 +379,7 @@ describe('RowParser test suite', () => {
|
|||||||
it('should be able to parse a lookup-name field', () => {
|
it('should be able to parse a lookup-name field', () => {
|
||||||
const parser = new RowParser(undefined);
|
const parser = new RowParser(undefined);
|
||||||
|
|
||||||
const rowModel = parser.parse(submissionId, row5, scopeUUID, initFormValues, submissionScope, readOnly);
|
const rowModel = parser.parse(submissionId, row5, scopeUUID, initFormValues, submissionScope, readOnly, typeField);
|
||||||
|
|
||||||
expect(rowModel).toBeDefined();
|
expect(rowModel).toBeDefined();
|
||||||
});
|
});
|
||||||
@@ -386,7 +387,7 @@ describe('RowParser test suite', () => {
|
|||||||
it('should be able to parse a list field', () => {
|
it('should be able to parse a list field', () => {
|
||||||
const parser = new RowParser(undefined);
|
const parser = new RowParser(undefined);
|
||||||
|
|
||||||
const rowModel = parser.parse(submissionId, row6, scopeUUID, initFormValues, submissionScope, readOnly);
|
const rowModel = parser.parse(submissionId, row6, scopeUUID, initFormValues, submissionScope, readOnly, typeField);
|
||||||
|
|
||||||
expect(rowModel).toBeDefined();
|
expect(rowModel).toBeDefined();
|
||||||
});
|
});
|
||||||
@@ -394,7 +395,7 @@ describe('RowParser test suite', () => {
|
|||||||
it('should be able to parse a date field', () => {
|
it('should be able to parse a date field', () => {
|
||||||
const parser = new RowParser(undefined);
|
const parser = new RowParser(undefined);
|
||||||
|
|
||||||
const rowModel = parser.parse(submissionId, row7, scopeUUID, initFormValues, submissionScope, readOnly);
|
const rowModel = parser.parse(submissionId, row7, scopeUUID, initFormValues, submissionScope, readOnly, typeField);
|
||||||
|
|
||||||
expect(rowModel).toBeDefined();
|
expect(rowModel).toBeDefined();
|
||||||
});
|
});
|
||||||
@@ -402,7 +403,7 @@ describe('RowParser test suite', () => {
|
|||||||
it('should be able to parse a tag field', () => {
|
it('should be able to parse a tag field', () => {
|
||||||
const parser = new RowParser(undefined);
|
const parser = new RowParser(undefined);
|
||||||
|
|
||||||
const rowModel = parser.parse(submissionId, row8, scopeUUID, initFormValues, submissionScope, readOnly);
|
const rowModel = parser.parse(submissionId, row8, scopeUUID, initFormValues, submissionScope, readOnly, typeField);
|
||||||
|
|
||||||
expect(rowModel).toBeDefined();
|
expect(rowModel).toBeDefined();
|
||||||
});
|
});
|
||||||
@@ -410,7 +411,7 @@ describe('RowParser test suite', () => {
|
|||||||
it('should be able to parse a textarea field', () => {
|
it('should be able to parse a textarea field', () => {
|
||||||
const parser = new RowParser(undefined);
|
const parser = new RowParser(undefined);
|
||||||
|
|
||||||
const rowModel = parser.parse(submissionId, row9, scopeUUID, initFormValues, submissionScope, readOnly);
|
const rowModel = parser.parse(submissionId, row9, scopeUUID, initFormValues, submissionScope, readOnly, typeField);
|
||||||
|
|
||||||
expect(rowModel).toBeDefined();
|
expect(rowModel).toBeDefined();
|
||||||
});
|
});
|
||||||
@@ -418,7 +419,7 @@ describe('RowParser test suite', () => {
|
|||||||
it('should be able to parse a group field', () => {
|
it('should be able to parse a group field', () => {
|
||||||
const parser = new RowParser(undefined);
|
const parser = new RowParser(undefined);
|
||||||
|
|
||||||
const rowModel = parser.parse(submissionId, row10, scopeUUID, initFormValues, submissionScope, readOnly);
|
const rowModel = parser.parse(submissionId, row10, scopeUUID, initFormValues, submissionScope, readOnly, typeField);
|
||||||
|
|
||||||
expect(rowModel).toBeDefined();
|
expect(rowModel).toBeDefined();
|
||||||
});
|
});
|
||||||
|
@@ -31,7 +31,8 @@ export class RowParser {
|
|||||||
scopeUUID,
|
scopeUUID,
|
||||||
initFormValues: any,
|
initFormValues: any,
|
||||||
submissionScope,
|
submissionScope,
|
||||||
readOnly: boolean): DynamicRowGroupModel {
|
readOnly: boolean,
|
||||||
|
typeField: string): DynamicRowGroupModel {
|
||||||
let fieldModel: any = null;
|
let fieldModel: any = null;
|
||||||
let parsedResult = null;
|
let parsedResult = null;
|
||||||
const config: DynamicFormGroupModelConfig = {
|
const config: DynamicFormGroupModelConfig = {
|
||||||
@@ -47,7 +48,8 @@ export class RowParser {
|
|||||||
const parserOptions: ParserOptions = {
|
const parserOptions: ParserOptions = {
|
||||||
readOnly: readOnly,
|
readOnly: readOnly,
|
||||||
submissionScope: submissionScope,
|
submissionScope: submissionScope,
|
||||||
collectionUUID: scopeUUID
|
collectionUUID: scopeUUID,
|
||||||
|
typeField: typeField
|
||||||
};
|
};
|
||||||
|
|
||||||
// Iterate over row's fields
|
// Iterate over row's fields
|
||||||
|
@@ -12,7 +12,8 @@ describe('SeriesFieldParser test suite', () => {
|
|||||||
const parserOptions: ParserOptions = {
|
const parserOptions: ParserOptions = {
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
submissionScope: 'testScopeUUID',
|
submissionScope: 'testScopeUUID',
|
||||||
collectionUUID: null
|
collectionUUID: null,
|
||||||
|
typeField: 'dc_type'
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -12,7 +12,8 @@ describe('TagFieldParser test suite', () => {
|
|||||||
const parserOptions: ParserOptions = {
|
const parserOptions: ParserOptions = {
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
submissionScope: 'testScopeUUID',
|
submissionScope: 'testScopeUUID',
|
||||||
collectionUUID: null
|
collectionUUID: null,
|
||||||
|
typeField: 'dc_type'
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -12,7 +12,8 @@ describe('TextareaFieldParser test suite', () => {
|
|||||||
const parserOptions: ParserOptions = {
|
const parserOptions: ParserOptions = {
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
submissionScope: null,
|
submissionScope: null,
|
||||||
collectionUUID: null
|
collectionUUID: null,
|
||||||
|
typeField: 'dc_type'
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -100,7 +100,9 @@ describe('ItemVersionsComponent', () => {
|
|||||||
isAuthenticated: observableOf(true),
|
isAuthenticated: observableOf(true),
|
||||||
setRedirectUrl: {}
|
setRedirectUrl: {}
|
||||||
});
|
});
|
||||||
const authorizationServiceSpy = jasmine.createSpyObj('authorizationService', ['isAuthorized']);
|
const authorizationServiceSpy = jasmine.createSpyObj('authorizationService', {
|
||||||
|
isAuthorized: observableOf(true)
|
||||||
|
});
|
||||||
const workspaceItemDataServiceSpy = jasmine.createSpyObj('workspaceItemDataService', {
|
const workspaceItemDataServiceSpy = jasmine.createSpyObj('workspaceItemDataService', {
|
||||||
findByItem: EMPTY,
|
findByItem: EMPTY,
|
||||||
});
|
});
|
||||||
|
14
src/app/shared/mocks/find-id-config-data.service.mock.ts
Normal file
14
src/app/shared/mocks/find-id-config-data.service.mock.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils';
|
||||||
|
import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
|
||||||
|
|
||||||
|
export function getMockFindByIdDataService(propertyKey: string, ...values: string[]) {
|
||||||
|
return jasmine.createSpyObj('findByIdDataService', {
|
||||||
|
findByPropertyName: createSuccessfulRemoteDataObject$({
|
||||||
|
... new ConfigurationProperty(),
|
||||||
|
name: propertyKey,
|
||||||
|
values: values,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@@ -1,7 +1,9 @@
|
|||||||
import { FormBuilderService } from '../form/builder/form-builder.service';
|
import { FormBuilderService } from '../form/builder/form-builder.service';
|
||||||
import { FormControl, FormGroup } from '@angular/forms';
|
import { FormControl, FormGroup } from '@angular/forms';
|
||||||
|
import {DsDynamicInputModel} from '../form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model';
|
||||||
|
|
||||||
export function getMockFormBuilderService(): FormBuilderService {
|
export function getMockFormBuilderService(): FormBuilderService {
|
||||||
|
|
||||||
return jasmine.createSpyObj('FormBuilderService', {
|
return jasmine.createSpyObj('FormBuilderService', {
|
||||||
modelFromConfiguration: [],
|
modelFromConfiguration: [],
|
||||||
createFormGroup: new FormGroup({}),
|
createFormGroup: new FormGroup({}),
|
||||||
@@ -17,8 +19,26 @@ export function getMockFormBuilderService(): FormBuilderService {
|
|||||||
isQualdropGroup: false,
|
isQualdropGroup: false,
|
||||||
isModelInCustomGroup: true,
|
isModelInCustomGroup: true,
|
||||||
isRelationGroup: true,
|
isRelationGroup: true,
|
||||||
hasArrayGroupValue: true
|
hasArrayGroupValue: true,
|
||||||
|
getTypeBindModel: new DsDynamicInputModel({
|
||||||
|
name: 'dc.type',
|
||||||
|
id: 'dc_type',
|
||||||
|
readOnly: false,
|
||||||
|
disabled: false,
|
||||||
|
repeatable: false,
|
||||||
|
value: {
|
||||||
|
value: 'boundType',
|
||||||
|
display: 'Bound Type',
|
||||||
|
authority: 'bound-auth-key'
|
||||||
|
},
|
||||||
|
submissionId: '1234',
|
||||||
|
metadataFields: ['dc.type'],
|
||||||
|
hasSelectableMetadata: false,
|
||||||
|
typeBindRelations: [
|
||||||
|
{match: 'VISIBLE', operator: 'OR', when: [{id: 'dc.type', value: 'boundType'}]}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -89,7 +89,8 @@ const rowArrayQualdropConfig = {
|
|||||||
submissionId: '1234',
|
submissionId: '1234',
|
||||||
metadataKey: 'dc.some.key',
|
metadataKey: 'dc.some.key',
|
||||||
metadataFields: ['dc.some.key'],
|
metadataFields: ['dc.some.key'],
|
||||||
hasSelectableMetadata: false
|
hasSelectableMetadata: false,
|
||||||
|
showButtons: true
|
||||||
} as DynamicRowArrayModelConfig;
|
} as DynamicRowArrayModelConfig;
|
||||||
|
|
||||||
export const MockRowArrayQualdropModel: DynamicRowArrayModel = new DynamicRowArrayModel(rowArrayQualdropConfig);
|
export const MockRowArrayQualdropModel: DynamicRowArrayModel = new DynamicRowArrayModel(rowArrayQualdropConfig);
|
||||||
@@ -305,3 +306,57 @@ export const mockFileFormEditRowGroupModel = new DynamicRowGroupModel({
|
|||||||
id: 'mockRowGroupModel',
|
id: 'mockRowGroupModel',
|
||||||
group: [mockFileFormEditInputModel]
|
group: [mockFileFormEditInputModel]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Mock configuration and model for an input with type binding
|
||||||
|
export const inputWithTypeBindConfig = {
|
||||||
|
name: 'testWithTypeBind',
|
||||||
|
id: 'testWithTypeBind',
|
||||||
|
readOnly: false,
|
||||||
|
disabled: false,
|
||||||
|
repeatable: false,
|
||||||
|
value: {
|
||||||
|
value: 'testWithTypeBind',
|
||||||
|
display: 'testWithTypeBind',
|
||||||
|
authority: 'bound-auth-key'
|
||||||
|
},
|
||||||
|
submissionId: '1234',
|
||||||
|
metadataFields: [],
|
||||||
|
hasSelectableMetadata: false,
|
||||||
|
getTypeBindModel: new DsDynamicInputModel({
|
||||||
|
name: 'testWithTypeBind',
|
||||||
|
id: 'testWithTypeBind',
|
||||||
|
readOnly: false,
|
||||||
|
disabled: false,
|
||||||
|
repeatable: false,
|
||||||
|
value: {
|
||||||
|
value: 'testWithTypeBind',
|
||||||
|
display: 'testWithTypeBind',
|
||||||
|
authority: 'bound-auth-key'
|
||||||
|
},
|
||||||
|
submissionId: '1234',
|
||||||
|
metadataFields: [],
|
||||||
|
hasSelectableMetadata: false,
|
||||||
|
typeBindRelations: [
|
||||||
|
{match: 'VISIBLE', operator: 'OR', when: [{'id': 'dc.type', 'value': 'boundType'}]}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
export const mockInputWithTypeBindModel = new DsDynamicInputModel(inputWithAuthorityValueConfig);
|
||||||
|
|
||||||
|
export const dcTypeInputConfig = {
|
||||||
|
name: 'dc.type',
|
||||||
|
id: 'dc_type',
|
||||||
|
readOnly: false,
|
||||||
|
disabled: false,
|
||||||
|
repeatable: false,
|
||||||
|
submissionId: '1234',
|
||||||
|
metadataFields: [],
|
||||||
|
hasSelectableMetadata: false,
|
||||||
|
value: {
|
||||||
|
value: 'boundType'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const mockDcTypeInputModel = new DsDynamicInputModel(dcTypeInputConfig);
|
||||||
|
@@ -1,21 +1,15 @@
|
|||||||
<ng-container *ngVar="(actionRD$ | async)?.payload as workflowAction">
|
<ng-container *ngVar="(actionRD$ | async)?.payload as workflowAction">
|
||||||
<div class="mt-1 mb-3 space-children-mr">
|
<div class="mt-1 mb-3 space-children-mr">
|
||||||
<ds-claimed-task-actions-loader *ngFor="let option of workflowAction?.options"
|
<ds-claimed-task-actions-loader *ngFor="let option of workflowAction?.options" [option]="option" [object]="object"
|
||||||
[option]="option"
|
|
||||||
[object]="object"
|
|
||||||
(processCompleted)="this.processCompleted.emit($event)">
|
(processCompleted)="this.processCompleted.emit($event)">
|
||||||
</ds-claimed-task-actions-loader>
|
</ds-claimed-task-actions-loader>
|
||||||
|
|
||||||
<ng-container *ngIf="hasViewAction(workflowAction)">
|
<button class="btn btn-primary workflow-view" ngbTooltip="{{'submission.workflow.generic.view-help' | translate}}"
|
||||||
<button class="btn btn-primary workflow-view"
|
|
||||||
ngbTooltip="{{'submission.workflow.generic.view-help' | translate}}"
|
|
||||||
[routerLink]="[getWorkflowItemViewRoute((workflowitem$ | async))]">
|
[routerLink]="[getWorkflowItemViewRoute((workflowitem$ | async))]">
|
||||||
<i class="fa fa-info-circle"></i> {{"submission.workflow.generic.view" | translate}}
|
<i class="fa fa-info-circle"></i> {{"submission.workflow.generic.view" | translate}}
|
||||||
</button>
|
</button>
|
||||||
</ng-container>
|
|
||||||
|
|
||||||
<ds-claimed-task-actions-loader [option]="returnToPoolOption"
|
<ds-claimed-task-actions-loader [option]="returnToPoolOption" [object]="object"
|
||||||
[object]="object"
|
|
||||||
(processCompleted)="this.processCompleted.emit($event)">
|
(processCompleted)="this.processCompleted.emit($event)">
|
||||||
</ds-claimed-task-actions-loader>
|
</ds-claimed-task-actions-loader>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -161,7 +161,6 @@ describe('ClaimedTaskActionsComponent', () => {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('when edit options is not available', () => {
|
|
||||||
it('should display a view button', waitForAsync(() => {
|
it('should display a view button', waitForAsync(() => {
|
||||||
component.object = null;
|
component.object = null;
|
||||||
component.initObjects(mockObject);
|
component.initObjects(mockObject);
|
||||||
@@ -179,7 +178,5 @@ describe('ClaimedTaskActionsComponent', () => {
|
|||||||
const href = component.getWorkflowItemViewRoute(workflowitem);
|
const href = component.getWorkflowItemViewRoute(workflowitem);
|
||||||
expect(href).toEqual('/workflowitems/333/view');
|
expect(href).toEqual('/workflowitems/333/view');
|
||||||
}));
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -102,14 +102,6 @@ export class ClaimedTaskActionsComponent extends MyDSpaceActionsComponent<Claime
|
|||||||
this.actionRD$ = object.action;
|
this.actionRD$ = object.action;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if claimed task actions should display a view item button.
|
|
||||||
* @param workflowAction
|
|
||||||
*/
|
|
||||||
hasViewAction(workflowAction: WorkflowAction) {
|
|
||||||
return !workflowAction?.options.includes('submit_edit_metadata');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the workflowitem view route.
|
* Get the workflowitem view route.
|
||||||
*/
|
*/
|
||||||
|
@@ -1,8 +1,13 @@
|
|||||||
<button type="button"
|
<button type="button" class="btn btn-info mt-1 mb-3"
|
||||||
class="btn btn-info mt-1 mb-3"
|
ngbTooltip="{{'submission.workflow.tasks.pool.claim_help' | translate}}" [disabled]="(processing$ | async)"
|
||||||
ngbTooltip="{{'submission.workflow.tasks.pool.claim_help' | translate}}"
|
|
||||||
[disabled]="(processing$ | async)"
|
|
||||||
(click)="claim()">
|
(click)="claim()">
|
||||||
<span *ngIf="(processing$ | async)"><i class='fas fa-circle-notch fa-spin'></i> {{'submission.workflow.tasks.generic.processing' | translate}}</span>
|
<span *ngIf="(processing$ | async)"><i class='fas fa-circle-notch fa-spin'></i>
|
||||||
<span *ngIf="!(processing$ | async)"><i class="fas fa-hand-paper"></i> {{'submission.workflow.tasks.pool.claim' | translate}}</span>
|
{{'submission.workflow.tasks.generic.processing' | translate}}</span>
|
||||||
|
<span *ngIf="!(processing$ | async)"><i class="fas fa-hand-paper"></i> {{'submission.workflow.tasks.pool.claim' |
|
||||||
|
translate}}</span>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-primary workflow-view ml-1 mt-1 mb-3" data-test="view-btn"
|
||||||
|
ngbTooltip="{{'submission.workflow.generic.view-help' | translate}}"
|
||||||
|
[routerLink]="[getWorkflowItemViewRoute((workflowitem$ | async))]">
|
||||||
|
<i class="fa fa-info-circle"></i> {{"submission.workflow.generic.view" | translate}}
|
||||||
</button>
|
</button>
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { ChangeDetectionStrategy, Injector, NO_ERRORS_SCHEMA } from '@angular/core';
|
import { ChangeDetectionStrategy, Injector, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
@@ -133,6 +133,12 @@ describe('PoolTaskActionsComponent', () => {
|
|||||||
expect(btn).toBeDefined();
|
expect(btn).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should display view button', () => {
|
||||||
|
const btn = fixture.debugElement.query(By.css('button [data-test="view-btn"]'));
|
||||||
|
|
||||||
|
expect(btn).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
it('should call claim task with href of getPoolTaskEndpointById', ((done) => {
|
it('should call claim task with href of getPoolTaskEndpointById', ((done) => {
|
||||||
|
|
||||||
const poolTaskHref = 'poolTaskHref';
|
const poolTaskHref = 'poolTaskHref';
|
||||||
|
@@ -19,6 +19,7 @@ import { Item } from '../../../core/shared/item.model';
|
|||||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||||
import { MyDSpaceReloadableActionsComponent } from '../mydspace-reloadable-actions';
|
import { MyDSpaceReloadableActionsComponent } from '../mydspace-reloadable-actions';
|
||||||
import { ProcessTaskResponse } from '../../../core/tasks/models/process-task-response';
|
import { ProcessTaskResponse } from '../../../core/tasks/models/process-task-response';
|
||||||
|
import { getWorkflowItemViewRoute } from '../../../workflowitems-edit-page/workflowitems-edit-page-routing-paths';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This component represents mydspace actions related to PoolTask object.
|
* This component represents mydspace actions related to PoolTask object.
|
||||||
@@ -115,4 +116,11 @@ export class PoolTaskActionsComponent extends MyDSpaceReloadableActionsComponent
|
|||||||
this.subs.forEach((sub) => sub.unsubscribe());
|
this.subs.forEach((sub) => sub.unsubscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the workflowitem view route.
|
||||||
|
*/
|
||||||
|
getWorkflowItemViewRoute(workflowitem: WorkflowItem): string {
|
||||||
|
return getWorkflowItemViewRoute(workflowitem?.id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user