diff --git a/src/app/access-control/bulk-access/browse/bulk-access-browse.component.ts b/src/app/access-control/bulk-access/browse/bulk-access-browse.component.ts index 43adae7ec0..7cbb8740a7 100644 --- a/src/app/access-control/bulk-access/browse/bulk-access-browse.component.ts +++ b/src/app/access-control/bulk-access/browse/bulk-access-browse.component.ts @@ -17,56 +17,7 @@ import { hasValue } from '../../../shared/empty.util'; @Component({ selector: 'ds-bulk-access-browse', - template: ` - - - -
- -
-
- - -
-
-
-
- - -
-
-
-
- `, + templateUrl: 'bulk-access-browse.component.html', styleUrls: ['./bulk-access-browse.component.scss'], providers: [ { diff --git a/src/app/community-page/edit-community-page/community-access-control/community-access-control.service.ts b/src/app/community-page/edit-community-page/community-access-control/community-access-control.service.ts deleted file mode 100644 index 89534683b7..0000000000 --- a/src/app/community-page/edit-community-page/community-access-control/community-access-control.service.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { Injectable } from '@angular/core'; -import { of } from 'rxjs'; -import { BulkAccessConditionOptionsService } from '../../../core/data/bulk-access-condition-options.service'; -import { BulkAccessConditionOptions } from '../../../core/shared/bulk-access-condition-options.model'; - - -@Injectable() -export class CommunityAccessControlService { - constructor(private service: BulkAccessConditionOptionsService) {} - - dropdownData$ = of(accessControlDropdownData); - - // dropdownData$ = this.service.getAll().pipe( - // getAllSucceededRemoteData(), - // filter((data) => data.hasSucceeded), - // map((data) => data.payload) - // ); -} - -const accessControlDropdownData: BulkAccessConditionOptions = { - _links: { self: undefined }, type: undefined, uuid: '', - 'id': 'default', - 'itemAccessConditionOptions': [ - { - 'name': 'openaccess' - }, - { - 'name': 'administrator' - }, - { - 'name': 'embargo', - 'hasStartDate': true, - 'maxStartDate': '2018-06-24T00:40:54.970+0000' - }, - { - 'name': 'lease', - 'hasEndDate': true, - 'maxEndDate': '2017-12-24T00:40:54.970+0000' - } - ], - 'bitstreamAccessConditionOptions': [ - { - 'name': 'openaccess' - }, - { - 'name': 'administrator' - }, - { - 'name': 'embargo', - 'hasStartDate': true, - 'maxStartDate': '2018-06-24T00:40:54.970+0000' - }, - { - 'name': 'lease', - 'hasEndDate': true, - 'maxEndDate': '2017-12-24T00:40:54.970+0000' - } - ] -}; diff --git a/src/app/core/data/bulk-access-condition-options.service.ts b/src/app/core/config/bulk-access-config-data.service.ts similarity index 53% rename from src/app/core/data/bulk-access-condition-options.service.ts rename to src/app/core/config/bulk-access-config-data.service.ts index 30e0402dbf..f27b59eee1 100644 --- a/src/app/core/data/bulk-access-condition-options.service.ts +++ b/src/app/core/config/bulk-access-config-data.service.ts @@ -3,16 +3,16 @@ import { Observable } from 'rxjs'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { ObjectCacheService } from '../cache/object-cache.service'; import { HALEndpointService } from '../shared/hal-endpoint.service'; -import { RemoteData } from './remote-data'; -import { RequestService } from './request.service'; -import { IdentifiableDataService } from './base/identifiable-data.service'; -import { BulkAccessConditionOptions } from '../shared/bulk-access-condition-options.model'; +import { RemoteData } from '../data/remote-data'; +import { RequestService } from '../data/request.service'; +import { BulkAccessConditionOptions } from './models/bulk-access-condition-options.model'; +import { ConfigDataService } from './config-data.service'; @Injectable({ providedIn: 'root' }) /** * Data Service responsible for retrieving Bulk Access Condition Options from the REST API */ -export class BulkAccessConditionOptionsService extends IdentifiableDataService { +export class BulkAccessConfigDataService extends ConfigDataService { constructor( protected requestService: RequestService, @@ -23,11 +23,7 @@ export class BulkAccessConditionOptionsService extends IdentifiableDataService> { - return this.findByHref(this.halService.getEndpoint(this.linkPath)); + findByPropertyName(name: string): Observable> { + return this.findById(name) as Observable>; } - - // findByPropertyName(name: string): Observable> { - // return this.findById(name); - // } } diff --git a/src/app/core/config/config-data.service.ts b/src/app/core/config/config-data.service.ts index 9ef2f11ad1..f8f46435c5 100644 --- a/src/app/core/config/config-data.service.ts +++ b/src/app/core/config/config-data.service.ts @@ -4,13 +4,13 @@ import { RemoteData } from '../data/remote-data'; import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model'; import { getFirstCompletedRemoteData } from '../shared/operators'; import { map } from 'rxjs/operators'; -import { BaseDataService } from '../data/base/base-data.service'; +import { IdentifiableDataService } from '../data/base/identifiable-data.service'; /** * Abstract data service to retrieve configuration objects from the REST server. * Common logic for configuration objects should be implemented here. */ -export abstract class ConfigDataService extends BaseDataService { +export abstract class ConfigDataService extends IdentifiableDataService { /** * Returns an observable of {@link RemoteData} of an object, based on an href, with a list of * {@link FollowLinkConfig}, to automatically resolve {@link HALLink}s of the object @@ -37,4 +37,8 @@ export abstract class ConfigDataService extends BaseDataService { }), ); } + + findByName(name: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig[]): Observable> { + return super.findById(name, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); + } } diff --git a/src/app/core/config/models/bulk-access-condition-options.model.ts b/src/app/core/config/models/bulk-access-condition-options.model.ts new file mode 100644 index 0000000000..f10965ea31 --- /dev/null +++ b/src/app/core/config/models/bulk-access-condition-options.model.ts @@ -0,0 +1,38 @@ +import { autoserialize, autoserializeAs, deserialize } from 'cerialize'; +import { typedObject } from '../../cache/builders/build-decorators'; +import { excludeFromEquals } from '../../utilities/equals.decorators'; +import { ResourceType } from '../../shared/resource-type'; +import { HALLink } from '../../shared/hal-link.model'; +import { ConfigObject } from './config.model'; +import { AccessesConditionOption } from './config-accesses-conditions-options.model'; + +export const BULK_ACCESS_CONDITION_OPTIONS = new ResourceType('bulkAccessConditionOptions'); + +/** + * Model class for a bulk access condition options + */ +@typedObject +export class BulkAccessConditionOptions extends ConfigObject { + static type = BULK_ACCESS_CONDITION_OPTIONS; + + /** + * The object type + */ + @excludeFromEquals + @autoserialize + type: ResourceType; + + @autoserializeAs(String, 'name') + uuid: string; + + @autoserialize + id: string; + + @deserialize + itemAccessConditionOptions: AccessesConditionOption[]; + + @deserialize + bitstreamAccessConditionOptions: AccessesConditionOption[]; + + _links: { self: HALLink }; +} diff --git a/src/app/core/shared/bulk-access-condition-options.model.ts b/src/app/core/shared/bulk-access-condition-options.model.ts deleted file mode 100644 index a1c8fe0702..0000000000 --- a/src/app/core/shared/bulk-access-condition-options.model.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { autoserialize, autoserializeAs, deserialize } from 'cerialize'; -import { typedObject } from '../cache/builders/build-decorators'; -import { excludeFromEquals } from '../utilities/equals.decorators'; -import { ResourceType } from './resource-type'; -import { CacheableObject } from '../cache/cacheable-object.model'; -import { HALLink } from './hal-link.model'; - -export const BULK_ACCESS_CONDITION_OPTIONS = new ResourceType('bulkAccessConditionOptions'); - -/** - * Model class for a bulk access condition options - */ -@typedObject -export class BulkAccessConditionOptions implements CacheableObject { - static type = BULK_ACCESS_CONDITION_OPTIONS; - - /** - * The object type - */ - @excludeFromEquals - @autoserialize - type: ResourceType; - - @autoserializeAs(String, 'name') - uuid: string; - - @autoserialize - id: string; - - @deserialize - itemAccessConditionOptions: AccessControlItem[]; - - @deserialize - bitstreamAccessConditionOptions: AccessControlItem[]; - - _links: { self: HALLink }; -} - -export interface AccessControlItem { - name: string - hasStartDate?: boolean - maxStartDate?: string - hasEndDate?: boolean - maxEndDate?: string -} diff --git a/src/app/shared/access-control-array-form/access-control-array-form.component.html b/src/app/shared/access-control-array-form/access-control-array-form.component.html index 24dcc11120..5d0fb6d97e 100644 --- a/src/app/shared/access-control-array-form/access-control-array-form.component.html +++ b/src/app/shared/access-control-array-form/access-control-array-form.component.html @@ -7,7 +7,7 @@
@@ -20,7 +20,7 @@ placeholder="yyyy-mm-dd" name="dp" formControlName="startDate" - [minDate]="control | maxStartDate: dropdownOptions" + [minDate]="control | maxStartDate: (dropdownData$ | async)" ngbDatepicker #d="ngbDatepicker" /> @@ -40,7 +40,7 @@ placeholder="yyyy-mm-dd" name="dp" formControlName="endDate" - [maxDate]="control | maxEndDate: dropdownOptions" + [maxDate]="control | maxEndDate: (dropdownData$ | async)" ngbDatepicker #d1="ngbDatepicker" /> diff --git a/src/app/shared/access-control-array-form/access-control-array-form.component.ts b/src/app/shared/access-control-array-form/access-control-array-form.component.ts index ace507a3a6..13d13375b2 100644 --- a/src/app/shared/access-control-array-form/access-control-array-form.component.ts +++ b/src/app/shared/access-control-array-form/access-control-array-form.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, NgModule, OnDestroy, OnInit } from '@angular/core'; +import { Component, NgModule, OnDestroy, OnInit } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FormArray, FormBuilder, FormControl, ReactiveFormsModule } from '@angular/forms'; import { SharedBrowseByModule } from '../browse-by/shared-browse-by.module'; @@ -6,9 +6,13 @@ import { TranslateModule } from '@ngx-translate/core'; import { NgbDatepickerModule } from '@ng-bootstrap/ng-bootstrap'; import { ControlMaxStartDatePipe } from './control-max-start-date.pipe'; import { ControlMaxEndDatePipe } from './control-max-end-date.pipe'; -import { AccessControlItem } from '../../core/shared/bulk-access-condition-options.model'; -import { distinctUntilChanged, takeUntil } from 'rxjs/operators'; + +import { distinctUntilChanged, map, shareReplay, takeUntil, tap } from 'rxjs/operators'; import { Subject } from 'rxjs'; +import { getFirstCompletedRemoteData } from '../../core/shared/operators'; +import { RemoteData } from '../../core/data/remote-data'; +import { BulkAccessConditionOptions } from '../../core/config/models/bulk-access-condition-options.model'; +import { BulkAccessConfigDataService } from '../../core/config/bulk-access-config-data.service'; // will be used on the form value @@ -25,8 +29,6 @@ export interface AccessControlItemValue { exportAs: 'accessControlArrayForm' }) export class AccessControlArrayFormComponent implements OnInit, OnDestroy { - @Input() dropdownOptions: AccessControlItem[] = []; - @Input() accessControlItems: AccessControlItemValue[] = []; private destroy$ = new Subject(); @@ -34,17 +36,28 @@ export class AccessControlArrayFormComponent implements OnInit, OnDestroy { accessControl: this.fb.array([]) }); - constructor(private fb: FormBuilder) { + constructor(private bulkAccessConfigService: BulkAccessConfigDataService, + private fb: FormBuilder) { } + dropdownData$ = this.bulkAccessConfigService.findByPropertyName('default').pipe( + getFirstCompletedRemoteData(), + map((configRD: RemoteData) => configRD.hasSucceeded ? configRD.payload : null), + shareReplay(1), + tap(console.log) + ); + ngOnInit(): void { - if (this.accessControlItems.length === 0) { + // console.log(this.dropdownOptions); +/* if (this.accessControlItems.length === 0) { this.addAccessControlItem(); } else { for (const item of this.accessControlItems) { this.addAccessControlItem(item.itemName); } - } + }*/ + + this.addAccessControlItem(); this.accessControl.valueChanges .pipe( diff --git a/src/app/shared/access-control-array-form/control-max-end-date.pipe.ts b/src/app/shared/access-control-array-form/control-max-end-date.pipe.ts index 810f3e71d0..86ba3b996a 100644 --- a/src/app/shared/access-control-array-form/control-max-end-date.pipe.ts +++ b/src/app/shared/access-control-array-form/control-max-end-date.pipe.ts @@ -1,7 +1,7 @@ import { Pipe, PipeTransform } from '@angular/core'; import { AbstractControl } from '@angular/forms'; import { NgbDateStruct } from '@ng-bootstrap/ng-bootstrap/datepicker/ngb-date-struct'; -import { AccessControlItem } from 'src/app/core/shared/bulk-access-condition-options.model'; +import { AccessesConditionOption } from '../../core/config/models/config-accesses-conditions-options.model'; @Pipe({ // eslint-disable-next-line @angular-eslint/pipe-prefix @@ -9,7 +9,7 @@ import { AccessControlItem } from 'src/app/core/shared/bulk-access-condition-opt pure: false }) export class ControlMaxEndDatePipe implements PipeTransform { - transform(control: AbstractControl, dropdownOptions: AccessControlItem[]): NgbDateStruct | null { + transform(control: AbstractControl, dropdownOptions: AccessesConditionOption[]): NgbDateStruct | null { const { itemName } = control.value; const item = dropdownOptions.find((x) => x.name === itemName); if (!item?.hasEndDate) { diff --git a/src/app/shared/access-control-array-form/control-max-start-date.pipe.ts b/src/app/shared/access-control-array-form/control-max-start-date.pipe.ts index 458cb36465..77be77b029 100644 --- a/src/app/shared/access-control-array-form/control-max-start-date.pipe.ts +++ b/src/app/shared/access-control-array-form/control-max-start-date.pipe.ts @@ -1,7 +1,8 @@ import { Pipe, PipeTransform } from '@angular/core'; import { AbstractControl } from '@angular/forms'; import { NgbDateStruct } from '@ng-bootstrap/ng-bootstrap/datepicker/ngb-date-struct'; -import { AccessControlItem } from 'src/app/core/shared/bulk-access-condition-options.model'; +import { AccessesConditionOption } from '../../core/config/models/config-accesses-conditions-options.model'; + @Pipe({ // eslint-disable-next-line @angular-eslint/pipe-prefix @@ -9,7 +10,7 @@ import { AccessControlItem } from 'src/app/core/shared/bulk-access-condition-opt pure: false }) export class ControlMaxStartDatePipe implements PipeTransform { - transform(control: AbstractControl, dropdownOptions: AccessControlItem[]): NgbDateStruct | null { + transform(control: AbstractControl, dropdownOptions: AccessesConditionOption[]): NgbDateStruct | null { const { itemName } = control.value; const item = dropdownOptions.find((x) => x.name === itemName); if (!item?.hasStartDate) { diff --git a/src/app/shared/access-control-form-container/access-control-form-container.component.html b/src/app/shared/access-control-form-container/access-control-form-container.component.html index 71175ce588..70f1b1e6cd 100644 --- a/src/app/shared/access-control-form-container/access-control-form-container.component.html +++ b/src/app/shared/access-control-form-container/access-control-form-container.component.html @@ -48,10 +48,7 @@
- - +
@@ -137,10 +134,7 @@
- - + diff --git a/src/app/shared/access-control-form-container/access-control-form-container.component.ts b/src/app/shared/access-control-form-container/access-control-form-container.component.ts index a2e9cb08ab..0807236796 100644 --- a/src/app/shared/access-control-form-container/access-control-form-container.component.ts +++ b/src/app/shared/access-control-form-container/access-control-form-container.component.ts @@ -1,5 +1,5 @@ import { ChangeDetectorRef, Component, Input, NgModule, ViewChild } from '@angular/core'; -import { concatMap, shareReplay } from 'rxjs'; +import { concatMap } from 'rxjs'; import { RemoteData } from '../../core/data/remote-data'; import { Item } from '../../core/shared/item.model'; import { @@ -20,6 +20,7 @@ import { ITEM_ACCESS_CONTROL_SELECT_BITSTREAMS_LIST_ID, ItemAccessControlSelectBitstreamsModalComponent } from './item-access-control-select-bitstreams-modal/item-access-control-select-bitstreams-modal.component'; +import { BulkAccessConfigDataService } from '../../core/config/bulk-access-config-data.service'; @Component({ selector: 'ds-access-control-form-container', @@ -27,7 +28,7 @@ import { styleUrls: [ './access-control-form-container.component.scss' ], exportAs: 'dsAccessControlForm' }) -export class AccessControlFormContainerComponent { +export class AccessControlFormContainerComponent implements OnInit { @Input() showLimitToSpecificBitstreams = false; @Input() itemRD: RemoteData; @@ -38,6 +39,7 @@ export class AccessControlFormContainerComponent { @ViewChild('itemAccessCmp', { static: true }) itemAccessCmp: AccessControlArrayFormComponent; constructor( + private bulkAccessConfigService: BulkAccessConfigDataService, private bulkAccessControlService: BulkAccessControlService, private selectableListService: SelectableListService, protected modalService: NgbModal, @@ -46,9 +48,16 @@ export class AccessControlFormContainerComponent { state = initialState; - dropdownData$ = this.bulkAccessControlService.dropdownData$.pipe( +/* dropdownData$ = this.bulkAccessConfigService.findByPropertyName('default').pipe( + getFirstCompletedRemoteData(), + map((configRD: RemoteData) => configRD.hasSucceeded ? configRD.payload : null), + shareReplay(1), + tap(console.log) + );*/ + +/* dropdownData$ = this.bulkAccessControlService.dropdownData$.pipe( shareReplay(1) - ); + );*/ getFormValue() { return { diff --git a/src/app/shared/access-control-form-container/bulk-access-control.service.ts b/src/app/shared/access-control-form-container/bulk-access-control.service.ts index 85ec05cd60..1cce44d828 100644 --- a/src/app/shared/access-control-form-container/bulk-access-control.service.ts +++ b/src/app/shared/access-control-form-container/bulk-access-control.service.ts @@ -1,21 +1,12 @@ import { Injectable } from '@angular/core'; -import { Observable, of } from 'rxjs'; -import { AccessControlItem } from '../../core/shared/bulk-access-condition-options.model'; + import { ScriptDataService } from '../../core/data/processes/script-data.service'; import { ProcessParameter } from '../../process-page/processes/process-parameter.model'; -export interface AccessControlDropdownDataResponse { - id: string; - itemAccessConditionOptions: AccessControlItem[]; - bitstreamAccessConditionOptions: AccessControlItem[]; -} - @Injectable({ providedIn: 'root' }) export class BulkAccessControlService { constructor(private scriptService: ScriptDataService) {} - dropdownData$: Observable = of(accessControlDropdownData); - createPayloadFile(payload: any) { console.log('execute', payload); @@ -43,43 +34,3 @@ export class BulkAccessControlService { return this.scriptService.invoke('bulk-access-control', params, [file]); } } - -const accessControlDropdownData: AccessControlDropdownDataResponse = { - 'id': 'default', - 'itemAccessConditionOptions': [ - { - 'name': 'openaccess' - }, - { - 'name': 'administrator' - }, - { - 'name': 'embargo', - 'hasStartDate': true, - 'maxStartDate': '2023-05-12T00:40:54.970+0000' - }, - { - 'name': 'lease', - 'hasEndDate': true, - 'maxEndDate': '2017-12-24T00:40:54.970+0000' - } - ], - 'bitstreamAccessConditionOptions': [ - { - 'name': 'openaccess' - }, - { - 'name': 'administrator' - }, - { - 'name': 'embargo', - 'hasStartDate': true, - 'maxStartDate': '2018-06-24T00:40:54.970+0000' - }, - { - 'name': 'lease', - 'hasEndDate': true, - 'maxEndDate': '2017-12-24T00:40:54.970+0000' - } - ] -};