mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[CST-9636] Added jsdoc comments
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
import { AccessControlArrayFormComponent, AccessControlItemValue } from './access-control-array-form.component';
|
import { AccessControlArrayFormComponent } from './access-control-array-form.component';
|
||||||
import { ReactiveFormsModule } from '@angular/forms';
|
import { ReactiveFormsModule } from '@angular/forms';
|
||||||
import { SharedBrowseByModule } from '../browse-by/shared-browse-by.module';
|
import { SharedBrowseByModule } from '../browse-by/shared-browse-by.module';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
@@ -26,7 +26,7 @@ fdescribe('AccessControlArrayFormComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(AccessControlArrayFormComponent);
|
fixture = TestBed.createComponent(AccessControlArrayFormComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
component.dropdownOptions = [{name: 'Option1'}, {name: 'Option2'}];
|
component.dropdownOptions = [{name: 'Option1'}, {name: 'Option2'}] as any;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -54,14 +54,14 @@ fdescribe('AccessControlArrayFormComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should set access control item value', () => {
|
it('should set access control item value', () => {
|
||||||
const item: AccessControlItemValue = { itemName: 'item1', startDate: '2022-01-01', endDate: '2022-02-01' };
|
const item = { itemName: 'item1', startDate: '2022-01-01', endDate: '2022-02-01' };
|
||||||
component.addAccessControlItem(item.itemName);
|
component.addAccessControlItem(item.itemName);
|
||||||
component.accessControl.controls[0].patchValue(item);
|
component.accessControl.controls[0].patchValue(item);
|
||||||
expect(component.form.value.accessControl[0]).toEqual(item);
|
expect(component.form.value.accessControl[0]).toEqual(item);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reset form value', () => {
|
it('should reset form value', () => {
|
||||||
const item: AccessControlItemValue = { itemName: 'item1', startDate: '2022-01-01', endDate: '2022-02-01' };
|
const item = { itemName: 'item1', startDate: '2022-01-01', endDate: '2022-02-01' };
|
||||||
component.addAccessControlItem(item.itemName);
|
component.addAccessControlItem(item.itemName);
|
||||||
component.accessControl.controls[1].patchValue(item);
|
component.accessControl.controls[1].patchValue(item);
|
||||||
component.reset();
|
component.reset();
|
||||||
|
@@ -31,7 +31,89 @@ export class AccessControlArrayFormComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.addAccessControlItem();
|
this.addAccessControlItem();
|
||||||
|
this.handleValidationOnFormArrayChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the access control form array.
|
||||||
|
*/
|
||||||
|
get accessControl() {
|
||||||
|
return this.form.get('accessControl') as FormArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new access control item to the form.
|
||||||
|
* Start and end date are disabled by default.
|
||||||
|
* @param itemName The name of the item to add
|
||||||
|
*/
|
||||||
|
addAccessControlItem(itemName: string = null) {
|
||||||
|
this.accessControl.push(this.fb.group({
|
||||||
|
itemName,
|
||||||
|
startDate: new FormControl({ value: null, disabled: true }),
|
||||||
|
endDate: new FormControl({ value: null, disabled: true })
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove an access control item from the form.
|
||||||
|
* @param index
|
||||||
|
*/
|
||||||
|
removeAccessControlItem(index: number) {
|
||||||
|
this.accessControl.removeAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of the form.
|
||||||
|
* This will be used to read the form value from the parent component.
|
||||||
|
* @return The form value
|
||||||
|
*/
|
||||||
|
getValue() {
|
||||||
|
return this.form.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the value of the form from the parent component.
|
||||||
|
*/
|
||||||
|
reset() {
|
||||||
|
this.accessControl.reset([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable the form.
|
||||||
|
* This will be used to disable the form from the parent component.
|
||||||
|
* This will also disable all date controls.
|
||||||
|
*/
|
||||||
|
disable() {
|
||||||
|
this.form.disable();
|
||||||
|
|
||||||
|
// disable all date controls
|
||||||
|
for (const control of this.accessControl.controls) {
|
||||||
|
control.get('startDate').disable();
|
||||||
|
control.get('endDate').disable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable the form.
|
||||||
|
* This will be used to enable the form from the parent component.
|
||||||
|
* This will also enable all date controls.
|
||||||
|
*/
|
||||||
|
enable() {
|
||||||
|
this.form.enable();
|
||||||
|
|
||||||
|
// enable date controls
|
||||||
|
for (const control of this.accessControl.controls) {
|
||||||
|
control.get('startDate').enable();
|
||||||
|
control.get('endDate').enable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle validation on form array changes.
|
||||||
|
* This will be used to enable/disable date controls based on the selected item.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private handleValidationOnFormArrayChanges() {
|
||||||
this.accessControl.valueChanges
|
this.accessControl.valueChanges
|
||||||
.pipe(
|
.pipe(
|
||||||
distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)),
|
distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)),
|
||||||
@@ -61,50 +143,6 @@ export class AccessControlArrayFormComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get accessControl() {
|
|
||||||
return this.form.get('accessControl') as FormArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
addAccessControlItem(itemName: string = null) {
|
|
||||||
this.accessControl.push(this.fb.group({
|
|
||||||
itemName,
|
|
||||||
startDate: new FormControl({ value: null, disabled: true }),
|
|
||||||
endDate: new FormControl({ value: null, disabled: true })
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
removeAccessControlItem(index: number) {
|
|
||||||
this.accessControl.removeAt(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
getValue() {
|
|
||||||
return this.form.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.accessControl.reset([]);
|
|
||||||
}
|
|
||||||
|
|
||||||
disable() {
|
|
||||||
this.form.disable();
|
|
||||||
|
|
||||||
// disable all date controls
|
|
||||||
for (const control of this.accessControl.controls) {
|
|
||||||
control.get('startDate').disable();
|
|
||||||
control.get('endDate').disable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enable() {
|
|
||||||
this.form.enable();
|
|
||||||
|
|
||||||
// enable date controls
|
|
||||||
for (const control of this.accessControl.controls) {
|
|
||||||
control.get('startDate').enable();
|
|
||||||
control.get('endDate').enable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
this.destroy$.next();
|
this.destroy$.next();
|
||||||
this.destroy$.complete();
|
this.destroy$.complete();
|
||||||
|
@@ -3,8 +3,8 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|||||||
import { AccessControlFormContainerComponent } from './access-control-form-container.component';
|
import { AccessControlFormContainerComponent } from './access-control-form-container.component';
|
||||||
|
|
||||||
describe('AccessControlFormContainerComponent', () => {
|
describe('AccessControlFormContainerComponent', () => {
|
||||||
let component: AccessControlFormContainerComponent;
|
let component: AccessControlFormContainerComponent<any>;
|
||||||
let fixture: ComponentFixture<AccessControlFormContainerComponent>;
|
let fixture: ComponentFixture<AccessControlFormContainerComponent<any>>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { ChangeDetectorRef, Component, Input, NgModule, ViewChild } from '@angular/core';
|
import { ChangeDetectorRef, Component, Input, NgModule, OnDestroy, ViewChild } from '@angular/core';
|
||||||
import { concatMap, Observable, shareReplay } from 'rxjs';
|
import { concatMap, Observable, shareReplay } 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';
|
||||||
@@ -30,11 +30,23 @@ import { BulkAccessConditionOptions } from '../../core/config/models/bulk-access
|
|||||||
styleUrls: [ './access-control-form-container.component.scss' ],
|
styleUrls: [ './access-control-form-container.component.scss' ],
|
||||||
exportAs: 'dsAccessControlForm'
|
exportAs: 'dsAccessControlForm'
|
||||||
})
|
})
|
||||||
export class AccessControlFormContainerComponent<T extends DSpaceObject> {
|
export class AccessControlFormContainerComponent<T extends DSpaceObject> implements OnDestroy {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will be used to determine if we need to show the limit changes to specific bitstreams radio buttons
|
||||||
|
*/
|
||||||
@Input() showLimitToSpecificBitstreams = false;
|
@Input() showLimitToSpecificBitstreams = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The item to which the access control form applies
|
||||||
|
*/
|
||||||
@Input() itemRD: RemoteData<T>;
|
@Input() itemRD: RemoteData<T>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to show the submit and cancel button
|
||||||
|
* We want to hide these buttons when the form is
|
||||||
|
* used in an accordion, and we want to show buttons somewhere else
|
||||||
|
*/
|
||||||
@Input() showSubmit = true;
|
@Input() showSubmit = true;
|
||||||
|
|
||||||
@ViewChild('bitstreamAccessCmp', { static: true }) bitstreamAccessCmp: AccessControlArrayFormComponent;
|
@ViewChild('bitstreamAccessCmp', { static: true }) bitstreamAccessCmp: AccessControlArrayFormComponent;
|
||||||
@@ -57,6 +69,9 @@ export class AccessControlFormContainerComponent<T extends DSpaceObject> {
|
|||||||
tap(x => console.log('options', x))
|
tap(x => console.log('options', x))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will be used from a parent component to read the value of the form
|
||||||
|
*/
|
||||||
getFormValue() {
|
getFormValue() {
|
||||||
return {
|
return {
|
||||||
bitstream: this.bitstreamAccessCmp.getValue(),
|
bitstream: this.bitstreamAccessCmp.getValue(),
|
||||||
@@ -65,12 +80,20 @@ export class AccessControlFormContainerComponent<T extends DSpaceObject> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the form to its initial state
|
||||||
|
* This will also reset the state of the child components (bitstream and item access)
|
||||||
|
*/
|
||||||
reset() {
|
reset() {
|
||||||
this.bitstreamAccessCmp.reset();
|
this.bitstreamAccessCmp.reset();
|
||||||
this.itemAccessCmp.reset();
|
this.itemAccessCmp.reset();
|
||||||
this.state = initialState;
|
this.state = initialState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submit the form
|
||||||
|
* This will create a payload file and execute the script
|
||||||
|
*/
|
||||||
submit() {
|
submit() {
|
||||||
const bitstreamAccess = this.bitstreamAccessCmp.getValue();
|
const bitstreamAccess = this.bitstreamAccessCmp.getValue();
|
||||||
const itemAccess = this.itemAccessCmp.getValue();
|
const itemAccess = this.itemAccessCmp.getValue();
|
||||||
@@ -89,6 +112,12 @@ export class AccessControlFormContainerComponent<T extends DSpaceObject> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the status change of the access control form (item or bitstream)
|
||||||
|
* This will enable/disable the access control form for the item or bitstream
|
||||||
|
* @param type The type of the access control form (item or bitstream)
|
||||||
|
* @param active boolean indicating whether the access control form should be enabled or disabled
|
||||||
|
*/
|
||||||
handleStatusChange(type: 'item' | 'bitstream', active: boolean) {
|
handleStatusChange(type: 'item' | 'bitstream', active: boolean) {
|
||||||
if (type === 'bitstream') {
|
if (type === 'bitstream') {
|
||||||
active ? this.bitstreamAccessCmp.enable() : this.bitstreamAccessCmp.disable();
|
active ? this.bitstreamAccessCmp.enable() : this.bitstreamAccessCmp.disable();
|
||||||
@@ -97,6 +126,11 @@ export class AccessControlFormContainerComponent<T extends DSpaceObject> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open the modal to select bitstreams for which to change the access control
|
||||||
|
* This will open the modal and pass the currently selected bitstreams
|
||||||
|
* @param item The item for which to change the access control
|
||||||
|
*/
|
||||||
openSelectBitstreamsModal(item: Item) {
|
openSelectBitstreamsModal(item: Item) {
|
||||||
const ref = this.modalService.open(ItemAccessControlSelectBitstreamsModalComponent);
|
const ref = this.modalService.open(ItemAccessControlSelectBitstreamsModalComponent);
|
||||||
ref.componentInstance.selectedBitstreams = this.state.bitstream.selectedBitstreams;
|
ref.componentInstance.selectedBitstreams = this.state.bitstream.selectedBitstreams;
|
||||||
@@ -111,7 +145,6 @@ export class AccessControlFormContainerComponent<T extends DSpaceObject> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @angular-eslint/use-lifecycle-interface
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.selectableListService.deselectAll(ITEM_ACCESS_CONTROL_SELECT_BITSTREAMS_LIST_ID);
|
this.selectableListService.deselectAll(ITEM_ACCESS_CONTROL_SELECT_BITSTREAMS_LIST_ID);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user